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

  1. /* @(#)Z 1.26 os2/src/core/Info.cpp, odcore, od96os2, odos29712d 97/03/21 17:40:45 (97/03/12 10:11:26) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odcore
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. /*
  30.         File:           Info.cpp
  31.  
  32.         Contains:       implementation of the Info object including ShowPartFrameInfo
  33.  
  34.         Owned by:       Tantek  elik
  35.  
  36.         Copyright:      c 1993-94 by Apple Computer, Inc., all rights reserved.
  37.  
  38.  
  39. */
  40.  
  41. #define ODInfo_Class_Source
  42. #define VARIABLE_MACROS
  43. #include <Info.xih>
  44.  
  45.  
  46. #ifndef SOM_ODSession_xh
  47. #include <ODSessn.xh>
  48. #endif
  49.  
  50. #ifndef SOM_ODHelp_xh
  51. #include <ODHelp.xh>
  52. #endif
  53.  
  54. #ifndef _HLPPANELS_
  55. #include <hlppanls.h>
  56. #endif
  57.  
  58. #ifndef SOM_ODDraft_xh
  59. #include <Draft.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODDocument_xh
  63. #include <Document.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODContainer_xh
  67. #include <ODCtr.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODWindowState_xh
  71. #include <WinStat.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODWindow_xh
  75. #include <Window.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODFrameFacetIterator_xh
  79. #include <FrFaItr.xh>
  80. #endif
  81.  
  82. #ifndef _ODTYPESP_
  83. #include "ODTypesP.h"
  84. #endif
  85.  
  86.  
  87. #ifndef _INFODEFS_
  88. #include "InfoDefs.h"
  89. #endif
  90.  
  91. #ifndef SOM_Module_OpenDoc_StdProps_defined
  92. #include <StdProps.xh>
  93. #endif
  94.  
  95. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  96. #include <StdTypes.xh>
  97. #endif
  98.  
  99. #ifndef _ODUTILS_
  100. #include <ODUtils.h>
  101. #endif
  102.  
  103. #ifndef _UTILDEFS_
  104. #include <UtilDefs.h>
  105. #endif
  106.  
  107. #ifndef SOM_ODFrame_xh
  108. #include <Frame.xh>
  109. #endif
  110.  
  111. #ifndef SOM_ODFacet_xh
  112. #include <Facet.xh>
  113. #endif
  114.  
  115. #ifndef SOM_ODPart_xh
  116. #include <Part.xh>
  117. #endif
  118.  
  119. #ifndef SOM_ODStorageUnit_xh
  120. #include <StorageU.xh>
  121. #endif
  122.  
  123. #ifndef SOM_ODStorageUnitView_xh
  124. #include <SUView.xh>
  125. #endif
  126.  
  127. #ifndef SOM_ODSettingsExtension_xh
  128. #include <Settings.xh>
  129. #endif
  130.  
  131. #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
  132. #include <StdExts.xh>
  133. #endif
  134.  
  135. #ifndef _PASCLSTR_
  136. #include <PasclStr.h>
  137. #endif
  138.  
  139. #ifndef _ODMEMORY_
  140. #include <ODMemory.h>
  141. #endif
  142.  
  143. #ifndef _PLFMFILE_
  144. #include <PlfmFile.h>
  145. #endif
  146.  
  147. #ifndef SOM_ODTypeList_xh
  148. #include <TypeList.xh>
  149. #endif
  150.  
  151. #ifndef SOM_ODTypeListIterator_xh
  152. #include <TypLsItr.xh>
  153. #endif
  154.  
  155. #ifndef _BNDNSUTL_
  156. #include <BndNSUtl.h>
  157. #endif
  158.  
  159. #ifndef _TEMPOBJ_
  160. #include <TempObj.h>
  161. #endif
  162.  
  163. #ifndef _EXCEPT_
  164. #include <Except.h>
  165. #endif
  166.  
  167. #ifndef _ITEXT_
  168. #include <IText.h>
  169. #endif
  170.  
  171. #ifndef _STORUTIL_
  172. #include <StorUtil.h>
  173. #endif
  174.  
  175. #ifndef _EDITRSET_
  176. #include <EditrSet.h>
  177. #endif
  178.  
  179. #ifndef _ISOSTR_
  180. #include <ISOStr.h>
  181. #endif
  182.  
  183. #ifndef SOM_ODPartWrapper_xh
  184. #include <PartWrap.xh>
  185. #endif
  186.  
  187. #ifndef SOM_ODNameSpace_xh
  188. #include <namspac.xh>
  189. #endif
  190.  
  191. #ifndef _STDTYPIO_
  192. #include <StdTypIO.h>
  193. #endif
  194.  
  195. #ifndef SOM_ODTranslation_xh
  196. #include <Translt.xh>
  197. #endif
  198.  
  199. #ifndef SOM_ODDispatcher_xh
  200. #include <Disptch.xh>
  201. #endif
  202.  
  203. #ifndef SOM_ODStorageSystem_xh
  204. #include <ODStor.xh>
  205. #endif
  206.  
  207. #ifndef SOM_ODNameSpaceManager_xh
  208. #include <NmSpcMg.xh>
  209. #endif
  210.  
  211. #ifndef _ORDCOLL_
  212. #include <OrdColl.h>
  213. #endif
  214.  
  215. #ifndef _ODRES_
  216. #include <ODRES.H>
  217. #endif
  218.  
  219. #ifndef _LinkSrc_
  220. #include <LinkSrc.xh>
  221. #endif
  222.  
  223. #ifndef _DOCMGR_
  224. #include <DocMgr.xh>
  225. #endif
  226.  
  227. #include <odos2.h>
  228. #include <TIME.h>
  229.  
  230. #define INCL_WINSTDBOOK         /* KDJ - for PM notebook */
  231. #include <ODMessag.h>           // Header file for catalog IDs
  232.  
  233. #ifndef _ODPRTREG_
  234. #include <ODPrtReg.xh>
  235. #endif
  236.  
  237. #ifndef _ODPRTREIG_
  238. #include <ODPrtRei.xh>
  239. #endif
  240.  
  241. #ifndef SOM_ODWindowIterator_xh
  242. #include <WinIter.xh>
  243. #endif
  244.  
  245. #include <langinfo.h>
  246.  
  247. typedef struct ODInfoDlgProgDataTag
  248. {
  249.     ODBoolean    allowEditing;
  250.     ODFacet    *facet;
  251. } ODInfoDlgProcData;
  252.  
  253. //==============================================================================
  254. // Constants
  255. //==============================================================================
  256. const ODULong kODDateLength = 29; // Length of date in property notebook
  257.  
  258. //==============================================================================
  259. // Scalar types
  260. //==============================================================================
  261.  
  262. //==============================================================================
  263. // Static Globals
  264. //==============================================================================
  265.  
  266. static ODTypeList*  ODInfo_kindList;
  267. static ODEditor     ODInfo_editorID;
  268. static ODEditor     ODInfo_currentEditorName;
  269. static ODSShort     ODInfo_currentKindItem;
  270. static ODSShort     ODInfo_currentEditorItem;
  271.  
  272. //==============================================================================
  273. // Kind/Editor functions
  274. //==============================================================================
  275.  
  276. void EnableApplModal(Environment *ev, ODWindowState *winState, HWND hwnd,
  277.                      BOOL enable);
  278.  
  279. void AddTypesToMenu(ODTypeList* typeList, ODType kindID,
  280.                     MenuHandle editorMenu, ODSession* session);
  281.  
  282. void AddEditorsToMenu(ODTypeList* kindsList, ODEditor editorID,
  283.                       MenuHandle editorMenu, ODSession* session);
  284.  
  285.  
  286. static HMODULE resInst;                           /* handle to resource DLL */
  287. static ODBoolean AllowEditing;
  288. int CreatePropSheet(HWND  hpwnd, ODFacet* facet);
  289. MRESULT EXPENTRY ODInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  290. MRESULT EXPENTRY PresPageDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  291. MRESULT EXPENTRY ViewPageDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  292. MRESULT EXPENTRY FilePageDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  293. MRESULT EXPENTRY SettingsPageDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  294. BOOL InitializeNoteBook(HWND hwnd,ODFacet* facet);
  295.  
  296. static ULONG ulPageIdPresentation = 0;
  297. static ULONG ulPageIdBinding = 0;
  298. static ULONG ulPageIdDocument = 0;
  299. static HWND  hwndPresentation = NULL;
  300. static HWND  hwndBinding      = NULL;
  301. static HWND  hwndDocument     = NULL;
  302. static ODSession * __session  = kODNULL;
  303. static HWND  hwndParent       = NULL;
  304.  
  305. //==============================================================================
  306. // InitInfo
  307. //==============================================================================
  308.  
  309. SOM_Scope void  SOMLINK ODInfoInitInfo(ODInfo *somSelf, Environment *ev,
  310.                 ODSession* session)
  311. {
  312.     ODInfoData *somThis = ODInfoGetData(somSelf);
  313.     ODInfoMethodDebug("ODInfo","ODInfoInitInfo");
  314.  
  315.         _fSession = session;
  316.         __session = session;  // Static for dialog proceedures
  317. }
  318.  
  319. //==============================================================================
  320. // ShowPartFrameInfo
  321. //==============================================================================
  322.  
  323. SOM_Scope ODBoolean  SOMLINK ODInfoShowPartFrameInfo(ODInfo *somSelf, Environment *ev,
  324.                 ODFacet* facet, ODBoolean allowEditing)
  325. {
  326.         ODInfoData *somThis = ODInfoGetData(somSelf);
  327.         ODInfoMethodDebug("ODInfo","ODInfoShowPartFrameInfo");
  328.         int result;
  329.  
  330.         // Need to acquire frame and storage unit before using them. Put
  331.         // them in temp object so that when the temp object is out of
  332.         // scope, the object get released.
  333.         TempODFrame frame = facet->GetFrame(ev);
  334.         frame->Acquire(ev);
  335.         TempODStorageUnit su = frame->GetStorageUnit(ev);
  336.         su->Acquire(ev);
  337.         ODSession* session = su->GetSession(ev);
  338.  
  339.         resInst = session->GetWindowSystemData(ev)->resInstance; //kdj - get resource handle
  340.  
  341.         ODWindowState* WinStat = session->GetWindowState(ev);
  342.  
  343.         // Need to release the window. Use temp object to accomplish
  344.         // the release when the temp object is out of scope.
  345.         TempODWindow Window = WinStat->AcquireActiveWindow(ev);
  346.         HWND hwnd = Window->GetPlatformWindow(ev);
  347.  
  348.         // Allow editing if the part says so and the draft permissions allow it
  349.         AllowEditing = allowEditing;
  350.     if (AllowEditing)
  351.             AllowEditing = su->GetDraft(ev)->GetPermissions(ev) 
  352.                                >= kODDPSharedWrite;
  353.  
  354.     // Use Apple's technique of forcing a part's externalization so
  355.     // that all necessary data is sure to exist in the SU
  356.     TempODPart part = frame->AcquirePart(ev);
  357.     if (su->GetDraft(ev)->GetPermissions(ev) >= kODDPSharedWrite)
  358.         part->Externalize(ev);
  359.  
  360.         // Before creating the dialog, disable mouse and keyboard inputs
  361.         // to all the OD windows except the window that is going to own
  362.         // the dialog. After dismissing the dialog, enable back all the
  363.         // OD windows except the owner window for the dialog.
  364.         EnableApplModal(ev, WinStat, hwnd, FALSE);
  365.         result = CreatePropSheet(hwnd, facet);
  366.         EnableApplModal(ev, WinStat, hwnd, TRUE);
  367.  
  368.         return result;
  369. }
  370.  
  371.  
  372. /*----------------------------------------------------------------------*/
  373. /* KDJ - start major portion of OS/2 port                               */
  374. /*----------------------------------------------------------------------*/
  375. int CreatePropSheet(HWND  hpwnd, ODFacet* facet )
  376.  
  377.    {
  378.  
  379.    return (int)WinDlgBox( HWND_DESKTOP,  /* Place anywhere on desktop   */
  380.                hpwnd,             /* Owned by frame                     */
  381.                ODInfoDlgProc,     /* Address of dialog procedure        */
  382.                (HMODULE)resInst,  /* Module handle                      */
  383.                IDD_NOTEBOOKDLG,   /* Dialog identifier in resource      */
  384.                facet);            /* Initialization data                */
  385.    }
  386.  
  387.  
  388. /*----------------------------------------------------------------------*/
  389. /* Notebook dialog procedure                                            */
  390. /*----------------------------------------------------------------------*/
  391. MRESULT EXPENTRY ODInfoDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  392. {
  393.   Environment *ev = somGetGlobalEnvironment();
  394.   ODFacet* facet;
  395.  
  396.   switch ( msg )
  397.   {
  398.     case WM_INITDLG:
  399.     {
  400.        facet = (ODFacet *) MPFROMP(mp2);
  401.        WinSetWindowULong(hwndDlg, QWL_USER, (ULONG) facet);
  402.  
  403.        if (!InitializeNoteBook(hwndDlg,facet))
  404.        {
  405.           WinDismissDlg(hwndDlg, FALSE);
  406.        }
  407.     }
  408.     break;
  409.  
  410.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  411.        /*
  412.         * PM sends a WM_COMMAND message when the user presses either
  413.         * the Enter or Escape pushbuttons.
  414.         */
  415.        facet = (ODFacet*) WinQueryWindowULong(hwndDlg, QWL_USER);
  416.  
  417.        switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  418.        {
  419.          case DID_OK:  /* the OK button was pressed */
  420.          {
  421.             /* Need to propagate this message to all of the pages. */
  422.             WinSendMsg(hwndPresentation,WM_DID_OK,NULL,NULL);
  423.             WinSendMsg(hwndBinding,WM_DID_OK,NULL,NULL);
  424.             WinSendMsg(hwndDocument,WM_DID_OK,NULL,NULL);
  425.  
  426.             /* Send on to any settings pages */
  427.             TempODFrame frame = facet->GetFrame(ev); frame->Acquire(ev);
  428.             TempODPart part = frame->AcquirePart(ev);
  429.             if (part->HasExtension(ev,kODSettingsExtension)) 
  430.             {
  431.                ODSettingsExtension* settings = (ODSettingsExtension*)
  432.                                part->AcquireExtension(ev,kODSettingsExtension);
  433.  
  434.                // Call Settings method to add the pages.
  435.                ODSheet* sheets = NULL;
  436.                ODULong sheetCount = 0;
  437.                settings->GetNotebookSheets(ev, &sheets, &sheetCount);
  438.  
  439.                for (int i = 0; i < sheetCount; i++) 
  440.                   WinSendMsg(sheets[i].hwnd,WM_DID_OK,NULL,NULL);
  441.  
  442.                ODReleaseObject(ev, settings);
  443.             }
  444.  
  445.             WinDismissDlg( hwndDlg, TRUE );  /* Removes the dialog box    */
  446.             return (MRESULT) FALSE;
  447.          }
  448.  
  449.          case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  450.          {
  451.             WinDismissDlg( hwndDlg, TRUE );  /* Removes the dialog box    */
  452.             return (MRESULT) FALSE;
  453.          }
  454.          default:
  455.             break;
  456.        }
  457.        break;
  458.  
  459.     case WM_HELP:
  460.        {
  461.          ULONG   ulCurPgID;
  462.  
  463.          // Query NOTEBOOK for pageID
  464.          ulCurPgID = (ULONG) WinSendDlgItemMsg(hwndDlg, IDC_NOTEBOOK,
  465.                                                BKM_QUERYPAGEID, (MPARAM)0,
  466.                                                MPFROM2SHORT(BKA_TOP,0));
  467.  
  468.          HWND ulCurPg = (ULONG) WinSendDlgItemMsg(hwndDlg, IDC_NOTEBOOK,
  469.                                     BKM_QUERYPAGEWINDOWHWND, (MPARAM) ulCurPgID,
  470.                                     (MPARAM) 0);
  471.  
  472.          WinSendMsg(ulCurPg,WM_HELP,NULL,NULL); 
  473.        }
  474.        break;
  475.  
  476.     case WM_CONTROL:
  477.        {
  478.           facet = (ODFacet*) WinQueryWindowULong(hwndDlg, QWL_USER);
  479.           USHORT notifycode;
  480.           PPAGESELECTNOTIFY pPageSelNotify;
  481.           notifycode = SHORT2FROMMP(mp1);
  482.           if (notifycode == BKN_PAGESELECTEDPENDING) 
  483.           {
  484.               /*-----------------------------------------------------*/
  485.               /* send a user defined message to the correct notebook */
  486.               /* page when that page is about to become the active   */
  487.               /* page.                                               */
  488.               /*-----------------------------------------------------*/
  489.               pPageSelNotify = (PPAGESELECTNOTIFY) PVOIDFROMMP(mp2);
  490.               if (pPageSelNotify->ulPageIdNew == ulPageIdPresentation) 
  491.               {
  492.                  if (hwndPresentation) {
  493.                     WinSendMsg(hwndPresentation,WM_SET_ACTIVE,NULL,NULL);
  494.                  }
  495.               } else if (pPageSelNotify->ulPageIdNew == ulPageIdBinding) {
  496.                  if (hwndBinding) {
  497.                     WinSendMsg(hwndBinding,WM_SET_ACTIVE,NULL,NULL);
  498.                  }
  499.               } else if (pPageSelNotify->ulPageIdNew == ulPageIdDocument) {
  500.                  if (hwndDocument) {
  501.                     WinSendMsg(hwndDocument,WM_SET_ACTIVE,NULL,NULL);
  502.                  }
  503.               } else {
  504.                  /* Send on to any settings pages */
  505.                  TempODFrame frame = facet->GetFrame(ev); frame->Acquire(ev);
  506.                  TempODPart part = frame->AcquirePart(ev);
  507.  
  508.                  if (part->HasExtension(ev,kODSettingsExtension)) 
  509.                  {
  510.                     ODSettingsExtension* settings = (ODSettingsExtension*)
  511.                                part->AcquireExtension(ev,kODSettingsExtension);
  512.      
  513.                     // Call Settings method to get the pages.
  514.                     ODSheet* sheets;
  515.                     ODULong  sheetCount;
  516.                     settings->GetNotebookSheets(ev, &sheets, &sheetCount);
  517.        
  518.                     // Find the corresponding sheet handle
  519.                     ODUShort i = 0;
  520.                     while ((i < sheetCount) && 
  521.                          (pPageSelNotify->ulPageIdNew != sheets[i].pageId)) i++;
  522.                     if (i < sheetCount)
  523.                        WinSendMsg(sheets[i].hwnd,WM_SET_ACTIVE,NULL,NULL);
  524.       
  525.                     ODReleaseObject(ev, settings);
  526.                  }
  527.               }
  528.            }
  529.        }
  530.        break;
  531.     default:
  532.       /*
  533.        * Any event messages that the dialog procedure has not processed
  534.        * come here and are processed by WinDefDlgProc.
  535.        * This call MUST exist in your dialog procedure.
  536.        */
  537.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  538.   }
  539.   return (MRESULT) FALSE;
  540. }
  541.  
  542. /*--------------------------------------------------*/
  543. /* Initialize the Notebook by inserting the         */
  544. /* three default pages as well as any dummy pages   */
  545. /* that have been set up.                           */
  546. /*--------------------------------------------------*/
  547. BOOL InitializeNoteBook(HWND hwnd, ODFacet * facet)
  548. {
  549.  
  550.    POINTL ptl;
  551.    USHORT usTabX, usTabY;
  552.    HWND hwndNoteBook;
  553.    ODSettingsExtension *settings;
  554.    ODSheet* Sheet;
  555.    ODULong sheet_count;
  556.  
  557.    // Save the window handle to the notebook dialog
  558.    hwndParent = hwnd;
  559.  
  560.    hwndNoteBook = WinWindowFromID(hwnd,IDC_NOTEBOOK);
  561.  
  562.    ptl.x = 4;  /* average width of a character in dialog coordinates */
  563.    ptl.y = 8;  /* average height of a character in dialog coordinates */
  564.  
  565.    WinMapDlgPoints(hwndNoteBook, &ptl, 1, TRUE); /* get pels per character */
  566.  
  567.    usTabX = ptl.x * 15;                 /* 15 characters wide */
  568.    usTabY = (ptl.y * 2) - (ptl.y / 2);  /* 1.5 characters high */
  569.  
  570.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK, BKM_SETDIMENSIONS,
  571.                        MPFROM2SHORT(usTabX,usTabY), /* width and height pels */
  572.                        MPFROMSHORT(BKA_MAJORTAB)))
  573.      return FALSE;
  574.  
  575.    /*
  576.     * Insert the first page.
  577.     */
  578.    ulPageIdPresentation = (LONG)WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  579.         BKM_INSERTPAGE, NULL,
  580.         MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
  581.         BKA_LAST));
  582.  
  583.    if ( !ulPageIdPresentation) return FALSE;
  584.  
  585.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  586.         BKM_SETTABTEXT, MPFROMLONG(ulPageIdPresentation),
  587.         MPFROMP( catgets(ODcat_handle, INFO_SET, INFO_5, "Presentation")
  588.         )))
  589.      return FALSE;
  590.  
  591.    hwndPresentation = WinLoadDlg(hwnd,hwnd,(PFNWP)PresPageDlgProc,
  592.                                (HMODULE)resInst,IDD_PRESENTATIONPAGEDLG,facet);
  593.  
  594.    if (!hwndPresentation) return FALSE;
  595.  
  596.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  597.          BKM_SETPAGEWINDOWHWND, MPFROMLONG(ulPageIdPresentation),
  598.          MPFROMHWND(hwndPresentation)))
  599.      return FALSE;
  600.  
  601.  
  602.    /*
  603.     * Insert the second page.
  604.     */
  605.    ulPageIdBinding = (LONG)WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  606.         BKM_INSERTPAGE, NULL,
  607.         MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
  608.         BKA_LAST));
  609.  
  610.    if ( !ulPageIdBinding) return FALSE;
  611.  
  612.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  613.         BKM_SETTABTEXT, MPFROMLONG(ulPageIdBinding),
  614.         MPFROMP( catgets(ODcat_handle, INFO_SET, INFO_6, "Binding")
  615.         )))
  616.      return FALSE;
  617.  
  618.  
  619.    hwndBinding = WinLoadDlg( hwnd, hwnd, (PFNWP)ViewPageDlgProc,
  620.                              (HMODULE)resInst, IDD_VIEWPAGEDLG, facet);
  621.  
  622.    if (!hwndBinding) return FALSE;
  623.  
  624.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  625.          BKM_SETPAGEWINDOWHWND, MPFROMLONG(ulPageIdBinding),
  626.          MPFROMHWND(hwndBinding)))
  627.      return FALSE;
  628.  
  629.  
  630.    /*
  631.     * Insert the third page.
  632.     */
  633.    ulPageIdDocument = (LONG)WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  634.         BKM_INSERTPAGE, NULL,
  635.         MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
  636.         BKA_LAST));
  637.  
  638.    if ( !ulPageIdDocument) return FALSE;
  639.  
  640.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  641.         BKM_SETTABTEXT, MPFROMLONG(ulPageIdDocument),
  642.         MPFROMP( catgets(ODcat_handle, INFO_SET, INFO_7, "Document"))))
  643.      return FALSE;
  644.  
  645.    hwndDocument = WinLoadDlg( hwnd, hwnd, (PFNWP)FilePageDlgProc,
  646.                               (HMODULE)resInst, IDD_FILEPAGE1DLG, facet);
  647.  
  648.    if (!hwndDocument) return FALSE;
  649.  
  650.    if ( !WinSendDlgItemMsg(hwnd, IDC_NOTEBOOK,
  651.          BKM_SETPAGEWINDOWHWND, MPFROMLONG(ulPageIdDocument),
  652.          MPFROMHWND(hwndDocument)))
  653.      return FALSE;
  654.  
  655.    /*
  656.     * Insert any settings pages
  657.     */
  658.    Environment *ev = somGetGlobalEnvironment();
  659.  
  660.    // Need to acquire the frame before using it. Put it
  661.    // in temp object so that the frame is released when
  662.    // the temp object is out of scope.
  663.    TempODFrame frame = facet->GetFrame(ev); frame->Acquire(ev);
  664.  
  665.    // Need to acquire the part. Put it in temp object so that when
  666.    // the temp object is out of scope, the part is released.
  667.    TempODPart part = frame->AcquirePart(ev);
  668.  
  669.    if (part->HasExtension(ev,kODSettingsExtension))
  670.    {
  671.        settings = (ODSettingsExtension*)
  672.                     part->AcquireExtension(ev,kODSettingsExtension);
  673.  
  674.        // Call Settings method to add the pages.
  675.        settings->ShowSettingsPages(ev, facet, hwnd, IDC_NOTEBOOK);
  676.  
  677.        // Release the settings
  678.        ODReleaseObject(ev, settings);
  679.    }
  680.  
  681.    return TRUE;
  682. }                                       /* End of InitializeNotebook    */
  683.  
  684.  
  685. /*-------------------------------------------------------------------*/
  686. /* Dialog procedure for the presentation page.                       */
  687. /* "View" page, Presentation                                         */
  688. /*-------------------------------------------------------------------*/
  689. MRESULT EXPENTRY PresPageDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  690. {
  691.    static ODFacet* facet;
  692.  
  693.    Str255  aStr255, partNameS255, partCommentsS255;
  694.    Environment *ev = somGetGlobalEnvironment();
  695.  
  696.    ODSession* session ;
  697.    ODBoolean isRootPart ;
  698.    ODBoolean isRootPartOfDocument ;
  699.    ODUShort viewval;
  700.    HWND hKindList;
  701.    HWND hCategory;
  702.    HWND hEditorList;
  703.    ODName* partName = kODNULL;
  704.  
  705.   switch ( msg )
  706.   {
  707.     case WM_INITDLG:
  708.     {
  709.        facet = (ODFacet *)MPFROMP(mp2);
  710.  
  711.        //port start
  712.         TempODFrame frame = facet->GetFrame(ev);
  713.  
  714.         // Need to acquire the frame before using it. Put it
  715.         // in temp object so that the frame is released when
  716.         // the temp object is out of scope.
  717.         frame->Acquire(ev);
  718.  
  719.         // Need to release the part. Put it in temp object so that when
  720.         // the temp object is out of scope, the part is released.
  721.        TempODPart part = frame->AcquirePart(ev);
  722.  
  723.        TempODWindow window = facet->GetWindow(ev);
  724.  
  725.         // Need to acquire the window and storage unit before using them.
  726.         // Put them in temp object so that they get released.
  727.         window->Acquire(ev);
  728.         TempODStorageUnit su = frame->GetStorageUnit(ev);
  729.         su->Acquire(ev);
  730.         session = su->GetSession(ev);
  731.  
  732.         // Need to release the containing frame. Use temp object
  733.         // to accomplish the release.
  734.         TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
  735.         isRootPart = (containingFrame == kODNULL);
  736.         isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
  737.  
  738.  
  739.         // Set up Name
  740.         partName = ODGetPOName(ev, part, kODNULL);
  741.         IntlToStr(partName, (PSZ)partNameS255);
  742.         WinSendDlgItemMsg (hwndDlg, DID_PARTNAME, EM_SETTEXTLIMIT, MPFROMSHORT(255), 0 );
  743.         WinSetDlgItemText (hwndDlg, DID_PARTNAME, (PSZ)partNameS255);
  744.         ODDisposePtr (partName);
  745.  
  746.         // set up viewas
  747.         //  This need to be put into a resource so that it can be internationalized.
  748.         WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_INSERTITEM, (MPARAM)0,
  749.                MPFROMP(catgets(ODcat_handle, INFO_SET, INFO_1, "Frame") ));
  750.  
  751.  
  752.         // test to see if additional view types should be added - use isRootPart
  753.     // instead of ...OfDocument so part windows are OK.
  754.         if (!(isRootPart))
  755.         {
  756.            WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_INSERTITEM, (MPARAM)1,
  757.                MPFROMP(catgets(ODcat_handle, INFO_SET, INFO_2, "Large Icon") ));
  758.            WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_INSERTITEM, (MPARAM)2,
  759.                MPFROMP(catgets(ODcat_handle, INFO_SET, INFO_3, "Small Icon") ));
  760.            WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_INSERTITEM, (MPARAM)3,
  761.                MPFROMP(catgets(ODcat_handle, INFO_SET, INFO_4, "Thumb Nail") ));
  762.         }
  763.  
  764.         viewval = 0;
  765.  
  766.         WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
  767.  
  768.         // set up frozen
  769.         WinCheckButton(hwndDlg,DID_BUNDLED, frame->IsFrozen(ev));
  770.  
  771.         if (isRootPartOfDocument)
  772.         {
  773.            // set up stationery from aFrame and its part
  774.            WinCheckButton(hwndDlg,DID_STATIONARY, ODGetIsStationery(ev, frame));
  775.            WinShowWindow(WinWindowFromID(hwndDlg, kPartInfoStationeryCheckbox), FALSE);
  776.            WinShowWindow(WinWindowFromID(hwndDlg, kPartInfoStationeryText), FALSE);
  777.  
  778.            // set up show links from the window
  779.            WinCheckButton(hwndDlg, DID_SHOWLINKS, window->ShouldShowLinks(ev));
  780.  
  781.         }
  782.         else
  783.         {
  784.             // disable stationery button if NOT root
  785.             WinEnableControl(hwndDlg, DID_STATIONARY, FALSE);
  786.  
  787.             // disable Show Links button if NOT root
  788.             WinEnableControl(hwndDlg, DID_SHOWLINKS, FALSE);
  789.         }
  790.  
  791.     }
  792.        break;
  793.  
  794. /*---------------------------------------------------------------------*/
  795. /* This is code in response to a user defined message which is sent    */
  796. /* when the notebook page is about to come to the top as the active    */
  797. /* page.  This corresponds to the PSN_SETACTIVE case in Windows.       */
  798. /*---------------------------------------------------------------------*/
  799.     case WM_SET_ACTIVE:
  800.       // Initialize the controls.
  801.     {
  802.  
  803.       TempODFrame frame = facet->GetFrame(ev);
  804.  
  805.       // Need to acquire frame and storage unit before using them. Put
  806.       // them in temp object so that when the temp object is out of
  807.       // scope, the object get released.
  808.       frame->Acquire(ev);
  809.       TempODStorageUnit su = frame->GetStorageUnit(ev);
  810.       su->Acquire(ev);
  811.       session = su->GetSession(ev);
  812.       ODTypeToken view = frame->GetViewType(ev);
  813.  
  814.       if (view == session->Tokenize(ev, kODViewAsFrame))
  815.               viewval = 0;
  816.       else if (view == session->Tokenize(ev, kODViewAsLargeIcon))
  817.               viewval = 1;
  818.       else if (view == session->Tokenize(ev, kODViewAsSmallIcon))
  819.               viewval = 2;
  820.       else if (view == session->Tokenize(ev, kODViewAsThumbnail))
  821.               viewval = 3;
  822.  
  823.       WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_SELECTITEM,
  824.                          MPFROMSHORT(0), MPFROMSHORT(TRUE));
  825.  
  826.     }
  827.        break;
  828.  
  829.     //the OK button was pressed and this page was on the top - execute
  830.     //the equivalent code as for the PSN_APPLY windows version
  831. /*---------------------------------------------------------------------*/
  832. /* This is code in response to a user defined message which is sent    */
  833. /* when the user hit the OK button and this page was on top.  This     */
  834. /* corresponds to the PSN_SETACTIVE case in Windows.                   */
  835. /*---------------------------------------------------------------------*/
  836.     case WM_DID_OK:
  837.               {
  838.                 if (AllowEditing)
  839.                 {
  840.                   TempODFrame frame = facet->GetFrame(ev);
  841.  
  842.                   // Need to release the part. Put it in temp object so that when
  843.                   // the temp object is out of scope, the part is released.
  844.                   TempODPart part = frame->AcquirePart(ev);
  845.  
  846.  
  847.                   // Need to acquire frame, window, and su before using. Put
  848.                   // them in temp object so that they are released when
  849.                   // the temp objects are out of scope.
  850.                   frame->Acquire(ev);
  851.                   TempODWindow window = facet->GetWindow(ev);
  852.                   window->Acquire(ev);
  853.                   TempODStorageUnit su = frame->GetStorageUnit(ev);
  854.                   su->Acquire(ev);
  855.                   session = su->GetSession(ev);
  856.  
  857.                   // update Frozen
  858.                   frame->SetFrozen(ev, WinQueryButtonCheckstate(hwndDlg, DID_BUNDLED));
  859.  
  860.                   // update Stationery
  861.                   ODSetIsStationery(ev, frame, WinQueryButtonCheckstate(hwndDlg, DID_STATIONARY));
  862.  
  863.                   // update Show Links
  864.                   window->SetShouldShowLinks(ev,WinQueryButtonCheckstate(hwndDlg, DID_SHOWLINKS));
  865.  
  866.                   // Update Name
  867.                   WinQueryDlgItemText (hwndDlg, DID_PARTNAME, sizeof(partNameS255),   (PSZ)partNameS255);
  868.                   partName =StrToIntl((PSZ)partNameS255, kODNULL);
  869.                   ODSetPOName(ev, part, partName);
  870.                   ODDisposePtr (partName);
  871.  
  872.                   // update ViewAs
  873.                   switch (SHORT1FROMMR (WinSendDlgItemMsg (hwndDlg, DID_VIEW, LM_QUERYSELECTION, 0, 0)) )
  874.                   {
  875.                         case 0: // view as frame
  876.                                 frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsFrame));
  877.                                 break;
  878.                         case 1: // view as large icon
  879.                                 frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsLargeIcon));
  880.                                 break;
  881.                         case 2: // view as small icon
  882.                                 frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsSmallIcon));
  883.                                 break;
  884.                         case 3: // view as thumbnail
  885.                                 frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsThumbnail));
  886.                                 break;
  887.                         default:
  888.                                 break;
  889.                   }
  890.                 }
  891.               }
  892.        break;
  893.     case WM_COMMAND:
  894.       if (SHORT1FROMMP( mp1 )  == DID_CANCEL)
  895.       {
  896.        /* This occured as a result of the Escape key being pressed while this
  897.         * page was active.  Want to intercept this so it doesn't go onto
  898.         * WinDefDlgProc.  Eventually, need to pass event back up to parent to
  899.         * handle.
  900.         */
  901.         WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_CANCEL),
  902.                    MPARAM(0));
  903.         break;
  904.       }
  905.  
  906.     case WM_HELP:
  907.       {
  908.          SOM_TRY
  909.            if (__session != kODNULL)
  910.            {
  911.              ODHelp * helpme  = __session->GetHelp(ev);
  912.              helpme->DisplayHelp(ev,ODHELPFILE,SET_VIEW1_PANEL);
  913.            } /* endif */
  914.          SOM_CATCH_ALL
  915.          SOM_ENDTRY
  916.          break;
  917.       }
  918.  
  919.     case WM_CHAR:
  920.       {
  921.          // To catch the accelerator for OK button, somehow notebook does
  922.          // not generate a WM_COMMAND message as the Escape key. This is
  923.          // a clutch to catch the 'o' or 'O' keyboard input. If the focus
  924.          // is not in an entry field, then treat the 'o' or 'O' as the
  925.          // accelerator for the OK button and generate a WM_COMMAND message
  926.          // event to send back up to the parent.
  927.          switch( SHORT1FROMMP( mp2 ) )     
  928.          {
  929.             case 0x186F: // for lower case o 
  930.             case 0x006F:
  931.             case 0x184F: // for upper case O 
  932.             case 0x004F:
  933.                if (WinQueryFocus(HWND_DESKTOP) != 
  934.                    WinWindowFromID(hwndDlg, DID_PARTNAME))
  935.                {
  936.                   WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_OK),
  937.                              MPARAM(0));
  938.                   break;
  939.                }
  940.          }
  941.       }
  942.     default:
  943.       /*
  944.        * Any event messages that the dialog procedure has not processed
  945.        * come here and are processed by WinDefDlgProc.
  946.        * This call MUST exist in your dialog procedure.
  947.        */
  948.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  949.   }
  950.   return (MRESULT) FALSE;
  951. }
  952.  
  953.  
  954. /*-------------------------------------------------------------------*/
  955. /* Dialog procedure for the view page.                               */
  956. /* Callback for "BIND" page, Binding                                 */
  957. /*-------------------------------------------------------------------*/
  958. MRESULT EXPENTRY ViewPageDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  959. {
  960.   static ODFacet* facet;
  961.   Str255  aStr255, partNameS255, partCommentsS255;
  962.   Environment *ev = somGetGlobalEnvironment();
  963.   HWND hKindList;
  964.   HWND hCategory;
  965.   HWND hEditorList;
  966.   ODType  kindID;
  967.   ODBoolean content_exists;
  968.   static ODBoolean partSaved;
  969.  
  970.   switch ( msg )
  971.   {
  972.     case WM_INITDLG:
  973.       {
  974.          facet = (ODFacet *)MPFROMP(mp2);
  975.  
  976.          TempODFrame frame = facet->GetFrame(ev);
  977.          // Need to acquire the frame before using it. Put it
  978.          // in temp object so that the frame is released when
  979.          // the temp object is out of scope.
  980.          frame->Acquire(ev);
  981.  
  982.          // Need to release the part. Put it in temp object so
  983.          // that when the temp object is out of scope, the part
  984.          // is released.
  985.          TempODPart part = frame->AcquirePart(ev);
  986.  
  987.          // Need to acquire the storage unit before using it
  988.          TempODStorageUnit su = frame->GetStorageUnit(ev);
  989.          su->Acquire(ev);
  990.          ODSession* session = su->GetSession(ev);
  991.  
  992.          // get editorID
  993.          ODInfo_editorID = GetCurrentEditorForPart(part);
  994.          kindID = ODGetKind(ev, part);
  995.  
  996.          // check for existence of the Part's storage unit
  997.          if ( (part->GetStorageUnit(ev))->Exists(ev, kODPropContents, kODNULL, 0) )
  998.          {
  999.             //      set up Kind Menu
  1000.             ODInfo_kindList = new ODTypeList;
  1001.             ODInfo_kindList->InitTypeList(ev,(ODTypeList*) kODNULL);
  1002.             ContentValueTypes(part->GetStorageUnit(ev), ODInfo_kindList);
  1003.  
  1004.             HWND hKindList = WinWindowFromID(hwndDlg,DID_KIND);
  1005.             AddTypesToMenu(ODInfo_kindList, kindID, hKindList, session);
  1006.  
  1007.             //      set up Category static text
  1008.             // $$$$$ for now just put in the user string of the first category of the first kind
  1009.             // should put in user string of the first category of the CURRENT kind
  1010.             HWND hCategory = WinWindowFromID(hwndDlg,DID_CATEGORY);
  1011.             SetCategory(ODInfo_editorID, kindID, hCategory, session);
  1012.  
  1013.             //      set up Editor Menu
  1014.             HWND hEditorList = WinWindowFromID(hwndDlg,DID_EDITOR);
  1015.             AddEditorsToMenu(ODInfo_kindList, ODInfo_editorID, hEditorList, session);
  1016.  
  1017.             partSaved = kODTrue;
  1018.          }
  1019.          else // list was empty, return error code saying so
  1020.          {
  1021.             WARNMSG(WARN_INDEX(AMSG_902),
  1022.                "Part's properties cannot be displayed until Document is saved.");
  1023.             partSaved = kODFalse;
  1024.          }
  1025.  
  1026.       }
  1027.       break;
  1028. /*---------------------------------------------------------------------*/
  1029. /* This is code in response to a user defined message which is sent    */
  1030. /* when the notebook page is about to come to the top as the active    */
  1031. /* page.  This corresponds to the PSN_SETACTIVE case in Windows.       */
  1032. /*---------------------------------------------------------------------*/
  1033.     case WM_SET_ACTIVE:
  1034.       {
  1035.               TempODFrame frame = facet->GetFrame(ev);
  1036.               // Need to acquire the frame before using it. Put it
  1037.               // in temp object so that the frame is released when
  1038.               // the temp object is out of scope.
  1039.               frame->Acquire(ev);
  1040.  
  1041.               // Need to release the part. Put it in temp object so
  1042.               // that when the temp object is out of scope, the part
  1043.               // is released.
  1044.               TempODPart part = frame->AcquirePart(ev);
  1045.  
  1046.               // Need to acquire the storage unit before using it
  1047.               TempODStorageUnit su = frame->GetStorageUnit(ev);
  1048.               su->Acquire(ev);
  1049.               ODSession* session = su->GetSession(ev);
  1050.  
  1051.       }
  1052.       break;
  1053. /*---------------------------------------------------------------------*/
  1054. /* This is code in response to a user defined message which is sent    */
  1055. /* when the user hit the OK button and this page was on top.  This     */
  1056. /* corresponds to the PSN_SETACTIVE case in Windows.                   */
  1057. /*---------------------------------------------------------------------*/
  1058.     case WM_DID_OK:
  1059.     {
  1060.       if (AllowEditing && partSaved)
  1061.       {
  1062.         TempODFrame frame = facet->GetFrame(ev);
  1063.  
  1064.         // Need to acquire the frame before using it. Put it
  1065.         // in temp object so that the frame is released when
  1066.         // the temp object is out of scope.
  1067.         frame->Acquire(ev);
  1068.  
  1069.         // Need to release the part. Put it in temp object so
  1070.         // that when the temp object is out of scope, the part
  1071.         // is released.
  1072.         TempODPart part = frame->AcquirePart(ev);
  1073.  
  1074.         // Need to acquire the storage unit before using it
  1075.         TempODStorageUnit su = frame->GetStorageUnit(ev);
  1076.         su->Acquire(ev);
  1077.         ODSession* session = su->GetSession(ev);
  1078.  
  1079.         // update Kind
  1080.         ODSShort kindItem = SHORT1FROMMR (WinSendDlgItemMsg (hwndDlg, DID_KIND,
  1081.                 LM_QUERYSELECTION, 0, 0));
  1082.         ODType  oldKind, newKind;
  1083.         if (kindItem != ODInfo_currentKindItem)
  1084.         {
  1085.             oldKind  =  GetThisKindFromList( ODInfo_currentKindItem, ODInfo_kindList );
  1086.             newKind  =  GetThisKindFromList( kindItem, ODInfo_kindList );
  1087.         }
  1088.         else
  1089.         {
  1090.             oldKind  =  GetThisKindFromList( ODInfo_currentKindItem, ODInfo_kindList );
  1091.             newKind  =  GetThisKindFromList( ODInfo_currentKindItem, ODInfo_kindList );
  1092.         }
  1093.  
  1094.         // update Editor
  1095.         ODSShort editorItem = SHORT1FROMMR (WinSendDlgItemMsg (hwndDlg, DID_EDITOR,
  1096.                 LM_QUERYSELECTION, 0, 0));
  1097.         if (editorItem != ODInfo_currentEditorItem)
  1098.         {
  1099.             ODInfo_editorID = ODInfo_currentEditorName;
  1100.             if ( EditorSupportsKind_Reg(ODInfo_editorID,  oldKind, session ))
  1101.             {
  1102.                     // change kind first, then editor
  1103.                     part->ChangeKind(ev, newKind);
  1104.                     ChangeEditor( part, ODInfo_editorID);
  1105.             }
  1106.             else
  1107.             {
  1108.                     // change editor first, then kind
  1109.                     ChangeEditor( part, ODInfo_editorID);
  1110.                     part->ChangeKind(ev, newKind);
  1111.             }
  1112.  
  1113.         }
  1114.         else
  1115.            if (kindItem != ODInfo_currentKindItem) part->ChangeKind(ev, newKind);
  1116.               //   set return value of dialog equal to TRUE
  1117.               //   WinSetWindowULong(HWND,  DWL_MSGRESULT, MPFROMSHORT(TRUE));
  1118.               return MRESULT(TRUE);
  1119.         break;
  1120.       }
  1121.     }
  1122.  
  1123.       break;
  1124.  
  1125.     case WM_COMMAND:
  1126.       if (SHORT1FROMMP( mp1 )  == DID_CANCEL)
  1127.       {
  1128.        /* This occured as a result of the Escape key being pressed while this
  1129.         * page was active.  Want to intercept this so it doesn't go onto
  1130.         * WinDefDlgProc.  Eventually, need to pass event back up to parent to
  1131.         * handle.
  1132.         */
  1133.         WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_CANCEL),
  1134.                    MPARAM(0));
  1135.         break;
  1136.       }
  1137.  
  1138.     case WM_HELP:
  1139.       {
  1140.          SOM_TRY
  1141.            if (__session != kODNULL)
  1142.            {
  1143.              ODHelp * helpme  = __session->GetHelp(ev);
  1144.              helpme->DisplayHelp(ev,ODHELPFILE,SET_TYPE_PANEL);
  1145.            } /* endif */
  1146.          SOM_CATCH_ALL
  1147.          SOM_ENDTRY
  1148.          break;
  1149.       }
  1150.  
  1151.     case WM_CHAR:
  1152.       {
  1153.          // To catch the accelerator for OK button, somehow notebook does
  1154.          // not generate a WM_COMMAND message as the Escape key. This is
  1155.          // a clutch to catch the 'o' or 'O' keyboard input. Since this page
  1156.          // does not have any entry field, treat the 'o' or 'O' as the
  1157.          // accelerator for the OK button and generate a WM_COMMAND message
  1158.          // event to send back up to the parent.
  1159.          switch( SHORT1FROMMP( mp2 ) )
  1160.          {
  1161.             case 0x186F: // for lower case o
  1162.             case 0x006F:
  1163.             case 0x184F: // for upper case O
  1164.             case 0x004F:
  1165.                WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_OK),
  1166.                              MPARAM(0));
  1167.                break;
  1168.          }
  1169.       }
  1170.  
  1171.     default:
  1172.       /*
  1173.        * Any event messages that the dialog procedure has not processed
  1174.        * come here and are processed by WinDefDlgProc.
  1175.        * This call MUST exist in your dialog procedure.
  1176.        */
  1177.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1178.   }
  1179.   return (MRESULT) FALSE;
  1180. }
  1181.  
  1182.  
  1183. /*-------------------------------------------------------------------*/
  1184. /* Dialog procedure for the file page.                               */
  1185. /* Callback for "DOCU" page, Document                                */
  1186. /*-------------------------------------------------------------------*/
  1187. MRESULT EXPENTRY FilePageDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1188. {
  1189.   static ODFacet* facet;
  1190.   Str255  aStr255, partNameS255, partCommentsS255;
  1191.   ODName* partComments;
  1192.   ODName* partName;
  1193.   char theDate[kODDateLength]    = "";
  1194.   Environment *ev = somGetGlobalEnvironment();
  1195.   switch ( msg )
  1196.   {
  1197.     case WM_INITDLG:
  1198.      {
  1199.        facet = (ODFacet *)MPFROMP(mp2);
  1200.         TempODFrame frame = facet->GetFrame(ev);
  1201.         // Need to acquire the frame before using it. Put it
  1202.         // in temp object so that the frame is released when
  1203.         // the temp object is out of scope.
  1204.         frame->Acquire(ev);
  1205.  
  1206.         // Need to release the part. Put it in temp object so
  1207.         // that when the temp object is out of scope, the part
  1208.         // is released.
  1209.         TempODPart part = frame->AcquirePart(ev);
  1210.  
  1211.         // set up Comments
  1212.         partComments = kODNULL;
  1213.         partComments = ODGetPOComments(ev, part, kODNULL);
  1214.         IntlToStr(partComments, (PSZ)partCommentsS255);
  1215.  
  1216.         WinSendDlgItemMsg (hwndDlg, DID_COMMENTS, EM_SETTEXTLIMIT, MPFROMSHORT(255), 0 );
  1217.         WinSetDlgItemText (hwndDlg, DID_COMMENTS, (PSZ)partCommentsS255);
  1218.  
  1219.         ODDisposePtr (partComments);
  1220.  
  1221.         // set up size
  1222.         WinSetDlgItemShort(hwndDlg, DID_DATASIZE, ODGetPOSize(ev, part), FALSE);
  1223.  
  1224.         // Need to acquire the storage unit before using it. Put it
  1225.         // in temp object so that the storage unit is released when
  1226.         // the temp object is out of scope.
  1227.         TempODStorageUnit partSU = part->GetStorageUnit(ev);
  1228.         partSU->Acquire(ev);
  1229.  
  1230.         // set up created date
  1231.         char* dateFormat = nl_langinfo(D_T_FMT);
  1232.         time_t theTime = ODGetCreationDate(ev, partSU);
  1233.         if (theTime)
  1234.         {
  1235.           struct tm *timeptr = localtime((const time_t*) &theTime);
  1236.           strftime(theDate, kODDateLength, dateFormat, timeptr);
  1237.           WinSetDlgItemText (hwndDlg, DID_CRDATE, theDate);
  1238.         }
  1239.  
  1240.         // set up modified date
  1241.         theTime = ODGetModificationDate(ev, partSU);
  1242.         if (theTime)
  1243.         {
  1244.           struct tm *timeptr = localtime((const time_t*) &theTime);
  1245.           strftime(theDate, kODDateLength, dateFormat, timeptr);
  1246.           WinSetDlgItemText (hwndDlg, DID_MODDATE, theDate);
  1247.         }
  1248.  
  1249.         // set up by
  1250.         ODName* partUser = kODNULL;
  1251.         partUser = ODGetModifiedBy(ev, partSU, kODNULL);
  1252.         IntlToStr(partUser, (PSZ)aStr255);
  1253.         WinSetDlgItemText(hwndDlg, DID_MODBY, (PSZ)aStr255);
  1254.         ODDisposePtr (partUser);
  1255.  
  1256.         // set up Draft ID
  1257.         WinSetDlgItemShort(hwndDlg, DID_KEY, partSU->GetID(ev), FALSE);
  1258.  
  1259.  
  1260.      }
  1261.         return MRESULT(TRUE);
  1262.        break;
  1263.  
  1264. /*---------------------------------------------------------------------*/
  1265. /* This is code in response to a user defined message which is sent    */
  1266. /* when the notebook page is about to come to the top as the active    */
  1267. /* page.  This corresponds to the PSN_SETACTIVE case in Windows.       */
  1268. /*---------------------------------------------------------------------*/
  1269.     case WM_SET_ACTIVE:
  1270.       break;
  1271. /*---------------------------------------------------------------------*/
  1272. /* This is code in response to a user defined message which is sent    */
  1273. /* when the user hit the OK button and this page was on top.  This     */
  1274. /* corresponds to the PSN_SETACTIVE case in Windows.                   */
  1275. /*---------------------------------------------------------------------*/
  1276.     case WM_DID_OK:
  1277.     {
  1278.       if (AllowEditing)
  1279.       {
  1280.         // Need to acquire the frame before using it. Put it
  1281.         // in temp object so that the frame is released when
  1282.         // the temp object is out of scope.
  1283.         TempODFrame frame = facet->GetFrame(ev);
  1284.         frame->Acquire(ev);
  1285.  
  1286.          // Need to release the part. Put it in temp object so that when
  1287.          // the temp object is out of scope, the part is released.
  1288.         TempODPart part = frame->AcquirePart(ev);
  1289.  
  1290.         // Update Comments
  1291.         WinQueryDlgItemText (hwndDlg, DID_COMMENTS, sizeof(partNameS255),   (PSZ)partNameS255);
  1292.         partComments =StrToIntl((PSZ)partNameS255, kODNULL);
  1293.         ODSetPOComments(ev, part, partComments);
  1294.       }
  1295.       break;
  1296.     }
  1297.  
  1298.     case WM_COMMAND:
  1299.       if (SHORT1FROMMP( mp1 )  == DID_CANCEL)
  1300.       {
  1301.        /* This occured as a result of the Escape key being pressed while this
  1302.         * page was active.  Want to intercept this so it doesn't go onto
  1303.         * WinDefDlgProc.  Eventually, need to pass event back up to parent to
  1304.         * handle.
  1305.         */
  1306.         WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_CANCEL),
  1307.                    MPARAM(0));
  1308.         break;
  1309.       }
  1310.  
  1311.     case WM_HELP:
  1312.       {
  1313.          SOM_TRY
  1314.            if (__session != kODNULL)
  1315.            {
  1316.              ODHelp * helpme  = __session->GetHelp(ev);
  1317.              helpme->DisplayHelp(ev,ODHELPFILE,SET_FILE1_PANEL);
  1318.            } /* endif */
  1319.          SOM_CATCH_ALL
  1320.          SOM_ENDTRY
  1321.          break;
  1322.       }
  1323.  
  1324.     case WM_CHAR:
  1325.       {
  1326.          // To catch the accelerator for OK button, somehow notebook does
  1327.          // not generate a WM_COMMAND message as the Escape key. This is
  1328.          // a clutch to catch the 'o' or 'O' keyboard input. If the focus
  1329.          // is not in an entry field, then treat the 'o' or 'O' as the
  1330.          // accelerator for the OK button and generate a WM_COMMAND message
  1331.          // event to send back up to the parent.
  1332.          switch( SHORT1FROMMP( mp2 ) )
  1333.          {
  1334.             case 0x186F: // for lower case o
  1335.             case 0x006F:
  1336.             case 0x184F: // for upper case O
  1337.             case 0x004F:
  1338.                if (WinQueryFocus(HWND_DESKTOP) !=
  1339.                    WinWindowFromID(hwndDlg, DID_COMMENTS))
  1340.                {
  1341.                   WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_OK),
  1342.                              MPARAM(0));
  1343.                   break;
  1344.                }
  1345.          }
  1346.       }
  1347.  
  1348.     default:
  1349.       /*
  1350.        * Any event messages that the dialog procedure has not processed
  1351.        * come here and are processed by WinDefDlgProc.
  1352.        * This call MUST exist in your dialog procedure.
  1353.        */
  1354.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1355.   }
  1356.   return (MRESULT) FALSE;
  1357. }
  1358.  
  1359.  
  1360. /*----------------------------------------------------------------------*/
  1361. /* KDJ - end major portion of OS/2 port                                 */
  1362. /*----------------------------------------------------------------------*/
  1363.  
  1364.  
  1365.  
  1366. SOM_Scope void  SOMLINK ODInfosomInit(ODInfo *somSelf)
  1367. {
  1368.          ODInfoData *somThis = ODInfoGetData(somSelf);
  1369.          ODInfoMethodDebug("ODInfo","ODInfosomInit");
  1370.  
  1371.          ODInfo_parent_ODObject_somInit(somSelf);
  1372. }
  1373.  
  1374. SOM_Scope void  SOMLINK ODInfosomUninit(ODInfo *somSelf)
  1375. {
  1376.          ODInfoData *somThis = ODInfoGetData(somSelf);
  1377.          ODInfoMethodDebug("ODInfo","ODInfosomUninit");
  1378.  
  1379.          ODInfo_parent_ODObject_somUninit(somSelf);
  1380. }
  1381.  
  1382.  
  1383.  
  1384. //-------------------------------------------------------------------------------------
  1385. // Editor and Kind Menu manipulation functions
  1386. //-------------------------------------------------------------------------------------
  1387.  
  1388.  
  1389. //------------------------------------------------------------------------------
  1390. // AddTypesToMenu
  1391. //------------------------------------------------------------------------------
  1392.  
  1393. void AddTypesToMenu(ODTypeList* typeList, ODType kindID,
  1394.                     MenuHandle kindMenu, ODSession* session)
  1395. {
  1396.   ODSShort                item = 0;
  1397.   ODSShort                i = 0;
  1398.   ISOString               displayname;
  1399.   ODPartHandlerRegistryInt* ODRegistry;
  1400.   Environment*            ev = somGetGlobalEnvironment();
  1401.  
  1402.         ODRegistry = session -> GetRegistry(ev);
  1403.         ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
  1404.  
  1405.         for (ODType type = typeIter->First(ev);
  1406.                 typeIter->IsNotComplete(ev);
  1407.                 type = typeIter->Next(ev))
  1408.         {
  1409.            // convert kind name to appropriate display name for dialogue
  1410.            displayname = ODRegistry->GetKindDisplayNameFromKind(ev,type);
  1411.  
  1412.            // Copy the PartKind list to dialog box
  1413.            WinSendMsg(kindMenu, LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(displayname));
  1414.  
  1415.         }
  1416.  
  1417.  
  1418.         // Set the cursor position to the 1st entry.
  1419.         WinSendMsg(kindMenu, LM_SELECTITEM, 0, MPFROMSHORT(TRUE));
  1420.  
  1421.         // initialize currentKindItem to part kind index
  1422.         item = 0;
  1423.         for (ODType kind = typeIter->First(ev);
  1424.               typeIter->IsNotComplete(ev);
  1425.               kind = typeIter->Next(ev), ++item)
  1426.         {
  1427.               if (ODISOStrEqual(kind, kindID))
  1428.                       break;
  1429.         }
  1430.  
  1431.         ODInfo_currentKindItem = item;
  1432.  
  1433.         ODDeleteObject( typeIter );
  1434.  
  1435. }
  1436.  
  1437. //------------------------------------------------------------------------------
  1438. // AddEditorsToMenu
  1439. //------------------------------------------------------------------------------
  1440.  
  1441. void AddEditorsToMenu(ODTypeList* kindsList, ODEditor editorID,
  1442.                       MenuHandle editorMenu, ODSession* session)
  1443. {
  1444.  
  1445.     ODSShort   unique;
  1446.     ODSShort   i,j;
  1447.     ODSShort   item;
  1448.     ODSShort  list_loaded = FALSE;
  1449.     enum {STR_COUNT =  50};
  1450.     char *strarray[STR_COUNT] = {NULL};
  1451.  
  1452.     unsigned  long          size;
  1453.     ODPartHandlerRegistryInt* ODRegistry;
  1454.     _IDL_SEQUENCE_ISOString PartHandlerList;
  1455.  
  1456.  
  1457.         Environment*            ev = somGetGlobalEnvironment();
  1458.         ODRegistry = session -> GetRegistry(ev);
  1459.  
  1460.         ODTypeListIterator* kindIter = kindsList->CreateTypeListIterator(ev);
  1461.         for (ODType kind = kindIter->First(ev);
  1462.                 kindIter->IsNotComplete(ev);
  1463.                 kind = kindIter->Next(ev) )
  1464.         {
  1465.  
  1466.            // retrieve PartHandler list from Registry
  1467.            // this is a buffer that the Registry allocates and we need to dispose of.
  1468.            PartHandlerList = ODRegistry-> GetPartHandlerList( ev, kind, 0);
  1469.  
  1470.            //   if (GetUserEditorFromEditor(nsm, editor, &name))
  1471.            // if the list is not empty, continue
  1472.            if ( PartHandlerList. _length ) {
  1473.                list_loaded = TRUE;
  1474.            }
  1475.  
  1476.            // Copy the PartHandler list to dialog box
  1477.            for ( i = 0; i < PartHandlerList. _length; i++)
  1478.            {
  1479.  
  1480.               for ( j = 0, unique = TRUE; strarray[j]; j++)
  1481.               {
  1482.                  if (strcmp(PartHandlerList. _buffer[i],strarray[j]) == 0 )
  1483.                  {
  1484.                     // set unique to false if duplicate editor exists in string array
  1485.                     unique = FALSE;
  1486.                  }
  1487.               }
  1488.               if (unique ==  TRUE)
  1489.               {
  1490.                  // Copy the PartHandler list to dialog box if first occurrence
  1491.                  WinSendMsg(editorMenu, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  1492.                     MPFROMP((ODRegistry->GetHandlerDisplayNameFromHandler(ev,PartHandlerList. _buffer[i]))));
  1493.  
  1494.                  // copy Part Handler name to string for duplicate check
  1495.                  strarray[j] = new char[strlen(PartHandlerList. _buffer[i]) +1];
  1496.                  strcpy ( strarray[j], PartHandlerList. _buffer[i] );
  1497.               }
  1498.            }
  1499.  
  1500.            // now free up the buffer we got from the Registry
  1501.            for ( i = 0; i < PartHandlerList. _length; i++)
  1502.            {
  1503.                      SOMFree( PartHandlerList. _buffer[i]);
  1504.            }
  1505.            SOMFree( PartHandlerList. _buffer);
  1506.  
  1507.         }
  1508.  
  1509.  
  1510.  
  1511.         // If list was loaded, set up list boxes.
  1512.         if ( list_loaded == TRUE )
  1513.         {
  1514.            // set editor name to current editor
  1515.            ODInfo_currentEditorName = editorID;
  1516.  
  1517.            for ( item = 0;  strarray[item] != NULL; item++)
  1518.            {
  1519.  
  1520.               // Set the cursor position to the current editor in list box
  1521.               if (strcmp(strarray[item], editorID ) == 0 )
  1522.               {
  1523.                  WinSendMsg(editorMenu, LM_SELECTITEM, MPFROMSHORT(item), MPFROMSHORT(TRUE));
  1524.                  // set editor name to current editor
  1525.                  ODInfo_currentEditorItem = item;
  1526.               }
  1527.  
  1528.               // free up Part Handler Strings, strarray
  1529.               delete[] strarray[item];
  1530.               strarray[item] = NULL;
  1531.            }
  1532.  
  1533.         }
  1534.         else // list was empty, return error code saying so
  1535.         {
  1536.             WARNMSG(WARN_INDEX(AMSG_903),
  1537.               "Couldn't load Part Handler list.");
  1538.         }
  1539.  
  1540. }
  1541.  
  1542.  
  1543.  
  1544. //------------------------------------------------------------------------------
  1545. // EnableApplModal - Simulates application modality by disabling/enabling
  1546. //                   all the OD windows except the window which owns the dialog.
  1547. //------------------------------------------------------------------------------
  1548. void EnableApplModal(Environment *ev, ODWindowState *winState, HWND hwnd,
  1549.                      BOOL enable)
  1550. {
  1551.     ODWindowIterator *iter = kODNULL;
  1552.     ODWindow         *curWindow;
  1553.  
  1554.     SOM_TRY
  1555.         // Disable/Enable mouse and keyboard input to all the OD windows
  1556.         // except the one which is going to own the display dialog.
  1557.         //
  1558.         // Note: The window which is going to own the display dialog is
  1559.         //       disable/enable by the system.
  1560.         iter = winState->CreateWindowIterator(ev);
  1561.         for (curWindow = iter->First(ev); iter->IsNotComplete(ev);
  1562.              curWindow = iter->Next(ev))
  1563.         {
  1564.             HWND platformWindow = curWindow->GetPlatformWindow(ev);
  1565.             if (platformWindow != hwnd)
  1566.                WinEnableWindow(platformWindow, enable);
  1567.         }
  1568.         ODDeleteObject(iter);
  1569.  
  1570.     SOM_CATCH_ALL
  1571.         LOG("SOM exception occured in EnableApplModal");
  1572.         ODDeleteObject(iter);
  1573.  
  1574.     SOM_ENDTRY
  1575. }
  1576.