home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Core / Info.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  66.3 KB  |  2,170 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Info.cpp
  3.  
  4.     Contains:    implementation of the Info object including ShowPartFrameInfo
  5.  
  6.     Owned by:    Ed Lai
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <18>     6/22/96    EL        1344140: dialogLib's ShowPartFrameInfo now
  13.                                     returns ODError.
  14.         <17>     6/21/96    jpa        T10002: Changed min/default heap size.
  15.                                     (Also improved debug msg from
  16.                                     GetSharedLibrary.)
  17.         <16>      6/7/96    eeh        T10017: function ptrs must be extern C
  18.         <15>      6/7/96    eeh        T10017: use current architecture
  19.         <14>      6/7/96    eeh        T10017: return CFM errors
  20.         <13>      6/7/96    eeh        T10017: move most dlg stuff to InfoDlg.cpp
  21.         <12>      6/5/96    EL        1355529: Use menu item count to determine
  22.                                     the translation menu item.
  23.         <11>      6/4/96    EL        1323543: Remove some unneeded comment from
  24.                                     last check in.
  25.         <10>      6/4/96    EL        1323543: Bundled checkbox is now two radio
  26.                                     buttons. 1289557: Alert for bad file name
  27.                                     and comment too long.
  28.          <9>     5/30/96    CC        1299865: ShowPartFrameInfo: If the kind
  29.                                     popup is changed, keep the same editor
  30.                                     unless it doesn't support the new kind.
  31.          <8>     5/29/96    TJ        Worked around temp var scoping problem.
  32.          <7>     5/28/96    EL        #1234149: Remove staticText covering
  33.                                     checkbox so that checkbox can be shown as
  34.                                     dimmed for read only document.
  35.          <6>     5/24/96    jpa        1246074: Fix SOM_CATCH. Also: Disable CW
  36.                                     optimizer on GetPartFrameInfo to avoid CW8
  37.                                     compiler crashes.
  38.          <5>     5/22/96    EL        #1263100: If cancel out of SynchNSTable,
  39.                                     reraise the error.
  40.          <4>      5/3/96    EL        1313942: release settings extension before
  41.                                     editor is swapped. 1329522: document info
  42.                                     size dialog button will be inverted on
  43.                                     mouse down to give user feedback.
  44.          <3>     3/20/96    EL        1289563: for read-only field from read-only
  45.                                     documents, disallow editing. Allow viewing
  46.                                     of heap size info from read-only document
  47.                                     but don't allow editing.
  48.          <2>     1/12/96    CC        1302700: ShowPartFrameInfo: Show part id if
  49.                                     frame is non-persistent.
  50.                                     1295846:  ShowPartFrameInfo: ASSERT that
  51.                                     part is a part wrapper.
  52.  
  53.     In Progress:
  54.         
  55. */
  56.  
  57. #define _USE_DIALOGS_LIB_
  58.  
  59. #define ODInfo_Class_Source
  60. #define VARIABLE_MACROS
  61. #include <Info.xih>
  62.  
  63. #ifndef _USERSRCM_
  64. #include <UseRsrcM.h>
  65. #endif
  66.  
  67. #ifndef SOM_ODSession_xh
  68. #include <ODSessn.xh>
  69. #endif
  70.  
  71. #ifndef SOM_ODDraft_xh
  72. #include <Draft.xh>
  73. #endif
  74.  
  75. #ifndef SOM_ODDocument_xh
  76. #include <Document.xh>
  77. #endif
  78.  
  79. #ifndef SOM_ODContainer_xh
  80. #include <ODCtr.xh>
  81. #endif
  82.  
  83. #ifndef SOM_ODWindowState_xh
  84. #include <WinStat.xh>
  85. #endif
  86.  
  87. #ifndef SOM_ODWindow_xh
  88. #include <Window.xh>
  89. #endif
  90.  
  91. #ifndef SOM_ODFrameFacetIterator_xh
  92. #include <FrFaItr.xh>
  93. #endif
  94.  
  95. #ifndef _INFODEFS_
  96. #include <InfoDefs.h>
  97. #endif
  98.  
  99. #ifndef _PREFS_
  100. #include "Prefs.h"
  101. #endif
  102.  
  103. #ifndef SOM_Module_OpenDoc_StdProps_defined
  104. #include <StdProps.xh>
  105. #endif
  106.  
  107. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  108. #include <StdTypes.xh>
  109. #endif
  110.  
  111. #ifndef _ODUTILS_
  112. #include <ODUtils.h>
  113. #endif
  114.  
  115. #ifndef SOM_ODFrame_xh
  116. #include <Frame.xh>
  117. #endif
  118.  
  119. #ifndef SOM_ODFacet_xh
  120. #include <Facet.xh>
  121. #endif
  122.  
  123. #ifndef SOM_ODPart_xh
  124. #include <Part.xh>
  125. #endif
  126.  
  127. #ifndef SOM_ODStorageUnit_xh
  128. #include <StorageU.xh>
  129. #endif
  130.  
  131. #ifndef SOM_ODStorageUnitView_xh
  132. #include <SUView.xh>
  133. #endif
  134.  
  135. #ifndef SOM_ODSettingsExtension_xh
  136. #include <Settings.xh>
  137. #endif
  138.  
  139. #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
  140. #include <StdExts.xh>
  141. #endif
  142.  
  143. #ifndef _PASCLSTR_
  144. #include <PasclStr.h>
  145. #endif
  146.  
  147. #ifndef _ODMEMORY_
  148. #include <ODMemory.h>
  149. #endif
  150.  
  151. #ifndef _PLFMFILE_
  152. #include <PlfmFile.h>
  153. #endif
  154.  
  155. #ifndef SOM_ODTypeList_xh
  156. #include <TypeList.xh>
  157. #endif
  158.  
  159. #ifndef SOM_ODTypeListIterator_xh
  160. #include <TypLsItr.xh>
  161. #endif
  162.  
  163. #ifndef _BINDNGH_
  164. #include <BindngH.h>
  165. #endif
  166.  
  167. #ifndef _BNDNSUTL_
  168. #include <BndNSUtl.h>
  169. #endif
  170.  
  171. #ifndef _DLOGUTIL_
  172. #include <DlogUtil.h>
  173. #endif
  174.  
  175. #ifndef _DOCUTILS_
  176. #include <DocUtils.h>
  177. #endif
  178.  
  179. #ifndef _TEMPOBJ_
  180. #include <TempObj.h>
  181. #endif
  182.  
  183. #ifndef _EXCEPT_
  184. #include <Except.h>
  185. #endif
  186.  
  187. #ifndef _ITEXT_
  188. #include <IText.h>
  189. #endif
  190.  
  191. #ifndef _STORUTIL_
  192. #include <StorUtil.h>
  193. #endif
  194.  
  195. #ifndef _EDITRSET_
  196. #include <EditrSet.h>
  197. #endif
  198.  
  199. #ifndef _ISOSTR_
  200. #include <ISOStr.h>
  201. #endif
  202.  
  203. #ifdef __SC__
  204. #ifndef __PACKAGES__
  205. #include <Packages.h>
  206. #endif
  207. #else
  208. #ifndef __TEXTUTILS__
  209. #include <TextUtils.h>
  210. #endif
  211. #endif
  212.  
  213. #ifndef __STRING__
  214. #include <String.h>
  215. #endif
  216.  
  217. #ifndef __GESTALTEQU__
  218. #include <GestaltEqu.h>
  219. #endif
  220.  
  221. #ifndef __DIALOGS__
  222. #include <Dialogs.h>
  223. #endif
  224.  
  225. #ifndef __TEXTEDIT__
  226. #include <TextEdit.h>
  227. #endif
  228.  
  229. #ifndef __TOOLUTILS__
  230. #include <ToolUtils.h>
  231. #endif
  232.  
  233. #ifndef __FONTS__
  234. #include <Fonts.h>
  235. #endif
  236.  
  237. #ifndef __CONTROLS__
  238. #include <Controls.h>
  239. #endif
  240.  
  241. #ifndef SOM_ODPartWrapper_xh
  242. #include <PartWrap.xh>
  243. #endif
  244.  
  245. #ifndef _INFOUTIL_
  246. #include <InfoUtil.h>
  247. #endif
  248.  
  249. #ifndef _STDTYPIO_
  250. #include <StdTypIO.h>
  251. #endif
  252.  
  253. #ifndef _TEMPOBJ_
  254. #include <TempObj.h>
  255. #endif
  256.  
  257. #ifndef SOM_ODTranslation_xh
  258. #include <Translt.xh>
  259. #endif
  260.  
  261. #ifndef SOM_ODDispatcher_xh
  262. #include <Disptch.xh>
  263. #endif
  264.  
  265. #ifndef __PALETTES__
  266. #include <Palettes.h>
  267. #endif
  268.  
  269. #ifndef __ICONS__
  270. #include <Icons.h>
  271. #endif
  272.  
  273. #ifndef __FOLDERS__
  274. #include <Folders.h>
  275. #endif
  276.  
  277. #ifndef _TRANSUTL_
  278. #include <TransUtl.h>
  279. #endif
  280.  
  281. #ifndef __MENUS__
  282. #include <Menus.h>
  283. #endif
  284.  
  285. #ifndef SOM_ODStorageSystem_xh
  286. #include <ODStor.xh>
  287. #endif
  288.  
  289. #ifndef SOM_ODNameSpaceManager_xh
  290. #include <NmSpcMg.xh>
  291. #endif
  292.  
  293. #ifndef _ORDCOLL_
  294. #include "OrdColl.h"
  295. #endif
  296.  
  297. #pragma segment ODInfo
  298.  
  299. #ifdef _USE_DIALOGS_LIB_
  300.  
  301. //==============================================================================
  302. // InitInfo
  303. //==============================================================================
  304.  
  305. SOM_Scope void  SOMLINK ODInfoInitInfo(ODInfo *somSelf, Environment *ev,
  306.         ODSession* session)
  307. {
  308.     ODInfoData *somThis = ODInfoGetData(somSelf);
  309.     ODInfoMethodDebug("ODInfo","ODInfoInitInfo");
  310.     
  311.     _fSession = session;
  312. //    gSession = _fSession;
  313. }
  314.  
  315. //==============================================================================
  316. // ShowPartFrameInfo
  317. //==============================================================================
  318.  
  319. static pascal ODBoolean CallCheckScriptFirstThenStdFilterProc( DialogPtr dialog,
  320.         EventRecord *event, short *itemHit)
  321. {
  322.     return CheckKeyScriptChangeFilterProc( dialog, event, itemHit )
  323.         || ODDialogFilterProc( dialog, event, itemHit );
  324. }
  325.  
  326. // <eeh> this ought to be moved to a utility file at some point
  327. OSErr LoadODSharedLibrary( Str63 libName, Str255 entryName,
  328.         CFragConnectionID* connID, void** entryPoint );
  329. OSErr LoadODSharedLibrary( Str63 libName, Str255 entryName,
  330.         CFragConnectionID* connID, void** entryPoint )
  331. {
  332.     Ptr ignore;
  333.     Str255 errName;
  334. //    CFragConnectionID connID;
  335.  
  336.     OSErr err = GetSharedLibrary( libName, kCurrentCFragArch, 1, connID,
  337.             &ignore, errName );
  338.     if ( err == noErr )
  339.     {
  340.         CFragSymbolClass symClass;
  341.         err = FindSymbol( *connID, entryName, (Ptr*)entryPoint, &symClass );
  342.         if ( err == noErr )
  343.             WASSERT( symClass == kTVectorCFragSymbol );
  344.         else
  345.         {
  346.             WARN( "Didn't find symbol address" );
  347.             *entryPoint = kODNULL;
  348.         }
  349.     }
  350.     else
  351.     {
  352. #if ODDebug
  353.         PascalToCString( errName );
  354.         WARN( "GetSharedLibrary returned error %d '%s'", err, errName );
  355. #endif
  356.     }
  357.  
  358.     return err;
  359. }
  360.  
  361. void UnloadODSharedLibrary( CFragConnectionID* connID );
  362. void UnloadODSharedLibrary( CFragConnectionID* connID )
  363. {
  364.     OSErr err = CloseConnection( connID );
  365.     WASSERT( err == noErr );
  366. }
  367.  
  368. #ifdef __cplusplus
  369. extern "C" {
  370. #endif
  371. typedef ODError (*InfoDialogEntry)( Environment *ev,
  372.         ODSession* session, ODFacet* facet, ODBoolean allowEditing);
  373. #ifdef __cplusplus
  374. }
  375. #endif
  376.  
  377. SOM_Scope ODBoolean  SOMLINK ODInfoShowPartFrameInfo(ODInfo *somSelf, Environment *ev,
  378.         ODFacet* facet, ODBoolean allowEditing)
  379. {
  380.     ODInfoData *somThis = ODInfoGetData(somSelf);
  381.     ODInfoMethodDebug("ODInfo","ODInfoShowPartFrameInfo");
  382.  
  383.     // already volatile since address taken....
  384.     InfoDialogEntry ide = kODNULL; ODVolatile( ide );
  385.     CFragConnectionID connID; ODVolatile( connID );
  386.     ODBoolean result = kODFalse; ODVolatile(result);
  387.  
  388.     SOM_TRY
  389.         ODError    error = 0;
  390.         THROW_IF_ERROR( LoadODSharedLibrary( "\pDialogsLib",
  391.                 "\pShowPartFrameInfo", &connID, (void**)&ide ) );
  392.         error = (*ide)( ev, _fSession, facet, allowEditing );
  393.         if (error && (error != userCanceledErr))
  394.             THROW(error);
  395.         UnloadODSharedLibrary( &connID );
  396.         result = kODTrue;
  397.     SOM_CATCH_ALL
  398.         if ( ide != kODNULL )        // we loaded the library
  399.             UnloadODSharedLibrary( &connID );
  400.         // reraise happens automatically
  401.     SOM_ENDTRY
  402.     return result;
  403. }
  404.  
  405. SOM_Scope void  SOMLINK ODInfosomUninit(ODInfo *somSelf)
  406. {
  407.     //ODInfoData *somThis = ODInfoGetData(somSelf);
  408.     ODInfoMethodDebug("ODInfo","ODInfosomUninit");
  409.  
  410.     ODInfo_parent_ODObject_somUninit(somSelf);
  411. }
  412.  
  413. #else
  414.  
  415. //=========================================================================
  416. // Globals
  417. //=========================================================================
  418.  
  419. static ODSession* gSession;    // For use in Dialog Filter Proc
  420. static ODFrame* gFrame;    // For use in Dialog Filter Proc
  421. static ODName*    gKindName;
  422.  
  423. // For use in Document Heap Dialog Filter Proc
  424. static ODHandle gArrowBtnsPictOff;    
  425. static ODHandle gArrowBtnsPictTopOn;
  426. static ODHandle gArrowBtnsPictBotOn;
  427.  
  428.  
  429. //==============================================================================
  430. // Constants
  431. //==============================================================================
  432.  
  433. const short kControlInactive = 255;
  434.  
  435. //==============================================================================
  436. // Scalar types
  437. //==============================================================================
  438.  
  439. typedef char ODHandleState;
  440. struct DrawProcInfoStruct {
  441.     ODIText* authorName;
  442.     ODIText* category;
  443. };
  444. typedef struct DrawProcInfoStruct DrawProcInfoStruct, *DrawProcInfo;
  445.  
  446. //==============================================================================
  447. // Function Prototypes
  448. //==============================================================================
  449.  
  450. ODStatic void SetCategory(    ODPart* part, 
  451.                             Handle categoryItem, 
  452.                             ODNameSpaceManager* nsm);
  453.                             
  454. ODStatic void InitEditorPopup(EditorSet* editorList,
  455.                                    ODEditor editorID,
  456.                                    ControlHandle    itemHandle,
  457.                                    ODSShort* currentEditorItem,
  458.                                    MenuHandle editorMenu);
  459.                                    
  460. ODStatic void GenerateEditorsList(ODSShort currentKindItem, ODTypeList* kindsList,
  461.                                 EditorSet* editorList, 
  462.                             ODNameSpaceManager* nsm);
  463.  
  464. ODStatic void SetSizeText(DialogPtr dlg, ODSShort item, ODULong size);
  465.  
  466. ODStatic void SetModifiedByText(DialogPtr dlg, ODSShort item, ODName* name);
  467.  
  468. ODStatic ODBoolean GetDialogBoolean(DialogPtr dlg, short itemNo);
  469. ODStatic void SetDialogBoolean(DialogPtr dlg, short itemNo, ODBoolean bool, ODBoolean active);
  470. ODStatic void SetDialogItemHandle(DialogPtr dlg, short itemNo, Handle itemHandle);
  471. ODStatic void GetPStrFromDialog(DialogPtr dlg, short itemNo, Str255 pStr);
  472. ODStatic void SetDialogFromPStr(DialogPtr dlg, short itemNo, Str255 pStr, ODBoolean editable, ODBoolean selectIt);
  473. ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue);
  474.  
  475. ODStatic void SetModCreatDateTimeText( Environment* ev, ODStorageUnit* partSU);
  476.  
  477. ODStatic pascal void DrawThumbnail(DialogPtr theDialog, short theItem);
  478.  
  479. ODStatic pascal void DrawIntlStaticText(DialogPtr dialog, SInt16 item);
  480.  
  481. ODStatic void DeleteAllMenuItems(MenuHandle theMenu);
  482.  
  483. ODStatic ODIText* PickOneIText( ODIText* itext1, ODIText* itext2 );
  484. ODStatic ODScriptCode GetRealScriptCode( ODIText* itext );
  485.  
  486. //------------------------------------------------------------------------------
  487. // Document Heap Dialog Prototypes
  488. //------------------------------------------------------------------------------
  489.  
  490. ODStatic void         ShowSizeDialog(Environment* ev, ODSession* session, 
  491.                             PlatformFile* file, Str255 partNameS255, ODBoolean allowEditing);
  492. ODStatic ODULong    DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID);
  493. ODStatic void         DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID, 
  494.                             PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes);
  495.  
  496. ODStatic ODULong    DHGetODDefaultHeapSize();
  497. ODStatic void        DHSetODDefaultHeapSize(PlatformFile* documentFile, ODULong numKBytes);
  498. ODStatic ODULong    DHGetDocumentPreferredHeapSize(PlatformFile* file);
  499. ODStatic void        DHClearDocumentPreferredHeapSize(PlatformFile* file);
  500. ODStatic void        DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes);
  501.  
  502. //==============================================================================
  503. // InitInfo
  504. //==============================================================================
  505.  
  506. SOM_Scope void  SOMLINK ODInfoInitInfo(ODInfo *somSelf, Environment *ev,
  507.         ODSession* session)
  508. {
  509.     ODInfoData *somThis = ODInfoGetData(somSelf);
  510.     ODInfoMethodDebug("ODInfo","ODInfoInitInfo");
  511.     
  512.     _fSession = session;
  513.     gSession = _fSession;
  514. }
  515.  
  516. //==============================================================================
  517. // NewKindPopup
  518. //==============================================================================
  519.  
  520. static ODTypeList* NewKindPopup(Environment *ev,
  521.                         ODPartWrapper* part,
  522.                         ControlHandle popupHandle,
  523.                         MenuHandle kindMenu,
  524.                         ODSShort* currentKindItem,
  525.                         ODSShort* translateItem)
  526. {
  527.     ODStorageUnit* partSU = part->GetStorageUnit(ev);
  528.     ODSession* session = partSU->GetSession(ev);
  529.     ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  530.  
  531.     TempODType theKind = kODNULL;
  532.  
  533.     ODTypeList* kindList = session->GetStorageSystem(ev)->CreateTypeList(ev,(ODTypeList*)kODNULL);
  534.  
  535.     ContentValueTypes(partSU, kindList);
  536.  
  537.     TempODEditor editorID = part->GetEditor(ev);
  538.     GetAllKindsForEditor(nsm, kindList, editorID);
  539.     theKind = ODGetKindFromPartSU(ev, partSU);
  540.     InitKindsPopup(kindList, theKind, popupHandle, currentKindItem, kindMenu, translateItem, gSession);
  541.  
  542.     return kindList;
  543. }
  544.  
  545.  
  546. //==============================================================================
  547. // NewEditorPopup
  548. //==============================================================================
  549.  
  550. static EditorSet* NewEditorPopup(Environment *ev,
  551.                         ODPartWrapper* part,
  552.                         ControlHandle popupHandle,
  553.                         MenuHandle editorMenu,
  554.                         ODTypeList* kindList,
  555.                         ODSShort currentKindItem,
  556.                         ODEditor editorID,
  557.                         ODSShort* currentEditorItem)
  558. {
  559.     ODSession* session = part->GetStorageUnit(ev)->GetSession(ev);
  560.  
  561.     EditorSet* editorsList = new EditorSet;
  562.     THROW_IF_NULL(editorsList);
  563.     editorsList->InitEditorSet();
  564.  
  565.      TempODType initialKind = GetTypeListItem(kindList, currentKindItem);
  566.      if ( initialKind ) {
  567.         SetupEditorMenu(initialKind, editorsList, editorMenu, popupHandle, session);
  568.  
  569.         // determine which editor to check mark
  570.         ODSShort item = 1;
  571.         EditorSetIterator* editorIter = editorsList->CreateIterator();
  572.         for (ODEditor editor = editorIter->First();
  573.             editorIter->IsNotComplete();
  574.             editor = editorIter->Next(), ++item)
  575.         {
  576.             if (ODISOStrEqual(editor, editorID)) {
  577.                 *currentEditorItem = item;
  578.                 break;
  579.             }
  580.         }
  581.         ODDeleteObject( editorIter);
  582.         SetControlValue(popupHandle, item);
  583.     }
  584.  
  585.     return editorsList;
  586. }
  587.  
  588. //------------------------------------------------------------------------------
  589. // SetPopupControlValue
  590. //------------------------------------------------------------------------------
  591.  
  592. ODStatic void SetPopupControlValue(ControlHandle popupControlHandle, short itemValue)
  593. {
  594.     // The resource file must be in the chain in order for the popup to redraw.
  595.     CUsingLibraryResources r;
  596.     SetControlValue(popupControlHandle, itemValue);
  597. }
  598.  
  599. // Here are a few utility for use with the dialog manager, it could be moved to
  600. // the utility if other dialogs are going to use them
  601.  
  602. //------------------------------------------------------------------------------
  603. // GetDialogBoolean
  604. //------------------------------------------------------------------------------
  605.  
  606. ODStatic ODBoolean GetDialogBoolean(DialogPtr dlg, short itemNo)
  607. {
  608.     short     itemType;
  609.     Handle     itemHandle;
  610.     Rect     scratchRect;
  611.     
  612.     GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
  613.     return (ODBoolean)GetControlValue((ControlHandle)itemHandle);
  614. }
  615.  
  616. //------------------------------------------------------------------------------
  617. // SetDialogBoolean
  618. //------------------------------------------------------------------------------
  619.  
  620. ODStatic void SetDialogBoolean(DialogPtr dlg, short itemNo, ODBoolean bool, ODBoolean active)
  621. {
  622.     short     itemType;
  623.     Handle     itemHandle;
  624.     Rect     scratchRect;
  625.     
  626.     GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
  627.     SetControlValue((ControlHandle)itemHandle, bool);
  628.     HiliteControl((ControlHandle)itemHandle, active ? 0:255);
  629. }
  630.  
  631. //------------------------------------------------------------------------------
  632. // SetDialogItemHandle
  633. //------------------------------------------------------------------------------
  634.  
  635. ODStatic void SetDialogItemHandle(DialogPtr dlg, short itemNo, Handle itemHandle)
  636. {
  637.     short     itemType;
  638.     Handle     dummy;
  639.     Rect     scratchRect;
  640.     
  641.     GetDialogItem(dlg, itemNo, &itemType, &dummy, &scratchRect);
  642.     SetDialogItem(dlg, itemNo, itemType, itemHandle, &scratchRect);
  643. }
  644.  
  645. //------------------------------------------------------------------------------
  646. // SetDialogItemAndUpdate
  647. //------------------------------------------------------------------------------
  648.  
  649. ODStatic void SetDialogItemAndUpdate(DialogPtr dlg, short itemNo, Handle itemHandle)
  650. {
  651.     short     itemType;
  652.     Handle     dummy;
  653.     Rect     itemRect;
  654.     
  655.     GetDialogItem(dlg, itemNo, &itemType, &dummy, &itemRect);
  656.     if (itemHandle)
  657.         SetDialogItem(dlg, itemNo, itemType, itemHandle, &itemRect);
  658.     
  659.     RgnHandle itemRgn = ODNewRgn();
  660.     if (itemRgn) {
  661.         RectRgn(itemRgn,&itemRect);
  662.         UpdateDialog(dlg, itemRgn);
  663.         ODDisposeHandle((Handle)itemRgn);
  664.     }
  665. }
  666.  
  667. //------------------------------------------------------------------------------
  668. // GetPStrFromDialog
  669. //------------------------------------------------------------------------------
  670.  
  671. ODStatic void GetPStrFromDialog(DialogPtr dlg, short itemNo, Str255 pStr)
  672. {
  673.     short     itemType;
  674.     Handle     itemHandle;
  675.     Rect     scratchRect;
  676.     
  677.     GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
  678.     GetDialogItemText(itemHandle, pStr);
  679. }
  680.  
  681. //------------------------------------------------------------------------------
  682. // SetDialogFromPStr
  683. //------------------------------------------------------------------------------
  684.  
  685. ODStatic void SetDialogFromPStr(DialogPtr dlg, short itemNo, Str255 pStr, ODBoolean editable, ODBoolean selectIt)
  686. {
  687.     short     itemType;
  688.     Handle     itemHandle;
  689.     Rect     scratchRect;
  690.     
  691.     GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
  692.     short newEditType = editable ? editText : statText;
  693.     if ((itemType & (editText+statText)) != newEditType) { // dialog item type is not what we want
  694.         SetDialogItem(dlg, itemNo, (itemDisable & itemType)+newEditType, itemHandle, &scratchRect);
  695.     }
  696.     SetDialogItemText(itemHandle, pStr);
  697.     if (editable && selectIt)
  698.         SelectDialogItemText(dlg, itemNo, 0, pStr[0]);
  699. }
  700.  
  701. //------------------------------------------------------------------------------
  702. // GetITextFromDialog
  703. //------------------------------------------------------------------------------
  704.  
  705. ODStatic ODIText* GetITextFromDialog(DialogPtr dlg, short itemNo, ODScriptCode script, ODLangCode lang)
  706. {
  707.     short     itemType;
  708.     Handle     itemHandle;
  709.     Rect     scratchRect;
  710.     
  711.     GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
  712.     ODSize itemSize = GetHandleSize(itemHandle);
  713.     return CreateIText( script, lang, (ODUByte*)*itemHandle, itemSize );
  714. }
  715.  
  716. //------------------------------------------------------------------------------
  717. // SetDialogFromIText
  718. //------------------------------------------------------------------------------
  719.  
  720. ODStatic void SetDialogFromIText(DialogPtr dlg, short itemNo, ODIText* iText, ODBoolean editable, ODBoolean selectIt)
  721. {
  722.     short     itemType;
  723.     Handle     itemHandle;
  724.     Rect     scratchRect;
  725.     ODSize     itemSize;
  726.     
  727.     GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
  728.     short newEditType = editable ? editText : statText;
  729.     if ((itemType & (editText+statText)) != newEditType) { // dialog item type is not what we want
  730.         SetDialogItem(dlg, itemNo, (itemDisable & itemType)+newEditType, itemHandle, &scratchRect);
  731.     }
  732.     if (iText)
  733.         itemSize = GetITextStringLength(iText);
  734.     else
  735.         itemSize = 0;
  736.     SetHandleSize(itemHandle, itemSize);
  737.     if (iText)
  738.         ODBlockMove(GetITextPtr(iText), *itemHandle, itemSize);
  739.     if (selectIt)
  740.         SelectDialogItemText(dlg, itemNo, 0, itemSize);
  741. }
  742.  
  743. ODStatic ODBoolean ITextStrEqual(ODIText *text1, ODIText *text2)
  744. {
  745.     ODSize len1 = 0;
  746.     if (text1)
  747.         len1 = GetITextStringLength(text1);
  748.     ODSize len2 = 0;
  749.     if (text2)
  750.         len2 = GetITextStringLength(text2);
  751.     if (len1 != len2)
  752.         return 0;
  753.     else if (len1 == 0)
  754.         return kODTrue;
  755.     else
  756.         return (ODISOStrNCompare(GetITextPtr(text1),GetITextPtr(text2),len1) == 0);
  757. }
  758.  
  759. //------------------------------------------------------------------------------
  760. // SetNumText
  761. //------------------------------------------------------------------------------
  762.  
  763. ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue)
  764. {
  765.     short    itemType;
  766.     Handle    itemHandle;
  767.     Rect    itemRect;
  768.     Str255    text;
  769.  
  770.     NumToString(numValue, text);
  771.     GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
  772.     SetDialogItemText(itemHandle,text);
  773.  
  774. }
  775.  
  776. //------------------------------------------------------------------------------
  777. // GetOrderedCollectionElement
  778. //------------------------------------------------------------------------------
  779.  
  780. ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index)
  781. {
  782.     OrderedCollectionIterator* oci = collection->CreateIterator();
  783.     THROW_IF_NULL(oci);
  784.  
  785.     ODUShort elem = 0;
  786.  
  787.     for (    elem = (ODUShort) oci->First();
  788.             oci->IsNotComplete(); 
  789.             elem = (ODUShort) oci->Next() )
  790.     {
  791.         if ( --index == 0 )
  792.             break;
  793.     }
  794.  
  795.     ODDeleteObject(oci);
  796.  
  797.     return elem;
  798. }
  799.  
  800. //------------------------------------------------------------------------------
  801. // ODGetFirstCategoryOfKind
  802. //------------------------------------------------------------------------------
  803. ODStatic ODType ODGetFirstCategoryOfKind(Environment* ev, ODType kind, ODNameSpaceManager* nsm)
  804. {
  805.     ODTypeList* categoryList = GetCategoriesOfKind(nsm, kind);
  806.     ODTypeListIterator* catIter = kODNULL;
  807.     ODType category = kODNULL;
  808.     
  809.     if (categoryList)
  810.     {
  811.         catIter = categoryList->CreateTypeListIterator(ev);
  812.         category = catIter->First(ev);
  813.         ODDeleteObject(catIter);
  814.     }
  815.     
  816.     return category;
  817. }
  818.  
  819. //==============================================================================
  820. // ShowPartFrameInfo
  821. //==============================================================================
  822.  
  823. static pascal ODBoolean CallCheckScriptFirstThenStdFilterProc( DialogPtr dialog,
  824.         EventRecord *event, short *itemHit)
  825. {
  826.     return CheckKeyScriptChangeFilterProc( dialog, event, itemHit )
  827.         || ODDialogFilterProc( dialog, event, itemHit );
  828. }
  829.  
  830. #ifdef __MWERKS__
  831. #if GENERATINGPOWERPC
  832. #if __option(global_optimizer)
  833. // Turn optimization down to level 4 to avoid out-of-memory errors on this very long fn
  834. #pragma push
  835. #pragma optimization_level 1
  836. #endif
  837. #endif
  838. #endif
  839.  
  840. SOM_Scope ODBoolean  SOMLINK ODInfoShowPartFrameInfo(ODInfo *somSelf, Environment *ev,
  841.         ODFacet* facet, ODBoolean allowEditing)
  842. {
  843.     //ODInfoData *somThis = ODInfoGetData(somSelf);
  844.     ODInfoMethodDebug("ODInfo","ODInfoShowPartFrameInfo");
  845.     
  846.     short          itemHit = kPartInfoCancelBtn;
  847.  
  848.     SOM_TRY
  849.  
  850.         gArrowBtnsPictOff = 
  851.             ODReadResource(kPICTRsrcType, kArrowBtnsPictOffID);
  852.         gArrowBtnsPictTopOn = 
  853.             ODReadResource(kPICTRsrcType, kArrowBtnsPictTopOnID);
  854.         gArrowBtnsPictBotOn = 
  855.             ODReadResource(kPICTRsrcType, kArrowBtnsPictBotOnID);
  856.     
  857.     
  858.         DialogPtr      dlg = kODNULL;    ODVolatile(dlg);
  859.         Handle        itemHandle = kODNULL;
  860.         Handle        scratchHandle = kODNULL;
  861.         MenuHandle     editorMenu = kODNULL;
  862.         MenuHandle    kindMenu = kODNULL;
  863.         Rect        scratchRect;
  864.         ODSShort     itemType;
  865.         Str255         aStr255 = "\p",
  866.                     partNameS255 = "\p",
  867.                     partCommentsS255 = "\p";
  868.         ODError     result = noErr;
  869.         ODSShort     popUpValue = 0;
  870.         ODSShort     currentKindItem = 0;
  871.         ODUShort    translateToIndex = 0;    // Index in translateToList of currently chosen kind
  872.         ODUShort    translateToItem = 0;    // Item of the Kind popup showing translate to choice
  873.          ODSShort     translateItem = 0;        // Item of the Kind popup that opens translation dialog
  874.         ODSShort     currentEditorItem = 0;
  875.         ODUShort     viewval = 0;
  876.                     
  877.         ControlHandle kindPopupControlHandle;
  878.         ControlHandle editorPopupControlHandle;
  879.     
  880.         Rect        partInfoCategoryRect;
  881.     
  882.         ODBoolean     isRootPart = kODFalse;
  883.         ODBoolean     frameIsFrozen = kODFalse;
  884.         ODBoolean     isRootPartOfDocument = kODFalse;
  885.         ODBoolean     showLinks = kODFalse;
  886.         ODBoolean     isStationary = kODFalse;
  887.     
  888.         ODNameSpaceManager* nsm = kODNULL;
  889.         ODStorageUnit* partSU = kODNULL;
  890.         ODFrame*     frame = kODNULL;
  891.         ODDraft*    draft = kODNULL;
  892.         PlatformFile*    usersFile = kODNULL;    ODVolatile(usersFile);
  893.         ODWindow*    window = kODNULL;
  894.         ODSession*     session = kODNULL;
  895.         ODWindowState* winstate = kODNULL;         ODVolatile(winstate);
  896.     
  897.         ODName*     partName = kODNULL;    ODVolatile(partName);
  898.     
  899.         ODTypeList*    kindList = kODNULL;    ODVolatile(kindList);
  900.         ODTypeList*    translateToList = kODNULL; ODVolatile(translateToList);
  901.         OrderedCollection* translateFromList = kODNULL;    ODVolatile(translateFromList);
  902.         EditorSet*     editorsList     = kODNULL;    ODVolatile(editorsList);
  903.         ODSettingsExtension*    settings = kODNULL;    ODVolatile(settings);
  904.     
  905.         UserItemUPP DrawBoxItemUPP = kODNULL;
  906.         UserItemUPP DrawThumbnailUPP = kODNULL;
  907.         UserItemUPP DrawIntlStaticTextUPP = kODNULL;
  908.     
  909.         ODScriptCode script = smCurrentScript;
  910.         DialogScriptData dsd;
  911.         ModalFilterUPP modalFilter = kODNULL; ODVolatile(modalFilter);
  912.         DrawProcInfoStruct dpis;
  913.         dpis.category = kODNULL;
  914.         dpis.authorName = kODNULL;
  915.     
  916.         ODError     error = noErr;
  917.     
  918.         frame = facet->GetFrame(ev);
  919.         TempODPart    part = frame->AcquirePart(ev);
  920.         
  921.         ASSERT(!part->IsRealPart(ev), kODErrPartNotWrapper);
  922.  
  923.         session = part->GetStorageUnit(ev)->GetSession(ev);
  924.         
  925.         // Need to load latest nmaps before CUsingLibraryResources
  926.     
  927.         TRY {
  928.             nsm = session->GetNameSpaceManager(ev);
  929.             nsm->SynchNSTable(ev);
  930.         }CATCH_ALL{
  931.             if( ErrorCode()==userCanceledErr)
  932.                 RERAISE;
  933.         }ENDTRY
  934.         
  935.         // Need to make sure that the ODReadResource calls happen BEFORE the resource fork is
  936.         // put in use and left in use by the below CUsingLibraryResources.
  937.         
  938.         {CUsingLibraryResources res;
  939.     
  940.         TRY
  941.             winstate = session->GetWindowState(ev);
  942.  
  943.             gFrame = frame;
  944.             partSU = part->GetStorageUnit(ev);
  945.             draft = partSU->GetDraft(ev); // needed for GetPersistentObjectID
  946.             //! is externalization really necessary? the problems is that this cause the document
  947.             //! to be dirty when in most case all the user did was take a peek at the info 
  948.             if (HAS_WRITE_ACCESS(draft->GetPermissions(ev)))
  949.                 part->Externalize(ev); // Externalize the part so current editor can remove obsolete kinds [cc]
  950.  
  951.             window = facet->GetWindow(ev); // needed for ShouldShowLinks
  952.             
  953.             {
  954.             TempODFrame    containingFrame = frame->AcquireContainingFrame(ev);
  955.             isRootPart = ( containingFrame == kODNULL );
  956.             isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
  957.             }
  958.             
  959.             winstate->DeactivateFrontWindows(ev);
  960.             
  961.             dlg  = ODGetNewDialog(ev,kPartInfoDlgID,session);
  962.             THROW_IF_NULL(dlg);
  963.             
  964.             if (allowEditing)    // we need to hide the message that is for read only document
  965.                 HideDialogItem(dlg, kPartNoChangeStatText);
  966.     
  967.             if (isRootPartOfDocument)
  968.             {
  969.                 StringHandle str = GetString(kODDocumentInfoWindowName);
  970.                 ODLockHandle((ODHandle) str);
  971.                 SetWTitle(dlg,(StringPtr)*str);
  972.                 ODUnlockHandle((ODHandle) str);
  973.                 ReleaseResource((Handle) str);
  974.                 usersFile = 
  975.                     GetPlatformFileFromContainer(ev, draft->GetDocument(ev)->GetContainer(ev));
  976.             }
  977.         
  978.             // Set the draw routine for the default button outline item
  979.             SetDialogItemHandle(dlg, kPartInfoDefaultButtonItem, (Handle)GetODOutlineDefaultButtonDrawProc());
  980.                     
  981.             /* separator lines need to be drawn */
  982.             DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  983.         
  984.             SetDialogItemHandle(dlg, kPartInfoSep1, (Handle)DrawBoxItemUPP);
  985.         
  986.             SetDialogItemHandle(dlg, kPartInfoSep2, (Handle)DrawBoxItemUPP);
  987.         
  988.             // Set up Thumbnail
  989.             DrawThumbnailUPP = NewUserItemProc(DrawThumbnail);
  990.             SetDialogItemHandle(dlg, kPartInfoPartThumbnail, (Handle)DrawThumbnailUPP);
  991.         
  992.             // Set up Name
  993.             partName = ODGetPartName(ev, frame, kODNULL);
  994.             if (partName != kODNULL)
  995.                 IntlToPStr(partName,(StringPtr)&partNameS255);
  996.             SetDialogFromIText(dlg, kPartInfoNameEditFld, partName, allowEditing, allowEditing);
  997.  
  998.             // set up Comments
  999.             TempODName tempPartComments = ODGetComments(ev, frame, kODNULL);
  1000.             SetDialogFromIText(dlg, kPartInfoCommentsEditFld, tempPartComments, allowEditing, kODFalse);
  1001.  
  1002.             // get binding object & editorID
  1003.             ODBinding* binding = session->GetBinding(ev);
  1004.             ODPart* partw = part;
  1005.             TempODEditor editorID = ((ODPartWrapper*)partw)->GetEditor(ev);
  1006.         
  1007.             //    set up Kind Menu
  1008.             GetDialogItem(dlg, kPartInfoKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &scratchRect);
  1009.             kindMenu = GetMenu(kPartInfoKindMenu);
  1010.             THROW_IF_NULL(kindMenu);
  1011.     
  1012.             kindList = NewKindPopup(ev, 
  1013.                                     (ODPartWrapper*) partw,
  1014.                                     kindPopupControlHandle, 
  1015.                                     kindMenu, 
  1016.                                     ¤tKindItem, 
  1017.                                     &translateItem);
  1018.     
  1019.             // set up possible translations
  1020.             // These are the translations from any kinds present in the storage unit,
  1021.             // plus all other kinds supported by the current editor.
  1022.             translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  1023.             translateFromList = new OrderedCollection;
  1024.             THROW_IF_NULL(translateFromList);
  1025.             TranslateValueTypes(kindList, translateToList, translateFromList, session);
  1026.     
  1027.             //    set up Category user item
  1028.             dpis.category = ODGetCategory(ev, part, nsm);
  1029.             
  1030.             SetDialogItemHandle(dlg, kPartInfoCategoryFld, (Handle)DrawThumbnailUPP);
  1031.             
  1032.             //    set up Editor Menu
  1033.             GetDialogItem(dlg, kPartInfoEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &scratchRect);
  1034.             editorMenu = GetMenu(kPartInfoEditorMenu);
  1035.             THROW_IF_NULL(editorMenu);
  1036.     
  1037.             editorsList = NewEditorPopup(ev,
  1038.                                         (ODPartWrapper*) partw,
  1039.                                         editorPopupControlHandle,
  1040.                                         editorMenu,
  1041.                                         kindList,
  1042.                                         currentKindItem,
  1043.                                         editorID,
  1044.                                         ¤tEditorItem
  1045.                                         );
  1046.  
  1047.             if ( currentEditorItem > editorsList->GetEditorCount() )
  1048.             {
  1049.                 HideDialogItem(dlg, kPartInfoEditorPopup);
  1050.             }
  1051.             else
  1052.             {
  1053.                 HideDialogItem(dlg, kPartInfoEditorLabel);
  1054.                 HideDialogItem(dlg, kPartInfoNoEditorText);
  1055.             }
  1056.             if (!allowEditing) {
  1057.                 // disable everything but the current editor if no editing allowed
  1058.                 for (ODUShort i=1;i<=CountMItems(editorMenu);i++) {
  1059.                     if (currentEditorItem != i)
  1060.                         DisableItem(editorMenu, i);
  1061.                 }
  1062.                 // disable everything but the current kind if no editing allowed
  1063.                 for (ODUShort j=1;j<=CountMItems(kindMenu);j++) {
  1064.                     if (currentKindItem != j)
  1065.                         DisableItem(kindMenu, j);
  1066.                 }
  1067.             }
  1068.             
  1069.             // set up size
  1070.             ODULong        size = ODGetPOSize(ev, part);
  1071.             SetSizeText(dlg, kPartInfoSizeFld, size);
  1072.         
  1073.             // set up Create and Modify date and time
  1074.             SetModCreatDateTimeText( ev, partSU );
  1075.         
  1076.             // set up by
  1077.             SetDialogItemHandle(dlg, kPartInfoByFld, (Handle)DrawThumbnailUPP);
  1078.             dpis.authorName = ODGetModifiedBy( ev, partSU, kODNULL );
  1079.     
  1080.             WASSERT( !GetWRefCon(dlg) );        // will be null if no one's using it 
  1081.             SetWRefCon(dlg, (long)&dpis);
  1082.     
  1083.             // set up the scripting ID
  1084.             // If the frame is non-persistent, show the part's scripting ID.
  1085.             // Note that the scripting ID is not the same as the object ID returned by the
  1086.             // persistent object's GetID method.
  1087.             ODPersistentObjectID id;
  1088.             if ( frame->GetStorageUnit(ev) != kODNULL )
  1089.             {
  1090.                 id = draft->GetPersistentObjectID(ev,
  1091.                                 (ODPersistentObject*) frame,
  1092.                                 kODFrameObject);
  1093.             }
  1094.             else
  1095.             {
  1096.                 id = draft->GetPersistentObjectID(ev,
  1097.                                 (ODPersistentObject*) part,
  1098.                                 kODPartObject);
  1099.             }
  1100.             SetNumText(dlg, kPartInfoIDFld, (ODSLong)id);
  1101.         
  1102.             // set up viewas
  1103.             GetDialogItem(dlg, kPartInfoViewAsPopup, &itemType, &itemHandle, &scratchRect);
  1104.             
  1105.             ODTypeToken view = frame->GetViewType(ev);
  1106.         
  1107.             if (view == session->Tokenize(ev, kODViewAsFrame))
  1108.                 viewval = 1;
  1109.             else if (view == session->Tokenize(ev, kODViewAsLargeIcon))
  1110.                 viewval = 2;
  1111.             else if (view == session->Tokenize(ev, kODViewAsSmallIcon))
  1112.                 viewval = 3;
  1113.             else if (view == session->Tokenize(ev, kODViewAsThumbnail))
  1114.                 viewval = 4;
  1115.         
  1116.             SetControlValue((ControlHandle)itemHandle, viewval);
  1117.             MenuHandle viewAsMenu = ((PopupPrivateData*)(*(**(ControlHandle)itemHandle).contrlData))->mHandle;
  1118.             if ((isRootPartOfDocument) || (!allowEditing)) {
  1119.                 // disable everything but the current selection if no editing or root frame (current select is frame)
  1120.                 for (ODUShort i=1;i<=4;i++) {
  1121.                     if (viewval != i)
  1122.                         DisableItem(viewAsMenu, i);
  1123.                 }
  1124.             }
  1125.             else {
  1126.                 // enable them just in case they were disabled
  1127.                 EnableItem(viewAsMenu, 2);
  1128.                 EnableItem(viewAsMenu, 3);
  1129.                 EnableItem(viewAsMenu, 4);
  1130.             }
  1131.         
  1132.             if (isRootPartOfDocument) {
  1133.                 HideDialogItem(dlg, kPartInfoBundledText);
  1134.                 HideDialogItem(dlg, kPartInfoActPartRadBtn);
  1135.                 HideDialogItem(dlg, kPartInfoSelPartRadBtn);
  1136.                 
  1137.                 // set up stationery from aFrame and its part
  1138.                 isStationary = ODGetIsStationery(ev, frame);
  1139.                 SetDialogBoolean(dlg, kPartInfoStationeryCheckbox, isStationary, allowEditing);
  1140.             
  1141.                 // set up show links from the window
  1142.                 showLinks = window->ShouldShowLinks(ev);
  1143.                 SetDialogBoolean(dlg, kPartInfoShowLinksCheckbox, showLinks, allowEditing);    
  1144.             }
  1145.             else {
  1146.                 HideDialogItem(dlg, kPartInfoShowLinksCheckbox);
  1147.                 HideDialogItem(dlg, kPartInfoStationeryCheckbox);
  1148.                 HideDialogItem(dlg, kPartInfoMemorySizeButton);
  1149.  
  1150.                 // set up frozen
  1151.                 frameIsFrozen = frame->IsFrozen(ev);
  1152.                 SetDialogBoolean(dlg, kPartInfoSelPartRadBtn, frameIsFrozen, allowEditing);
  1153.                 SetDialogBoolean(dlg, kPartInfoActPartRadBtn, !frameIsFrozen, allowEditing);
  1154.             }
  1155.         
  1156.         // set up Settings…
  1157.             if (part->HasExtension(ev, kODSettingsExtension))
  1158.             {
  1159.                 settings = (ODSettingsExtension*)part->AcquireExtension(ev,kODSettingsExtension);
  1160.             }
  1161.             else
  1162.             {
  1163.                 HideDialogItem(dlg, kPartInfoSettingsButton);
  1164.             }
  1165.  
  1166.         // Display the dialog
  1167.             {
  1168.             TempODMenuBar    currentMenuBar = winstate->AcquireCurrentMenuBar(ev);
  1169.             ODDialogBegin(ev, session, currentMenuBar, dlg);
  1170.             }
  1171.     
  1172.             ODUseDialogScriptData( &dsd, dlg );
  1173.             ODIText* tmpText = PickOneIText( tempPartComments, partName );
  1174.             if ( tmpText )
  1175.                 dsd.SetScriptAndLockKeyboard( script = GetRealScriptCode(tmpText) );
  1176.     
  1177.             ShowWindow(dlg);
  1178.             modalFilter = NewModalFilterProc(CallCheckScriptFirstThenStdFilterProc);
  1179.             SetPort(dlg);
  1180.             SetDialogTextStyle(dlg, kPartInfoDlgID, script);
  1181.             
  1182.             do {
  1183.                 // Remember the currently selected kind
  1184.                 currentKindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
  1185.                 ModalDialog(modalFilter, &itemHit);
  1186.                 GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
  1187.                 switch (itemHit) {
  1188.                     case kPartInfoActPartRadBtn:
  1189.                     case kPartInfoSelPartRadBtn:
  1190.                         if (!GetControlValue((ControlHandle)itemHandle)) {
  1191.                             SetControlValue((ControlHandle)itemHandle,1);
  1192.                             itemHit = (itemHit == kPartInfoActPartRadBtn) ?
  1193.                                             kPartInfoSelPartRadBtn : kPartInfoActPartRadBtn;
  1194.                             GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
  1195.                             SetControlValue((ControlHandle)itemHandle,0);
  1196.                         }
  1197.                         break;
  1198.                     case kPartInfoStationeryCheckbox:
  1199.                     case kPartInfoShowLinksCheckbox:
  1200.                         SetControlValue((ControlHandle)itemHandle,
  1201.                                         1-GetControlValue((ControlHandle)itemHandle));
  1202.                         break;
  1203.                     case kPartInfoSettingsButton:
  1204.                         if (settings != kODNULL) {
  1205.                             ActivateAllControls(dlg, kODFalse); // deactivate control
  1206.                             settings->ShowSettings(ev,facet);
  1207.                             ActivateAllControls(dlg, kODTrue);    // reactivate control
  1208.                         }
  1209.                         break;
  1210.                     case kPartInfoMemorySizeButton:
  1211.                         ActivateAllControls(dlg, kODFalse); // deactivate control
  1212.                         ShowSizeDialog(ev, session, usersFile, partNameS255, allowEditing);
  1213.                         ActivateAllControls(dlg, kODTrue);    // reactivate control
  1214.                         break;
  1215.                     case kPartInfoKindPopup:
  1216.                         popUpValue = GetControlValue(kindPopupControlHandle);
  1217.                         if (popUpValue == translateItem)
  1218.                         {
  1219.                             ODUShort selectedIndex;
  1220.                             ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  1221.                             TempODEditor initialEditorID = GetThisEditorFromList(editorItem, editorsList);
  1222.                             TempODEditor tempEditorID = kODNULL;
  1223.                             ODEditor newEditorID = kODNULL;
  1224.     
  1225.                             // Return the kind popup to its current value 
  1226.                             SetPopupControlValue(kindPopupControlHandle, currentKindItem);
  1227.                             
  1228.                             session->GetWindowState(ev)->DeactivateFrontWindows(ev);
  1229.                             
  1230.                             ODBoolean doTranslate = session->GetTranslation(ev)->ShowTranslateDialog(
  1231.                                                                     ev,
  1232.                                                                     translateToList,
  1233.                                                                     translateToIndex,
  1234.                                                                     &selectedIndex,
  1235.                                                                     initialEditorID,
  1236.                                                                     kODTrue,
  1237.                                                                     &newEditorID);
  1238.                             tempEditorID = newEditorID;    // Dispose, eventually
  1239.                             if ( doTranslate )
  1240.                             {
  1241.                                 // Add translationKind to the list just above "Translate to…", 
  1242.                                 //  and make it the current selection.
  1243.                                 translateToIndex = selectedIndex;
  1244.     
  1245.                                 TempODType oldKind = GetThisKindFromList(currentKindItem, kindList);
  1246.                                 TempODType translationKind = GetThisKindFromList(translateToIndex, translateToList);
  1247.                                 AddTranslationKindToMenu(translationKind,
  1248.                                                             kindMenu,
  1249.                                                             translateItem-1, 
  1250.                                                             (translateToItem == 0),
  1251.                                                             session);
  1252.     
  1253.                                 // Add the translationKind to the end of kindList
  1254.                                 if ( translateToItem != 0 )
  1255.                                 {
  1256.                                     TempODType currentTranslationKind = GetThisKindFromList(translateToItem, kindList);
  1257.                                     kindList->Remove(ev, currentTranslationKind);
  1258.                                 }
  1259.                                 kindList->AddLast(ev, translationKind);
  1260.     
  1261.                                 if ( translateToItem == 0 )
  1262.                                 {
  1263.                                     translateToItem = translateItem;
  1264.                                     translateItem += 1;
  1265.                                 }
  1266.     
  1267.                                 SetPopupControlValue(kindPopupControlHandle, translateToItem);
  1268.     
  1269.                                 editorsList->RemoveAllEditors();
  1270.                                 ODBoolean anyEditors = SetupEditorMenu(translationKind,
  1271.                                                                         editorsList,
  1272.                                                                         editorMenu,
  1273.                                                                         editorPopupControlHandle,
  1274.                                                                         session);
  1275.  
  1276.                                 if ( anyEditors )
  1277.                                 {
  1278.                                     // Select editorID in the list (it SHOULD be in the list!)
  1279.                                     ODSShort editorItem = IndexOfEditorInList(editorsList, newEditorID);
  1280.                                     if ( editorItem != 0 )
  1281.                                         SetPopupControlValue(editorPopupControlHandle, editorItem);
  1282.                                     HideDialogItem(dlg, kPartInfoEditorLabel);
  1283.                                     HideDialogItem(dlg, kPartInfoNoEditorText);
  1284.                                     ShowDialogItem(dlg, kPartInfoEditorPopup);
  1285.                                 }
  1286.                                 else
  1287.                                 {
  1288.                                     HideDialogItem(dlg, kPartInfoEditorPopup);
  1289.                                     ShowDialogItem(dlg, kPartInfoEditorLabel);
  1290.                                     ShowDialogItem(dlg, kPartInfoNoEditorText);
  1291.                                 }
  1292.  
  1293.                                 TempODType newCat = ODGetFirstCategoryOfKind(ev, translationKind, nsm);
  1294.                                 TempODType oldCat = ODGetFirstCategoryOfKind(ev, oldKind, nsm);
  1295.                                 if ( !ODISOStrEqual(newCat, oldCat) )
  1296.                                 {
  1297.                                     DisposeIText(dpis.category);
  1298.                                     dpis.category = ODGetCatFromKind(ev, translationKind, nsm);
  1299.                                     InvalRect(&partInfoCategoryRect);
  1300.                                 }
  1301.                             }
  1302.                         }
  1303.                         else if ( popUpValue != currentKindItem )
  1304.                         {
  1305.                             // Determine the old and new kinds for later
  1306.                             TempODType oldKind = GetThisKindFromList(currentKindItem, kindList);
  1307.                             TempODType newKind = GetThisKindFromList(popUpValue, kindList);
  1308.  
  1309.                             // Remember the currently selected editor
  1310.                             ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  1311.                             TempODEditor lastEditorID = GetThisEditorFromList(editorItem, editorsList);
  1312.  
  1313.                             editorsList->RemoveAllEditors();
  1314.                             SetupEditorMenu(newKind,
  1315.                                             editorsList,
  1316.                                             editorMenu,
  1317.                                             editorPopupControlHandle,
  1318.                                             session);
  1319.  
  1320.                             // Reselect the last editor if it supports the new kind
  1321.                             ODSShort newEditorItem = 0;
  1322.                             if ( EditorSupportsKind(nsm, lastEditorID, newKind) )
  1323.                                 newEditorItem = IndexOfEditorInList(editorsList, lastEditorID);
  1324.                             if ( newEditorItem != 0 )
  1325.                                 SetPopupControlValue(editorPopupControlHandle, newEditorItem);
  1326.                             else
  1327.                                 Draw1Control(editorPopupControlHandle);
  1328.     
  1329.                             // Change the category string if changed
  1330.                             TempODType oldCat = ODGetFirstCategoryOfKind(ev, oldKind, nsm);
  1331.                             TempODType newCat = ODGetFirstCategoryOfKind(ev, newKind, nsm);
  1332.                             if ( !ODISOStrEqual(newCat, oldCat) )
  1333.                             {
  1334.                                 DisposeIText(dpis.category);
  1335.                                 dpis.category = ODGetCatFromKind(ev, newKind, nsm);
  1336.                                 SetPort(dlg);
  1337.                                 InvalRect(&partInfoCategoryRect);
  1338.                             }
  1339.                         }
  1340.                     break;
  1341.                     
  1342.                 case kPartInfoCancelBtn:    
  1343.                     if (allowEditing) {        // cancel, make sure we restore all the values
  1344.                         TempODName newPartName = GetITextFromDialog(dlg, kPartInfoNameEditFld,
  1345.                                             dsd.Script(), dsd.Language());
  1346.                         if (newPartName) {
  1347.                             if (!ITextStrEqual(newPartName, partName))
  1348.                                 ODSetPartName(ev, frame, partName, kAEAsk);
  1349.                         }
  1350.                         TempODName newPartComment = GetITextFromDialog(dlg, kPartInfoCommentsEditFld,
  1351.                                             dsd.Script(), dsd.Language());
  1352.                         if (newPartComment) {
  1353.                             if (!ITextStrEqual(newPartComment, tempPartComments))
  1354.                                 ODSetComments(ev, frame, tempPartComments);
  1355.                         }
  1356.                     }
  1357.                     break;
  1358.                     
  1359.                 case kPartInfoOKBtn:
  1360.                     if (allowEditing)
  1361.                     {
  1362.                         script = dsd.Script();
  1363.                         ODLangCode lang = dsd.Language();
  1364.                         
  1365.                         // update Name
  1366.                             
  1367.                         ODIText *newPartName = GetITextFromDialog(dlg, kPartInfoNameEditFld,
  1368.                                                 script, lang);
  1369.                         if (newPartName) {
  1370.                             if (!ITextStrEqual(newPartName, partName)) {
  1371.                                 if (!ODSetPartName(ev, frame, newPartName, kAEAsk)) {
  1372.                                     itemHit = kPartInfoNameEditFld;
  1373.                                     SelectDialogItemText(dlg, kPartInfoNameEditFld, 0, GetITextStringLength(newPartName));
  1374.                                     DisposeIText(newPartName);
  1375.                                     ActivateAllControls(dlg, kODFalse); // deactivate control
  1376.                                     (void) ShowAlert(ev, kPartInfoInvalidNameAlertID, kODNULL, session);
  1377.                                     ActivateAllControls(dlg, kODTrue);    // reactivate control
  1378.                                     break;
  1379.                                 }
  1380.                             }
  1381.                             DisposeIText(newPartName);
  1382.                         }
  1383.                     
  1384.                         // update Comments
  1385.                         ODIText *newPartComment = GetITextFromDialog(dlg, kPartInfoCommentsEditFld,
  1386.                                                     script, lang);
  1387.                         if (newPartComment) {
  1388.                             if (!ITextStrEqual(newPartComment, tempPartComments)) {
  1389.                                 ODSetComments(ev, frame, newPartComment);
  1390.                                 TempODName actualPartComments = ODGetComments(ev, frame, kODNULL);
  1391.                                 if (!ITextStrEqual(newPartComment, actualPartComments)) {
  1392.                                     itemHit = kPartInfoCommentsEditFld;
  1393.                                     SetDialogFromIText(dlg, kPartInfoCommentsEditFld, actualPartComments, allowEditing, kODTrue);
  1394.                                     DisposeIText(newPartComment);
  1395.                                     ActivateAllControls(dlg, kODFalse); // deactivate control
  1396.                                     (void) ShowAlert(ev, kPartInfoLongCommentAlertID, kODNULL, session);
  1397.                                     ActivateAllControls(dlg, kODTrue);    // reactivate control
  1398.                                     break;
  1399.                                 }
  1400.                             }
  1401.                             DisposeIText(newPartComment);
  1402.                         }
  1403.                     
  1404.                         if (isRootPartOfDocument) {
  1405.                         // update Stationery
  1406.                             ODBoolean checkBoxValue = GetDialogBoolean(dlg, kPartInfoStationeryCheckbox);
  1407.                             if (checkBoxValue != isStationary)
  1408.                                 ODSetIsStationery(ev, frame, checkBoxValue);
  1409.                     
  1410.                         // update Show Links
  1411.                             checkBoxValue = GetDialogBoolean(dlg, kPartInfoShowLinksCheckbox);
  1412.                             if (checkBoxValue != showLinks)
  1413.                                 SetAllWindowShowLinks(ev, winstate, checkBoxValue);
  1414.         //                        window->SetShouldShowLinks(ev,checkBoxValue);
  1415.                         }
  1416.                         else {
  1417.                         // update Frozen
  1418.                             ODBoolean checkBoxValue = GetDialogBoolean(dlg, kPartInfoSelPartRadBtn);
  1419.                             if (checkBoxValue != frameIsFrozen)
  1420.                                 frame->SetFrozen(ev, checkBoxValue);
  1421.                         }
  1422.                     
  1423.                     // update ViewAs
  1424.                         GetDialogItem(dlg, kPartInfoViewAsPopup, &itemType, &itemHandle, &scratchRect);
  1425.                         popUpValue = GetControlValue((ControlHandle)itemHandle);
  1426.                         if (popUpValue != viewval )
  1427.                         {
  1428.                             switch (popUpValue)
  1429.                             {
  1430.                                 case 1:    // view as frame
  1431.                                     frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsFrame));
  1432.                                     break;
  1433.                                 case 2: // view as large icon
  1434.                                     frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsLargeIcon));
  1435.                                     break;
  1436.                                 case 3: // view as small icon
  1437.                                     frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsSmallIcon));
  1438.                                     break;
  1439.                                 case 4: // view as thumbnail
  1440.                                     frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsThumbnail));
  1441.                                     break;
  1442.                                 default:
  1443.                                     break;
  1444.                             }
  1445.                         }
  1446.                         
  1447.                     // update Kind or Editor
  1448.                         currentKindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
  1449.                         TempODType newKind = GetThisKindFromList(currentKindItem, kindList);
  1450.                 
  1451.                         ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  1452.                         TempODEditor newEditorID = GetThisEditorFromList(editorItem, editorsList);
  1453.                 
  1454.                         TempODType partKind = ODGetKindFromPartSU(ev, partSU);
  1455.                         TempODEditor partEditor = GetCurrentEditorForPart(part);
  1456.                 
  1457.                         if ( ((ODType) newKind) && !ODISOStrEqual(newKind, partKind) )
  1458.                         {
  1459.                             if ( (currentKindItem == translateToItem) && (translateToItem > 0) )
  1460.                             {
  1461.                                 ODUShort translateFromIndex = 
  1462.                                             GetOrderedCollectionElement(translateFromList, translateToIndex);
  1463.                                 TempODType fromKind = GetThisKindFromList(translateFromIndex, kindList);
  1464.                 
  1465.                                 // If fromKind does not yet exist, force part to change to that kind.
  1466.                                 // Otherwise, force the part to externalize any changes to its storage unit.
  1467.                                 ODBoolean forceChangeKind = !partSU->Exists(ev, kODPropContents, (ODType) fromKind, 0);
  1468.                                 if ( forceChangeKind )
  1469.                                     part->ChangeKind(ev, (ODType) fromKind);
  1470.                                 else
  1471.                                     part->Externalize(ev);
  1472.                 
  1473.                                 partSU->Focus(ev, kODPropContents, kODPosUndefined, (ODType) fromKind, 0, kODPosUndefined);
  1474.                                 TempODStorageUnitView fromView = partSU->CreateView(ev);
  1475.                                 
  1476.                                 partSU->Focus(ev, kODPropContents, kODPosAll, kODTypeAll, 0, kODPosUndefined);
  1477.                 
  1478.                                 partSU->AddValue(ev, (ODType) newKind);
  1479.                                 TempODStorageUnitView toView = partSU->CreateView(ev);
  1480.                                 
  1481.                                 TRY
  1482.                                     session->GetTranslation(ev)->TranslateView(ev, fromView, toView);
  1483.                                 CATCH_ALL
  1484.                                     // Remove the translated value type
  1485.                                     if ( ODSUExistsThenFocus(ev, partSU, kODPropContents, newKind) )
  1486.                                         partSU->Remove(ev);
  1487.                                     // If translation fails after changing the kind, change kind back
  1488.                                     if ( forceChangeKind )
  1489.                                         part->ChangeKind(ev, partKind);
  1490.                                     RERAISE;
  1491.                                 ENDTRY
  1492.         
  1493.                                 ChangeKindAndEditor(ev, part, newKind, newEditorID, nsm);
  1494.                             }
  1495.                             else
  1496.                                 ChangeKindAndEditor(ev, part, newKind, newEditorID, nsm);
  1497.                         }
  1498.                         else if ( ((ODEditor) newEditorID) && !ODISOStrEqual(newEditorID, partEditor) )
  1499.                         {
  1500.                             ODReleaseObject(ev, settings); // editor may delete its settings, so release it first
  1501.                             ChangeEditor(part, newEditorID);
  1502.                         }
  1503.                     }
  1504.                     break;
  1505.                         
  1506.                 default: break;
  1507.                 }
  1508.             } while ((itemHit != kPartInfoOKBtn) && (itemHit != kPartInfoCancelBtn));
  1509.             
  1510.         CATCH_ALL
  1511.             error = ErrorCode();
  1512.         ENDTRY
  1513.         
  1514.         ODDialogEnd();
  1515.  
  1516.         DeleteMenu(kPartInfoEditorMenu);
  1517.         ReleaseResource((Handle)editorMenu);
  1518.         DeleteMenu(kPartInfoKindMenu);
  1519.         ReleaseResource((Handle)kindMenu);
  1520.     
  1521.         DisposeIText(dpis.category);
  1522.         DisposeIText(dpis.authorName);
  1523.         
  1524.         DisposeIText(partName);
  1525.     
  1526.         ODReleaseObject(ev, settings);
  1527.         ODDeleteObject (editorsList);
  1528.         ODDeleteObject (kindList);
  1529.         ODDeleteObject (translateToList);
  1530.         ODDeleteObject (translateFromList);
  1531.         ODDeleteObject (usersFile);
  1532.         
  1533.         DisposeRoutineDescriptor(DrawBoxItemUPP);
  1534.         if (DrawThumbnailUPP)
  1535.             DisposeRoutineDescriptor(DrawThumbnailUPP);
  1536.         ODDisposeRoutineDescriptor(DrawIntlStaticTextUPP);
  1537.     
  1538.         if (dlg)
  1539.             DisposeDialog(dlg);
  1540.             
  1541.         DisposeRoutineDescriptor( modalFilter );
  1542.          
  1543.         } // EndUsingResources of CUsingLibraryResources.
  1544.  
  1545.         ODDisposeHandle(gArrowBtnsPictOff);
  1546.         ODDisposeHandle(gArrowBtnsPictTopOn);
  1547.         ODDisposeHandle(gArrowBtnsPictBotOn);
  1548.     
  1549.         ODReleaseObject(ev, part);
  1550.     
  1551.         winstate->ActivateFrontWindows(ev);
  1552.     
  1553.         THROW_IF_ERROR(error);
  1554.     
  1555.     SOM_CATCH_ALL
  1556.         itemHit = kPartInfoCancelBtn;
  1557.     SOM_ENDTRY
  1558.  
  1559.     return itemHit != kPartInfoCancelBtn;
  1560. }
  1561.  
  1562. #ifdef MWERKS
  1563. #if GENERATINGPOWERPC
  1564. #if __option(global_optimizer)
  1565. // Restore settings [see before fn]
  1566. #pragma pop
  1567. #endif
  1568. #endif
  1569. #endif
  1570.  
  1571. SOM_Scope void  SOMLINK ODInfosomUninit(ODInfo *somSelf)
  1572. {
  1573.     //ODInfoData *somThis = ODInfoGetData(somSelf);
  1574.     ODInfoMethodDebug("ODInfo","ODInfosomUninit");
  1575.  
  1576.     ODInfo_parent_ODObject_somUninit(somSelf);
  1577. }
  1578.  
  1579.  
  1580. //-------------------------------------------------------------------------------------
  1581. // Kind Menu manipulation functions
  1582. //-------------------------------------------------------------------------------------
  1583. // copied from LinkDlgs.cpp (!with changes by TÇ)
  1584. //------------------------------------------------------------------------------
  1585. //------------------------------------------------------------------------------
  1586. // GenerateEditorsList
  1587. //------------------------------------------------------------------------------
  1588.  
  1589. ODStatic void GenerateEditorsList(ODSShort currentKindItem, 
  1590.                                     ODTypeList* kindsList,
  1591.                                     EditorSet* editorsList, 
  1592.                                     ODNameSpaceManager* nsm)
  1593. {
  1594.     ODSShort i = 1;
  1595.     Environment* ev = somGetGlobalEnvironment();
  1596.  
  1597.         //clear editorsList
  1598.     editorsList->RemoveAllEditors();
  1599.     
  1600.     ODTypeListIterator* kindIter = kindsList->CreateTypeListIterator(ev);
  1601.     for (ODType kind = kindIter->First(ev);
  1602.         kindIter->IsNotComplete(ev);
  1603.         kind = kindIter->Next(ev), i++)
  1604.     {
  1605.         if (i == currentKindItem)
  1606.             GetAllEditorsForKind( nsm, kind, editorsList );
  1607.         ODDisposePtr(kind);
  1608.     }
  1609.     ODDeleteObject( kindIter );
  1610. }
  1611.  
  1612. //------------------------------------------------------------------------------
  1613. // InitEditorPopup
  1614. //------------------------------------------------------------------------------
  1615.  
  1616. ODStatic void InitEditorPopup ( EditorSet* editorsList,
  1617.                                    ODEditor editorID,
  1618.                                    ControlHandle itemHandle,
  1619.                                    ODSShort* currentEditorItem,
  1620.                                    MenuHandle editorMenu )
  1621. {
  1622.     DeleteAllMenuItems( editorMenu );
  1623.     AddEditorsToMenu(editorsList,editorMenu, gSession);
  1624.  
  1625.     ODSShort item = 1;
  1626.     EditorSetIterator* editorIter = editorsList->CreateIterator();
  1627.     
  1628.     // determine which editor to check mark
  1629.     for (ODEditor editor = editorIter->First();
  1630.         editorIter->IsNotComplete();
  1631.         editor = editorIter->Next(), ++item)
  1632.     {
  1633.         if (ODISOStrEqual(editor, editorID))
  1634.             break;
  1635.     }
  1636.     ODDeleteObject( editorIter);
  1637.  
  1638.     SetControlMinimum(itemHandle, 1);
  1639.     SetControlMaximum(itemHandle, editorsList->GetEditorCount());
  1640.     SetControlValue(itemHandle, item);
  1641.     *currentEditorItem = item;
  1642. }
  1643.  
  1644.  
  1645. //------------------------------------------------------------------------------
  1646. // SetCategory
  1647. //------------------------------------------------------------------------------
  1648. #if 0
  1649. ODStatic void SetCategory(    ODPart* part,
  1650.                             Handle categoryItem, 
  1651.                             ODNameSpaceManager* nsm)
  1652. {
  1653.     StringHandle strHandle = 0;
  1654.     ODName*        name;
  1655.  
  1656.     Environment* ev = somGetGlobalEnvironment();
  1657.  
  1658.     name = ODGetCategory(ev, part, nsm);
  1659.     strHandle = (StringHandle) NewHandle(256);
  1660.     HLock((Handle) strHandle);
  1661.     IntlToPStr(name, *strHandle);
  1662.     SetDialogItemText(categoryItem, *strHandle);
  1663.     HUnlock((Handle) strHandle);
  1664.     DisposeHandle((Handle)strHandle);
  1665.     DisposeIText(name);
  1666. }
  1667. #endif
  1668.  
  1669. //------------------------------------------------------------------------------
  1670. // SetModCreatDateTimeText
  1671. //------------------------------------------------------------------------------
  1672. ODStatic void SetModCreatDateTimeText(Environment* ev, ODStorageUnit* partSU )
  1673. {
  1674.     Str255        createDateString = "\p"; 
  1675.     Str255        createTimeString = "\p";
  1676.     Str255        modDateString = "\p"; 
  1677.     Str255        modTimeString = "\p";
  1678.     
  1679.     ODULong createDateTime = ODGetCreationDate(ev, partSU);
  1680.     if ( createDateTime == 0 )
  1681.     {
  1682.         StringHandle str = GetString(kODPartInfoStrUnknownID);
  1683.         if ( str != kODNULL )
  1684.         {
  1685.             ODLockHandle((ODHandle) str);
  1686.             ODBlockMove((ODPtr) *str, (ODPtr) createDateString, (ODULong) (*str[0])+1);
  1687.             ODUnlockHandle((ODHandle) str);
  1688.             ReleaseResource((Handle) str);
  1689.         }
  1690.         else
  1691.         {
  1692.             createDateString[0] = (char) 0;
  1693.         }
  1694.         createTimeString[0] = (char) 0;
  1695.     }
  1696.     else
  1697.     {
  1698.         DateString(createDateTime, abbrevDate, createDateString, kODNULL);
  1699.         TimeString(createDateTime, kODFalse, createTimeString, kODNULL);
  1700.     }
  1701.  
  1702.     ODULong modDateTime = ODGetModificationDate(ev, partSU);
  1703.  
  1704.     if ( modDateTime == 0 )
  1705.     {
  1706.         StringHandle str = GetString(kODPartInfoStrUnknownID);
  1707.         if ( str != kODNULL )
  1708.         {
  1709.             ODLockHandle((ODHandle) str);
  1710.             ODBlockMove((ODPtr) *str, (ODPtr) modDateString, (ODULong) (*str[0])+1);
  1711.             ODUnlockHandle((ODHandle) str);
  1712.             ReleaseResource((Handle) str);
  1713.         }
  1714.         else
  1715.         {
  1716.             modDateString[0] = (char) 0;
  1717.         }
  1718.         modTimeString[0] = (char) 0;
  1719.     }
  1720.     else
  1721.     {
  1722.         DateString(modDateTime, abbrevDate, modDateString, kODNULL);
  1723.         TimeString(modDateTime, kODFalse, modTimeString, kODNULL);
  1724.     }
  1725.  
  1726.     ParamText( createDateString, createTimeString, modDateString, modTimeString);
  1727. }
  1728.  
  1729. //------------------------------------------------------------------------------
  1730. // SetSizeText
  1731. //------------------------------------------------------------------------------
  1732. ODStatic void SetSizeText(DialogPtr dlg, ODSShort item, ODULong size)
  1733. {
  1734.     Str255    text;
  1735.     Str63    sizeString;
  1736.     short    strTemplateID;
  1737.  
  1738.     if ( size < 1024 )
  1739.     {
  1740.         NumToString(size, sizeString);
  1741.         strTemplateID = kODPartInfoSizeInBytes;
  1742.     }
  1743.     else
  1744.     {
  1745.         // Round off to nearest K
  1746.         size = (size + 512) / 1024;
  1747.         NumToString(size, sizeString);
  1748.         strTemplateID = kODPartInfoSizeInK;
  1749.     }
  1750.  
  1751.     //CUsingLibraryResources r;
  1752.     ReplaceIntoString(strTemplateID, sizeString, kODNULL, text);
  1753.  
  1754.     SetDialogFromPStr(dlg, item, text, kODFalse, kODFalse);
  1755. }
  1756.  
  1757.  
  1758. //------------------------------------------------------------------------------
  1759. // SetModifiedByText
  1760. //------------------------------------------------------------------------------
  1761.  
  1762. ODStatic void SetModifiedByText(DialogPtr dlg, ODSShort item, ODName* name)
  1763. {
  1764.     short    itemType;
  1765.     Handle    itemHandle;
  1766.     Rect    itemRect;
  1767.  
  1768.     // I suspect that we'll have to change the model here to support
  1769.     // two-byte text.  Rather than stick the text into the dialog
  1770.     // before it's drawn and then let the Dialog Mgr. draw it with
  1771.     // no information about what script to use, we need to draw it
  1772.     // ourselves via a drawproc that will get called each time it's
  1773.     // redrawn.  Confirm this suspicion before doing the work....
  1774.  
  1775. //    Str255    text = "\p";
  1776.  
  1777. //    if (name) 
  1778. //        IntlToPStr(name,(StringPtr)&text);
  1779.     GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
  1780.     PaintRect( &itemRect );
  1781. //    SetDialogItemText(itemHandle,text);
  1782.  
  1783.     if (name) 
  1784.         DrawITextInDlogBox(name, &itemRect, dlg, kODTrue);
  1785. }
  1786.  
  1787. //------------------------------------------------------------------------------
  1788. // DrawThumbnail
  1789. // Now draws thumbnail *and* the modified by name.
  1790. //------------------------------------------------------------------------------
  1791.  
  1792. pascal void DrawThumbnail(DialogPtr theDialog, short theItem)
  1793. {
  1794.     Rect     frameRect;
  1795.     Handle    scratchHandle = kODNULL;
  1796.     short    scratchKind;
  1797.     ODPtr    theIcon = kODNULL;
  1798.     ODIconFamily iconSuite = kODNULL;
  1799.     Environment*        ev = somGetGlobalEnvironment();
  1800.     
  1801.     GetDialogItem(theDialog, theItem, &scratchKind, &scratchHandle, &frameRect);
  1802.     DrawProcInfo dpi = (DrawProcInfo)GetWRefCon(theDialog);
  1803.  
  1804.     switch( theItem )
  1805.     {
  1806.         case kPartInfoPartThumbnail:
  1807.             iconSuite = ODGetIconFamily(ev, gFrame );
  1808.             if (iconSuite)
  1809.             {
  1810.                 IconAlignmentType align = atAbsoluteCenter;
  1811.                 IconTransformType transform = ttNone;
  1812.                 ODError result = PlotIconSuite( &frameRect, align, transform,
  1813.                         (Handle)iconSuite );
  1814.                 DisposeIconSuite( (Handle)iconSuite,kODTrue );
  1815.             }
  1816.             else
  1817.                 FrameRect(&frameRect);
  1818.             break;
  1819.         case kPartInfoByFld:
  1820.             if (dpi->authorName) 
  1821.                 DrawITextInDlogBox( dpi->authorName, &frameRect, theDialog, kODTrue );
  1822.             break;
  1823.         case kPartInfoCategoryFld:
  1824.             if (dpi->category) 
  1825.                 DrawITextInDlogBox( dpi->category, &frameRect, theDialog, kODTrue );
  1826.             break;
  1827.     }
  1828. }
  1829.  
  1830. //------------------------------------------------------------------------------
  1831. // DeleteAllMenuItems
  1832. //------------------------------------------------------------------------------
  1833. ODStatic void DeleteAllMenuItems(MenuHandle theMenu)
  1834. {
  1835.     ODUShort i;
  1836.  
  1837.     for (i = CountMItems(theMenu);  i > 0;  --i)
  1838.     {
  1839.         DeleteMenuItem(theMenu, i);
  1840.     }
  1841. }
  1842.  
  1843. //------------------------------------------------------------------------------
  1844. // Document Heap Dialog Functions
  1845. //------------------------------------------------------------------------------
  1846.  
  1847. //=========================================================================
  1848. // Constants
  1849. //=========================================================================
  1850.  
  1851. static const ODULong kDocHeapSizeDelta = 32;
  1852.  
  1853.  
  1854. #define k1K                    1024
  1855.  
  1856. // copied from ShellDef.h!
  1857. // Should be same as min size in DocStub.r, SIZE -1 resource
  1858. // 1242449 Should probably create a common ≈def.h constant kDocStubMinHeapSize
  1859. // accessible from both subsystems.
  1860. #define    kDocStubMinHeapSize    (230 * 1024)    // 220K min app heap [Was 256k]
  1861. #define    kDocStubDefaultSize    (230 * 1024)    // 220K default app heap [Was 384k]
  1862.  
  1863. //=========================================================================
  1864. // DocHeapArrowButtonsFilterProc
  1865. //=========================================================================
  1866.  
  1867. pascal Boolean
  1868. DocHeapArrowButtonsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit);
  1869.  
  1870. //=========================================================================
  1871. // ShowSizeDialog
  1872. //=========================================================================
  1873.  
  1874. ODStatic void ShowSizeDialog(Environment* ev, ODSession* session, 
  1875.             PlatformFile* file, Str255 partNameS255, ODBoolean allowEditing)
  1876. {
  1877.     THROW_IF_NULL(ev);
  1878.     THROW_IF_NULL(session);
  1879.     THROW_IF_NULL(file);
  1880.  
  1881.     DialogPtr      dlg = kODNULL;
  1882.     short          itemHit = kDocHeapCancelBtn;
  1883.     Handle        itemHandle = kODNULL;
  1884.     Handle        scratchHandle = kODNULL;
  1885.     Rect        scratchRect;
  1886.  
  1887.     dlg  = ODGetNewDialog(ev,kDocHeapDlgID,session);
  1888.     
  1889.     THROW_IF_NULL(dlg);
  1890.     SetPort(dlg);
  1891.     SetDialogTextStyle(dlg, kDocHeapDlgID, smCurrentScript);
  1892.  
  1893.     // Set the draw routine for the default button outline item
  1894.     SetDialogItemHandle(dlg, kDocHeapDefaultButtonItem, (Handle)GetODOutlineDefaultButtonDrawProc());
  1895.     
  1896.     // Set the Document name text field
  1897.     SetDialogFromPStr(dlg, kDocHeapDocumentNameFld, partNameS255, kODFalse, kODFalse);
  1898.     
  1899.     // Set the OpenDoc Default Size
  1900.     ODULong curDefaultSize = DHGetODDefaultHeapSize();
  1901.     if (curDefaultSize < kDocStubMinHeapSize/k1K)
  1902.         curDefaultSize = kDocStubMinHeapSize/k1K;
  1903.     SetNumText(dlg, kDocHeapDefaultSizeFld, curDefaultSize);
  1904.     
  1905.     // Set the Document Preferred Size
  1906.     ODULong curPreferredSize = 
  1907.         DHGetDocumentPreferredHeapSize(file);
  1908.     ODBoolean curDefaultSizeChosen = (curPreferredSize == 0);
  1909.     if (curDefaultSizeChosen)
  1910.         curPreferredSize = curDefaultSize;
  1911.         
  1912.     SetNumText(dlg, kDocHeapPreferdSizeFld, curPreferredSize);
  1913.     
  1914.     // set up the radio button, if editing not allowed disable the other option
  1915.     SetDialogBoolean(dlg, kDocHeapDefaultSizeRadBtn, curDefaultSizeChosen, allowEditing | curDefaultSizeChosen);
  1916.     SetDialogBoolean(dlg, kDocHeapPreferdSizeRadBtn, !curDefaultSizeChosen, allowEditing | !curDefaultSizeChosen);
  1917.  
  1918.     ODULong newPreferredSize = curPreferredSize;
  1919.     ODULong newDefaultSize = curDefaultSize;
  1920.     ODBoolean newDefaultSizeChosen = curDefaultSizeChosen;
  1921.     
  1922.     if (!allowEditing) {
  1923.         // no editing, then hide the arrow buttons for changing the size
  1924.         HideDialogItem(dlg, kDocHeapDefaultSizeTopBtnRect);
  1925.         HideDialogItem(dlg, kDocHeapPreferdSizeTopBtnRect);
  1926.         HideDialogItem(dlg, kDocHeapDefaultSizeBotBtnRect);
  1927.         HideDialogItem(dlg, kDocHeapPreferdSizeBotBtnRect);
  1928.         HideDialogItem(dlg, kDocHeapPreferdSizeBtns);
  1929.         HideDialogItem(dlg, kDocHeapDefaultSizeBtns);
  1930.         HideDialogItem(dlg, kDocHeapMakeChangeStatText);
  1931.         HideDialogItem(dlg, kDocHeapChangeNextLaunchStatText);
  1932.     }
  1933.     
  1934.     ModalFilterUPP docHeapSizeUPP = NewModalFilterProc(&DocHeapArrowButtonsFilterProc);
  1935.     
  1936.     // Display the dialog
  1937.     ShowWindow(dlg);
  1938.     do {
  1939.         ODULong* newSizePtr;
  1940.         ODSShort itemType;
  1941.         ODULong delta;
  1942.         ODSShort btnsItemNum;
  1943.         ModalDialog(docHeapSizeUPP, &itemHit);
  1944.         GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
  1945.         switch (itemHit) {
  1946.             case kDocHeapDefaultSizeTopBtnRect:
  1947.             case kDocHeapPreferdSizeTopBtnRect:
  1948.             case kDocHeapDefaultSizeBotBtnRect:
  1949.             case kDocHeapPreferdSizeBotBtnRect:
  1950.                 newDefaultSizeChosen = 
  1951.                     (itemHit == kDocHeapDefaultSizeTopBtnRect ||
  1952.                      itemHit == kDocHeapDefaultSizeBotBtnRect);
  1953.                      
  1954.                 btnsItemNum = 
  1955.                     newDefaultSizeChosen ? 
  1956.                     kDocHeapDefaultSizeBtns : 
  1957.                     kDocHeapPreferdSizeBtns ;
  1958.  
  1959.                 GetDialogItem(dlg, btnsItemNum, &itemType, &itemHandle, &scratchRect);
  1960.                 SetDialogItem(dlg, btnsItemNum, picItem, gArrowBtnsPictOff, 
  1961.                                 &scratchRect);
  1962.                                 
  1963.                 delta = kDocHeapSizeDelta;
  1964.                 if (itemHit == kDocHeapDefaultSizeBotBtnRect ||
  1965.                     itemHit == kDocHeapPreferdSizeBotBtnRect)
  1966.                     delta = -kDocHeapSizeDelta;
  1967.                     
  1968.                 newSizePtr =    
  1969.                     newDefaultSizeChosen ?
  1970.                     &newDefaultSize :
  1971.                     &newPreferredSize ;
  1972.                 
  1973.                 (*newSizePtr) += delta;    
  1974.                 if (*newSizePtr < kDocStubMinHeapSize/k1K)
  1975.                     *newSizePtr = kDocStubMinHeapSize/k1K;
  1976.  
  1977.                 SetNumText(dlg, 
  1978.                     newDefaultSizeChosen ? kDocHeapDefaultSizeFld : kDocHeapPreferdSizeFld,
  1979.                     *newSizePtr);
  1980.  
  1981.         // NOTE: deliberately fall through to next bunch o' case statements
  1982.         // to pick the appropriate radio button
  1983.             case kDocHeapDefaultSizeRadBtn:
  1984.             case kDocHeapPreferdSizeRadBtn:
  1985.             case kDocHeapDefaultSizeFld:
  1986.             case kDocHeapPreferdSizeFld:
  1987.                 if (allowEditing) {
  1988.                     newDefaultSizeChosen = 
  1989.                     (itemHit == kDocHeapDefaultSizeRadBtn ||
  1990.                      itemHit == kDocHeapDefaultSizeFld ||
  1991.                      itemHit == kDocHeapDefaultSizeTopBtnRect ||
  1992.                      itemHit == kDocHeapDefaultSizeBotBtnRect ||
  1993.                      itemHit == kDocHeapDefaultSizeBtns);
  1994.                     SetDialogBoolean(dlg, kDocHeapDefaultSizeRadBtn, newDefaultSizeChosen, kODTrue);
  1995.                     SetDialogBoolean(dlg, kDocHeapPreferdSizeRadBtn, !newDefaultSizeChosen, kODTrue);
  1996.                 }
  1997.                 break;
  1998.             default: 
  1999.                 break;
  2000.         }
  2001.     } while ((itemHit != kDocHeapOKBtn) && (itemHit != kDocHeapCancelBtn));
  2002.     if ((itemHit == kDocHeapOKBtn) && (allowEditing))
  2003.     {
  2004.         if (newDefaultSizeChosen != kODFalse)
  2005.         {
  2006.             if (newDefaultSize != curDefaultSize || !curDefaultSizeChosen)
  2007.                 DHSetODDefaultHeapSize(file, newDefaultSize);
  2008.             DHClearDocumentPreferredHeapSize(file);
  2009.         }
  2010.         else
  2011.         {
  2012.             if (newPreferredSize != curPreferredSize || curDefaultSizeChosen)
  2013.                 DHSetDocumentPreferredHeapSize(file, newPreferredSize);
  2014.         }
  2015.     }
  2016.     
  2017.     ODDisposeRoutineDescriptor(docHeapSizeUPP);
  2018.     DisposeDialog(dlg);
  2019. }
  2020.  
  2021. ODStatic ODULong    DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID)
  2022. {
  2023. // returns 0 if the resource is not found
  2024.     ODULong size = 0;
  2025.     ODPtr sizeRes =
  2026.         file->ReadResourcePtr(kSIZERsrcType, resourceID, kODNULL);
  2027.     if (sizeRes != kODNULL)
  2028.     {
  2029.         memcpy(&size, ((char*)sizeRes)+2, sizeof(size)); // Should probably use a constant.
  2030.         ODDisposePtr(sizeRes);
  2031.     }
  2032.     return size / 1024;
  2033. }
  2034.  
  2035. ODStatic void         DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID, 
  2036.         PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes)
  2037. {
  2038.     if (fromFile == kODNULL)
  2039.         fromFile = file;
  2040.     ODULong sizeOfResource;
  2041.     ODPtr sizeRes =
  2042.         fromFile->ReadResourcePtr(kSIZERsrcType, fromResID, &sizeOfResource);
  2043.     
  2044.     if (sizeRes != kODNULL)
  2045.     {
  2046.         numKBytes *= 1024; // Should probably use a constant.
  2047.         memcpy(((char*)sizeRes)+2, &numKBytes, sizeof(numKBytes)); // Should probably use a constant.
  2048.     
  2049.         file->WriteResourcePtr(kSIZERsrcType, resourceID, sizeRes, sizeOfResource);
  2050.         ODDisposePtr(sizeRes);
  2051.     }
  2052. }
  2053.  
  2054.  
  2055. ODStatic ODULong    DHGetODDefaultHeapSize()
  2056. {
  2057.     Environment*        ev = somGetGlobalEnvironment();
  2058.     PlatformFile* file = gSession->GetNameSpaceManager(ev)->GetPreferences(ev)->GetPrefsFile();
  2059.     ODULong size = DHGetPreferredSizeInSIZE(file, -1); // Should probably use a constant.
  2060.     if (size == 0)
  2061.         size = kDocStubDefaultSize/k1K;
  2062.     return size;
  2063. }
  2064.  
  2065. ODStatic void        DHSetODDefaultHeapSize(PlatformFile* documentFile, ODULong numKBytes)
  2066. {
  2067.     Environment*        ev = somGetGlobalEnvironment();
  2068.     PlatformFile* file = gSession->GetNameSpaceManager(ev)->GetPreferences(ev)->GetPrefsFile();
  2069.     DHSetPreferredSizeInSIZE(file, -1, documentFile, -1, numKBytes); // Should probably use a constant.
  2070. }
  2071.  
  2072. ODStatic ODULong    DHGetDocumentPreferredHeapSize(PlatformFile* file)
  2073. {
  2074.     // returns 0 if there is no preferred size    
  2075.     return DHGetPreferredSizeInSIZE(file, 0); // Should probably use a constant.
  2076. }
  2077.  
  2078. ODStatic void        DHClearDocumentPreferredHeapSize(PlatformFile* file)
  2079. {
  2080.     file->DeleteResource(kSIZERsrcType, 0); // Should probably use constants.
  2081.     file->DeleteResource(kSIZERsrcType, 1);
  2082. }
  2083.  
  2084.  
  2085. ODStatic void        DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes)
  2086. {
  2087.     DHSetPreferredSizeInSIZE(file, 0, kODNULL, -1, numKBytes); // Should probably use constants.
  2088.     DHSetPreferredSizeInSIZE(file, 1, kODNULL, -1, numKBytes);
  2089. }
  2090.  
  2091.  
  2092. pascal Boolean
  2093. DocHeapArrowButtonsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
  2094. {
  2095.     if (event->what == mouseDown)
  2096.     {
  2097.         Point thePt = event->where;
  2098.         GlobalToLocal(&thePt);
  2099.         *itemHit = FindDialogItem(dialog, thePt) + 1;
  2100.         if (*itemHit == kDocHeapDefaultSizeTopBtnRect ||
  2101.             *itemHit == kDocHeapDefaultSizeBotBtnRect ||
  2102.             *itemHit == kDocHeapPreferdSizeTopBtnRect ||
  2103.             *itemHit == kDocHeapPreferdSizeBotBtnRect ) {
  2104.             ODSShort picItemNum = 
  2105.              (*itemHit == kDocHeapDefaultSizeTopBtnRect ||
  2106.               *itemHit == kDocHeapDefaultSizeBotBtnRect)   ?
  2107.              kDocHeapDefaultSizeBtns :
  2108.              kDocHeapPreferdSizeBtns ;
  2109.             ODHandle pictHandle = 
  2110.              (*itemHit == kDocHeapDefaultSizeTopBtnRect ||
  2111.               *itemHit == kDocHeapPreferdSizeTopBtnRect)   ?
  2112.              gArrowBtnsPictTopOn :
  2113.              gArrowBtnsPictBotOn ;
  2114.              
  2115.             SetDialogItemAndUpdate(dialog, picItemNum, pictHandle);
  2116.         }
  2117.     }
  2118.     else if (event->what == mouseUp)
  2119.     {
  2120.         SetDialogItemAndUpdate(dialog, kDocHeapDefaultSizeBtns, gArrowBtnsPictOff);
  2121.         SetDialogItemAndUpdate(dialog, kDocHeapPreferdSizeBtns, gArrowBtnsPictOff);
  2122.     }
  2123.     return ODDialogFilterProc(dialog,event,itemHit);
  2124. }
  2125.  
  2126. //==============================================================================
  2127. // PickOneIText
  2128. // Choose the more "interesting" IText for use as the basis of setting the
  2129. // dialog's script.  Those of zero length are not interesting, as the user has
  2130. // not previously typed anything whose appearance he might want preserved.
  2131. // Similarly, the Roman script is not interesting because non-Roman scripts can
  2132. // display Roman text just fine.  So we want non-Roman text with content.  In
  2133. // the case of a tie either will do -- except that if both are fully interesting
  2134. // it's better to return null and let the default application font win.
  2135. //==============================================================================
  2136.  
  2137. static ODScriptCode GetRealScriptCode( ODIText* itext )
  2138. {
  2139.     ODScriptCode script;
  2140.     if (itext)
  2141.         script = GetITextScriptCode( itext );
  2142.     else
  2143.         script = smSystemScript;
  2144.     if ( script == smSystemScript )
  2145.         script = GetScriptManagerVariable(smSysScript);
  2146.     return script;
  2147. }
  2148.  
  2149. ODStatic ODIText* PickOneIText( ODIText* itext1, ODIText* itext2 )
  2150. {
  2151.     ODIText* leadingCandidate;
  2152.     ODBoolean text1NotRoman = itext1 && GetRealScriptCode( itext1 ) != smRoman;
  2153.     ODBoolean text2NotRoman = itext2 && GetRealScriptCode( itext2 ) != smRoman;
  2154.  
  2155.     if ( text1NotRoman && (GetITextStringLength(itext1) > 0) )
  2156.         leadingCandidate = itext1;
  2157.     else if ( text2NotRoman && (GetITextStringLength(itext2) > 0) )
  2158.         leadingCandidate = itext2;
  2159.     else
  2160.         leadingCandidate = kODNULL;
  2161.  
  2162.     if ( leadingCandidate )
  2163.         if ( text1NotRoman && text2NotRoman &&
  2164.                 (GetRealScriptCode( itext1 ) != GetRealScriptCode( itext2 )) )
  2165.             leadingCandidate = kODNULL;
  2166.     return leadingCandidate;
  2167. }
  2168.  
  2169. #endif
  2170.