helpCB.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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: helpCB.c /main/4 1996/04/16 16:42:13 mgreess $ */
  24. /**********************************<+>*************************************
  25. ***************************************************************************
  26. **
  27. ** File: helpCB.c
  28. **
  29. ** Project: DT dtpad, a memo maker type editor based on the Dt Editor
  30. ** widget.
  31. **
  32. ** Description:
  33. ** -----------
  34. **
  35. ** This file contains the all the Text Editor help related callbacks:
  36. **
  37. ** o 'XmNhelpCallback' callbacks for:
  38. ** - the menu bar and the individual menus within the bar
  39. ** - file selection boxes, dialogs and dialog components relating to
  40. ** the [File] menu
  41. ** - the DtEditor widget
  42. ** o 'XmNActivateCallback' callbacks for each item in the [Help]
  43. ** pulldown menu
  44. ** o 'DtNhyperLinkCallback' and 'DtNcloseCallback' callbacks passed to
  45. ** DtCreateHelpDialog() (via helpDlg.c:CreateHelpDialog()).
  46. **
  47. ** All 'XmNhelpCallback' and 'XmNActivateCallback' callbacks, except for
  48. ** [Help] menu [On Item...], simply set the help location id to correspond
  49. ** to help text on the widget for which the callback was set. The On Item
  50. ** 'XmNActivateCallback' callback determines the widget on which it was
  51. ** invoked and then calls the 'XmNhelpCallback' callback directly. If no
  52. ** 'XmNhelpCallback' is installed, it searches up the widget's parentage
  53. * until it finds one and then calls it.
  54. **
  55. ** NOTE: All dialogs relating to the [Edit] and [Format] menus are
  56. ** controlled directly by the DtEditor widget. Consequently,
  57. ** all of the help location ids for the "Find/Change", "Check
  58. ** Spelling" and "Format Settings" dialogs are set in the
  59. ** in the DtEditor widget's 'XmNhelpCallback' callback
  60. ** (i.e. in, HelpEditorWidgetCB).
  61. **
  62. *******************************************************************
  63. ** (c) Copyright Hewlett-Packard Company, 1991, 1992, 1993. All rights are
  64. ** reserved. Copying or other reproduction of this program
  65. ** except for archival purposes is prohibited without prior
  66. ** written consent of Hewlett-Packard Company.
  67. ********************************************************************
  68. **
  69. ********************************************************************
  70. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  71. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  72. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  73. ** (c) Copyright 1993, 1994 Novell, Inc.
  74. ********************************************************************
  75. **
  76. **
  77. **************************************************************************
  78. **********************************<+>*************************************/
  79. #include "dtpad.h"
  80. #include "help.h"
  81. #include <Dt/HelpDialog.h>
  82. /************************************************************************
  83. * The following callbacks are set as the 'XmNhelpCallback' for the menu
  84. * menu bar and for the individual pulldown menus within the menu bar.
  85. ************************************************************************/
  86. void
  87. HelpMenubarCB(
  88. Widget w,
  89. caddr_t client_data,
  90. caddr_t call_data )
  91. {
  92. SetHelpVolAndDisplayHelp((Editor *)client_data, MENUBAR_HELP,
  93. (char *) NULL);
  94. }
  95. void
  96. HelpFileCB(
  97. Widget w,
  98. caddr_t client_data,
  99. caddr_t call_data )
  100. {
  101. SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_MENU_HELP,
  102. (char *) NULL);
  103. }
  104. void
  105. HelpEditCB(
  106. Widget w,
  107. caddr_t client_data,
  108. caddr_t call_data )
  109. {
  110. SetHelpVolAndDisplayHelp((Editor *)client_data, EDIT_MENU_HELP,
  111. (char *) NULL);
  112. }
  113. void
  114. HelpFormatCB(
  115. Widget w,
  116. caddr_t client_data,
  117. caddr_t call_data )
  118. {
  119. SetHelpVolAndDisplayHelp((Editor *)client_data, FORMAT_MENU_HELP,
  120. (char *) NULL);
  121. }
  122. void
  123. HelpOptionsCB(
  124. Widget w,
  125. caddr_t client_data,
  126. caddr_t call_data)
  127. {
  128. SetHelpVolAndDisplayHelp((Editor *)client_data, OPTIONS_MENU_HELP,
  129. (char *) NULL);
  130. }
  131. void
  132. HelpHelpCB(
  133. Widget w,
  134. caddr_t client_data,
  135. caddr_t call_data )
  136. {
  137. SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_HELP,
  138. (char *) NULL);
  139. }
  140. /************************************************************************
  141. * The following callbacks are set as the 'XmNhelpCallback' on file
  142. * selection boxes and prompt dialogs relating to the [File] menu.
  143. ************************************************************************/
  144. void
  145. HelpOpenDialogCB(
  146. Widget w,
  147. caddr_t client_data,
  148. caddr_t call_data )
  149. {
  150. SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_OPEN_DIALOG_HELP,
  151. (char *) NULL);
  152. }
  153. void
  154. HelpIncludeDialogCB(
  155. Widget w,
  156. caddr_t client_data,
  157. caddr_t call_data )
  158. {
  159. SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_INCLUDE_DIALOG_HELP,
  160. (char *) NULL);
  161. }
  162. void
  163. HelpSaveAsDialogCB(
  164. Widget w,
  165. caddr_t client_data,
  166. caddr_t call_data )
  167. {
  168. Editor *pPad = (Editor *) client_data;
  169. if (pPad->xrdb.nameChange) {
  170. SetHelpVolAndDisplayHelp(pPad, FILE_SAVEAS_DIALOG_HELP,
  171. (char *) NULL);
  172. } else {
  173. SetHelpVolAndDisplayHelp(pPad, FILE_COPYTOFILE_DIALOG_HELP,
  174. (char *) NULL);
  175. }
  176. }
  177. void
  178. HelpAskIfSaveDialogCB(
  179. Widget w,
  180. caddr_t client_data,
  181. caddr_t call_data )
  182. {
  183. SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_ASKIFSAVE_DIALOG_HELP,
  184. (char *) NULL);
  185. }
  186. void
  187. HelpFileAlreadyExistsCB(
  188. Widget w,
  189. caddr_t client_data,
  190. caddr_t call_data )
  191. {
  192. SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_EXISTS_DIALOG_HELP,
  193. (char *) NULL);
  194. }
  195. /************************************************************************
  196. * The following callback is set as the 'XmNhelpCallback' on the DtEditor
  197. * widget. It controls help for the "Find/Change", "Check Spelling" and
  198. * "Format Settings" dialogs and dialog components.
  199. ************************************************************************/
  200. void
  201. HelpEditorWidgetCB(
  202. Widget w,
  203. caddr_t client_data,
  204. caddr_t call_data )
  205. {
  206. DtEditorHelpCallbackStruct *editorHelp =
  207. (DtEditorHelpCallbackStruct *) call_data;
  208. switch (editorHelp->reason) {
  209. /* -----> edit area */
  210. case DtEDITOR_HELP_EDIT_WINDOW:
  211. SetHelpVolAndDisplayHelp((Editor *)client_data,
  212. EDIT_AREA_HELP,
  213. (char *) NULL);
  214. break;
  215. /* -----> status line area and fields */
  216. case DtEDITOR_HELP_STATUS_LINE:
  217. SetHelpVolAndDisplayHelp((Editor *)client_data,
  218. STATUS_LINE_HELP,
  219. (char *) NULL);
  220. break;
  221. case DtEDITOR_HELP_STATUS_CURRENT_LINE:
  222. SetHelpVolAndDisplayHelp((Editor *)client_data,
  223. STATUS_CURRENT_LINE_HELP,
  224. (char *) NULL);
  225. break;
  226. case DtEDITOR_HELP_STATUS_TOTAL_LINES:
  227. SetHelpVolAndDisplayHelp((Editor *)client_data,
  228. STATUS_TOTAL_LINES_HELP,
  229. (char *) NULL);
  230. break;
  231. case DtEDITOR_HELP_STATUS_MESSAGE:
  232. SetHelpVolAndDisplayHelp((Editor *)client_data,
  233. STATUS_MESSAGE_HELP,
  234. (char *) NULL);
  235. break;
  236. case DtEDITOR_HELP_STATUS_OVERSTRIKE:
  237. SetHelpVolAndDisplayHelp((Editor *)client_data,
  238. STATUS_OVERSTRIKE_HELP,
  239. (char *) NULL);
  240. break;
  241. /* -----> Format Settings dialog and dialog fields */
  242. case DtEDITOR_HELP_FORMAT_DIALOG:
  243. SetHelpVolAndDisplayHelp((Editor *)client_data,
  244. FORMAT_SETTINGS_HELP,
  245. (char *) NULL);
  246. break;
  247. case DtEDITOR_HELP_FORMAT_LEFT_MARGIN:
  248. SetHelpVolAndDisplayHelp((Editor *)client_data,
  249. FORMAT_LEFT_MARGIN_HELP,
  250. (char *) NULL);
  251. break;
  252. case DtEDITOR_HELP_FORMAT_RIGHT_MARGIN:
  253. SetHelpVolAndDisplayHelp((Editor *)client_data,
  254. FORMAT_RIGHT_MARGIN_HELP,
  255. (char *) NULL);
  256. break;
  257. case DtEDITOR_HELP_FORMAT_ALIGNMENT:
  258. SetHelpVolAndDisplayHelp((Editor *)client_data,
  259. FORMAT_ALIGNMENT_HELP,
  260. (char *) NULL);
  261. break;
  262. /* -----> Find/Change dialog and dialog fields */
  263. case DtEDITOR_HELP_CHANGE_DIALOG:
  264. SetHelpVolAndDisplayHelp((Editor *)client_data,
  265. FINDCHANGE_HELP,
  266. (char *) NULL);
  267. break;
  268. case DtEDITOR_HELP_CHANGE_FIND:
  269. SetHelpVolAndDisplayHelp((Editor *)client_data,
  270. FINDCHANGE_FIND_HELP,
  271. (char *) NULL);
  272. break;
  273. case DtEDITOR_HELP_CHANGE_CHANGE:
  274. SetHelpVolAndDisplayHelp((Editor *)client_data,
  275. FINDCHANGE_CHANGETO_HELP,
  276. (char *) NULL);
  277. break;
  278. /* -----> Check Spelling dialog and dialog fields */
  279. case DtEDITOR_HELP_SPELL_DIALOG:
  280. SetHelpVolAndDisplayHelp((Editor *)client_data,
  281. SPELL_HELP,
  282. (char *) NULL);
  283. break;
  284. case DtEDITOR_HELP_SPELL_MISSPELLED_WORDS:
  285. SetHelpVolAndDisplayHelp((Editor *)client_data,
  286. SPELL_MISSPELLED_WORDS_HELP,
  287. (char *) NULL);
  288. break;
  289. case DtEDITOR_HELP_SPELL_CHANGE:
  290. SetHelpVolAndDisplayHelp((Editor *)client_data,
  291. SPELL_CHANGETO_HELP,
  292. (char *) NULL);
  293. break;
  294. default:
  295. ;
  296. } /* switch (editorHelp->reason) */
  297. }
  298. /************************************************************************
  299. * The following callbacks are set as the 'XmNhelpCallback' on the print
  300. * setup dialogs accessible from the [File] [Print...] menu button.
  301. ************************************************************************/
  302. void
  303. HelpPrintSetupDialogCB(
  304. Widget w,
  305. XtPointer client_data,
  306. XtPointer call_data )
  307. {
  308. SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_SETUP_DIALOG_HELP,
  309. (char *) NULL);
  310. }
  311. void
  312. HelpPrintSetupAppSpecificCB(
  313. Widget w,
  314. XtPointer client_data,
  315. XtPointer call_data )
  316. {
  317. SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_APP_SPECIFIC_OPTIONS,
  318. (char *) NULL);
  319. }
  320. void
  321. HelpPrintSetupGenericCB(
  322. Widget w,
  323. XtPointer client_data,
  324. XtPointer call_data )
  325. {
  326. SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_GENERIC_OPTIONS,
  327. (char *) NULL);
  328. }
  329. void
  330. HelpPrintSetupPageHeadersFootersCB(
  331. Widget w,
  332. XtPointer client_data,
  333. XtPointer call_data )
  334. {
  335. SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_PAGE_HEADERS_FOOTERS,
  336. (char *) NULL);
  337. }
  338. void
  339. HelpPrintSetupPageMargins(
  340. Widget w,
  341. XtPointer client_data,
  342. XtPointer call_data )
  343. {
  344. SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_PAGE_MARGINS,
  345. (char *) NULL);
  346. }
  347. /************************************************************************
  348. * The following callbacks are set (in dtpad.c:CreateHelpMenu) as the
  349. * 'XmNactivateCallback' for each of the items in the Help menu:
  350. *
  351. * Overview...
  352. * ----------
  353. * Table of Contents...
  354. * Tasks...
  355. * Reference...
  356. * On Item
  357. * ----------
  358. * Using Help...
  359. * ----------
  360. * About Text Editor...
  361. *
  362. ************************************************************************/
  363. void
  364. HelpOverviewCB(
  365. Widget w,
  366. caddr_t client_data,
  367. caddr_t call_data )
  368. {
  369. SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_OVERVIEW_HELP,
  370. (char *) NULL);
  371. }
  372. void
  373. HelpTasksCB(
  374. Widget w,
  375. caddr_t client_data,
  376. caddr_t call_data )
  377. {
  378. SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_TASKS_HELP,
  379. (char *) NULL);
  380. }
  381. void
  382. HelpTOCCB(
  383. Widget w,
  384. caddr_t client_data,
  385. caddr_t call_data )
  386. {
  387. SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_TOC_HELP,
  388. (char *) NULL);
  389. }
  390. void
  391. HelpReferenceCB(
  392. Widget w,
  393. caddr_t client_data,
  394. caddr_t call_data )
  395. {
  396. SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_REFERENCE_HELP,
  397. (char *) NULL);
  398. }
  399. void
  400. HelpOnItemCB(
  401. Widget w,
  402. caddr_t client_data,
  403. caddr_t call_data )
  404. {
  405. Editor *pPad = (Editor *)client_data;
  406. Widget widget;
  407. switch(DtHelpReturnSelectedWidgetId(pPad->app_shell, (Cursor)NULL, &widget))
  408. {
  409. /*
  410. * There are additional cases (e.g. user aborts request) but I
  411. * don't feel they warrant an error dialog.
  412. */
  413. case DtHELP_SELECT_VALID:
  414. while (!XtIsShell(widget)) {
  415. if (XtHasCallbacks(widget, XmNhelpCallback) == XtCallbackHasSome) {
  416. XtCallCallbacks(widget, XmNhelpCallback, (XtPointer)pPad);
  417. return;
  418. }
  419. widget = XtParent(widget);
  420. }
  421. break;
  422. case DtHELP_SELECT_INVALID:
  423. Warning(pPad,
  424. GETMESSAGE(12, 1, "You must select an item within the Text Editor."),
  425. XmDIALOG_INFORMATION);
  426. break;
  427. }
  428. }
  429. void
  430. HelpUsingHelpCB(
  431. Widget w,
  432. caddr_t client_data,
  433. caddr_t call_data )
  434. {
  435. SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_USING_HELP_HELP,
  436. HELP_ON_HELP_VOLUME);
  437. }
  438. void
  439. HelpAboutCB(
  440. Widget w,
  441. caddr_t client_data,
  442. caddr_t call_data )
  443. {
  444. SetHelpVolAndDisplayHelp((Editor *) client_data, HELP_MENU_ABOUT_HELP,
  445. (char *) NULL);
  446. }
  447. /************************************************************************
  448. * HelpHyperlinkCB - is the 'DtNhyperLinkCallback' passed to
  449. * DtCreateHelpDialog (in CreateHelpDialog).
  450. ************************************************************************/
  451. void
  452. HelpHyperlinkCB(
  453. Widget w,
  454. caddr_t client_data,
  455. caddr_t call_data )
  456. {
  457. DtHelpDialogCallbackStruct *pHyper =
  458. (DtHelpDialogCallbackStruct *) call_data;
  459. switch(pHyper->hyperType)
  460. {
  461. case DtHELP_LINK_JUMP_NEW:
  462. DisplayNewHelpWindow((Editor *)client_data, pHyper->helpVolume,
  463. pHyper->locationId);
  464. break;
  465. default:
  466. ;
  467. /* application defined link code goes here */
  468. }
  469. }
  470. /************************************************************************
  471. * HelpCloseCB - is the 'DtNcloseCallback' passed to DtCreateHelpDialog
  472. * (in CreateHelpDialog) to close/unmap all help dialogs, both cached
  473. * and uncached. It checks to see if the referenced dialog is in the
  474. * uncached help for the current pad.
  475. ************************************************************************/
  476. void
  477. HelpCloseCB(
  478. Widget w,
  479. caddr_t client_data,
  480. caddr_t call_data )
  481. {
  482. Editor *pPad = (Editor *)client_data;
  483. HelpStruct *pHelp;
  484. if(w != pPad->MainHelp)
  485. {
  486. /*
  487. * empty for loop just marches pHelp to the right place
  488. */
  489. for(pHelp = pPad->pHelpCache;
  490. pHelp != (HelpStruct *)NULL && pHelp->dialog != w;
  491. pHelp = pHelp->pNext)
  492. ;
  493. if(pHelp != (HelpStruct *)NULL)
  494. {
  495. /* this should always happen */
  496. pHelp->inUse = False;
  497. }
  498. }
  499. XtUnmanageChild(w);
  500. }