home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xhelp.cpp < prev    next >
C/C++ Source or Header  |  1997-06-30  |  4KB  |  149 lines

  1. #include "XHelp.h"
  2. #include "XFrmwnd.H"
  3. #include "XResLib.h"
  4. #include "XRes.h"
  5. #include "XApp.h"
  6. #include "xdialog.h"
  7.  
  8. #include <string.h>
  9.  
  10. /*@ 
  11. @class XHelpInstance
  12. @type overview
  13. @symbol _
  14. @remarks XHelpInstance handles help functions for you. Therefore you have
  15. to write your help-text for your controls and give the text the same id
  16. (res=XXX in the IPF-file) like you have defined for the requested control.<BR>
  17. You can associate a XHelpInstance to one ore more framewindows.
  18. <p>The help-instance also supports help for a message-box, refer to XMessageBox for details.
  19. */
  20.  
  21.  
  22. BOOL HelpHook(HAB hab, ULONG mode, ULONG idT, ULONG idS, PRECTL rect)
  23. {
  24.     if (mode)                    // == HLPM_MESSAGE)
  25.     {
  26.         HWND hwnd = WinQueryFocus(HWND_DESKTOP);
  27.  
  28.         hwnd = WinQueryWindow(hwnd, QW_OWNER);
  29.         if (idT == 0)
  30.             idT = WinQueryWindowUShort(hwnd, QWS_ID);
  31.         if (hwnd)
  32.         {
  33.             WinSendMsg(WinQueryHelpInstance(hwnd), HM_DISPLAY_HELP, MPFROMSHORT(idT), MPFROMSHORT(HM_RESOURCEID));
  34.             return TRUE;
  35.         }
  36.     }
  37.     return FALSE;
  38. }
  39.  
  40.  
  41. /*@ XHelpInstance :: XHelpInstance(const char *path, const char *title, const XResource * helpTable, const XResourceLibrary * actionBarLib)
  42. @group constructors/destructors
  43. @remarks Construct a helpinstance
  44. @parameters    <t '°' c=2>
  45.                     °char * path                        °path for the help-file
  46.                °char * title                       °window -title (default is NULL)
  47.                °XResource * helpTableLib           °resource for the help-table (default is NULL)
  48.                °XResourceLibrary * actionBarLib    °library for action-bar (defaul tis NULL)
  49.                     </t>
  50. */
  51. XHelpInstance :: XHelpInstance(const char *path, const char *title, const XResource * helpTable, const XResourceLibrary * actionBarLib)
  52. {
  53.     HELPINIT helpinit;
  54.  
  55.     memset(&helpinit, 0, sizeof(helpinit));
  56.  
  57.     helpinit.cb = sizeof(HELPINIT);
  58.     helpinit.ulReturnCode = 0;
  59.     helpinit.pszTutorialName = NULL;
  60.     if (helpTable)
  61.         helpinit.phtHelpTable = (PHELPTABLE) MPFROM2SHORT(helpTable->GetID(), 0xFFFF);
  62.  
  63.     helpinit.idAccelTable = 0;
  64.     helpinit.idActionBar = 0;
  65.  
  66.     helpinit.pszHelpWindowTitle = (PSZ) title;
  67.     helpinit.fShowPanelId = CMIC_HIDE_PANEL_ID;
  68.     helpinit.fShowPanelId = 0;
  69.     helpinit.pszHelpLibraryName = (PSZ) path;
  70.     if (actionBarLib)
  71.         helpinit.hmodAccelActionBarModule = actionBarLib->GetModuleHandle();
  72.     if (helpTable)
  73.         if (helpTable->GetResourceLibrary())
  74.             helpinit.hmodHelpTableModule = helpTable->GetResourceLibrary()->GetModuleHandle();
  75.     helpInstance = WinCreateHelpInstance(XApplication::GetApplication()->GetAnchorBlock(), &helpinit);
  76.     WinSetHook( XApplication::GetApplication()->GetAnchorBlock(), HMQ_CURRENT, HK_HELP, (PFN) HelpHook, NULLHANDLE);
  77. }
  78.  
  79.  
  80. /*@ XHelpInstance::ShowHelpForHelp(void)
  81. @group help funcions
  82. @remarks Shows how to use help
  83. */
  84. void XHelpInstance::ShowHelpForHelp(void) const
  85. {
  86.     WinSendMsg(helpInstance, HM_DISPLAY_HELP, NULL, NULL);
  87. }
  88.  
  89.  
  90.  
  91. /*@ XHelpInstance::ShowHelpContents(void)
  92. @group help funcions
  93. @remarks Show the contents
  94. */
  95. void XHelpInstance::ShowHelpContents(void) const
  96. {
  97.     WinSendMsg(helpInstance, HM_HELP_CONTENTS, NULL, NULL);
  98. }
  99.  
  100.  
  101. /*@ XHelpInstance::ShowHelpIndex(void)
  102. @group help funcions
  103. @remarks Shows the index
  104. */
  105. void XHelpInstance::ShowHelpIndex(void) const
  106. {
  107.     WinSendMsg(helpInstance, HM_HELP_INDEX, NULL, NULL);
  108. }
  109.  
  110.  
  111. /*@ XHelpInstance::ShowHelpForId(const LONG id)
  112. @group help funcions
  113. @remarks Shows the help for a given ID
  114. @parameters LONG id     the requested id
  115. */
  116. void XHelpInstance::ShowHelpForId(const LONG id) const
  117. {
  118.     WinSendMsg(helpInstance, HM_DISPLAY_HELP, MPFROMSHORT(id), MPFROMSHORT(HM_RESOURCEID));
  119. }
  120.  
  121.  
  122. XHelpInstance :: ~XHelpInstance()
  123. {
  124.     if (helpInstance)
  125.         WinDestroyHelpInstance(helpInstance);
  126. }
  127.  
  128.  
  129. /*@ XHelpInstance::AssociateWindow(const XFrameWindow * fWin)
  130. @group window functions
  131. @remarks Associate a frame-window with the help-instance
  132. @parameters XFrameWindow * window
  133. */
  134. void XHelpInstance::AssociateWindow(const XFrameWindow * fWin) const
  135. {
  136.     WinAssociateHelpInstance(helpInstance, fWin->frame);
  137. }
  138.  
  139.  
  140. /*@ XHelpInstance::AssociateWindow(const XDialog * fWin)
  141. @group window functions
  142. @remarks Associate a dialog with the help-instance
  143. @parameters XDialog * dialog
  144. */
  145. void XHelpInstance::AssociateWindow(const XDialog * dlg) const
  146. {
  147.     WinAssociateHelpInstance(helpInstance, dlg->GetHandle());
  148. }
  149.