home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DragPriv.cpp
-
- Contains: Implementation of Private classes for ODDragAndDrop.
-
- Owned by: Vincent Lo
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <10> 7/18/96 DH #136990:Drags don't contain all types. Now
- correctly counts drag item flavors.
- <9> 7/11/96 DH 1365986 1.1GM: Crash when drag fails and
- another drag is attempted. Fixed many stale
- object references.
- <8> 6/21/96 DH 1353507: 1.0.x: Dragging Scrapbook OpenDoc
- clipping to document can cause crash.
- <6> 5/23/96 DH 1344338: Force quit of document when
- dragging 'Bad' file or Container. Turned
- off fatal Bento errors for Open and Create
- container operations.
- <5> 5/15/96 DH Removed bogus include so that will build
- will not be broken!
- <4> 5/13/96 DH 1305572 - 1.1MRD:[Cyberdog]Dragging
- multiple items *really* slow.
- 1314704 - 1.0.x: Enourmous performance hit
- when dragging numb erous items over
- windows.
- <3> 5/1/96 JA 1314704: Allow ODMemDragItem to use
- pre-existing container.
- <2> 3/15/96 DH 1287259 - 1.0.2 Don't get back what I put
- in the scrapbook. Changed ODMemContainer so
- that it has a constructor that makes a new
- container given a container handle.
- <27> 10/13/95 EL 1287340: Use standard ISO prefix
- <26> 10/4/95 jpa Added missing ODVolatiles [1285799]
- <25> 10/4/95 VL 1287585: Check to see whether we are
- dragging a folder before getting the file
- info.
- <24> 9/13/95 VL 1283523: Stop copying names for stationery
- files.
- <23> 9/8/95 VL 1274572: Preserved the curResFile in
- GetIconFamilyFromFile.
- <22> 9/8/95 TÇ 1281096 FB2:Many constants in ODTypesB
- without kOD prefix!
- <21> 9/6/95 VL 1274572: Added GetFinderInfo and
- GetIconFamilyFromFile.
- <20> 8/12/95 TÇ 1276812 Need to use TempObjs and TempRefs
- for exception safety and to avoid TRY
- blocks, 1276807 Opt./Bug: use StdTypIO
- routines for portable streaming & smaller
- footprint
- <19> 7/26/95 VL 1270320: ClearAllPromises when deleting
- memory container.
- <18> 5/26/95 VL 1251403: Multithreading naming support.
- <17> 5/25/95 jpa Fixed usage of ODDebug. [1253321]
- <16> 4/25/95 VL 1240737: Make sure that ID for file
- container is set to the right _length.
- <15> 4/15/95 VL 1240014: turned off debug statements.
- <14> 4/14/95 VL Temporarily turned on debug printf.
- <13> 3/10/95 VL 1227218: Get rid of system heap.
- <12> 2/27/95 VL 1198037: Removed debugstr from code.
- <11> 2/10/95 VL 1205627: Used kODBentoUpdateContainer.
- <10> 1/26/95 VL #???: Use updated Storage Unit Ref API.
- <9> 1/19/95 CC 1212419 Pass kODBentoMemoryContainer to
- CreateMemoryContainer & GetMemoryContainer.
- <8> 12/20/94 VL 1195012: Make Storage calls be
- marshallable.
- <7> 12/13/94 VL 1203627,1200603,1203451,1198037,1194537,119
- 4755,1186815: Bug fixes.
- <6> 9/23/94 VL 1184272: ContainerID is now a sequence of
- octets.
- <5> 8/26/94 VL 1183174: Use updated cloning APIs
- (specifically GetStorageUnitRef takes ID
- now).
- <4> 8/15/94 TÇ #1180922 Removed most obsolete types from
- StdTypes.idl
- <3> 8/3/94 VL 1153123: Storage to ODStor.
- <2> 7/26/94 VL Got rid of dependency on Bento.
- <1> 7/21/94 VL first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _DRAGPRIV_
- #include <DragPriv.h>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <ODDraft.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #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
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _ICONS_
- #include <Icons.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef __FINDER__
- #include <Finder.h>
- #endif
-
- #ifndef _CONSTDEF_
- #include "ConstDef.h"
- #endif
-
- //#ifndef _BENTOSUPPRESS_
- //#include <BentoSuppress.h>
- //#endif
-
- #if ODDebug
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
- #endif
-
- #if ODDebug
- // #define ODDebug_DragPriv 1
- #endif
-
- const ODContainerType kODBentoUpdateContainer = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Bento Container Suite:ContainerType:Update";
-
- //==============================================================================
- // Function Prototype
- //==============================================================================
-
- ODContainerType GetContainerSuiteType(FSSpec* fsSpec);
-
- //==============================================================================
- // ODDragItem
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODDragItem::ODDragItem
- //------------------------------------------------------------------------------
- ODDragItem::ODDragItem(ODStorageSystem *storage, ODBoolean IsForeignDataSU,
- ODPlatformDragReference currentDrag,
- ItemReference theDragItemRefNumber,
- HFSFlavor* hfsFlavor)
- {
- fStorageSystem = storage;
- fCurrentDragItemRefNumber = theDragItemRefNumber;
- fCurrentDrag = currentDrag;
- fHFSFlavorPtr = hfsFlavor;
-
- fContainer = kODNULL;
- fDocument = kODNULL;
- fDraft = kODNULL;
- fSU = kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // ODDragItem::Open
- //------------------------------------------------------------------------------
- void ODDragItem::Open(Environment* ev)
- {
- WARN("ODDragItem::Open should not be called.");
- }
-
-
- //------------------------------------------------------------------------------
- // ODDragItem::Close
- //------------------------------------------------------------------------------
- void ODDragItem::Close(Environment* ev)
- {
- WARN("ODDragItem::Open should not be called.");
- }
-
- //------------------------------------------------------------------------------
- // ODDragItem::AddFinderInfoToSU
- //------------------------------------------------------------------------------
- void ODDragItem::AddFinderInfoToSU( Environment* ev )
- {
- // Integrating code from EnterHandler to now generate Finder Info here.
-
- // If the drag item was an HFS flavor, then write out the Finder info here
- // so that a part could mimic the Finder and have all of the Finder
- // info available to it. Otherwise, parts have not have enough info
- // to deal with Finder files.
-
- TRY
- if ( fHFSFlavorPtr != kODNULL )
- {
- TempPlatformFile finderFile = new PlatformFile;
- // finderFile = new PlatformFile();
- finderFile->Specify(&(fHFSFlavorPtr->fileSpec));
-
- GetFinderInfo(ev, fSU, finderFile);
- GetIconFamilyFromFile(ev, fSU, finderFile);
- }
- CATCH_ALL
- // If the drag item is not a finder file, like from the Scrapbook,
- // then we don't have anything to add. Therefor, don't reraise if there
- // are exceptions.
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODDragItem::AddMacOSTypeInfoToSU
- //------------------------------------------------------------------------------
- void ODDragItem::AddMacOSTypeInfoToSU( Environment* ev )
- {
- // Now add old-style MacOS kinds to the SU, if kinds were dragged from a non-OpenDoc
- // process. Otherwise, don't need to do anything.
-
- if( fCurrentDrag != 0 )
- {
- // Go through all of the flavors in the drag item, and add an ISO kind to the
- // storage unit. These will constitute the multiple kinds that a drag
- // might have. For example, if an app wrote out TEXT and STYL kinds, we want
- // those both to be available to a part in the data transfer SU.
- ODUShort numDragFlavors = 0;
- ODTranslation* translation = fStorageSystem->GetSession(ev)->GetTranslation(ev);
- CountDragItemFlavors(fCurrentDrag, fCurrentDragItemRefNumber, &numDragFlavors);
-
- for ( ODUShort dragFlavorIndex = 1; dragFlavorIndex <= numDragFlavors; dragFlavorIndex++)
- {
- OSType theType;
- OSErr err = GetFlavorType(fCurrentDrag, fCurrentDragItemRefNumber, dragFlavorIndex, &theType);
- TempODValueType isoType = kODNULL;
- isoType = translation->GetISOTypeFromPlatformType(ev, theType, kODPlatformDataType);
- fSU->Focus(ev, kODPropContents, kODPosUndefined, kODNULL,
- 0, kODPosUndefined);
- StorageUnitSetPromiseValue(fSU, ev, isoType, 0,
- sizeof(ItemReference), &fCurrentDragItemRefNumber, kODNULL);
- // ODDisposePtr(isoType); // No longer needed because it is now temp.
- // If theType is 'styl', add a promise for 'stxt'
- if ( theType == kODScrapTypestyl )
- {
- if ( DragItemHasFlavor(fCurrentDrag, fCurrentDragItemRefNumber, kODScrapTypeTEXT) &&
- !DragItemHasFlavor(fCurrentDrag, fCurrentDragItemRefNumber, kODScrapTypestxt) )
- StorageUnitSetPromiseValue(fSU, ev, kODApplestxt, 0,
- sizeof(ItemReference), &fCurrentDragItemRefNumber, kODNULL);
- }
- else if (theType == flavorTypeHFS)
- {
- TempODValueType isoType = translation->GetISOTypeFromPlatformType(ev,
- fHFSFlavorPtr->fileType, kODPlatformFileType);
- fSU->AddValue(ev, isoType);
- // ODDisposePtr(isoType); // No longer needed because it is now temp.
- }
- }
- }
- }
-
- //==============================================================================
- // ODMemDragItem
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODMemDragItem::~ODMemDragItem
- //------------------------------------------------------------------------------
-
- ODMemDragItem::~ODMemDragItem()
- {
- Environment* ev = somGetGlobalEnvironment();
-
- if (fSU != kODNULL)
- {
- fSU->ClearAllPromises(ev);
- ODSafeReleaseObject( fSU );
- }
- ODSafeReleaseObject( fDraft );
- ODSafeReleaseObject( fDocument );
- ODSafeReleaseObject( fContainer);
- if( fContainerHandle != kODNULL)
- ODDisposeHandle(fContainerHandle);
- }
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::Initialize
- //------------------------------------------------------------------------------
- void ODMemDragItem::Initialize(Environment* ev)
- {
- ODDragItem::Initialize(ev);
-
- // Need to do this acquire so we will have the same number of releases
- // whether the DragItem is used or not.
- if( fDraft != kODNULL )
- fDraft->Acquire(ev);
- }
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::Open
- //------------------------------------------------------------------------------
- void ODMemDragItem::Open(Environment* ev)
- {
- if( fContainerHandle )
- {
- TRY
- fContainer = GetMemoryContainer(ev, fStorageSystem->GetSession(ev),
- fContainerHandle, kODBentoMemoryContainer);
- fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);
- fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
- TempODStorageUnit draftProperties = fDraft->AcquireDraftProperties(ev);
- fSU = fDraft->AcquireStorageUnit(ev, ODGetStrongSURefProp(ev, draftProperties,
- kODPropRootPartSU, kODStrongStorageUnitRef));
- CATCH_ALL
- if (fSU != kODNULL)
- {
- ODSafeReleaseObject( fSU );
- fSU = kODNULL;
- }
- if (fDraft != kODNULL)
- {
- ODSafeReleaseObject( fDraft );
- fDraft = kODNULL;
- }
- if (fDocument != kODNULL)
- {
- ODSafeReleaseObject( fDocument );
- fDocument = kODNULL;
- }
- if (fContainer != kODNULL)
- {
- ODSafeReleaseObject( fContainer );
- fContainer = kODNULL;
- }
- if( fContainerHandle != kODNULL)
- ODDisposeHandle(fContainerHandle);
- RERAISE;
- ENDTRY
- }
- else if( fDraft )
- {
- fSU = fDraft->CreateStorageUnit(ev);
- }
- }
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::Close
- //------------------------------------------------------------------------------
- void ODMemDragItem::Close(Environment* ev)
- {
- ODSafeReleaseObject( fSU );
- if (fDraft != kODNULL) {
- fDraft->Externalize(ev);
- ODSafeReleaseObject( fDraft );
- }
- ODSafeReleaseObject( fDocument );
- ODSafeReleaseObject( fContainer );
- }
-
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::GetStorageUnit
- //------------------------------------------------------------------------------
- ODStorageUnit* ODMemDragItem::GetStorageUnit(Environment* ev)
- {
- if( fSU == kODNULL )
- {
- TRY
- Open( ev );
-
- AddFinderInfoToSU(ev);
- AddMacOSTypeInfoToSU(ev);
- CATCH_ALL
- #ifdef ODDebug_DragPriv
- ODError err = ErrorCode();
- WARN("Error in ODFileDragItem::Initialize");
- char errString[100];
- numtostring(err, errString);
- WARN(errString);
- #endif
- if (fSU != kODNULL)
- {
- ODSafeReleaseObject( fSU );
- fSU = kODNULL;
- }
- if (fDraft != kODNULL)
- {
- ODSafeReleaseObject( fDraft );
- fDraft = kODNULL;
- }
- if (fDocument != kODNULL)
- {
- ODSafeReleaseObject( fDocument );
- fDocument = kODNULL;
- }
- if (fContainer != kODNULL)
- {
- ODSafeReleaseObject( fContainer );
- fContainer = kODNULL;
- }
- RERAISE;
- ENDTRY
- }
- return fSU;
- }
-
- //==============================================================================
- // ODFileDragItem
- //==============================================================================
-
-
- //------------------------------------------------------------------------------
- // ODFileDragItem::~ODFileDragItem
- //------------------------------------------------------------------------------
- ODFileDragItem::~ODFileDragItem()
- {
- #if ODDebug_DragPriv
- somPrintf("~ODFileDragItem: %x %x %x %x\n", fSU, fDraft, fDocument, fContainer);
- #endif
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODSafeReleaseObject( fSU );
- ODSafeReleaseObject( fDraft );
- ODSafeReleaseObject( fDocument );
- ODSafeReleaseObject( fContainer );
- if (fContainerID)
- DisposeByteArray(fContainerID);
- }
-
- //------------------------------------------------------------------------------
- // ODFileDragItem::Initialize
- //------------------------------------------------------------------------------
- void ODFileDragItem::Initialize(Environment* ev, ODContainerID* containerID )
- {
- ODDragItem::Initialize(ev);
- fContainerID = CopyByteArray(containerID);
- }
-
- //------------------------------------------------------------------------------
- // ODFileDragItem::GetStorageUnit
- //------------------------------------------------------------------------------
- ODStorageUnit* ODFileDragItem::GetStorageUnit(Environment* ev)
- {
- if (fSU == kODNULL)
- {
- ODStorageUnitID suid;
- ODContainerType containerType = kODNULL; ODVolatile(containerType);
-
- TRY
- containerType = GetContainerSuiteType((FSSpec*) fContainerID->_buffer);
- fContainerID->_length = sizeof(short) + sizeof(long) + ((FSSpec*) fContainerID->_buffer)->name[0] + 1;
- fContainer = fStorageSystem->CreateContainer(ev, containerType, fContainerID);
- fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);
- fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
- TempODStorageUnit draftProperties = fDraft->AcquireDraftProperties(ev);
- suid = ODGetStrongSURefProp(ev, draftProperties, kODPropRootPartSU, kODStrongStorageUnitRef);
- fSU = fDraft->AcquireStorageUnit(ev, suid);
-
- AddFinderInfoToSU(ev);
- AddMacOSTypeInfoToSU(ev);
-
- ODDisposePtr(containerType);
-
- #if ODDebug_DragPriv
- somPrintf("ODFileDragItem::Initialize %x %x %x %x\n", fSU, fDraft, fDocument, fContainer);
- #endif
-
- CATCH_ALL
- #ifdef ODDebug_DragPriv
- ODError err = ErrorCode();
- WARN("Error in ODFileDragItem::Initialize");
- char errString[100];
- numtostring(err, errString);
- WARN(errString);
- #endif
- if (fSU != kODNULL)
- {
- ODSafeReleaseObject( fSU );
- fSU = kODNULL;
- }
- if (fDraft != kODNULL)
- {
- ODSafeReleaseObject( fDraft );
- fDraft = kODNULL;
- }
- if (fDocument != kODNULL)
- {
- ODSafeReleaseObject( fDocument );
- fDocument = kODNULL;
- }
- if (fContainer != kODNULL)
- {
- ODSafeReleaseObject( fContainer );
- fContainer = kODNULL;
- }
- if( containerType )
- ODDisposePtr(containerType);
- RERAISE;
- ENDTRY
- }
- return fSU;
- }
-
- //==============================================================================
- // ODDragLink
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODDragLink::ODDragLink
- //------------------------------------------------------------------------------
- ODDragLink::ODDragLink(ODDragItem *theItem, ODBoolean cleanup)
- {
- fItem = theItem;
- fCleanup = cleanup;
- }
-
- //------------------------------------------------------------------------------
- // ODDragLink::~ODDragLink
- //------------------------------------------------------------------------------
- ODDragLink::~ODDragLink()
- {
- if (fCleanup)
- delete fItem;
- }
-
- //------------------------------------------------------------------------------
- // GetContainerSuiteType
- //------------------------------------------------------------------------------
-
- ODContainerType GetContainerSuiteType(FSSpec* fsSpec)
- {
- #if USE_GETCONTAINER_SUITE_TYPE
- PlatformFile file;
- file.Specify(fsSpec);
-
- ODContainerType containerType = file.AcquireContainerType();
- if (ODISOStrEqual(containerType, kODBentoFileContainer) ||
- ODISOStrEqual(containerType, "")) {
- containerType = kODBentoUpdateContainer;
- }
- #else
- ODULong len = strlen(kODBentoUpdateContainer);
- ODContainerType containerType = (ODContainerType) ODNewPtr(len + 1);
- strcpy(containerType, kODBentoUpdateContainer);
- return containerType;
- #endif
- }
-
- //------------------------------------------------------------------------------
- // GetFinderInfo
- //------------------------------------------------------------------------------
- void GetFinderInfo(Environment* ev, ODStorageUnit* su, PlatformFile* file)
- {
- if (!file->IsDirectory())
- {
- ODTime creationDate = file->GetFileCreationDate();
- ODSetCreationDate(ev, su, creationDate);
- ODTime modDate = file->GetFileModDate();
- ODSetModificationDate(ev, su, modDate);
-
- if (!file->IsStationery())
- {
- ODName* name = file->GetName();
- ODSetPONameUsingSU(ev, su, name);
- DisposeIText(name);
- }
-
- // Stationery bit is purposedly left out.
- }
- }
-
- //------------------------------------------------------------------------------
- // GetIconFamilyFromFile
- //------------------------------------------------------------------------------
- void GetIconFamilyFromFile(Environment* ev, ODStorageUnit* su, PlatformFile* file)
- {
- if (!file->IsDirectory())
- {
- Handle iconFamily;
-
- short refNum = 0;
- ODBoolean hasCustomIcon;
- OSErr err = noErr;
- ODVolatile(err);
- TRY
- hasCustomIcon = file->HasCustomIcon();
- if (hasCustomIcon)
- {
- file->SetPermission(fsRdPerm);
- refNum = CurResFile();
- err = ResError();
- if( err == noErr )
- file->OpenResFile();
- }
- CATCH_ALL
- file->CloseResFile();
- UseResFile(refNum);
- ENDTRY
-
- if (hasCustomIcon && (err == noErr))
- {
- err = GetIconSuite(&iconFamily, kCustomIconResource, svAllAvailableData);
- if (err == noErr)
- {
- ODSetIconFamilyProp(ev, su, kODPropCustomIcon, kODIconFamily, iconFamily, kODFalse);
- DisposeIconSuite(iconFamily, true);
- }
- #ifdef ODDEBUG
- else
- WARN("Problem getting icon family: %d ", err);
- #endif
- file->CloseResFile();
- }
- }
- }
-
-