helpDlg.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: helpDlg.c /main/4 1999/09/15 15:16:22 mgreess $ */
  24. /**********************************<+>*************************************
  25. ***************************************************************************
  26. **
  27. ** File: helpDlg.c
  28. **
  29. ** Project: HP DT dtpad, a memo maker type editor based on the
  30. ** Dt Editor widget.
  31. **
  32. ** Description: Routines which manipulate the dialogs associated with
  33. ** operations in the Help menu.
  34. ** -----------
  35. **
  36. *******************************************************************
  37. ** (c) Copyright Hewlett-Packard Company, 1990, 1991, 1992. All rights are
  38. ** reserved. Copying or other reproduction of this program
  39. ** except for archival purposes is prohibited without prior
  40. ** written consent of Hewlett-Packard Company.
  41. ********************************************************************
  42. **
  43. *******************************************************************
  44. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  45. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  46. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  47. ** (c) Copyright 1993, 1994 Novell, Inc.
  48. ********************************************************************
  49. **
  50. **
  51. **************************************************************************
  52. **********************************<+>*************************************/
  53. #include <stdio.h>
  54. #include "dtpad.h"
  55. #include "help.h"
  56. #include <Xm/DialogS.h>
  57. #include <Xm/Form.h>
  58. #include <Xm/MwmUtil.h>
  59. #include <Dt/HelpDialog.h>
  60. /************************************************************************
  61. * GetHelpDialog - obtains an "unused" help dialog from the cached list
  62. * for the pad or, if one doesn't exist, creates a new help dialog
  63. * and puts it in the cache.
  64. ************************************************************************/
  65. static Widget
  66. GetHelpDialog(
  67. Editor *pPad)
  68. {
  69. HelpStruct *pHelp;
  70. if (pPad->pHelpCache == (HelpStruct *)NULL) {
  71. pHelp = pPad->pHelpCache = (HelpStruct *)XtMalloc(sizeof(HelpStruct));
  72. pHelp->pNext = (HelpStruct *)NULL;
  73. pHelp->pPrev = (HelpStruct *)NULL;
  74. pHelp->inUse = True;
  75. pHelp->dialog = CreateHelpDialog(pPad);
  76. return pHelp->dialog;
  77. } else {
  78. for (pHelp = pPad->pHelpCache; pHelp != (HelpStruct *)NULL;
  79. pHelp = pHelp->pNext) {
  80. if (pHelp->inUse == False) {
  81. pHelp->inUse = True;
  82. return pHelp->dialog;
  83. }
  84. }
  85. pHelp = (HelpStruct *) XtMalloc(sizeof(HelpStruct));
  86. pPad->pHelpCache->pPrev = pHelp;
  87. pHelp->pNext = pPad->pHelpCache;
  88. pPad->pHelpCache = pHelp;
  89. pHelp->pPrev = (HelpStruct *)NULL;
  90. pHelp->inUse = True;
  91. pHelp->dialog = CreateHelpDialog(pPad);
  92. return pHelp->dialog;
  93. }
  94. }
  95. /************************************************************************
  96. * SetHelpVolAndDisplayHelp - sets the help volume and displays the help
  97. * text beginning at the specified location id within the volume
  98. ************************************************************************/
  99. void
  100. SetHelpVolAndDisplayHelp(
  101. Editor *pPad,
  102. char *locationId,
  103. char *helpVolume)
  104. {
  105. if (helpVolume == (char *) NULL)
  106. helpVolume = TEXTEDITOR_HELP_VOLUME;
  107. DisplayHelp(pPad, helpVolume, locationId);
  108. }
  109. /************************************************************************
  110. * DisplayHelp - is called to display all the "normal" help windows. It
  111. * uses the one "MainHelp" dialog associated with the relevant pad.
  112. ************************************************************************/
  113. void
  114. DisplayHelp(
  115. Editor *pPad,
  116. char *helpVolume,
  117. char *locationId)
  118. {
  119. if (pPad->MainHelp == NULL) {
  120. pPad->MainHelp = CreateHelpDialog(pPad);
  121. }
  122. DisplayHelpDialog(pPad, pPad->MainHelp, helpVolume, locationId);
  123. }
  124. /************************************************************************
  125. * CreateHelpDialog - creates the "MainHelp" help for the pad and sets
  126. * up the hyperLink and Close callbacks for it.
  127. ************************************************************************/
  128. Widget
  129. CreateHelpDialog(
  130. Editor *pPad)
  131. {
  132. Arg args[10];
  133. int n = 0;
  134. Widget dialog;
  135. dialog = DtCreateHelpDialog(pPad->app_shell, "helpDlg", args, n);
  136. XtAddCallback(dialog, DtNhyperLinkCallback,
  137. (XtCallbackProc)HelpHyperlinkCB, pPad);
  138. XtAddCallback(dialog, DtNcloseCallback,
  139. (XtCallbackProc)HelpCloseCB, pPad);
  140. return dialog;
  141. }
  142. /************************************************************************
  143. * DisplayNewHelpWindow - is called by the hyperLink callback,
  144. * helpCB.c:HelpHyperlinkCB to open a new, cached, help dialog for
  145. * this pad.
  146. ************************************************************************/
  147. void
  148. DisplayNewHelpWindow(
  149. Editor *pPad,
  150. char *helpVolume,
  151. char *locationId)
  152. {
  153. DisplayHelpDialog(pPad, GetHelpDialog(pPad), helpVolume, locationId);
  154. }
  155. /************************************************************************
  156. * DisplayHelpDialog - sets the help type topic, volume, location id and
  157. * title for the specified help dialog.
  158. ************************************************************************/
  159. void
  160. DisplayHelpDialog(
  161. Editor *pPad,
  162. Widget helpDialog,
  163. char *helpVolume,
  164. char *locationId)
  165. {
  166. Arg args[10];
  167. int n = 0;
  168. char *titleStr, *helpStr;
  169. n = 0;
  170. XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC);n++;
  171. XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
  172. XtSetArg(args[n], DtNlocationId, locationId); n++;
  173. XtSetValues(helpDialog, args, n);
  174. /*
  175. * It's a bit bogus to set the dialog title each time we display the
  176. * dialog, but it's an easy way to make sure the title is right if the
  177. * pad is reused and the previous user had a mainTitle specified.
  178. */
  179. helpStr = (char*)GETMESSAGE(2, 1, "Help");
  180. titleStr = (char*)XtMalloc(strlen(helpStr)+strlen(DialogTitle(pPad))+1);
  181. sprintf(titleStr, "%s%s", DialogTitle(pPad), helpStr);
  182. n = 0;
  183. XtSetArg (args[n], XmNtitle, titleStr); n++;
  184. XtSetValues(XtParent(helpDialog), args, n);
  185. XtManageChild(helpDialog);
  186. XtFree(titleStr);
  187. }