home *** CD-ROM | disk | FTP | other *** search
- /*
- File: InfoUtil.cpp
-
- Contains: implementation of Info getters & setters
-
- Owned by: Doug Hill
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <13> 7/10/96 EL 1366381: if there is no comment,
- ODSetPOComments should delete comment
- property.
- <12> 7/8/96 EL 1364853: Add ODSetPartNameReturnError to do
- set part name but get error code back.
- <11> 6/24/96 RA T10025: Wrapped obsoleted utils w/
- _OD_IMPL_ ; they are not available to parts
- <10> 6/19/96 EL 1348424: Deactivate file types that appears
- in "kinds" popup
- <9> 6/18/96 TJ Don't use private ODPartWrapper class
- <8> 6/12/96 RA 1301627, 1297102: ODGetIconFamily now looks
- in all volume DTDB's , added StVolumeLoop;
- ODGetPartName no longer crashes if window
- isn't registered
- <7> 6/5/96 EL 1355529: Move InitKindsPopUp from Info.cpp
- to here for sharing, add parameters for
- AddTypesToMenu to check for default data
- kind.
- <6> 6/4/96 EL 1279544: Move GetTypeListItem from
- TransDlg.cpp to InfoUtil.cpp.
- <5> 5/31/96 jpa T10012: Added ODGetIconFilePlatformCreator.
- <4> 5/28/96 EL #1328903: slash and other meta characters
- should be allowed in the kind popup menu.
- #1348424: File Types should not appear in
- kind popup menu.
- <3> .04.1996 NP 1330731: Don't use stationery property
- anymore.
- <2> 3/15/96 DH 1.0.2: OpenDoc: Drag of no-part to trash
- rejected. Fixed
- ODGetIconFilePlatformTypeFromPartSU so that
- it has proper exception handling and a
- default return value.
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.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_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef SOM_ODTypeListIterator_xh
- #include <TypLsItr.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _BNDNSUTL_
- #include "BndNSUtl.h"
- #endif
-
- #ifndef _TRANSUTL_
- #include <TransUtl.h>
- #endif
-
- #ifdef __SC__
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
- #else
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __FINDER__
- #include <Finder.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include "InfoUtil.h"
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef _EDITRSET_
- #include "EditrSet.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_ODWindowIterator_xh
- #include <WinIter.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef SOM_ODValueNameSpace_xh
- #include <ValueNS.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef _NMSPCUTL_
- #include <NmSpcUtl.h>
- #endif
-
- #ifndef _UTILDEFS_
- #include "UtilDefs.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include "DocUtils.h"
- #endif
-
- #pragma segment Info
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- // this duplicate the definition from StorDef.h
- const ODValueType kODAppleFileTypePrefix = "+//ISO 9070/ANSI::113722::US::CI LABS::MacOS:FileType:";
-
- const short kControlInactive = 255;
- const short kControlActive = 0;
- #define SKIPOMPARSE
- #ifdef SKIPOMPARSE
- static const char* const kODIconFamilyBaseString = kODIconFamily ":";
- #else
- static const char* const kODIconFamilyBaseString = "^^^^correct def.^^^^^";
- #endif
- static const ResType kIconType[6] = {'ICN#','icl4','icl8','ics#','ics4','ics8'};
- static const short kIconSize[6] = {256, 512, 1024, 64, 128, 256 };
-
- const ODPlatformType kODFileType_hfs = 0x68667320; // 'hfs '
-
- //==============================================================================
- // Static Function declarations
- //==============================================================================
-
- ODTime ODGetDateProperty(Environment* ev,
- ODStorageUnit* su,
- ODPropertyName prop);
-
- void ODSetDateProperty(Environment* ev,
- ODStorageUnit* su,
- ODPropertyName prop,
- ODTime dateTime);
-
- ODStatic ODBoolean ODUserRenameFile(Environment* ev,
- ODSession* session,
- PlatformFile* usersFile,
- ODIText* name,
- DescType replaceOption);
- // If PlatformFile is made a shared utility, then the above function should probably be
- // integrated into the PlatformFile::Rename method.
-
- ODStatic ODIconFamily GetGenericIcon( short iconID );
-
- ODStatic OSErr DetachIconProc( ResType, Handle *theIcon, void */*yourDataPtr*/ );
-
- ODStatic ODBoolean CommentsDontMatch(ODIText* dtComments, ODIText* propComments);
-
- //==============================================================================
- // Info functions
- //==============================================================================
-
-
- ODStorageUnit* ODGetSUFromPstObj(Environment* ev, ODPersistentObject* pstobj)
- {
- return pstobj->GetStorageUnit(ev);
- }
-
- //-------------------------------------------------------------------------------------
- // Part & Frame Property getters and setters
- //-------------------------------------------------------------------------------------
-
- ODIText*
- ODGetPOComments(Environment* ev, ODPart *part, ODIText* comments)
- {
- ODStorageUnit* su = ODGetSUFromPstObj(ev, part);
- ODIText* propComments;
-
- propComments = ODGetITextProp(ev, su, kODPropComments, kODMacIText, comments);
- return propComments;
- }
-
- void ODSetPOComments(Environment* ev, ODPart *part, ODIText* comments)
- {
- ODStorageUnit* su = ODGetSUFromPstObj(ev, part);
-
- if (comments)
- ODSetITextProp(ev, su, kODPropComments, kODMacIText, comments);
- else {
- if ( ODSUExistsThenFocus(ev, su, kODPropComments, kODMacIText) )
- su->Remove(ev);
- if ( ODSUExistsThenFocus(ev, su, kODPropComments, kODIntlText) )
- su->Remove(ev);
- }
- }
-
-
- ODIText*
- ODGetComments(Environment* ev, ODFrame* frame, ODIText* comments)
- {
- TempODPart part = frame->AcquirePart(ev);
- ODIText* propComments;
- ODIText* dtComments;
-
- propComments = ODGetPOComments(ev, part, comments);
- if (comments && !propComments)
- propComments = comments;
- TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
- if (usersFile)
- {
- dtComments = usersFile->GetComments();
- if (dtComments && GetITextStringLength(dtComments) == 0)
- {
- // since there are no desktop comments
- // make the desktop comments match the property
- usersFile->SetComments(propComments);
- }
- else if (CommentsDontMatch(dtComments, propComments) && dtComments)
- {
- // if there are desktop comments and the property comments don't match
- // then the desktop comments take precedence, so return the desktop comments
- DisposeIText(propComments);
- propComments = dtComments;
- dtComments = kODNULL;
- }
- DisposeIText(dtComments);
- }
- return propComments;
- }
-
- void ODSetComments(Environment* ev, ODFrame* frame, ODIText* comments)
- {
- TempODPart part = frame->AcquirePart(ev);
- ODSetPOComments(ev, part, comments);
- TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
- if (usersFile)
- usersFile->SetComments(comments);
- }
-
-
- ODULong ODGetPOSize(Environment* ev, ODPersistentObject* pstobj)
- {
- ODStorageUnit* su = ODGetSUFromPstObj(ev, pstobj);
- su->Focus(ev, kODNULL, kODPosAll, kODNULL,0, kODPosAll);
- return su->GetSize(ev);
- }
-
- ODID ODGetPOID(Environment* ev, ODPersistentObject* pstobj)
- {
- ODStorageUnit* su = ODGetSUFromPstObj(ev, pstobj);
- su->Focus(ev, kODNULL, kODPosAll, kODNULL,0, kODPosAll);
- return su->GetID(ev);
- }
-
- ODTime ODGetDateProperty(Environment* ev,
- ODStorageUnit* su,
- ODPropertyName prop)
- { return ODGetTime_TProp(ev, su, prop, kODTime_T);}
-
- void ODSetDateProperty(Environment* ev,
- ODStorageUnit* su,
- ODPropertyName prop,
- ODTime dateTime)
- { ODSetTime_TProp(ev, su, prop, kODTime_T, dateTime);}
-
-
- ODULong ODGetCreationDate(Environment* ev,
- ODStorageUnit* su)
- { return ODGetDateProperty(ev, su, kODPropCreateDate);}
-
- void ODSetCreationDate(Environment* ev,
- ODStorageUnit* su,
- ODTime dateTime)
- { ODSetDateProperty(ev, su, kODPropCreateDate, dateTime);}
-
-
- ODULong ODGetModificationDate(Environment* ev,
- ODStorageUnit* su)
- { return ODGetDateProperty(ev, su, kODPropModDate);}
-
- void ODSetModificationDate(Environment* ev,
- ODStorageUnit* su,
- ODTime dateTime)
- { ODSetDateProperty(ev, su, kODPropModDate, dateTime);}
-
-
- ODIText* ODGetModifiedBy(Environment* ev,
- ODStorageUnit* su, ODIText* userName)
- {
- return ODGetITextProp(ev, su, kODPropModUser,
- kODMacIText, userName);
- }
-
- void ODSetModifiedBy(Environment* ev,
- ODStorageUnit* su, ODIText* userName)
- {
- ODSetITextProp(ev, su, kODPropModUser,
- kODMacIText, userName);
- }
-
-
- //-------------------------------------------------------------------------------------
- // Part only Property getters and setters
- //-------------------------------------------------------------------------------------
- ODIText* ODGetPartName(Environment* ev,
- ODFrame* frame, ODIText* name)
- {
- TempODPart part = frame->AcquirePart(ev);
- TempODIText partName = ODGetPOName(ev, part, name);
-
- TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
- if (usersFile)
- {
- TempODIText fileName = usersFile->GetName();
- if ( CommentsDontMatch( fileName, partName ) )
- return CopyIText( fileName );
- }
- return CopyIText( partName );
- }
-
- ODError ODSetPartNameReturnError(Environment* ev,
- ODFrame* frame, ODIText* name, DescType replaceOption)
- // Renames the part of the frame passed in.
- // If there is any error return the error.
- // The frame helps more easily determine whether
- // the part is the root part of the document or not.
- // For example, renaming the root part of the document could fail
- // if there was a file with the same name and the user canceled the
- // "Replace?" dialog.
- {
- ASSERT(frame != kODNULL, kODErrIllegalNullInput);
-
- TempODPart part = frame->AcquirePart(ev);
- TempODWindow window = frame->AcquireWindow(ev);
-
- ODFrame* contFrame = frame->AcquireContainingFrame(ev);
- ODBoolean isRootPart = (contFrame == kODNULL);
- ODReleaseObject(ev, contFrame);
-
- ODBoolean isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
-
- ODName* oldName = kODNULL; ODVolatile(oldName);
- PlatformFile* usersFile = kODNULL; ODVolatile(usersFile);
- ODError error = noErr;
-
- TRY
- ODStorageUnit* partSU = ODGetSUFromPstObj(ev, part);
- ODSession* session = partSU->GetSession(ev);
- oldName = ODGetPartName(ev, frame, kODNULL);
-
- if (isRootPartOfDocument)
- {
- ODDraft* draft = partSU->GetDraft(ev);
- usersFile =
- GetPlatformFileFromContainer(ev, draft->GetDocument(ev)->GetContainer(ev));
-
- if (ODUserRenameFile(ev, session, usersFile, name, replaceOption))
- {
- ODWindowState* windowState = session->GetWindowState(ev);
- windowState->SetDefaultWindowTitles(ev, draft);
- ODSetPOName(ev, part, name);
- ODRenamePartWindows(ev,session,part,oldName,name);
- if (isRootPart)
- {
- Str255 pName;
- GetITextPString(name, pName);
- SetWTitle(window->GetPlatformWindow(ev), pName);
- }
- }
- }
- else
- {
- ODSetPOName(ev, part,name);
- ODRenamePartWindows(ev,session,part,oldName,name);
- }
-
- CATCH_ALL
- error = ErrorCode();
- #if ODDebug
- if (error != userCanceledErr)
- WARN("ODSetPartName failed, error %ld",error);
- #endif
- ENDTRY
-
- ODDeleteObject(usersFile);
- DisposeIText(oldName);
-
- return error;
- }
-
- ODBoolean ODSetPartName(Environment* ev,
- ODFrame* frame, ODIText* name, DescType replaceOption)
- // Renames the part of the frame passed in.
- // Returns whether or not it succeeded.
- // Just call ODSetPartNameReportError and return false if there is error
- {
- return (ODSetPartNameReturnError(ev, frame, name, replaceOption) == noErr);
- }
-
- void
- ODRenamePartWindows( Environment *ev, ODSession *session,
- ODPart *part, ODIText *oldName, ODIText *name )
- {
- // go through all windows which have this part as their root, and
- // have the current name of the part as a prefix
- // rename their prefix to be the new name
- Str255 pOldName;
- Str255 pNewName;
- Str255 pWinTitle;
- ODUByte pOldNameLen;
- ODUByte pNewNameLen;
-
- GetITextPString(oldName, pOldName);
- pOldNameLen = pOldName[0];
- GetITextPString(name, pNewName);
- pNewNameLen = pNewName[0];
-
- ODWindowIterator* iter = session->GetWindowState(ev)->CreateWindowIterator(ev);
- for (ODWindow* window = iter->First(ev);
- iter->IsNotComplete(ev);
- window = iter->Next(ev))
- {
- TempODPart winPart = window->GetRootFrame(ev)->AcquirePart(ev);
- if (ODObjectsAreEqual(ev, part, winPart))
- {
- // Check to see if name of window has pOldName as prefix
- ODPlatformWindow pwindow = window->GetPlatformWindow(ev);
- GetWTitle(pwindow, pWinTitle);
- if (!strncmp((char*)&pWinTitle[1], (char*)&pOldName[1], pOldNameLen) &&
- !EqualPascalStrings(pWinTitle, pNewName))
- {
- ODUByte suffixLen = pWinTitle[0] - pOldNameLen;
- if (suffixLen + pNewNameLen > 255)
- suffixLen = 255 - pNewNameLen;
- strncpy((char*)&pNewName[pNewNameLen+1],
- (char*)&pWinTitle[pOldNameLen+1],
- suffixLen);
- pNewName[0] = pNewNameLen+suffixLen;
- SetWTitle(pwindow, pNewName);
- }
- }
- }
- ODDeleteObject(iter);
- }
-
-
- ODIText* ODGetPOName(Environment* ev, ODPersistentObject* pstobj,ODIText* name)
- {
- return ODGetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, kODMacIText,name);
- }
-
- void ODSetPOName(Environment* ev, ODPersistentObject* pstobj,ODIText* name)
- {
- ODSetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, kODMacIText, name);
- }
-
- void ODSetPONameUsingSU(Environment* ev, ODStorageUnit* su, ODIText* name)
- {
- ODSetITextProp(ev, su, kODPropName, kODMacIText, name);
- }
-
- ODName* ODGetCategory(Environment* ev, ODPart* part, ODNameSpaceManager* nsm)
- {
- return ODGetCatFromPartSU(ev, ODGetSUFromPstObj(ev, part), nsm);
- }
-
- ODName* ODGetCatFromPartSU(Environment* ev, ODStorageUnit* su, ODNameSpaceManager* nsm)
- {
- ODType kind = ODGetKindFromPartSU(ev, su);
- ODName* categoryName = ODGetCatFromKind(ev, kind, nsm);
- ODDisposePtr( kind );
-
- return categoryName;
- }
-
- #ifdef _OD_IMPL_
- ODName* ODGetCatFromKind(Environment* ev, ODType kind, ODNameSpaceManager* nsm)
- {
- StringHandle strHandle = 0;
- ODTypeList* categoryList = GetCategoriesOfKind(nsm, kind);
- ODTypeListIterator* catIter = kODNULL;
- ODType category = kODNULL;
- ODName* categoryName = kODNULL;
-
- if (categoryList)
- {
- catIter = categoryList->CreateTypeListIterator(ev);
- category = catIter->First(ev);
- ODDeleteObject(catIter);
- }
-
- if (category == kODNULL || !GetUserCatFromCat(nsm, category, &categoryName)) {
- CUsingLibraryResources r;
- categoryName = GetODIText(kODPartInfoStrUnknownID);
- }
- //else // make a disposable copy // NO NEED TO! GetUserCatFromCat returns a copy!
- // categoryName = CopyIText(categoryName);
-
- ODDisposePtr(category);
-
- return categoryName;
- }
- #endif
-
- ODType ODGetKindFromPartSU(Environment* ev, ODStorageUnit* su)
- {
- ODULong unused;
- ODType kind = ODGetISOStrProp(ev, su, kODPropPreferredKind, kODISOStr, kODNULL, &unused);
- if ( kind == kODNULL )
- if ( su->Exists(ev, kODPropContents, (ODValueType) kODNULL,1) )
- {
- su->Focus(ev, kODPropContents, kODPosSame, (ODValueType) kODNULL,1, kODPosSame);
- kind = su->GetType(ev);
-
- ODTranslation* translation = su->GetSession(ev)->GetTranslation(ev);
- TempODType hfsType =
- translation->GetISOTypeFromPlatformType(ev, kODFileType_hfs, kODPlatformDataType);
-
- if ( ODISOStrEqual(kind, hfsType) )
- {
- ODDisposePtr(kind);
- kind = kODNULL;
- if ( su->Exists(ev, kODPropContents, (ODValueType) kODNULL,2) )
- {
- su->Focus(ev, kODPropContents, kODPosSame, (ODValueType) kODNULL,2, kODPosSame);
- kind = su->GetType(ev);
- }
- }
- }
- return kind;
- }
-
- ODType ODGetKind(Environment* ev, ODPart* part)
- {
- return ODGetKindFromPartSU(ev, ODGetSUFromPstObj(ev, part));
- }
-
- ODPlatformType ODGetIconFilePlatformTypeFromPartSU(Environment* ev, ODStorageUnit* su)
- {
- ODType partKind = kODNULL;
- ODPlatformType partOSType;
- ODVolatile(partKind);
- ODVolatile(partOSType);
-
- TRY
- ODSession* session = su->GetSession(ev);
-
- partKind = ODGetKindFromPartSU(ev, su);
- partOSType = session->GetTranslation(ev)->
- GetPlatformTypeFromISOType(ev, partKind);
- if (partOSType != kODNULL)
- {
- ((ODUByte*)(&partOSType))[0] = kODPlatformKindFileChar1;
- }
- else
- {
- ODBoolean partOSTypeFound = kODFalse;
- ODValueNameSpace* osTypeNameSpace = (ODValueNameSpace*)
- (session->GetNameSpaceManager(ev)->HasNameSpace(ev, kODKindOldMacOSType));
-
- if (osTypeNameSpace)
- {
- ODPlatformType* typePtr;
- ODULong unusedLength;
- partOSTypeFound = ValueNameSpaceGetEntry(osTypeNameSpace,
- ev, partKind,
- (ODPtr*) &typePtr,
- &unusedLength);
- if (partOSTypeFound)
- {
- partOSType = *typePtr;
- ODDeleteObject( typePtr );
- }
- }
- if (!partOSTypeFound)
- partOSType = kODShellSignature;
- }
-
- ODDisposePtr(partKind);
- CATCH_ALL
- ODDisposePtr(partKind);
- partOSType = kODShellSignature;
- ENDTRY
-
- return partOSType;
- }
-
-
- static ODPlatformType
- LookupEditorCreator( Environment *ev, ODSession *session, ODEditor editor )
- {
- ODPlatformType creator = kODShellSignature;
-
- if( editor ) {
- ODNameSpaceManager *nsm = session->GetNameSpaceManager(ev);
- ODValueNameSpace *ns = (ODValueNameSpace*)
- nsm->HasNameSpace(ev, kODEditorPlatformSignature);
- if (ns) {
- ODPlatformType* typePtr;
- ODULong unusedLength;
- if( ValueNameSpaceGetEntry(ns, ev, editor, (ODPtr*) &typePtr, &unusedLength) ) {
- creator = *typePtr;
- ODDeleteObject( typePtr );
- }
- }
- }
- return creator;
- }
-
-
- ODPlatformType ODGetIconFilePlatformCreatorFromPartSU( Environment *ev, ODStorageUnit *su )
- {
- // Ask Binding which editor will be used for this storage unit:
- TempODISOStr editor = ODGetSession(ev,su)->GetBinding(ev)
- ->ChooseEditorForPart(ev,su,kODNULL);
- return LookupEditorCreator(ev, ODGetSession(ev,su), editor);
- }
-
-
- ODPlatformType ODGetIconFilePlatformCreator( Environment *ev, ODPart *part )
- {
- return LookupEditorCreator( ev, ODGetSession(ev,part),
- part->GetRealPart(ev)->somGetClassName() );
- }
-
-
- //--------------------------------------------------------------------
- // ODGetPOIconFamily
- //--------------------------------------------------------------------
-
- ODIconFamily
- ODGetPOIconFamily(Environment* ev, ODPart* part)
- {
- //// FIRST, get the Mac icon value if one exists:
- ODStorageUnit* su = ODGetSUFromPstObj(ev, part);
- ODIconFamily icons = ODGetIconFamilyProp(ev, su,
- kODPropCustomIcon, kODIconFamily, kAllIconsMask);
- if (icons )
- return icons;
-
- //// OTHERWISE, look for other platform icon values:
- if (ODSUExistsThenFocus(ev,su, kODPropCustomIcon, kODNULL))
- {
- ODULong numValues = su->CountValues(ev);
- for( ODULong i = 1; i <= numValues; i++ )
- {
- su->Focus(ev, kODNULL, kODPosSame, kODNULL, 0, kODPosNextSib); // Next value
- TempODValueType type = su->GetType(ev);
- if( strncmp(type,kODIconFamilyBaseString,strlen(kODIconFamilyBaseString)) == 0 )
- {
- // This value is an icon family for some platform. Use the b/w icons
- // because we don't know what color table the color ones may use.
- icons = ODGetIconFamilyProp(ev, su, kODPropCustomIcon, type, kBWIconsMask);
- if( icons )
- return icons;
- }
- }
- return kODNULL;
- }
- return icons;
- }
-
-
-
- //--------------------------------------------------------------------
- // ODSetPOIconFamily
- //--------------------------------------------------------------------
-
- void ODSetPOIconFamily(Environment* ev, ODPart* part,
- ODIconFamily icons, ODBoolean deleteOtherPlatformIcons)
- {
- ODSetIconFamilyProp(ev, ODGetSUFromPstObj(ev, part),
- kODPropCustomIcon, kODIconFamily,
- icons, deleteOtherPlatformIcons);
- }
-
- //==============================================================================
- // StVolumeLoop
- //==============================================================================
-
- //——————————————————————————————————————————————————————————————————————————————
- // StVolumeLoop::StVolumeLoop
- //——————————————————————————————————————————————————————————————————————————————
-
- const short kSystemVolumeID = -1; // -1 is the refnum of the System Volume.
-
- //——————————————————————————————————————————————————————————————————————————————
- // StVolumeLoop::StVolumeLoop
- //——————————————————————————————————————————————————————————————————————————————
-
- StVolumeLoop::StVolumeLoop()
- {
- mInitialVRefNum = kSystemVolumeID;
-
- mVolumePass = kInitialPass;
- mVolumeIndex = 0;
- }
-
- //——————————————————————————————————————————————————————————————————————————————
- // StVolumeLoop::StVolumeLoop
- //——————————————————————————————————————————————————————————————————————————————
-
- StVolumeLoop::StVolumeLoop(short inInitialVolume)
- {
- mInitialVRefNum = inInitialVolume;
-
- mVolumePass = kInitialPass;
- mVolumeIndex = 0;
- }
-
- //——————————————————————————————————————————————————————————————————————————————
- // StVolumeLoop::NextVolume
- //——————————————————————————————————————————————————————————————————————————————
- Boolean
- StVolumeLoop::NextVolume(short& outVolume)
- {
- Boolean foundVolumeToReturn = false;
-
- do
- {
- if (mVolumePass == kInitialPass)
- {
- // if we're on the initial pass (kInitialPass) just use
- // the vRefNum of the initial volume itself.
-
- // desktopParams.ioVRefNum = initialVRefNum;
- outVolume = mInitialVRefNum;
- foundVolumeToReturn = true;
-
- SetupNextVolumePass();
- }
- else
- {
- // Find the vRefNum of the next volume appropriate for this pass.
-
- mVolumeIndex++;
-
- // Convert the volumeIndex into a vRefNum.
-
- HParamBlockRec hfsParams;
- hfsParams.volumeParam.ioNamePtr = nil;
- hfsParams.volumeParam.ioVRefNum = 0;
- hfsParams.volumeParam.ioVolIndex = mVolumeIndex;
- OSErr error = ::PBHGetVInfoSync(&hfsParams);
-
- // A nsvErr indicates that the current pass is over.
-
- if (error != nsvErr)
- THROW_IF_ERROR(error);
-
- if (error == nsvErr)
- {
- SetupNextVolumePass();
- }
- else if (hfsParams.volumeParam.ioVRefNum == mInitialVRefNum)
- {
- // Since we handled the document volume during the initialPass,
- // skip it if we have hit that volume again.
-
- // Don’t do anything, just let it continue to the next volume.
- }
- else if (IsRemoteVolume(hfsParams) != (mVolumePass == kRemotePass))
- {
- // The current volume should be ignored by this pass because
- // it's not of the right type.
-
- // Don’t do anything, just let it continue to the next volume.
- }
- else
- {
- // Okay, now we’ve found the vRefNum to return.
-
- // desktopParams.ioVRefNum = hfsParams.volumeParam.ioVRefNum;
- outVolume = hfsParams.volumeParam.ioVRefNum;
- foundVolumeToReturn = true;
- }
- }
-
- // ••• This is where we return the correct volume ref.
- }
- while (!foundVolumeToReturn && mVolumePass != kDonePass);
-
- return mVolumePass != kDonePass;
- }
-
- //——————————————————————————————————————————————————————————————————————————————
- // StVolumeLoop::SetupNextVolumePass
- //——————————————————————————————————————————————————————————————————————————————
- void
- StVolumeLoop::SetupNextVolumePass()
- {
- mVolumePass = (EPass) ((short) mVolumePass + 1);
- mVolumeIndex = 0;
- }
-
- //——————————————————————————————————————————————————————————————————————————————
- // StVolumeLoop::IsRemoteVolume
- //——————————————————————————————————————————————————————————————————————————————
- Boolean
- StVolumeLoop::IsRemoteVolume(HParamBlockRec& inHFSParams)
- {
- // Call GetVolParms to determine if this volume is a server
- // (a remote volume).
-
- GetVolParmsInfoBuffer volumeInfoBuffer;
-
- inHFSParams.ioParam.ioBuffer = (Ptr) &volumeInfoBuffer;
- inHFSParams.ioParam.ioReqCount = sizeof(GetVolParmsInfoBuffer);
- THROW_IF_ERROR(::PBHGetVolParmsSync(&inHFSParams));
-
- inHFSParams.ioParam.ioBuffer = NULL; // Make sure it's not pointing to
- // the stack anymore.
-
- // If the vMServerAdr field of the volume information buffer
- // is zero, this is a local volume.
-
- return (volumeInfoBuffer.vMServerAdr != 0);
- }
- //==============================================================================
-
- //--------------------------------------------------------------------
- // ODGetIconFamily
- //
- // Returns an ODIconFamily for the frames part or generic icons
- // if an associated ODIconFamily is not found. Throws only if it can't
- // get the generic icons.
- //--------------------------------------------------------------------
- ODIconFamily
- ODGetIconFamily(Environment* ev, ODFrame* frame)
- {
- ODIconFamily r = kODNULL; ODVolatile(r);
- TempPlatformFile usersFile = kODNULL; ODVolatile(usersFile);
-
- ASSERT_NOT_NULL(frame);
-
- TRY
- {
- usersFile = ODGetFileIfRoot(ev, frame);
- }
- CATCH_ALL
- //Thanks for sharing, but I can still continue my search, so I will.
- ENDTRY
-
- // First search phase, get custom icon family or look in the storage unit
- if (usersFile)
- {
- TRY
- {
- r = usersFile->GetCustomIconFamily();
- }
- CATCH_ALL
- //Thanks for sharing, but I can still continue my search, so I will.
- ENDTRY
- }
- else
- {
- TRY
- {
- TempODPart part = kODNULL;
- part = frame->AcquirePart(ev);
- r = ODGetPOIconFamily(ev, part);
- // TempODPart is released here &/or on exception
- }
- CATCH_ALL
- ENDTRY
- }
-
- // Second search phase, search the available desktop databases
- if (r == kODNULL)
- {
- TRY
- {
- ODPlatformType kInvalidFileType = '\0\0\0\0';
- ODPlatformType fileType = kInvalidFileType; ODVolatile(fileType);
- ODPlatformType fileCreator = kODShellSignature;
-
- TRY
- {
- TempODPart part = kODNULL;
- ODStorageUnit* su = kODNULL;
- part = frame->AcquirePart(ev);
- su = ODGetSUFromPstObj(ev, CAST(part,ODPart));
- ASSERT_NOT_NULL(su);
- fileType = ODGetIconFilePlatformTypeFromPartSU(ev, su);
- // TempODPart is released here &/or on exception
- }
- CATCH_ALL
- ENDTRY
-
- // Ask the desktop database by filetype for suite
- if (fileType != kInvalidFileType)
- r = ODGetIconSuiteFromDesktopDB(fileType,fileCreator);
- }
- CATCH_ALL
- ENDTRY
- }
-
- // Final search phase, use generic icons as last resort
- if (r == kODNULL)
- {
- ODBoolean isStationery = kODFalse;
- ODSShort id = 0;
-
- TRY
- {
- isStationery = ODGetIsStationery(ev, frame);
- }
- CATCH_ALL
- ENDTRY
-
- if (isStationery)
- {
- id = genericStationeryIconResource;
- }
- else
- {
- id = genericDocumentIconResource;
- }
-
- TRY
- {
- r = GetGenericIcon(id);
- }
- CATCH_ALL
- RERAISE;
- ENDTRY
- }
-
- return r;
- }
-
- // Allocates an IconSuite if found and returns a ptr to it.
- ODIconFamily ODGetIconSuiteFromDesktopDB(ODPlatformType fileType,ODPlatformType fileCreator)
- {
- ODIconFamily r = kODNULL; ODVolatile(r);
- StVolumeLoop volumeLoop;
- short theVolume;
-
- TRY
- {
- while (!r && volumeLoop.NextVolume(theVolume))
- {
- OSErr err = noErr;
- DTPBRec pb;
- memset(&pb,'\0',sizeof(DTPBRec));
- pb.ioNamePtr = kODNULL;
- pb.ioVRefNum = theVolume; // index
- err = ::PBDTGetPath( &pb );
-
- if (err == noErr)
- {
- short DTRefNum = pb.ioDTRefNum; ODVolatile(DTRefNum);
-
- TRY
- {
- r = BuildIconSuiteFromDesktop(DTRefNum,fileType,fileCreator);
- }
- CATCH_ALL
- ENDTRY
- }
- else if (err == desktopDamagedErr)
- {
- //if (!Finder) ::PBReset();
- }
- // if there is a PBDTGetPath() error we ignore it and continue to next volume
- }
- }
- CATCH_ALL
- // if volume iterator dies, we can't get icons...
- ENDTRY
-
- return r;
- }
-
- ODIconFamily BuildIconSuiteFromDesktop(short DTRefNum,ODPlatformType fileType,ODPlatformType fileCreator)
- {
- ODIconFamily icons = kODNULL; ODVolatile(icons);
- char iconBuffer[kLarge8BitIconSize]; // make room for largest possible icon bitmap
- const ODBoolean kDisposeHandlesInIconSuite = kODTrue;
-
- THROW_IF_ERROR( NewIconSuite(&icons) );
-
- TRY
- {
- ODBoolean hasIcon = kODFalse;
- for(int i = 1; i <= 6; i++)
- {
- OSErr err = noErr;
- DTPBRec pb;
- memset(&pb,'\0',sizeof(DTPBRec));
-
- pb.ioCompletion = NULL;
- pb.ioDTRefNum = DTRefNum;
- pb.ioTagInfo = 0; // Reserved ; must be zero
- pb.ioDTBuffer = (Ptr)&iconBuffer;
- pb.ioDTReqCount = sizeof(iconBuffer);
- pb.ioIconType = i; // index
- pb.ioFileCreator= fileCreator;
- pb.ioFileType = fileType;
- err = ::PBDTGetIconSync(&pb);
-
- if (err == noErr)
- {
- WASSERT(pb.ioDTActCount == kIconSize[i-1]);
- Handle hIcon = ODNewHandle(kIconSize[i-1]);
- HLock(hIcon);
- ODBlockMove(iconBuffer,*hIcon,kIconSize[i-1]);
- HUnlock(hIcon);
- err = AddIconToSuite(hIcon ,icons, kIconType[i-1] );
- if(err)
- {
- DisposeHandle(hIcon);
- hIcon = kODNULL;
- THROW_IF_ERROR(err);
- }
- hasIcon = kODTrue;
- }
- else if (err != afpItemNotFound)
- {
- THROW_IF_ERROR(err);
- }
- } // For loop
-
- // return NULL if we could not find any icon data.
- if (!hasIcon)
- {
- if (icons)
- DisposeIconSuite(icons, kDisposeHandlesInIconSuite);
- icons = kODNULL;
- }
- } // TRY
- CATCH_ALL
- if (icons)
- DisposeIconSuite(icons, kDisposeHandlesInIconSuite);
- icons = kODNULL;
- RERAISE;
- ENDTRY
-
- return icons;
- }
-
-
- //--------------------------------------------------------------------
- // ODSetIconFamily
- //--------------------------------------------------------------------
-
- void ODSetIconFamily(Environment* ev,
- ODFrame* frame, ODIconFamily icons, ODBoolean deleteOtherPlatformIcons)
- {
- TempODPart part = frame->AcquirePart(ev);
-
- ODSetPOIconFamily(ev, part, icons, deleteOtherPlatformIcons);
-
- TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
- if (usersFile)
- usersFile->SetCustomIconFamily(icons);
- }
-
- //--------------------------------------------------------------------
- // ODGetFileIfRoot
- //--------------------------------------------------------------------
-
- PlatformFile* ODGetFileIfRoot(Environment* ev, ODFrame* frame)
- {
- ASSERT_NOT_NULL(frame);
-
- PlatformFile* file = kODNULL;
-
- TempODPart part = frame->AcquirePart(ev);
-
- // Get the root part of the document.
- ODDraft* draft = ODGetDraft(ev,part);
- TempODPart rootPart = ODAcquireRootPartOfDraft(ev, draft);
-
- // If the part is the root of the document, return the corresponding file.
- if ( ODObjectsAreEqual(ev, part, rootPart) )
- {
- ODContainer* container = draft->GetDocument(ev)->GetContainer(ev);
- file = GetPlatformFileFromContainer(ev, container);
- }
-
- return file;
- }
-
- //--------------------------------------------------------------------
- // DetachIconProc
- //--------------------------------------------------------------------
-
- static OSErr DetachIconProc( ResType, Handle *theIcon, void */*yourDataPtr*/ )
- {
- if( *theIcon ) {
- DetachResource(*theIcon);
- return ResError();
- } else
- return noErr;
- }
-
- //--------------------------------------------------------------------
- // GetGenericIcon
- //--------------------------------------------------------------------
-
- ODStatic ODIconFamily GetGenericIcon( short iconID )
- {
- ODIconFamily icon;
- THROW_IF_ERROR( GetIconSuite( &icon, iconID, svAllAvailableData ) );
- IconActionUPP detachProc = NewIconActionProc(&DetachIconProc);
- (void) ForEachIconDo(icon, svAllAvailableData, detachProc, kODNULL);
- DisposeRoutineDescriptor(detachProc);
- return icon;
- }
-
-
- //--------------------------------------------------------------------
- // ODGetIsStationery
- //--------------------------------------------------------------------
-
- ODBoolean ODGetIsStationery(Environment* ev,
- ODFrame* frame)
- {
- TempODPart part = frame->AcquirePart(ev);
- ODBoolean isStationery = kODFalse;
-
- TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
- if (usersFile)
- isStationery = usersFile->IsStationery();
- // else
- // isStationery = ODGetSUIsStationery(ev, ODGetSUFromPstObj(ev, part));
- return isStationery;
- }
-
- //--------------------------------------------------------------------
- // ODSetIsStationery
- //--------------------------------------------------------------------
-
- void ODSetIsStationery(Environment* ev,
- ODFrame* frame, ODBoolean isStationery)
- {
- // { TempODPart part = frame->AcquirePart(ev);
- // ODSetBooleanProp( ev, ODGetSUFromPstObj(ev, part),
- // kODPropIsStationery, kODBoolean, isStationery);
- // }
- TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
- if (usersFile)
- usersFile->SetStationery(isStationery);
- }
- #if 0
- //--------------------------------------------------------------------
- // ODSetSUIsStationery
- //--------------------------------------------------------------------
-
- void ODSetSUIsStationery(Environment* ev,
- ODStorageUnit* su, ODBoolean isStationery)
- {
- ODSetBooleanProp( ev, su, kODPropIsStationery, kODBoolean, isStationery);
- }
-
- //--------------------------------------------------------------------
- // ODGetSUIsStationery
- //--------------------------------------------------------------------
-
- ODBoolean ODGetSUIsStationery(Environment* ev,
- ODStorageUnit* su)
- {
- ODBoolean isStationery;
-
- if (su->Exists(ev, kODPropIsStationery, kODBoolean, 0))
- isStationery = ODGetBooleanProp( ev, su, kODPropIsStationery, kODBoolean);
- else
- isStationery = kODFalse;
-
- return isStationery;
- }
- #endif /* 0 */
- //-------------------------------------------------------------------------------------
- // Editor and Kind Menu manipulation functions
- //-------------------------------------------------------------------------------------
- // copied from LinkDlgs.cpp (with changes by TÇ)
- //------------------------------------------------------------------------------
- // InitKindsPopup
- //------------------------------------------------------------------------------
-
- void InitKindsPopup ( ODTypeList* kindList,
- ODType theKind,
- ControlHandle itemHandle,
- ODSShort* currentKindItem,
- MenuHandle kindMenu,
- ODSShort* translateItem,
- ODSession* session)
- {
- ODSShort item = 1;
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODUShort i;
-
- // remove all except last item in menu
- for (i = CountMItems(kindMenu) - 1; i > 0; --i)
- {
- DeleteMenuItem(kindMenu, i);
- }
-
- AddTypesToMenu(kindList, kindMenu, theKind, currentKindItem, session);
-
- *translateItem = CountMItems(kindMenu);
- EnableItem(kindMenu, *translateItem);
-
- SetControlMinimum(itemHandle, 1);
- SetControlMaximum(itemHandle, *translateItem);
- SetControlValue(itemHandle, *currentKindItem);
-
- // Determine if translation is an option
- ODTypeList* translateToList =
- session->GetStorageSystem(ev)->CreateTypeList(ev,(ODTypeList*)kODNULL);
-
- TRY
- GetDestinationKindsList(kindList, translateToList, kODNULL, session);
- if ( translateToList->Count(ev) == 0 )
- DisableItem(kindMenu, *translateItem);
- CATCH_ALL
- DisableItem(kindMenu, *translateItem);
- ENDTRY
-
- ODDeleteObject( translateToList );
- }
-
- #ifdef _OD_IMPL_
- //------------------------------------------------------------------------------
- // AddTypesToMenu
- //------------------------------------------------------------------------------
-
- void AddTypesToMenu(ODTypeList* typeList, MenuHandle kindMenu, ODType defaultKind,
- ODSShort* currentKindItem, ODSession* session)
- {
- ODName* name;
- ODSShort item = 0;
- Environment* ev = somGetGlobalEnvironment();
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
- ODULong prefixSize = ODISOStrLength(kODAppleFileTypePrefix);
-
- ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
-
- EditorSet* editorList = new EditorSet;
- editorList->InitEditorSet();
-
- for (ODType type = typeIter->First(ev);
- typeIter->IsNotComplete(ev);
- type = typeIter->Next(ev))
- {
- ODBoolean isDefaultKind = defaultKind ? ODISOStrEqual(type, defaultKind) : kODFalse;
-
- if ( GetUserKindFromKind(nsm, type, &name) )
- {
- Str255 itemString;
- IntlToPStr(name, itemString);
- InsertMenuItem(kindMenu, "\p ", item++);
- SetMenuItemText(kindMenu, item, itemString);
-
- ScriptCode itemScript = GetITextScriptCode(name);
- SetPopupItemScript(kindMenu, item, itemScript);
-
- DisposeIText( name );
- }
- else
- {
- // there's no name for this type
- Str255 pKindStr;
- ODTranslation* translation = session->GetTranslation(ev);
- ODPlatformType platformType =
- translation->GetPlatformTypeFromISOType(ev, type);
- if ( platformType == kODNULL )
- {
- // Special menu item
- CUsingLibraryResources r;
- GetIndString(pKindStr, kODInfoUtilStrsID, kODStrIndNoKinds);
- }
- else
- {
- ODBlockMove(&platformType, &(pKindStr[1]), (ODULong) sizeof(ODPlatformType));
- pKindStr[0] = (unsigned char) sizeof(ODPlatformType);
- }
- // Allow metacharacters in item text
- InsertMenuItem(kindMenu, "\p ", item++);
- SetMenuItemText(kindMenu, item, pKindStr);
- }
-
- // if it is a file type that is not the default type, we would disable it
- // we also disable it if if cannot find any editor for the kind
- if (((ODISOStrNCompare(kODAppleFileTypePrefix, (ODISOStr) type, prefixSize) == 0) && !isDefaultKind) ||
- (!GetAllEditorsForKind(nsm, type, editorList)))
- DisableItem(kindMenu, item);
- editorList->RemoveAllEditors();
-
- if (isDefaultKind)
- *currentKindItem = item;
-
- ODDisposePtr(type);
- }
- ODDeleteObject( editorList );
- ODDeleteObject( typeIter );
- }
-
- //------------------------------------------------------------------------------
- // EnableTypesInMenu
- //------------------------------------------------------------------------------
-
- ODUShort EnableTypesInMenu(
- ODTypeList* typeList,
- MenuHandle kindMenu,
- ODEditor editor,
- ODNameSpaceManager* nsm)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODUShort itemStart = 0;
-
- if ( kindMenu && typeList && (typeList->Count(ev) > 0) )
- {
- ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
-
- for (ODType type = typeIter->First(ev);
- typeIter->IsNotComplete(ev);
- type = typeIter->Next(ev))
- {
- if ( editor == kODNULL )
- {
- // Editor is not fixed; Aassume kind can be embedded even if there is
- // no editor installed for it
- EnableItem(kindMenu, ++itemStart);
- }
- else
- {
- if ( EditorSupportsKind(nsm, editor, type) )
- EnableItem(kindMenu, ++itemStart);
- else
- DisableItem(kindMenu, ++itemStart);
- }
- ODDisposePtr(type);
- }
-
- ODDeleteObject( typeIter );
- }
-
- return itemStart;
- }
- #endif
-
- //------------------------------------------------------------------------------
- // DeleteAllMenuItems
- //------------------------------------------------------------------------------
- ODStatic void DeleteAllMenuItems(MenuHandle theMenu)
- {
- ODUShort i;
-
- for (i = CountMItems(theMenu); i > 0; --i)
- {
- DeleteMenuItem(theMenu, i);
- }
- }
-
- #ifdef _OD_IMPL_
- //------------------------------------------------------------------------------
- // SetupEditorMenu
- //------------------------------------------------------------------------------
- ODBoolean SetupEditorMenu(ODType kind,
- EditorSet* editorList,
- MenuHandle editorMenu,
- ControlHandle popupCtlHndl,
- ODSession* session)
- {
- ODBoolean anyEditors = (editorList->GetEditorCount() > 0);
-
- Environment* ev = somGetGlobalEnvironment();
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
-
- // And remove all items from the editors menu
- DeleteAllMenuItems(editorMenu);
-
- // Get all editors supporting that kind; Preferred editor must be first
- if ( kind && !anyEditors)
- {
- ODEditor prefEditor = GetSysPrefEditorForKind(nsm, kind);
- if ( prefEditor )
- editorList->AddEditor(prefEditor);
- ODDisposePtr((ODPtr) prefEditor);
- anyEditors = GetAllEditorsForKind(nsm, kind, editorList);
- }
-
- if ( anyEditors )
- {
- AddEditorsToMenu(editorList, editorMenu, session);
- if ( popupCtlHndl )
- {
- SetControlMaximum(popupCtlHndl, editorList->GetEditorCount());
- HiliteControl(popupCtlHndl, kControlActive);
- }
- }
- else
- {
- // The editor popup should be inactive, remove all editors
- editorList->InitEditorSet();
- }
-
- if ( popupCtlHndl )
- {
- SetControlMinimum(popupCtlHndl, 1);
- SetControlValue(popupCtlHndl, 1);
- }
-
- return anyEditors;
- }
- #endif
-
- //------------------------------------------------------------------------------
- // AddEditorsToMenu
- //------------------------------------------------------------------------------
-
- void AddEditorsToMenu(EditorSet* editorList,
- MenuHandle editorMenu,
- ODSession* session)
- {
- ODName* name;
- Str255 pEditorString;
- ODSShort item = 0;
- Environment* ev = somGetGlobalEnvironment();
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
-
- EditorSetIterator* editorIter = editorList->CreateIterator();
-
- for (ODType editor = editorIter->First();
- editorIter->IsNotComplete();
- editor = editorIter->Next())
- {
- if (GetUserEditorFromEditor(nsm, editor, &name))
- {
- TempODName tempName = name; // DMc: ensure it's deleted
- IntlToPStr(name, pEditorString);
- InsertMenuItem(editorMenu, pEditorString, item);
- EnableItem(editorMenu, ++item);
- // comments for SetPopupItemScript say don't call unless the script
- // needs setting, but there's no way to test that here. Sounds like
- // an optimization to me....
- SetPopupItemScript( editorMenu, item, GetITextScriptCode(name) );
- }
- else
- {
- // Special menu item in italics
- CUsingLibraryResources r;
- GetIndString(pEditorString, kODInfoUtilStrsID, kODStrIndNoEditors);
-
- InsertMenuItem(editorMenu, pEditorString, item);
- DisableItem(editorMenu, ++item);
- }
- }
-
- ODDeleteObject( editorIter );
- }
-
- //------------------------------------------------------------------------------
- // GetThisEditorFromList
- //------------------------------------------------------------------------------
- ODEditor GetThisEditorFromList(ODSShort editorIndex, EditorSet* editorList)
- {
- ODEditor result = kODNULL;
-
- if ( editorIndex > 0 )
- {
- ODEditor editor;
- EditorSetIterator* iter = editorList->CreateIterator();
-
- for ( editor = iter->First();
- (--editorIndex > 0) && iter->IsNotComplete();
- editor = iter->Next() )
- {
- }
-
- delete iter;
-
- if ( editor != kODNULL )
- result = ODISOStrFromCStr((char *) editor);
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // IndexOfEditorInList
- //------------------------------------------------------------------------------
- ODSShort IndexOfEditorInList(EditorSet* editorList, ODEditor editor)
- {
- ODSShort retVal = 0;
-
- if ( editorList->GetEditorCount() )
- {
- ODSShort i = 1;
- EditorSetIterator* editorIter = editorList->CreateIterator();
-
- for (ODEditor anEditor = editorIter->First();
- editorIter->IsNotComplete();
- anEditor = editorIter->Next())
- {
- if ( (anEditor == editor) || ODISOStrEqual(anEditor, editor) )
- {
- retVal = i;
- break;
- }
- i++;
- }
-
- ODDeleteObject( editorIter );
- }
-
- return retVal;
- }
-
- //------------------------------------------------------------------------------
- // IndexOfKindInList
- //------------------------------------------------------------------------------
- ODSShort IndexOfKindInList(ODTypeList* kindList, ODType kind)
- {
- ODSShort retVal = 0;
-
- Environment* ev = somGetGlobalEnvironment();
-
- if ( kindList->Count(ev) )
- {
- ODSShort i = 1;
- ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
-
- TRY
-
- for (ODType type = kindIter->First(ev);
- kindIter->IsNotComplete(ev);
- type = kindIter->Next(ev), i++)
- {
- if ( ODISOStrEqual(type, kind) )
- retVal = i;
- ODDisposePtr(type);
- if ( retVal != 0 )
- break;
- }
-
- CATCH_ALL
- ODDeleteObject(kindIter);
- RERAISE;
- ENDTRY
-
- ODDeleteObject(kindIter);
- }
-
- return retVal;
- }
-
- //------------------------------------------------------------------------------
- // GetThisKindFromList
- //------------------------------------------------------------------------------
- ODType GetThisKindFromList(ODSShort kindItem, ODTypeList* kindList)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODType type = kODNULL;
- ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
-
- for ( type = kindIter->First(ev);
- (--kindItem > 0) && kindIter->IsNotComplete(ev);
- type = kindIter->Next(ev) )
- {
- ODDisposePtr(type);
- type = kODNULL;
- }
-
- ODDeleteObject(kindIter);
-
- return type;
- }
-
-
- //------------------------------------------------------------------------------
- // ContentValueTypes
- //------------------------------------------------------------------------------
- void ContentValueTypes(ODStorageUnit* contentSU, ODTypeList* typeList)
- {
- TempODType hfsType = kODNULL;
-
- TRY
- ODULong count;
- ODULong index;
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODTranslation* translation = contentSU->GetSession(ev)->GetTranslation(ev);
- hfsType = translation->GetISOTypeFromPlatformType(ev, kODFileType_hfs, kODPlatformDataType);
-
- contentSU->Focus(ev, kODPropContents, kODPosUndefined, 0, 0, kODPosUndefined);
- count = contentSU->CountValues(ev);
- for (index = 1; index <= count; ++index)
- {
- contentSU->Focus(ev, kODPropContents, kODPosUndefined, 0, index, kODPosUndefined);
- TempODType type = contentSU->GetType(ev);
- if ( !ODISOStrEqual(type, hfsType) )
- typeList->AddLast(ev, type);
- }
- CATCH_ALL
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODUserRenameFile
- //------------------------------------------------------------------------------
-
-
- ODStatic ODBoolean ODUserRenameFile(Environment* ev,
- ODSession* session,
- PlatformFile* usersFile,
- ODIText* name,
- DescType replaceOption)
- {
- ODBoolean fileRenamed = kODFalse;
-
- // name to aStr255
- Str255 aStr255;
-
- GetITextPString(name, aStr255);
-
- TRY
- usersFile->Rename(aStr255);
- fileRenamed = kODTrue;
- CATCH_ALL
- if (ErrorCode() == dupFNErr)
- {
- switch (replaceOption) {
- case kAEAsk:
- ParamText(aStr255, "\p","\p","\p");
- fileRenamed = ODAskUserReplace(ev, session);
- if (!fileRenamed)
- THROW(userCanceledErr);
- break;
- case kAEYes:
- fileRenamed = kODTrue; break;
- case kAENo:
- fileRenamed = kODFalse; break;
- }
-
- if (fileRenamed)
- {
- ODFileSpec fsspec = usersFile->GetFileSpec();
- ODError result = HDelete(fsspec.vRefNum,fsspec.parID,aStr255);
- if ( result!=wPrErr && result!=fLckdErr &&
- result!=fBsyErr && result!=afpAccessDenied )
- {
- TRY
- usersFile->Rename(aStr255);
- CATCH_ALL
- WARN("File renaming failed, err %ld",ErrorCode());
- fileRenamed = kODFalse;
- ENDTRY
- }
- else
- {
- fileRenamed = kODFalse;
- if (replaceOption == kAEAsk)
- switch(result)
- {
- case wPrErr:
- case fLckdErr:
- case fBsyErr:
- {
- CUsingLibraryResources res;
- StopAlert(kFilelockedAlrtID, GetODDialogFilter());
- break;
- }
- default:
- SysBeep(2);
- }
- else
- SysBeep(2);
- }
- }
- }
- else
- RERAISE;
- ENDTRY
- return( fileRenamed );
- }
-
- //------------------------------------------------------------------------------
- // ODAskUserReplace
- //------------------------------------------------------------------------------
-
- ODBoolean ODAskUserReplace(Environment* ev,
- ODSession* session)
- // Pass in the name in question via ParamText(^0).
- {
- CUsingLibraryResources r;
- ODBoolean doReplace = kODFalse;
- short itemHit = 0;
- DialogPtr dlg = ODGetNewDialog(ev, kNameConflictDlgID,
- session, kODFalse );
- if (dlg)
- {
- Handle scratchHandle = kODNULL;
- Rect scratchRect;
-
- SetPort(dlg);
-
- // Set the draw routine for the default button outline item
- GetDialogItem(dlg, kNameConflictDefaultButtonItem, &itemHit, &scratchHandle, &scratchRect);
- SetDialogItem(dlg, kNameConflictDefaultButtonItem, itemHit,
- (Handle)GetODOutlineDefaultButtonDrawProc(), &scratchRect);
-
- ShowWindow(dlg);
-
- do {
- ModalDialog(GetODDialogFilter(), &itemHit);
- switch(itemHit)
- {
- case kNameConflictReplaceBtn:
- doReplace = kODTrue;
- break;
- case kNameConflictCancelBtn:
- break;
- }
- } while ((itemHit != kNameConflictReplaceBtn) &&
- (itemHit != kNameConflictCancelBtn));
-
- ODDisposeDialog(dlg);
- }
- return doReplace;
- }
-
- //------------------------------------------------------------------------------
- // CommentsDontMatch
- //
- // This compares 2 ODIText strings to see if they match and returns TRUE if
- // they do not match. It take into account the fact that the comments field
- // of the desktop database clips its string to 200 characters.
- //
- // Returns false if the strings are identical but the script/language are
- // not. This is because these values in dtComments have been set using
- // system defaults while those in propComments were actually saved, and
- // should therefore take precedence. <eeh>
- //
- // propComments can be NULL, dtComments cannot
- //------------------------------------------------------------------------------
-
- ODBoolean
- CommentsDontMatch(ODIText* dtComments, ODIText* propComments)
- {
- ODBoolean result;
- ODULong dtLen, propLen;
- Str255 dtStr, propStr;
-
- if (dtComments != kODNULL)
- dtLen = GetITextStringLength(dtComments);
- else
- dtLen = 0;
- if (propComments == kODNULL)
- return (dtLen != 0);
- propLen = GetITextStringLength(propComments);
- if (dtLen == 0)
- return (propLen != 0);
-
- // if either string is length 0 (or NULL) we won't get here
- WASSERT(dtComments && propComments);
- result = kODTrue;
-
- // because the Finder does not store script and language with the
- // comments or file names, we ignore these in comparing strings. That
- // is, if the strings are identical byte-for-byte, we consider them
- // to be equal. That way, the string *we* stored will be used, as will
- // the script and language information we stored with it.
-
- ODBoolean lengthsMatch =
- (dtLen == propLen) || (dtLen == 200 && propLen >= 200);
- if ( lengthsMatch )
- {
- GetITextPString(dtComments, (StringPtr) &dtStr);
- GetITextPString(propComments, (StringPtr) &propStr);
- propStr[0] = dtStr[0]; // fix the 200 case
- result = !EqualString( dtStr, propStr, kODTrue, kODTrue );
- }
- return result;
-
- }
-
-
- void SetAllWindowShowLinks(Environment* ev, ODWindowState* winState, ODBoolean showLinks)
- {
- ODWindowIterator* iter = kODNULL; ODVolatile(iter);
-
- TRY
-
- iter = winState->CreateWindowIterator(ev);
-
- for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
- window = iter->Next(ev))
- {
- if (window)
- {
- window->SetShouldShowLinks(ev, showLinks);
- ODFrame* root = window->GetRootFrame(ev);
- root->Invalidate(ev, kODNULL, kODNULL);
- }
- }
- ODDeleteObject(iter);
-
-
- CATCH_ALL
-
- ODDeleteObject(iter);
- RERAISE;
-
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // TranslateValueTypes
- //------------------------------------------------------------------------------
- void TranslateValueTypes(
- ODTypeList* kindList,
- ODTypeList* translateToList,
- OrderedCollection* translateFromList,
- ODSession* session)
- {
- Environment* ev = somGetGlobalEnvironment();
-
- ODTranslation* translation = session->GetTranslation(ev);
-
- ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
-
- ODUShort kindIndex = 0;
-
- for (ODType kind = kindIter->First(ev);
- kindIter->IsNotComplete(ev);
- kind = kindIter->Next(ev))
- {
- ++kindIndex;
-
- TRY
- ODTypeList* toList = translation->GetTranslationOf(ev, kind);
-
- ODTypeListIterator* toIter = toList->CreateTypeListIterator(ev);
-
- for (ODType toKind = toIter->First(ev);
- toIter->IsNotComplete(ev);
- toKind = toIter->Next(ev))
- {
- TRY
-
- if ( (kindList->Contains(ev, toKind) == kODFalse)
- &&
- (translateToList->Contains(ev, toKind) == kODFalse)
- )
- {
- translateToList->AddLast(ev, toKind);
- translateFromList->AddLast((void*) kindIndex);
- }
-
- CATCH_ALL
- ENDTRY
- ODDisposePtr(toKind);
- }
- delete toIter;
- delete toList;
-
- CATCH_ALL
- ENDTRY
-
- ODDisposePtr(kind);
- }
- delete kindIter;
- }
-
- //------------------------------------------------------------------------------
- // StringPtrFromStrHandle
- //------------------------------------------------------------------------------
-
- ODStatic StringPtr StringPtrFromStrHandle(StringHandle strHandle)
- {
- StringPtr result = kODNULL;
-
- if ( strHandle )
- {
- ODULong size = GetHandleSize((Handle) strHandle);
- StringPtr strPtr = (StringPtr) ODLockHandle((ODHandle) strHandle);
- result = (StringPtr) ODNewPtr(size);
- ODBlockMove(strPtr, result, size);
- ODUnlockHandle((ODHandle) strHandle);
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // DefaultMenuStringForKind
- //------------------------------------------------------------------------------
-
- ODStatic StringPtr DefaultMenuStringForKind()
- {
- CUsingLibraryResources r;
-
- StringPtr result = kODNULL;
-
- StringHandle strHandle = GetString(kODPartInfoStrUnknownID);
- if ( strHandle )
- {
- result = StringPtrFromStrHandle(strHandle);
- ReleaseResource((Handle) strHandle);
- }
- else
- {
- strHandle = NewString("\p");
- result = StringPtrFromStrHandle(strHandle);
- ODDisposeHandle((ODHandle) strHandle);
- }
- return result;
- }
-
- //------------------------------------------------------------------------------
- // GetMenuStringForKind
- //------------------------------------------------------------------------------
-
- ODStatic void GetMenuStringForKind(
- ODSession* session,
- ODType kind,
- StringPtr* itemString,
- ODScriptCode* itemScript)
- {
- ODName* name;
- Environment* ev = somGetGlobalEnvironment();
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
-
- if ( GetUserKindFromKind(nsm, kind, &name) )
- {
- TempODName tempName = name; // DMc: ensure it's deleted
- *itemString = (StringPtr) ODNewPtr(GetITextStringLength(name)+1);
- IntlToPStr(name, *itemString);
- *itemScript = GetITextScriptCode(name);
- }
- else
- {
- // No available editors support this kind
- ODTranslation* translation = session->GetTranslation(ev);
- ODPlatformType platformType = translation->GetPlatformTypeFromISOType(ev, kind);
- if ( platformType != kODNULL )
- {
- *itemString = (StringPtr) ODNewPtr(sizeof(ODPlatformType) + 1);
- ODBlockMove(&platformType, &((*itemString)[1]), (ODULong) sizeof(ODPlatformType));
- (*itemString)[0] = (unsigned char) sizeof(ODPlatformType);
- }
- else
- {
- *itemString = DefaultMenuStringForKind();
- }
- *itemScript = smSystemScript;
- }
- }
-
- //------------------------------------------------------------------------------
- // AddTranslationKindToMenu
- //------------------------------------------------------------------------------
-
- void AddTranslationKindToMenu(
- ODType kind,
- MenuHandle kindMenu,
- short item,
- ODBoolean insert,
- ODSession* session)
- {
- StringPtr itemString;
- ODScriptCode itemScript;
-
- GetMenuStringForKind(session, kind, &itemString, &itemScript);
- TempODString tempItemString = (char*) itemString; // DMc: ensure it's deleted
-
- if ( insert )
- {
- InsertMenuItem(kindMenu, itemString, item);
- item += 1;
- }
- else
- SetMenuItemText(kindMenu, item, itemString);
-
- SetPopupItemScript(kindMenu, item, itemScript);
- }
-
- //------------------------------------------------------------------------------
- // GetTypeListItem
- //------------------------------------------------------------------------------
-
- ODType GetTypeListItem(ODTypeList* typeList, ODUShort index)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODType theType = kODNULL;
-
- if ( index > 0 )
- {
- ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
-
- for (theType = typeIter->First(ev);
- (typeIter->IsNotComplete(ev)) && (index > 1);
- theType = typeIter->Next(ev), --index)
- {
- ODDisposePtr(theType);
- }
-
- delete typeIter;
- }
-
- return theType;
- }
-
-