home *** CD-ROM | disk | FTP | other *** search
- /*
- File: LinkMgr.cpp
-
- Contains: Implementation for ODLinkManager class.
-
- Owned by: Craig Carper
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 5/24/96 jpa 1246074: SOM_CATCH --> SOM_TRY..SOM_ENDTRY
- <3> 3/26/96 CC 1288720: Removed kODULongSequence value
- type.
- <2> 3/15/96 CC 1328345: Extracted code from
- GetLinkAEHandler to make GetLink;
- Extracted code from RequestLinkAEHandler to
- make UseLinkEdition.
-
- To Do:
- In Progress:
-
- */
-
- #define VARIABLE_MACROS
-
- #define ODLinkManager_Class_Source
- #include <LinkMgr.xih>
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODLink_xh
- #include <Link.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODLinkIterator_xh
- #include <LinkItr.xh>
- #endif
-
- #ifndef SOM_ODLinkSourceIterator_xh
- #include <LkSrcItr.xh>
- #endif
-
- #ifndef _LINKDEFS_
- #include <LinkDefs.h>
- #endif
-
- #ifndef _LINKDLGS_
- #include <LinkDlgs.h>
- #endif
-
- #ifndef _ORDCOLL_
- #include <OrdColl.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Errors_defined
- #include <ErrorDef.xh>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _REFCTCOL_
- #include "RefCtCol.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- // For smSystemScript
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __NOTIFICATION__
- #include <Notification.h>
- #endif
-
- #pragma segment ODLinkManager
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const Boolean kNotSysHandler = false;
-
- // Apple event constants
- #define kODGetLinkEventID 'gtln'
- #define kODRequestLinkEventID 'rqln'
- #define keyEditionAlias 'edas'
- #define kODLinkSourceKey 'lksr'
-
- const ODUShort kODStorageUnitRefLen = 4;
- const ODUShort kODULongSize = 4;
-
- //==============================================================================
- // Local Function Prototypes
- //==============================================================================
- ODStatic StringPtr BuildErrorString(ODSShort strResourceID, ODError error);
-
- ODStatic EditionContainerSpec NewEditionFile(Environment* ev,
- PlatformFile* documentFile,
- ODDraft* draft);
-
- ODStatic void EditionFileName(Str255 fileName, ODUShort numb);
- ODStatic void TruncateFileName(Str255 fileName, Str63 numberString);
-
- ODStatic ODULong NewEditionID(Environment *ev, ODDraft* draft);
-
- ODStatic void RegisterPublishingLinks(Environment *ev, ODDraft* draft);
- ODStatic void RegisterSubscribingLinks(Environment *ev, ODDraft* draft);
- ODStatic void UpdateEditionFiles(Environment *ev, ODRefCntCollection* collection);
- ODStatic void DeleteEditionFiles(Environment *ev, ODRefCntCollection* collection);
- // ODStatic void RemoveAllLinksInCollection(Environment *ev, OrderedCollection* collection);
- ODStatic OSErr GetSectionFromEvent(const AppleEvent* theAppleEvent,
- SectionHandle* section);
- ODStatic void AppendULongToDraftProperty(Environment *ev,
- ODDraft* draft, ODPropertyName prop, ODULong value);
- ODStatic ODBoolean SectionIDReserved(Environment *ev,
- ODDraft* draft, ODULong requestedID);
- ODStatic ODULong PeekNextGlobalID(Environment *ev,
- ODDraft* draft,
- ODPropertyName globalProp);
- ODStatic ODULong ReserveGlobalID(Environment *ev,
- ODDraft* draft,
- ODPropertyName globalProp);
-
- ODStatic OSErr ODPascal GetLinkAEHandler(
- const AppleEvent* theAppleEvent,
- AppleEvent* reply,
- long refCon);
- ODStatic OSErr ODPascal RequestLinkAEHandler(
- const AppleEvent* theAppleEvent,
- AppleEvent* reply,
- long refCon);
- ODStatic OSErr ODPascal SectionReadAEHandler(
- const AppleEvent* theAppleEvent,
- const AppleEvent* reply,
- long refCon);
- ODStatic OSErr ODPascal SectionWriteAEHandler(
- const AppleEvent* theAppleEvent,
- const AppleEvent* reply,
- long refCon);
- ODStatic OSErr ODPascal SectionScrollAEHandler(
- const AppleEvent* theAppleEvent,
- const AppleEvent* reply,
- long refCon);
-
-
- //==============================================================================
- // struct DraftInfo
- //==============================================================================
-
- struct DraftInfo
- {
- ODDraft* draft;
- ODRefCntCollection* linksToExport;
- ODRefCntCollection* linksToDelete;
- ODRefCntCollection* newExportedLinks;
- ODBoolean linksImported;
- };
-
- // ODObjectCollection is replaced by ODObjectOrdColl in RefCtCol.h in Utilities
-
- //==============================================================================
- // class ODObjectCollection
- //==============================================================================
- //
- // class ODObjectCollection : public OrderedCollection
- // {
- // public:
- // ODObjectCollection() : OrderedCollection() {}
- // ODVMethod ~ODObjectCollection() {}
- //
- // ODMethod ODBoolean ElementsMatch(ElementType v1,ElementType v2) const;
- // };
-
- //------------------------------------------------------------------------------
- // ODObjectCollection::ElementsMatch (OVERRIDE)
- //------------------------------------------------------------------------------
-
- // ODBoolean ODObjectCollection::ElementsMatch(ElementType v1,ElementType v2) const
- // {
- // Environment* ev = somGetGlobalEnvironment();
- // return ODObjectsAreEqual(ev, (ODObject*) v1, (ODObject*) v2);
- // }
-
- //==============================================================================
- // Static functions
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // LinkMgrNMResponse
- //------------------------------------------------------------------------------
-
- ODStatic void ODPascal LinkMgrNMResponse(NMRecPtr theNMRecPtr)
- {
- OSErr error = NMRemove(theNMRecPtr);
- }
-
- //==============================================================================
- // class ODLinkManager
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ODLinkManager::InitLinkManager
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerInitLinkManager(ODLinkManager *somSelf, Environment *ev,
- ODSession* session)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","InitLinkManager");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fSuspendedUpdateLinks = (ODRefCntCollection*) kODNULL;
- _fDraftInfos = (OrderedCollection*) kODNULL;
- _fNMResponseUPP = (NMUPP) kODNULL;
- _fNMRecPtr = (NMRecPtr) kODNULL;
- */
- somSelf->InitObject(ev);
-
- long gestaltResult;
- OSErr result;
-
- // Check if the Edition manager is present
- result = Gestalt(gestaltEditionMgrAttr, &gestaltResult);
- THROW_IF_ERROR (result, "Error from Gestalt");
-
- // The mysterious 31 is the bit position as BitTst uses a convention opposite to MC68000
- if ( BitTst(&gestaltResult, (31 - gestaltEditionMgrPresent)) == false )
- THROW(kODErrNoEditionManager);
-
- InitLinkDialogs(session);
-
- _fSuspendedUpdateLinks = new ODRefCntCollection(ev);
- _fDraftInfos = new OrderedCollection;
- _fNMResponseUPP = NewNMProc(LinkMgrNMResponse);
- _fNMRecPtr = (NMRecPtr) ODNewPtr(sizeof(NMRec));
- THROW_IF_NULL(_fNMRecPtr);
- _fNMRecPtr->nmStr = kODNULL;
-
- AEEventHandlerUPP theHandlerUPP ;
- theHandlerUPP = NewAEEventHandlerProc( GetLinkAEHandler ) ;
- THROW_IF_ERROR(AEInstallEventHandler(kODShellSignature,
- kODGetLinkEventID, theHandlerUPP, (long)somSelf, kNotSysHandler));
-
- theHandlerUPP = NewAEEventHandlerProc( RequestLinkAEHandler ) ;
- THROW_IF_ERROR(AEInstallEventHandler(kODShellSignature,
- kODRequestLinkEventID, theHandlerUPP, (long)somSelf, kNotSysHandler));
-
- theHandlerUPP = NewAEEventHandlerProc( SectionReadAEHandler ) ;
- THROW_IF_ERROR(AEInstallEventHandler(sectionEventMsgClass, sectionReadMsgID,
- theHandlerUPP, (long)somSelf, kNotSysHandler));
-
- theHandlerUPP = NewAEEventHandlerProc( SectionWriteAEHandler );
- THROW_IF_ERROR(AEInstallEventHandler(sectionEventMsgClass, sectionWriteMsgID,
- theHandlerUPP, (long)somSelf, kNotSysHandler));
-
- theHandlerUPP = NewAEEventHandlerProc( SectionScrollAEHandler );
- THROW_IF_ERROR(AEInstallEventHandler(sectionEventMsgClass, sectionScrollMsgID,
- theHandlerUPP, (long)somSelf, kNotSysHandler));
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::NewSectionID
- //------------------------------------------------------------------------------
-
- SOM_Scope ODULong SOMLINK ODLinkManagerNewSectionID(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","NewSectionID");
-
- ODULong sectionID;
-
- SOM_TRY
-
- do
- sectionID = ReserveGlobalID(ev, draft, kODPropSectionID);
- while
- ( SectionIDReserved(ev, draft, sectionID) );
-
- return sectionID;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return 0;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::ReserveSectionID
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkManagerReserveSectionID(ODLinkManager *somSelf, Environment *ev,
- ODULong sectionID,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","ReserveSectionID");
-
- SOM_TRY
-
- ODBoolean result = kODFalse;
-
- if ( sectionID >= PeekNextGlobalID(ev, draft, kODPropSectionID) )
- if ( !SectionIDReserved(ev, draft, sectionID) )
- {
- AppendULongToDraftProperty(ev, draft, kODPropReservedSectionIDs, sectionID);
- result = kODTrue;
- }
-
- return result;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //-------------------------------------------------------------------------------------
- // ODLinkManager: ShowLinkUpdateAlert
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODLinkUpdateResult SOMLINK ODLinkManagerShowLinkUpdateAlert(ODLinkManager *somSelf, Environment *ev,
- ODBaseLinkSource* link)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","ShowLinkUpdateAlert");
-
- ODLinkUpdateResult result = kODLinkUpdateContinue; ODVolatile(result);
-
- SOM_TRY
-
- // When we leave the background, iterate over all the link sources
- // that attempted to call ShowLinkUpdateAlert() in the background,
- // showing the alert now and calling the links back with the
- // resulting information.
-
- if ( _fInBackground )
- {
- result = kODLinkUpdateStop;
- if ( !_fSuspendedUpdateLinks->Contains(link) )
- _fSuspendedUpdateLinks->AddLastAndAcquire(link);
- result = kODLinkUpdateSuspend;
- }
- else
- {
- result = ( ::ShowLinkUpdateAlert() )?
- kODLinkUpdateContinue : kODLinkUpdateStop;
- }
-
- SOM_CATCH_ALL
-
- SOM_ENDTRY
-
- return result;
- }
-
- //-------------------------------------------------------------------------------------
- // ODLinkManager: SuspendResume
- //-------------------------------------------------------------------------------------
-
- #if ODDebug
- extern int gODButtonKeyNoEnterOkay;
- #endif
-
- SOM_Scope void SOMLINK ODLinkManagerSuspendResume(ODLinkManager *somSelf, Environment *ev,
- ODEventData* event)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","SuspendResume");
-
- const short kResumeMask = 0x01; // High byte suspend/resume event
-
- ODBoolean inBackground = (event->message & kResumeMask) == 0;
- _fInBackground = inBackground;
-
- SOM_TRY
-
- // When we leave the background, show the alert and iterate over all the
- // link sources that attempted to call ShowLinkUpdateAlert() in the
- // background, calling the links back with the resulting alert information.
-
- if ( !inBackground )
- {
- ODBaseLinkSource* link = (ODBaseLinkSource*) _fSuspendedUpdateLinks->RemoveFirst();
- if (link)
- {
-
- ODLinkUpdateResult result = ( ::ShowLinkUpdateAlert() )?
- kODLinkUpdateContinue : kODLinkUpdateStop;
-
- while ( link )
- {
- TempODRefCntObject tempLink = link; // ensure it is released
-
- // Ignore errors returned by LinkUpdateAlertCompleted
- TRY
- link->LinkUpdateAlertCompleted(ev, result);
- CATCH_ALL
- ENDTRY
-
- link = (ODBaseLinkSource*) _fSuspendedUpdateLinks->RemoveFirst();
- }
- }
- }
-
- SOM_CATCH_ALL
-
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::UnsavedExportedLinks
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkManagerUnsavedExportedLinks(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","UnsavedExportedLinks");
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, draft);
-
- if ( info != (DraftInfo*) kODNULL )
- {
- return info->newExportedLinks->Count() > 0;
- }
- else
- return kODFalse;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::AnyLinkImported
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkManagerAnyLinkImported(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","AnyLinkImported");
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, draft);
-
- if ( info != (DraftInfo*) kODNULL )
- {
- return info->linksImported;
- }
- else
- return kODFalse;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::DraftOpened
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerDraftOpened(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","DraftOpened");
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, draft);
-
- if ( info == (DraftInfo*) kODNULL )
- {
- somSelf->NewDraftInfo(ev, draft);
- RegisterSubscribingLinks(ev, draft);
- RegisterPublishingLinks(ev, draft);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::DraftSaved
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerDraftSaved(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","DraftSaved");
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, draft);
-
- if ( info != (DraftInfo*) kODNULL )
- {
- UpdateEditionFiles(ev, info->linksToExport);
- // old: RemoveAllLinksInCollection(ev, info->linksToExport);
- info->linksToExport->RemoveAndReleaseAll();
-
- DeleteEditionFiles(ev, info->linksToDelete);
- // old: RemoveAllLinksInCollection(ev, info->linksToDelete);
- info->linksToDelete->RemoveAndReleaseAll();
-
- // old: RemoveAllLinksInCollection(ev, info->newExportedLinks);
- info->newExportedLinks->RemoveAndReleaseAll();
-
- info->linksImported = kODFalse;
- }
- else
- {
- WARN("Draft is not opened yet.");
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::DraftClosing
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerDraftClosing(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","DraftClosing");
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, draft);
-
- if ( info != (DraftInfo*) kODNULL )
- {
- // old: RemoveAllLinksInCollection(ev, info->linksToExport);
- // new: info->linksToExport->RemoveAndReleaseAll();
- ODDeleteObject(info->linksToExport); // calls RemoveAndReleaseAll()
-
- // old: RemoveAllLinksInCollection(ev, info->linksToDelete);
- // new: info->linksToDelete->RemoveAndReleaseAll();
- ODDeleteObject(info->linksToDelete); // calls RemoveAndReleaseAll()
-
- DeleteEditionFiles(ev, info->newExportedLinks);
- // old: RemoveAllLinksInCollection(ev, info->newExportedLinks);
- // new: info->newExportedLinks->RemoveAndReleaseAll();
- ODDeleteObject(info->newExportedLinks); // calls RemoveAndReleaseAll()
-
- _fDraftInfos->Remove(info);
- delete info;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::ExportOnSave
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkManagerExportOnSave(ODLinkManager *somSelf, Environment *ev,
- ODLink* link,
- ODBoolean doExport)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","ExportOnSave");
-
- ODBoolean wereToExport = kODFalse;
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, link->GetStorageUnit(ev)->GetDraft(ev));
- if ( info != (DraftInfo*) kODNULL )
- {
- wereToExport = info->linksToExport->Contains(link);
- if ( wereToExport && !doExport )
- {
- info->linksToExport->RemoveAndRelease(link);
- // link->Release(ev);
- }
- else if ( !wereToExport && doExport )
- {
- info->linksToExport->AddLastAndAcquire(link);
- // link->Acquire(ev);
- }
- }
-
- return wereToExport;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::DeleteOnSave
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkManagerDeleteOnSave(ODLinkManager *somSelf, Environment *ev,
- ODLink* link,
- ODBoolean doDelete)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","DeleteOnSave");
-
- ODBoolean wereToDelete = kODFalse;
-
- SOM_TRY
-
- DraftInfo* info = somSelf->GetDraftInfo(ev, link->GetStorageUnit(ev)->GetDraft(ev));
- if ( info != (DraftInfo*) kODNULL )
- {
- wereToDelete = info->linksToDelete->Contains(link);
- if ( wereToDelete && !doDelete )
- {
- info->linksToDelete->RemoveAndRelease(link);
- // link->Release(ev);
- }
- else if ( !wereToDelete && doDelete )
- {
- info->linksToDelete->AddLastAndAcquire(link);
- // link->Acquire(ev);
- }
- }
-
- return wereToDelete;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::CreateLink
- //------------------------------------------------------------------------------
-
- SOM_Scope ODLinkSource* SOMLINK ODLinkManagerCreateLink(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft,
- ODLinkSpec* linkSpec)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","CreateLink");
-
- ODLinkSource* linkSource = kODNULL; ODVolatile(linkSource);
- AppleEvent theAppleEvent, replyAppleEvent;
- AEAddressDesc targetAddress;
- OSErr error;
- ProcessSerialNumber psn;
- ProcessSerialNumber psnLinkSource;
- ODBoolean isSamePSN;
-
- SOM_TRY
-
- // Create a link source to return
- linkSource = draft->CreateLinkSource(ev, (ODPart*) kODNULL);
-
- // If the draft was created by this process, call the part directly
- GetCurrentProcess(&psn);
- linkSpec->GetOriginatingProcessID(ev, &psnLinkSource);
- SameProcess(&psn, &psnLinkSource, &isSamePSN);
- if ( isSamePSN )
- {
- TempODByteArrayStruct aliasBA;
- somSelf->GetLink(ev, linkSpec, (ODByteArray*) aliasBA);
- somSelf->UseLinkEdition(ev, linkSource, (ODByteArray*) aliasBA);
- }
- else
- {
- // Send an Apple Event to this process specifying a process number
- // address, so the event is delivered as a high-level event
- error = AECreateDesc(typeProcessSerialNumber, &psn,
- sizeof(ProcessSerialNumber), &targetAddress);
- THROW_IF_ERROR(error);
- TempAEDesc tmpTargetAddress(&targetAddress);
-
- error = AECreateAppleEvent(kODShellSignature, kODRequestLinkEventID,
- &targetAddress, kAutoGenerateReturnID,
- kAnyTransactionID, &theAppleEvent);
- THROW_IF_ERROR(error);
- TempAEDesc tmpAppleEvent(&theAppleEvent);
-
- // Add the link spec to the Apple event
- linkSpec->WriteToAppleEvent(ev, &theAppleEvent);
-
- // Add the source link to the Apple event
- error = AEPutParamPtr(&theAppleEvent, kODLinkSourceKey, typeLongInteger,
- &linkSource, sizeof(linkSource));
- THROW_IF_ERROR(error);
-
- error = AESend(&theAppleEvent, &replyAppleEvent, kAENoReply | kAENeverInteract,
- kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
- THROW_IF_ERROR(error);
- }
-
- SOM_CATCH_ALL
-
- ODSafeReleaseObject(linkSource);
- linkSource = kODNULL;
-
- SOM_ENDTRY
-
- return linkSource;
- }
-
- //------------------------------------------------------------------------------
- // GetLinkAEHandler
- //------------------------------------------------------------------------------
-
- ODStatic OSErr ODPascal GetLinkAEHandler(
- const AppleEvent* theAppleEvent,
- AppleEvent* reply,
- long refCon)
- {
- ODLinkManager* somSelf = (ODLinkManager*)refCon;
- Environment* ev = somGetGlobalEnvironment ();
- ODLinkSpec* linkSpec = (ODLinkSpec*) kODNULL; ODVolatile(linkSpec);
- OSErr error = noErr;
-
- #if ODDebug
- somPrintf("ODLinkManager: Get Link event received\n");
- #endif
-
- TRY
- linkSpec = new ODLinkSpec; // Can't use factory method; no draft object!
- THROW_IF_NULL(linkSpec, kODErrOutOfMemory);
- linkSpec->ReadFromAppleEvent(ev, (AppleEvent*) theAppleEvent);
-
- TempODByteArrayStruct aliasBA;
- somSelf->GetLink(ev, linkSpec, (ODByteArray*) aliasBA);
-
- error = AEPutParamPtr(reply, keyEditionAlias, typeAlias,
- aliasBA->_buffer, aliasBA->_length);
- CATCH_ALL
- // Must catch any exceptions thrown!
- error = ErrorCode();
- ENDTRY
-
- delete linkSpec;
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // GetLink
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerGetLink(ODLinkManager *somSelf, Environment *ev,
- ODLinkSpec* linkSpec,
- ODByteArray* aliasData)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","GetLink");
-
- SOM_TRY
-
- ODPart* part = linkSpec->GetPart(ev);
-
- // If document has never been saved, refuse to create a link
- DraftInfo* info = somSelf->GetDraftInfo(ev, part->GetStorageUnit(ev)->GetDraft(ev));
- THROW_IF_NULL(info, kODErrDocNotSaved);
-
- TempODLink link = kODNULL;
- TempODByteArrayStruct partData = linkSpec->GetPartData(ev);
- ODVolatile(partData);
-
- TempODLinkSource linkSource = kODNULL;
- ODVolatile(linkSource);
-
- linkSource = part->CreateLink(ev, (ODByteArray*) partData);
- THROW_IF_NULL(linkSource, kODErrCannotCreateLink);
- link = linkSource->GetLink(ev);
- THROW_IF_NULL(link, kODErrCannotCreateLink);
- link->Acquire(ev);
-
- ODLinkKey key; ODVolatile(key);
- if ( link->Lock(ev,0,&key) )
- {
- TRY
- if ( link->GetLinkEdition(ev, key, aliasData) )
- {
- // If a new cross-document destination is being created, and the edition
- // file is waiting for a save to update, force the edition file to update
- // now so the link content is the same as the content that would be pasted.
- // [cc; #1190727]
- DraftInfo* info = somSelf->GetDraftInfo(ev, link->GetStorageUnit(ev)->GetDraft(ev));
- if ( info && info->linksToExport->Contains(link) )
- {
- TRY
- link->UpdateLinkEdition(ev, key);
- info->linksToExport->RemoveAndRelease(link);
- CATCH_ALL
- ENDTRY
- }
- }
- else
- {
- ODDraft* draft = part->GetStorageUnit(ev)->GetDraft(ev);
- ODContainer* container = draft->GetDocument(ev)->GetContainer(ev);;
-
- TempPlatformFile documentFile = GetPlatformFileFromContainer(ev, container);
- ODFileSpec documentSpec = documentFile->GetFileSpec();
-
- EditionContainerSpec editionContainer = NewEditionFile(ev, documentFile, draft);
-
- link->CreateLinkEdition(ev,
- editionContainer,
- &documentSpec,
- somSelf->NewSectionID(ev, draft),
- key,
- aliasData);
-
- info->newExportedLinks->AddLastAndAcquire(link);
- }
- CATCH_ALL
- link->Unlock(ev, key);
- RERAISE;
- ENDTRY
- link->Unlock(ev, key);
- }
-
- SOM_CATCH_ALL
-
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // UseLinkEdition
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerUseLinkEdition(ODLinkManager *somSelf, Environment *ev,
- ODLinkSource* linkSource,
- ODByteArray* aliasData)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","UseLinkEdition");
-
- AliasHandle aliasHandle;
- EditionContainerSpec editionContainer;
- ODBoolean wasChanged;
- OSErr error;
-
- SOM_TRY
- error = PtrToHand(aliasData->_buffer, (Handle*) &aliasHandle, aliasData->_length);
- THROW_IF_ERROR(error);
- TempODHandle editionAlias((ODHandle) aliasHandle);
-
- error = ResolveAlias(nil, aliasHandle, &editionContainer.theFile, &wasChanged);
- THROW_IF_ERROR(error);
-
- editionContainer.theFileScript = smSystemScript;
- editionContainer.thePart = kPartsNotUsed;
-
- ODDraft* draft = linkSource->GetStorageUnit(ev)->GetDraft(ev);
-
- ODContainer* container = draft->GetDocument(ev)->GetContainer(ev);;
- ODFileSpec documentSpec = GetODFileSpecFromContainer(ev, container);
-
- ODLinkKey key; ODVolatile(key);
- if ( linkSource->Lock(ev,0,&key) )
- {
- TRY
- linkSource->UseLinkEdition(ev,
- editionContainer,
- &documentSpec,
- somSelf->NewSectionID(ev, draft),
- key);
- CATCH_ALL
- linkSource->Unlock(ev, key);
- RERAISE;
- ENDTRY
- linkSource->Unlock(ev, key);
- }
-
- SOM_CATCH_ALL
-
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // RequestLinkAEHandler
- //------------------------------------------------------------------------------
-
- ODStatic OSErr ODPascal RequestLinkAEHandler(
- const AppleEvent* requestLinkAppleEvent,
- AppleEvent* reply,
- long refCon)
- {
- ODLinkManager* somSelf = (ODLinkManager*) refCon;
- Environment* ev = somGetGlobalEnvironment();
- AppleEvent getLinkAppleEvent;
- AppleEvent replyAppleEvent;
- AEAddressDesc targetAddress;
- ProcessSerialNumber psn;
- DescType returnedType;
- Size actualSize;
- OSErr error;
- const long kGetLinkReplyTimeout = 600; // Ten seconds
-
- ODLinkSource* linkSource = kODNULL; ODVolatile(linkSource);
- ODLinkSpec* linkSpec = kODNULL; ODVolatile(linkSpec);
-
- TRY
-
- linkSpec = new ODLinkSpec; // Can't use factory method; no draft object!
- THROW_IF_NULL(linkSpec, kODErrOutOfMemory);
-
- linkSpec->ReadFromAppleEvent(ev, (AppleEvent*) requestLinkAppleEvent);
-
- error = AEGetParamPtr(requestLinkAppleEvent, kODLinkSourceKey,
- typeLongInteger, &returnedType,
- &linkSource, sizeof(linkSource), &actualSize);
- THROW_IF_ERROR(error);
-
- // Create the GetLink event
-
- linkSpec->GetOriginatingProcessID(ev, &psn);
-
- error = AECreateDesc(typeProcessSerialNumber, &psn,
- sizeof(ProcessSerialNumber), &targetAddress);
- THROW_IF_ERROR(error);
- TempAEDesc tmpTargetAddress(&targetAddress);
-
- error = AECreateAppleEvent(kODShellSignature, kODGetLinkEventID,
- &targetAddress, kAutoGenerateReturnID,
- kAnyTransactionID, &getLinkAppleEvent);
- THROW_IF_ERROR(error);
- TempAEDesc tmpGetLinkAppleEvent(&getLinkAppleEvent);
-
- linkSpec->WriteToAppleEvent(ev, &getLinkAppleEvent);
-
- error = AESend(&getLinkAppleEvent, &replyAppleEvent,
- kAEWaitReply | kAENeverInteract, kAENormalPriority,
- kGetLinkReplyTimeout, NULL, NULL);
- TempAEDesc tmpReplyAppleEvent(&replyAppleEvent);
- THROW_IF_ERROR(error);
-
- // Process the reply
-
- TempODByteArray aliasData = ODAEGetByteArray(&replyAppleEvent, keyEditionAlias, typeAlias);
- somSelf->UseLinkEdition(ev, linkSource, aliasData);
-
- CATCH_ALL
-
- if ( linkSource )
- {
- linkSource->SetStatus(ev, kODErrCannotEstablishLink);
-
- // Ignore errors returned by UpdateDependents
- TRY
- linkSource->GetLink(ev)->UpdateDependents(ev);
- CATCH_ALL
- ENDTRY
- }
-
- ENDTRY
-
- ODDeleteObject(linkSpec);
-
- return noErr;
- }
-
- //------------------------------------------------------------------------------
- // SectionReadAEHandler
- //------------------------------------------------------------------------------
-
- ODStatic OSErr ODPascal SectionReadAEHandler(
- const AppleEvent* theAppleEvent,
- const AppleEvent* reply,
- long refCon)
- {
- ODUnused(reply);
-
- ODLinkManager* somSelf = (ODLinkManager*)refCon;
- Environment* ev = somGetGlobalEnvironment ();
- SectionHandle section = kODNULL;
- OSErr error;
-
- error = GetSectionFromEvent(theAppleEvent, §ion);
-
- #if ODDebug
- somPrintf("ODLinkManager: Section Read event received; section = %x, linkSource = %x\n",
- section, (**section).refCon);
- #endif
-
- if ( error == noErr )
- {
- if ( IsRegisteredSection(section) == noErr )
- {
- ODLinkSource* linkSource = (ODLinkSource*) (*section)->refCon;
- ODLinkKey key;
-
- if ( linkSource->Lock(ev,0,&key) )
- {
- TRY
- linkSource->ReadLinkEdition(ev,key);
- DraftInfo* info = somSelf->GetDraftInfo(ev, linkSource->GetStorageUnit(ev)->GetDraft(ev));
- if ( info != (DraftInfo*) kODNULL )
- {
- info->linksImported = kODTrue;
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
- linkSource->Unlock(ev, key);
- }
- }
- }
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SectionWriteAEHandler
- //------------------------------------------------------------------------------
-
- ODStatic OSErr ODPascal SectionWriteAEHandler(
- const AppleEvent* theAppleEvent,
- const AppleEvent* reply,
- long refCon)
- {
- ODUnused(reply);
-
- ODLinkManager* somSelf = (ODLinkManager*)refCon;
- Environment* ev = somGetGlobalEnvironment ();
- ODLinkKey key;
- SectionHandle section = kODNULL;
- OSErr error;
-
- error = GetSectionFromEvent(theAppleEvent, §ion);
-
- #if ODDebug
- somPrintf("ODLinkManager: Section Write event received; section = %x, link = %x\n",
- section, (**section).refCon);
- #endif
-
- if ( error == noErr )
- {
- if ( IsRegisteredSection(section) == noErr )
- {
- ODLink* link = (ODLink*) (**section).refCon;
-
- // Force ExportLinkEdition to write the edition file
- (**section).mdDate = (TimeStamp) 0;
-
- if ( link->Lock(ev,0,&key) )
- {
- TRY
- link->UpdateLinkEdition(ev, key);
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
- link->Unlock(ev, key);
- }
- }
- }
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // BuildErrorString
- //------------------------------------------------------------------------------
-
- ODStatic StringPtr BuildErrorString(ODSShort strResourceID, ODError error)
- {
- Str63 numberString;
- Str255 msgStr;
-
- StringPtr result = kODNULL;
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- NumToString(error, numberString);
- ReplaceIntoString(strResourceID, numberString, kODNULL, msgStr);
-
- if ( msgStr[0] > 0 )
- {
- ODULong ptrSize = msgStr[0]+1;
- result = (StringPtr) ODNewPtr(ptrSize);
- if ( result )
- ODBlockMove((ODPtr) &msgStr, (ODPtr) result, ptrSize);
- }
-
- EndUsingLibraryResources(savedRefNum);
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // SectionScrollAEHandler
- //------------------------------------------------------------------------------
-
- ODStatic OSErr ODPascal SectionScrollAEHandler(
- const AppleEvent* theAppleEvent,
- const AppleEvent* reply,
- long refCon)
- {
- ODUnused(reply);
-
- ODLinkManager* somSelf = (ODLinkManager*)refCon;
- ODLinkManagerData* somThis = ODLinkManagerGetData(somSelf);
- Environment* ev = somGetGlobalEnvironment ();
- SectionHandle section = kODNULL;
- OSErr error;
-
- error = GetSectionFromEvent(theAppleEvent, §ion);
-
- #if ODDebug
- somPrintf("ODLinkManager: Section Scroll event received; section = %x, link = %x\n",
- section, (section ? (**section).refCon : 0));
- #endif
-
- if ( error == noErr )
- {
- if ( IsRegisteredSection(section) == noErr )
- {
- TRY
- ODLink* link = (ODLink*) (**section).refCon;
-
- if ( link != kODNULL )
- {
- DraftInfo* info = somSelf->GetDraftInfo(ev, link->GetStorageUnit(ev)->GetDraft(ev));
- if ( info && info->linksToDelete && info->linksToDelete->Contains(link) )
- THROW(kODErrCannotRevealLink);
- else
- link->ShowSourceContent(ev);
- }
- CATCH_ALL
- error = ErrorCode();
-
- NMRemove(_fNMRecPtr); // ensure not already queued
- _fNMRecPtr->qType = nmType;
- _fNMRecPtr->nmMark = 0;
- _fNMRecPtr->nmIcon = nil;
- _fNMRecPtr->nmSound = nil;
- ODDisposePtr((ODPtr) _fNMRecPtr->nmStr);
- _fNMRecPtr->nmStr = BuildErrorString(kODLinkMgrCannotShowSourceID, error);
- _fNMRecPtr->nmResp = _fNMResponseUPP;
- error = NMInstall(_fNMRecPtr);
- ENDTRY
- }
- }
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // NewEditionFile
- //------------------------------------------------------------------------------
-
- ODStatic EditionContainerSpec NewEditionFile(Environment* ev,
- PlatformFile* documentFile,
- ODDraft* draft)
- {
- EditionContainerSpec editionContainer;
- OSErr error;
- Str255 documentName;
- ODFileSpec documentSpec = documentFile->GetFileSpec();
-
- do {
- documentFile->GetAsciiName((char *) documentName, 254);
- CToPascalString((char *) documentName);
- EditionFileName(documentName, (ODUShort) NewEditionID(ev, draft));
- error = FSMakeFSSpec(documentSpec.vRefNum,
- documentSpec.parID,
- documentName,
- &(editionContainer.theFile));
- }
- while (error == noErr);
-
- // Expect a file not found error
- if ( error != fnfErr )
- THROW_IF_ERROR(error);
-
- editionContainer.theFileScript = smSystemScript;
- editionContainer.thePart = kPartsNotUsed;
-
- return editionContainer;
- }
-
- //------------------------------------------------------------------------------
- // GetSectionFromEvent
- //------------------------------------------------------------------------------
-
- ODStatic OSErr GetSectionFromEvent(const AppleEvent* theAppleEvent,
- SectionHandle* section)
- {
- DescType returnedType;
- Size actualSize;
- OSErr error;
-
- error = AEGetParamPtr(theAppleEvent, keyDirectObject, typeSectionH, &returnedType,
- section, sizeof(*section), &actualSize);
- #if ODDebug
- if ( error != noErr )
- somPrintf("ODLinkManager: Error %d getting section from event\n", error);
- #endif
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // EditionFileName
- //------------------------------------------------------------------------------
-
- ODStatic void EditionFileName(Str255 fileName, ODUShort numb)
- {
- Str63 numberString;
-
- NumToString(numb, numberString);
-
- TruncateFileName(fileName, numberString);
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- ReplaceIntoString(kODLinkMgrEditionTemplateID, fileName, numberString, fileName);
-
- EndUsingLibraryResources(savedRefNum);
- }
-
- //------------------------------------------------------------------------------
- // TruncateFileName
- //------------------------------------------------------------------------------
-
- ODStatic void TruncateFileName(Str255 fileName, Str63 numberString)
- {
- const maxFileNameLength = 31;
-
- Str255 emptyString;
- emptyString[0] = (unsigned char) 0;
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- ReplaceIntoString(kODLinkMgrEditionTemplateID, emptyString, numberString, emptyString);
-
- EndUsingLibraryResources(savedRefNum);
-
- if ( (StrLength(fileName)+StrLength(emptyString)) > maxFileNameLength )
- ClipStringToBytes( fileName,
- maxFileNameLength-StrLength(emptyString), smCurrentScript );
- }
-
- //------------------------------------------------------------------------------
- // NewEditionID
- //------------------------------------------------------------------------------
-
- ODStatic ODULong NewEditionID(Environment *ev, ODDraft* draft)
- {
- return ReserveGlobalID(ev, draft, kODPropEditionID);
- }
-
- //------------------------------------------------------------------------------
- // PeekNextGlobalID
- //------------------------------------------------------------------------------
-
- ODStatic ODULong PeekNextGlobalID(Environment *ev,
- ODDraft* draft,
- ODPropertyName globalProp)
- {
- TempODStorageUnit draftPropertiesSU = draft->AcquireDraftProperties(ev);
- ODULong id = 0;
-
- if ( ODSUExistsThenFocus(ev, draftPropertiesSU, globalProp, kODULong) )
- StorageUnitGetValue(draftPropertiesSU, ev, sizeof(ODULong), (ODValue) &id);
-
- return ++id;
- }
-
- //------------------------------------------------------------------------------
- // ReserveGlobalID
- //------------------------------------------------------------------------------
-
- ODStatic ODULong ReserveGlobalID(Environment *ev,
- ODDraft* draft,
- ODPropertyName globalProp)
- {
- TempODStorageUnit draftPropertiesSU = draft->AcquireDraftProperties(ev);
- ODULong id = 0;
-
- ODSUForceFocus(ev, draftPropertiesSU, globalProp, kODULong);
- if ( draftPropertiesSU->GetSize(ev) > 0 )
- id = ODGetULongProp(ev, draftPropertiesSU, globalProp, kODULong);
- ++id;
- ODSetULongProp(ev, draftPropertiesSU, globalProp, kODULong, id);
-
- return id;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::NewDraftInfo
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagerNewDraftInfo(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","NewDraftInfo");
-
- SOM_TRY
-
- // Create a new info structure for this draft
- DraftInfo* info = new DraftInfo;
-
- info->draft = draft;
- info->linksToExport = new ODRefCntCollection(ev);
- info->linksToDelete = new ODRefCntCollection(ev);
- info->newExportedLinks = new ODRefCntCollection(ev);
- info->linksImported = kODFalse;
- _fDraftInfos->AddLast(info);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::GetDraftInfo
- //------------------------------------------------------------------------------
-
- SOM_Scope DraftInfo* SOMLINK ODLinkManagerGetDraftInfo(ODLinkManager *somSelf, Environment *ev,
- ODDraft* draft)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","GetDraftInfo");
-
- OrderedCollectionIterator* iter = kODNULL; ODVolatile(iter);
-
- DraftInfo* result = (DraftInfo*) kODNULL;
-
- if ( draft && _fDraftInfos )
- {
- TRY
- iter = _fDraftInfos->CreateIterator();
-
- for (DraftInfo* info = (DraftInfo*) iter->First();
- iter->IsNotComplete();
- info = (DraftInfo*) iter->Next() )
- {
- if ( info && draft->IsEqualTo(ev, info->draft) )
- {
- result = info;
- break;
- }
- }
- CATCH_ALL
- ENDTRY
-
- ODDeleteObject(iter);
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::DeleteDraftInfos
- //------------------------------------------------------------------------------
-
- // SOM_Scope void SOMLINK ODLinkManagerDeleteDraftInfos(ODLinkManager *somSelf, Environment *ev)
- // {
- // ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- // ODLinkManagerMethodDebug("ODLinkManager","DeleteDraftInfos");
- //
- // SOM_CATCH return;
- //
- // if (_fDraftInfos != (OrderedCollection*) kODNULL)
- // {
- // DraftInfo* info;
- // while ((info = (DraftInfo*) _fDraftInfos->First()) != (DraftInfo*) kODNULL)
- // {
- // ODDeleteObject(info->linksToExport);
- // ODDeleteObject(info->linksToDelete);
- // ODDeleteObject(info->newExportedLinks);
- // _fDraftInfos->RemoveFirst();
- // delete info;
- // }
- // ODDeleteObject(_fDraftInfos);
- // }
- // }
-
- //------------------------------------------------------------------------------
- // ODLinkManager::somUninit
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkManagersomUninit(ODLinkManager *somSelf)
- {
- ODLinkManagerData *somThis = ODLinkManagerGetData(somSelf);
- ODLinkManagerMethodDebug("ODLinkManager","somUninit");
-
- AEEventHandlerUPP toBeDisposedUPP;
- long toBeIgnoredRefCon;
- OSErr error;
-
- // somSelf->DeleteDraftInfos(ev);
- // It is incorrect to call methods on somSelf inside somUninit,
- // a subclass may have already been somUninited. See OpenDoc Building Code for details.
- // Instead the implementation of DeleteDraftInfos has been copied here.
-
- // BEGIN copy of DeleteDraftInfos implementation
- if (_fDraftInfos != (OrderedCollection*) kODNULL )
- {
- Environment* ev = somGetGlobalEnvironment();
- DraftInfo* info;
- while ((info = (DraftInfo*) _fDraftInfos->First()) != (DraftInfo*) kODNULL)
- {
- ODDeleteObject(info->linksToExport);
- ODDeleteObject(info->linksToDelete);
- ODDeleteObject(info->newExportedLinks);
- _fDraftInfos->RemoveFirst();
- delete info;
- }
- ODDeleteObject(_fDraftInfos);
- }
- // END copy of DeleteDraftInfos implementation
-
- if ( _fSuspendedUpdateLinks != (ODRefCntCollection*) kODNULL )
- {
- // _fSuspendedUpdateLinks->RemoveAndReleaseAll();
- ODDeleteObject(_fSuspendedUpdateLinks);
- }
-
- error = AEGetEventHandler(kODShellSignature, kODGetLinkEventID,
- &toBeDisposedUPP, &toBeIgnoredRefCon, kNotSysHandler);
- if ( error == noErr )
- {
- DisposeRoutineDescriptor(toBeDisposedUPP);
- error = AERemoveEventHandler(kODShellSignature, kODGetLinkEventID,
- kODNULL, // a UPP wouldn't work: it might not be ==
- kNotSysHandler);
- }
-
- error = AEGetEventHandler(kODShellSignature, kODRequestLinkEventID,
- &toBeDisposedUPP, &toBeIgnoredRefCon, kNotSysHandler);
- if ( error == noErr )
- {
- DisposeRoutineDescriptor(toBeDisposedUPP);
- error = AERemoveEventHandler(kODShellSignature, kODRequestLinkEventID,
- kODNULL, // a UPP wouldn't work: it might not be ==
- kNotSysHandler);
- }
-
- error = AEGetEventHandler(sectionEventMsgClass, sectionReadMsgID,
- &toBeDisposedUPP, &toBeIgnoredRefCon, kNotSysHandler);
- if ( error == noErr )
- {
- DisposeRoutineDescriptor(toBeDisposedUPP);
- error = AERemoveEventHandler(sectionEventMsgClass, sectionReadMsgID,
- kODNULL,
- kNotSysHandler);
- }
-
- error = AEGetEventHandler(sectionEventMsgClass, sectionWriteMsgID,
- &toBeDisposedUPP, &toBeIgnoredRefCon, kNotSysHandler);
- if ( error == noErr )
- {
- DisposeRoutineDescriptor(toBeDisposedUPP) ;
- error = AERemoveEventHandler(sectionEventMsgClass, sectionWriteMsgID,
- kODNULL,
- kNotSysHandler);
- }
-
- error = AEGetEventHandler(sectionEventMsgClass, sectionScrollMsgID,
- &toBeDisposedUPP, &toBeIgnoredRefCon, kNotSysHandler);
- if ( error == noErr )
- {
- DisposeRoutineDescriptor(toBeDisposedUPP) ;
- error = AERemoveEventHandler(sectionEventMsgClass, sectionScrollMsgID,
- kODNULL,
- kNotSysHandler);
- }
-
- if ( _fNMResponseUPP != kODNULL )
- DisposeRoutineDescriptor(_fNMResponseUPP);
-
- if ( _fNMRecPtr )
- ODDisposePtr((ODPtr) _fNMRecPtr->nmStr);
- ODDisposePtr(_fNMRecPtr);
-
- parent_somUninit(somSelf);
- }
-
- //------------------------------------------------------------------------------
- // RegisterSubscribingLinks
- //------------------------------------------------------------------------------
-
- ODStatic void RegisterSubscribingLinks(Environment *ev, ODDraft* draft)
- {
- // Internalize all link source objects; each link subscribing to an edition
- // file will register with the edition manager.
-
- ODLinkSourceIterator* iter;
-
- iter = draft->CreateLinkSourceIterator(ev);
-
- TRY{
- for (ODLinkSource* linkSource = iter->First(ev);
- iter->IsNotComplete(ev);
- linkSource = iter->Next(ev) )
- {
- linkSource->Release(ev);
- }
- }CATCH_ALL{
- }ENDTRY
-
- delete iter;
- }
-
- //------------------------------------------------------------------------------
- // RegisterPublishingLinks
- //------------------------------------------------------------------------------
- ODStatic void RegisterPublishingLinks(Environment *ev, ODDraft* draft)
- {
- // Internalize all link objects; each link publishing an edition file will
- // register with the edition manager.
-
- ODLinkIterator* iter;
-
- iter = draft->CreateLinkIterator(ev);
-
- TRY{
- for (ODLink* link = iter->First(ev);
- iter->IsNotComplete(ev);
- link = iter->Next(ev) )
- {
- link->Release(ev);
- }
- }CATCH_ALL{
- }ENDTRY
-
- delete iter;
- }
-
- //------------------------------------------------------------------------------
- // UpdateEditionFiles
- //------------------------------------------------------------------------------
-
- ODStatic void UpdateEditionFiles(Environment *ev, ODRefCntCollection* collection)
- {
- if ( collection != kODNULL )
- {
- ODRefCntCollectionIterator iter(collection);
- ODLinkKey key;
-
- for (ODLink* link = (ODLink*) iter.First();
- iter.IsNotComplete();
- link = (ODLink*) iter.Next() )
- {
- if ( link->Lock(ev,0,&key) )
- {
- TRY
- link->UpdateLinkEdition(ev, key);
- CATCH_ALL
- ENDTRY
- link->Unlock(ev, key);
- }
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // DeleteEditionFiles
- //------------------------------------------------------------------------------
-
- ODStatic void DeleteEditionFiles(Environment *ev, ODRefCntCollection* collection)
- {
- if ( collection != kODNULL )
- {
- ODRefCntCollectionIterator iter(collection);
- ODLinkKey key;
-
- for (ODLink* link = (ODLink*) iter.First();
- iter.IsNotComplete();
- link = (ODLink*) iter.Next() )
- {
- if ( link->Lock(ev,0,&key) )
- {
- TRY
- link->DeleteLinkEdition(ev, key);
- CATCH_ALL
- ENDTRY
- link->Unlock(ev, key);
- }
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // RemoveAllLinksInCollection
- //------------------------------------------------------------------------------
-
- // ODStatic void RemoveAllLinksInCollection(Environment *ev, ODRefCntCollection* collection)
- // // collection must contain only ODLink subclass instances
- // {
- // if ( collection != kODNULL )
- // {
- // ODRefCntCollectionIterator iter(collection);
- //
- // TRY
- // for (ODLink* link = (ODLink*) iter->First();
- // iter->IsNotComplete();
- // link = (ODLink*) iter->Next() )
- // {
- // ODReleaseObject(ev, link);
- // }
- // CATCH_ALL
- // ENDTRY
- //
- // collection->RemoveAll();
- // }
- // }
-
- //------------------------------------------------------------------------------
- // AppendULongToDraftProperty
- //------------------------------------------------------------------------------
-
- ODStatic void AppendULongToDraftProperty(Environment *ev,
- ODDraft* draft, ODPropertyName prop, ODULong value)
- {
- TempODStorageUnit draftProperties = draft->AcquireDraftProperties(ev);
- ODSUForceFocus(ev, draftProperties, prop, kODULongSequence);
- draftProperties->SetOffset(ev, draftProperties->GetSize(ev));
- ODSetULongProp(ev, draftProperties, kODNULL, kODNULL, value);
-
- draft->SetChangedFromPrev(ev);
- }
-
- //------------------------------------------------------------------------------
- // SectionIDReserved
- //------------------------------------------------------------------------------
-
- ODStatic ODBoolean SectionIDReserved(Environment *ev,
- ODDraft* draft, ODULong requestedID)
- {
- ODBoolean result = kODFalse;
-
- TempODStorageUnit draftProperties = draft->AcquireDraftProperties(ev);
-
- if ( ODSUExistsThenFocus(ev, draftProperties, kODPropReservedSectionIDs, kODULongSequence) )
- {
- ODULong size = draftProperties->GetSize(ev);
- while ( draftProperties->GetOffset(ev) < size )
- {
- if ( ODGetULongProp(ev, draftProperties, kODNULL, kODNULL) == requestedID )
- {
- result = kODTrue;
- break;
- }
- }
- }
-
- return result;
- }
-