home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / LinkDlgs.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  171KB  |  4,013 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: oddataxfer
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.24 com/src/storage/LinkDlgs.cpp, oddataxfer, od96os2, odos29712d 3/7/97 11:22:59 [ 3/21/97 17:18:47 ]
  28. #ifdef _PLATFORM_OS2_
  29.  
  30.  
  31. /**********************************************************************\
  32.  *  Module Header                                                     *
  33.  *                                                                    *
  34.  *  File Name: LinkDlgs.cpp                                           *
  35.  *                                                                    *
  36.  *  Description:                                                      *
  37.  *  This file implements the dialog's required for                    *
  38.  *  OpenDoc Link Support for OS/2 :                                   *
  39.  *  It contains implementation of the Paste As and Link Info dialogs  *
  40.  *                                                                    *
  41.  *  Written by: Saurabh Kumar                                         *
  42.  *                                                                    *
  43.  *                                                                    *
  44.  *  Change History (most recent first):                               *
  45.  *  -------                                                           *
  46.  * <3>   7/19/95  129813   Saurabh Kumar   Disable Embed As if canEmbed False *
  47.  * <2>   5/01/95  123004   Saurabh Kumar   Added code for ShowPasteAsDialog   *
  48.  * <1>   3/10/95   <OS2>   Saurabh Kumar   Created for Link Dialogs   *
  49.  *                                                                    *
  50.  *   To Do                                                            *
  51.  *  -------                                                           *
  52.  *                                                                    *
  53. \**********************************************************************/
  54.  
  55.  
  56. #define INCL_WIN
  57. #define INCL_DOS
  58. #define INCL_DOSERRORS
  59. #define INCL_ERROR_H
  60. #include <os2.h>
  61. #include <bseerr.h>
  62. #include <odres.h>       //For PasteAs dialog's resource id's
  63. #include <ODPagtun.h>
  64. #include <isostr.h>
  65.  
  66. #ifndef _PLFMDEF_
  67. #include "plfmdef.h"
  68. #endif
  69.  
  70. #ifndef _LINKDLGS_
  71. #include "LinkDlgs.h"
  72. #endif
  73.  
  74. #if (defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_))
  75. #ifndef SOM_ODHelp_xh
  76. #include <ODHelp.xh>
  77. #endif
  78. #ifndef _HLPPANELS_
  79. #include <hlppanls.h>
  80. #endif
  81. #endif //_PLATFORM_WIN32_ || _PLATFORM_OS2_
  82.  
  83. #ifndef _EXCEPT_
  84. #include "Except.h"
  85. #endif
  86.  
  87. #ifndef _LINKDEFS_
  88. #include "LinkDefs.h"
  89. #endif
  90.  
  91. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  92. #include <StdDefs.xh>
  93. #endif
  94.  
  95. #ifndef SOM_Module_OpenDoc_StdProps_defined
  96. #include <StdProps.xh>
  97. #endif
  98.  
  99. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  100. #include <StdTypes.xh>
  101. #endif
  102.  
  103. #ifndef SOM_ODTypeList_xh
  104. #include <TypeList.xh>
  105. #endif
  106.  
  107. #ifndef SOM_RegistryManager_xh
  108. #include <RManager.xh>
  109. #endif
  110.  
  111. #ifndef _ODPRTREIG_
  112. #include <ODPrtRei.xh>
  113. #endif
  114.  
  115. #ifndef SOM_ODPartHandlerRegistry_xh
  116. #include <ODPrtReg.xh>
  117. #endif
  118.  
  119.  
  120. #ifndef SOM_ODTranslation_xh
  121. #include "Translt.xh"
  122. #endif
  123.  
  124. #ifndef SOM_ODTypeListIterator_xh
  125. #include <TypLsItr.xh>
  126. #endif
  127.  
  128. #ifndef SOM_ODBinding_xh
  129. #include <ODBindng.xh>
  130. #endif
  131.  
  132. #ifndef SOM_ODFrame_xh
  133. #include <Frame.xh>
  134. #endif
  135.  
  136. #ifndef SOM_Facet_xh
  137. #include "Facet.xh"
  138. #endif
  139.  
  140. #ifndef SOM_ODWindow_xh
  141. #include <Window.xh>
  142. #endif
  143.  
  144. #ifndef SOM_ODPartWrapper_xh
  145. #include <PartWrap.xh>
  146. #endif
  147.  
  148. //#ifndef SOM_ODPart_xh
  149. //#include <Part.xh>
  150. //#endif
  151.  
  152. /*
  153. #ifndef _INFOUTIL_
  154. #include "infoutil.h"
  155. #endif
  156. */
  157.  
  158. #ifndef _BNDNSUTL_
  159. #include "bndnsutl.h"
  160. #endif
  161.  
  162. #ifndef SOM_ODTypeList_xh
  163. #include <TypeList.xh>
  164. #endif
  165.  
  166. #ifndef SOM_Facet_xh
  167. #include "Facet.xh"
  168. #endif
  169.  
  170. #ifndef SOM_ODSession_xh
  171. #include "ODSessn.xh"
  172. #endif
  173.  
  174. #ifndef _TEMPOBJ_
  175. #include "TempObj.h"
  176. #endif
  177.  
  178. #ifndef _ITEXT_
  179. #include "IText.h"
  180. #endif
  181.  
  182.  
  183. #ifndef _STDTYPIO_
  184. #include "StdTypIO.h"
  185. #endif
  186.  
  187. // #define RRK_DEBUG 1
  188. #ifndef SOM_ODBaseLinkSource_xh
  189. #include <LinkSrcB.xh>
  190. #endif
  191.  
  192. #ifndef SOM_ODBaseLink_xh
  193. #include <LinkB.xh>
  194. #endif
  195.  
  196. #include <rmutil.h>
  197. #include <wchar.h>
  198. #include <DraftWn.h>
  199. #include <langinfo.h>
  200.  
  201. ODStatic void GetBestKindAndSize(ODStorageUnit* contentSU, ODType* kind, ODULong* size);
  202.  
  203. ODStatic ISOString GetDisplayKind(ODType type, ODSession* session);
  204.  
  205. // infoutil is no longer part of OS2 release.
  206. void AddTypesToListBox(ODTypeList* typeList, HWND kindMenu,
  207.                           ODSession* session, ODULong idItem);
  208.  
  209.  
  210. HMODULE hmodDLL;
  211.  
  212. static ODLinkInfoResult*   gLIResult;
  213. static ODFacet*            gFacet;
  214. static ODSShort            gAlertResult;
  215. static ODBaseLink*           gLink;              // passed in to ShowLinkDestinationInfo function.
  216. static ODUpdateID       gUpdateID;           // passed in to ShowLinkSourceInfo function.
  217. static ODBoolean       gChangesAllowed;    // passed in to both Link info functions.
  218. static ODSession*          gSession;
  219.  
  220. //==============================================================================
  221. // Constants
  222. //==============================================================================
  223.  
  224.  
  225. //==============================================================================
  226. // Scalar types
  227. //==============================================================================
  228.  
  229. //==============================================================================
  230. // Function Prototypes
  231. //==============================================================================
  232.  
  233. //------------------------------------------------------------------------------
  234. // ShowPasteAsDialog
  235. //------------------------------------------------------------------------------
  236.  
  237. ODBoolean ShowPasteAsDialog(
  238.         ODBoolean        canPasteLink,
  239.         ODPasteAsMergeSetting  mergeSetting,
  240.         ODBoolean        isMove,
  241.         ODStorageUnit*      contentSU,
  242.         ODFacet*        facet,
  243.         ODTypeToken        viewType,
  244.         ODPasteAsResult*    result)
  245.  
  246. {
  247.  
  248.   ULONG rc = 0;
  249.   PDIALOGDATA pDialogData = NULL;
  250.   CHAR LoadError[CCHMAXPATH];
  251.   Environment* ev = somGetGlobalEnvironment();
  252.  
  253.   DosLoadModule(LoadError, sizeof(LoadError), "ODRes", &hmodDLL);
  254.  
  255.   // Allocate memory for our private DIALOGDATA structure
  256.   // memory should be freed in the dialog proc.
  257.   pDialogData = new DIALOGDATA;
  258.   memset((PVOID) pDialogData, 0, sizeof(DIALOGDATA));
  259.  
  260.   //Initialize result
  261.   if ( canPasteLink )
  262.         canPasteLink = contentSU->Exists(ev, kODPropLinkSpec, (ODValueType) kODLinkSpec, 0);
  263.  
  264.         result->pasteLinkSetting =  canPasteLink;
  265.         result->autoUpdateSetting = kODTrue;
  266.         result->translateKind = (ODType) kODNULL;
  267.         char* myString = catgets(ODcat_handle, LINKSPEC_SET, LINKSPEC_90, "No user editor");
  268.         result->editor = myString;
  269.  
  270.  
  271.     result->mergeSetting = mergeSetting;
  272.  
  273.  
  274. // result->selectedView = 0;
  275. // result->selectedKind = (ODType) kODNULL;
  276.  
  277.       // Fill in the DIALOGDATA structure
  278.   pDialogData->su = contentSU;
  279.   pDialogData->facet = facet;
  280.   pDialogData->result.pasteLinkSetting = result->pasteLinkSetting;
  281.   pDialogData->result.autoUpdateSetting = result->autoUpdateSetting;
  282.   pDialogData->result.mergeSetting = result->mergeSetting;
  283.   pDialogData->result.selectedView = result->selectedView;
  284.   pDialogData->result.selectedKind = result->selectedKind;
  285.   pDialogData->result.translateKind = result->translateKind;
  286.   pDialogData->result.editor = result->editor;
  287.  
  288.   // Need to acquire frame and storage unit before using them. Put
  289.   // them in temp object so that when the temp object is out of
  290.   // scope, the object get released.
  291.   TempODFrame frame = facet->GetFrame(ev);
  292.   frame->Acquire(ev);
  293.   TempODStorageUnit su = frame->GetStorageUnit(ev);
  294.   su->Acquire(ev);
  295.   ODSession* session = su->GetSession(ev);
  296.  
  297.   ODWindowState* WinStat = session->GetWindowState(ev);
  298.  
  299.   // Need to release the window. Use temp object to accomplish
  300.   // the release when the temp object is out of scope.
  301.   TempODWindow Window = WinStat->AcquireFrontRootWindow(ev);
  302.   HWND hwnd = Window->GetPlatformWindow(ev);
  303.  
  304.  
  305.   //Create a modal dialog box and display it.
  306.   rc = WinDlgBox(HWND_DESKTOP,      //Parent is the DeskTop
  307. //            HWND_DESKTOP,
  308.              hwnd,
  309.             (PFNWP)PasteAsDlgProc,  //dialog window proc
  310.             hmodDLL,         //handle to the DLL containing Dialog resource.
  311.             IDD_PASTEASDLG,  //dialog template ID
  312.             (PVOID) pDialogData );           //application data
  313.  
  314.   //Update result
  315.   result->pasteLinkSetting  = pDialogData->result.pasteLinkSetting;
  316.   result->autoUpdateSetting = pDialogData->result.autoUpdateSetting;
  317.   result->mergeSetting = pDialogData->result.mergeSetting;
  318.   result->selectedView = pDialogData->result.selectedView;
  319.   result->selectedKind = pDialogData->result.selectedKind;
  320.   result->translateKind = pDialogData->result.translateKind;
  321.   result->editor = pDialogData->result.editor;
  322.  
  323. #ifdef RRK_DEBUG
  324.        PRINT("*** RRK ODPasteAsResult structure.\n");
  325.        PRINT("\t pasteLinkSetting:\t %d.\n", result->pasteLinkSetting);
  326.        PRINT("\t autoUpdateSetting:\t %d.\n", result->autoUpdateSetting);
  327.        PRINT("\t mergeSetting:\t %d.\n", result->mergeSetting);
  328.        PRINT("\t selectedView:\t %d.\n", result->selectedView);
  329.        PRINT("\t selectedKind:\t %s.\n", result->selectedKind);
  330.        PRINT("\t translateKind:\t %s.\n", result->translateKind);
  331.        PRINT("\t editor:\t %s.\n", result->editor);
  332. #endif
  333.   return rc;
  334. }
  335.  
  336.  
  337. /*********************************************************************
  338.  *  Name : PasteAsDlgProc
  339.  *
  340.  *************************************************************************/
  341. MRESULT EXPENTRY PasteAsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  342.                                   MPARAM mp2)
  343. {
  344. static PDIALOGDATA pDlgData = NULL;
  345. Environment* ev = somGetGlobalEnvironment();
  346. static ODTypeList * kindList = NULL;
  347. static ODBoolean  autoUpdateSetting;
  348. static ODPasteAsMergeSetting mergeSetting;
  349. static pasteLinkSetting;
  350. ODEditor editorID = kODNULL;
  351. ODULong maxEditors = 0;
  352. ODSShort  currentKindItem = 1;
  353. ODSShort  currentEditorItem = 0;
  354. static ODBoolean canMerge;
  355. static ODBoolean canEmbed;
  356. static ODBoolean flag = kODFalse;
  357.  
  358.    switch(msg)
  359.    {
  360.       case WM_INITDLG:
  361.            {
  362.             CenterWindow(hwnd);
  363.  
  364.             pDlgData = (PDIALOGDATA) mp2;
  365.  
  366.              // Set Window pointer with object pointer and instance data info
  367.              WinSetWindowPtr(hwnd, QWL_USER, pDlgData);
  368.  
  369.             //If "Paste with Link" is NOT checked then disable
  370.             //the controls used only for linking.
  371.  
  372.             if (!pDlgData->result.pasteLinkSetting)
  373.                {
  374.                 WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTEAUTOBTN), FALSE);
  375.                 WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTEMANUALBTN), FALSE);
  376.                 WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTELINKCHKBOX), FALSE);
  377.                }
  378.             else   //Linking is enabled
  379.                {
  380.                 //Check the "Paste with Link" check box
  381.                  WinCheckButton(hwnd,IDD_PASTELINKCHKBOX,TRUE);
  382.                 //Setup default settings
  383.                  autoUpdateSetting = kODTrue;
  384.                 //Check the radio button for getting updates to Automatic.
  385.                  WinCheckButton(hwnd,IDD_PASTEAUTOBTN,TRUE);
  386.                
  387.  
  388.                  canMerge = (pDlgData->result.mergeSetting != kODPasteAsEmbedOnly);
  389.                  canEmbed = (pDlgData->result.mergeSetting != kODPasteAsMergeOnly);
  390.                  pDlgData->result.mergeSetting = (pDlgData->result.mergeSetting == kODPasteAsMerge)
  391.                                       || (pDlgData->result.mergeSetting == kODPasteAsMergeOnly);
  392.  
  393.                  mergeSetting = pDlgData->result.mergeSetting;
  394.  
  395.                 if (mergeSetting)  //Merge initially selected
  396.                  {
  397.                  //Check "Merge with Contents" Radio Button
  398.                  WinCheckButton(hwnd,IDD_MERGEBTN,TRUE);
  399.  
  400.                  if(canEmbed)
  401.                   {
  402.                     WinEnableWindow(WinWindowFromID(hwnd,IDD_EMBEDAS), TRUE);
  403.                     WinEnableWindow(WinWindowFromID(hwnd,IDD_EMBEDBTN), TRUE);
  404.                   }
  405.                  else   //canEmbed is False only when MergeOnly is selected
  406.                   {
  407.                     // inactivate(grey out) the "Embed as:" combo box
  408.                     // if merge only is initially selected
  409.                     WinEnableWindow(WinWindowFromID(hwnd,IDD_EMBEDAS), FALSE);
  410.                     WinEnableWindow(WinWindowFromID(hwnd,IDD_EMBEDBTN), FALSE);
  411.                   }
  412.  
  413.                  }
  414.                 else   //Embed is intially selected
  415.                   {
  416.  
  417.                   flag = kODTrue;
  418.                   //Check "Embed as "
  419.                   WinCheckButton(hwnd,IDD_EMBEDBTN,TRUE);
  420.  
  421.                  if(canMerge)
  422.                   {
  423.                     WinEnableWindow(WinWindowFromID(hwnd,IDD_MERGEBTN), TRUE);
  424.                   }
  425.                  else   //canMerge is False only when EmbedOnly is selected
  426.                   {
  427.                     // inactivate(grey out) the "Merge Btn"
  428.                     WinEnableWindow(WinWindowFromID(hwnd,IDD_MERGEBTN), FALSE);
  429.                   }
  430.  
  431.  
  432.                   //Load data into "Embed As" Combo Box
  433.                   LoadEmbedAsComboBox(hwnd, IDD_EMBEDAS);
  434.  
  435.                   //Set up Paste As Kind List
  436.                   kindList = new ODTypeList;
  437.                   kindList->InitTypeList(ev, (ODTypeList *) kODNULL);
  438.  
  439.                   ContentValueTypes(pDlgData->su, kindList);
  440.                   AddTypesToListBox(kindList,hwnd,pDlgData->su->GetSession(ev)
  441.                               ,IDD_PARTKIND);
  442.                   ODEditor preferredEditor = pDlgData->su->GetSession(ev)->GetBinding(ev)->
  443.                                     ChooseEditorForPart(ev,pDlgData->su,kODNULL);
  444.                   WinSetDlgItemText(hwnd, IDD_PARTEDITOR, preferredEditor);
  445.  
  446.                   pDlgData->result.editor = preferredEditor;
  447.                   WinSendMsg( WinWindowFromID(hwnd, IDD_PARTKIND),
  448.                              LM_SELECTITEM, MPFROMSHORT(0),
  449.                              MPFROMSHORT( TRUE | FALSE));
  450.  
  451.                   }
  452.                }
  453.  
  454.          }
  455.       break;
  456.  
  457.      case WM_HELP:
  458.            {
  459.              #if (defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_))
  460.              ODULong ulHelpid = IDMS_EDIT_PASTEAS_PANEL;
  461.              ODHelp * helpme  = pDlgData->su->GetSession(ev)->GetHelp(ev);
  462.              helpme->DisplayHelp(ev,ODHELPFILE,ulHelpid);
  463.              #endif
  464.            }
  465.      break;
  466.  
  467.       case WM_COMMAND:
  468.  
  469.          switch (SHORT1FROMMP (mp1) )
  470.          {
  471.           case DID_PASTE:
  472.            {
  473.            //Check whether "Paste with Link" was checked
  474.  
  475.            pDlgData=(PDIALOGDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  476.  
  477.            if(! WinQueryButtonCheckstate(hwnd, IDD_PASTELINKCHKBOX))
  478.            {
  479.             //  Do Paste Content
  480.             pasteLinkSetting = kODFalse;
  481.            }
  482.  
  483.            else  //Do Paste Link
  484.            {
  485.             pasteLinkSetting = kODTrue;
  486.            }
  487.            //Get user selected information from the dialog box.
  488.            ODType selectedKind = (ODISOStr)kODNULL;     ;
  489.            ODTypeToken  selectedView= 0;
  490.            SHORT sitemselected = 0;
  491.            ULONG ultextlength = 0;
  492.            CHAR  szBuffer[CCHMAXPATH];
  493.            memset((PSZ) szBuffer, 0, sizeof(szBuffer));
  494.  
  495.            if (pDlgData->result.mergeSetting)  //Merge initially selected
  496.            {
  497.  
  498.            }
  499.            else   //Embed is selected
  500.             {
  501.             //Get the Part 'Kind'
  502.             sitemselected =(ULONG) WinSendMsg (WinWindowFromID(hwnd, IDD_PARTKIND),
  503.                                LM_QUERYSELECTION,
  504.                                MPFROMSHORT((SHORT) LIT_FIRST),
  505.                                (MPARAM) NULL);
  506.  
  507.              if (sitemselected != LIT_NONE)
  508.                {
  509.                ultextlength = (ULONG)WinSendMsg (WinWindowFromID(hwnd, IDD_PARTKIND),
  510.                                LM_QUERYITEMTEXTLENGTH,
  511.                                MPFROMSHORT(sitemselected),
  512.                                (MPARAM) NULL);
  513.  
  514.               //Now , get the part kind the user has selected
  515.                              MRESULT mr = WinSendMsg (WinWindowFromID(hwnd, IDD_PARTKIND),
  516.                                LM_QUERYSELECTION, 0, 0);
  517.                              ODULong kindIndex = (ODULong) mr;
  518.                              selectedKind = GetThisKindFromList( kindIndex+1, kindList );
  519.  
  520.               }
  521.            else
  522.               {
  523.               selectedKind = (ODISOStr)kODNULL;
  524.               }
  525.          //Determine which item of the 'Embed As' Combo Box the user selected
  526.          selectedView   =(ULONG)  WinSendMsg (WinWindowFromID(hwnd, IDD_EMBEDAS),
  527.                                LM_QUERYSELECTION,
  528.                                MPFROMSHORT((SHORT) LIT_FIRST),
  529.                                (MPARAM) NULL);
  530.  
  531.            }
  532.  
  533.          pDlgData->result.pasteLinkSetting = pasteLinkSetting;
  534.          pDlgData->result.autoUpdateSetting = autoUpdateSetting;
  535.          pDlgData->result.mergeSetting = mergeSetting;
  536.          pDlgData->result.selectedView = selectedView;
  537.          pDlgData->result.selectedKind = selectedKind;
  538.  
  539. //       pDlgData->result.translateKind = translateKind;
  540. //       pDlgData->result.editor = editor;
  541.          WinDismissDlg(hwnd, TRUE); //WindismissDlg is called with result value TRUE.
  542.         }
  543.              break;
  544.  
  545.           case DID_CANCEL:
  546.  
  547.              pDlgData=(PDIALOGDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  548.              pDlgData->result.pasteLinkSetting = kODFalse;
  549.              WinDismissDlg(hwnd, FALSE); //WindismissDlg is called with result value FALSE.
  550.             break;
  551.  
  552.           case DID_HELP:
  553.            {
  554.              #if (defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_))
  555.              ODULong ulHelpid = IDMS_EDIT_PASTEAS_PANEL;
  556.              ODHelp * helpme  = pDlgData->su->GetSession(ev)->GetHelp(ev);
  557.              helpme->DisplayHelp(ev,ODHELPFILE,ulHelpid);
  558.              #endif
  559.            }
  560.      break;
  561.           }  /* end switch WM_COMMAND */
  562.  
  563.          break;
  564.  
  565.  
  566.      case WM_CONTROL:
  567.  
  568.         switch ( SHORT1FROMMP ( mp1 ) )
  569.           {
  570.  
  571.  
  572.                    case IDD_PASTELINKCHKBOX:
  573.                        if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED )
  574.                        {
  575.                         pDlgData=(PDIALOGDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  576.                         if(! WinQueryButtonCheckstate(hwnd, IDD_PASTELINKCHKBOX))
  577.                           {
  578.                            //disable for linking
  579.                            WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTEAUTOBTN), FALSE);
  580.                            WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTEMANUALBTN), FALSE);
  581.                            //Do Paste Content
  582.                            pDlgData->result.pasteLinkSetting = kODFalse;
  583.                           }
  584.                         else
  585.                         {
  586.                            //Enable for linking
  587.                            WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTEAUTOBTN), TRUE);
  588.                            WinEnableWindow(WinWindowFromID(hwnd,IDD_PASTEMANUALBTN), TRUE);
  589.                            pasteLinkSetting = kODTrue;
  590.                         }
  591.                        }
  592.                      break;
  593.  
  594.  
  595.                    case IDD_PASTEAUTOBTN:
  596.                        if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED )
  597.                        {
  598.                        autoUpdateSetting = kODTrue;
  599.                        }
  600.                      break;
  601.  
  602.                    case IDD_PASTEMANUALBTN:
  603.                        if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED )
  604.                        {
  605.                        autoUpdateSetting = kODFalse;
  606.                        }
  607.                      break;
  608.  
  609.                    case IDD_MERGEBTN:
  610.                        if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED )
  611.                        {
  612.                         mergeSetting = kODTrue;
  613.                          // Inactivate(grey out) the "Embed as:" combo box
  614.                          WinEnableWindow(WinWindowFromID(hwnd,IDD_EMBEDAS), FALSE);
  615.                          WinEnableWindow(WinWindowFromID(hwnd,IDD_PARTKIND), FALSE);
  616.                          WinEnableWindow(WinWindowFromID(hwnd,IDD_PARTEDITOR), FALSE);
  617.                        }
  618.                      break;
  619.  
  620.                    case IDD_EMBEDBTN:
  621.                        if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED )
  622.                        {
  623.                          // Activate the "Embed as:" combo box
  624.                          WinEnableWindow(WinWindowFromID(hwnd,IDD_EMBEDAS), TRUE);
  625.                          WinEnableWindow(WinWindowFromID(hwnd,IDD_PARTKIND), TRUE);
  626.                          WinEnableWindow(WinWindowFromID(hwnd,IDD_PARTEDITOR), TRUE);
  627.                         mergeSetting = kODFalse;
  628.  
  629.                          if (!flag)
  630.                            {
  631.                            //Check "Embed as "
  632.                            WinCheckButton(hwnd,IDD_EMBEDBTN,TRUE);
  633.                            //Load data into "Embed As" Combo Box
  634.                             LoadEmbedAsComboBox(hwnd, IDD_EMBEDAS);
  635.  
  636.                           //Set up Paste As Kind List
  637.                             kindList = new ODTypeList;
  638.                             kindList->InitTypeList(ev, (ODTypeList *) kODNULL);
  639.                             ContentValueTypes(pDlgData->su, kindList);
  640.                             AddTypesToListBox(kindList,hwnd,pDlgData->su->GetSession(ev)
  641.                                              ,IDD_PARTKIND);
  642.                             ODEditor preferredEditor = pDlgData->su->GetSession(ev)->GetBinding(ev)->
  643.                                          ChooseEditorForPart(ev,pDlgData->su,kODNULL);
  644.                             WinSetDlgItemText(hwnd, IDD_PARTEDITOR, preferredEditor);
  645.  
  646.                             WinSendMsg( WinWindowFromID(hwnd, IDD_PARTKIND),
  647.                                         LM_SELECTITEM, MPFROMSHORT(0),
  648.                                         MPFROMSHORT( TRUE | FALSE));
  649.                        }
  650.                        }
  651.                      break;
  652.  
  653.  
  654.            }
  655.         return (MRESULT) TRUE;
  656.         break;
  657.  
  658.  
  659.       case WM_DESTROY:
  660.  
  661.          // Clean up memory
  662.  
  663.          if (pDlgData){
  664.              delete pDlgData;
  665.              pDlgData = NULL;
  666.            }
  667.  
  668.           if(kindList)
  669.              {
  670.                delete kindList;
  671.                kindList = NULL;
  672.              }
  673.  
  674.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  675.          break;
  676.  
  677.  
  678.       default:
  679.          //Pass all unprocessed messages to the default dialog proc
  680.  
  681.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  682.          break;
  683.  
  684.    }  //end switch (msg)
  685.  
  686.   return (MRESULT) FALSE;
  687. }
  688.  
  689.  
  690. /*********************************************************************
  691.  *  Name : LoadEmbedAsComboBox
  692.  *
  693.  *  Description : Loads the EmbedAs Combo Box. The string is added via LM_INSERTITEM
  694.  *
  695.  *  Parameters : hwnd - Dialog Window Handle
  696.  *                    id - Resource ID of the combo box.
  697.  *
  698.  *  Returns: TRUE if list box is loaded successfully, FALSE otherwise
  699.  *
  700.  ****************************************************************/
  701. ODBoolean LoadEmbedAsComboBox(HWND hwnd, ULONG id)
  702. {
  703.    HWND hwndcbox;
  704.    ULONG ulCounter=0;
  705.    CHAR pszTemp[CCHMAXPATH];
  706.  
  707.    hwndcbox = WinWindowFromID(hwnd,id);
  708.  
  709.    //All strings must be loaded from the RC file
  710.     HAB hab = WinQueryAnchorBlock(HWND_DESKTOP);
  711.  
  712.     for (ulCounter=0; ulCounter<=3 ; ulCounter++ ) {
  713.       if (!WinLoadString(hab, hmodDLL, (IDS_FRAME + ulCounter),
  714.                         CCHMAXPATH, (PSZ)pszTemp))
  715.       {
  716.          return FALSE;
  717.       }
  718.  
  719.     WinSendMsg (hwndcbox,
  720.                 LM_INSERTITEM,
  721.                 MPFROMSHORT(LIT_END),
  722.                 MPFROMP((PSZ)pszTemp));
  723.     } /* endfor */
  724.  
  725.     WinSendMsg( hwndcbox,
  726.                LM_SELECTITEM, MPFROMSHORT(0),
  727.                MPFROMSHORT( TRUE | FALSE));
  728.     return TRUE;
  729. }
  730.  
  731. //------------------------------------------------------------------------------
  732. // ShowMoveCopyDialog
  733. //------------------------------------------------------------------------------
  734.  
  735. ODBoolean ShowMoveCopyDialog(
  736.         ODMoveCopyResult*  result)
  737.  
  738. {
  739.  
  740.   ULONG rc = 0;
  741.   CHAR LoadError[CCHMAXPATH];
  742.   Environment* ev = somGetGlobalEnvironment();
  743.  
  744.   //first check if a file existst in the old path name. If not -
  745.   //then this is definitely a move.
  746.   HDIR dirHandle = HDIR_SYSTEM;
  747.   ULONG searchCount = 1;
  748.   FILEFINDBUF3 fileInfo;
  749.   rc = DosFindFirst((PCSZ)(result->fOldDocPathName), &dirHandle, FILE_ARCHIVED, &fileInfo,
  750.                            sizeof(fileInfo), &searchCount, FIL_STANDARD);
  751.   if (rc == ERROR_NO_MORE_FILES)
  752.   {
  753.      result->FileMoved   =   kODTrue;
  754.      result->FileCopied  =   kODFalse;
  755.      return rc;
  756.   }
  757.  
  758.  
  759.   DosLoadModule(LoadError, sizeof(LoadError), "ODRes", &hmodDLL);
  760.  
  761.   result->FileMoved   =   kODTrue;
  762.   result->FileCopied  =   kODFalse;
  763.  
  764.   //Create a modal dialog box and display it.
  765.   rc = WinDlgBox(HWND_DESKTOP,               //Parent is the DeskTop
  766.             HWND_DESKTOP,                    //displayed in DeskTop window
  767.             (PFNWP)MoveCopyDlgProc,          //dialog window proc
  768.             hmodDLL,                         //handle to the DLL containing Dialog resource.
  769.             IDD_MOVECOPYDLG,                 //dialog template ID
  770.             (PVOID) result );           //application data
  771.  
  772.   return rc;
  773. }
  774.  
  775.  
  776. /*********************************************************************
  777.  *  Name : MoveCopyDlgProc
  778.  *
  779.  *************************************************************************/
  780. MRESULT EXPENTRY MoveCopyDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  781.                                   MPARAM mp2)
  782. {
  783.  
  784. RECTL rclScreen, rclDialog;
  785. LONG sWidth,sHeight, sBLCx,sBLCy;
  786. static ODMoveCopyResult *pDlgData = NULL;
  787. USHORT okMoved  = MBID_ENTER;
  788. USHORT okCopied = MBID_ENTER;
  789. Environment* ev = somGetGlobalEnvironment();
  790.  
  791.  
  792.    switch(msg)
  793.    {
  794.       case WM_INITDLG:
  795.               {
  796.  
  797.             //Center the dialog window and get the screen rectange
  798.             WinQueryWindowRect(HWND_DESKTOP, &rclScreen);
  799.  
  800.             //Get the dialog-window rectange
  801.             WinQueryWindowRect(hwnd, &rclDialog);
  802.  
  803.             //Get the dialog - window width;
  804.             sWidth = (LONG) (rclDialog.xRight - rclDialog.xLeft);
  805.  
  806.             //Get the dialog - window height;
  807.             sHeight = (LONG) (rclDialog.yTop - rclDialog.yBottom);
  808.  
  809.             //Set the horizontal coordinate of the lower-left corner
  810.             sBLCx = ((LONG) rclScreen.xRight - sWidth) /2;
  811.  
  812.             //Set the vertical   coordinate of the lower-left corner
  813.             sBLCy = ((LONG) rclScreen.yTop - sHeight) /2;
  814.  
  815.             //Move, size and show the window
  816.  
  817.             WinSetWindowPos(hwnd,
  818.                                 HWND_TOP,
  819.                                 sBLCx, sBLCy,
  820.                                 0,0,                      //ignore size arguments
  821.                                 SWP_MOVE);
  822.  
  823.  
  824.             pDlgData = (ODMoveCopyResult*) mp2;
  825.             WinSetDlgItemText(hwnd, IDD_OLDFILENAME, pDlgData->fOldDocPathName);
  826.             WinSetDlgItemText(hwnd, IDD_NEWFILENAME, pDlgData->fNewDocPathName);
  827.  
  828.              // Set Window pointer with object pointer and instance data info
  829.              WinSetWindowPtr(hwnd, QWL_USER, pDlgData);
  830.  
  831.  
  832.          }
  833.       break;
  834.  
  835.       case WM_COMMAND:
  836.  
  837.          switch (SHORT1FROMMP (mp1) )
  838.          {
  839.           case DID_FILECOPIED:
  840.              pDlgData=(ODMoveCopyResult *) WinQueryWindowPtr(hwnd, QWL_USER);
  841.              pDlgData->FileCopied = kODTrue;
  842.              pDlgData->FileMoved  = kODFalse;
  843.              char       messageCopied[256];
  844.              strcpy(messageCopied, "This Document will not be responsible for any sources previously owned by: \n");
  845.              strcat(messageCopied, pDlgData->fOldDocPathName);
  846.              okCopied = WinMessageBox(HWND_DESKTOP, hwnd, messageCopied, "Notice:",0, MB_MOVEABLE | MB_OKCANCEL);
  847.              if (okCopied == MBID_OK)
  848.              {
  849.               WinDismissDlg(hwnd, TRUE); //WindismissDlg is called with result value TRUE.
  850.              }
  851.             break;
  852.  
  853.           case DID_FILEMOVED:
  854.              pDlgData=(ODMoveCopyResult *) WinQueryWindowPtr(hwnd, QWL_USER);
  855.              pDlgData->FileCopied = kODFalse;
  856.              pDlgData->FileMoved  = kODTrue;
  857.              char       messageMoved[256];
  858.              strcpy(messageMoved, "This Document will now be responsible for all sources previously owned by: \n");
  859.              strcat(messageMoved, pDlgData->fOldDocPathName);
  860.              okMoved = WinMessageBox(HWND_DESKTOP, hwnd, messageMoved, "Notice:",0, MB_MOVEABLE | MB_OKCANCEL);
  861.              if (okMoved == MBID_OK)
  862.              {
  863.                WinDismissDlg(hwnd, TRUE); //WindismissDlg is called with result value TRUE.
  864.              }
  865.             break;
  866.  
  867.  
  868.           case DID_CANCEL:
  869.  
  870.              pDlgData=(ODMoveCopyResult *) WinQueryWindowPtr(hwnd, QWL_USER);
  871.              WinDismissDlg(hwnd, FALSE); //WindismissDlg is called with result value FALSE.
  872.             break;
  873.  
  874. //          case DID_MOVECOPYHELP:
  875. //           break;
  876.  
  877.           }  /* end switch WM_COMMAND */
  878.  
  879.          break;
  880.  
  881.  
  882.       case WM_DESTROY:
  883.  
  884.          // Clean up memory
  885.  
  886.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  887.          break;
  888.  
  889.  
  890.       default:
  891.          //Pass all unprocessed messages to the default dialog proc
  892.  
  893.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  894.          break;
  895.  
  896.      } //end switch (msg)
  897.  
  898.   return (MRESULT) FALSE;
  899. }
  900.  
  901. //--------------------------------------------------------------------------
  902. //
  903. // This function will center a Dialog Window over it's parent window.
  904. //
  905. //--------------------------------------------------------------------------
  906.  
  907. void CenterWindow (HWND hwnd)
  908. {
  909.          HWND hwndParent;
  910.          RECTL rectl;
  911.          RECTL rectlParent;
  912.  
  913.          WinQueryWindowRect(hwnd,&rectl);
  914.  
  915.          hwndParent=WinQueryWindow(hwnd,QW_PARENT);
  916.          WinQueryWindowRect(hwndParent,&rectlParent);
  917.  
  918.          rectl.xRight/=2;
  919.          rectl.yTop/=2;
  920.          rectlParent.xRight/=2;
  921.          rectlParent.yTop/=2;
  922.  
  923.          WinSetWindowPos(hwnd,
  924.                          (HWND)NULL,
  925.                          (LONG)(rectlParent.xRight-rectl.xRight),
  926.                          (LONG)(rectlParent.yTop-rectl.yTop),
  927.                          0l,
  928.                          0l,
  929.                          (ULONG)SWP_MOVE );
  930. }
  931.  
  932. //------------------------------------------------------------------------------
  933. // AddTypesToListBox
  934. //------------------------------------------------------------------------------
  935.  
  936.  
  937. void AddTypesToListBox(ODTypeList* typeList, HWND kindMenu,
  938.                           ODSession* session, ODULong idItem)
  939. {
  940.   ISOString        name;
  941.   char * pWorkArea = kODNULL;
  942.   ODSShort      item = 0;
  943.   Environment*    ev = somGetGlobalEnvironment();
  944.   ODNameSpaceManager*  nsm = session->GetNameSpaceManager(ev);
  945.   HWND hwndListBox = WinWindowFromID(kindMenu, idItem);
  946.  
  947.   ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
  948.  
  949.    ODPartHandlerRegistryInt* odRegistry;
  950.    odRegistry = session -> GetRegistry(ev);
  951.  
  952.   for (ODType type = typeIter->First(ev);
  953.     typeIter->IsNotComplete(ev);
  954.     type = typeIter->Next(ev))
  955.   {
  956.     ISOString   theName = GetDisplayKind(type, session);
  957.     WinInsertLboxItem(hwndListBox, LIT_FIRST, theName);
  958.     return;
  959.   }
  960.   ODDisposePtr(pWorkArea);
  961.   delete typeIter;
  962. }
  963.  
  964. //------------------------------------------------------------------------------
  965. // ShowLinkDestinationInfoDlg
  966. //------------------------------------------------------------------------------
  967. ODBoolean ShowLinkDestinationInfo(
  968.                ODBaseLink*         link,
  969.                ODLinkInfo*         info,
  970.                ODBoolean           ChangesAllowed,
  971.                HWND                    hwnd,
  972.                ODFacet*                facet,
  973.                ODLinkInfoResult*   infoResult)
  974.  
  975. {
  976.    CHAR LoadError[CCHMAXPATH];
  977.    ULONG rc = 0;
  978.  
  979.    Environment *ev = somGetGlobalEnvironment();
  980.  
  981.    gLIResult = infoResult;
  982.    gLink     = link;
  983.    gChangesAllowed = ChangesAllowed;
  984.  
  985.    gFacet = facet;
  986.  
  987.    gSession = gFacet->GetFrame(ev)->GetStorageUnit(ev)->GetSession(ev);
  988.    // Load the resource file
  989.    DosLoadModule(LoadError, sizeof(LoadError), "ODRes", &hmodDLL);
  990.  
  991.   // Need to acquire frame and storage unit before using them. Put
  992.   // them in temp object so that when the temp object is out of
  993.   // scope, the object get released.
  994.   TempODFrame frame = facet->GetFrame(ev);
  995.   frame->Acquire(ev);
  996.   TempODStorageUnit su = frame->GetStorageUnit(ev);
  997.   su->Acquire(ev);
  998.   ODSession* session = su->GetSession(ev);
  999.  
  1000.   ODWindowState* WinStat = session->GetWindowState(ev);
  1001.  
  1002.   // Need to release the window. Use temp object to accomplish
  1003.   // the release when the temp object is out of scope.
  1004.   TempODWindow Window = WinStat->AcquireFrontRootWindow(ev);
  1005.   HWND Temphwnd = Window->GetPlatformWindow(ev);
  1006.  
  1007.   //Create a modal dialog box and display it.
  1008.   rc = WinDlgBox(HWND_DESKTOP,           //Parent is the DeskTop
  1009. //            HWND_DESKTOP,
  1010.             Temphwnd,
  1011.             (PFNWP)LinkDestInfoDlgProc,  //dialog window proc
  1012.             hmodDLL,                     //handle to the DLL containing Dialog resource.
  1013.             IDD_LDPAGEDLG,               //dialog template ID
  1014.             (PVOID) info);               //application data
  1015.  
  1016.    if (gLIResult){
  1017.        return kODTrue;
  1018.    }else
  1019.        return kODFalse;
  1020. }
  1021.  
  1022.  
  1023.  
  1024. /*********************************************************************
  1025.  *  Name : LinkDestInfoDlgProc
  1026.  *
  1027.  *************************************************************************/
  1028. MRESULT EXPENTRY LinkDestInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  1029.                                       MPARAM mp2)
  1030. {
  1031.  
  1032. Environment* ev = somGetGlobalEnvironment();
  1033.  
  1034.    ODBoolean needsUpdate;
  1035.    static ODBoolean firstTime;
  1036.    static ODLinkInfo* info;
  1037.  
  1038.    static wchar_t wcsDate[kODDateLength]    = L"";
  1039.    char* mbsDate;
  1040.  
  1041.    switch(msg)
  1042.    {
  1043.       case WM_INITDLG:
  1044.       {
  1045.  
  1046.             info = (ODLinkInfo*)mp2;
  1047.  
  1048.             // set the Kind
  1049.             WinSetDlgItemText(hwnd, IDD_LDKINDTXT, GetDisplayKind(info->kind, gSession));
  1050.  
  1051.             // set up created
  1052.             time_t theTime = info->creationTime;
  1053.         if (theTime) {
  1054.            char* dateFormat = nl_langinfo(D_T_FMT); 
  1055.            struct tm *timeptr = localtime((const time_t*) &theTime);
  1056.  
  1057.            wchar_t wcsDateFormat [kODDateLength * kODWcsLength];
  1058.            mbstowcs (wcsDateFormat, dateFormat, kODDateLength * kODWcsLength);
  1059.            wcsftime(wcsDate, kODDateLength*kODWcsLength, wcsDateFormat, timeptr);
  1060.            mbsDate = (char*) malloc (kODDateLength*kODWcsLength);
  1061.            wcstombs(mbsDate, wcsDate, kODDateLength*kODWcsLength);
  1062.                WinSetDlgItemText(hwnd, IDD_LDCREATEDTXT, mbsDate);
  1063.            free(mbsDate);
  1064.         }
  1065.  
  1066.             // set up modified
  1067.             theTime = info->changeTime;
  1068.         if (theTime) {
  1069.            char* dateFormat = nl_langinfo(D_T_FMT); 
  1070.            struct tm *timeptr = localtime((const time_t*) &theTime);
  1071.  
  1072.            wchar_t wcsDateFormat [kODDateLength * kODWcsLength];
  1073.            mbstowcs (wcsDateFormat, dateFormat, kODDateLength * kODWcsLength);
  1074.            wcsftime(wcsDate, kODDateLength*kODWcsLength, wcsDateFormat, timeptr);
  1075.            mbsDate = (char*) malloc (kODDateLength*kODWcsLength);
  1076.            wcstombs(mbsDate, wcsDate, kODDateLength*kODWcsLength);
  1077.                WinSetDlgItemText(hwnd, IDD_LDUPDATEDTXT, mbsDate);
  1078.            free(mbsDate);
  1079.  
  1080.         }
  1081.        
  1082.         needsUpdate = (info->change == kODUnknownUpdate) || (info->change != gLink->GetUpdateID(ev));
  1083.             
  1084.             gLIResult->autoUpdate = info->autoUpdate;
  1085.             firstTime = kODTrue;
  1086.             WinCheckButton(hwnd,IDD_LDAUTOMATICALLYBTN,(gLIResult->autoUpdate));
  1087.             WinCheckButton(hwnd,DID_LDMANUALLYBTN,!(gLIResult->autoUpdate));
  1088.         // Disable Update Now button if updates are automatic or link is up to date.
  1089.         if ( info->autoUpdate || !needsUpdate ) {
  1090.  
  1091.                 WinEnableWindow(WinWindowFromID(hwnd,DID_LDUPDATENOWBTN), FALSE);
  1092.  
  1093.             }else{
  1094.                 WinEnableWindow(WinWindowFromID(hwnd,DID_LDUPDATENOWBTN), TRUE);
  1095.             }
  1096.  
  1097.  
  1098.             WinSetWindowPtr(hwnd, QWL_USER, info);
  1099.  
  1100.  
  1101.       }
  1102.       return FALSE;
  1103.       break;
  1104.       case WM_HELP:
  1105.             {
  1106.               #if (defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_))
  1107.               ODFrame   *frame   = gFacet->GetFrame(ev);
  1108.               ODSession* session = frame->GetStorageUnit(ev)->GetSession(ev);
  1109.               ODHelp   * helpme  = session->GetHelp(ev);
  1110.               helpme->DisplayHelp(ev,ODHELPFILE,IDD_LTPAGEDLG_PANEL);
  1111.               #endif
  1112.             }
  1113.       break;
  1114.  
  1115.       case WM_CONTROL:
  1116.          switch (SHORT1FROMMP (mp1) )
  1117.          {
  1118.           case IDD_LDAUTOMATICALLYBTN:
  1119.               // we get this message when the dialog comes up; don't want to act on it.
  1120.               if(firstTime)
  1121.                  firstTime = kODFalse;
  1122.               else if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED ) {
  1123.                    WinCheckButton(hwnd,IDD_LDAUTOMATICALLYBTN,TRUE);
  1124.                    WinCheckButton(hwnd,DID_LDMANUALLYBTN,FALSE);
  1125.                    gLIResult->autoUpdate = kODTrue;
  1126.                    WinEnableWindow(WinWindowFromID(hwnd,DID_LDUPDATENOWBTN), FALSE);
  1127.               }
  1128.           break;
  1129.  
  1130.           case DID_LDMANUALLYBTN:
  1131.               if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED ) {
  1132.                    WinCheckButton(hwnd,DID_LDMANUALLYBTN,TRUE);
  1133.                    WinCheckButton(hwnd,IDD_LDAUTOMATICALLYBTN,FALSE);
  1134.                    gLIResult->autoUpdate = kODFalse;
  1135.                needsUpdate = (info->change == kODUnknownUpdate) || (info->change != gLink->GetUpdateID(ev));
  1136.                if (needsUpdate) {
  1137.                      WinEnableWindow(WinWindowFromID(hwnd,DID_LDUPDATENOWBTN), TRUE);
  1138.                    }
  1139.               }
  1140.           break;
  1141.          }
  1142.       break;
  1143.  
  1144.       case WM_COMMAND:
  1145.  
  1146.          switch (SHORT1FROMMP (mp1) )
  1147.          {
  1148.           case DID_OK:
  1149.             gLIResult->action = kODLinkInfoOk;
  1150.             WinDismissDlg(hwnd, TRUE);
  1151.           break;
  1152.  
  1153.           case DID_CANCEL:
  1154.               gLIResult = kODNULL;
  1155.               WinDismissDlg(hwnd, FALSE);
  1156.           break;
  1157.  
  1158.           case DID_LDBREAKLINKBTN:
  1159.               gLIResult->action = kODLinkInfoBreakLink;
  1160.               WinDismissDlg(hwnd, TRUE);
  1161.           break;
  1162.  
  1163.           case DID_LDUPDATENOWBTN:
  1164.               gLIResult->action = kODLinkInfoUpdateNow;
  1165.               WinDismissDlg(hwnd, TRUE);
  1166.           break;
  1167.  
  1168.           case IDD_LDFINDSOURCEBTN:
  1169.               gLIResult->action = kODLinkInfoFindSource;
  1170.               WinDismissDlg(hwnd, TRUE);
  1171.           break;
  1172.  
  1173.           case DID_HELP:
  1174.               {
  1175.                 // We need to get a handle to the session object here...
  1176.                 ODFrame   *frame   = gFacet->GetFrame(ev);
  1177.                 ODSession* session = frame->GetStorageUnit(ev)->GetSession(ev);
  1178.                 ODHelp   * helpme  = session->GetHelp(ev);
  1179.                 helpme->DisplayHelp(ev,ODHELPFILE,IDD_LTPAGEDLG_PANEL);
  1180.               }
  1181.               break;
  1182.  
  1183.           }  /* end switch WM_COMMAND */
  1184.  
  1185.          break;
  1186.  
  1187.  
  1188.       case WM_DESTROY:
  1189.  
  1190.          // Clean up memory
  1191.  
  1192.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1193.          break;
  1194.  
  1195.  
  1196.       default:
  1197.          //Pass all unprocessed messages to the default dialog proc
  1198.  
  1199.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1200.          break;
  1201.  
  1202.      } //end switch (msg)
  1203.  
  1204.   return (MRESULT) FALSE;
  1205. }
  1206.  
  1207.  
  1208.  
  1209. //------------------------------------------------------------------------------
  1210. // ShowLinkSourceInfo
  1211. //------------------------------------------------------------------------------
  1212. ODBoolean ShowLinkSourceInfo(
  1213.                ODBaseLinkSource*   linkSource,
  1214.                ODUpdateID          change,
  1215.                ODBoolean           changesAllowed,
  1216.                HWND                hwnd,
  1217.                ODFacet*            facet,
  1218.                ODLinkInfoResult*   infoResult)
  1219.  
  1220. {
  1221.    CHAR LoadError[CCHMAXPATH];
  1222.    ULONG rc = 0;
  1223.    Environment *ev = somGetGlobalEnvironment();
  1224.  
  1225.    gLIResult = infoResult;
  1226.  
  1227.    gFacet = facet;
  1228.  
  1229.    gSession = gFacet->GetFrame(ev)->GetStorageUnit(ev)->GetSession(ev);
  1230.    gUpdateID = change;
  1231.    gChangesAllowed = changesAllowed;
  1232.  
  1233.    // Load the resource file
  1234.    DosLoadModule(LoadError, sizeof(LoadError), "ODRes", &hmodDLL);
  1235.  
  1236.   // Need to acquire frame and storage unit before using them. Put
  1237.   // them in temp object so that when the temp object is out of
  1238.   // scope, the object get released.
  1239.   TempODFrame frame = facet->GetFrame(ev);
  1240.   frame->Acquire(ev);
  1241.   TempODStorageUnit su = frame->GetStorageUnit(ev);
  1242.   su->Acquire(ev);
  1243.   ODSession* session = su->GetSession(ev);
  1244.  
  1245.   ODWindowState* WinStat = session->GetWindowState(ev);
  1246.  
  1247.   // Need to release the window. Use temp object to accomplish
  1248.   // the release when the temp object is out of scope.
  1249.   TempODWindow Window = WinStat->AcquireFrontRootWindow(ev);
  1250.   HWND Temphwnd = Window->GetPlatformWindow(ev);
  1251.  
  1252.    //Create a modal dialog box and display it.
  1253.    rc = WinDlgBox(HWND_DESKTOP,           //Parent is the DeskTop
  1254. //             HWND_DESKTOP,
  1255.              Temphwnd,
  1256.              (PFNWP)LinkSourceInfoDlgProc,  //dialog window proc
  1257.              hmodDLL,                     //handle to the DLL containing Dialog resource.
  1258.              IDD_LSPAGEDLG,               //dialog template ID
  1259.              (PVOID) linkSource);         //application data
  1260.  
  1261.    if (gLIResult){
  1262.        return kODTrue;
  1263.    }else
  1264.        return kODFalse;
  1265. }
  1266.  
  1267.  
  1268. /*********************************************************************
  1269.  *  Name : LinkSourceInfoDlgProc
  1270.  *
  1271.  *************************************************************************/
  1272. MRESULT EXPENTRY LinkSourceInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  1273.                                         MPARAM mp2)
  1274. {
  1275.  
  1276.    Environment *ev = somGetGlobalEnvironment();
  1277.    static ODNameSpaceManager* nsm;
  1278.  
  1279.    static ODBaseLinkSource* linkSource;
  1280.    ODBoolean needsUpdate;
  1281.    static ODBoolean firstTime;
  1282.  
  1283.    static wchar_t wcsDate[kODDateLength]    = L"";
  1284.    char* mbsDate;
  1285.  
  1286.    switch(msg)
  1287.    {
  1288.       case WM_INITDLG:
  1289.       {
  1290.  
  1291.             linkSource = (ODBaseLinkSource*)mp2;
  1292.  
  1293.             ODLinkKey key;
  1294.             if (linkSource->Lock(ev, 0, &key))
  1295.             {
  1296.               TRY
  1297.                 ODStorageUnit *contentSU = linkSource->GetContentStorageUnit(ev, key);
  1298.  
  1299.                 // set the Kind
  1300.                 ODULong kindLen;
  1301.                 ODType  kind;
  1302.                 GetBestKindAndSize(contentSU, &kind, &kindLen);
  1303.                 if (kind)  // was kindLen - rrk 28feb97
  1304.                     WinSetDlgItemText(hwnd, IDD_LSKINDTXT,GetDisplayKind(kind, gSession));
  1305.  
  1306.                 // set up created
  1307.  
  1308.                 // ODGetPOCreationDate is replaced by ODGetCreationDate; pass in SU instead
  1309.                 // of PersistentObject ptr.
  1310.                 // time_t theTime = ODGetPOCreationDate(ev, linkSource);
  1311.                 //  time_t theTime = ODGetCreationDate(ev, contentSU);
  1312.  
  1313.                 time_t theTime = ODGetCreationDate(ev, ODGetSUFromPstObj(ev, linkSource));
  1314.             if (theTime) {
  1315.                char* dateFormat = nl_langinfo(D_T_FMT); 
  1316.                      struct tm *timeptr = localtime((const time_t*) &theTime);
  1317.  
  1318.                wchar_t wcsDateFormat [kODDateLength * kODWcsLength];
  1319.                mbstowcs (wcsDateFormat, dateFormat, kODDateLength * kODWcsLength);
  1320.                wcsftime(wcsDate, kODDateLength*kODWcsLength, wcsDateFormat, timeptr);
  1321.                mbsDate = (char*) malloc (kODDateLength*kODWcsLength);
  1322.                wcstombs(mbsDate, wcsDate, kODDateLength*kODWcsLength);
  1323.                    WinSetDlgItemText(hwnd, IDD_LSCREATEDTXT, mbsDate);
  1324.                free(mbsDate);
  1325.              }
  1326.  
  1327.  
  1328.                 // set up modified
  1329.                 theTime = linkSource->GetChangeTime(ev);
  1330.             if (theTime) {
  1331.                char* dateFormat = nl_langinfo(D_T_FMT); 
  1332.                      struct tm *timeptr = localtime((const time_t*) &theTime);
  1333.  
  1334.                wchar_t wcsDateFormat [kODDateLength * kODWcsLength];
  1335.                mbstowcs (wcsDateFormat, dateFormat, kODDateLength * kODWcsLength);
  1336.                wcsftime(wcsDate, kODDateLength*kODWcsLength, wcsDateFormat, timeptr);
  1337.                mbsDate = (char*) malloc (kODDateLength*kODWcsLength);
  1338.                wcstombs(mbsDate, wcsDate, kODDateLength*kODWcsLength);
  1339.                    WinSetDlgItemText(hwnd, IDD_LSUPDATEDTXT, mbsDate);
  1340.                free(mbsDate);
  1341.              }
  1342.  
  1343.               CATCH_ALL
  1344.                     linkSource->Unlock(ev, key);
  1345.                     RERAISE;
  1346.               ENDTRY
  1347.               linkSource->Unlock(ev, key);
  1348.             }
  1349.         needsUpdate = (gUpdateID == kODUnknownUpdate) || (gUpdateID != linkSource->GetUpdateID(ev));
  1350.             
  1351.         gLIResult->autoUpdate = linkSource->IsAutoUpdate(ev);
  1352.             firstTime = kODTrue;
  1353.             WinCheckButton(hwnd,IDD_LSONSAVEBTN,(gLIResult->autoUpdate));
  1354.             WinCheckButton(hwnd,DID_LSMANUALLYBTN,!(gLIResult->autoUpdate));
  1355.  
  1356.         if ( gLIResult->autoUpdate || !needsUpdate ) {
  1357.                 WinEnableWindow(WinWindowFromID(hwnd,DID_LSUPDATENOWBTN), FALSE);
  1358.             }else{
  1359.                 WinEnableWindow(WinWindowFromID(hwnd,DID_LSUPDATENOWBTN), TRUE);
  1360.             }
  1361.  
  1362.             WinSetWindowPtr(hwnd, QWL_USER, linkSource);
  1363.  
  1364.       }
  1365.       return FALSE;
  1366.       break;
  1367.       case WM_HELP:
  1368.             {
  1369.               ODFrame   *frame   = gFacet->GetFrame(ev);
  1370.               ODSession* session = frame->GetStorageUnit(ev)->GetSession(ev);
  1371.               ODHelp   * helpme  = session->GetHelp(ev);
  1372.               helpme->DisplayHelp(ev,ODHELPFILE,IDD_LSPAGEDLG_PANEL);
  1373.  
  1374.             }
  1375.       break;
  1376.  
  1377.       case WM_CONTROL:
  1378.          switch (SHORT1FROMMP (mp1) )
  1379.          {
  1380.           case IDD_LSONSAVEBTN:
  1381.               // we get this message when the dialog comes up; don't want to act on it.
  1382.               if(firstTime)
  1383.                  firstTime = kODFalse;
  1384.               else if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED ) {
  1385.                    WinCheckButton(hwnd,IDD_LSONSAVEBTN,TRUE);
  1386.                    WinCheckButton(hwnd,DID_LSMANUALLYBTN,FALSE);
  1387.                    gLIResult->autoUpdate = kODTrue;
  1388.                    WinEnableWindow(WinWindowFromID(hwnd,DID_LSUPDATENOWBTN), FALSE);
  1389.               }
  1390.           break;
  1391.  
  1392.           case DID_LSMANUALLYBTN:
  1393.               if ((USHORT) SHORT2FROMMP (mp1) == BN_CLICKED ) {
  1394.                    WinCheckButton(hwnd,DID_LSMANUALLYBTN,TRUE);
  1395.                    WinCheckButton(hwnd,IDD_LSONSAVEBTN,FALSE);
  1396.                    gLIResult->autoUpdate = kODFalse;
  1397.                needsUpdate = (gUpdateID == kODUnknownUpdate) || (gUpdateID != linkSource->GetUpdateID(ev));
  1398.                if (needsUpdate) {
  1399.                      WinEnableWindow(WinWindowFromID(hwnd,DID_LSUPDATENOWBTN), TRUE);
  1400.                    }
  1401.               }
  1402.           break;
  1403.          }
  1404.       break;
  1405.  
  1406.       case WM_COMMAND:
  1407.  
  1408.          switch (SHORT1FROMMP (mp1) )
  1409.          {
  1410.           case DID_OK:
  1411.             gLIResult->action = kODLinkInfoOk;
  1412.             WinDismissDlg(hwnd, TRUE);
  1413.           break;
  1414.  
  1415.           case DID_CANCEL:
  1416.               gLIResult = kODNULL;
  1417.               WinDismissDlg(hwnd, FALSE);
  1418.           break;
  1419.  
  1420.           case DID_LSBREAKLINKBTN:
  1421.               gLIResult->action = kODLinkInfoBreakLink;
  1422.               WinDismissDlg(hwnd, TRUE);
  1423.           break;
  1424.  
  1425.           case DID_LSUPDATENOWBTN:
  1426.               gLIResult->action = kODLinkInfoUpdateNow;
  1427.               WinDismissDlg(hwnd, TRUE);
  1428.           break;
  1429.  
  1430.           case DID_HELP:
  1431.               {
  1432.                 // We need to get a handle to the session object here...
  1433.                 ODFrame   *frame   = gFacet->GetFrame(ev);
  1434.                 ODSession* session = frame->GetStorageUnit(ev)->GetSession(ev);
  1435.                 ODHelp   * helpme  = session->GetHelp(ev);
  1436.                 helpme->DisplayHelp(ev,ODHELPFILE,IDD_LSPAGEDLG_PANEL);
  1437.               }
  1438.               break;
  1439.  
  1440.  
  1441.           }  /* end switch WM_COMMAND */
  1442.  
  1443.          break;
  1444.  
  1445.  
  1446.       case WM_DESTROY:
  1447.  
  1448.          // Clean up memory
  1449.  
  1450.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1451.          break;
  1452.  
  1453.  
  1454.       default:
  1455.          //Pass all unprocessed messages to the default dialog proc
  1456.  
  1457.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1458.          break;
  1459.  
  1460.      } //end switch (msg)
  1461.  
  1462.   return (MRESULT) FALSE;
  1463. }
  1464.  
  1465.  
  1466. //------------------------------------------------------------------------------
  1467. // GetBestKindAndSize
  1468. #ifdef DEFECT_22109
  1469. // note:  Will want to use GetUserKindForKind here when 22109 is resolved.
  1470. #endif
  1471. //------------------------------------------------------------------------------
  1472. ODStatic void GetBestKindAndSize(ODStorageUnit* contentSU, ODType* kind, ODULong* size)
  1473. {
  1474.    Environment* ev = somGetGlobalEnvironment();
  1475.  
  1476.    if (contentSU->Exists(ev, kODPropContents, (ODValueType)kODNULL, 1))
  1477.    {
  1478.        contentSU->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType)kODNULL, 1, kODPosUndefined);
  1479.        *kind = contentSU->GetType(ev);
  1480.        *size = contentSU->GetSize(ev);
  1481.    }
  1482.    else
  1483.    {
  1484.        *kind = (ODType) kODNULL;
  1485.        *size = 0;
  1486.    }
  1487. }
  1488.  
  1489.  
  1490. //------------------------------------------------------------------------------
  1491. // GetDisplayKind
  1492. //------------------------------------------------------------------------------
  1493. ODStatic ISOString GetDisplayKind(ODType type, ODSession* session)
  1494. {
  1495.    Environment* ev = somGetGlobalEnvironment();
  1496.        
  1497.    ISOString   theName;
  1498.  
  1499.    ODPartHandlerRegistryInt* odRegistry;
  1500.    odRegistry = session -> GetRegistry(ev);
  1501.  
  1502.    theName =  odRegistry->GetKindDisplayNameFromKind(ev, type);
  1503.    if ( (strcmp(theName, "GetKindDisplayName: No PartKind matches partKindName") != 0)
  1504.     && (strcmp(theName, "GetKindDisplayName: No Parts found") != 0) ) {
  1505.         return(theName);
  1506.         }
  1507.    else {
  1508.         // No available editors support this type
  1509.         ODTranslation* translation = session->GetTranslation(ev);
  1510.         ODPlatformType platformType = translation->GetPlatformTypeFromISOType(ev, type);
  1511.         if ( platformType == kODNULL ) {
  1512.            return( catgets(ODcat_handle, LINKSPEC_SET, LINKSPEC_80, "No user kind"));
  1513.         }
  1514.         else {
  1515. #ifdef RRK_DEBUG
  1516.            PRINT("RRK **** platformType is %d\t type is %s.\n", platformType, type);
  1517. #endif           
  1518.       char    szUserKind[256];
  1519.       memset(szUserKind,0,256);
  1520.  
  1521.       switch ( (UINT)platformType ) {
  1522.             case CF_TEXT:
  1523.         return(newString("TEXT"));
  1524.         break;                    
  1525.         case CF_BITMAP:
  1526.         return(newString("BITMAP")); 
  1527.         break;                    
  1528.         case CF_DSPTEXT:
  1529.         return(newString("DSPTEXT"));
  1530.         break;                    
  1531.            case CF_DSPBITMAP:
  1532.         return(newString("DSPBITMAP")); 
  1533.         break;                    
  1534.         case CF_METAFILE:
  1535.         return(newString("METAFILE"));
  1536.         break;                    
  1537.         case CF_DSPMETAFILE:
  1538.         return(newString("DSPMETAFILE"));
  1539.         break;                    
  1540.         case CF_PALETTE:
  1541.         return(newString("PALETTE"));
  1542.         break;                    
  1543.             default:
  1544.         return( catgets(ODcat_handle, LINKSPEC_SET, LINKSPEC_80, "No user kind"));
  1545. #if 0
  1546.                 if (!WinQueryAtomName(WinQuerySystemAtomTable(), platformType, szUserKind, 256)) {
  1547.                         pWorkArea = catgets(ODcat_handle, LINKSPEC_SET, LINKSPEC_80, "No user kind");
  1548.                 }
  1549. #endif
  1550.                   break;
  1551.                  }
  1552.     }
  1553.    }
  1554. }
  1555.  
  1556. //------------------------------------------------------------------------------
  1557. // ShowLinkUpdateAlert
  1558. //------------------------------------------------------------------------------
  1559.  
  1560. ODBoolean ShowLinkUpdateAlert()
  1561. {
  1562.  
  1563.    CHAR LoadError[CCHMAXPATH];
  1564.    ULONG rc = 0;
  1565.    HSWITCH hswitch;
  1566.    SWCNTRL swcntrl;
  1567.    PTIB    ptib;
  1568.    PPIB    ppib;
  1569.    PID     pid;
  1570.    HWND    hwnd = HWND_DESKTOP;
  1571.  
  1572.    Environment *ev = somGetGlobalEnvironment();
  1573.  
  1574.    gAlertResult = kLinkUpdateStopBtn;
  1575.  
  1576.    // Load the resource file
  1577.    DosLoadModule(LoadError, sizeof(LoadError), "ODRes", &hmodDLL);
  1578.    
  1579.    // get the current hwnd so the dialog can be made modal.
  1580.    if(DosGetInfoBlocks(&ptib, &ppib) == 0) {
  1581.      pid = ppib->pib_ulpid;
  1582.      if ((hswitch = WinQuerySwitchHandle(0, pid) ) != NULLHANDLE)
  1583.        if (!WinQuerySwitchEntry(hswitch, &swcntrl))
  1584.      hwnd = swcntrl.hwnd;
  1585.    }
  1586.     
  1587.    //Create a modal dialog box and display it.
  1588.    rc = WinDlgBox(HWND_DESKTOP,
  1589.              hwnd,
  1590.              (PFNWP)LinkUpdateAlertDlgProc,  //dialog window proc
  1591.              hmodDLL,                        //handle to the DLL containing Dialog resource.
  1592.              IDD_LUDLG,                      //dialog template ID
  1593.              NULL);
  1594.  
  1595.    return (gAlertResult == kLinkUpdateContinueBtn);
  1596. }
  1597.  
  1598.  
  1599. /*********************************************************************
  1600.  *  Name : LinkUpdateAlertDlgProc
  1601.  *
  1602.  *************************************************************************/
  1603. MRESULT EXPENTRY LinkUpdateAlertDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  1604.                                         MPARAM mp2)
  1605. {
  1606.  
  1607.    Environment *ev = somGetGlobalEnvironment();
  1608.    static ODNameSpaceManager* nsm;
  1609.  
  1610.  
  1611.    switch(msg)
  1612.    {
  1613.       case WM_INITDLG:
  1614.       {
  1615.  
  1616.             WinSetWindowPtr(hwnd, QWL_USER, mp2);
  1617.  
  1618.       }
  1619.       return FALSE;
  1620.       break;
  1621.  
  1622.       case WM_COMMAND:
  1623.  
  1624.          switch (SHORT1FROMMP (mp1) )
  1625.          {
  1626.           case IDD_LUUPDATE:
  1627.             gAlertResult = kLinkUpdateContinueBtn;
  1628.             WinDismissDlg(hwnd, TRUE);
  1629.           break;
  1630.           case IDD_LUSTOP:
  1631.             gAlertResult = kLinkUpdateStopBtn;
  1632.             WinDismissDlg(hwnd, TRUE);
  1633.           break;
  1634.           }  /* end switch WM_COMMAND */
  1635.  
  1636.          break;
  1637.  
  1638.  
  1639.       case WM_DESTROY:
  1640.  
  1641.          // Clean up memory
  1642.  
  1643.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1644.          break;
  1645.  
  1646.  
  1647.       default:
  1648.          //Pass all unprocessed messages to the default dialog proc
  1649.  
  1650.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1651.          break;
  1652.  
  1653.      } //end switch (msg)
  1654.  
  1655.   return (MRESULT) FALSE;
  1656. }
  1657.  
  1658.  
  1659. #endif //  _PLATFORM_OS2_
  1660.  
  1661. #ifdef _PLATFORM_MACINTOSH_         //Mac specific file - not used by IBM
  1662. /*
  1663.         File:           LinkDlgs.cpp
  1664.  
  1665.         Contains:       implementation of the Paste As and Link Info dialogs
  1666.  
  1667.         Owned by:       Craig Carper
  1668.  
  1669.         Copyright:      ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  1670.  
  1671.         Change History (most recent first):
  1672.  
  1673.                 <58>    10/16/95        CC              GM 1292157: Moved TranslateValueTypes,
  1674.                                                                         AddTranslationKindToMenu,
  1675.                                                                         GetMenuStringForKind,
  1676.                                                                         DefaultMenuStringForKind,
  1677.                                                                         StringPtrFromStrHandle to InfoUtil.cpp.
  1678.                 <57>    10/10/95        DM              1285040: GM: PasteAs into part viewed in
  1679.                                                                         window hangs (dont assume persistent frame
  1680.                                                                         in ShowPasteAsDialog())
  1681.                 <56>     10/3/95        eeh             1284995: new default param to
  1682.                                                                         SetDialogTextStyle
  1683.                 <55>     10/3/95        TJ              Changes done by RefBall Team
  1684.                 <54>     9/12/95        DM              1280020 FB1 part trans dlg mem leaks
  1685.                 <53>      9/8/95        Té              1281096 FB2:Many constants in ODTypesB
  1686.                                                                         without kOD prefix!
  1687.                 <52>      9/1/95        CC              1279449: Initialize dlg to null & use
  1688.                                                                         ODVolatile.
  1689.                                                                         ShowLinkSourceInfo,
  1690.                                                                         ShowLinkDestinationInfo: Use ODVolatile.
  1691.                 <51>     8/29/95        DM              1221778, 1276165: [ShowLinkUpdateAlert]
  1692.                                                                         drop count arg in ShowLinkUpdateAlert
  1693.                 <50>     8/26/95        Té              1274606 FB2: Patching Remarks
  1694.                 <49>     8/25/95        eeh             1230007: new param to DrawITextInDlogBox
  1695.                 <48>     8/23/95        CC              1278378: ShowPasteAsDialog behaves
  1696.                                                                         incorrectly on switch from Embed to Merge.
  1697.                                                                         1242581: ShowPasteAsDialog should respect
  1698.                                                                         preferred editor.
  1699.                                                                         1278840: ShowPasteAsDialog should respect
  1700.                                                                         preferred kind.
  1701.                 <47>     8/15/95        CC              1276520: Adapted to changes to
  1702.                                                                         ShowTranslateDialog.
  1703.                 <46>     8/12/95        Té              1276812 Need to use TempObjs and TempRefs
  1704.                                                                         for exception safety and to avoid TRY
  1705.                                                                         blocks, 1276807 Opt./Bug: use StdTypIO
  1706.                                                                         routines for portable streaming & smaller
  1707.                                                                         footprint
  1708.                 <45>     7/28/95        CC              1242576: Removed obsolete Others dialog
  1709.                                                                         code.
  1710.                 <44>     7/24/95        CC              1236616: Use CreateTypeList factory method.
  1711.                 <43>     7/18/95        eeh             1222282: move constants to DlogUtil.h
  1712.                 <42>     6/21/95        CC              1260937: BB: ODTypeListIterator must return
  1713.                                                                         copies of ODType values.
  1714.                 <41>     6/16/95        CC              1258538: ShowPasteAsDialog: Release kind
  1715.                                                                         and editor menu resources and delete the
  1716.                                                                         menu; also check GetMenu result.
  1717.                                                                         1257141: TranslateValueTypes: Changed
  1718.                                                                         translateFromList parameter to
  1719.                                                                         OrderedCollection. Added
  1720.                                                                         GetIndexedElement() function.
  1721.                                                                         SetDateTimeStrings: Added
  1722.                                                                         CUsingLibraryResources.
  1723.                                                                         DefaultMenuStringForKind: Added
  1724.                                                                         CUsingLibraryResources.
  1725.                 <40>      6/7/95        jpa             Fixed EndUsingLibRsrcs calls. [1255369]
  1726.                 <39>      6/7/95        CC              1236299:  Wrap individual calls with using
  1727.                                                                         library resources calls.
  1728.                 <38>      6/2/95        CC              1255476: ShowPasteAsDialog: Release object
  1729.                                                                         returned by ODFrame::AcquirePart().
  1730.                 <37>     5/30/95        CG              #1251234 Extraneous items in Paste As kind
  1731.                                                                         popup.
  1732.                 <36>     5/26/95        VL              1251403: Multithreading naming support.
  1733.                 <35>     5/18/95        CG              #1249263 BB: BndNSUtl.cpp does not compile
  1734.                                                                         standalone.
  1735.                 <34>      5/1/95        CG              #1240845        BB: Kinds popups need to include
  1736.                                                                         all kinds that an editor can edit.
  1737.                 <33>     4/29/95        Té              1243222 BB: New documents from stationery
  1738.                                                                         should have create/modinfo reset.
  1739.                 <32>     4/27/95        CC              1243348: Moved ShowAlert into
  1740.                                                                         DlogUtils.cpp.
  1741.                                                                         ShowLinkInfo: Don't alert user on break
  1742.                                                                         link (problems with nested calls use
  1743.                                                                         library resources).
  1744.                 <31>     4/25/95        CC              1242555: TranslateValueTypes: $5 entered as
  1745.                                                                         bug 1242571.
  1746.                                                                         1242555: ShowPasteAsDialog: $5 entered as
  1747.                                                                         bug 1242581.
  1748.                                                                         1242555:  OthersDlgFilterProc: Removed
  1749.                                                                         obsolete $5 comment.
  1750.                 <30>     4/14/95        Té              #1235279 BB: InfoUtil & StdTypIO functions
  1751.                                                                         should take Environment* and SU* when
  1752.                                                                         possible
  1753.                 <29>     3/28/95        CC              1229640: Added LinkInfoFilterProc and
  1754.                                                                         PasteAsFilterProc.
  1755.                                                                         Added DeavtivateModalDialog routine.
  1756.                                                                         DrawKindName and DrawEditorName calls
  1757.                                                                         DrawITextInDlogBox utility.
  1758.                 <28>     3/27/95        CC              1229640: Use ODTranslation::
  1759.                                                                         ShowTranslateDialog() in ShowPasteAsDialog.
  1760.                                                                         Show editor in Paste As dialog.
  1761.                 <27>     3/22/95        CC              1230322: Changed parameter to
  1762.                                                                         ShowPasteAsDialog(); removed
  1763.                                                                         DefaultMergeSetting().
  1764.                 <26>     3/17/95        CC              1203315: Added DefaultMergeSetting(),
  1765.                                                                         EnablePasteAsOkButton() and
  1766.                                                                         DrawDeactivePICTItem().
  1767.                                                                         Removed InitialMergeSetting() &
  1768.                                                                         DrawDeactiveDialogItem().
  1769.                                                                         Fix to PrepareToDrawGray to set the pen
  1770.                                                                         pattern to gray if no gray color is
  1771.                                                                         available.
  1772.                 <25>      3/9/95        CC              1221471: Added changesAllowed parameter to
  1773.                                                                         ShowLinkDestinationInfo() and
  1774.                                                                         ShowLinkSourceInfo().
  1775.                 <24>      3/9/95        CC              1220342: DrawIntlStaticText: Save and
  1776.                                                                         restore font; don't change font if dialog
  1777.                                                                         font is same script as intl text.
  1778.                                                                         defined ODDisposeRoutineDescriptor and
  1779.                                                                         ODDisposeDlg macros.
  1780.                                                                         MakeOthersList(): don't set window font and
  1781.                                                                         size; adopt font and size as determined by
  1782.                                                                         'finf' resource.
  1783.                                                                         ShowOthersDialog: removed okButtonEnabled.
  1784.                                                                         Moved DrawDefaultButtonOutline to DlogUtils
  1785.                                                                         and renamed.
  1786.                 <23>      3/7/95        CC              1226083: Removed SetKindText(); added
  1787.                                                                         DrawIntlStaticText() and gKindName global.
  1788.                 <22>      3/6/95        jpa             Use dialog utilities (ODGetNewDialog,
  1789.                                                                         ODDialogFilterProc) to make dlogs movable.
  1790.                                                                         [1218957]
  1791.                 <21>      3/3/95        CC              1199186 Save and restore the current port
  1792.                                                                         in ShowPasteAsDialog, ShowLinkSourceInfo,
  1793.                                                                         and ShowLinkDestinationInfo.
  1794.                                                                         1223607 Removed link size from info
  1795.                                                                         dialogs;
  1796.                                                                         GetBestKindAndSize->BestContentKind.
  1797.                                                                         1224967 Time updated was incorrect.
  1798.                                                                         1223861 Added ShowLinkStatusAlert().
  1799.                 <20>     2/24/95        jpa             Use ODNewRgn. [1220810]
  1800.                 <19>     2/24/95        CC              1220342: GetMenuStringForKind: Return
  1801.                                                                         script code.
  1802.                                                                         1220342: AddTranslationKindToMenu: Set
  1803.                                                                         script code for menu item.
  1804.                                                                         1220339: CreateTranslationStrings: Modified
  1805.                                                                         to build StringWithScriptCodeArrayPtr.
  1806.                 <18>     2/15/95        CC              Lots of changes:
  1807.                                                                         1194329 UpdateNow button in info dialogs is
  1808.                                                                         enabled only if "Manually" is selected and
  1809.                                                                         the link (or link destination) needs
  1810.                                                                         updating.
  1811.                                                                         1220318 Added LinkDialogFilter.
  1812.                                                                         1220318 ShowLinkInfo -- Use
  1813.                                                                         LinkDialogFilter in call to ModalDialog.
  1814.                                                                         1205033 LinkInfo dialogs should be static
  1815.                                                                         if draft is read-only
  1816.                                                                         1218931 Link Info Dialog changes when draft
  1817.                                                                         is read-only
  1818.                                                                         1196831 Show link size in K bytes if 1K or
  1819.                                                                         larger.
  1820.                                                                         1220327 Data Interchange dialogs need to
  1821.                                                                         use filter procs.
  1822.                                                                         1153942 Changes to Destination Link Info
  1823.                                                                         dialog
  1824.                 <17>      2/7/95        CC              1211295: Added GetOriginalDraft() and
  1825.                                                                         SUClonedFromDraft().  ShowPasteAsDialog()
  1826.                                                                         takes an isMove parameter.
  1827.                                                                         1216124: ShowPasteAsDialog calls
  1828.                                                                         ODWindowState::DeactivateFrontWindow() and
  1829.                                                                         ActivateFrontWindow().
  1830.                 <16>     1/25/95        jpa             New ODIText format [1212619]
  1831.                 <15>     1/25/95        CC              1213198 ShowOthersDialog: Call LDispose
  1832.                                                                         BEFORE disposing of the LDEF.
  1833.                                                                         1213954 Initialize editor field of
  1834.                                                                         ODPasteAsResult to kODNoEditor.
  1835.                 <14>     1/12/95        jpa             Don't use obsolete Toolbox names [1211211]
  1836.                 <13>     1/10/95        CC              1153930: Added translation dialog;
  1837.                                                                         implemented new technique for dimming
  1838.                                                                         inactive items in Paste As dialog.
  1839.                 <12>    11/17/94        CG              #1187128: Moved GetDestinationKindsList to
  1840.                                                                         TransUtl.cpp to be shared with Part Info
  1841.                                                                         and NoPart.
  1842.                 <11>    10/31/94        CG              #1147225: Moved ContentValueTypes to
  1843.                                                                         InfoUtil.cpp.
  1844.                 <10>    10/27/94        CG              #1147225: Moved AddTypesToMenu to
  1845.                                                                         InfoUtil.cpp.
  1846.                  <9>     10/7/94        CC              1160232 - Added calls to
  1847.                                                                         EndUsingLibraryResources().
  1848.                  <8>     10/4/94        CC              1190299 - Use utility fcns in InfoUtil.h
  1849.                                                                         and DlogUtil.h.
  1850.                  <7>     9/20/94        CC              1160232 - Added ShowLinkUpdateAlert()
  1851.                                                                         1153930 - Added TranslateValueTypes() and
  1852.                                                                         other mods to add translation choices to
  1853.                                                                         Paste As dialog.
  1854.                  <6>     8/10/94        CC              1179943 - LinkInfo dialog functions take
  1855.                                                                         ODBaseLink and ODBaseLinkSource parameters.
  1856.                  <5>      8/2/94        CC              #1178169 - ShowPasteAsDialog() takes
  1857.                                                                         ODFacet* instead of ODFrame*.
  1858.                  <4>     7/31/94        CC              ShowLinkDestinationInfo - fix to display
  1859.                                                                         dialog correctly.
  1860.                  <3>     7/27/94        CC              Allocate kindList (a SOM object) on the
  1861.                                                                         heap, not the stack.
  1862.                  <2>      7/5/94        CC              Added typecasts of pascal strings for PPCC
  1863.                                                                         compiler.
  1864.                  <1>     6/24/94        CC              first checked in
  1865.                  <0>     6/13/94        SV              SOMverted
  1866.  
  1867.                 ------------------- CC ---- Converted to SOM
  1868.  
  1869.                 <14>      6/1/94        CG              Changed to use new public binding object.
  1870.                 <13>     5/11/94        Té              #1162405 Removed explicit ASLM dependency
  1871.                                                                         for using resources (missed a couple)
  1872.                 <12>     5/10/94        Té              #1162405 Removed explicit ASLM dependency
  1873.                                                                         for using resources
  1874.                 <11>      5/9/94        MB              #1162181: Changes necessary to install MMM.
  1875.                 <10>      4/6/94        CC              XMPTypeInfo: Changed field "creationDate"
  1876.                                                                         to "creationTime" and "modificationDate" to
  1877.                                                                         "changeTime". (1154722)
  1878.                  <9>      4/4/94        CC              Convert from using XMPTypeSet to
  1879.                                                                         XMPTypeList (1153046).
  1880.                  <8>      4/1/94        Té              #1154941: Get OpenDoc source to actually
  1881.                                                                         compile for PowerPC
  1882.                  <7>     3/28/94        CG              1153547: Renamed XMPSessn.h to XMPSessM.h.
  1883.                  <6>     3/25/94        JA              Added missing #include (1147588)
  1884.                  <5>     3/25/94        eeh             bug #1153053: Changes for PPC nativity.
  1885.                  <4>     3/24/94        CC              ShowLinkSourceInfo() takes XMPUpdateID
  1886.                                                                         parameter; XMPPasteAsResult specifies
  1887.                                                                         original kind when selected kind is a
  1888.                                                                         translation (1153068).
  1889.                  <3>     3/17/94        CC              Added ShowLinkSourceInfo() and
  1890.                                                                         ShowLinkDestinationInfo(). (1151329)
  1891.                  <1>     3/14/94        CC              first checked in
  1892.                  <0>     3/14/94        CC              Create ShowPasteAsDialog (1144253).
  1893.  
  1894.         In Progress:
  1895.  
  1896. */
  1897.  
  1898. #ifndef _PLFMDEF_
  1899. #include <plfmdef.h>
  1900. #endif
  1901.  
  1902. #ifndef _LINKDLGS_
  1903. #include <LinkDlgs.h>
  1904. #endif
  1905.  
  1906. #ifndef _INFOUTIL_
  1907. #include <InfoUtil.h>
  1908. #endif
  1909.  
  1910. #ifndef _DLOGUTIL_
  1911. #include <DlogUtil.h>
  1912. #endif
  1913.  
  1914. #ifndef _EXCEPT_
  1915. #include <Except.h>
  1916. #endif
  1917.  
  1918. #ifndef _LINKDEFS_
  1919. #include <LinkDefs.h>
  1920. #endif
  1921.  
  1922. #ifndef _USERSRCM_
  1923. #include <UseRsrcM.h>
  1924. #endif
  1925.  
  1926. #ifndef SOM_Module_OpenDoc_StdProps_defined
  1927. #include <StdProps.xh>
  1928. #endif
  1929.  
  1930. #ifndef SOM_Module_OpenDoc_Foci_defined
  1931. #include <Foci.xh>
  1932. #endif
  1933.  
  1934. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  1935. #include <StdTypes.xh>
  1936. #endif
  1937.  
  1938. #ifndef SOM_ODTypeList_xh
  1939. #include <TypeList.xh>
  1940. #endif
  1941.  
  1942. #ifndef SOM_ODTypeListIterator_xh
  1943. #include <TypLsItr.xh>
  1944. #endif
  1945.  
  1946. #ifndef SOM_ODStorageUnit_xh
  1947. #include <StorageU.xh>
  1948. #endif
  1949.  
  1950. #ifndef SOM_ODPart_xh
  1951. #include <Part.xh>
  1952. #endif
  1953.  
  1954. #ifndef SOM_ODFrame_xh
  1955. #include <Frame.xh>
  1956. #endif
  1957.  
  1958. #ifndef SOM_ODFacet_xh
  1959. #include <Facet.xh>
  1960. #endif
  1961.  
  1962. #ifndef SOM_ODBaseLink_xh
  1963. #include <LinkB.xh>
  1964. #endif
  1965.  
  1966. #ifndef SOM_ODBaseLinkSource_xh
  1967. #include <LinkSrcB.xh>
  1968. #endif
  1969.  
  1970. #ifndef SOM_ODBinding_xh
  1971. #include <ODBindng.xh>
  1972. #endif
  1973.  
  1974. #ifndef SOM_ODTranslation_xh
  1975. #include <Translt.xh>
  1976. #endif
  1977.  
  1978. #ifndef SOM_ODWindowState_xh
  1979. #include <WinStat.xh>
  1980. #endif
  1981.  
  1982. #ifndef _BINDNGH_
  1983. #include <BindngH.h>
  1984. #endif
  1985.  
  1986. #ifndef _BNDNSUTL_
  1987. #include <BndNSUtl.h>
  1988. #endif
  1989.  
  1990. #ifndef SOM_ODSession_xh
  1991. #include <ODSessn.xh>
  1992. #endif
  1993.  
  1994. #ifndef SOM_ODArbitrator_xh
  1995. #include <Arbitrat.xh>
  1996. #endif
  1997.  
  1998. #ifndef SOM_ODDispatcher_xh
  1999. #include <Disptch.xh>
  2000. #endif
  2001.  
  2002. #ifndef _ODUTILS_
  2003. #include <ODUtils.h>
  2004. #endif
  2005.  
  2006. #ifndef _PASCLSTR_
  2007. #include <PasclStr.h>
  2008. #endif
  2009.  
  2010. #ifndef _ISOSTR_
  2011. #include <ISOStr.h>
  2012. #endif
  2013.  
  2014. #ifndef _DOCUTILS_
  2015. #include <DocUtils.h>
  2016. #endif
  2017.  
  2018. #ifndef _ODMEMORY_
  2019. #include <ODMemory.h>
  2020. #endif
  2021.  
  2022. #ifdef __SC__
  2023. #ifndef __PACKAGES__
  2024. #include <Packages.h>
  2025. #endif
  2026. #else
  2027. #ifndef __TEXTUTILS__
  2028. #include <TextUtils.h>
  2029. #endif
  2030. #endif
  2031.  
  2032. #ifndef __STRING__
  2033. #include <String.h>
  2034. #endif
  2035.  
  2036. #ifndef __GESTALTEQU__
  2037. #include <GestaltEqu.h>
  2038. #endif
  2039.  
  2040. #ifndef __DIALOGS__
  2041. #include <Dialogs.h>
  2042. #endif
  2043.  
  2044. #ifndef __TOOLUTILS__
  2045. #include <ToolUtils.h>
  2046. #endif
  2047.  
  2048. #ifndef __FONTS__
  2049. #include <Fonts.h>
  2050. #endif
  2051.  
  2052. #ifndef __CONTROLS__
  2053. #include <Controls.h>
  2054. #endif
  2055.  
  2056. #ifndef __RESOURCES__
  2057. #include <Resources.h>
  2058. #endif
  2059.  
  2060. #ifndef _TRANSUTL_
  2061. #include <TransUtl.h>
  2062. #endif
  2063.  
  2064. #ifndef __LISTS__
  2065. #include <Lists.h>
  2066. #endif
  2067.  
  2068. #ifndef __PALETTES__
  2069. #include <Palettes.h>
  2070. #endif
  2071.  
  2072. #ifndef _STORUTIL_
  2073. #include <StorUtil.h>
  2074. #endif
  2075.  
  2076. #ifndef _EDITRSET_
  2077. #include <EditrSet.h>
  2078. #endif
  2079.  
  2080. #ifndef _STDTYPIO_
  2081. #include <StdTypIO.h>
  2082. #endif
  2083.  
  2084. #ifndef _TEMPOBJ_
  2085. #include <TempObj.h>
  2086. #endif
  2087.  
  2088. #ifndef _ORDCOLL_
  2089. #include "OrdColl.h"
  2090. #endif
  2091.  
  2092. #ifndef SOM_ODStorageSystem_xh
  2093. #include "ODStor.xh"
  2094. #endif
  2095.  
  2096. #pragma segment Info
  2097.  
  2098. #if ODDebug
  2099. #define ODDebugLinkDlgs 0
  2100. #else
  2101. #define ODDebugLinkDlgs 0
  2102. #endif
  2103.  
  2104. //==============================================================================
  2105. // Global variables
  2106. //==============================================================================
  2107.  
  2108. // Use a global to pass the current session to the LinkFilterProc
  2109. // Globals are per process, and there is only one session per process.
  2110. static ODSession* gSession = kODNULL;
  2111.  
  2112. static ODName* gKindName = kODNULL;
  2113. static ODName* gEditorName = kODNULL;
  2114. static ODName* gEmbeddedEditorName = kODNULL;
  2115.  
  2116. //==============================================================================
  2117. // Constants
  2118. //==============================================================================
  2119.  
  2120. const Boolean kNoDefaultButton = kODFalse;
  2121.  
  2122. const short kButtonFrameInset = -4;
  2123.  
  2124. const short kControlInactive = 255;
  2125. const short kControlActive = 0;
  2126.  
  2127. // Constants used in list manager calls
  2128. const Boolean kDoDraw = true;
  2129. const Boolean kNoGrow = false;
  2130. const Boolean kIncludeScrollBar = true;
  2131.  
  2132. // Key codes
  2133. // <eeh> moved to DlogUtil.h
  2134. // const char kEnterKey         = 0x03;
  2135. // const char kReturnKey                = 0x0D;
  2136. // const char kEscapeKey                = 0x1B;
  2137. // const char kUpArrowKey               = 0x1E;
  2138. // const char kDownArrowKey     = 0x1F;
  2139.  
  2140. //==============================================================================
  2141. // Scalar types
  2142. //==============================================================================
  2143. typedef char ODHandleState;
  2144.  
  2145. //==============================================================================
  2146. // Function declarations
  2147. //==============================================================================
  2148. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name);
  2149.  
  2150. ODStatic void SetDateTimeStrings(
  2151.                                         ODULong         dateTime,
  2152.                                         Str255          dateString,
  2153.                                         Str255          timeString);
  2154.  
  2155. ODStatic void InitItemActive(
  2156.                                         DialogPtr       dlg,
  2157.                                         short           itemNumber,
  2158.                                         UserItemUPP     itemUPP,
  2159.                                         ODBoolean       itemActive);
  2160.  
  2161. ODStatic pascal void DrawDeactivePICTItem(DialogPtr theDialog, short theItem);
  2162.  
  2163. ODStatic ODBoolean DraftIsReadOnly(Environment* ev, ODStorageUnit* su);
  2164.  
  2165. ODStatic void SetControlActive(
  2166.                                         DialogPtr       dlg,
  2167.                                         short           itemNumber,
  2168.                                         ODBoolean       itemActive);
  2169.  
  2170. ODStatic ODType BestContentKind(ODStorageUnit* contentSU);
  2171.  
  2172. ODStatic pascal void DrawKindName(DialogPtr dialog, SInt16 item);
  2173. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item);
  2174.  
  2175. ODStatic void ResetEditorPopup(ODTypeList* kindList,
  2176.                                                                 ODUShort kindIndex,
  2177.                                                                 ODTypeList* translateToList,
  2178.                                                                 ODUShort translateToIndex,
  2179.                                                                 EditorSet* editorList,
  2180.                                                                 MenuHandle editorMenu,
  2181.                                                                 ControlHandle popupCtlHndl,
  2182.                                                                 ODSession* session);
  2183.  
  2184. static pascal Boolean
  2185. PasteAsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit);
  2186.  
  2187. ODStatic void SetPopupControlValue(ControlHandle popupControlHandle, short itemValue);
  2188.  
  2189. //------------------------------------------------------------------------------
  2190. // DisposeGlobalODNameAndZeroPtr
  2191. //------------------------------------------------------------------------------
  2192. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name)
  2193. {
  2194.         if (*name)
  2195.         {
  2196.                 // simple way to force deletion of old name value without knowing
  2197.                 // that DisposeIText is the right way to destroy an ODName:
  2198.                 TempODName tempName = *name;
  2199.                 *name = kODNULL;
  2200.         }
  2201. }
  2202.  
  2203. //------------------------------------------------------------------------------
  2204. // InitLinkDialogs
  2205. //------------------------------------------------------------------------------
  2206. void InitLinkDialogs(ODSession* session)
  2207. {
  2208.         gSession = session;
  2209. }
  2210.  
  2211. //------------------------------------------------------------------------------
  2212. // DrawEditorName
  2213. //------------------------------------------------------------------------------
  2214.  
  2215. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item)
  2216. {
  2217.         short                   itemType;
  2218.         Handle                  itemHandle;
  2219.         Rect                    itemRect;
  2220.  
  2221.         GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  2222.  
  2223.         if ( gEditorName )
  2224.                 DrawITextInDlogBox(gEditorName, &itemRect, dialog, kODTrue);
  2225. }
  2226.  
  2227. //------------------------------------------------------------------------------
  2228. // DrawEmbeddedEditorName
  2229. //------------------------------------------------------------------------------
  2230.  
  2231. ODStatic pascal void DrawEmbeddedEditorName(DialogPtr dialog, SInt16 item)
  2232. {
  2233.         short                   itemType;
  2234.         Handle                  itemHandle;
  2235.         Rect                    itemRect;
  2236.  
  2237.         GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  2238.  
  2239.         if ( gEmbeddedEditorName )
  2240.                 DrawITextInDlogBox(gEmbeddedEditorName, &itemRect, dialog, kODTrue);
  2241. }
  2242.  
  2243. //------------------------------------------------------------------------------
  2244. // GetSelectedType
  2245. //------------------------------------------------------------------------------
  2246. // $$$$$ Should be replaced by GetThisKindFromList in InfoUtil.h
  2247.  
  2248. ODStatic ODType GetSelectedType(ODTypeList* typeList, ODSShort typeIndex)
  2249. {
  2250.         Environment*            ev = somGetGlobalEnvironment();
  2251.         ODType                          type = kODNULL;
  2252.         ODTypeListIterator*     iter = typeList->CreateTypeListIterator(ev);
  2253.  
  2254.         for ( type = iter->First(ev);
  2255.                   (--typeIndex > 0) && iter->IsNotComplete(ev);
  2256.                   type = iter->Next(ev) )
  2257.         {
  2258.                 ODDisposePtr(type);
  2259.                 type = kODNULL;
  2260.         }
  2261.  
  2262.         delete iter;
  2263.  
  2264.         return type;
  2265. }
  2266.  
  2267. //------------------------------------------------------------------------------
  2268. // GetSelectedEditor
  2269. //------------------------------------------------------------------------------
  2270.  
  2271. ODStatic ODEditor GetSelectedEditor(EditorSet* editorList, ODSShort editorIndex)
  2272. {
  2273.         ODEditor                        editor;
  2274.         EditorSetIterator*      iter = editorList->CreateIterator();
  2275.  
  2276.         for ( editor = iter->First();
  2277.                   (--editorIndex > 0) && iter->IsNotComplete();
  2278.                   editor = iter->Next() )
  2279.         {
  2280.         }
  2281.  
  2282.         delete iter;
  2283.  
  2284.         if ( editor != kODNULL )
  2285.                 editor = ODISOStrFromCStr((char *) editor);
  2286.  
  2287.         return editor;
  2288. }
  2289.  
  2290. //------------------------------------------------------------------------------
  2291. // EnableKindPopupItems
  2292. //------------------------------------------------------------------------------
  2293.  
  2294. ODStatic void EnableKindPopupItems(
  2295.                                         ODBoolean                       forMerge,
  2296.                                         ODTypeList*                     typeList,
  2297.                                         ODTypeList*                     translateList,
  2298.                                         ODSShort                        translationIndex,
  2299.                                         MenuHandle                      kindMenu,
  2300.                                         ODEditor                        editor,
  2301.                                         ODNameSpaceManager*     nsm)
  2302. {
  2303.         Environment* ev = somGetGlobalEnvironment();
  2304.  
  2305.         ODUShort item = EnableTypesInMenu(typeList, kindMenu, forMerge ? editor : kODNULL, nsm);
  2306.  
  2307.         // If a translation choice is present in the popup, enable it if appropriate;
  2308.         if ( translationIndex != 0 )
  2309.         {
  2310.                 TempODType translationKind = GetSelectedType(translateList, translationIndex);
  2311.  
  2312.                 if ( !forMerge || EditorSupportsKind(nsm, editor, translationKind) )
  2313.                         EnableItem(kindMenu, ++item);
  2314.                 else
  2315.                         DisableItem(kindMenu, ++item);
  2316.         }
  2317.  
  2318.         // Enable the "Translate to╔" item in the kind popup if translation is possible
  2319.         if ( translateList->Count(ev) > 0 )
  2320.                 EnableItem(kindMenu, ++item);
  2321.         else
  2322.                 DisableItem(kindMenu, ++item);
  2323. }
  2324.  
  2325. //------------------------------------------------------------------------------
  2326. // EnablePasteAsOkButton
  2327. //------------------------------------------------------------------------------
  2328.  
  2329. ODStatic void EnablePasteAsOkButton(DialogPtr dlog, MenuHandle kindMenu)
  2330. {
  2331.         Environment*    ev = somGetGlobalEnvironment();
  2332.         short                   itemType;
  2333.         Handle                  itemHandle;
  2334.         Rect                    itemRect;
  2335.         ODSShort                kindItemSelected;
  2336.         ODBoolean               shouldBeEnabled;
  2337.  
  2338.         GetDialogItem(dlog, kPasteAsKindPopup, &itemType, &itemHandle, &itemRect);
  2339.         ASSERT_CONTROL_ITEM(itemType);
  2340.         kindItemSelected = (ODSShort) GetControlValue((ControlHandle)itemHandle);
  2341.  
  2342.         // Only the first 31 items of a menu may be disabled
  2343.         if ( kindItemSelected > 31 )
  2344.                 shouldBeEnabled = kODTrue;
  2345.         else
  2346.                 // BitTst numbers the bits hi to low
  2347.                 shouldBeEnabled = BitTst(&(**kindMenu).enableFlags, 31-kindItemSelected);
  2348.  
  2349.         EnableOkButton(dlog, shouldBeEnabled);
  2350. }
  2351.  
  2352. //------------------------------------------------------------------------------
  2353. // BestMergeKindSetting
  2354. //------------------------------------------------------------------------------
  2355.  
  2356. ODStatic ODSShort BestMergeKindSetting(
  2357.                                         ODTypeList*                     kinds,
  2358.                                         ODType                          bestKind,
  2359.                                         ODEditor                        editor,
  2360.                                         ODNameSpaceManager*     nsm)
  2361. {
  2362.         if ( bestKind && EditorSupportsKind(nsm, editor, bestKind) )
  2363.                 return IndexOfKindInList(kinds, bestKind);
  2364.  
  2365.         Environment*            ev = somGetGlobalEnvironment();
  2366.         ODSShort                        kindItem = 0;           // Default in case none are supported
  2367.  
  2368.         ODTypeListIterator*     iter = kinds->CreateTypeListIterator(ev);
  2369.  
  2370.         ODType                          type;
  2371.         ODSShort                        i;
  2372.         for ( type = iter->First(ev), i = 1;
  2373.                   iter->IsNotComplete(ev);
  2374.                   type = iter->Next(ev), ++i )
  2375.         {
  2376.                 ODBoolean supports = EditorSupportsKind(nsm, editor, type);
  2377.                 ODDisposePtr(type);
  2378.                 if ( supports )
  2379.                 {
  2380.                         kindItem = i;
  2381.                         break;
  2382.                 }
  2383.         }
  2384.  
  2385.         delete iter;
  2386.  
  2387.         return kindItem;
  2388. }
  2389.  
  2390. //------------------------------------------------------------------------------
  2391. // InitialViewSelection
  2392. //------------------------------------------------------------------------------
  2393. ODStatic void InitialViewSelection(DialogPtr dlg, ODTypeToken viewType, ODSession* session)
  2394. {
  2395.         short           itemType;
  2396.         Handle          itemHandle;
  2397.         Rect            itemRect;
  2398.         ODSShort        viewItem;
  2399.  
  2400.         Environment* ev = somGetGlobalEnvironment();
  2401.  
  2402.         if (viewType == session->Tokenize(ev, kODViewAsFrame))
  2403.                 viewItem = kODPasteAsFrameMenuItem;
  2404.         else if (viewType == session->Tokenize(ev, kODViewAsLargeIcon))
  2405.                 viewItem = kODPasteAsLargeIconMenuItem;
  2406.         else if (viewType == session->Tokenize(ev, kODViewAsSmallIcon))
  2407.                 viewItem = kODPasteAsSmallIconMenuItem;
  2408.         else if (viewType == session->Tokenize(ev, kODViewAsThumbnail))
  2409.                 viewItem = kODPasteAsThumbnailMenuItem;
  2410.         else
  2411.                 viewItem = kODPasteAsFrameMenuItem;
  2412.  
  2413.         GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  2414.         ASSERT_CONTROL_ITEM(itemType);
  2415.         SetControlValue((ControlHandle)itemHandle, viewItem);
  2416. }
  2417.  
  2418. //------------------------------------------------------------------------------
  2419. // GetViewSelected
  2420. //------------------------------------------------------------------------------
  2421. ODStatic ODTypeToken GetViewSelected(DialogPtr dlg, ODSession* session)
  2422. {
  2423.         short           itemType;
  2424.         Handle          itemHandle;
  2425.         Rect            itemRect;
  2426.  
  2427.         Environment* ev = somGetGlobalEnvironment();
  2428.  
  2429.         GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  2430.         ASSERT_CONTROL_ITEM(itemType);
  2431.         ODSShort viewItem = (ODSShort) GetControlValue((ControlHandle)itemHandle);
  2432.         ODType viewAs;
  2433.         switch ( viewItem )
  2434.         {
  2435.         case kODPasteAsLargeIconMenuItem:
  2436.                         viewAs = kODViewAsLargeIcon;
  2437.                         break;
  2438.         case kODPasteAsSmallIconMenuItem:
  2439.                         viewAs = kODViewAsSmallIcon;
  2440.                         break;
  2441.         case kODPasteAsThumbnailMenuItem:
  2442.                         viewAs = kODViewAsThumbnail;
  2443.                         break;
  2444.         default:
  2445.                         viewAs = kODViewAsFrame;
  2446.                         break;
  2447.         }
  2448.  
  2449.         return session->Tokenize(ev, viewAs);
  2450. }
  2451.  
  2452. //------------------------------------------------------------------------------
  2453. // HaveColorQuickdraw
  2454. //------------------------------------------------------------------------------
  2455. ODStatic ODBoolean HaveColorQuickdraw()
  2456. {
  2457.         long response;
  2458.  
  2459.         Gestalt(gestaltQuickdrawFeatures, &response);
  2460.  
  2461.         /* check if Color QuickDraw is available */
  2462.         return BitTst(&response, 31-gestaltHasColor);
  2463. }
  2464.  
  2465. //------------------------------------------------------------------------------
  2466. // EnableDialogItem
  2467. //------------------------------------------------------------------------------
  2468. ODStatic void EnableDialogItem(DialogPtr dlg, short itemNumber, ODBoolean enable)
  2469. {
  2470.         short           itemType;
  2471.         Handle          itemHandle;
  2472.         Rect            itemRect;
  2473.  
  2474.         GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  2475.         if ( enable )
  2476.                 itemType &= ~itemDisable;
  2477.         else
  2478.                 itemType |= itemDisable;
  2479.         SetDialogItem(dlg, itemNumber, itemType, itemHandle, &itemRect);
  2480. }
  2481.  
  2482. //------------------------------------------------------------------------------
  2483. // InvalDialogItem
  2484. //------------------------------------------------------------------------------
  2485. ODStatic void InvalDialogItem(DialogPtr dlg, short itemNumber)
  2486. {
  2487.         short           itemType;
  2488.         Handle          itemHandle;
  2489.         Rect            itemRect;
  2490.         WindowPtr       savePort;
  2491.  
  2492.         GetPort(&savePort);
  2493.         SetPort(dlg);
  2494.         GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  2495.         InvalRect(&itemRect);
  2496.         SetPort(savePort);
  2497. }
  2498.  
  2499. //------------------------------------------------------------------------------
  2500. // SetPopupControlValue
  2501. //------------------------------------------------------------------------------
  2502. ODStatic void SetPopupControlValue(ControlHandle popupControlHandle, short itemValue)
  2503. {
  2504.         // The resource file must be in the chain in order for the popup to redraw.
  2505.         CUsingLibraryResources r;
  2506.         SetControlValue(popupControlHandle, itemValue);
  2507. }
  2508.  
  2509. //------------------------------------------------------------------------------
  2510. // SetupControlItem
  2511. //------------------------------------------------------------------------------
  2512. ODStatic void SetupControlItem(
  2513.                                         DialogPtr       dlg,
  2514.                                         short           itemNumber,
  2515.                                         short           itemValue,
  2516.                                         ODBoolean       itemActive)
  2517. {
  2518.         short           itemType;
  2519.         Handle          itemHandle;
  2520.         Rect            itemRect;
  2521.  
  2522.         GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  2523.         ASSERT_CONTROL_ITEM(itemType);
  2524.         SetControlValue((ControlHandle)itemHandle, itemActive? itemValue : 0);
  2525.         HiliteControl((ControlHandle)itemHandle, itemActive ? kControlActive : kControlInactive);
  2526. }
  2527.  
  2528. //------------------------------------------------------------------------------
  2529. // InactivateEmbedAsPopup
  2530. //------------------------------------------------------------------------------
  2531.  
  2532. ODStatic void InactivateEmbedAsPopup(DialogPtr dlg)
  2533. // Set clipping to just the display area of the popup so the radio button
  2534. // label isn't dimmed.
  2535. {
  2536.         short           aItem;
  2537.         Handle          aHandle;
  2538.         Handle          embedPopupCntlHandle;
  2539.         Rect            aRect;
  2540.         RgnHandle       embedTextRgn = ODNewRgn();
  2541.         RgnHandle       embedPopupRgn = ODNewRgn();
  2542.         RgnHandle       clipRgn = ODNewRgn();
  2543.  
  2544.         GetDialogItem(dlg, kPasteAsEmbedRadioBtn, &aItem, &aHandle, &aRect);
  2545.         RectRgn(embedTextRgn,&aRect);
  2546.  
  2547.         GetDialogItem(dlg, kPasteAsEmbedPopup, &aItem, &embedPopupCntlHandle, &aRect);
  2548.         RectRgn(embedPopupRgn,&aRect);
  2549.  
  2550.         GetClip(clipRgn);
  2551.         DiffRgn(embedPopupRgn, embedTextRgn, embedPopupRgn);
  2552.         SetClip(embedPopupRgn);
  2553.         HiliteControl((ControlHandle)embedPopupCntlHandle, kControlInactive);
  2554.         SetClip(clipRgn);
  2555.  
  2556.         ODDisposeHandle((Handle)clipRgn);
  2557.         ODDisposeHandle((Handle)embedPopupRgn);
  2558.         ODDisposeHandle((Handle)embedTextRgn);
  2559. }
  2560.  
  2561. //------------------------------------------------------------------------------
  2562. // ClipOutRect
  2563. //------------------------------------------------------------------------------
  2564.  
  2565. ODStatic RgnHandle ClipOutRect(Rect* r)
  2566. {
  2567.         RgnHandle       saveRgn = ODNewRgn();
  2568.         RgnHandle       rectRgn = ODNewRgn();
  2569.         RgnHandle       clipRgn = ODNewRgn();
  2570.  
  2571.         GetClip(saveRgn);
  2572.  
  2573.         RectRgn(rectRgn, r);
  2574.  
  2575.         GetClip(clipRgn);
  2576.         DiffRgn(clipRgn, rectRgn, clipRgn);
  2577.         SetClip(clipRgn);
  2578.  
  2579.         ODDisposeHandle((Handle)rectRgn);
  2580.         ODDisposeHandle((Handle)clipRgn);
  2581.  
  2582.         return saveRgn;
  2583. }
  2584.  
  2585. //------------------------------------------------------------------------------
  2586. // SetAutomaticUpdateControls
  2587. //------------------------------------------------------------------------------
  2588. ODStatic void SetAutomaticUpdateControls(DialogPtr dlg, ODBoolean autoUpdateSetting)
  2589. {
  2590.         short   itemType;
  2591.         Handle  itemHandle;
  2592.         Rect    itemRect;
  2593.  
  2594.         GetDialogItem(dlg, kPasteAsAutomaticRadioBtn, &itemType, &itemHandle, &itemRect);
  2595.         ASSERT_CONTROL_ITEM(itemType);
  2596.         SetControlValue((ControlHandle)itemHandle, autoUpdateSetting);
  2597.         GetDialogItem(dlg, kPasteAsManualRadioBtn, &itemType, &itemHandle, &itemRect);
  2598.         ASSERT_CONTROL_ITEM(itemType);
  2599.         SetControlValue((ControlHandle)itemHandle, !autoUpdateSetting);
  2600. }
  2601.  
  2602. //------------------------------------------------------------------------------
  2603. // SetMergeEmbedControls
  2604. //------------------------------------------------------------------------------
  2605. ODStatic void SetMergeEmbedControls(DialogPtr dlg, ODBoolean mergeSetting)
  2606. {
  2607.         short   itemType;
  2608.         Handle  itemHandle;
  2609.         Rect    itemRect;
  2610.  
  2611.         CUsingLibraryResources r;       // Necessary to change embed popup
  2612.  
  2613.         GetDialogItem(dlg, kPasteAsMergeRadioBtn, &itemType, &itemHandle, &itemRect);
  2614.         ASSERT_CONTROL_ITEM(itemType);
  2615.         SetControlValue((ControlHandle)itemHandle, mergeSetting);
  2616.  
  2617.         GetDialogItem(dlg, kPasteAsEmbedRadioBtn, &itemType, &itemHandle, &itemRect);
  2618.         ASSERT_CONTROL_ITEM(itemType);
  2619.         SetControlValue((ControlHandle)itemHandle, !mergeSetting);
  2620.  
  2621.         if ( mergeSetting )
  2622.         {
  2623.                 InactivateEmbedAsPopup(dlg);
  2624.         }
  2625.         else
  2626.         {
  2627.                 GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  2628.                 ASSERT_CONTROL_ITEM(itemType);
  2629.                 HiliteControl((ControlHandle)itemHandle, kControlActive);
  2630.         }
  2631. }
  2632.  
  2633. //------------------------------------------------------------------------------
  2634. // GetIndexedElement
  2635. //------------------------------------------------------------------------------
  2636.  
  2637. ODStatic ODULong GetIndexedElement(OrderedCollection* translateFromList, ODULong translationIndex)
  2638. {
  2639.         OrderedCollectionIterator* oci = translateFromList->CreateIterator();
  2640.  
  2641.         ODULong elem = 0;
  2642.  
  2643.         for (   elem = (ODULong) oci->First();
  2644.                         oci->IsNotComplete();
  2645.                         elem = (ODULong) oci->Next() )
  2646.         {
  2647.                 if ( --translationIndex == 0 )
  2648.                         break;
  2649.         }
  2650.  
  2651.         ODDeleteObject(oci);
  2652.  
  2653.         return elem;
  2654. }
  2655.  
  2656. //------------------------------------------------------------------------------
  2657. // GetOriginalDraft
  2658. //------------------------------------------------------------------------------
  2659. // Returns 0 if the original draft is unknown.  This is the case when content
  2660. // was placed in the draft without cloning.  This code is dependent on properties
  2661. // created by the argument storage unit's container suite.
  2662.  
  2663.  
  2664. static ODULong GetOriginalDraft(Environment* ev, ODDraft* draft)
  2665. {
  2666.         TempODStorageUnit       draftProperties = draft->AcquireDraftProperties(ev);
  2667.         return ODGetULongProp(ev, draftProperties, kODPropOriginalDraft, kODULong);
  2668. }
  2669.  
  2670. //------------------------------------------------------------------------------
  2671. // SUClonedFromDraft
  2672. //------------------------------------------------------------------------------
  2673. // Returns kODTrue is the argument storage unit is the clone of a storage unit
  2674. // from the argument draft.  This code is dependent on properties created by
  2675. // the argument storage unit's container suite.
  2676.  
  2677. static ODBoolean SUClonedFromDraft(Environment* ev,
  2678.                         ODStorageUnit* su,
  2679.                         ODDraft* draft)
  2680. {
  2681.         return ((ODDraft*)GetOriginalDraft(ev, su->GetDraft(ev)) == draft &&
  2682.                         su->Exists(ev, kODPropOriginalID, kODULong, 0));
  2683. }
  2684.  
  2685. //------------------------------------------------------------------------------
  2686. // DeactivateModalDialog
  2687. //------------------------------------------------------------------------------
  2688.  
  2689. ODStatic void DeactivateModalDialog(ModalFilterUPP filterProc)
  2690. {
  2691.         DialogPtr dialog = (DialogPtr) FrontWindow();
  2692.  
  2693.         if ( dialog )
  2694.         {
  2695.                 EventRecord event;
  2696.  
  2697.                 event.what = activateEvt;
  2698.                 event.message = (long) dialog;
  2699.                 event.modifiers = 0;
  2700.  
  2701.                 CallModalFilterProc(filterProc, dialog, &event, 0);
  2702.         }
  2703. }
  2704.  
  2705. //------------------------------------------------------------------------------
  2706. // PasteAsFilterProc
  2707. //------------------------------------------------------------------------------
  2708.  
  2709. static pascal Boolean
  2710. PasteAsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
  2711. {
  2712.         // If the event is a deactivate event, the ok button must be deactivated
  2713.         // before the surrounding outline is drawn so it is drawn dim.
  2714.         ODBoolean rslt = ODButtonKeyFilterProc(dialog,event,itemHit);
  2715.  
  2716.         if ( event->what == activateEvt )
  2717.         {
  2718.                 ODOutlineDefaultButtonDrawProc(dialog, kPasteAsDefaultButtonItem);
  2719.         }
  2720.  
  2721.         return rslt;
  2722. }
  2723.  
  2724. //------------------------------------------------------------------------------
  2725. // ShowPasteAsDialog
  2726. //------------------------------------------------------------------------------
  2727.  
  2728. ODBoolean ShowPasteAsDialog(
  2729.                                 ODBoolean                               canPasteLink,
  2730.                                 ODPasteAsMergeSetting   mergeSetting,
  2731.                                 ODBoolean                               isMove,
  2732.                                 ODStorageUnit*                  contentSU,
  2733.                                 ODFacet*                                facet,
  2734.                                 ODTypeToken                             viewType,
  2735.                                 ODPasteAsResult*                result)
  2736.  
  2737. {
  2738.         Environment* ev = somGetGlobalEnvironment();
  2739.  
  2740.         WindowPtr       savePort;                                                       ODVolatile(savePort);
  2741.         GetPort(&savePort);
  2742.  
  2743.         short           itemHit = kPasteAsCancelBtn;
  2744.         short           itemType;
  2745.         DialogPtr       dlg = kODNULL;                                          ODVolatile(dlg);
  2746.         Handle          itemHandle;
  2747.         Rect            itemRect;
  2748.         Rect            kindPopupRect;
  2749.         Rect            editorPopupRect;
  2750.         short           kindItemSelected;
  2751.         short           kindItemOthers;
  2752.         short           kindItemCurrent;
  2753.         ODBoolean       kindPopupHasNoTranslationKind = kODTrue;
  2754.         ODUShort        translationIndex = 0;
  2755.  
  2756.         ODSLong         refSaved;
  2757.         OSErr           resErr;
  2758.  
  2759.         ODBoolean       userChangedKind = kODFalse;
  2760.  
  2761.         ControlHandle kindPopupControlHandle;
  2762.         ControlHandle editorPopupControlHandle;
  2763.  
  2764.         ODEditor mergeEditorID = kODNULL;                               ODVolatile(mergeEditorID);
  2765.         ODEditor embedEditorID = kODNULL;                               ODVolatile(embedEditorID);
  2766.         ODEditor preferredEditorID = kODNULL;                   ODVolatile(preferredEditorID);
  2767.  
  2768.         EditorSet* editorList = kODNULL;                                ODVolatile(editorList);
  2769.  
  2770.         ODSShort bestKindIndex = 1;
  2771.         ODSShort bestMergeKind = 1;
  2772.  
  2773.         ODType bestKind = kODNULL;                                              ODVolatile(bestKind);
  2774.         ODTypeList*     kindList = kODNULL;                                     ODVolatile(kindList);
  2775.         ODTypeList*     translateToList = kODNULL;                      ODVolatile(translateToList);
  2776.         OrderedCollection* translateFromList = kODNULL; ODVolatile(translateFromList);
  2777.  
  2778.         MenuHandle kindMenu = kODNULL;                                  ODVolatile(kindMenu);
  2779.         MenuHandle editorMenu = kODNULL;                                ODVolatile(editorMenu);
  2780.  
  2781.         UserItemUPP DrawBoxItemUPP = kODNULL;                   ODVolatile(DrawBoxItemUPP);
  2782.         UserItemUPP DrawDeactiveItemUPP = kODNULL;              ODVolatile(DrawDeactiveItemUPP);
  2783.         UserItemUPP     DrawEditorNameUPP = kODNULL;            ODVolatile(DrawEditorNameUPP);
  2784.         UserItemUPP     DrawEmbeddedEditorNameUPP = kODNULL;ODVolatile(DrawEmbeddedEditorNameUPP);
  2785.         UserItemUPP     DrawKindNameUPP = kODNULL;                      ODVolatile(DrawKindNameUPP);
  2786.  
  2787.         ModalFilterUPP modalFilter = kODNULL;                   ODVolatile(modalFilter);
  2788.  
  2789.         if ( canPasteLink )
  2790.                 canPasteLink = contentSU->Exists(ev, kODPropLinkSpec, (ODValueType) kODLinkSpec, 0);
  2791.  
  2792.         result->pasteLinkSetting = (!isMove) && canPasteLink;
  2793.         result->autoUpdateSetting = kODTrue;
  2794.         result->selectedKind = (ODType) kODNULL;
  2795.         result->translateKind = (ODType) kODNULL;
  2796.         result->editor = kODNoEditor;
  2797.  
  2798.         ODSession* session;
  2799.         {
  2800.                 TempODPart part = facet->GetFrame(ev)->AcquirePart(ev);
  2801.                 session = part->GetStorageUnit(ev)->GetSession(ev);
  2802.         }
  2803.  
  2804.         TRY
  2805.                 ODBinding* binding = session->GetBinding(ev);
  2806.                 ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  2807.  
  2808.                 session->GetWindowState(ev)->DeactivateFrontWindows(ev);
  2809.  
  2810.                 { TempODPart part = facet->GetFrame(ev)->AcquirePart(ev);
  2811.                   mergeEditorID = GetCurrentEditorForPart(part);
  2812.                 }
  2813.  
  2814.                 kindList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  2815.                 ContentValueTypes(contentSU, kindList);
  2816.  
  2817.                 // Now get all possible translations from the available kinds
  2818.                 translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  2819.                 translateFromList = new OrderedCollection;
  2820.                 TranslateValueTypes(kindList, translateToList, translateFromList, session);
  2821.  
  2822.                 refSaved = BeginUsingLibraryResources();
  2823.                 kindMenu = GetMenu(kPasteAsKindPopupMenu);
  2824.                 resErr = ResError();
  2825.                 EndUsingLibraryResources(refSaved);
  2826.                 THROW_IF_NULL(kindMenu, resErr ? resErr : resNotFound);
  2827.  
  2828.                 AddTypesToMenu(kindList, kindMenu, session);
  2829.                 kindItemOthers = kindList->Count(ev) + 1;
  2830.  
  2831.                 ODBoolean canMerge = (mergeSetting != kODPasteAsEmbedOnly);
  2832.                 ODBoolean canEmbed = (mergeSetting != kODPasteAsMergeOnly);
  2833.  
  2834.                 result->mergeSetting = (mergeSetting == kODPasteAsMerge) || (mergeSetting == kODPasteAsMergeOnly);
  2835.  
  2836.                 {
  2837.                         CUsingLibraryResources r;
  2838.                         dlg = ODGetNewDialog(ev, kPasteAsDlgID, session, kNoDefaultButton);
  2839.                         THROW_IF_NULL(dlg);
  2840.                         SetPort(dlg);
  2841.                         SetDialogTextStyle(dlg, kPasteAsDlgID, smCurrentScript);
  2842.                 }
  2843.  
  2844.                 /* Horizontal line needs to be drawn */
  2845.                 GetDialogItem(dlg, kPasteAsHorizSep, &itemHit, &itemHandle, &itemRect);
  2846.                 DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  2847.                 SetDialogItem(dlg, kPasteAsHorizSep, itemHit, (Handle)DrawBoxItemUPP, &itemRect);
  2848.  
  2849.                 // Set the draw routine for the default button outline item
  2850.                 GetDialogItem(dlg, kPasteAsDefaultButtonItem, &itemHit, &itemHandle, &itemRect);
  2851.                 SetDialogItem(dlg, kPasteAsDefaultButtonItem, itemHit, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  2852.  
  2853.                 // Create one UPP for all user items used to draw deactive PICTs
  2854.                 DrawDeactiveItemUPP = NewUserItemProc(DrawDeactivePICTItem);
  2855.  
  2856.                 // Initialize state of "Paste with Link" checkbox and label
  2857.                 SetupControlItem(dlg, kPasteAsLinkCheckbox, result->pasteLinkSetting, canPasteLink);
  2858.  
  2859.                 // Initialize state of "Get Updates" radio buttons and labels
  2860.                 if ( result->pasteLinkSetting)
  2861.                         HideDialogItem(dlg, kPasteAsUpdateDisabledText);
  2862.                 else
  2863.                         HideDialogItem(dlg, kPasteAsUpdateText);
  2864.  
  2865.                 SetupControlItem(dlg, kPasteAsAutomaticRadioBtn, result->autoUpdateSetting, canPasteLink);
  2866.                 SetupControlItem(dlg, kPasteAsManualRadioBtn, !result->autoUpdateSetting, canPasteLink);
  2867.  
  2868.                 // set up merge picture, radio button, and label
  2869.                 InitItemActive(dlg, kPasteAsMergePict, DrawDeactiveItemUPP, canMerge);
  2870.                 SetupControlItem(dlg, kPasteAsMergeRadioBtn, result->mergeSetting, canMerge);
  2871.  
  2872.                 // set up embed picture, radio button, and label
  2873.                 InitItemActive(dlg, kPasteAsEmbedPict, DrawDeactiveItemUPP, canEmbed);
  2874.                 SetupControlItem(dlg, kPasteAsEmbedRadioBtn, !result->mergeSetting, canEmbed);
  2875.  
  2876.                 // set up initial "Paste as:" popup selection
  2877.                 InitialViewSelection(dlg, viewType, session);
  2878.  
  2879.                 // inactivate the "Embed as:" popup if merge is initially selected
  2880.                 if ( result->mergeSetting )
  2881.                 {
  2882.                         GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  2883.                         ASSERT_CONTROL_ITEM(itemType);
  2884.                         HiliteControl((ControlHandle)itemHandle, kControlInactive);
  2885.                 }
  2886.  
  2887.                 // Determine the indices of the best kind and the best kind that can be merged
  2888.                 bestKind = BestContentKind(contentSU);
  2889.                 if ( bestKind )
  2890.                         bestKindIndex = IndexOfKindInList(kindList, bestKind);
  2891.                 if ( bestKindIndex == 0 )       // In case preferred kind property is bogus
  2892.                         bestKindIndex = 1;
  2893.  
  2894.                 bestMergeKind = BestMergeKindSetting(kindList, bestKind, mergeEditorID, nsm);
  2895.  
  2896.                 // Suppress the preferred editor if it doesn't support the preferred kind
  2897.                 preferredEditorID = ODGetISOStrProp(ev, contentSU, kODPropPreferredEditor, kODEditor, kODNULL, kODNULL);
  2898.                 if ( preferredEditorID && bestKind && !EditorSupportsKind(nsm, preferredEditorID, bestKind) )
  2899.                 {
  2900.                         ODDisposePtr((ODPtr) preferredEditorID);
  2901.                         preferredEditorID = kODNULL;
  2902.                 }
  2903.  
  2904. #if ODDebugLinkDlgs
  2905.                 somPrintf("ShowPasteAsDialog: mergeSetting = %u, best merge kind = %u\n", mergeSetting, (bestMergeKind != 0));
  2906. #endif
  2907.  
  2908.                 // Set up the Kind popup items
  2909.                 EnableKindPopupItems(result->mergeSetting, kindList, translateToList, 0, kindMenu, mergeEditorID, nsm);
  2910.                 GetDialogItem(dlg, kPasteAsKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &kindPopupRect);
  2911.                 ASSERT_CONTROL_ITEM(itemType);
  2912.                 SetControlValue(kindPopupControlHandle, result->mergeSetting ? bestMergeKind : bestKindIndex);
  2913.  
  2914.                 // Determine if the root storage unit is an existing part from the same draft
  2915.                 // as the pasting part
  2916.  
  2917.                 ODDraft* partDraft;
  2918.                 // Get the draft from the part, not the frame, because the frame's storage
  2919.                 // unit is null if non-persistent.
  2920.                 {
  2921.                         TempODPart part = facet->GetFrame(ev)->AcquirePart(ev);
  2922.                         partDraft = part->GetStorageUnit(ev)->GetDraft(ev);
  2923.                 }
  2924.                 ODBoolean contentIsPart = SUClonedFromDraft(ev, contentSU, partDraft);
  2925.  
  2926.                 // Set text of static "Kind:" label
  2927.                 DisposeGlobalODNameAndZeroPtr(&gKindName);
  2928.                 if ( bestKind && GetUserKindFromKind(nsm, bestKind, &gKindName) )
  2929.                 {
  2930.                         GetDialogItem(dlg, kPasteAsKindText, &itemType, &itemHandle, &itemRect);
  2931.                         DrawKindNameUPP = NewUserItemProc(DrawKindName);
  2932.                         SetDialogItem(dlg, kPasteAsKindText, userItem+itemDisable, (Handle) DrawKindNameUPP, &itemRect);
  2933.                 }
  2934.  
  2935.                 // inactivate the "Kind:" popup if embedding is initially selected, the operation is
  2936.                 // a move, and a cloned part is in the storage unit (not intrinsic content).
  2937.                 if ( (!result->mergeSetting) && isMove && contentIsPart )
  2938.                 {
  2939.                         HideDialogItem(dlg, kPasteAsKindPopup);
  2940.                 }
  2941.                 else
  2942.                 {
  2943.                         HideDialogItem(dlg, kPasteAsKindLabel);
  2944.                         HideDialogItem(dlg, kPasteAsKindText);
  2945.                 }
  2946.  
  2947.                 // Setup the static text for the merge editor
  2948.                 DisposeGlobalODNameAndZeroPtr(&gEditorName);
  2949.                 if ( mergeEditorID && GetUserEditorFromEditor(nsm, mergeEditorID, &gEditorName) )
  2950.                 {
  2951.                         GetDialogItem(dlg, kPasteAsEditorText, &itemType, &itemHandle, &itemRect);
  2952.                         DrawEditorNameUPP = NewUserItemProc(DrawEditorName);
  2953.                         SetDialogItem(dlg, kPasteAsEditorText, userItem+itemDisable, (Handle) DrawEditorNameUPP, &itemRect);
  2954.                 }
  2955.  
  2956.                 // Setup the static text for the embedding editor
  2957.                 // Since the contentSU will not be cloned during a move in the same document, this is a guess as to the
  2958.                 // editor actually bound to the moved frame.
  2959.                 if ( preferredEditorID )
  2960.                         embedEditorID = ODISOStrFromCStr((char *) preferredEditorID);
  2961.                 else
  2962.                         embedEditorID = binding->ChooseEditorForPart(ev, contentSU, bestKind);
  2963.  
  2964.                 DisposeGlobalODNameAndZeroPtr(&gEmbeddedEditorName);
  2965.                 if ( embedEditorID && GetUserEditorFromEditor(nsm, embedEditorID, &gEmbeddedEditorName) )
  2966.                 {
  2967.                         GetDialogItem(dlg, kPasteAsEmbedEditorText, &itemType, &itemHandle, &itemRect);
  2968.                         DrawEmbeddedEditorNameUPP = NewUserItemProc(DrawEmbeddedEditorName);
  2969.                         SetDialogItem(dlg, kPasteAsEmbedEditorText, userItem+itemDisable, (Handle) DrawEmbeddedEditorNameUPP, &itemRect);
  2970.                 }
  2971.  
  2972.                 // Setup the editor popup
  2973.                 editorList = new EditorSet;
  2974.                 editorList->InitEditorSet();
  2975.  
  2976.                 refSaved = BeginUsingLibraryResources();
  2977.                 editorMenu = GetMenu(kPasteAsEditorPopupMenu);
  2978.                 resErr = ResError();
  2979.                 EndUsingLibraryResources(refSaved);
  2980.                 THROW_IF_NULL(editorMenu, resErr ? resErr : resNotFound);
  2981.  
  2982.                 GetDialogItem(dlg, kPasteAsEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &editorPopupRect);
  2983.                 SetupEditorMenu(bestKind, editorList, editorMenu, editorPopupControlHandle, session);
  2984.  
  2985.                 if ( result->mergeSetting )
  2986.                 {
  2987.                         HideDialogItem(dlg, kPasteAsEditorPopup);
  2988.                         HideDialogItem(dlg, kPasteAsEmbedEditorText);
  2989.                 }
  2990.                 else if ( isMove && contentIsPart )
  2991.                 {
  2992.                         HideDialogItem(dlg, kPasteAsEditorPopup);
  2993.                         HideDialogItem(dlg, kPasteAsEditorText);
  2994.                 }
  2995.                 else
  2996.                 {
  2997.                         HideDialogItem(dlg, kPasteAsEditorLabel);
  2998.                         HideDialogItem(dlg, kPasteAsEditorText);
  2999.                 }
  3000.  
  3001.                 modalFilter = NewModalFilterProc(PasteAsFilterProc);
  3002.  
  3003.                 // Display the dialog
  3004.                 ShowWindow(dlg);
  3005.  
  3006.                 do {
  3007.                         // Remember the currently selected kind
  3008.                         kindItemCurrent = (ODSShort) GetControlValue(kindPopupControlHandle);
  3009.  
  3010.                         {       CUsingLibraryResources r;
  3011.                                 ModalDialog(modalFilter, &itemHit);
  3012.                         }
  3013.  
  3014.                         switch (itemHit)
  3015.                         {
  3016.                         case kPasteAsLinkCheckbox:
  3017.                                         result->pasteLinkSetting = !result->pasteLinkSetting;
  3018.                                         GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &itemRect);
  3019.                                         ASSERT_CONTROL_ITEM(itemType);
  3020.                                         SetControlValue((ControlHandle)itemHandle, result->pasteLinkSetting);
  3021.  
  3022.                                         if ( result->pasteLinkSetting )
  3023.                                         {
  3024.                                                 GetDialogItem(dlg, kPasteAsUpdateDisabledText, &itemType, &itemHandle, &itemRect);
  3025.                                                 itemRect.left += 16384;
  3026.                                                 itemRect.right += 16384;
  3027.                                                 SetDialogItem(dlg, kPasteAsUpdateDisabledText, itemType, itemHandle, &itemRect);
  3028.                                                 ShowDialogItem(dlg, kPasteAsUpdateText);
  3029.                                         }
  3030.                                         else
  3031.                                         {
  3032.                                                 GetDialogItem(dlg, kPasteAsUpdateText, &itemType, &itemHandle, &itemRect);
  3033.                                                 itemRect.left += 16384;
  3034.                                                 itemRect.right += 16384;
  3035.                                                 SetDialogItem(dlg, kPasteAsUpdateText, itemType, itemHandle, &itemRect);
  3036.                                                 ShowDialogItem(dlg, kPasteAsUpdateDisabledText);
  3037.                                         }
  3038.  
  3039.                                         SetupControlItem(dlg, kPasteAsAutomaticRadioBtn, result->autoUpdateSetting, result->pasteLinkSetting);
  3040.                                         SetupControlItem(dlg, kPasteAsManualRadioBtn, !result->autoUpdateSetting, result->pasteLinkSetting);
  3041.                                         break;
  3042.  
  3043.                         case kPasteAsAutomaticRadioBtn:
  3044.                                         result->autoUpdateSetting = kODTrue;
  3045.                                         SetAutomaticUpdateControls(dlg, result->autoUpdateSetting);
  3046.                                         break;
  3047.  
  3048.                         case kPasteAsManualRadioBtn:
  3049.                                         result->autoUpdateSetting = kODFalse;
  3050.                                         SetAutomaticUpdateControls(dlg, result->autoUpdateSetting);
  3051.                                         break;
  3052.  
  3053.                         case kPasteAsMergePict:
  3054.                         case kPasteAsMergeRadioBtn:
  3055.                                         if ( !result->mergeSetting )
  3056.                                         {
  3057.                                                 result->mergeSetting = kODTrue;
  3058.                                                 SetMergeEmbedControls(dlg, result->mergeSetting);
  3059.  
  3060.                                                 TempODType selectedKind = kODNULL;
  3061.                                                 if ( kindItemCurrent <= kindList->Count(ev) )
  3062.                                                         selectedKind = GetSelectedType(kindList, kindItemCurrent);
  3063.                                                 else
  3064.                                                         selectedKind = GetSelectedType(translateToList, translationIndex);
  3065.  
  3066.                                                 if ( !EditorSupportsKind(nsm, mergeEditorID, selectedKind) )
  3067.                                                 {
  3068.                                                         SetPopupControlValue(kindPopupControlHandle, bestMergeKind);
  3069.                                                         userChangedKind = kODFalse;     // Allow embed to automatically select best kind
  3070.                                                 }
  3071.  
  3072.                                                 EnableKindPopupItems(result->mergeSetting, kindList, translateToList, translationIndex, kindMenu, mergeEditorID, nsm);
  3073.  
  3074.                                                 if ( isMove && contentIsPart )
  3075.                                                 {
  3076.                                                         HideDialogItem(dlg, kPasteAsKindLabel);
  3077.                                                         HideDialogItem(dlg, kPasteAsKindText);
  3078.                                                         ShowDialogItem(dlg, kPasteAsKindPopup);
  3079.                                                 }
  3080.                                                 else
  3081.                                                 {
  3082.                                                         EnablePasteAsOkButton(dlg, kindMenu);
  3083.                                                 }
  3084.  
  3085.                                                 HideDialogItem(dlg, kPasteAsEditorPopup);
  3086.                                                 HideDialogItem(dlg, kPasteAsEmbedEditorText);
  3087.                                                 ShowDialogItem(dlg, kPasteAsEditorLabel);
  3088.                                                 ShowDialogItem(dlg, kPasteAsEditorText);
  3089.                                         }
  3090.                                         break;
  3091.  
  3092.                         case kPasteAsEmbedPict:
  3093.                         case kPasteAsEmbedRadioBtn:
  3094.                                         if ( result->mergeSetting )
  3095.                                         {
  3096.                                                 result->mergeSetting = kODFalse;
  3097.                                                 SetMergeEmbedControls(dlg, result->mergeSetting);
  3098.  
  3099.                                                 // If the user has not changed the kind setting, switch to the preferred kind
  3100.                                                 kindItemSelected = (ODSShort) GetControlValue(kindPopupControlHandle);
  3101.                                                 if ( !userChangedKind )
  3102.                                                 {
  3103.                                                         // Make sure item is enabled before drawing it!
  3104.                                                         EnableItem(kindMenu, bestKindIndex);
  3105.                                                         SetPopupControlValue(kindPopupControlHandle, bestKindIndex);
  3106.                                                         kindItemSelected = bestKindIndex;
  3107.                                                 }
  3108.  
  3109.                                                 // When embedding is chosen, determine the preferred editor, then enable the kind menu
  3110.                                                 ResetEditorPopup(kindList,
  3111.                                                                                 kindItemSelected,
  3112.                                                                                 translateToList,
  3113.                                                                                 translationIndex,
  3114.                                                                                 editorList,
  3115.                                                                                 editorMenu,
  3116.                                                                                 editorPopupControlHandle,
  3117.                                                                                 session);
  3118.  
  3119.                                                 // Select the preferred editor if specified
  3120.                                                 ODSShort preferredEditorItem = IndexOfEditorInList(editorList, preferredEditorID);
  3121.                                                 if ( preferredEditorItem != 0 )
  3122.                                                         SetPopupControlValue(editorPopupControlHandle, preferredEditorItem);
  3123.  
  3124.                                                 if ( isMove && contentIsPart )
  3125.                                                 {
  3126.                                                         HideDialogItem(dlg, kPasteAsEditorText);
  3127.                                                         ShowDialogItem(dlg, kPasteAsEmbedEditorText);
  3128.                                                 }
  3129.                                                 else
  3130.                                                 {
  3131.                                                         HideDialogItem(dlg, kPasteAsEditorLabel);
  3132.                                                         HideDialogItem(dlg, kPasteAsEditorText);
  3133.                                                         ShowDialogItem(dlg, kPasteAsEditorPopup);
  3134.                                                 }
  3135.  
  3136.                                                 // Now enable the kind items
  3137.                                                 if ( isMove && contentIsPart )
  3138.                                                 {
  3139.                                                         HideDialogItem(dlg, kPasteAsKindPopup);
  3140.                                                         ShowDialogItem(dlg, kPasteAsKindLabel);
  3141.                                                         ShowDialogItem(dlg, kPasteAsKindText);
  3142.                                                 }
  3143.                                                 else
  3144.                                                 {
  3145.                                                         ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  3146.                                                         ODEditor selectedEditor = GetSelectedEditor(editorList, editorItem);
  3147.                                                         EnableKindPopupItems(result->mergeSetting, kindList, translateToList, translationIndex, kindMenu, selectedEditor, nsm);
  3148.                                                         ODDisposePtr((ODPtr) selectedEditor);
  3149.                                                         EnablePasteAsOkButton(dlg, kindMenu);
  3150.                                                 }
  3151.                                         }
  3152.                                         break;
  3153.  
  3154.                         case kPasteAsKindPopup:
  3155.                                         kindItemSelected = (ODSShort) GetControlValue(kindPopupControlHandle);
  3156.                                         if ( kindItemSelected == kindItemOthers )
  3157.                                         {
  3158.                                                 ODUShort selectedIndex;
  3159.                                                 ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  3160.                                                 ODEditor initialEditorID;
  3161.                                                 if ( result->mergeSetting )
  3162.                                                         initialEditorID = ODISOStrFromCStr((char *) mergeEditorID);
  3163.                                                 else
  3164.                                                         initialEditorID = GetSelectedEditor(editorList, editorItem);
  3165.                                                 ODEditor newEditorID = kODNULL;
  3166.  
  3167.                                                 // Return the kind popup to its current value
  3168.                                                 SetPopupControlValue(kindPopupControlHandle, kindItemCurrent);
  3169.                                                 DeactivateModalDialog(modalFilter);
  3170.  
  3171.                                                 if ( session->GetTranslation(ev)->ShowTranslateDialog(
  3172.                                                                                                                                 ev,
  3173.                                                                                                                                 translateToList,
  3174.                                                                                                                                 translationIndex,
  3175.                                                                                                                                 &selectedIndex,
  3176.                                                                                                                                 initialEditorID,
  3177.                                                                                                                                 !result->mergeSetting,
  3178.                                                                                                                                 &newEditorID) )
  3179.                                                 {
  3180.                                                         // Add translationKind to the list just above "Translate to╔",
  3181.                                                         //  and make it the current selection.
  3182.                                                         translationIndex = selectedIndex;
  3183.  
  3184.                                                         { TempODType translationKind = GetSelectedType(translateToList, translationIndex);
  3185.                                                           AddTranslationKindToMenu(translationKind, kindMenu, kindItemOthers-1,
  3186.                                                                                                                 kindPopupHasNoTranslationKind, session);
  3187.                                                         }
  3188.  
  3189.                                                         if ( kindPopupHasNoTranslationKind )
  3190.                                                         {
  3191.                                                                 kindPopupHasNoTranslationKind = kODFalse;
  3192.                                                                 kindItemOthers += 1;
  3193.                                                         }
  3194.  
  3195.                                                         SetPort(dlg);
  3196.                                                         SetControlValue(kindPopupControlHandle, kindItemOthers-1);
  3197.                                                         InvalRect(&kindPopupRect);      // Redraw the popup
  3198.  
  3199.                                                         if ( !result->mergeSetting )
  3200.                                                         {
  3201.                                                                 ResetEditorPopup(kindList,
  3202.                                                                                                 kindItemSelected,
  3203.                                                                                                 translateToList,
  3204.                                                                                                 translationIndex,
  3205.                                                                                                 editorList,
  3206.                                                                                                 editorMenu,
  3207.                                                                                                 editorPopupControlHandle,
  3208.                                                                                                 session);
  3209.                                                                 // Select editorID in the list
  3210.                                                                 ODSShort editorItem = IndexOfEditorInList(editorList, newEditorID);
  3211.                                                                 if ( editorItem != 0 )
  3212.                                                                         SetControlValue(editorPopupControlHandle, editorItem);
  3213.                                                                 InvalRect(&editorPopupRect);    // Redraw the popup
  3214.                                                         }
  3215.                                                         ODDisposePtr((ODPtr) initialEditorID);
  3216.                                                         ODDisposePtr((ODPtr) newEditorID);
  3217.  
  3218.                                                         userChangedKind = kODTrue;
  3219.                                                 }
  3220.                                         }
  3221.                                         else if ( kindItemSelected != kindItemCurrent )
  3222.                                         {
  3223.                                                 userChangedKind = kODTrue;
  3224.                                                 if ( !result->mergeSetting )
  3225.                                                 {
  3226.                                                         ResetEditorPopup(kindList,
  3227.                                                                                         kindItemSelected,
  3228.                                                                                         translateToList,
  3229.                                                                                         translationIndex,
  3230.                                                                                         editorList,
  3231.                                                                                         editorMenu,
  3232.                                                                                         editorPopupControlHandle,
  3233.                                                                                         session);
  3234.                                                         SetPort(dlg);
  3235.                                                         InvalRect(&editorPopupRect);    // Redraw the popup
  3236.                                                 }
  3237.                                         }
  3238.                                         EnablePasteAsOkButton(dlg, kindMenu);
  3239.                                         break;
  3240.                         default:
  3241.                                         break;
  3242.                         }
  3243.                 } while ((itemHit != kPasteAsOKBtn) && (itemHit != kPasteAsCancelBtn));
  3244.  
  3245.                 if ( itemHit == kPasteAsOKBtn )
  3246.                 {
  3247.                         // update from "View" popup
  3248.                         if ( !result->mergeSetting )
  3249.                                 result->selectedView = GetViewSelected(dlg, session);
  3250.  
  3251.                         // update from "Kind" popup
  3252.                         if ( (!result->mergeSetting) && isMove && contentIsPart )
  3253.                         {
  3254.                                 // Selected kind is the best kind
  3255.                                 result->selectedKind = GetSelectedType(kindList, bestKindIndex);
  3256.                         }
  3257.                         else
  3258.                         {
  3259.                                 ODSShort kindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
  3260.                                 ODSShort kindCount = (ODSShort) kindList->Count(ev);
  3261.                                 if (kindItem <= kindCount)
  3262.                                 {
  3263.                                         result->selectedKind = GetSelectedType(kindList, kindItem);
  3264.                                 }
  3265.                                 else
  3266.                                 {
  3267.                                         result->selectedKind = GetSelectedType(translateToList, translationIndex);
  3268.                                         result->translateKind = GetSelectedType(kindList, GetIndexedElement(translateFromList, translationIndex));
  3269.                                 }
  3270.                         }
  3271.  
  3272.                         // update from "Editor" popup
  3273.                         if ( (!result->mergeSetting) && (!isMove || !contentIsPart) )
  3274.                         {
  3275.                                 ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  3276.                                 result->editor = GetSelectedEditor(editorList, editorItem);
  3277.                         }
  3278.                 }
  3279.  
  3280.         CATCH_ALL
  3281.                 ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  3282.                 ODDisposeRoutineDescriptor(DrawDeactiveItemUPP);
  3283.                 ODDisposeRoutineDescriptor(DrawKindNameUPP);
  3284.                 ODDisposeRoutineDescriptor(DrawEditorNameUPP);
  3285.                 ODDisposeRoutineDescriptor(DrawEmbeddedEditorNameUPP);
  3286.                 ODDisposeRoutineDescriptor(modalFilter);
  3287.  
  3288.                 refSaved = BeginUsingLibraryResources();
  3289.                 if ( kindMenu )
  3290.                 {
  3291.                         DeleteMenu(kPasteAsKindPopupMenu);
  3292.                         ReleaseResource((Handle) kindMenu);
  3293.                 }
  3294.                 if ( editorMenu )
  3295.                 {
  3296.                         DeleteMenu(kPasteAsEditorPopupMenu);
  3297.                         ReleaseResource((Handle) editorMenu);
  3298.                 }
  3299.                 ODDisposeDialog(dlg);
  3300.                 EndUsingLibraryResources(refSaved);
  3301.  
  3302.                 ODDisposePtr((ODPtr) mergeEditorID);
  3303.                 ODDisposePtr((ODPtr) embedEditorID);
  3304.                 ODDisposePtr((ODPtr) preferredEditorID);
  3305.                 ODDisposePtr((ODPtr) bestKind);
  3306.  
  3307.                 ODDeleteObject(kindList);
  3308.                 ODDeleteObject(translateToList);
  3309.                 ODDeleteObject(translateFromList);
  3310.                 delete editorList; editorList = kODNULL;
  3311.  
  3312.                 DisposeGlobalODNameAndZeroPtr(&gEditorName);
  3313.                 DisposeGlobalODNameAndZeroPtr(&gEmbeddedEditorName);
  3314.  
  3315.                 SetPort(savePort);
  3316.                 RERAISE;
  3317.         ENDTRY;
  3318.  
  3319.         DisposeRoutineDescriptor(DrawBoxItemUPP);
  3320.         DisposeRoutineDescriptor(DrawDeactiveItemUPP);
  3321.         DisposeRoutineDescriptor(DrawKindNameUPP);
  3322.         DisposeRoutineDescriptor(DrawEditorNameUPP);
  3323.         DisposeRoutineDescriptor(DrawEmbeddedEditorNameUPP);
  3324.         DisposeRoutineDescriptor(modalFilter);
  3325.  
  3326.         refSaved = BeginUsingLibraryResources();
  3327.         if ( kindMenu )
  3328.         {
  3329.                 DeleteMenu(kPasteAsKindPopupMenu);
  3330.                 ReleaseResource((Handle) kindMenu);
  3331.         }
  3332.         if ( editorMenu )
  3333.         {
  3334.                 DeleteMenu(kPasteAsEditorPopupMenu);
  3335.                 ReleaseResource((Handle) editorMenu);
  3336.         }
  3337.         DisposeDialog(dlg);
  3338.         EndUsingLibraryResources(refSaved);
  3339.  
  3340.         ODDisposePtr((ODPtr) mergeEditorID);
  3341.         ODDisposePtr((ODPtr) embedEditorID);
  3342.         ODDisposePtr((ODPtr) preferredEditorID);
  3343.         ODDisposePtr((ODPtr) bestKind);
  3344.  
  3345.         ODDeleteObject(kindList);
  3346.         ODDeleteObject(translateToList);
  3347.         ODDeleteObject(translateFromList);
  3348.         delete editorList; editorList = kODNULL;
  3349.  
  3350.         DisposeGlobalODNameAndZeroPtr(&gEditorName);
  3351.         DisposeGlobalODNameAndZeroPtr(&gEmbeddedEditorName);
  3352.  
  3353.         session->GetWindowState(ev)->ActivateFrontWindows(ev);
  3354.  
  3355.         SetPort(savePort);
  3356.  
  3357.         return (itemHit == kPasteAsOKBtn);
  3358. }
  3359.  
  3360. //------------------------------------------------------------------------------
  3361. // ResetEditorPopup
  3362. //------------------------------------------------------------------------------
  3363.  
  3364. ODStatic void ResetEditorPopup(ODTypeList* kindList,
  3365.                                                                 ODUShort kindIndex,
  3366.                                                                 ODTypeList* translateToList,
  3367.                                                                 ODUShort translateToIndex,
  3368.                                                                 EditorSet* editorList,
  3369.                                                                 MenuHandle editorMenu,
  3370.                                                                 ControlHandle popupCtlHndl,
  3371.                                                                 ODSession* session)
  3372. {
  3373.         Environment* ev = somGetGlobalEnvironment();
  3374.         TempODType kind = kODNULL;
  3375.  
  3376.         ODSShort kindCount = (ODSShort) kindList->Count(ev);
  3377.         if (kindIndex <= kindCount)
  3378.                 kind = GetSelectedType(kindList, kindIndex);
  3379.         else
  3380.                 kind = GetSelectedType(translateToList, translateToIndex);
  3381.  
  3382.         editorList->RemoveAllEditors();
  3383.         SetupEditorMenu(kind,
  3384.                                         editorList,
  3385.                                         editorMenu,
  3386.                                         popupCtlHndl,
  3387.                                         session);
  3388. }
  3389.  
  3390. //------------------------------------------------------------------------------
  3391. // PrepareToDrawGray
  3392. //------------------------------------------------------------------------------
  3393. //
  3394. // Sets the foreground color to the best color midway between the forground and
  3395. // background colors; usually gray.  If no intermediate gray is available (4 or
  3396. // fewer colors available), the pen pattern is set to draw gray.
  3397.  
  3398. ODStatic Boolean PrepareToDrawGray(DialogPtr theDialog, short theItem, RGBColor* fgSaveColor)
  3399. {
  3400.         Boolean result = false;
  3401.         const short kColorPort = 0xC000;
  3402.  
  3403.         Boolean isColorPort = ((((CGrafPtr)theDialog)->portVersion & kColorPort) == kColorPort);
  3404.  
  3405.         if ( isColorPort )
  3406.         {
  3407.                 RGBColor        fgNewColor;
  3408.                 RGBColor        bgColor;
  3409.  
  3410.                 Rect            itemRect;
  3411.                 Handle          itemHandle;
  3412.                 short           itemKind;
  3413.  
  3414.                 GetBackColor(&bgColor);
  3415.                 GetForeColor(fgSaveColor);
  3416.                 fgNewColor = *fgSaveColor;
  3417.  
  3418.                 GetDialogItem(theDialog, kPasteAsOKBtn, &itemKind, &itemHandle, &itemRect);
  3419.  
  3420.                 Rect globalRect = itemRect;
  3421.                 LocalToGlobal((Point *)&(globalRect.top));
  3422.                 LocalToGlobal((Point *)&(globalRect.bottom));
  3423.                 GDHandle targetDevice = GetMaxDevice(&globalRect);
  3424.  
  3425.                 result = GetGray(targetDevice, &bgColor, &fgNewColor);
  3426.  
  3427.                 if ( result )
  3428.                         RGBForeColor(&fgNewColor);
  3429.         }
  3430.  
  3431.         if ( !result )
  3432.         {
  3433. #ifdef THINK_CPLUS
  3434.                 PenPat(ODQDGlobals.gray);
  3435. #else
  3436.                 PenPat(&ODQDGlobals.gray);
  3437. #endif
  3438.         }
  3439.  
  3440.         return result;
  3441. }
  3442.  
  3443. //------------------------------------------------------------------------------
  3444. // DrawDeactivePICTItem
  3445. //------------------------------------------------------------------------------
  3446. //
  3447. // Draws a dimmed image of the preceeding dialog item, which should be
  3448. // beyond the visible area of the dialog, in this item's rectangle.
  3449.  
  3450. ODStatic pascal void DrawDeactivePICTItem(DialogPtr theDialog, short theItem)
  3451. {
  3452.         Rect            itemRect, otherRect;
  3453.         Handle          itemHandle, otherHandle;
  3454.         short           itemKind, otherKind;
  3455.  
  3456.         WindowPtr       savePort;
  3457.         PenState        savePen;
  3458.  
  3459.         RGBColor        fgSaveColor;
  3460.         Boolean         isColor;
  3461.  
  3462.         GetPort(&savePort);
  3463.         SetPort(theDialog);
  3464.         GetPenState(&savePen);
  3465.         PenNormal();
  3466.  
  3467.         // Get this dialog item
  3468.         GetDialogItem(theDialog, theItem, &itemKind, &itemHandle, &itemRect);
  3469.  
  3470.         // Get the dialog item to be drawn disabled
  3471.         GetDialogItem(theDialog, theItem-1, &otherKind, &otherHandle, &otherRect);
  3472.         if ( (otherKind & ~itemDisable) == picItem )
  3473.         {
  3474.                 DrawPicture((PicHandle) otherHandle, &itemRect);
  3475.                 isColor = PrepareToDrawGray(theDialog, theItem, &fgSaveColor);
  3476.                 if ( isColor )
  3477.                         PenMode(addMax);
  3478.                 else
  3479.                         PenMode(patBic);
  3480.                 PaintRect(&itemRect);
  3481.                 if ( isColor )
  3482.                         RGBForeColor(&fgSaveColor);
  3483.         }
  3484.  
  3485.         SetPenState(&savePen);
  3486.         SetPort(savePort);
  3487. }
  3488.  
  3489. //------------------------------------------------------------------------------
  3490. // InitItemActive
  3491. //------------------------------------------------------------------------------
  3492.  
  3493. ODStatic void InitItemActive(
  3494.                                         DialogPtr       dlg,
  3495.                                         short           itemNumber,
  3496.                                         UserItemUPP     itemUPP,
  3497.                                         ODBoolean       itemActive)
  3498. {
  3499.         Rect            itemRect, otherRect;
  3500.         Handle          itemHandle, otherHandle;
  3501.         short           itemKind, otherKind;
  3502.  
  3503.         // Get the rectangle from the actual item
  3504.         GetDialogItem(dlg, itemNumber, &otherKind, &otherHandle, &otherRect);
  3505.  
  3506.         // Establish the draw routine and rectangle for the user item
  3507.         GetDialogItem(dlg, itemNumber+1, &itemKind, &itemHandle, &itemRect);
  3508.         SetDialogItem(dlg, itemNumber+1, itemKind, (Handle)itemUPP, &otherRect);
  3509.  
  3510.         if ( itemActive )
  3511.                 HideDialogItem(dlg, itemNumber+1);
  3512.         else
  3513.                 HideDialogItem(dlg, itemNumber);
  3514. }
  3515.  
  3516. //------------------------------------------------------------------------------
  3517. // SetControlActive
  3518. //------------------------------------------------------------------------------
  3519. ODStatic void SetControlActive(
  3520.                                         DialogPtr       dlg,
  3521.                                         short           itemNumber,
  3522.                                         ODBoolean       itemActive)
  3523. {
  3524.         short           itemType;
  3525.         Handle          itemHandle;
  3526.         Rect            itemRect;
  3527.  
  3528.         GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  3529.         ASSERT_CONTROL_ITEM(itemType);
  3530.         HiliteControl((ControlHandle)itemHandle, itemActive ? kControlActive : kControlInactive);
  3531. }
  3532.  
  3533. //------------------------------------------------------------------------------
  3534. // BestContentKind
  3535. //------------------------------------------------------------------------------
  3536. ODStatic ODType BestContentKind(ODStorageUnit* contentSU)
  3537. {
  3538.         Environment* ev = somGetGlobalEnvironment();
  3539.  
  3540.         ODType bestKind = ODGetISOStrProp(ev, contentSU, kODPropPreferredKind, kODISOStr, kODNULL, kODNULL);
  3541.  
  3542.         if ( bestKind == kODNULL )
  3543.         {
  3544.                 if (contentSU->Exists(ev, kODPropContents, (ODValueType)kODNULL, 1))
  3545.                 {
  3546.                         contentSU->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType)kODNULL, 1, kODPosUndefined);
  3547.                         bestKind = contentSU->GetType(ev);
  3548.                 }
  3549.         }
  3550.  
  3551.         return bestKind;
  3552. }
  3553.  
  3554. //------------------------------------------------------------------------------
  3555. // SetLinkUpdateUpdateControls
  3556. //------------------------------------------------------------------------------
  3557. ODStatic void SetLinkUpdateUpdateControls(DialogPtr dlg, ODBoolean autoUpdateSetting)
  3558. {
  3559.         short   itemType;
  3560.         Handle  itemHandle;
  3561.         Rect    itemRect;
  3562.  
  3563.         GetDialogItem(dlg, kLinkInfoOnSaveRadioBtn, &itemType, &itemHandle, &itemRect);
  3564.         ASSERT_CONTROL_ITEM(itemType);
  3565.         SetControlValue((ControlHandle)itemHandle, autoUpdateSetting);
  3566.         GetDialogItem(dlg, kLinkInfoManualRadioBtn, &itemType, &itemHandle, &itemRect);
  3567.         ASSERT_CONTROL_ITEM(itemType);
  3568.         SetControlValue((ControlHandle)itemHandle, !autoUpdateSetting);
  3569. }
  3570.  
  3571. //------------------------------------------------------------------------------
  3572. // LinkInfoFilterProc
  3573. //------------------------------------------------------------------------------
  3574.  
  3575. static pascal Boolean
  3576. LinkInfoFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
  3577. {
  3578.         // If the event is a deactivate event, the ok button must be deactivated
  3579.         // before the surrounding outline is drawn so it is drawn dim.
  3580.         ODBoolean rslt = ODButtonKeyFilterProc(dialog,event,itemHit);
  3581.  
  3582.         if ( event->what == activateEvt )
  3583.         {
  3584.                 ODOutlineDefaultButtonDrawProc(dialog, kLinkInfoDefaultButtonItem);
  3585.         }
  3586.  
  3587.         return rslt;
  3588. }
  3589.  
  3590. //------------------------------------------------------------------------------
  3591. // ShowLinkInfo
  3592. //------------------------------------------------------------------------------
  3593.  
  3594. ODStatic ODBoolean ShowLinkInfo(
  3595.                                                 DialogPtr                       dlg,
  3596.                                                 ConstStr255Param        creationDate,
  3597.                                                 ConstStr255Param        creationTime,
  3598.                                                 ConstStr255Param        modificationDate,
  3599.                                                 ConstStr255Param        modificationTime,
  3600.                                                 ODBoolean                       needsUpdate,
  3601.                                                 ODLinkInfoResult*       infoResult
  3602.                                                 )
  3603. {
  3604.         short   itemHit;
  3605.  
  3606.         ParamText(creationDate, creationTime, modificationDate, modificationTime);
  3607.  
  3608.         ShowWindow(dlg);
  3609.  
  3610.         ModalFilterUPP modalFilter = NewModalFilterProc(LinkInfoFilterProc);
  3611.  
  3612.         do {
  3613.                 ODSLong refSaved = BeginUsingLibraryResources();
  3614.                 ModalDialog(modalFilter, &itemHit);
  3615.                 EndUsingLibraryResources(refSaved);
  3616.  
  3617.                 switch (itemHit)
  3618.                 {
  3619.                 case kLinkInfoManualRadioBtn :
  3620.                         if ( infoResult->autoUpdate )
  3621.                         {
  3622.                                 infoResult->autoUpdate = kODFalse;
  3623.                                 SetLinkUpdateUpdateControls(dlg, infoResult->autoUpdate);
  3624.                                 SetControlActive(dlg, kLinkInfoUpdateBtn, needsUpdate);
  3625.                         }
  3626.                         break;
  3627.  
  3628.                 case kLinkInfoOnSaveRadioBtn :
  3629.                         if ( !infoResult->autoUpdate )
  3630.                         {
  3631.                                 infoResult->autoUpdate = kODTrue;
  3632.                                 SetLinkUpdateUpdateControls(dlg, infoResult->autoUpdate);
  3633.                                 SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  3634.                         }
  3635.                         break;
  3636.                 }
  3637.         } while ((itemHit != kLinkInfoOKBtn) && (itemHit != kLinkInfoCancelBtn) &&
  3638.                          (itemHit != kLinkInfoUpdateBtn) && (itemHit != kLinkInfoBreakLinkBtn) &&
  3639.                          (itemHit != kLinkInfoFindSrcBtn));
  3640.  
  3641.         switch (itemHit) {
  3642.         case kLinkInfoOKBtn:
  3643.                         infoResult->action = kODLinkInfoOk;
  3644.                         break;
  3645.         case kLinkInfoUpdateBtn:
  3646.                         infoResult->action = kODLinkInfoUpdateNow;
  3647.                         break;
  3648.         case kLinkInfoBreakLinkBtn:
  3649.                         infoResult->action = kODLinkInfoBreakLink;
  3650.                         break;
  3651.         case kLinkInfoFindSrcBtn:
  3652.                         infoResult->action = kODLinkInfoFindSource;
  3653.                         break;
  3654.         default:
  3655.                         infoResult->action = kODLinkInfoCancel;
  3656.                         break;
  3657.         }
  3658.  
  3659.         ODDisposeRoutineDescriptor(modalFilter);
  3660.  
  3661.         return (itemHit != kLinkInfoCancelBtn);
  3662. }
  3663.  
  3664. //------------------------------------------------------------------------------
  3665. // DrawKindName
  3666. //------------------------------------------------------------------------------
  3667.  
  3668. pascal void DrawKindName(DialogPtr dialog, SInt16 item)
  3669. {
  3670.         short   itemType;
  3671.         Handle  itemHandle;
  3672.         Rect    itemRect;
  3673.  
  3674.         GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  3675.  
  3676.         DrawITextInDlogBox(gKindName, &itemRect, dialog, kODTrue);
  3677. }
  3678.  
  3679. //------------------------------------------------------------------------------
  3680. // ShowLinkSourceInfo
  3681. //------------------------------------------------------------------------------
  3682.  
  3683. ODBoolean ShowLinkSourceInfo(
  3684.                                 ODBaseLinkSource*       linkSource,
  3685.                                 ODUpdateID                      change,
  3686.                                 ODBoolean                       changesAllowed,
  3687.                                 ODLinkInfoResult*       infoResult)
  3688. {
  3689.         Environment* ev = somGetGlobalEnvironment();
  3690.  
  3691.         WindowPtr       savePort;                                               ODVolatile(savePort);
  3692.         GetPort(&savePort);
  3693.         ODSLong         refSaved;
  3694.  
  3695.         DialogPtr       dlg = kODNULL;                                  ODVolatile(dlg);
  3696.         UserItemUPP DrawBoxItemUPP = kODNULL;           ODVolatile(DrawBoxItemUPP);
  3697.         UserItemUPP DrawKindNameUPP = kODNULL;          ODVolatile(DrawKindNameUPP);
  3698.         short           itemType;
  3699.         Handle          itemHandle;
  3700.         Rect            itemRect;
  3701.         Str255          creationDate, modificationDate;
  3702.         Str255          creationTime, modificationTime;
  3703.         ODType          kind;
  3704.         ODBoolean       needsUpdate;
  3705.         ODBoolean       result;
  3706.  
  3707.         TRY
  3708.                 ODSession* session = linkSource->GetStorageUnit(ev)->GetSession(ev);
  3709.                 ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  3710.  
  3711.                 {
  3712.                         CUsingLibraryResources r;
  3713.                         dlg = ODGetNewDialog(ev, kLinkSrcInfoDlgID, session, kNoDefaultButton);
  3714.                         THROW_IF_NULL(dlg);
  3715.                 }
  3716.  
  3717.                 SetPort(dlg);
  3718.  
  3719.                 {       CUsingLibraryResources r;
  3720.                         SetDialogTextStyle(dlg, kLinkSrcInfoDlgID, smCurrentScript);
  3721.                 }
  3722.  
  3723.                 // Set the draw routine for the default button outline item
  3724.                 GetDialogItem(dlg, kLinkInfoDefaultButtonItem, &itemType, &itemHandle, &itemRect);
  3725.                 SetDialogItem(dlg, kLinkInfoDefaultButtonItem, itemType, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  3726.  
  3727.                 // Vertical and horizontal lines need to be drawn
  3728.                 GetDialogItem(dlg, kLinkInfoSeparator, &itemType, &itemHandle, &itemRect);
  3729.                 DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  3730.                 SetDialogItem(dlg, kLinkInfoSeparator, itemType, (Handle)DrawBoxItemUPP, &itemRect);
  3731.  
  3732.                 ODLinkKey key;
  3733.                 if (linkSource->Lock(ev, 0, &key))
  3734.                 {
  3735.                         TRY
  3736.                                 ODStorageUnit*  contentSU = linkSource->GetContentStorageUnit(ev, key);
  3737.  
  3738.                                 // Set up kind
  3739.                                 kind = BestContentKind(contentSU);
  3740.                                 DisposeGlobalODNameAndZeroPtr(&gKindName);
  3741.                                 if ( kind && GetUserKindFromKind(nsm, kind, &gKindName) )
  3742.                                 {
  3743.                                         GetDialogItem(dlg, kLinkInfoKind, &itemType, &itemHandle, &itemRect);
  3744.                                         DrawKindNameUPP = NewUserItemProc(DrawKindName);
  3745.                                         SetDialogItem(dlg, kLinkInfoKind, userItem+itemDisable, (Handle) DrawKindNameUPP, &itemRect);
  3746.                                 }
  3747.                                 ODDisposePtr((ODPtr) kind);
  3748.  
  3749.                                 // Set up creation date
  3750.                                 SetDateTimeStrings(ODGetCreationDate(ev, ODGetSUFromPstObj(ev, linkSource)),
  3751.                                                                         creationDate, creationTime);
  3752.  
  3753.                                 // Set up modified date
  3754.                                 SetDateTimeStrings(linkSource->GetChangeTime(ev), modificationDate, modificationTime);
  3755.                         CATCH_ALL
  3756.                                 linkSource->Unlock(ev, key);
  3757.                                 RERAISE;
  3758.                         ENDTRY
  3759.  
  3760.                         linkSource->Unlock(ev, key);
  3761.                 }
  3762.  
  3763.                 // Set up Send Updates
  3764.                 SetLinkUpdateUpdateControls(dlg, infoResult->autoUpdate);
  3765.  
  3766.                 needsUpdate = (change == kODUnknownUpdate) || (change != linkSource->GetUpdateID(ev));
  3767.  
  3768.                 // Disable Update Now button if updates are automatic or link is up to date.
  3769.                 if ( infoResult->autoUpdate || !needsUpdate )
  3770.                 {
  3771.                         GetDialogItem(dlg, kLinkInfoUpdateBtn, &itemType, &itemHandle, &itemRect);
  3772.                         ASSERT_CONTROL_ITEM(itemType);
  3773.                         HiliteControl((ControlHandle)itemHandle, kControlInactive);
  3774.                 }
  3775.  
  3776.                 // Disable some items if changes are not allowed or draft is read only
  3777.                 if ( !changesAllowed || DraftIsReadOnly(ev, linkSource->GetStorageUnit(ev)) )
  3778.                 {
  3779.                         SetControlActive(dlg, kLinkInfoOnSaveRadioBtn, kODFalse);
  3780.                         SetControlActive(dlg, kLinkInfoManualRadioBtn, kODFalse);
  3781.                         SetControlActive(dlg, kLinkInfoBreakLinkBtn, kODFalse);
  3782.                         SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  3783.                 }
  3784.  
  3785.                 result = ShowLinkInfo(dlg, creationDate, creationTime, modificationDate,
  3786.                                                                 modificationTime, needsUpdate, infoResult);
  3787.  
  3788.         CATCH_ALL
  3789.                 ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  3790.                 ODDisposeRoutineDescriptor(DrawKindNameUPP);
  3791.  
  3792.                 refSaved = BeginUsingLibraryResources();
  3793.                 ODDisposeDialog(dlg);
  3794.                 EndUsingLibraryResources(refSaved);
  3795.  
  3796.                 SetPort(savePort);
  3797.                 RERAISE;
  3798.         ENDTRY
  3799.  
  3800.         ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  3801.         ODDisposeRoutineDescriptor(DrawKindNameUPP);
  3802.  
  3803.         refSaved = BeginUsingLibraryResources();
  3804.         ODDisposeDialog(dlg);
  3805.         EndUsingLibraryResources(refSaved);
  3806.  
  3807.         SetPort(savePort);
  3808.  
  3809.         return result;
  3810. }
  3811.  
  3812. //------------------------------------------------------------------------------
  3813. // SetDateTimeStrings
  3814. //------------------------------------------------------------------------------
  3815.  
  3816. ODStatic void SetDateTimeStrings(
  3817.                                         ODULong         dateTime,
  3818.                                         Str255          dateString,
  3819.                                         Str255          timeString)
  3820. {
  3821.         if ( dateTime == 0 )
  3822.         {
  3823.                 CUsingLibraryResources r;
  3824.  
  3825.                 StringHandle str = GetString(kODLinkInfoStrUnknownID);
  3826.                 if ( str != kODNULL )
  3827.                 {
  3828.                         ODLockHandle((ODHandle) str);
  3829.                         ODBlockMove((ODPtr) *str, (ODPtr) dateString, (ODULong) (*str[0])+1);
  3830.                         ODUnlockHandle((ODHandle) str);
  3831.                         ReleaseResource((Handle) str);
  3832.                 }
  3833.                 else
  3834.                 {
  3835.                         dateString[0] = (char) 0;
  3836.                 }
  3837.                 timeString[0] = (char) 0;
  3838.         }
  3839.         else
  3840.         {
  3841.                 DateString(dateTime, abbrevDate, dateString, kODNULL);
  3842.                 TimeString(dateTime, kODFalse, timeString, kODNULL);
  3843.         }
  3844. }
  3845.  
  3846. //------------------------------------------------------------------------------
  3847. // DraftIsReadOnly
  3848. //------------------------------------------------------------------------------
  3849. ODStatic ODBoolean DraftIsReadOnly(Environment* ev, ODStorageUnit* su)
  3850. {
  3851.         return (!HAS_WRITE_ACCESS(su->GetDraft(ev)->GetPermissions(ev)));
  3852. }
  3853.  
  3854. //------------------------------------------------------------------------------
  3855. // ShowLinkDestinationInfo
  3856. //------------------------------------------------------------------------------
  3857.  
  3858. ODBoolean ShowLinkDestinationInfo(
  3859.                                 ODBaseLink*                     link,
  3860.                                 ODLinkInfo*             info,
  3861.                                 ODBoolean                       changesAllowed,
  3862.                                 ODLinkInfoResult*       infoResult)
  3863. {
  3864.         Environment* ev = somGetGlobalEnvironment();
  3865.  
  3866.         WindowPtr       savePort;                                               ODVolatile(savePort);
  3867.         GetPort(&savePort);
  3868.         ODSLong         refSaved;
  3869.  
  3870.         short           itemType;
  3871.         DialogPtr       dlg = kODNULL;                                  ODVolatile(dlg);
  3872.         UserItemUPP DrawBoxItemUPP = kODNULL;           ODVolatile(DrawBoxItemUPP);
  3873.         UserItemUPP DrawKindNameUPP = kODNULL;          ODVolatile(DrawKindNameUPP);
  3874.         Handle          itemHandle;
  3875.         Rect            itemRect;
  3876.         Str255          creationDate, modificationDate;
  3877.         Str255          creationTime, modificationTime;
  3878.         ODBoolean       needsUpdate;
  3879.         ODBoolean       result;
  3880.  
  3881.         TRY
  3882.                 ODSession* session = link->GetStorageUnit(ev)->GetSession(ev);
  3883.                 ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  3884.  
  3885.                 {
  3886.                         CUsingLibraryResources r;
  3887.                         dlg = ODGetNewDialog(ev, kLinkDstInfoDlgID, session, kNoDefaultButton);
  3888.                         THROW_IF_NULL(dlg);
  3889.                 }
  3890.  
  3891.                 SetPort(dlg);
  3892.  
  3893.                 {       CUsingLibraryResources r;
  3894.                         SetDialogTextStyle(dlg, kLinkDstInfoDlgID, smCurrentScript);
  3895.                 }
  3896.  
  3897.                 // Set the draw routine for the default button outline item
  3898.                 GetDialogItem(dlg, kLinkInfoDefaultButtonItem, &itemType, &itemHandle, &itemRect);
  3899.                 SetDialogItem(dlg, kLinkInfoDefaultButtonItem, itemType, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  3900.  
  3901.                 // Vertical and horizontal lines need to be drawn
  3902.                 GetDialogItem(dlg, kLinkInfoSeparator, &itemType, &itemHandle, &itemRect);
  3903.                 DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  3904.                 SetDialogItem(dlg, kLinkInfoSeparator, itemType, (Handle) DrawBoxItemUPP, &itemRect);
  3905.  
  3906.                 // Set up kind
  3907.                 DisposeGlobalODNameAndZeroPtr(&gKindName);
  3908.                 if ( info->kind && GetUserKindFromKind(nsm, info->kind, &gKindName) )
  3909.                 {
  3910.                         GetDialogItem(dlg, kLinkInfoKind, &itemType, &itemHandle, &itemRect);
  3911.                         DrawKindNameUPP = NewUserItemProc(DrawKindName);
  3912.                         SetDialogItem(dlg, kLinkInfoKind, userItem+itemDisable, (Handle) DrawKindNameUPP, &itemRect);
  3913.                 }
  3914.  
  3915.                 // Set up creation date
  3916.                 SetDateTimeStrings(info->creationTime, creationDate, creationTime);
  3917.  
  3918.                 // Set up modified date
  3919.                 SetDateTimeStrings(info->changeTime, modificationDate, modificationTime);
  3920.  
  3921.                 // Set up Send Updates
  3922.                 SetLinkUpdateUpdateControls(dlg, info->autoUpdate);
  3923.  
  3924.                 needsUpdate = (info->change == kODUnknownUpdate) || (info->change != link->GetUpdateID(ev));
  3925.  
  3926.                 // Disable Update Now button if updates are automatic or destination is up to date.
  3927.                 if ( info->autoUpdate || !needsUpdate )
  3928.                 {
  3929.                         SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  3930.                 }
  3931.  
  3932.                 // Disable some items if changes are not allowed or draft is read only
  3933.                 if ( !changesAllowed || DraftIsReadOnly(ev, link->GetStorageUnit(ev)) )
  3934.                 {
  3935.                         SetControlActive(dlg, kLinkInfoOnSaveRadioBtn, kODFalse);
  3936.                         SetControlActive(dlg, kLinkInfoManualRadioBtn, kODFalse);
  3937.                         SetControlActive(dlg, kLinkInfoBreakLinkBtn, kODFalse);
  3938.                         SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  3939.                 }
  3940.  
  3941.                 result = ShowLinkInfo(dlg, creationDate, creationTime, modificationDate,
  3942.                                                                 modificationTime, needsUpdate, infoResult);
  3943.  
  3944.         CATCH_ALL
  3945.                 ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  3946.                 ODDisposeRoutineDescriptor(DrawKindNameUPP);
  3947.  
  3948.                 refSaved = BeginUsingLibraryResources();
  3949.                 ODDisposeDialog(dlg);
  3950.                 EndUsingLibraryResources(refSaved);
  3951.  
  3952.                 SetPort(savePort);
  3953.                 RERAISE;
  3954.         ENDTRY
  3955.  
  3956.         ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  3957.         ODDisposeRoutineDescriptor(DrawKindNameUPP);
  3958.  
  3959.         refSaved = BeginUsingLibraryResources();
  3960.         ODDisposeDialog(dlg);
  3961.         EndUsingLibraryResources(refSaved);
  3962.  
  3963.         SetPort(savePort);
  3964.  
  3965.         return result;
  3966. }
  3967.  
  3968. //------------------------------------------------------------------------------
  3969. // ShowLinkUpdateAlert
  3970. //------------------------------------------------------------------------------
  3971.  
  3972. ODBoolean ShowLinkUpdateAlert( /*ODUShort count*/ )
  3973. {
  3974.         Environment* ev = somGetGlobalEnvironment();
  3975.  
  3976.         // ODUnused(count);
  3977.  
  3978.         gSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  3979.         ODSShort alertResult = ShowAlert(ev, kLinkUpdateAlertID, GetODButtonKeyFilterProc(), gSession);
  3980.         gSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  3981.  
  3982.         ResetAlertStage();
  3983.  
  3984.         return (alertResult == kLinkUpdateContinueBtn);
  3985. }
  3986.  
  3987. //------------------------------------------------------------------------------
  3988. // ShowLinkStatusAlert
  3989. //------------------------------------------------------------------------------
  3990.  
  3991. void ShowLinkStatusAlert(ODError error)
  3992. {
  3993.         Environment* ev = somGetGlobalEnvironment();
  3994.  
  3995.         ODSShort alertID;
  3996.         Str63 numberString;
  3997.  
  3998.         NumToString(error, numberString);
  3999.         ParamText(numberString, 0, 0, 0);
  4000.  
  4001.         if ( error == kODErrCannotFindLinkSourceEdition )
  4002.                 alertID = kLinkEditionAlertID;
  4003.         else
  4004.                 alertID = kLinkStatusAlertID;
  4005.  
  4006.         gSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  4007.         ShowAlert(ev, alertID, GetODButtonKeyFilterProc(), gSession);
  4008.         gSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  4009.  
  4010.         ResetAlertStage();
  4011. }
  4012. #endif // _PLATFORM_MACINTOSH_
  4013.