HelpAccess.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 librararies 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. /* $XConsortium: HelpAccess.c /main/6 1996/08/28 16:46:12 drk $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: HelpAccess.c
  28. **
  29. ** Project: Cache Creek (Rivers) Project
  30. **
  31. ** Description: This module handles all the help requests within a given
  32. ** help dialog widget.
  33. **
  34. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  35. **
  36. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  37. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  38. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  39. ** (c) Copyright 1993, 1994 Novell, Inc.
  40. **
  41. **
  42. **
  43. ****************************************************************************
  44. ************************************<+>*************************************/
  45. #include <stdio.h>
  46. #include <signal.h>
  47. #include <X11/Intrinsic.h>
  48. #include <X11/Shell.h>
  49. #include <Xm/RowColumnP.h>
  50. #include <Xm/LabelG.h>
  51. #include <Xm/PushBG.h>
  52. #include <Xm/CascadeB.h>
  53. #include <Xm/CascadeBG.h>
  54. /* Help Library Includes */
  55. #include "DisplayAreaI.h"
  56. #include "Access.h"
  57. #include "StringFuncsI.h"
  58. #include "HelpDialogI.h"
  59. #include "HelpDialogP.h"
  60. #include <Dt/Help.h>
  61. #include "HelpI.h"
  62. #include "HelposI.h"
  63. #include "HelpUtilI.h"
  64. #include "HelpQuickD.h"
  65. #include "HelpQuickDP.h"
  66. #include "HelpQuickDI.h"
  67. /******** Static Function Declarations ********/
  68. static void CloseOnHelpCB(
  69. Widget w,
  70. XtPointer client_data,
  71. XtPointer call_data);
  72. static void SetupHelpDialog(
  73. Widget parent,
  74. char *helpOnHelpVolume,
  75. Widget *helpWidget,
  76. char *locationId);
  77. /******** End Static Function Declarations ********/
  78. /*****************************************************************************
  79. * Function: static void CloseOnHelpCB(
  80. * Widget w,
  81. * XtPointer client_data,
  82. * XtPointer call_data);
  83. *
  84. * Parameters:
  85. *
  86. * Return Value:
  87. *
  88. * Purpose: This routine closes the onhelp dialog Widget that we
  89. * created for our help on help stuff.
  90. *
  91. ****************************************************************************/
  92. static void CloseOnHelpCB(
  93. Widget w,
  94. XtPointer client_data,
  95. XtPointer call_data )
  96. {
  97. XtUnmanageChild(w);
  98. }
  99. /****************************************************************************
  100. * Function: void _DtHelpCB ()
  101. *
  102. * Parameters: widget
  103. * clientData
  104. * callData
  105. *
  106. *
  107. * Return Value: Void.
  108. *
  109. * Purpose: Called when any "F1" key is pressed in a help dialog
  110. * widget, or a user selects any of the help buttons in
  111. * any of the help dialogs dialogs.
  112. *
  113. ***************************************************************************/
  114. void _DtHelpCB(
  115. Widget widget,
  116. XtPointer clientData,
  117. XtPointer callData)
  118. {
  119. char *errorStr;
  120. DtHelpListStruct * pHelpInfo = (DtHelpListStruct *) clientData;
  121. _DtHelpCommonHelpStuff * help = pHelpInfo->help;
  122. /* If helpOnHelp resource is set use it, else post an error dialog */
  123. if (help->helpOnHelpVolume != NULL)
  124. {
  125. SetupHelpDialog((Widget)pHelpInfo->widget, help->helpOnHelpVolume,
  126. &(help->onHelpDialog), pHelpInfo->locationId);
  127. }
  128. else
  129. {
  130. /* We have no help available for the help stuff so generate an error */
  131. /* Do NOT EVER provide a help button */
  132. /* ??? ERROR */
  133. errorStr = XtNewString(((char *) _DTGETMESSAGE(6, 4,
  134. "Help On Help not provided for this application!")));
  135. _DtHelpErrorDialog(XtParent(pHelpInfo->widget), errorStr);
  136. XtFree(errorStr);
  137. }
  138. }
  139. /*****************************************************************************
  140. * Function: void SetupHelpDialog ();
  141. *
  142. *
  143. * Parameters:
  144. *
  145. * Return Value: Void.
  146. *
  147. * Purpose: Creates or re-uses a help on help quick help widget.
  148. *
  149. *****************************************************************************/
  150. static void SetupHelpDialog(
  151. Widget parent,
  152. char *helpOnHelpVolume,
  153. Widget *helpDialog,
  154. char *locationId)
  155. {
  156. Arg args[10];
  157. int n;
  158. XmString printString;
  159. XmString closeString;
  160. XmString backString;
  161. XmString helpString;
  162. char *title;
  163. if (*helpDialog == NULL)
  164. {
  165. /* Create the QuickHelpDialog widget for help on help */
  166. title = XtNewString(((char *)_DTGETMESSAGE(6, 1, "Help On Help")));
  167. printString = XmStringCreateLocalized(((char *)_DTGETMESSAGE
  168. (6, 2,"Print ...")));
  169. closeString = XmStringCreateLocalized(((char *)_DTGETMESSAGE
  170. (6, 3,"Close")));
  171. backString = XmStringCreateLocalized(((char *)_DTGETMESSAGE
  172. (6, 5,"Backtrack")));
  173. helpString = XmStringCreateLocalized(((char *)_DTGETMESSAGE
  174. (6, 6,"Help ...")));
  175. n =0;
  176. XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
  177. XtSetArg (args[n], XmNtitle, title); n++;
  178. XtSetArg (args[n], DtNprintLabelString, printString); n++;
  179. XtSetArg (args[n], DtNcloseLabelString, closeString); n++;
  180. XtSetArg (args[n], DtNbackLabelString, backString); n++;
  181. XtSetArg (args[n], DtNhelpLabelString, helpString); n++;
  182. XtSetArg (args[n], DtNhelpVolume,helpOnHelpVolume); n++;
  183. XtSetArg (args[n], DtNlocationId, locationId); n++;
  184. *helpDialog = DtCreateHelpQuickDialog((Widget)parent,
  185. "onHelpDialog", args, n);
  186. XmStringFree(printString);
  187. XmStringFree(closeString);
  188. XmStringFree(backString);
  189. XmStringFree(helpString);
  190. XtFree((char*) title);
  191. /* Catch the close callback so we can destroy the widget */
  192. XtAddCallback(*helpDialog, DtNcloseCallback,
  193. CloseOnHelpCB, (XtPointer) NULL);
  194. /* Add the popup position callback to our history dialog */
  195. XtAddCallback (XtParent(*helpDialog), XmNpopupCallback,
  196. (XtCallbackProc)_DtHelpMapCB,
  197. (XtPointer)XtParent(parent));
  198. }
  199. else
  200. {
  201. n = 0;
  202. XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
  203. XtSetArg (args[n], DtNhelpVolume,helpOnHelpVolume); n++;
  204. XtSetArg (args[n], DtNlocationId, locationId); n++;
  205. XtSetValues(*helpDialog, args, n);
  206. }
  207. /* Display the dialog */
  208. XtManageChild(*helpDialog);
  209. XtMapWidget(XtParent((Widget)*helpDialog));
  210. }
  211. /*****************************************************************************
  212. * Function: void _DtHelpListFree (DtHelpListStruct * * pHead);
  213. *
  214. *
  215. * Parameters: pHead Specifies the head pointer to the help list.
  216. *
  217. * Return Value: Void.
  218. *
  219. * Purpose: Frees all elements in a Help List.
  220. *
  221. *****************************************************************************/
  222. void _DtHelpListFree(
  223. DtHelpListStruct * * pHead)
  224. {
  225. DtHelpListStruct *pTemp = NULL;
  226. DtHelpListStruct *pTmpHead = *pHead;
  227. while (pTmpHead != NULL)
  228. {
  229. /* Free up each element in the current node */
  230. pTemp = pTmpHead;
  231. pTmpHead = pTmpHead->pNext;
  232. pTemp->pNext = NULL;
  233. /* Free the id String */
  234. XtFree(pTemp->locationId);
  235. /* Now, free the whole node */
  236. XtFree((char *)pTemp);
  237. }
  238. *pHead = NULL; /* reset pointer */
  239. }
  240. /*****************************************************************************
  241. * Function: DtHelpListStruct * _DtHelpListAdd(
  242. * char *locationId,
  243. * Widget new,
  244. * DtHelpListStruct **pHead)
  245. *
  246. *
  247. *
  248. * Parameters:
  249. *
  250. * Return Value: Void.
  251. *
  252. * Purpose: Adds an element to the top of the given topicList.
  253. *
  254. *****************************************************************************/
  255. DtHelpListStruct * _DtHelpListAdd(
  256. char *locationId,
  257. Widget widget,
  258. _DtHelpCommonHelpStuff * help,
  259. DtHelpListStruct **pHead)
  260. {
  261. DtHelpListStruct *pTemp=NULL;
  262. /* Add locationId as first element if pHead = NULL */
  263. if (*pHead == NULL)
  264. {
  265. *pHead = (DtHelpListStruct *) XtMalloc((sizeof(DtHelpListStruct)));
  266. /* Assign the passed in values to our first element */
  267. (*pHead)->locationId = XtNewString(locationId);
  268. (*pHead)->widget = widget;
  269. (*pHead)->help = help;
  270. (*pHead)->pNext = NULL;
  271. (*pHead)->pPrevious = NULL;
  272. }
  273. else
  274. { /* We have a list so add the new Help item to the top */
  275. pTemp = (DtHelpListStruct *) XtMalloc((sizeof(DtHelpListStruct)));
  276. pTemp->pNext = (*pHead);
  277. pTemp->pPrevious = NULL;
  278. (*pHead)->pPrevious = pTemp;
  279. pTemp->locationId = XtNewString(locationId);
  280. pTemp->widget = widget;
  281. pTemp->help = help;
  282. /* Re-Assign our head pointer to point to the new head of the list */
  283. (*pHead) = pTemp;
  284. }
  285. return (*pHead);
  286. }