PathArea.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. /* $XConsortium: PathArea.c /main/7 1996/08/28 16:47:42 drk $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: PathArea.c
  28. **
  29. ** Project: Cache Creek (Rivers) Project
  30. **
  31. ** Description: Routines to create & process the Path area portion of our
  32. ** help dialog.
  33. **
  34. **
  35. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  36. **
  37. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  38. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  39. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  40. ** (c) Copyright 1993, 1994 Novell, Inc.
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. #include <sys/param.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <Xm/Xm.h>
  48. #include <Xm/XmP.h>
  49. #include <Xm/ScrolledW.h>
  50. #include <Xm/List.h>
  51. #include <Xm/Form.h>
  52. #include <Xm/LabelG.h>
  53. #include <Xm/Frame.h>
  54. #include <Xm/RowColumn.h>
  55. #include <Xm/PushBG.h>
  56. #include <X11/Intrinsic.h>
  57. #include <X11/Shell.h>
  58. #include <Dt/Help.h>
  59. /*
  60. * private includes
  61. */
  62. #include "DisplayAreaI.h"
  63. #include "DisplayAreaP.h"
  64. #include "StringFuncsI.h"
  65. #include "HelposI.h"
  66. #include "HelpDialogI.h"
  67. #include "HelpDialogP.h"
  68. #include "HelpUtilI.h"
  69. #include "PathAreaI.h"
  70. #include "DestroyI.h"
  71. #include "SetListI.h"
  72. #include "XUICreateI.h"
  73. /*
  74. * Local Includes
  75. */
  76. /*****************************************************************************
  77. * Function: void _DtHelpBuildPathArea(Widget parent,
  78. * DtHelpDialogWidget nw);
  79. *
  80. *
  81. * Parameters: parent Specifies the widget ID of the help dialog you
  82. * want to set the topic in.
  83. * nw Specifies the current help dialog widget.
  84. *
  85. * Return Value: Void.
  86. *
  87. * Purpose: Creates/updates the Path Display area on top of the help
  88. * dialog.
  89. *
  90. *****************************************************************************/
  91. void _DtHelpBuildPathArea(
  92. Widget parent,
  93. DtHelpDialogWidget nw)
  94. {
  95. Arg args[20];
  96. int n;
  97. Widget pathForm, pathLabel, btnBox, tocFrame;
  98. Widget _pathForm;
  99. XmString labelString;
  100. XmFontList defaultList;
  101. DtHelpDialogWidget hw = (DtHelpDialogWidget) nw ;
  102. Dimension button1, button2, button3, button4;
  103. Dimension maxBtnWidth;
  104. /* Create a form to hold the topic map stuff */
  105. n = 0;
  106. XtSetArg (args[n], XmNmarginWidth, 1); n++;
  107. XtSetArg (args[n], XmNmarginHeight, 1); n++;
  108. XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
  109. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  110. pathForm = XmCreateForm (parent, "pathForm", args, n);
  111. n = 0;
  112. XtSetArg (args[n], XmNmarginWidth, 1); n++;
  113. XtSetArg (args[n], XmNmarginHeight, 1); n++;
  114. XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
  115. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  116. _pathForm = XmCreateForm (pathForm, "_pathForm", args, n);
  117. labelString = XmStringCreateLocalized(((char *)_DTGETMESSAGE
  118. (9, 1,"Volume: ")));
  119. n = 0;
  120. XtSetArg (args[n], XmNlabelString, labelString); n++;
  121. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  122. XtSetArg (args[n], XmNleftOffset, 0); n++;
  123. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  124. XtSetArg (args[n], XmNtopOffset, 0); n++;
  125. XtSetArg (args[n], XmNtraversalOn, FALSE); n++;
  126. pathLabel =
  127. XmCreateLabelGadget (_pathForm, "pathLabel", args, n);
  128. XtManageChild (pathLabel);
  129. XmStringFree (labelString);
  130. /* Create a label for our volume title. We fill it out later
  131. * bacause at this point we may not have yet opened the volume.
  132. */
  133. n = 0;
  134. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  135. XtSetArg (args[n], XmNleftWidget, pathLabel); n++;
  136. XtSetArg (args[n], XmNleftOffset, 1); n++;
  137. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  138. XtSetArg (args[n], XmNtopOffset, 0); n++;
  139. XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  140. hw->help_dialog.browser.volumeLabel =
  141. XmCreateLabelGadget (_pathForm, "volumeLabel", args, n);
  142. XtManageChild (hw->help_dialog.browser.volumeLabel);
  143. /* Build a container for our toc to sit in. We do this because we cannot
  144. * set form constraints on our toc, but can on the container.
  145. */
  146. n = 0;
  147. XtSetArg(args[n], XmNshadowThickness, 0); n++;
  148. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  149. XtSetArg (args[n], XmNleftOffset, 0); n++;
  150. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  151. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  152. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  153. XtSetArg (args[n], XmNtopOffset, 0); n++;
  154. XtSetArg (args[n], XmNtopWidget, _pathForm);n++;
  155. tocFrame = XmCreateFrame (pathForm, "tocFrame", args, n);
  156. XtManageChild (tocFrame);
  157. /* Build our button box rowcol widget container */
  158. n = 0;
  159. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  160. XtSetArg (args[n], XmNleftOffset,3); n++;
  161. XtSetArg (args[n], XmNleftWidget, tocFrame); n++;
  162. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  163. XtSetArg (args[n], XmNbottomOffset, 2); n++;
  164. XtSetArg (args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  165. XtSetArg (args[n], XmNtopOffset, 2); n++;
  166. XtSetArg (args[n], XmNtopWidget, tocFrame); n++;
  167. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  168. XtSetArg (args[n], XmNrightOffset, 1); n++;
  169. XtSetArg (args[n], XmNspacing, 5); n++;
  170. XtSetArg (args[n], XmNentryVerticalAlignment, XmALIGNMENT_CENTER); n++;
  171. XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
  172. XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  173. btnBox = XmCreateRowColumn (pathForm, "BtnBox", args, n);
  174. XtManageChild (btnBox);
  175. /* Backtrack button */
  176. labelString = XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 2,"Backtrack")));
  177. n = 0;
  178. XtSetArg(args[n], XmNlabelString, labelString); n++;
  179. hw->help_dialog.browser.btnBoxBackBtn = XmCreatePushButtonGadget(btnBox,
  180. "btnBoxBackBtn", args, n);
  181. XtManageChild (hw->help_dialog.browser.btnBoxBackBtn);
  182. XmStringFree(labelString);
  183. XtAddCallback(hw->help_dialog.browser.btnBoxBackBtn,XmNactivateCallback,
  184. _DtHelpDisplayBackCB, (XtPointer) hw);
  185. XtSetSensitive(hw->help_dialog.browser.btnBoxBackBtn, FALSE);
  186. /* History Button */
  187. labelString = XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 3,"History...")));
  188. n = 0;
  189. XtSetArg(args[n], XmNlabelString, labelString); n++;
  190. hw->help_dialog.browser.btnBoxHistoryBtn = XmCreatePushButtonGadget(btnBox,
  191. "btnBoxHistoryBtn",args, n);
  192. XtManageChild (hw->help_dialog.browser.btnBoxHistoryBtn);
  193. XmStringFree(labelString);
  194. XtAddCallback(hw->help_dialog.browser.btnBoxHistoryBtn,XmNactivateCallback,
  195. _DtHelpDisplayHistoryCB, (XtPointer) hw);
  196. /* Index button */
  197. labelString =
  198. XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 4,"Index...")));
  199. n = 0;
  200. XtSetArg(args[n], XmNlabelString, labelString); n++;
  201. hw->help_dialog.browser.btnBoxIndexBtn = XmCreatePushButtonGadget(btnBox,
  202. "btnBoxIndexBtn",args, n);
  203. XtManageChild (hw->help_dialog.browser.btnBoxIndexBtn);
  204. XmStringFree(labelString);
  205. XtAddCallback(hw->help_dialog.browser.btnBoxIndexBtn,XmNactivateCallback,
  206. _DtHelpDisplayIndexCB, (XtPointer) hw);
  207. /* Top Level Browser Button */
  208. if (hw->help_dialog.browser.showTopLevelBtn == TRUE)
  209. {
  210. labelString =
  211. XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 5,"Top Level")));
  212. n = 0;
  213. XtSetArg(args[n], XmNlabelString, labelString); n++;
  214. hw->help_dialog.browser.btnBoxTopLevelBtn = XmCreatePushButtonGadget(btnBox,
  215. "btnBoxTopLevelBtn",args, n);
  216. XtManageChild (hw->help_dialog.browser.btnBoxTopLevelBtn);
  217. XmStringFree(labelString);
  218. XtAddCallback(hw->help_dialog.browser.btnBoxTopLevelBtn,XmNactivateCallback,
  219. _DtHelpDisplayBrowserHomeCB, (XtPointer) hw);
  220. }
  221. /* Get our current fontlist value */
  222. n = 0;
  223. XtSetArg (args[n], XmNfontList, &(defaultList)); ++n;
  224. XtGetValues (hw->help_dialog.menu.topBtn, args, n);
  225. /* Build the Display Area */
  226. hw->help_dialog.browser.pTocArea = _DtHelpCreateDisplayArea(tocFrame,
  227. "TocArea",
  228. ((short) hw->help_dialog.display.scrollBarPolicy),
  229. ((short) hw->help_dialog.display.scrollBarPolicy),
  230. True,
  231. ((int) hw->help_dialog.browser.visiblePathCount),
  232. 1,
  233. _DtHelpDialogHypertextCB,
  234. NULL /*ResizeHelpDialogCB*/,
  235. _DtHelpFilterExecCmdCB,
  236. (XtPointer) hw,
  237. defaultList);
  238. /* We build a blank toc at first, it gets filled in later when
  239. * updatePathArea gets called.
  240. */
  241. XtManageChild(_pathForm);
  242. XtManageChild(pathForm);
  243. /* Perform some sizing stuff here to ensure that we layout our UI
  244. * per the current fonts.
  245. */
  246. /* Get the size of each button */
  247. n = 0;
  248. XtSetArg(args[n], XmNwidth, &button1); ++n;
  249. XtGetValues(hw->help_dialog.browser.btnBoxBackBtn, args, n);
  250. n = 0;
  251. XtSetArg(args[n], XmNwidth, &button2); ++n;
  252. XtGetValues(hw->help_dialog.browser.btnBoxHistoryBtn, args, n);
  253. n = 0;
  254. XtSetArg(args[n], XmNwidth, &button3); ++n;
  255. XtGetValues(hw->help_dialog.browser.btnBoxIndexBtn, args, n);
  256. if (hw->help_dialog.browser.showTopLevelBtn == True)
  257. {
  258. n = 0;
  259. XtSetArg(args[n], XmNwidth, &button4); ++n;
  260. XtGetValues(hw->help_dialog.browser.btnBoxTopLevelBtn, args, n);
  261. }
  262. else
  263. button4 = 0;
  264. if (button1 >= button2)
  265. maxBtnWidth = button1;
  266. else
  267. maxBtnWidth = button2;
  268. if (button3 >= maxBtnWidth)
  269. maxBtnWidth = button3;
  270. if (hw->help_dialog.browser.showTopLevelBtn == True)
  271. if (button4 >= maxBtnWidth)
  272. maxBtnWidth = button4;
  273. /* Set our toc right hand attachments */
  274. n = 0;
  275. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  276. XtSetArg (args[n], XmNrightOffset, maxBtnWidth +10); n++;
  277. XtSetValues (tocFrame, args, n);
  278. }
  279. /*****************************************************************************
  280. * Function: void _DtHelpUpdatePathArea(char *locationId,
  281. * DtHelpDialogWidget nw);
  282. *
  283. *
  284. * Parameters: locationId Specifies the ID string for the new topic we
  285. * are going to display in the HelpDialog widget.
  286. *
  287. * helpDialogWidget Specifies the current help dialog widget.
  288. *
  289. * Return Value: Void.
  290. *
  291. * Purpose: Updates the Path Display area on top of the help
  292. * dialog.
  293. *
  294. *****************************************************************************/
  295. void _DtHelpUpdatePathArea(
  296. char *locationId,
  297. DtHelpDialogWidget nw)
  298. {
  299. DtHelpDialogWidget hw = (DtHelpDialogWidget) nw ;
  300. int retState=-1;
  301. if (locationId != NULL)
  302. {
  303. retState = _DtHelpUpdatePath (hw->help_dialog.browser.pTocArea,
  304. hw->help_dialog.display.volumeHandle,
  305. locationId);
  306. if (retState == -1)
  307. {
  308. /* Some error occurred while processing the new toc,
  309. * error out or something ???
  310. */
  311. }
  312. }
  313. else if (locationId == NULL)
  314. {
  315. /* We have most likely entered an error state and must set our path
  316. * area to NULL values while we display and error message in the
  317. * display area
  318. */
  319. _DtHelpDisplayAreaClean(hw->help_dialog.browser.pTocArea);
  320. /* We set our volumeFlag back to false so we are sure to create a new
  321. * toc next time we enter this function (i.e. recovering from our
  322. * error state.
  323. */
  324. hw->help_dialog.ghelp.volumeFlag = FALSE;
  325. }
  326. }