home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / ted / tedhelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-06  |  10.8 KB  |  393 lines

  1. /**************************************************************************
  2.  
  3.     Tedhelp.c
  4.  
  5.     Created by Microsoft Corporation, IBM Corporation 1989
  6.  
  7. ---------------------------------------------------------------------------
  8.  
  9.  
  10.         This file contains all the helper procedures required to
  11.         include Help Manager in an application. The normal
  12.         procedure is to:
  13.  
  14.  
  15.             Define the .itl file which has all the help panel
  16.             text in it.
  17.  
  18.             Define the Help tables and sub tables.  This maps
  19.             help panel id numbers to menu id numbers so help
  20.             manager knows which contectual help to put up
  21.             when a user requestes it.
  22.  
  23.             Create a help instance.
  24.  
  25.             Associate a help instance with the current window
  26.             chain.  As long as each new window created is
  27.             part of the window chain (parent or owner) then
  28.             there is no need to associate a help instance with
  29.             each new window.
  30.  
  31.  
  32.  
  33.  
  34.     Modification history
  35.  
  36.             091189  -  James Bratsanos, created
  37.  
  38.  
  39. ***************************************************************************/
  40.  
  41.  
  42. /* Define Constants for additional includes  */
  43.  
  44.  
  45. #define INCL_BASE
  46. #define INCL_WIN
  47.  
  48.  
  49.  
  50. #include <os2.h>
  51. #include <string.h>
  52. #include "ted.h"
  53. #include "tedhelp.h"
  54. #include "tedhp.h"
  55. #include "teddlg.h"
  56.  
  57.  
  58.  
  59.  
  60. HWND hwndHelpInstance = (HWND) NULL;        /* The handle to the the Help */
  61.                                             /* Manager help instance      */
  62.  
  63. /****************************************************************************
  64.  
  65.     TEDTerminateHelp - This procedure disassociates the help instance
  66.                        attached to the passed in window handle, and then
  67.                        destroys it.
  68.  
  69. ****************************************************************************/
  70.  
  71.  
  72. VOID APIENTRY TEDTerminateHelp( HWND hwnd )
  73. {
  74.  
  75.  
  76.     if ( hwndHelpInstance != (HWND) NULL )
  77.     {
  78.  
  79.     /* Dissasociate the Help instance */
  80.  
  81.         WinAssociateHelpInstance( NULL, hwnd );
  82.  
  83.     /* Destroy the HELP instance */
  84.  
  85.         WinDestroyHelpInstance( hwndHelpInstance );
  86.     }
  87.  
  88. }
  89.  
  90.  
  91. /****************************************************************************
  92.  
  93.     TEDInitHelp - This procedure opens the defined help library for this
  94.                   application then creates a help instance and associates
  95.                   it with the passed in window handle (which is the frame)
  96.  
  97. ****************************************************************************/
  98.  
  99.  
  100. USHORT APIENTRY TEDInitHelp( HWND hFrame, HAB hab )
  101. {
  102.     HELPINIT stHMInit;                  /* Help Manager init structure       */
  103.     BOOL     bHelpLibFound=TRUE;        /* Help library found flag           */
  104.  
  105. /***************************************************************************
  106.     If the help tables were arrays instead of resources they would be
  107.     set up as static arrays at this point in the procedure.
  108. ***************************************************************************/
  109.  
  110.  
  111. /***************************************************************************
  112.     The help manager will search for the help library names first in
  113.     the HELP environment variable and then in the current directory.
  114.  
  115.     NOTE: To specify multiple library names seperate the names with
  116.           a blank.  Note the library names must include the extension
  117. ***************************************************************************/
  118.  
  119.  
  120.  
  121. /************************************************************************
  122.  
  123.     Initialize Help Manager init  structure
  124.  
  125. ************************************************************************/
  126.  
  127.     stHMInit.cb                        = sizeof(HELPINIT);
  128.     stHMInit.ulReturnCode              = 0L;
  129.     stHMInit.pszTutorialName           = NULL;
  130.     stHMInit.phtHelpTable              = (PHELPTABLE) (0xffff0000 |
  131.                                                       (LONG) TED_HELP_TABLE );
  132.     stHMInit.hmodHelpTableModule       = (HMODULE) NULL;
  133.     stHMInit.hmodAccelActionBarModule  = (HMODULE) NULL;
  134.     stHMInit.idAccelTable              = 0;
  135.     stHMInit.idActionBar               = 0;
  136.  
  137.  
  138.     stHMInit.pszHelpWindowTitle        = "Ted Editor Help";
  139.     stHMInit.usShowPanelId             = CMIC_HIDE_PANEL_ID;
  140.     stHMInit.pszHelpLibraryName        = HELP_LIBRARY;
  141.  
  142.  
  143.  
  144. /* Create Help Manager Object Window */
  145.  
  146.  
  147. /************************************************************************
  148.     NOTE to Windows Programmers: This hwndHelpInstance is simply
  149.                                  a window handle and not an INSTANCE
  150.                                  handle as defined in Windows.
  151. ************************************************************************/
  152.  
  153.  
  154.     if ( !( hwndHelpInstance = WinCreateHelpInstance( hab, &stHMInit )) )
  155.     {
  156.  
  157.  
  158.         if ( stHMInit.ulReturnCode == HMERR_OPEN_LIB_FILE )
  159.         {
  160.  
  161.            TEDDisplayErrorID( SID_HERR_NO_LIBRARY );
  162.  
  163.         }
  164.         else
  165.         {
  166.  
  167.            TEDDisplayErrorID( SID_HELP_CANT_CREATE_INST );
  168.  
  169.         }
  170.  
  171.         return( FALSE );                /* cleanup handled at exit */
  172.  
  173.     }
  174.  
  175.  
  176. /*  Associate an instance of the Help Manager with the window chain. */
  177.  
  178.  
  179.  
  180.     if (!WinAssociateHelpInstance( hwndHelpInstance, hFrame ))
  181.     {
  182.  
  183.         TEDDisplayErrorID( SID_HELP_CANT_ASSOC_INST );
  184.         return( FALSE );                  /* cleanup handled at exit */
  185.  
  186.     }
  187.  
  188.  
  189. /* Check for any other initialization error from Help Manager */
  190.  
  191.  
  192.     if(stHMInit.ulReturnCode)
  193.     {
  194.  
  195.         TEDDisplayErrorID( SID_HELP_HLP_ERROR );
  196.  
  197.         return(FALSE );          /* exit if help initialization failed  */
  198.  
  199.     }
  200.     else
  201.     {
  202.         return(HELP_OK);
  203.     }
  204.  
  205.  
  206. }                                                       /* return to main */
  207.  
  208.  
  209.  
  210. /***************************************************************************
  211.  
  212.     TEDSendHelpMsg - This procedure sends a message to the help manager
  213.  
  214. ***************************************************************************/
  215.  
  216.  
  217. VOID APIENTRY TEDSendHelpMsg( USHORT usMsg )
  218. {
  219.  
  220.     WinSendMsg( hwndHelpInstance, usMsg, NULL, NULL );
  221. }
  222.  
  223.  
  224.  
  225.  
  226. /***************************************************************************
  227.  
  228.     TEDAssociateHelp - This procedure associates a help instance with the
  229.                        passed in window handle.
  230.  
  231.                        NOTE: As long as a new window is part of the original
  232.                              window chain , where each succesive window had
  233.                              as its owner a handle that was associated with
  234.                              the help instance the there is no need to associate
  235.                              a help instance with this newly created window
  236.                              since this new window will inherit the instance
  237.                              because it is part of the chain.
  238.  
  239. ***************************************************************************/
  240.  
  241.  
  242. VOID APIENTRY TEDAssociateHelp( HWND hwnd)
  243. {
  244.     WinAssociateHelpInstance( hwndHelpInstance, hwnd );
  245. }
  246.  
  247.  
  248.  
  249. /***************************************************************************
  250.  
  251.     TEDProcessHelpMsg - This procedure determines if the Help Manager
  252.                         error is something that can be acted on and
  253.                         acts accordingly.
  254.  
  255.               Return  - TRUE if it handled the message. False otherwise
  256.  
  257. ***************************************************************************/
  258.  
  259. BOOL APIENTRY TEDProcessHelpMsg(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2,
  260.                         MRESULT *mresult)
  261. {
  262.  
  263.     switch( msg )
  264.     {
  265.  
  266.     /**************************************************************************
  267.  
  268.         In this case user pressed keys help and HELP manager sent a message
  269.         notifying us. Help Manager expects the help panel id # in the .ITL
  270.         file be returned so it can display that help panel in the help window.
  271.  
  272.     **************************************************************************/
  273.  
  274.         case HM_QUERY_KEYS_HELP:
  275.  
  276.             *mresult=MRFROMSHORT(KEYS_HELP_HP);
  277.             break;
  278.  
  279.         case HM_HELPSUBITEM_NOT_FOUND:
  280.         case HM_EXT_HELP_UNDEFINED:
  281.         case HM_ERROR:
  282.  
  283.             *mresult = TEDHelpError(hwnd,msg,mp1,mp2);
  284.             break;
  285.  
  286.         default:
  287.  
  288.             return (FALSE);
  289.             break;
  290.  
  291.     }
  292.  
  293.     return (TRUE);
  294. }
  295.  
  296.  
  297.  
  298.  
  299. MRESULT APIENTRY TEDHelpError( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  300. {
  301.   USHORT  SubTopicID;
  302.   USHORT  ErrorCode;
  303.  
  304.  
  305. /*  Process the Help Manager message  */
  306.  
  307.     switch (msg)
  308.     {
  309.         case HM_HELPSUBITEM_NOT_FOUND:
  310.  
  311.             SubTopicID = HIUSHORT(mp2);
  312.  
  313.  
  314.             switch (SubTopicID)
  315.             {
  316.                 case FID_CLIENT:         /* Edit area has input focus */
  317.              /*************************************************/
  318.              /* Returning false to HM in this case causes the   */
  319.              /* extended help panel GENERAL_HP to display.      */
  320.              /* Doing it this way instead of putting FID_CLIENT */
  321.              /* in SubTbl_MAIN_MENU causes the Extended help    */
  322.              /* item on the help panel's pull down to be        */
  323.              /* grayed out, which is the desired result.        */
  324.              /*************************************************/
  325.                     return((MRESULT)FALSE);
  326.                     break;
  327.  
  328.                 default:
  329.                     break;
  330.             }
  331.  
  332.             break;
  333.  
  334.         case HM_EXT_HELP_UNDEFINED:
  335.  
  336.             break;
  337.  
  338.         case HM_ERROR:
  339.  
  340.             ErrorCode = SHORT1FROMMP(mp1);
  341.  
  342.  
  343.  
  344.     /* Load the correct error message                 */
  345.  
  346.  
  347.  
  348.             switch (ErrorCode)
  349.             {
  350.                 case HMERR_NO_MEMORY:
  351.                 case HMERR_ALLOCATE_SEGMENT:
  352.                 case HMERR_FREE_MEMORY:
  353.  
  354.                     TEDDisplayErrorID( SID_HERR_MEMORY );
  355.                     break;
  356.  
  357.                 case HMERR_DATABASE_NOT_OPEN:
  358.                 case HMERR_OPEN_LIB_FILE:
  359.                 case HMERR_READ_LIB_FILE:
  360.                 case HMERR_CLOSE_LIB_FILE:
  361.                 case HMERR_INVALID_LIB_FILE:
  362.  
  363.                     TEDDisplayErrorID( SID_HERR_LIB_ERROR );
  364.                     break;
  365.  
  366.                 case HMERR_HELPITEM_NOT_FOUND:
  367.                 case HMERR_HELPSUBITEM_NOT_FOUND:
  368.  
  369.                     return((MRESULT)TRUE);
  370.                     break;
  371.  
  372.                 default:
  373.  
  374.                     TEDDisplayErrorID( SID_HERR_UNKNOWN );
  375.                     break;
  376.  
  377.  
  378.             }   /* End ErrorCode switch */
  379.  
  380.  
  381.             break;  /* end - case HM_ERROR: */
  382.  
  383.         default:
  384.  
  385.             break;
  386.  
  387.     }  /* end the big switch */
  388.  
  389.  
  390.     return((MRESULT)TRUE);
  391.  
  392. }
  393.