home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Info.cpp
-
- Contains: implementation of the Info object including ShowPartFrameInfo
-
- Owned by: Ed Lai
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <18> 6/22/96 EL 1344140: dialogLib's ShowPartFrameInfo now
- returns ODError.
- <17> 6/21/96 jpa T10002: Changed min/default heap size.
- (Also improved debug msg from
- GetSharedLibrary.)
- <16> 6/7/96 eeh T10017: function ptrs must be extern C
- <15> 6/7/96 eeh T10017: use current architecture
- <14> 6/7/96 eeh T10017: return CFM errors
- <13> 6/7/96 eeh T10017: move most dlg stuff to InfoDlg.cpp
- <12> 6/5/96 EL 1355529: Use menu item count to determine
- the translation menu item.
- <11> 6/4/96 EL 1323543: Remove some unneeded comment from
- last check in.
- <10> 6/4/96 EL 1323543: Bundled checkbox is now two radio
- buttons. 1289557: Alert for bad file name
- and comment too long.
- <9> 5/30/96 CC 1299865: ShowPartFrameInfo: If the kind
- popup is changed, keep the same editor
- unless it doesn't support the new kind.
- <8> 5/29/96 TJ Worked around temp var scoping problem.
- <7> 5/28/96 EL #1234149: Remove staticText covering
- checkbox so that checkbox can be shown as
- dimmed for read only document.
- <6> 5/24/96 jpa 1246074: Fix SOM_CATCH. Also: Disable CW
- optimizer on GetPartFrameInfo to avoid CW8
- compiler crashes.
- <5> 5/22/96 EL #1263100: If cancel out of SynchNSTable,
- reraise the error.
- <4> 5/3/96 EL 1313942: release settings extension before
- editor is swapped. 1329522: document info
- size dialog button will be inverted on
- mouse down to give user feedback.
- <3> 3/20/96 EL 1289563: for read-only field from read-only
- documents, disallow editing. Allow viewing
- of heap size info from read-only document
- but don't allow editing.
- <2> 1/12/96 CC 1302700: ShowPartFrameInfo: Show part id if
- frame is non-persistent.
- 1295846: ShowPartFrameInfo: ASSERT that
- part is a part wrapper.
-
- In Progress:
-
- */
-
- #define _USE_DIALOGS_LIB_
-
- #define ODInfo_Class_Source
- #define VARIABLE_MACROS
- #include <Info.xih>
-
- #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_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef _INFODEFS_
- #include <InfoDefs.h>
- #endif
-
- #ifndef _PREFS_
- #include "Prefs.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.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_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODSettingsExtension_xh
- #include <Settings.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
- #include <StdExts.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef SOM_ODTypeListIterator_xh
- #include <TypLsItr.xh>
- #endif
-
- #ifndef _BINDNGH_
- #include <BindngH.h>
- #endif
-
- #ifndef _BNDNSUTL_
- #include <BndNSUtl.h>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _EDITRSET_
- #include <EditrSet.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.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 __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
-
- #ifndef SOM_ODPartWrapper_xh
- #include <PartWrap.xh>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef __PALETTES__
- #include <Palettes.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef _TRANSUTL_
- #include <TransUtl.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #pragma segment ODInfo
-
- #ifdef _USE_DIALOGS_LIB_
-
- //==============================================================================
- // InitInfo
- //==============================================================================
-
- SOM_Scope void SOMLINK ODInfoInitInfo(ODInfo *somSelf, Environment *ev,
- ODSession* session)
- {
- ODInfoData *somThis = ODInfoGetData(somSelf);
- ODInfoMethodDebug("ODInfo","ODInfoInitInfo");
-
- _fSession = session;
- // gSession = _fSession;
- }
-
- //==============================================================================
- // ShowPartFrameInfo
- //==============================================================================
-
- static pascal ODBoolean CallCheckScriptFirstThenStdFilterProc( DialogPtr dialog,
- EventRecord *event, short *itemHit)
- {
- return CheckKeyScriptChangeFilterProc( dialog, event, itemHit )
- || ODDialogFilterProc( dialog, event, itemHit );
- }
-
- // <eeh> this ought to be moved to a utility file at some point
- OSErr LoadODSharedLibrary( Str63 libName, Str255 entryName,
- CFragConnectionID* connID, void** entryPoint );
- OSErr LoadODSharedLibrary( Str63 libName, Str255 entryName,
- CFragConnectionID* connID, void** entryPoint )
- {
- Ptr ignore;
- Str255 errName;
- // CFragConnectionID connID;
-
- OSErr err = GetSharedLibrary( libName, kCurrentCFragArch, 1, connID,
- &ignore, errName );
- if ( err == noErr )
- {
- CFragSymbolClass symClass;
- err = FindSymbol( *connID, entryName, (Ptr*)entryPoint, &symClass );
- if ( err == noErr )
- WASSERT( symClass == kTVectorCFragSymbol );
- else
- {
- WARN( "Didn't find symbol address" );
- *entryPoint = kODNULL;
- }
- }
- else
- {
- #if ODDebug
- PascalToCString( errName );
- WARN( "GetSharedLibrary returned error %d '%s'", err, errName );
- #endif
- }
-
- return err;
- }
-
- void UnloadODSharedLibrary( CFragConnectionID* connID );
- void UnloadODSharedLibrary( CFragConnectionID* connID )
- {
- OSErr err = CloseConnection( connID );
- WASSERT( err == noErr );
- }
-
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef ODError (*InfoDialogEntry)( Environment *ev,
- ODSession* session, ODFacet* facet, ODBoolean allowEditing);
- #ifdef __cplusplus
- }
- #endif
-
- SOM_Scope ODBoolean SOMLINK ODInfoShowPartFrameInfo(ODInfo *somSelf, Environment *ev,
- ODFacet* facet, ODBoolean allowEditing)
- {
- ODInfoData *somThis = ODInfoGetData(somSelf);
- ODInfoMethodDebug("ODInfo","ODInfoShowPartFrameInfo");
-
- // already volatile since address taken....
- InfoDialogEntry ide = kODNULL; ODVolatile( ide );
- CFragConnectionID connID; ODVolatile( connID );
- ODBoolean result = kODFalse; ODVolatile(result);
-
- SOM_TRY
- ODError error = 0;
- THROW_IF_ERROR( LoadODSharedLibrary( "\pDialogsLib",
- "\pShowPartFrameInfo", &connID, (void**)&ide ) );
- error = (*ide)( ev, _fSession, facet, allowEditing );
- if (error && (error != userCanceledErr))
- THROW(error);
- UnloadODSharedLibrary( &connID );
- result = kODTrue;
- SOM_CATCH_ALL
- if ( ide != kODNULL ) // we loaded the library
- UnloadODSharedLibrary( &connID );
- // reraise happens automatically
- SOM_ENDTRY
- return result;
- }
-
- SOM_Scope void SOMLINK ODInfosomUninit(ODInfo *somSelf)
- {
- //ODInfoData *somThis = ODInfoGetData(somSelf);
- ODInfoMethodDebug("ODInfo","ODInfosomUninit");
-
- ODInfo_parent_ODObject_somUninit(somSelf);
- }
-
- #else
-
- //=========================================================================
- // Globals
- //=========================================================================
-
- static ODSession* gSession; // For use in Dialog Filter Proc
- static ODFrame* gFrame; // For use in Dialog Filter Proc
- static ODName* gKindName;
-
- // For use in Document Heap Dialog Filter Proc
- static ODHandle gArrowBtnsPictOff;
- static ODHandle gArrowBtnsPictTopOn;
- static ODHandle gArrowBtnsPictBotOn;
-
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const short kControlInactive = 255;
-
- //==============================================================================
- // Scalar types
- //==============================================================================
-
- typedef char ODHandleState;
- struct DrawProcInfoStruct {
- ODIText* authorName;
- ODIText* category;
- };
- typedef struct DrawProcInfoStruct DrawProcInfoStruct, *DrawProcInfo;
-
- //==============================================================================
- // Function Prototypes
- //==============================================================================
-
- ODStatic void SetCategory( ODPart* part,
- Handle categoryItem,
- ODNameSpaceManager* nsm);
-
- ODStatic void InitEditorPopup(EditorSet* editorList,
- ODEditor editorID,
- ControlHandle itemHandle,
- ODSShort* currentEditorItem,
- MenuHandle editorMenu);
-
- ODStatic void GenerateEditorsList(ODSShort currentKindItem, ODTypeList* kindsList,
- EditorSet* editorList,
- ODNameSpaceManager* nsm);
-
- ODStatic void SetSizeText(DialogPtr dlg, ODSShort item, ODULong size);
-
- ODStatic void SetModifiedByText(DialogPtr dlg, ODSShort item, ODName* name);
-
- ODStatic ODBoolean GetDialogBoolean(DialogPtr dlg, short itemNo);
- ODStatic void SetDialogBoolean(DialogPtr dlg, short itemNo, ODBoolean bool, ODBoolean active);
- ODStatic void SetDialogItemHandle(DialogPtr dlg, short itemNo, Handle itemHandle);
- ODStatic void GetPStrFromDialog(DialogPtr dlg, short itemNo, Str255 pStr);
- ODStatic void SetDialogFromPStr(DialogPtr dlg, short itemNo, Str255 pStr, ODBoolean editable, ODBoolean selectIt);
- ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue);
-
- ODStatic void SetModCreatDateTimeText( Environment* ev, ODStorageUnit* partSU);
-
- ODStatic pascal void DrawThumbnail(DialogPtr theDialog, short theItem);
-
- ODStatic pascal void DrawIntlStaticText(DialogPtr dialog, SInt16 item);
-
- ODStatic void DeleteAllMenuItems(MenuHandle theMenu);
-
- ODStatic ODIText* PickOneIText( ODIText* itext1, ODIText* itext2 );
- ODStatic ODScriptCode GetRealScriptCode( ODIText* itext );
-
- //------------------------------------------------------------------------------
- // Document Heap Dialog Prototypes
- //------------------------------------------------------------------------------
-
- ODStatic void ShowSizeDialog(Environment* ev, ODSession* session,
- PlatformFile* file, Str255 partNameS255, ODBoolean allowEditing);
- ODStatic ODULong DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID);
- ODStatic void DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID,
- PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes);
-
- ODStatic ODULong DHGetODDefaultHeapSize();
- ODStatic void DHSetODDefaultHeapSize(PlatformFile* documentFile, ODULong numKBytes);
- ODStatic ODULong DHGetDocumentPreferredHeapSize(PlatformFile* file);
- ODStatic void DHClearDocumentPreferredHeapSize(PlatformFile* file);
- ODStatic void DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes);
-
- //==============================================================================
- // InitInfo
- //==============================================================================
-
- SOM_Scope void SOMLINK ODInfoInitInfo(ODInfo *somSelf, Environment *ev,
- ODSession* session)
- {
- ODInfoData *somThis = ODInfoGetData(somSelf);
- ODInfoMethodDebug("ODInfo","ODInfoInitInfo");
-
- _fSession = session;
- gSession = _fSession;
- }
-
- //==============================================================================
- // NewKindPopup
- //==============================================================================
-
- static ODTypeList* NewKindPopup(Environment *ev,
- ODPartWrapper* part,
- ControlHandle popupHandle,
- MenuHandle kindMenu,
- ODSShort* currentKindItem,
- ODSShort* translateItem)
- {
- ODStorageUnit* partSU = part->GetStorageUnit(ev);
- ODSession* session = partSU->GetSession(ev);
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
-
- TempODType theKind = kODNULL;
-
- ODTypeList* kindList = session->GetStorageSystem(ev)->CreateTypeList(ev,(ODTypeList*)kODNULL);
-
- ContentValueTypes(partSU, kindList);
-
- TempODEditor editorID = part->GetEditor(ev);
- GetAllKindsForEditor(nsm, kindList, editorID);
- theKind = ODGetKindFromPartSU(ev, partSU);
- InitKindsPopup(kindList, theKind, popupHandle, currentKindItem, kindMenu, translateItem, gSession);
-
- return kindList;
- }
-
-
- //==============================================================================
- // NewEditorPopup
- //==============================================================================
-
- static EditorSet* NewEditorPopup(Environment *ev,
- ODPartWrapper* part,
- ControlHandle popupHandle,
- MenuHandle editorMenu,
- ODTypeList* kindList,
- ODSShort currentKindItem,
- ODEditor editorID,
- ODSShort* currentEditorItem)
- {
- ODSession* session = part->GetStorageUnit(ev)->GetSession(ev);
-
- EditorSet* editorsList = new EditorSet;
- THROW_IF_NULL(editorsList);
- editorsList->InitEditorSet();
-
- TempODType initialKind = GetTypeListItem(kindList, currentKindItem);
- if ( initialKind ) {
- SetupEditorMenu(initialKind, editorsList, editorMenu, popupHandle, session);
-
- // determine which editor to check mark
- ODSShort item = 1;
- EditorSetIterator* editorIter = editorsList->CreateIterator();
- for (ODEditor editor = editorIter->First();
- editorIter->IsNotComplete();
- editor = editorIter->Next(), ++item)
- {
- if (ODISOStrEqual(editor, editorID)) {
- *currentEditorItem = item;
- break;
- }
- }
- ODDeleteObject( editorIter);
- SetControlValue(popupHandle, item);
- }
-
- return editorsList;
- }
-
- //------------------------------------------------------------------------------
- // SetPopupControlValue
- //------------------------------------------------------------------------------
-
- ODStatic void SetPopupControlValue(ControlHandle popupControlHandle, short itemValue)
- {
- // The resource file must be in the chain in order for the popup to redraw.
- CUsingLibraryResources r;
- SetControlValue(popupControlHandle, itemValue);
- }
-
- // Here are a few utility for use with the dialog manager, it could be moved to
- // the utility if other dialogs are going to use them
-
- //------------------------------------------------------------------------------
- // GetDialogBoolean
- //------------------------------------------------------------------------------
-
- ODStatic ODBoolean GetDialogBoolean(DialogPtr dlg, short itemNo)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- return (ODBoolean)GetControlValue((ControlHandle)itemHandle);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogBoolean
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogBoolean(DialogPtr dlg, short itemNo, ODBoolean bool, ODBoolean active)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- SetControlValue((ControlHandle)itemHandle, bool);
- HiliteControl((ControlHandle)itemHandle, active ? 0:255);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogItemHandle
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogItemHandle(DialogPtr dlg, short itemNo, Handle itemHandle)
- {
- short itemType;
- Handle dummy;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &dummy, &scratchRect);
- SetDialogItem(dlg, itemNo, itemType, itemHandle, &scratchRect);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogItemAndUpdate
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogItemAndUpdate(DialogPtr dlg, short itemNo, Handle itemHandle)
- {
- short itemType;
- Handle dummy;
- Rect itemRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &dummy, &itemRect);
- if (itemHandle)
- SetDialogItem(dlg, itemNo, itemType, itemHandle, &itemRect);
-
- RgnHandle itemRgn = ODNewRgn();
- if (itemRgn) {
- RectRgn(itemRgn,&itemRect);
- UpdateDialog(dlg, itemRgn);
- ODDisposeHandle((Handle)itemRgn);
- }
- }
-
- //------------------------------------------------------------------------------
- // GetPStrFromDialog
- //------------------------------------------------------------------------------
-
- ODStatic void GetPStrFromDialog(DialogPtr dlg, short itemNo, Str255 pStr)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- GetDialogItemText(itemHandle, pStr);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogFromPStr
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogFromPStr(DialogPtr dlg, short itemNo, Str255 pStr, ODBoolean editable, ODBoolean selectIt)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- short newEditType = editable ? editText : statText;
- if ((itemType & (editText+statText)) != newEditType) { // dialog item type is not what we want
- SetDialogItem(dlg, itemNo, (itemDisable & itemType)+newEditType, itemHandle, &scratchRect);
- }
- SetDialogItemText(itemHandle, pStr);
- if (editable && selectIt)
- SelectDialogItemText(dlg, itemNo, 0, pStr[0]);
- }
-
- //------------------------------------------------------------------------------
- // GetITextFromDialog
- //------------------------------------------------------------------------------
-
- ODStatic ODIText* GetITextFromDialog(DialogPtr dlg, short itemNo, ODScriptCode script, ODLangCode lang)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- ODSize itemSize = GetHandleSize(itemHandle);
- return CreateIText( script, lang, (ODUByte*)*itemHandle, itemSize );
- }
-
- //------------------------------------------------------------------------------
- // SetDialogFromIText
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogFromIText(DialogPtr dlg, short itemNo, ODIText* iText, ODBoolean editable, ODBoolean selectIt)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
- ODSize itemSize;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- short newEditType = editable ? editText : statText;
- if ((itemType & (editText+statText)) != newEditType) { // dialog item type is not what we want
- SetDialogItem(dlg, itemNo, (itemDisable & itemType)+newEditType, itemHandle, &scratchRect);
- }
- if (iText)
- itemSize = GetITextStringLength(iText);
- else
- itemSize = 0;
- SetHandleSize(itemHandle, itemSize);
- if (iText)
- ODBlockMove(GetITextPtr(iText), *itemHandle, itemSize);
- if (selectIt)
- SelectDialogItemText(dlg, itemNo, 0, itemSize);
- }
-
- ODStatic ODBoolean ITextStrEqual(ODIText *text1, ODIText *text2)
- {
- ODSize len1 = 0;
- if (text1)
- len1 = GetITextStringLength(text1);
- ODSize len2 = 0;
- if (text2)
- len2 = GetITextStringLength(text2);
- if (len1 != len2)
- return 0;
- else if (len1 == 0)
- return kODTrue;
- else
- return (ODISOStrNCompare(GetITextPtr(text1),GetITextPtr(text2),len1) == 0);
- }
-
- //------------------------------------------------------------------------------
- // SetNumText
- //------------------------------------------------------------------------------
-
- ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- Str255 text;
-
- NumToString(numValue, text);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
- SetDialogItemText(itemHandle,text);
-
- }
-
- //------------------------------------------------------------------------------
- // GetOrderedCollectionElement
- //------------------------------------------------------------------------------
-
- ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index)
- {
- OrderedCollectionIterator* oci = collection->CreateIterator();
- THROW_IF_NULL(oci);
-
- ODUShort elem = 0;
-
- for ( elem = (ODUShort) oci->First();
- oci->IsNotComplete();
- elem = (ODUShort) oci->Next() )
- {
- if ( --index == 0 )
- break;
- }
-
- ODDeleteObject(oci);
-
- return elem;
- }
-
- //------------------------------------------------------------------------------
- // ODGetFirstCategoryOfKind
- //------------------------------------------------------------------------------
- ODStatic ODType ODGetFirstCategoryOfKind(Environment* ev, ODType kind, ODNameSpaceManager* nsm)
- {
- ODTypeList* categoryList = GetCategoriesOfKind(nsm, kind);
- ODTypeListIterator* catIter = kODNULL;
- ODType category = kODNULL;
-
- if (categoryList)
- {
- catIter = categoryList->CreateTypeListIterator(ev);
- category = catIter->First(ev);
- ODDeleteObject(catIter);
- }
-
- return category;
- }
-
- //==============================================================================
- // ShowPartFrameInfo
- //==============================================================================
-
- static pascal ODBoolean CallCheckScriptFirstThenStdFilterProc( DialogPtr dialog,
- EventRecord *event, short *itemHit)
- {
- return CheckKeyScriptChangeFilterProc( dialog, event, itemHit )
- || ODDialogFilterProc( dialog, event, itemHit );
- }
-
- #ifdef __MWERKS__
- #if GENERATINGPOWERPC
- #if __option(global_optimizer)
- // Turn optimization down to level 4 to avoid out-of-memory errors on this very long fn
- #pragma push
- #pragma optimization_level 1
- #endif
- #endif
- #endif
-
- SOM_Scope ODBoolean SOMLINK ODInfoShowPartFrameInfo(ODInfo *somSelf, Environment *ev,
- ODFacet* facet, ODBoolean allowEditing)
- {
- //ODInfoData *somThis = ODInfoGetData(somSelf);
- ODInfoMethodDebug("ODInfo","ODInfoShowPartFrameInfo");
-
- short itemHit = kPartInfoCancelBtn;
-
- SOM_TRY
-
- gArrowBtnsPictOff =
- ODReadResource(kPICTRsrcType, kArrowBtnsPictOffID);
- gArrowBtnsPictTopOn =
- ODReadResource(kPICTRsrcType, kArrowBtnsPictTopOnID);
- gArrowBtnsPictBotOn =
- ODReadResource(kPICTRsrcType, kArrowBtnsPictBotOnID);
-
-
- DialogPtr dlg = kODNULL; ODVolatile(dlg);
- Handle itemHandle = kODNULL;
- Handle scratchHandle = kODNULL;
- MenuHandle editorMenu = kODNULL;
- MenuHandle kindMenu = kODNULL;
- Rect scratchRect;
- ODSShort itemType;
- Str255 aStr255 = "\p",
- partNameS255 = "\p",
- partCommentsS255 = "\p";
- ODError result = noErr;
- ODSShort popUpValue = 0;
- ODSShort currentKindItem = 0;
- ODUShort translateToIndex = 0; // Index in translateToList of currently chosen kind
- ODUShort translateToItem = 0; // Item of the Kind popup showing translate to choice
- ODSShort translateItem = 0; // Item of the Kind popup that opens translation dialog
- ODSShort currentEditorItem = 0;
- ODUShort viewval = 0;
-
- ControlHandle kindPopupControlHandle;
- ControlHandle editorPopupControlHandle;
-
- Rect partInfoCategoryRect;
-
- ODBoolean isRootPart = kODFalse;
- ODBoolean frameIsFrozen = kODFalse;
- ODBoolean isRootPartOfDocument = kODFalse;
- ODBoolean showLinks = kODFalse;
- ODBoolean isStationary = kODFalse;
-
- ODNameSpaceManager* nsm = kODNULL;
- ODStorageUnit* partSU = kODNULL;
- ODFrame* frame = kODNULL;
- ODDraft* draft = kODNULL;
- PlatformFile* usersFile = kODNULL; ODVolatile(usersFile);
- ODWindow* window = kODNULL;
- ODSession* session = kODNULL;
- ODWindowState* winstate = kODNULL; ODVolatile(winstate);
-
- ODName* partName = kODNULL; ODVolatile(partName);
-
- ODTypeList* kindList = kODNULL; ODVolatile(kindList);
- ODTypeList* translateToList = kODNULL; ODVolatile(translateToList);
- OrderedCollection* translateFromList = kODNULL; ODVolatile(translateFromList);
- EditorSet* editorsList = kODNULL; ODVolatile(editorsList);
- ODSettingsExtension* settings = kODNULL; ODVolatile(settings);
-
- UserItemUPP DrawBoxItemUPP = kODNULL;
- UserItemUPP DrawThumbnailUPP = kODNULL;
- UserItemUPP DrawIntlStaticTextUPP = kODNULL;
-
- ODScriptCode script = smCurrentScript;
- DialogScriptData dsd;
- ModalFilterUPP modalFilter = kODNULL; ODVolatile(modalFilter);
- DrawProcInfoStruct dpis;
- dpis.category = kODNULL;
- dpis.authorName = kODNULL;
-
- ODError error = noErr;
-
- frame = facet->GetFrame(ev);
- TempODPart part = frame->AcquirePart(ev);
-
- ASSERT(!part->IsRealPart(ev), kODErrPartNotWrapper);
-
- session = part->GetStorageUnit(ev)->GetSession(ev);
-
- // Need to load latest nmaps before CUsingLibraryResources
-
- TRY {
- nsm = session->GetNameSpaceManager(ev);
- nsm->SynchNSTable(ev);
- }CATCH_ALL{
- if( ErrorCode()==userCanceledErr)
- RERAISE;
- }ENDTRY
-
- // Need to make sure that the ODReadResource calls happen BEFORE the resource fork is
- // put in use and left in use by the below CUsingLibraryResources.
-
- {CUsingLibraryResources res;
-
- TRY
- winstate = session->GetWindowState(ev);
-
- gFrame = frame;
- partSU = part->GetStorageUnit(ev);
- draft = partSU->GetDraft(ev); // needed for GetPersistentObjectID
- //! is externalization really necessary? the problems is that this cause the document
- //! to be dirty when in most case all the user did was take a peek at the info
- if (HAS_WRITE_ACCESS(draft->GetPermissions(ev)))
- part->Externalize(ev); // Externalize the part so current editor can remove obsolete kinds [cc]
-
- window = facet->GetWindow(ev); // needed for ShouldShowLinks
-
- {
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- isRootPart = ( containingFrame == kODNULL );
- isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
- }
-
- winstate->DeactivateFrontWindows(ev);
-
- dlg = ODGetNewDialog(ev,kPartInfoDlgID,session);
- THROW_IF_NULL(dlg);
-
- if (allowEditing) // we need to hide the message that is for read only document
- HideDialogItem(dlg, kPartNoChangeStatText);
-
- if (isRootPartOfDocument)
- {
- StringHandle str = GetString(kODDocumentInfoWindowName);
- ODLockHandle((ODHandle) str);
- SetWTitle(dlg,(StringPtr)*str);
- ODUnlockHandle((ODHandle) str);
- ReleaseResource((Handle) str);
- usersFile =
- GetPlatformFileFromContainer(ev, draft->GetDocument(ev)->GetContainer(ev));
- }
-
- // Set the draw routine for the default button outline item
- SetDialogItemHandle(dlg, kPartInfoDefaultButtonItem, (Handle)GetODOutlineDefaultButtonDrawProc());
-
- /* separator lines need to be drawn */
- DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
-
- SetDialogItemHandle(dlg, kPartInfoSep1, (Handle)DrawBoxItemUPP);
-
- SetDialogItemHandle(dlg, kPartInfoSep2, (Handle)DrawBoxItemUPP);
-
- // Set up Thumbnail
- DrawThumbnailUPP = NewUserItemProc(DrawThumbnail);
- SetDialogItemHandle(dlg, kPartInfoPartThumbnail, (Handle)DrawThumbnailUPP);
-
- // Set up Name
- partName = ODGetPartName(ev, frame, kODNULL);
- if (partName != kODNULL)
- IntlToPStr(partName,(StringPtr)&partNameS255);
- SetDialogFromIText(dlg, kPartInfoNameEditFld, partName, allowEditing, allowEditing);
-
- // set up Comments
- TempODName tempPartComments = ODGetComments(ev, frame, kODNULL);
- SetDialogFromIText(dlg, kPartInfoCommentsEditFld, tempPartComments, allowEditing, kODFalse);
-
- // get binding object & editorID
- ODBinding* binding = session->GetBinding(ev);
- ODPart* partw = part;
- TempODEditor editorID = ((ODPartWrapper*)partw)->GetEditor(ev);
-
- // set up Kind Menu
- GetDialogItem(dlg, kPartInfoKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &scratchRect);
- kindMenu = GetMenu(kPartInfoKindMenu);
- THROW_IF_NULL(kindMenu);
-
- kindList = NewKindPopup(ev,
- (ODPartWrapper*) partw,
- kindPopupControlHandle,
- kindMenu,
- ¤tKindItem,
- &translateItem);
-
- // set up possible translations
- // These are the translations from any kinds present in the storage unit,
- // plus all other kinds supported by the current editor.
- translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
- translateFromList = new OrderedCollection;
- THROW_IF_NULL(translateFromList);
- TranslateValueTypes(kindList, translateToList, translateFromList, session);
-
- // set up Category user item
- dpis.category = ODGetCategory(ev, part, nsm);
-
- SetDialogItemHandle(dlg, kPartInfoCategoryFld, (Handle)DrawThumbnailUPP);
-
- // set up Editor Menu
- GetDialogItem(dlg, kPartInfoEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &scratchRect);
- editorMenu = GetMenu(kPartInfoEditorMenu);
- THROW_IF_NULL(editorMenu);
-
- editorsList = NewEditorPopup(ev,
- (ODPartWrapper*) partw,
- editorPopupControlHandle,
- editorMenu,
- kindList,
- currentKindItem,
- editorID,
- ¤tEditorItem
- );
-
- if ( currentEditorItem > editorsList->GetEditorCount() )
- {
- HideDialogItem(dlg, kPartInfoEditorPopup);
- }
- else
- {
- HideDialogItem(dlg, kPartInfoEditorLabel);
- HideDialogItem(dlg, kPartInfoNoEditorText);
- }
- if (!allowEditing) {
- // disable everything but the current editor if no editing allowed
- for (ODUShort i=1;i<=CountMItems(editorMenu);i++) {
- if (currentEditorItem != i)
- DisableItem(editorMenu, i);
- }
- // disable everything but the current kind if no editing allowed
- for (ODUShort j=1;j<=CountMItems(kindMenu);j++) {
- if (currentKindItem != j)
- DisableItem(kindMenu, j);
- }
- }
-
- // set up size
- ODULong size = ODGetPOSize(ev, part);
- SetSizeText(dlg, kPartInfoSizeFld, size);
-
- // set up Create and Modify date and time
- SetModCreatDateTimeText( ev, partSU );
-
- // set up by
- SetDialogItemHandle(dlg, kPartInfoByFld, (Handle)DrawThumbnailUPP);
- dpis.authorName = ODGetModifiedBy( ev, partSU, kODNULL );
-
- WASSERT( !GetWRefCon(dlg) ); // will be null if no one's using it
- SetWRefCon(dlg, (long)&dpis);
-
- // set up the scripting ID
- // If the frame is non-persistent, show the part's scripting ID.
- // Note that the scripting ID is not the same as the object ID returned by the
- // persistent object's GetID method.
- ODPersistentObjectID id;
- if ( frame->GetStorageUnit(ev) != kODNULL )
- {
- id = draft->GetPersistentObjectID(ev,
- (ODPersistentObject*) frame,
- kODFrameObject);
- }
- else
- {
- id = draft->GetPersistentObjectID(ev,
- (ODPersistentObject*) part,
- kODPartObject);
- }
- SetNumText(dlg, kPartInfoIDFld, (ODSLong)id);
-
- // set up viewas
- GetDialogItem(dlg, kPartInfoViewAsPopup, &itemType, &itemHandle, &scratchRect);
-
- ODTypeToken view = frame->GetViewType(ev);
-
- if (view == session->Tokenize(ev, kODViewAsFrame))
- viewval = 1;
- else if (view == session->Tokenize(ev, kODViewAsLargeIcon))
- viewval = 2;
- else if (view == session->Tokenize(ev, kODViewAsSmallIcon))
- viewval = 3;
- else if (view == session->Tokenize(ev, kODViewAsThumbnail))
- viewval = 4;
-
- SetControlValue((ControlHandle)itemHandle, viewval);
- MenuHandle viewAsMenu = ((PopupPrivateData*)(*(**(ControlHandle)itemHandle).contrlData))->mHandle;
- if ((isRootPartOfDocument) || (!allowEditing)) {
- // disable everything but the current selection if no editing or root frame (current select is frame)
- for (ODUShort i=1;i<=4;i++) {
- if (viewval != i)
- DisableItem(viewAsMenu, i);
- }
- }
- else {
- // enable them just in case they were disabled
- EnableItem(viewAsMenu, 2);
- EnableItem(viewAsMenu, 3);
- EnableItem(viewAsMenu, 4);
- }
-
- if (isRootPartOfDocument) {
- HideDialogItem(dlg, kPartInfoBundledText);
- HideDialogItem(dlg, kPartInfoActPartRadBtn);
- HideDialogItem(dlg, kPartInfoSelPartRadBtn);
-
- // set up stationery from aFrame and its part
- isStationary = ODGetIsStationery(ev, frame);
- SetDialogBoolean(dlg, kPartInfoStationeryCheckbox, isStationary, allowEditing);
-
- // set up show links from the window
- showLinks = window->ShouldShowLinks(ev);
- SetDialogBoolean(dlg, kPartInfoShowLinksCheckbox, showLinks, allowEditing);
- }
- else {
- HideDialogItem(dlg, kPartInfoShowLinksCheckbox);
- HideDialogItem(dlg, kPartInfoStationeryCheckbox);
- HideDialogItem(dlg, kPartInfoMemorySizeButton);
-
- // set up frozen
- frameIsFrozen = frame->IsFrozen(ev);
- SetDialogBoolean(dlg, kPartInfoSelPartRadBtn, frameIsFrozen, allowEditing);
- SetDialogBoolean(dlg, kPartInfoActPartRadBtn, !frameIsFrozen, allowEditing);
- }
-
- // set up Settings…
- if (part->HasExtension(ev, kODSettingsExtension))
- {
- settings = (ODSettingsExtension*)part->AcquireExtension(ev,kODSettingsExtension);
- }
- else
- {
- HideDialogItem(dlg, kPartInfoSettingsButton);
- }
-
- // Display the dialog
- {
- TempODMenuBar currentMenuBar = winstate->AcquireCurrentMenuBar(ev);
- ODDialogBegin(ev, session, currentMenuBar, dlg);
- }
-
- ODUseDialogScriptData( &dsd, dlg );
- ODIText* tmpText = PickOneIText( tempPartComments, partName );
- if ( tmpText )
- dsd.SetScriptAndLockKeyboard( script = GetRealScriptCode(tmpText) );
-
- ShowWindow(dlg);
- modalFilter = NewModalFilterProc(CallCheckScriptFirstThenStdFilterProc);
- SetPort(dlg);
- SetDialogTextStyle(dlg, kPartInfoDlgID, script);
-
- do {
- // Remember the currently selected kind
- currentKindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
- ModalDialog(modalFilter, &itemHit);
- GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
- switch (itemHit) {
- case kPartInfoActPartRadBtn:
- case kPartInfoSelPartRadBtn:
- if (!GetControlValue((ControlHandle)itemHandle)) {
- SetControlValue((ControlHandle)itemHandle,1);
- itemHit = (itemHit == kPartInfoActPartRadBtn) ?
- kPartInfoSelPartRadBtn : kPartInfoActPartRadBtn;
- GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
- SetControlValue((ControlHandle)itemHandle,0);
- }
- break;
- case kPartInfoStationeryCheckbox:
- case kPartInfoShowLinksCheckbox:
- SetControlValue((ControlHandle)itemHandle,
- 1-GetControlValue((ControlHandle)itemHandle));
- break;
- case kPartInfoSettingsButton:
- if (settings != kODNULL) {
- ActivateAllControls(dlg, kODFalse); // deactivate control
- settings->ShowSettings(ev,facet);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- }
- break;
- case kPartInfoMemorySizeButton:
- ActivateAllControls(dlg, kODFalse); // deactivate control
- ShowSizeDialog(ev, session, usersFile, partNameS255, allowEditing);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- break;
- case kPartInfoKindPopup:
- popUpValue = GetControlValue(kindPopupControlHandle);
- if (popUpValue == translateItem)
- {
- ODUShort selectedIndex;
- ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
- TempODEditor initialEditorID = GetThisEditorFromList(editorItem, editorsList);
- TempODEditor tempEditorID = kODNULL;
- ODEditor newEditorID = kODNULL;
-
- // Return the kind popup to its current value
- SetPopupControlValue(kindPopupControlHandle, currentKindItem);
-
- session->GetWindowState(ev)->DeactivateFrontWindows(ev);
-
- ODBoolean doTranslate = session->GetTranslation(ev)->ShowTranslateDialog(
- ev,
- translateToList,
- translateToIndex,
- &selectedIndex,
- initialEditorID,
- kODTrue,
- &newEditorID);
- tempEditorID = newEditorID; // Dispose, eventually
- if ( doTranslate )
- {
- // Add translationKind to the list just above "Translate to…",
- // and make it the current selection.
- translateToIndex = selectedIndex;
-
- TempODType oldKind = GetThisKindFromList(currentKindItem, kindList);
- TempODType translationKind = GetThisKindFromList(translateToIndex, translateToList);
- AddTranslationKindToMenu(translationKind,
- kindMenu,
- translateItem-1,
- (translateToItem == 0),
- session);
-
- // Add the translationKind to the end of kindList
- if ( translateToItem != 0 )
- {
- TempODType currentTranslationKind = GetThisKindFromList(translateToItem, kindList);
- kindList->Remove(ev, currentTranslationKind);
- }
- kindList->AddLast(ev, translationKind);
-
- if ( translateToItem == 0 )
- {
- translateToItem = translateItem;
- translateItem += 1;
- }
-
- SetPopupControlValue(kindPopupControlHandle, translateToItem);
-
- editorsList->RemoveAllEditors();
- ODBoolean anyEditors = SetupEditorMenu(translationKind,
- editorsList,
- editorMenu,
- editorPopupControlHandle,
- session);
-
- if ( anyEditors )
- {
- // Select editorID in the list (it SHOULD be in the list!)
- ODSShort editorItem = IndexOfEditorInList(editorsList, newEditorID);
- if ( editorItem != 0 )
- SetPopupControlValue(editorPopupControlHandle, editorItem);
- HideDialogItem(dlg, kPartInfoEditorLabel);
- HideDialogItem(dlg, kPartInfoNoEditorText);
- ShowDialogItem(dlg, kPartInfoEditorPopup);
- }
- else
- {
- HideDialogItem(dlg, kPartInfoEditorPopup);
- ShowDialogItem(dlg, kPartInfoEditorLabel);
- ShowDialogItem(dlg, kPartInfoNoEditorText);
- }
-
- TempODType newCat = ODGetFirstCategoryOfKind(ev, translationKind, nsm);
- TempODType oldCat = ODGetFirstCategoryOfKind(ev, oldKind, nsm);
- if ( !ODISOStrEqual(newCat, oldCat) )
- {
- DisposeIText(dpis.category);
- dpis.category = ODGetCatFromKind(ev, translationKind, nsm);
- InvalRect(&partInfoCategoryRect);
- }
- }
- }
- else if ( popUpValue != currentKindItem )
- {
- // Determine the old and new kinds for later
- TempODType oldKind = GetThisKindFromList(currentKindItem, kindList);
- TempODType newKind = GetThisKindFromList(popUpValue, kindList);
-
- // Remember the currently selected editor
- ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
- TempODEditor lastEditorID = GetThisEditorFromList(editorItem, editorsList);
-
- editorsList->RemoveAllEditors();
- SetupEditorMenu(newKind,
- editorsList,
- editorMenu,
- editorPopupControlHandle,
- session);
-
- // Reselect the last editor if it supports the new kind
- ODSShort newEditorItem = 0;
- if ( EditorSupportsKind(nsm, lastEditorID, newKind) )
- newEditorItem = IndexOfEditorInList(editorsList, lastEditorID);
- if ( newEditorItem != 0 )
- SetPopupControlValue(editorPopupControlHandle, newEditorItem);
- else
- Draw1Control(editorPopupControlHandle);
-
- // Change the category string if changed
- TempODType oldCat = ODGetFirstCategoryOfKind(ev, oldKind, nsm);
- TempODType newCat = ODGetFirstCategoryOfKind(ev, newKind, nsm);
- if ( !ODISOStrEqual(newCat, oldCat) )
- {
- DisposeIText(dpis.category);
- dpis.category = ODGetCatFromKind(ev, newKind, nsm);
- SetPort(dlg);
- InvalRect(&partInfoCategoryRect);
- }
- }
- break;
-
- case kPartInfoCancelBtn:
- if (allowEditing) { // cancel, make sure we restore all the values
- TempODName newPartName = GetITextFromDialog(dlg, kPartInfoNameEditFld,
- dsd.Script(), dsd.Language());
- if (newPartName) {
- if (!ITextStrEqual(newPartName, partName))
- ODSetPartName(ev, frame, partName, kAEAsk);
- }
- TempODName newPartComment = GetITextFromDialog(dlg, kPartInfoCommentsEditFld,
- dsd.Script(), dsd.Language());
- if (newPartComment) {
- if (!ITextStrEqual(newPartComment, tempPartComments))
- ODSetComments(ev, frame, tempPartComments);
- }
- }
- break;
-
- case kPartInfoOKBtn:
- if (allowEditing)
- {
- script = dsd.Script();
- ODLangCode lang = dsd.Language();
-
- // update Name
-
- ODIText *newPartName = GetITextFromDialog(dlg, kPartInfoNameEditFld,
- script, lang);
- if (newPartName) {
- if (!ITextStrEqual(newPartName, partName)) {
- if (!ODSetPartName(ev, frame, newPartName, kAEAsk)) {
- itemHit = kPartInfoNameEditFld;
- SelectDialogItemText(dlg, kPartInfoNameEditFld, 0, GetITextStringLength(newPartName));
- DisposeIText(newPartName);
- ActivateAllControls(dlg, kODFalse); // deactivate control
- (void) ShowAlert(ev, kPartInfoInvalidNameAlertID, kODNULL, session);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- break;
- }
- }
- DisposeIText(newPartName);
- }
-
- // update Comments
- ODIText *newPartComment = GetITextFromDialog(dlg, kPartInfoCommentsEditFld,
- script, lang);
- if (newPartComment) {
- if (!ITextStrEqual(newPartComment, tempPartComments)) {
- ODSetComments(ev, frame, newPartComment);
- TempODName actualPartComments = ODGetComments(ev, frame, kODNULL);
- if (!ITextStrEqual(newPartComment, actualPartComments)) {
- itemHit = kPartInfoCommentsEditFld;
- SetDialogFromIText(dlg, kPartInfoCommentsEditFld, actualPartComments, allowEditing, kODTrue);
- DisposeIText(newPartComment);
- ActivateAllControls(dlg, kODFalse); // deactivate control
- (void) ShowAlert(ev, kPartInfoLongCommentAlertID, kODNULL, session);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- break;
- }
- }
- DisposeIText(newPartComment);
- }
-
- if (isRootPartOfDocument) {
- // update Stationery
- ODBoolean checkBoxValue = GetDialogBoolean(dlg, kPartInfoStationeryCheckbox);
- if (checkBoxValue != isStationary)
- ODSetIsStationery(ev, frame, checkBoxValue);
-
- // update Show Links
- checkBoxValue = GetDialogBoolean(dlg, kPartInfoShowLinksCheckbox);
- if (checkBoxValue != showLinks)
- SetAllWindowShowLinks(ev, winstate, checkBoxValue);
- // window->SetShouldShowLinks(ev,checkBoxValue);
- }
- else {
- // update Frozen
- ODBoolean checkBoxValue = GetDialogBoolean(dlg, kPartInfoSelPartRadBtn);
- if (checkBoxValue != frameIsFrozen)
- frame->SetFrozen(ev, checkBoxValue);
- }
-
- // update ViewAs
- GetDialogItem(dlg, kPartInfoViewAsPopup, &itemType, &itemHandle, &scratchRect);
- popUpValue = GetControlValue((ControlHandle)itemHandle);
- if (popUpValue != viewval )
- {
- switch (popUpValue)
- {
- case 1: // view as frame
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsFrame));
- break;
- case 2: // view as large icon
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsLargeIcon));
- break;
- case 3: // view as small icon
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsSmallIcon));
- break;
- case 4: // view as thumbnail
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsThumbnail));
- break;
- default:
- break;
- }
- }
-
- // update Kind or Editor
- currentKindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
- TempODType newKind = GetThisKindFromList(currentKindItem, kindList);
-
- ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
- TempODEditor newEditorID = GetThisEditorFromList(editorItem, editorsList);
-
- TempODType partKind = ODGetKindFromPartSU(ev, partSU);
- TempODEditor partEditor = GetCurrentEditorForPart(part);
-
- if ( ((ODType) newKind) && !ODISOStrEqual(newKind, partKind) )
- {
- if ( (currentKindItem == translateToItem) && (translateToItem > 0) )
- {
- ODUShort translateFromIndex =
- GetOrderedCollectionElement(translateFromList, translateToIndex);
- TempODType fromKind = GetThisKindFromList(translateFromIndex, kindList);
-
- // If fromKind does not yet exist, force part to change to that kind.
- // Otherwise, force the part to externalize any changes to its storage unit.
- ODBoolean forceChangeKind = !partSU->Exists(ev, kODPropContents, (ODType) fromKind, 0);
- if ( forceChangeKind )
- part->ChangeKind(ev, (ODType) fromKind);
- else
- part->Externalize(ev);
-
- partSU->Focus(ev, kODPropContents, kODPosUndefined, (ODType) fromKind, 0, kODPosUndefined);
- TempODStorageUnitView fromView = partSU->CreateView(ev);
-
- partSU->Focus(ev, kODPropContents, kODPosAll, kODTypeAll, 0, kODPosUndefined);
-
- partSU->AddValue(ev, (ODType) newKind);
- TempODStorageUnitView toView = partSU->CreateView(ev);
-
- TRY
- session->GetTranslation(ev)->TranslateView(ev, fromView, toView);
- CATCH_ALL
- // Remove the translated value type
- if ( ODSUExistsThenFocus(ev, partSU, kODPropContents, newKind) )
- partSU->Remove(ev);
- // If translation fails after changing the kind, change kind back
- if ( forceChangeKind )
- part->ChangeKind(ev, partKind);
- RERAISE;
- ENDTRY
-
- ChangeKindAndEditor(ev, part, newKind, newEditorID, nsm);
- }
- else
- ChangeKindAndEditor(ev, part, newKind, newEditorID, nsm);
- }
- else if ( ((ODEditor) newEditorID) && !ODISOStrEqual(newEditorID, partEditor) )
- {
- ODReleaseObject(ev, settings); // editor may delete its settings, so release it first
- ChangeEditor(part, newEditorID);
- }
- }
- break;
-
- default: break;
- }
- } while ((itemHit != kPartInfoOKBtn) && (itemHit != kPartInfoCancelBtn));
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDialogEnd();
-
- DeleteMenu(kPartInfoEditorMenu);
- ReleaseResource((Handle)editorMenu);
- DeleteMenu(kPartInfoKindMenu);
- ReleaseResource((Handle)kindMenu);
-
- DisposeIText(dpis.category);
- DisposeIText(dpis.authorName);
-
- DisposeIText(partName);
-
- ODReleaseObject(ev, settings);
- ODDeleteObject (editorsList);
- ODDeleteObject (kindList);
- ODDeleteObject (translateToList);
- ODDeleteObject (translateFromList);
- ODDeleteObject (usersFile);
-
- DisposeRoutineDescriptor(DrawBoxItemUPP);
- if (DrawThumbnailUPP)
- DisposeRoutineDescriptor(DrawThumbnailUPP);
- ODDisposeRoutineDescriptor(DrawIntlStaticTextUPP);
-
- if (dlg)
- DisposeDialog(dlg);
-
- DisposeRoutineDescriptor( modalFilter );
-
- } // EndUsingResources of CUsingLibraryResources.
-
- ODDisposeHandle(gArrowBtnsPictOff);
- ODDisposeHandle(gArrowBtnsPictTopOn);
- ODDisposeHandle(gArrowBtnsPictBotOn);
-
- ODReleaseObject(ev, part);
-
- winstate->ActivateFrontWindows(ev);
-
- THROW_IF_ERROR(error);
-
- SOM_CATCH_ALL
- itemHit = kPartInfoCancelBtn;
- SOM_ENDTRY
-
- return itemHit != kPartInfoCancelBtn;
- }
-
- #ifdef MWERKS
- #if GENERATINGPOWERPC
- #if __option(global_optimizer)
- // Restore settings [see before fn]
- #pragma pop
- #endif
- #endif
- #endif
-
- SOM_Scope void SOMLINK ODInfosomUninit(ODInfo *somSelf)
- {
- //ODInfoData *somThis = ODInfoGetData(somSelf);
- ODInfoMethodDebug("ODInfo","ODInfosomUninit");
-
- ODInfo_parent_ODObject_somUninit(somSelf);
- }
-
-
- //-------------------------------------------------------------------------------------
- // Kind Menu manipulation functions
- //-------------------------------------------------------------------------------------
- // copied from LinkDlgs.cpp (!with changes by TÇ)
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- // GenerateEditorsList
- //------------------------------------------------------------------------------
-
- ODStatic void GenerateEditorsList(ODSShort currentKindItem,
- ODTypeList* kindsList,
- EditorSet* editorsList,
- ODNameSpaceManager* nsm)
- {
- ODSShort i = 1;
- Environment* ev = somGetGlobalEnvironment();
-
- //clear editorsList
- editorsList->RemoveAllEditors();
-
- ODTypeListIterator* kindIter = kindsList->CreateTypeListIterator(ev);
- for (ODType kind = kindIter->First(ev);
- kindIter->IsNotComplete(ev);
- kind = kindIter->Next(ev), i++)
- {
- if (i == currentKindItem)
- GetAllEditorsForKind( nsm, kind, editorsList );
- ODDisposePtr(kind);
- }
- ODDeleteObject( kindIter );
- }
-
- //------------------------------------------------------------------------------
- // InitEditorPopup
- //------------------------------------------------------------------------------
-
- ODStatic void InitEditorPopup ( EditorSet* editorsList,
- ODEditor editorID,
- ControlHandle itemHandle,
- ODSShort* currentEditorItem,
- MenuHandle editorMenu )
- {
- DeleteAllMenuItems( editorMenu );
- AddEditorsToMenu(editorsList,editorMenu, gSession);
-
- ODSShort item = 1;
- EditorSetIterator* editorIter = editorsList->CreateIterator();
-
- // determine which editor to check mark
- for (ODEditor editor = editorIter->First();
- editorIter->IsNotComplete();
- editor = editorIter->Next(), ++item)
- {
- if (ODISOStrEqual(editor, editorID))
- break;
- }
- ODDeleteObject( editorIter);
-
- SetControlMinimum(itemHandle, 1);
- SetControlMaximum(itemHandle, editorsList->GetEditorCount());
- SetControlValue(itemHandle, item);
- *currentEditorItem = item;
- }
-
-
- //------------------------------------------------------------------------------
- // SetCategory
- //------------------------------------------------------------------------------
- #if 0
- ODStatic void SetCategory( ODPart* part,
- Handle categoryItem,
- ODNameSpaceManager* nsm)
- {
- StringHandle strHandle = 0;
- ODName* name;
-
- Environment* ev = somGetGlobalEnvironment();
-
- name = ODGetCategory(ev, part, nsm);
- strHandle = (StringHandle) NewHandle(256);
- HLock((Handle) strHandle);
- IntlToPStr(name, *strHandle);
- SetDialogItemText(categoryItem, *strHandle);
- HUnlock((Handle) strHandle);
- DisposeHandle((Handle)strHandle);
- DisposeIText(name);
- }
- #endif
-
- //------------------------------------------------------------------------------
- // SetModCreatDateTimeText
- //------------------------------------------------------------------------------
- ODStatic void SetModCreatDateTimeText(Environment* ev, ODStorageUnit* partSU )
- {
- Str255 createDateString = "\p";
- Str255 createTimeString = "\p";
- Str255 modDateString = "\p";
- Str255 modTimeString = "\p";
-
- ODULong createDateTime = ODGetCreationDate(ev, partSU);
- if ( createDateTime == 0 )
- {
- StringHandle str = GetString(kODPartInfoStrUnknownID);
- if ( str != kODNULL )
- {
- ODLockHandle((ODHandle) str);
- ODBlockMove((ODPtr) *str, (ODPtr) createDateString, (ODULong) (*str[0])+1);
- ODUnlockHandle((ODHandle) str);
- ReleaseResource((Handle) str);
- }
- else
- {
- createDateString[0] = (char) 0;
- }
- createTimeString[0] = (char) 0;
- }
- else
- {
- DateString(createDateTime, abbrevDate, createDateString, kODNULL);
- TimeString(createDateTime, kODFalse, createTimeString, kODNULL);
- }
-
- ODULong modDateTime = ODGetModificationDate(ev, partSU);
-
- if ( modDateTime == 0 )
- {
- StringHandle str = GetString(kODPartInfoStrUnknownID);
- if ( str != kODNULL )
- {
- ODLockHandle((ODHandle) str);
- ODBlockMove((ODPtr) *str, (ODPtr) modDateString, (ODULong) (*str[0])+1);
- ODUnlockHandle((ODHandle) str);
- ReleaseResource((Handle) str);
- }
- else
- {
- modDateString[0] = (char) 0;
- }
- modTimeString[0] = (char) 0;
- }
- else
- {
- DateString(modDateTime, abbrevDate, modDateString, kODNULL);
- TimeString(modDateTime, kODFalse, modTimeString, kODNULL);
- }
-
- ParamText( createDateString, createTimeString, modDateString, modTimeString);
- }
-
- //------------------------------------------------------------------------------
- // SetSizeText
- //------------------------------------------------------------------------------
- ODStatic void SetSizeText(DialogPtr dlg, ODSShort item, ODULong size)
- {
- Str255 text;
- Str63 sizeString;
- short strTemplateID;
-
- if ( size < 1024 )
- {
- NumToString(size, sizeString);
- strTemplateID = kODPartInfoSizeInBytes;
- }
- else
- {
- // Round off to nearest K
- size = (size + 512) / 1024;
- NumToString(size, sizeString);
- strTemplateID = kODPartInfoSizeInK;
- }
-
- //CUsingLibraryResources r;
- ReplaceIntoString(strTemplateID, sizeString, kODNULL, text);
-
- SetDialogFromPStr(dlg, item, text, kODFalse, kODFalse);
- }
-
-
- //------------------------------------------------------------------------------
- // SetModifiedByText
- //------------------------------------------------------------------------------
-
- ODStatic void SetModifiedByText(DialogPtr dlg, ODSShort item, ODName* name)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- // I suspect that we'll have to change the model here to support
- // two-byte text. Rather than stick the text into the dialog
- // before it's drawn and then let the Dialog Mgr. draw it with
- // no information about what script to use, we need to draw it
- // ourselves via a drawproc that will get called each time it's
- // redrawn. Confirm this suspicion before doing the work....
-
- // Str255 text = "\p";
-
- // if (name)
- // IntlToPStr(name,(StringPtr)&text);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
- PaintRect( &itemRect );
- // SetDialogItemText(itemHandle,text);
-
- if (name)
- DrawITextInDlogBox(name, &itemRect, dlg, kODTrue);
- }
-
- //------------------------------------------------------------------------------
- // DrawThumbnail
- // Now draws thumbnail *and* the modified by name.
- //------------------------------------------------------------------------------
-
- pascal void DrawThumbnail(DialogPtr theDialog, short theItem)
- {
- Rect frameRect;
- Handle scratchHandle = kODNULL;
- short scratchKind;
- ODPtr theIcon = kODNULL;
- ODIconFamily iconSuite = kODNULL;
- Environment* ev = somGetGlobalEnvironment();
-
- GetDialogItem(theDialog, theItem, &scratchKind, &scratchHandle, &frameRect);
- DrawProcInfo dpi = (DrawProcInfo)GetWRefCon(theDialog);
-
- switch( theItem )
- {
- case kPartInfoPartThumbnail:
- iconSuite = ODGetIconFamily(ev, gFrame );
- if (iconSuite)
- {
- IconAlignmentType align = atAbsoluteCenter;
- IconTransformType transform = ttNone;
- ODError result = PlotIconSuite( &frameRect, align, transform,
- (Handle)iconSuite );
- DisposeIconSuite( (Handle)iconSuite,kODTrue );
- }
- else
- FrameRect(&frameRect);
- break;
- case kPartInfoByFld:
- if (dpi->authorName)
- DrawITextInDlogBox( dpi->authorName, &frameRect, theDialog, kODTrue );
- break;
- case kPartInfoCategoryFld:
- if (dpi->category)
- DrawITextInDlogBox( dpi->category, &frameRect, theDialog, kODTrue );
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // DeleteAllMenuItems
- //------------------------------------------------------------------------------
- ODStatic void DeleteAllMenuItems(MenuHandle theMenu)
- {
- ODUShort i;
-
- for (i = CountMItems(theMenu); i > 0; --i)
- {
- DeleteMenuItem(theMenu, i);
- }
- }
-
- //------------------------------------------------------------------------------
- // Document Heap Dialog Functions
- //------------------------------------------------------------------------------
-
- //=========================================================================
- // Constants
- //=========================================================================
-
- static const ODULong kDocHeapSizeDelta = 32;
-
-
- #define k1K 1024
-
- // copied from ShellDef.h!
- // Should be same as min size in DocStub.r, SIZE -1 resource
- // 1242449 Should probably create a common ≈def.h constant kDocStubMinHeapSize
- // accessible from both subsystems.
- #define kDocStubMinHeapSize (230 * 1024) // 220K min app heap [Was 256k]
- #define kDocStubDefaultSize (230 * 1024) // 220K default app heap [Was 384k]
-
- //=========================================================================
- // DocHeapArrowButtonsFilterProc
- //=========================================================================
-
- pascal Boolean
- DocHeapArrowButtonsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit);
-
- //=========================================================================
- // ShowSizeDialog
- //=========================================================================
-
- ODStatic void ShowSizeDialog(Environment* ev, ODSession* session,
- PlatformFile* file, Str255 partNameS255, ODBoolean allowEditing)
- {
- THROW_IF_NULL(ev);
- THROW_IF_NULL(session);
- THROW_IF_NULL(file);
-
- DialogPtr dlg = kODNULL;
- short itemHit = kDocHeapCancelBtn;
- Handle itemHandle = kODNULL;
- Handle scratchHandle = kODNULL;
- Rect scratchRect;
-
- dlg = ODGetNewDialog(ev,kDocHeapDlgID,session);
-
- THROW_IF_NULL(dlg);
- SetPort(dlg);
- SetDialogTextStyle(dlg, kDocHeapDlgID, smCurrentScript);
-
- // Set the draw routine for the default button outline item
- SetDialogItemHandle(dlg, kDocHeapDefaultButtonItem, (Handle)GetODOutlineDefaultButtonDrawProc());
-
- // Set the Document name text field
- SetDialogFromPStr(dlg, kDocHeapDocumentNameFld, partNameS255, kODFalse, kODFalse);
-
- // Set the OpenDoc Default Size
- ODULong curDefaultSize = DHGetODDefaultHeapSize();
- if (curDefaultSize < kDocStubMinHeapSize/k1K)
- curDefaultSize = kDocStubMinHeapSize/k1K;
- SetNumText(dlg, kDocHeapDefaultSizeFld, curDefaultSize);
-
- // Set the Document Preferred Size
- ODULong curPreferredSize =
- DHGetDocumentPreferredHeapSize(file);
- ODBoolean curDefaultSizeChosen = (curPreferredSize == 0);
- if (curDefaultSizeChosen)
- curPreferredSize = curDefaultSize;
-
- SetNumText(dlg, kDocHeapPreferdSizeFld, curPreferredSize);
-
- // set up the radio button, if editing not allowed disable the other option
- SetDialogBoolean(dlg, kDocHeapDefaultSizeRadBtn, curDefaultSizeChosen, allowEditing | curDefaultSizeChosen);
- SetDialogBoolean(dlg, kDocHeapPreferdSizeRadBtn, !curDefaultSizeChosen, allowEditing | !curDefaultSizeChosen);
-
- ODULong newPreferredSize = curPreferredSize;
- ODULong newDefaultSize = curDefaultSize;
- ODBoolean newDefaultSizeChosen = curDefaultSizeChosen;
-
- if (!allowEditing) {
- // no editing, then hide the arrow buttons for changing the size
- HideDialogItem(dlg, kDocHeapDefaultSizeTopBtnRect);
- HideDialogItem(dlg, kDocHeapPreferdSizeTopBtnRect);
- HideDialogItem(dlg, kDocHeapDefaultSizeBotBtnRect);
- HideDialogItem(dlg, kDocHeapPreferdSizeBotBtnRect);
- HideDialogItem(dlg, kDocHeapPreferdSizeBtns);
- HideDialogItem(dlg, kDocHeapDefaultSizeBtns);
- HideDialogItem(dlg, kDocHeapMakeChangeStatText);
- HideDialogItem(dlg, kDocHeapChangeNextLaunchStatText);
- }
-
- ModalFilterUPP docHeapSizeUPP = NewModalFilterProc(&DocHeapArrowButtonsFilterProc);
-
- // Display the dialog
- ShowWindow(dlg);
- do {
- ODULong* newSizePtr;
- ODSShort itemType;
- ODULong delta;
- ODSShort btnsItemNum;
- ModalDialog(docHeapSizeUPP, &itemHit);
- GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
- switch (itemHit) {
- case kDocHeapDefaultSizeTopBtnRect:
- case kDocHeapPreferdSizeTopBtnRect:
- case kDocHeapDefaultSizeBotBtnRect:
- case kDocHeapPreferdSizeBotBtnRect:
- newDefaultSizeChosen =
- (itemHit == kDocHeapDefaultSizeTopBtnRect ||
- itemHit == kDocHeapDefaultSizeBotBtnRect);
-
- btnsItemNum =
- newDefaultSizeChosen ?
- kDocHeapDefaultSizeBtns :
- kDocHeapPreferdSizeBtns ;
-
- GetDialogItem(dlg, btnsItemNum, &itemType, &itemHandle, &scratchRect);
- SetDialogItem(dlg, btnsItemNum, picItem, gArrowBtnsPictOff,
- &scratchRect);
-
- delta = kDocHeapSizeDelta;
- if (itemHit == kDocHeapDefaultSizeBotBtnRect ||
- itemHit == kDocHeapPreferdSizeBotBtnRect)
- delta = -kDocHeapSizeDelta;
-
- newSizePtr =
- newDefaultSizeChosen ?
- &newDefaultSize :
- &newPreferredSize ;
-
- (*newSizePtr) += delta;
- if (*newSizePtr < kDocStubMinHeapSize/k1K)
- *newSizePtr = kDocStubMinHeapSize/k1K;
-
- SetNumText(dlg,
- newDefaultSizeChosen ? kDocHeapDefaultSizeFld : kDocHeapPreferdSizeFld,
- *newSizePtr);
-
- // NOTE: deliberately fall through to next bunch o' case statements
- // to pick the appropriate radio button
- case kDocHeapDefaultSizeRadBtn:
- case kDocHeapPreferdSizeRadBtn:
- case kDocHeapDefaultSizeFld:
- case kDocHeapPreferdSizeFld:
- if (allowEditing) {
- newDefaultSizeChosen =
- (itemHit == kDocHeapDefaultSizeRadBtn ||
- itemHit == kDocHeapDefaultSizeFld ||
- itemHit == kDocHeapDefaultSizeTopBtnRect ||
- itemHit == kDocHeapDefaultSizeBotBtnRect ||
- itemHit == kDocHeapDefaultSizeBtns);
- SetDialogBoolean(dlg, kDocHeapDefaultSizeRadBtn, newDefaultSizeChosen, kODTrue);
- SetDialogBoolean(dlg, kDocHeapPreferdSizeRadBtn, !newDefaultSizeChosen, kODTrue);
- }
- break;
- default:
- break;
- }
- } while ((itemHit != kDocHeapOKBtn) && (itemHit != kDocHeapCancelBtn));
- if ((itemHit == kDocHeapOKBtn) && (allowEditing))
- {
- if (newDefaultSizeChosen != kODFalse)
- {
- if (newDefaultSize != curDefaultSize || !curDefaultSizeChosen)
- DHSetODDefaultHeapSize(file, newDefaultSize);
- DHClearDocumentPreferredHeapSize(file);
- }
- else
- {
- if (newPreferredSize != curPreferredSize || curDefaultSizeChosen)
- DHSetDocumentPreferredHeapSize(file, newPreferredSize);
- }
- }
-
- ODDisposeRoutineDescriptor(docHeapSizeUPP);
- DisposeDialog(dlg);
- }
-
- ODStatic ODULong DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID)
- {
- // returns 0 if the resource is not found
- ODULong size = 0;
- ODPtr sizeRes =
- file->ReadResourcePtr(kSIZERsrcType, resourceID, kODNULL);
- if (sizeRes != kODNULL)
- {
- memcpy(&size, ((char*)sizeRes)+2, sizeof(size)); // Should probably use a constant.
- ODDisposePtr(sizeRes);
- }
- return size / 1024;
- }
-
- ODStatic void DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID,
- PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes)
- {
- if (fromFile == kODNULL)
- fromFile = file;
- ODULong sizeOfResource;
- ODPtr sizeRes =
- fromFile->ReadResourcePtr(kSIZERsrcType, fromResID, &sizeOfResource);
-
- if (sizeRes != kODNULL)
- {
- numKBytes *= 1024; // Should probably use a constant.
- memcpy(((char*)sizeRes)+2, &numKBytes, sizeof(numKBytes)); // Should probably use a constant.
-
- file->WriteResourcePtr(kSIZERsrcType, resourceID, sizeRes, sizeOfResource);
- ODDisposePtr(sizeRes);
- }
- }
-
-
- ODStatic ODULong DHGetODDefaultHeapSize()
- {
- Environment* ev = somGetGlobalEnvironment();
- PlatformFile* file = gSession->GetNameSpaceManager(ev)->GetPreferences(ev)->GetPrefsFile();
- ODULong size = DHGetPreferredSizeInSIZE(file, -1); // Should probably use a constant.
- if (size == 0)
- size = kDocStubDefaultSize/k1K;
- return size;
- }
-
- ODStatic void DHSetODDefaultHeapSize(PlatformFile* documentFile, ODULong numKBytes)
- {
- Environment* ev = somGetGlobalEnvironment();
- PlatformFile* file = gSession->GetNameSpaceManager(ev)->GetPreferences(ev)->GetPrefsFile();
- DHSetPreferredSizeInSIZE(file, -1, documentFile, -1, numKBytes); // Should probably use a constant.
- }
-
- ODStatic ODULong DHGetDocumentPreferredHeapSize(PlatformFile* file)
- {
- // returns 0 if there is no preferred size
- return DHGetPreferredSizeInSIZE(file, 0); // Should probably use a constant.
- }
-
- ODStatic void DHClearDocumentPreferredHeapSize(PlatformFile* file)
- {
- file->DeleteResource(kSIZERsrcType, 0); // Should probably use constants.
- file->DeleteResource(kSIZERsrcType, 1);
- }
-
-
- ODStatic void DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes)
- {
- DHSetPreferredSizeInSIZE(file, 0, kODNULL, -1, numKBytes); // Should probably use constants.
- DHSetPreferredSizeInSIZE(file, 1, kODNULL, -1, numKBytes);
- }
-
-
- pascal Boolean
- DocHeapArrowButtonsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
- {
- if (event->what == mouseDown)
- {
- Point thePt = event->where;
- GlobalToLocal(&thePt);
- *itemHit = FindDialogItem(dialog, thePt) + 1;
- if (*itemHit == kDocHeapDefaultSizeTopBtnRect ||
- *itemHit == kDocHeapDefaultSizeBotBtnRect ||
- *itemHit == kDocHeapPreferdSizeTopBtnRect ||
- *itemHit == kDocHeapPreferdSizeBotBtnRect ) {
- ODSShort picItemNum =
- (*itemHit == kDocHeapDefaultSizeTopBtnRect ||
- *itemHit == kDocHeapDefaultSizeBotBtnRect) ?
- kDocHeapDefaultSizeBtns :
- kDocHeapPreferdSizeBtns ;
- ODHandle pictHandle =
- (*itemHit == kDocHeapDefaultSizeTopBtnRect ||
- *itemHit == kDocHeapPreferdSizeTopBtnRect) ?
- gArrowBtnsPictTopOn :
- gArrowBtnsPictBotOn ;
-
- SetDialogItemAndUpdate(dialog, picItemNum, pictHandle);
- }
- }
- else if (event->what == mouseUp)
- {
- SetDialogItemAndUpdate(dialog, kDocHeapDefaultSizeBtns, gArrowBtnsPictOff);
- SetDialogItemAndUpdate(dialog, kDocHeapPreferdSizeBtns, gArrowBtnsPictOff);
- }
- return ODDialogFilterProc(dialog,event,itemHit);
- }
-
- //==============================================================================
- // PickOneIText
- // Choose the more "interesting" IText for use as the basis of setting the
- // dialog's script. Those of zero length are not interesting, as the user has
- // not previously typed anything whose appearance he might want preserved.
- // Similarly, the Roman script is not interesting because non-Roman scripts can
- // display Roman text just fine. So we want non-Roman text with content. In
- // the case of a tie either will do -- except that if both are fully interesting
- // it's better to return null and let the default application font win.
- //==============================================================================
-
- static ODScriptCode GetRealScriptCode( ODIText* itext )
- {
- ODScriptCode script;
- if (itext)
- script = GetITextScriptCode( itext );
- else
- script = smSystemScript;
- if ( script == smSystemScript )
- script = GetScriptManagerVariable(smSysScript);
- return script;
- }
-
- ODStatic ODIText* PickOneIText( ODIText* itext1, ODIText* itext2 )
- {
- ODIText* leadingCandidate;
- ODBoolean text1NotRoman = itext1 && GetRealScriptCode( itext1 ) != smRoman;
- ODBoolean text2NotRoman = itext2 && GetRealScriptCode( itext2 ) != smRoman;
-
- if ( text1NotRoman && (GetITextStringLength(itext1) > 0) )
- leadingCandidate = itext1;
- else if ( text2NotRoman && (GetITextStringLength(itext2) > 0) )
- leadingCandidate = itext2;
- else
- leadingCandidate = kODNULL;
-
- if ( leadingCandidate )
- if ( text1NotRoman && text2NotRoman &&
- (GetRealScriptCode( itext1 ) != GetRealScriptCode( itext2 )) )
- leadingCandidate = kODNULL;
- return leadingCandidate;
- }
-
- #endif
-