home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Dialogs / InfoDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  69.5 KB  |  2,255 lines  |  [TEXT/MPS ]

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