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