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

  1. /* @(#)Z 1.86 com/src/docshell/AppShell.cpp, odshell, od96os2, odos29712d 97/03/21 17:37:28 (97/03/05 14:35:22) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odshell
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 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. // AppShell.cpp
  31. //
  32. //      This file implements the ApplicationShell class.  This abstract
  33. //      class is a subclass of OpenDocShell and adds the platform-independent
  34. //      docshell application functionality.
  35. //------------------------------------------------------------------------------
  36.  
  37. #ifndef SOM_Module_appshell_Source
  38. #define SOM_Module_appshell_Source
  39. #endif
  40. #define ApplicationShell_Class_Source
  41.  
  42. #include "DocShell.h"
  43. #include <ODTypes.h>
  44. #include <ODUtils.h>
  45. #include <PlfmFile.h>
  46. #include <Except.h>
  47. #include <sys/stat.h>
  48. #include <errno.h>
  49. #include <StorUtil.h>
  50. #include <DraftWn.h>
  51. #include <TempObj.h>
  52. #include <StdTypIO.h>
  53. #include <odres.h>
  54.  
  55. #include <DocMgr.xh>
  56. #include <Draft.xh>
  57. #include <Info.xh>
  58. #include <MenuBar.xh>
  59. #include <ODSessn.xh>
  60. #include <Disptch.xh>
  61. #include <Window.xh>
  62. #include <WinStat.xh>
  63. #include <StorageU.xh>
  64. #include <StdProps.xh>
  65. #include <StdTypes.xh>
  66. #include <Undo.xh>
  67. #include <Frame.xh>
  68.  
  69. #ifndef SOM_ODHelp_xh
  70. #include <odhelp.xh>
  71. #endif
  72. #ifndef _HLPPANELS_
  73. #include <hlppanls.h>
  74. #endif
  75.  
  76. #define VARIABLE_MACROS
  77. #include <AppShell.xih>
  78.  
  79. #define ACTION_LABEL_LENGTH 256
  80.  
  81. // Shell Dialog Utility Function prototypes
  82. #include "ShellUtl.h"
  83.  
  84. #undef LOGGING
  85. #define LOGGING 1
  86.  
  87. //------------------------------------------------------------------------------
  88. // Go
  89. //
  90. //      This is where all of the action takes place: the arguments are
  91. //      parsed, the system is initialized, and the events are processed.
  92. //      When we return from here we're done.
  93. //------------------------------------------------------------------------------
  94. SOM_Scope ODSLong  SOMLINK ApplicationShellGo(ApplicationShell *somSelf,
  95.                                 Environment *ev, ODSLong argc, char **argv)
  96. {
  97.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  98.     ApplicationShellMethodDebug("ApplicationShell","ApplicationShellGo");
  99.  
  100.     char        fileName[kODMaxFileNameSize];
  101.     char        kindName[kODMaxFileNameSize];
  102.     DocumentManager     *docMgr;
  103.     ODSLong             result = 0;
  104.     ODBoolean           closeDown = kODFalse;
  105.     ODUShort            actionFlag;
  106.  
  107.     // Initialize fileName, kindName to null strings
  108.     fileName[0] = NULL;
  109.     kindName[0] = NULL;
  110.  
  111.     // Initialize _fExecString to default value
  112.     strcpy(_fExecString, "docshell");
  113.  
  114.     try
  115.     {
  116.         // Initialize the Window System
  117.         somSelf->InitWindowSystem(ev);
  118.  
  119.         // Initialize the OpenDoc environment
  120.         somSelf->InitOpenDocShell(ev);
  121.  
  122.         // Parse the command line arguments.
  123.         // NOTE: ProcessArgs must be done after InitWindowSystem and
  124.         //       InitOpenDocShell because it relies on data set in
  125.         //       InitWindowSystem and InitOpenDocShell.
  126.         somSelf->ProcessArgs(ev, argc, argv, fileName, kindName, &actionFlag);
  127.  
  128.         // Create Menu Bar
  129.         somSelf->CreateMenuBar(ev);
  130.  
  131.         // Create a DocumentManager
  132.         docMgr = somSelf->CreateDocumentManager(ev);
  133.  
  134.         // Open a document (create it if necessary) and run it
  135.         if (somSelf->OpenDocument(ev, docMgr, fileName, kindName, actionFlag))
  136.             result = somSelf->MainLoop(ev); // Start the main loop
  137.     }
  138.     catch (ODException _exception)
  139.     {
  140.         result = -1;
  141.  
  142.         // Clear the exception
  143.         SetErrorCodeEv(ev, kODNoError);
  144.     }
  145.  
  146.     try
  147.     {
  148.        // Close up shop
  149.        somSelf->Terminate(ev);
  150.     }
  151.     catch (ODException _exception)
  152.     {
  153.        // Clear the exception
  154.         SetErrorCodeEv(ev, kODNoError);
  155.     }
  156.  
  157.     return result;
  158. }
  159.  
  160. //------------------------------------------------------------------------------
  161. // ProcessArgs
  162. //
  163. //      Process command line arguments
  164. //------------------------------------------------------------------------------
  165. SOM_Scope void  SOMLINK ApplicationShellProcessArgs(
  166.                                 ApplicationShell *somSelf, Environment *ev,
  167.                                 ODSLong argc, char **argv, char *fileName,
  168.                                 char *partKind, ODUShort *actionFlag)
  169. {
  170.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  171.     ApplicationShellMethodDebug("ApplicationShell",
  172.                                 "ApplicationShellProcessArgs");
  173.  
  174.     int      i;
  175.     ODBoolean    implicit_dash_f = kODFalse;
  176.  
  177.     try
  178.     {
  179.        // Save arg 0 so we have the command to exec for New and Open
  180.        if (argv != NULL)
  181.           strcpy (_fExecString, argv[0]);
  182.  
  183.        // Initialize flag to kODNULL
  184.        *actionFlag = kODNULL;
  185.  
  186.        // Save argc and argv
  187.        somSelf->SetArgc(ev, argc);
  188.        somSelf->SetArgv(ev, argv);
  189.  
  190.        // Allow "docshell filename" - backwards compatibility for Merlin
  191.        // - look for argc of 2 and the second arg must not be an option
  192. #ifdef _PLATFORM_WIN32_    // allow for "forward slash" options from OLE
  193.        if ((argc == 2) && ((argv[1][0] != '-') && (argv[1][0] != '/')))
  194. #else
  195.        if ((argc == 2) && (argv[1][0] != '-'))
  196. #endif
  197.            implicit_dash_f = kODTrue;
  198.  
  199.        // Look through the args and set appropriate options
  200.        for (i = 1; i < argc; i++)
  201.        {
  202.           if ((strcmp("-f", argv[i]) == 0) || (strcmp("-s", argv[i]) == 0)
  203.                             || implicit_dash_f)
  204.           {
  205.               if (implicit_dash_f)
  206.                   strcpy(fileName, argv[i]);
  207.               else
  208.               {
  209.                   if (strcmp("-s", argv[i]) == 0)
  210.                       // Set flag to edit stationery
  211.                       *actionFlag = kODEditStationery;
  212.  
  213.                   // If there is another argument and it is not another option
  214.                   if ((argc > i+1) && (*argv[i+1] != '-'))
  215.                     strcpy(fileName, argv[++i]);
  216.               }
  217.  
  218.               if (!(somSelf->IsValidFileName(ev, fileName)))
  219.               {
  220.                   WindowSystemData* wsData;
  221.  
  222.                   wsData = somSelf->GetWindowSystemData(ev);
  223.  
  224.                   // Null out filename so we know if we returned because user
  225.                   // cancelled dialog.
  226.                   fileName[0] = '\0';
  227.  
  228.                   // Clear the flag
  229.                   *actionFlag = kODNULL;
  230.  
  231.                   // Display the Open File Dialog to get filename.
  232.                   if (wsData) OpenFileDlg(wsData->parentWindow, fileName);
  233.               }
  234.           }
  235.           else if (strcmp("-k", argv[i]) == 0)
  236.           {
  237.               if ((argc > i+1) && (*argv[i+1] != '-'))
  238.                   strcpy(partKind, argv[++i]);
  239.           }
  240.           else if (strcmp("-c", argv[i]) == 0)
  241.           {
  242.               *actionFlag = kODCreateStationery;
  243.  
  244.               if ((argc > i+1) && (*argv[i+1] != '-'))
  245.                   strcpy(partKind, argv[++i]);
  246.           }
  247.        }
  248.     }
  249.     catch (ODException _exception)
  250.     {
  251.         LOG("SOM exception occured in ApplicationShell::ProcessArgs\n");
  252.         ODSetSOMException(ev, _exception);
  253.     }
  254. }
  255.  
  256. //------------------------------------------------------------------------------
  257. // OpenDocument
  258. //
  259. //      Open a document, creating it if necessary
  260. //------------------------------------------------------------------------------
  261. SOM_Scope ODBoolean  SOMLINK ApplicationShellOpenDocument(
  262.                               ApplicationShell *somSelf, Environment *ev,
  263.                               DocumentManager *docMgr, char *fileName,
  264.                               char *partKind, ODUShort actionFlag)
  265. {
  266.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  267.     ApplicationShellMethodDebug("ApplicationShell",
  268.                                 "ApplicationShellOpenDocument");
  269.  
  270.     ODBoolean   result  = kODTrue;
  271.     ODULong     selInfo = kODKindName;
  272.     struct stat statbuf;
  273.  
  274.     try
  275.     {
  276.         // If neither a filename or part kind name were given, display the
  277.         // part kind selection dialog
  278.         if ((fileName[0] == NULL) && (partKind[0] == NULL))
  279.         {
  280.             char selText[kODMaxFileNameSize];
  281.             selInfo = SelectKindDlg(ev, selText);
  282.  
  283.             if (selInfo == kODFileName)
  284.                 strcpy(fileName, selText);
  285.             else if (selInfo == kODKindName)
  286.                 strcpy(partKind, selText);
  287.             else if (selInfo == kODNoRootPart)
  288.             {
  289.                 OpenFileDlg(somSelf->GetWindowSystemData(ev)->parentWindow,
  290.                                                                     fileName);
  291.                 if (fileName[0] == '\0')
  292.                 {
  293.                     result = kODFalse;
  294.                     selInfo = kODCommandCancel;
  295.                 }
  296.             }
  297.         }
  298.  
  299.         // If SelectKindDialog was presented and the user didn't select Cancel
  300.         if (selInfo != kODCommandCancel)
  301.         {
  302.             // If a file name was specified ...
  303.             if (fileName[0] != '\0')
  304.             {
  305.                 // Open the document for regular document. If document is
  306.                 // read-only and user decides to open the document, then
  307.                 // enter the main loop, else don't enter the main loop.
  308.                 if (!(docMgr->OpenDocumentFromFile(ev, fileName, actionFlag)))
  309.                    // return kODFalse so as not to enter mainloop for regular
  310.                    // document processing 
  311.                    result = kODFalse;
  312.             }
  313.             else
  314.             {
  315.                 // Create a document with the given root part kind.
  316.                 // We don't care at this point if the partKind is valid.
  317.                 // Validity will be checked at a lower level.
  318.  
  319.                 // Check if creating document as stationery or creating a
  320.                 // regular document
  321.                 if (actionFlag == kODCreateStationery)
  322.                 {
  323.                     // return kODFalse so as not to enter mainloop for regular
  324.                     // document processing
  325.                     result = kODFalse;
  326.                     docMgr->CreateDocumentAsStationery(ev, partKind,
  327.                                                                  "NewDoc.od");
  328.                 }
  329.                 else
  330.                    docMgr->CreateDocumentInFile(ev, partKind, "NewDoc.od");
  331.             }
  332.         }
  333.         else // Otherwise the user must have cancelled dialog.
  334.             result = kODFalse;
  335.  
  336.     }
  337.     catch (ODException _exception)
  338.     {
  339.         result = kODFalse;
  340.     SetErrorCodeEv(ev, kODNoError); // Clear the exception
  341.     }
  342.  
  343.     return result;
  344. }
  345.  
  346. //------------------------------------------------------------------------------
  347. // DispatchEvent
  348. //
  349. //    Forward the event the the dispatcher but look for and act upon a
  350. //    few events that are of interest to us.
  351. //------------------------------------------------------------------------------
  352. SOM_Scope ODBoolean  SOMLINK ApplicationShellDispatchEvent(
  353.                                                 ApplicationShell *somSelf,
  354.                                                 Environment *ev,
  355.                                                 ODEventData* event)
  356. {
  357.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  358.     ApplicationShellMethodDebug("ApplicationShell",
  359.                                 "ApplicationShellDispatchEvent");
  360.  
  361.     ODBoolean handled = kODFalse;
  362.  
  363.     try
  364.     {
  365.         ODDispatcher* dispatcher = somSelf->GetDispatcher(ev);
  366.  
  367.         switch (somSelf->GetEventType(ev, event))
  368.         {
  369.             case  kODEvtInitMenu:
  370.             {
  371.                 // Give the parts a chance to adjust their menus before the
  372.                 //    message is sent to the dispatcher.
  373.                 somSelf->AdjustMenu(ev);
  374.             handled = dispatcher->Dispatch(ev, event);
  375.                 break;
  376.             }
  377.  
  378.             case kODEvtActivate:
  379.             {
  380.                 TempODWindow odWindow = somSelf->GetWindowState(ev)->
  381.                         AcquireODWindow(ev, somSelf->GetEventWindow(ev, event));
  382.                 if ((somSelf->GetEventSubType(ev, event) != kODEvtInactive)
  383.                             && odWindow)
  384.                 {
  385.                     somSelf->UpdateActiveDocumentManager(ev, odWindow);
  386.                     odWindow->Select(ev);
  387.                 }
  388.  
  389.                 handled = dispatcher->Dispatch(ev, event);
  390.                 break;
  391.             }
  392.  
  393.             case kODEvtCommand:
  394.             {
  395.                 if (!(handled = somSelf->HandleMenuEvent(ev, event)))
  396.                     handled = dispatcher->Dispatch(ev, event);
  397.                 break;
  398.             }
  399.  
  400.             case OD_HELP:
  401.             {
  402.                 handled = dispatcher->Dispatch(ev, event);  // Let Part override
  403.  
  404.                 if (!handled)
  405.                 {
  406.                   ODUShort context = somSelf->GetEventSubType(ev, event);
  407.                   if (context == HLPM_ODMENU)   // If F1 on Menu Item
  408.                   {
  409.                     handled = somSelf->HandleHelpEvent(ev, event);  // Handle base menu
  410.                     if (!handled) // if no help found for menu
  411.                     {
  412.                       ODHelp *helpMe = somSelf->GetSession(ev)->GetHelp(ev);
  413.                       helpMe->DisplayHelp(ev, ODHELPFILE, IDMS_NO_HELP_PROVIDED_PANEL);
  414.                     }
  415.                   }
  416.                   else if (context == HLPM_ODWINDOW)  // If F1 on window or part
  417.                   {
  418.                     ODHelp *helpMe = somSelf->GetSession(ev)->GetHelp(ev);
  419.                     helpMe->DisplayHelp(ev, ODHELPFILE, OPENDOC_HELP_PANEL);
  420.                   }
  421.                 }
  422.                 break;
  423.             }
  424.  
  425.             default:
  426.             {
  427.                 if (!(handled = ApplicationShell_parents_DispatchEvent(
  428.                                                            somSelf,ev, event)))
  429.                 {
  430.                     switch (somSelf->GetEventType(ev, event))
  431.                     {
  432.                         case kODEvtClose:
  433.                             handled = somSelf->HandleCloseEvent(ev, event);
  434.                             break;
  435.                     }
  436.                 }
  437.             }
  438.         }
  439.     }
  440.  
  441.     catch (ODException _exception)
  442.     {
  443.         LOG("SOM exception occured in ApplicationShell::DispatchEvent\n");
  444.     ODSetSOMException(ev, _exception);
  445.     }
  446.  
  447.     return handled;
  448.  
  449. }
  450.  
  451. //------------------------------------------------------------------------------
  452. // CreateMenuBar
  453. //
  454. //      Create the default base menubar for the docshell.  A subclass must
  455. //      provide an implementation of this platform-dependent method.
  456. //------------------------------------------------------------------------------
  457. SOM_Scope void  SOMLINK ApplicationShellCreateMenuBar(
  458.                                     ApplicationShell *somSelf, Environment *ev)
  459. {
  460.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  461.     ApplicationShellMethodDebug("ApplicationShell",
  462.                                 "ApplicationShellCreateMenuBar");
  463.  
  464.     somSelf->SubClassResponsibility(ev, "ApplicationShell::CreateMenuBar");
  465. }
  466.  
  467. //------------------------------------------------------------------------------
  468. // InitWindowSystem
  469. //
  470. //      Initialize the platform window system.  A subclass must provide an
  471. //      implementation of this platform-dependent method.
  472. //------------------------------------------------------------------------------
  473. SOM_Scope void  SOMLINK ApplicationShellInitWindowSystem(
  474.                                     ApplicationShell *somSelf, Environment *ev)
  475. {
  476.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  477.     ApplicationShellMethodDebug("ApplicationShell",
  478.                                          "ApplicationShellInitWindowSystem");
  479.  
  480.     somSelf->SubClassResponsibility(ev, "ApplicationShell::InitWindowSystem");
  481. }
  482.  
  483. //------------------------------------------------------------------------------
  484. // Exec
  485. //
  486. //      Spawn another docshell process.  A subclass must provide an
  487. //      implementation of this platform-dependent method.
  488. //------------------------------------------------------------------------------
  489. SOM_Scope void  SOMLINK ApplicationShellExec(ApplicationShell *somSelf,
  490.                                              Environment *ev,
  491.                                              char* str)
  492. {
  493.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  494.     ApplicationShellMethodDebug("ApplicationShell","ApplicationShellExec");
  495.  
  496.     somSelf->SubClassResponsibility(ev, "ApplicationShell::Exec");
  497. }
  498.  
  499. //------------------------------------------------------------------------------
  500. // MainLoop
  501. //
  502. //      Provide the event processing loop.  A subclass must provide an
  503. //      implementation of this platform-dependent method.
  504. //------------------------------------------------------------------------------
  505. SOM_Scope ODSLong  SOMLINK ApplicationShellMainLoop(ApplicationShell *somSelf,
  506.                                                   Environment *ev)
  507. {
  508.     ///* ApplicationShellData *somThis = ApplicationShellGetData(somSelf); */
  509.     ApplicationShellMethodDebug("ApplicationShell","ApplicationShellMainLoop");
  510.  
  511.     somSelf->SubClassResponsibility(ev, "ApplicationShell::MainLoop");
  512.     return 0;
  513. }
  514.  
  515. //------------------------------------------------------------------------------
  516. // HandleMenuEvent
  517. //
  518. //      Handle incoming events from menubar activity.
  519. //------------------------------------------------------------------------------
  520. SOM_Scope ODBoolean  SOMLINK ApplicationShellHandleMenuEvent(
  521.                                                   ApplicationShell *somSelf,
  522.                                                   Environment *ev,
  523.                                                   ODEventData* event)
  524. {
  525.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  526.     ApplicationShellMethodDebug("ApplicationShell",
  527.                                             "ApplicationShellHandleMenuEvent");
  528.  
  529.     ODBoolean handled = kODTrue;
  530.  
  531.     try
  532.     {
  533.         if (somSelf->GetEventType(ev,event) == kODEvtCommand)
  534.         {
  535.             switch (somSelf->GetEventSubType(ev,event))
  536.             {
  537.                 case kODCommandNew:
  538.                     somSelf->DocumentNew(ev);
  539.                     break;
  540.  
  541.                 case kODCommandOpenDocument:
  542.                     somSelf->DocumentOpen(ev);
  543.                     break;
  544.  
  545.                 case kODCommandSave:
  546.                     somSelf->DocumentSave(ev);
  547.                     break;
  548.  
  549.                 case kODCommandSaveACopy:
  550.                     somSelf->DocumentSaveAs(ev);
  551.                     break;
  552.  
  553.                 case kODCommandRevert:
  554.                     somSelf->DocumentRevert(ev);
  555.                     break;
  556.  
  557.                 case kODCommandDraftCreate:
  558.                     somSelf->DocumentDraftCreate(ev);
  559.                     break;
  560.  
  561.                 case kODCommandDraftHist:
  562.                     somSelf->DocumentDraftHistory(ev);
  563.                     break;
  564.  
  565.                 case kODCommandDocumentInfo:
  566.                     somSelf->DocumentInfo(ev);
  567.                     break;
  568.  
  569.                 case kODCommandPageSetup:
  570.                     somSelf->DocumentPageSetup(ev, event);
  571.                     break;
  572.  
  573.                 case kODCommandPrint:
  574.                     somSelf->DocumentPrint(ev, event);
  575.                     break;
  576.  
  577.                 case kODCommandClose:
  578.                     somSelf->DocumentClose(ev);
  579.                     break;
  580.  
  581.                 case kODCommandHelpIndex:
  582.                     {
  583.                         ODHelp *helpMe = somSelf->GetSession(ev)->GetHelp(ev);
  584.                         helpMe->DisplayHelpIndex(ev,ODHELPFILE);
  585.                     }
  586.                     break;
  587.  
  588.                 case kODCommandHelpGeneral:
  589.                     {
  590.                         ODHelp *helpMe = somSelf->GetSession(ev)->GetHelp(ev);
  591.                         helpMe->DisplayHelp(ev,ODHELPFILE,OPENDOC_HELP_PANEL);
  592.                     }
  593.                     break;
  594.  
  595.                  case kODCommandHelpUsing:
  596.                     {
  597.                         ODHelp *helpMe = somSelf->GetSession(ev)->GetHelp(ev);
  598.                         helpMe->DisplayHelpUsingHelp(ev,ODHELPFILE);
  599.                     }
  600.                     break;
  601.  
  602.                 case kODCommandHelpInfo:
  603.                     somSelf->DocumentAbout(ev);
  604.                     break;
  605.  
  606.                 case kODCommandUndo:
  607.                     somSelf->GetSession(ev)->GetUndo(ev)->Undo(ev);
  608.                     break;
  609.  
  610.                 case kODCommandRedo:
  611.                     somSelf->GetSession(ev)->GetUndo(ev)->Redo(ev);
  612.                     break;
  613.  
  614.                 default:
  615.                     handled = kODFalse;
  616.                     break;
  617.             } // end switch
  618.         }
  619.         else
  620.             handled = kODFalse;
  621.  
  622.     }
  623.     catch (ODException _exception)
  624.     {
  625.         LOG("SOM exception occured in ApplicationShell::HandleMenuEvent\n");
  626.         ODSetSOMException(ev, _exception);
  627.     }
  628.  
  629.     return handled;
  630. }
  631.  
  632. //------------------------------------------------------------------------------
  633. // HandleCloseEvent
  634. //
  635. //      Handle incoming events from menubar activity
  636. //------------------------------------------------------------------------------
  637. SOM_Scope ODBoolean  SOMLINK ApplicationShellHandleCloseEvent(
  638.                                                   ApplicationShell *somSelf,
  639.                                                   Environment *ev,
  640.                                                   ODEventData* event)
  641. {
  642.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  643.     ApplicationShellMethodDebug("ApplicationShell",
  644.                                             "ApplicationShellHandleCloseEvent");
  645.  
  646.     DocumentManager     *docMgr;
  647.     ODULong             changes = kODCommandCancel;
  648.     ODBoolean           handled = kODTrue;
  649.  
  650.     try
  651.     {
  652.  
  653.       docMgr = somSelf->GetActiveDocumentManager(ev);
  654.  
  655.       // Find out if window requesting to be closed is the Root Window. If not
  656.       // a root window, docMgr->CloseWindow will take care of closing it down.
  657.       ODULong isRootWindow = docMgr->CloseWindow(ev,
  658.                              somSelf->GetEventWindow(ev, event), kODTrue);
  659.  
  660.       // If it is a root window, we will need to do some extra work before
  661.       // closing the window.
  662.       if (isRootWindow)
  663.       {
  664.           changes = somSelf->GetEventSubType(ev,event);
  665.  
  666.           // if event not requesting to suppress close confirmation dialog
  667.           // pop it up.
  668.           if ((changes != kODCommandSaveChanges) &&
  669.               (changes != kODCommandDiscardChanges))
  670.           {
  671.               // If draft is not dirty, then bring up the dialog to confirm
  672.               // exiting of docshell. If draft is marked dirty, then bring
  673.               // up the dialog to confirm save changes or not.
  674.               ODDraft *draft = docMgr->GetDraft(ev);
  675.               if (draft && draft->ChangedFromPrev(ev) &&
  676.                   (draft->GetPermissions(ev) >= kODDPSharedWrite))
  677.                  changes = ConfirmCloseDlg(ev);
  678.               else
  679.                  changes = ConfirmExitDlg(ev);
  680.           }
  681.  
  682.           // if user didn't ask to cancel the close, proceed.
  683.           if (changes != kODCommandCancel)
  684.           {
  685.               // Close the document, passing in type of close (whether
  686.               // to save changes or not) chosen in Close dialog.
  687.               docMgr->CloseDocument(ev, changes);
  688.  
  689.               // Delete the document manager
  690.               somSelf->DeleteDocumentManager(ev, docMgr);
  691.               somSelf->SetActiveDocumentManager(ev, (DocumentManager*) kODNULL);
  692.  
  693.               // do any required clean for close to complete.
  694.               somSelf->CloseCleanup(ev);
  695.  
  696.               // Set handled to false, so ODDispatchEvent will close down.
  697.               handled = kODFalse;
  698.             }
  699.         }
  700.     }
  701.     catch (ODException _exception)
  702.     {
  703.     WARNMSG(WARN_INDEX(AMSG_570), "Docshell: Error %d returned during closing down of the document.\nDocument may not save correctly.", ErrorCode());
  704.  
  705.         // Clear the exception
  706.         SetErrorCodeEv(ev, kODNoError);
  707.  
  708.         if (changes != kODCommandCancel)
  709.         {
  710.             try
  711.             {
  712.                somSelf->CloseCleanup(ev);
  713.             }
  714.             catch (ODException _exception)
  715.             {
  716.                // Clear the exception
  717.                SetErrorCodeEv(ev, kODNoError);
  718.             }
  719.         }
  720.     }
  721.  
  722.     return handled;
  723. }
  724.  
  725. //------------------------------------------------------------------------------
  726. // HandleHelpEvent
  727. //
  728. //    Handle incoming help events
  729. //------------------------------------------------------------------------------
  730. SOM_Scope ODBoolean  SOMLINK ApplicationShellHandleHelpEvent(
  731.                                                   ApplicationShell *somSelf,
  732.                                                   Environment *ev,
  733.                                                   ODEventData* event)
  734. {
  735.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  736.     ApplicationShellMethodDebug("ApplicationShell",
  737.                                             "ApplicationShellHandleHelpEvent");
  738.     int        menuID;
  739.     ODULong    helpID;
  740.     ODBoolean    handled = kODTrue;
  741.     ODHelp    *helpMe;
  742.  
  743.     #ifdef _PLATFORM_OS2_
  744.     menuID      = SHORT1FROMMP(event->mp2);
  745.     #endif //_PLATFORM_OS2_
  746.     #ifdef _PLATFORM_WIN32_
  747.     menuID      = event->lParam;
  748.     #endif //_PLATFORM_WIN32_
  749.     #ifdef _PLATFORM_AIX_
  750.     menuID = 0;     // Handle Help Event is NOP on AIX, menu widget has callback
  751.     #endif //_PLATFORM_AIX_
  752.  
  753.     try
  754.     {
  755.         helpMe = somSelf->GetSession(ev)->GetHelp(ev);
  756.         helpID = helpMe->GetHelpID(ev, menuID);
  757.         if (helpID)
  758.             helpMe->DisplayHelp(ev, ODHELPFILE, helpID);
  759.         else
  760.             handled = kODFalse;
  761.     }
  762.  
  763.     catch (ODException _exception)
  764.     {
  765.         LOG("SOM exception occured in ApplicationShell::HandleHelpEvent\n");
  766.         ODSetSOMException(ev, _exception);
  767.     }
  768.  
  769.     return handled;
  770. }
  771.  
  772. //------------------------------------------------------------------------------
  773. // DocumentNew
  774. //
  775. //      Exec a new docshell with the same root part kind as the current
  776. //      document.
  777. //------------------------------------------------------------------------------
  778. SOM_Scope void  SOMLINK ApplicationShellDocumentNew(ApplicationShell *somSelf,
  779.                                                     Environment *ev)
  780. {
  781.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  782.     ApplicationShellMethodDebug("ApplicationShell",
  783.                                                 "ApplicationShellDocumentNew");
  784.  
  785.     DocumentManager    *docMgr;
  786.     char        str[kODMaxFileNameSize];
  787.  
  788.     try
  789.     {
  790.         docMgr = somSelf->GetActiveDocumentManager(ev);
  791.         sprintf(str, "%s -k %s", _fExecString, docMgr->GetPartKindName(ev));
  792.         somSelf->Exec(ev, str);
  793.  
  794.     }
  795.     catch (ODException _exception)
  796.     {
  797.         LOG("SOM exception occured in ApplicationShell::DocumentNew\n");
  798.         ODSetSOMException(ev, _exception);
  799.     }
  800. }
  801.  
  802.  
  803. //------------------------------------------------------------------------------
  804. // DocumentOpen
  805. //
  806. //      Get a document name from the user and exec a new docshell for that
  807. //      document.
  808. //------------------------------------------------------------------------------
  809. SOM_Scope void  SOMLINK ApplicationShellDocumentOpen(ApplicationShell *somSelf,
  810.                                                      Environment *ev)
  811. {
  812.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  813.     ApplicationShellMethodDebug("ApplicationShell",
  814.                                              "ApplicationShellDocumentOpen");
  815.  
  816.     char         docName[kODMaxFileNameSize] = "";
  817.     char         str[kODMaxFileNameSize] = "";
  818.  
  819.     try
  820.     {
  821.         ODWindowState* WinStat = somSelf->GetWindowState(ev);
  822.  
  823.         // Use TempODWindow so this object won't have to be released.
  824.         TempODWindow Window = WinStat->AcquireActiveWindow(ev);
  825.  
  826.         // Display the Open File Dialog to get filename.
  827.         OpenFileDlg(Window->GetPlatformWindow(ev), docName);
  828.  
  829.         if (strcmp(docName,"\0") != 0)
  830.         {
  831.             // launch another copy of the shell to open the passed in file name
  832.             sprintf(str, "%s -f \"%s\"", _fExecString, docName);
  833.             somSelf->Exec(ev, str);
  834.         }
  835.     }
  836.     catch (ODException _exception)
  837.     {
  838.         LOG("SOM exception occured in ApplicationShell::DocumentOpen\n");
  839.         ODSetSOMException(ev, _exception);
  840.     }
  841. }
  842.  
  843. //------------------------------------------------------------------------------
  844. // DocumentSave
  845. //
  846. //      Save the document
  847. //------------------------------------------------------------------------------
  848. SOM_Scope void  SOMLINK ApplicationShellDocumentSave(ApplicationShell *somSelf,
  849.                                                      Environment *ev)
  850. {
  851.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  852.     ApplicationShellMethodDebug("ApplicationShell",
  853.                                                "ApplicationShellDocumentSave");
  854.  
  855.     try
  856.     {
  857.         somSelf->GetActiveDocumentManager(ev)->SaveDocument(ev);
  858.     }
  859.     catch (ODException _exception)
  860.     {
  861.         WARNMSG(WARN_INDEX(AMSG_912), "CPPOD0459 - Docshell: Error %d returned when saving document.\\nDocument may not save correctly.", ErrorCode());
  862.         ODSetSOMException(ev, _exception);
  863.     }
  864. }
  865.  
  866. //------------------------------------------------------------------------------
  867. // DocumentSaveAs
  868. //
  869. //      Save a copy of this document in a new file specified by the user
  870. //------------------------------------------------------------------------------
  871. SOM_Scope void  SOMLINK ApplicationShellDocumentSaveAs(
  872.                                    ApplicationShell *somSelf, Environment *ev)
  873. {
  874.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  875.     ApplicationShellMethodDebug("ApplicationShell",
  876.                                              "ApplicationShellDocumentSaveAs");
  877.  
  878.     PlatformFile *file = kODNULL;
  879.  
  880.     try
  881.     {
  882.            ODWindowState *winStat = somSelf->GetWindowState(ev);
  883.            TempODWindow odWindow = winStat->AcquireActiveWindow(ev);
  884.  
  885.         file = SaveFileDlg(ev);
  886.         if (file)
  887.     {
  888.         ODDraft *draft = odWindow->GetDraft(ev);
  889.             if (draft)
  890.                 somSelf->GetActiveDocumentManager(ev)->
  891.                                                   SaveACopyAs(ev, draft, file);
  892.     }
  893.     }
  894.     catch (ODException _exception)
  895.     {
  896.         LOG("SOM exception occured in ApplicationShell::DocumentSaveAs\n");
  897.         ODSetSOMException(ev, _exception);
  898.     }
  899.  
  900.     delete file;
  901. }
  902.  
  903. //------------------------------------------------------------------------------
  904. // DocumentRevert
  905. //
  906. //      Discard all of the changes to this document since the last save
  907. //      was performed, but confirm this with the user first.
  908. //------------------------------------------------------------------------------
  909. SOM_Scope void  SOMLINK ApplicationShellDocumentRevert(
  910.                                     ApplicationShell *somSelf, Environment *ev)
  911. {
  912.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  913.     ApplicationShellMethodDebug("ApplicationShell",
  914.                                             "ApplicationShellDocumentRevert");
  915.  
  916.     try
  917.     {
  918.         if (ConfirmRevertDlg(ev))
  919.             somSelf->GetActiveDocumentManager(ev)->Revert(ev);
  920.     }
  921.     catch (ODException _exception)
  922.     {
  923.         LOG("SOM exception occured in ApplicationShell::DocumentRevert\n");
  924.         ODSetSOMException(ev, _exception);
  925.     }
  926. }
  927.  
  928. //------------------------------------------------------------------------------
  929. // DocumentDraftCreate
  930. //
  931. //      Display the Create Draft dialog
  932. //------------------------------------------------------------------------------
  933. SOM_Scope void  SOMLINK ApplicationShellDocumentDraftCreate(
  934.                                     ApplicationShell *somSelf, Environment *ev)
  935. {
  936.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  937.     ApplicationShellMethodDebug("ApplicationShell",
  938.                                       "ApplicationShellDocumentDraftCreate");
  939.  
  940.  
  941.     ODDraft*       draft = kODNULL;
  942.     ODStorageUnit* su = kODNULL;
  943.     ODULong        draftnum = 0;
  944.  
  945.     try
  946.     {
  947.         draft = somSelf->GetActiveDocumentManager(ev)->
  948.                                                 GetLatestCreatedDraft(ev);
  949.  
  950.         if (draft)
  951.         {
  952.             // Acquire the storage unit containing the draft properties.
  953.             su = draft->AcquireDraftProperties(ev);
  954.  
  955.             // Retrieve draft number
  956.             draftnum = ODGetULongProp(ev, su, kODPropDraftNumber, kODULong);
  957.  
  958.             // Release the storage unit
  959.             ODReleaseObject(ev,su);
  960.         }
  961.  
  962.         // Release the draft
  963.         ODReleaseObject(ev,draft);
  964.  
  965.         CreateDraftDlg(ev,draftnum);
  966.     }
  967.     catch (ODException _exception)
  968.     {
  969.         LOG("SOM exception occured in ApplicationShell::DocumentDraftCreate\n");
  970.         ODError error = ErrorCode();
  971.         if (draft || su)
  972.            SaveAndRestoreEv2(draft, su);
  973.         ODSetSOMException(ev, error);
  974.     }
  975. }
  976.  
  977. //------------------------------------------------------------------------------
  978. // DocumentDraftHistory
  979. //
  980. //      Display the Draft History dialog.
  981. //------------------------------------------------------------------------------
  982. SOM_Scope void  SOMLINK ApplicationShellDocumentDraftHistory(
  983.                                    ApplicationShell *somSelf, Environment *ev)
  984. {
  985.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  986.     ApplicationShellMethodDebug("ApplicationShell",
  987.                                       "ApplicationShellDocumentDraftHistory");
  988.  
  989.     ODWindowState* winStat;
  990.     ODPlatformWindow window;
  991.     DraftWindow* dw = kODNULL;
  992.  
  993.     try
  994.     {
  995.         winStat = somSelf->GetWindowState(ev);
  996.         TempODWindow odWindow = winStat->AcquireActiveWindow(ev);
  997.         window = odWindow->GetPlatformWindow(ev);
  998.  
  999.         dw = new DraftWindow(somSelf->GetActiveDocumentManager(ev),
  1000.                              somSelf->GetWindowSystemData(ev), window);
  1001.  
  1002.         dw->DraftHistory();
  1003.  
  1004.         // The dw object will be deleted within the draft history dialog
  1005.         // function when the dialog is brought down.
  1006.     }
  1007.     catch (ODException _exception)
  1008.     {
  1009.         LOG("SOM exception occured in ApplicationShell::DocumentDraftHistory\n");
  1010.         ODError error = ErrorCode();
  1011.         SaveEv();
  1012.         if (dw)
  1013.             delete dw;
  1014.         RestoreEv();
  1015.         ODSetSOMException(ev, error);
  1016.     }
  1017. }
  1018.  
  1019. //------------------------------------------------------------------------------
  1020. // DocumentInfo
  1021. //
  1022. //      Display the Document Info dialog.
  1023. //------------------------------------------------------------------------------
  1024. SOM_Scope void  SOMLINK ApplicationShellDocumentInfo(ApplicationShell *somSelf,
  1025.                                                      Environment *ev)
  1026. {
  1027.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1028.     ApplicationShellMethodDebug("ApplicationShell",
  1029.                                               "ApplicationShellDocumentInfo");
  1030.  
  1031.     ODWindowState* winState;
  1032.     ODSession* session;
  1033.     ODInfo* info;
  1034.  
  1035.     try
  1036.     {
  1037.         winState = somSelf->GetWindowState(ev);
  1038.         TempODWindow odWindow = winState->AcquireActiveWindow(ev);
  1039.         session = somSelf->GetSession(ev);
  1040.         info = session->GetInfo(ev);
  1041.  
  1042.         info->ShowPartFrameInfo(ev, odWindow->GetRootFacet(ev),
  1043.                 somSelf->GetActiveDocumentManager(ev)->HasWriteAccess(ev));
  1044.     }
  1045.     catch (ODException _exception)
  1046.     {
  1047.         LOG("SOM exception occured in ApplicationShell::DocumentInfo\n");
  1048.         ODSetSOMException(ev, _exception);
  1049.     }
  1050. }
  1051.  
  1052. //------------------------------------------------------------------------------
  1053. // DocumentPageSetup
  1054. //
  1055. //      Send the PageSetup menu event to the root part
  1056. //------------------------------------------------------------------------------
  1057. SOM_Scope void  SOMLINK ApplicationShellDocumentPageSetup(
  1058.                                     ApplicationShell *somSelf, Environment *ev,
  1059.                                     ODEventData* event)
  1060. {
  1061.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1062.     ApplicationShellMethodDebug("ApplicationShell",
  1063.                                          "ApplicationShellDocumentPageSetup");
  1064.  
  1065.     try
  1066.     {
  1067.        somSelf->SendEventToRootPart(ev, event);
  1068.     }
  1069.     catch (ODException _exception)
  1070.     {
  1071.         LOG("SOM exception occured in ApplicationShell::DocumentPageSetup\n");
  1072.         ODSetSOMException(ev, _exception);
  1073.     }
  1074. }
  1075.  
  1076. //------------------------------------------------------------------------------
  1077. // DocumentPrint
  1078. //
  1079. //      Send the Print menu event to the root part
  1080. //------------------------------------------------------------------------------
  1081. SOM_Scope void  SOMLINK ApplicationShellDocumentPrint(
  1082.                                    ApplicationShell *somSelf, Environment *ev,
  1083.                                    ODEventData* event)
  1084. {
  1085.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1086.     ApplicationShellMethodDebug("ApplicationShell",
  1087.                                             "ApplicationShellDocumentPrint");
  1088.  
  1089.     try
  1090.     {
  1091.        somSelf->SendEventToRootPart(ev, event);
  1092.     }
  1093.     catch (ODException _exception)
  1094.     {
  1095.         LOG("SOM exception occured in ApplicationShell::DocumentPrint\n");
  1096.         ODSetSOMException(ev, _exception);
  1097.     }
  1098. }
  1099.  
  1100. //------------------------------------------------------------------------------
  1101. // DocumentClose
  1102. //------------------------------------------------------------------------------
  1103. SOM_Scope void  SOMLINK ApplicationShellDocumentClose(
  1104.                                    ApplicationShell *somSelf, Environment *ev)
  1105. {
  1106.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1107.     ApplicationShellMethodDebug("ApplicationShell",
  1108.                                              "ApplicationShellDocumentClose");
  1109.  
  1110.     //  This method gets overridden by the platform shell class because it
  1111.     //  needs to make platform dependent calls.
  1112.     somSelf->SubClassResponsibility(ev, "ApplicationShell::DocumentClose");
  1113. }
  1114.  
  1115. //------------------------------------------------------------------------------
  1116. // DocumentAbout
  1117. //
  1118. //      Display the OpenDoc Information dialog
  1119. //------------------------------------------------------------------------------
  1120. SOM_Scope void  SOMLINK ApplicationShellDocumentAbout(
  1121.                                    ApplicationShell *somSelf, Environment *ev)
  1122. {
  1123.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1124.     ApplicationShellMethodDebug("ApplicationShell",
  1125.                                              "ApplicationShellDocumentAbout");
  1126.  
  1127.     // For the time being just display a message box
  1128.     AboutDlg(ev);
  1129. }
  1130.  
  1131. //------------------------------------------------------------------------------
  1132. // AdjustMenu
  1133. //
  1134. //      Update our menus items for the present context and then tell the
  1135. //      parts to do the same.
  1136. //------------------------------------------------------------------------------
  1137. SOM_Scope void  SOMLINK ApplicationShellAdjustMenu(
  1138.                                    ApplicationShell *somSelf, Environment *ev)
  1139. {
  1140.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1141.     ApplicationShellMethodDebug("ApplicationShell","AdjustMenu");
  1142.  
  1143.     ODWindowState* winState;
  1144.     ODDraft* draft;
  1145.  
  1146.     try
  1147.     {
  1148.         winState = somSelf->GetWindowState(ev);
  1149.         TempODMenuBar currentMenuBar = winState->AcquireCurrentMenuBar(ev);
  1150.         draft = somSelf->GetActiveDocumentManager(ev)->GetDraft(ev);
  1151.  
  1152.         if (currentMenuBar)
  1153.         {
  1154.             ODBoolean unsavedChanges = kODFalse;
  1155.  
  1156.             // if draft has write access, then check if draft is marked
  1157.             // dirty or not so as to enable/disable Save and Revert menu
  1158.             // items accordingly. Otherwise disable Save and Revert menu
  1159.             // items.
  1160.             if (draft && draft->GetPermissions(ev) >= kODDPSharedWrite)
  1161.                 unsavedChanges = draft->ChangedFromPrev(ev);
  1162.  
  1163.             currentMenuBar->EnableMenuItem(ev, kODCommandDocumentMenu,
  1164.                                         kODCommandRevert, unsavedChanges);
  1165.             currentMenuBar->EnableMenuItem(ev, kODCommandDocumentMenu,
  1166.                                         kODCommandSave, unsavedChanges);
  1167.             currentMenuBar->EnableMenuItem(ev, kODCommandViewMenu,
  1168.                                         kODCommandViewAsWin, kODFalse);
  1169.             currentMenuBar->EnableMenuItem(ev, kODCommandViewMenu,
  1170.                                         kODCommandViewProperties, kODFalse);
  1171.             currentMenuBar->EnableMenuItem(ev, kODCommandViewMenu,
  1172.                                         kODCommandViewShowAs, kODFalse);
  1173.  
  1174.             // Some platforms automatically disable submenus on creation.
  1175.             // Therefore, we enable Drafts to ensure it can be used.
  1176.             currentMenuBar->EnableMenu(ev, kODCommandDraftsMenu, kODTrue);
  1177.  
  1178.             if (draft && !(draft->GetPermissions(ev) >= kODDPSharedWrite))
  1179.                 currentMenuBar->EnableMenuItem(ev, kODCommandDraftsMenu,
  1180.                                         kODCommandDraftCreate, kODFalse);
  1181.  
  1182.             somSelf->UpdateUndoMenus(ev);
  1183.  
  1184.             // Let the parts have a last crack at the menus.
  1185.             winState->AdjustPartMenus(ev);
  1186.         }
  1187.     }
  1188.     catch (ODException _exception)
  1189.     {
  1190.         LOG("SOM exception occured in ApplicationShell::AdjustMenu\n");
  1191.         ODSetSOMException(ev, _exception);
  1192.     }
  1193. }
  1194.  
  1195. //------------------------------------------------------------------------------
  1196. // UpdateUndoMenus
  1197. //
  1198. //      Enable or disable the Undo and Redo menu items as appropriate.
  1199. //------------------------------------------------------------------------------
  1200. SOM_Scope void  SOMLINK ApplicationShellUpdateUndoMenus(
  1201.                                     ApplicationShell *somSelf, Environment *ev)
  1202. {
  1203.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1204.     ApplicationShellMethodDebug("ApplicationShell","UpdateUndoMenus");
  1205.  
  1206.     ODName    *actionLabel = kODNULL;
  1207.     char      *str = kODNULL, *tmpstr = kODNULL;
  1208.     char      *accel = "";
  1209.  
  1210.     try
  1211.     {
  1212.  
  1213.         ODSession       *Session = somSelf->GetSession(ev);
  1214.         ODUndo          *undo = Session->GetUndo( ev );
  1215.         ODPart          *part;
  1216.         ODActionData    actionData;
  1217.         ODActionType    actionType;
  1218.  
  1219.         ODWindowState*  WinState = somSelf->GetWindowState(ev);
  1220.         TempODMenuBar   currentMenu = WinState->AcquireCurrentMenuBar( ev );
  1221.  
  1222.         actionLabel = CreateIText(ACTION_LABEL_LENGTH);
  1223.         actionData._buffer = kODNULL;
  1224.  
  1225.         // Get string for accelerator 
  1226. #if (defined  _PLATFORM_WIN32_) 
  1227.         accel = catgets(ODcat_handle,DOCSH_SET,DOCMSG_96,"\tCtrl+Z");
  1228. #elif (defined _PLATFORM_OS2_)
  1229.         accel = catgets(ODcat_handle,DOCSH_SET,DOCMSG_94,"\tAlt+Backspace");
  1230. #endif
  1231.         if (undo->PeekUndoHistory(ev, &part, &actionData, &actionType,
  1232.                                                                   actionLabel))
  1233.         {
  1234.             currentMenu->EnableMenuItem(ev, kODCommandEditMenu, kODCommandUndo,
  1235.                                                                       kODTrue);
  1236.             str = GetITextString(actionLabel, (char*)kODNULL);
  1237.             tmpstr = new char [strlen(str) + strlen(accel) + 1];
  1238.             strcpy (tmpstr, str); strcat (tmpstr, accel);
  1239.             currentMenu->SetMenuItemText(ev, kODCommandEditMenu,
  1240.                                                        kODCommandUndo, tmpstr);
  1241.             if (str)
  1242.             {
  1243.                delete[] str;
  1244.                str = kODNULL;
  1245.             }
  1246.  
  1247.         }  
  1248.         else
  1249.         {
  1250.             currentMenu->EnableMenuItem(ev, kODCommandEditMenu, kODCommandUndo,
  1251.                                                                 kODFalse);
  1252.         char *undoStr = catgets(ODcat_handle, DOCSH_SET, DOCMSG_43, "Undo");
  1253.             tmpstr = new char [strlen(undoStr) + strlen(accel) + 1];
  1254.             strcpy (tmpstr, undoStr); strcat (tmpstr, accel);
  1255.             currentMenu->SetMenuItemText(ev, kODCommandEditMenu,
  1256.                                                        kODCommandUndo, tmpstr);
  1257.         }
  1258.         delete [] tmpstr;
  1259.         tmpstr = kODNULL;
  1260.  
  1261.         // Get string for accelerator 
  1262. #if (defined  _PLATFORM_WIN32_) 
  1263.         accel=catgets(ODcat_handle,DOCSH_SET,DOCMSG_97,"\tCtrl+Y");
  1264. #elif (defined _PLATFORM_OS2_)
  1265.         accel=catgets(ODcat_handle,DOCSH_SET,DOCMSG_95,"\tShift+Alt+Backspace");
  1266. #endif
  1267.         if (undo->PeekRedoHistory(ev, &part, &actionData, &actionType,
  1268.                                                                   actionLabel))
  1269.         {
  1270.             currentMenu->EnableMenuItem(ev, kODCommandEditMenu, kODCommandRedo,
  1271.                                                                 kODTrue);
  1272.             str = GetITextString(actionLabel, (char*)kODNULL);
  1273.             tmpstr = new char [strlen(str) + strlen(accel) + 1];
  1274.             strcpy (tmpstr, str); strcat (tmpstr, accel);
  1275.             currentMenu->SetMenuItemText(ev, kODCommandEditMenu,
  1276.                                                        kODCommandRedo, tmpstr);
  1277.             if (str)
  1278.             {
  1279.                delete[] str;
  1280.                str = kODNULL;
  1281.             }
  1282.         }
  1283.         else
  1284.         {
  1285.             currentMenu->EnableMenuItem(ev, kODCommandEditMenu, kODCommandRedo,
  1286.                                                                 kODFalse);
  1287.         char *redoStr = catgets(ODcat_handle, DOCSH_SET, DOCMSG_44, "Redo");
  1288.             tmpstr = new char [strlen(redoStr) + strlen(accel) + 1];
  1289.             strcpy (tmpstr, redoStr); strcat (tmpstr, accel);
  1290.             currentMenu->SetMenuItemText(ev, kODCommandEditMenu, 
  1291.                                                        kODCommandRedo, tmpstr);
  1292.         }
  1293.  
  1294.         delete [] tmpstr;
  1295.         tmpstr = kODNULL;
  1296.         DisposeIText( actionLabel );
  1297.         actionLabel = kODNULL;
  1298.  
  1299.     }
  1300.     catch (ODException _exception)
  1301.     {
  1302.         LOG("SOM exception occured in ApplicationShell::UpdateUndoMenus\n");
  1303.         if (str)
  1304.            delete[] str;
  1305.         if (tmpstr)
  1306.            delete [] tmpstr;
  1307.         if (actionLabel)
  1308.            DisposeIText(actionLabel);
  1309.  
  1310.         ODSetSOMException(ev, _exception);
  1311.     }
  1312.  
  1313. }
  1314.  
  1315. //------------------------------------------------------------------------------
  1316. // SendEventToRootPart
  1317. //
  1318. //      Send the event directly to the root part
  1319. //------------------------------------------------------------------------------
  1320. SOM_Scope void  SOMLINK ApplicationShellSendEventToRootPart(
  1321.                                     ApplicationShell *somSelf, Environment *ev,
  1322.                                     ODEventData* event)
  1323. {
  1324.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1325.     ApplicationShellMethodDebug("ApplicationShell",
  1326.                                         "ApplicationShellSendEventToRootPart");
  1327.  
  1328.     try
  1329.     {
  1330.         TempODWindow window =
  1331.                 somSelf->GetWindowState(ev)->AcquireActiveWindow(ev);
  1332.         ODFrame *rootFrame = window->GetRootFrame(ev);
  1333.         TempODPart rootPart = rootFrame->AcquirePart(ev);
  1334.         rootPart->HandleEvent(ev, event, rootFrame, kODNULL, kODNULL);
  1335.     }
  1336.     catch (ODException _exception)
  1337.     {
  1338.         LOG("SOM exception occured in ApplicationShell::SendEventToRootPart\n");
  1339.         ODSetSOMException(ev, _exception);
  1340.     }
  1341. }
  1342.  
  1343. //------------------------------------------------------------------------------
  1344. // CloseCleanup
  1345. //
  1346. //      Perform cleanup tasks not done in other methods during the close
  1347. //    process.  A subclass must provide an implementation of this
  1348. //      platform-dependent method.
  1349. //------------------------------------------------------------------------------
  1350. SOM_Scope void  SOMLINK ApplicationShellCloseCleanup(
  1351.                                     ApplicationShell *somSelf, Environment *ev)
  1352. {
  1353.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1354.     ApplicationShellMethodDebug("ApplicationShell",
  1355.                                 "ApplicationShellCloseCleanup");
  1356.  
  1357.     somSelf->SubClassResponsibility(ev, "ApplicationShell::CloseCleanup");
  1358. }
  1359.  
  1360. //------------------------------------------------------------------------------
  1361. // SetExecString
  1362. //
  1363. //      Accessor method for _fExecString
  1364. //------------------------------------------------------------------------------
  1365. SOM_Scope void  SOMLINK ApplicationShellSetExecString(
  1366.                                     ApplicationShell *somSelf, Environment *ev,
  1367.                                     char *execString)
  1368. {
  1369.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1370.     ApplicationShellMethodDebug("ApplicationShell",
  1371.                                 "ApplicationShellSetExecString");
  1372.  
  1373.     strcpy(_fExecString, execString);
  1374. }
  1375. //------------------------------------------------------------------------------
  1376. // GetExecString
  1377. //
  1378. //      Accessor method for _fExecString
  1379. //------------------------------------------------------------------------------
  1380. SOM_Scope char*  SOMLINK ApplicationShellGetExecString(
  1381.                                     ApplicationShell *somSelf, Environment *ev)
  1382. {
  1383.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1384.     ApplicationShellMethodDebug("ApplicationShell",
  1385.                                 "ApplicationShellGetExecString");
  1386.  
  1387.     return _fExecString;
  1388. }
  1389.  
  1390. //------------------------------------------------------------------------------
  1391. // IsValidFileName -
  1392. //
  1393. //     This function checks whether the filename is valid or not
  1394. //
  1395. //------------------------------------------------------------------------------
  1396. SOM_Scope ODBoolean SOMLINK ApplicationShellIsValidFileName(
  1397.                                     ApplicationShell *somSelf,
  1398.                                     Environment *ev,
  1399.                                     char *fileName)
  1400. {
  1401.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1402.     ApplicationShellMethodDebug("ApplicationShell",
  1403.                                 "ApplicationShellIsValidFileName");
  1404.  
  1405.     struct stat       statbuf;
  1406.     WindowSystemData* wsData;
  1407.  
  1408.  
  1409.     if (fileName[0] != '\0')
  1410.     {
  1411. #ifdef _PLATFORM_UNIX_
  1412.         if (stat(fileName, &statbuf) != 0)
  1413. #else
  1414.         if (_stat(fileName, &statbuf) != 0)
  1415. #endif
  1416.         {
  1417.             // something is wrong with the file.
  1418.             if (errno == ENOENT)
  1419.                 WARNMSG(WARN_INDEX(AMSG_780), "CPPOD0328 - Docshell: You specified a file that does not exist.");
  1420.             else WARNMSG(WARN_INDEX(AMSG_840), "CPPOD0334 - Docshell: Problem opening file. Error %d returned.", errno);
  1421.         }
  1422.         else // file exists so test if it is a regular file and readable
  1423.         {
  1424.             if ((statbuf.st_mode & S_IFREG) && (statbuf.st_mode & S_IREAD))
  1425.               return kODTrue;
  1426.             else
  1427.               WARNMSG(WARN_INDEX(AMSG_830), "CPPOD0333 - Docshell: File is not readable or not a regular file.");
  1428.         }
  1429.     }
  1430.     return kODFalse;
  1431. }
  1432.  
  1433. //------------------------------------------------------------------------------
  1434. // GetEventType
  1435. //
  1436. //    A subclass must provide a platform-dependent implementation of this
  1437. //    method which returns the event type from the event data structure.
  1438. //------------------------------------------------------------------------------
  1439. SOM_Scope ODULong  SOMLINK ApplicationShellGetEventType(
  1440.                                                      ApplicationShell *somSelf,
  1441.                                                      Environment *ev,
  1442.                                                      ODEventData* event)
  1443. {
  1444.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1445.     ApplicationShellMethodDebug("ApplicationShell",
  1446.                                 "ApplicationShellGetEventType");
  1447.  
  1448.     somSelf->SubClassResponsibility(ev, "ApplicationShell::GetEventType");
  1449.     return 0;
  1450.  
  1451. }
  1452.  
  1453. //------------------------------------------------------------------------------
  1454. // GetEventSubType
  1455. //
  1456. //    A subclass must provide a platform-dependent implementation of this
  1457. //    method which returns the primary parameter from the event data structure
  1458. //------------------------------------------------------------------------------
  1459. SOM_Scope ODULong  SOMLINK ApplicationShellGetEventSubType(
  1460.                                                      ApplicationShell *somSelf,
  1461.                                                      Environment *ev,
  1462.                                                      ODEventData* event)
  1463. {
  1464.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1465.     ApplicationShellMethodDebug("ApplicationShell",
  1466.                                 "ApplicationShellGetEventSubType");
  1467.  
  1468.     somSelf->SubClassResponsibility(ev, "ApplicationShell::GetEventSubType");
  1469.     return 0;
  1470.  
  1471. }
  1472.  
  1473. //------------------------------------------------------------------------------
  1474. // GetEventWindow
  1475. //
  1476. //    A subclass must provide a platform-dependent implementation of this
  1477. //    method which returns the window from the event data structure.
  1478. //------------------------------------------------------------------------------
  1479. SOM_Scope ODPlatformWindow  SOMLINK ApplicationShellGetEventWindow(
  1480.                         ApplicationShell *somSelf,
  1481.                                                 Environment *ev,
  1482.                                                 ODEventData* event)
  1483. {
  1484.     ApplicationShellData *somThis = ApplicationShellGetData(somSelf);
  1485.     ApplicationShellMethodDebug("ApplicationShell",
  1486.                                 "ApplicationShellGetEventWindow");
  1487.  
  1488.     somSelf->SubClassResponsibility(ev, "ApplicationShell::GetEventWindow");
  1489.     return 0;
  1490.  
  1491. }
  1492.