Link with C++ linker
[oweals/cde.git] / cde / programs / dtpad / helpCB.c
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: 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
84 /************************************************************************
85  * The following callbacks are set as the 'XmNhelpCallback' for the menu
86  * menu bar and for the individual pulldown menus within the menu bar.
87  ************************************************************************/
88
89 void
90 HelpMenubarCB(
91         Widget w,
92         caddr_t client_data,
93         caddr_t call_data )
94 {
95     SetHelpVolAndDisplayHelp((Editor *)client_data, MENUBAR_HELP,
96                              (char *) NULL);
97 }
98
99 void
100 HelpFileCB(
101         Widget w,
102         caddr_t client_data,
103         caddr_t call_data )
104 {
105     SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_MENU_HELP,
106                              (char *) NULL);
107 }
108
109 void
110 HelpEditCB(
111         Widget w,
112         caddr_t client_data,
113         caddr_t call_data )
114 {
115     SetHelpVolAndDisplayHelp((Editor *)client_data, EDIT_MENU_HELP,
116                              (char *) NULL);
117 }
118
119 void
120 HelpFormatCB(
121         Widget w,
122         caddr_t client_data,
123         caddr_t call_data )
124 {
125     SetHelpVolAndDisplayHelp((Editor *)client_data, FORMAT_MENU_HELP,
126                              (char *) NULL);
127 }
128
129 void
130 HelpOptionsCB(
131         Widget w,
132         caddr_t client_data,
133         caddr_t call_data)
134 {
135     SetHelpVolAndDisplayHelp((Editor *)client_data, OPTIONS_MENU_HELP,
136                              (char *) NULL);
137 }
138
139 void
140 HelpHelpCB(
141         Widget w,
142         caddr_t client_data,
143         caddr_t call_data )
144 {
145     SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_HELP,
146                              (char *) NULL);
147 }
148
149
150
151 /************************************************************************
152  * The following callbacks are set as the 'XmNhelpCallback' on file
153  * selection boxes and prompt dialogs relating to the [File] menu.
154  ************************************************************************/
155
156 void
157 HelpOpenDialogCB(
158         Widget w,
159         caddr_t client_data,
160         caddr_t call_data )
161 {
162     SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_OPEN_DIALOG_HELP,
163                              (char *) NULL);
164 }
165
166 void
167 HelpIncludeDialogCB(
168         Widget w,
169         caddr_t client_data,
170         caddr_t call_data )
171 {
172     SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_INCLUDE_DIALOG_HELP,
173                              (char *) NULL);
174 }
175
176 void
177 HelpSaveAsDialogCB(
178         Widget w,
179         caddr_t client_data,
180         caddr_t call_data )
181 {
182     Editor *pPad = (Editor *) client_data;
183
184     if (pPad->xrdb.nameChange) {
185         SetHelpVolAndDisplayHelp(pPad, FILE_SAVEAS_DIALOG_HELP,
186                                  (char *) NULL);
187     } else {
188         SetHelpVolAndDisplayHelp(pPad, FILE_COPYTOFILE_DIALOG_HELP,
189                                  (char *) NULL);
190     }
191 }
192
193 void
194 HelpAskIfSaveDialogCB(
195         Widget w,
196         caddr_t client_data,
197         caddr_t call_data )
198 {
199     SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_ASKIFSAVE_DIALOG_HELP,
200                              (char *) NULL);
201 }
202
203 void
204 HelpFileAlreadyExistsCB(
205         Widget w,
206         caddr_t client_data,
207         caddr_t call_data )
208 {
209     SetHelpVolAndDisplayHelp((Editor *)client_data, FILE_EXISTS_DIALOG_HELP,
210                              (char *) NULL);
211 }
212
213
214 /************************************************************************
215  * The following callback is set as the 'XmNhelpCallback' on the DtEditor
216  * widget.  It controls help for the "Find/Change", "Check Spelling" and
217  * "Format Settings" dialogs and dialog components.
218  ************************************************************************/
219
220 void
221 HelpEditorWidgetCB(
222         Widget w,
223         caddr_t client_data,
224         caddr_t call_data )
225 {
226
227     DtEditorHelpCallbackStruct *editorHelp = 
228                         (DtEditorHelpCallbackStruct *) call_data;
229
230     switch (editorHelp->reason) {
231
232         /* -----> edit area */
233         case DtEDITOR_HELP_EDIT_WINDOW:
234             SetHelpVolAndDisplayHelp((Editor *)client_data,
235                                      EDIT_AREA_HELP,
236                                      (char *) NULL);
237             break;
238
239         /* -----> status line area and fields */
240         case DtEDITOR_HELP_STATUS_LINE:
241             SetHelpVolAndDisplayHelp((Editor *)client_data,
242                                      STATUS_LINE_HELP,
243                                      (char *) NULL);
244             break;
245         case DtEDITOR_HELP_STATUS_CURRENT_LINE:
246             SetHelpVolAndDisplayHelp((Editor *)client_data,
247                                      STATUS_CURRENT_LINE_HELP,
248                                      (char *) NULL);
249             break;
250         case DtEDITOR_HELP_STATUS_TOTAL_LINES:
251             SetHelpVolAndDisplayHelp((Editor *)client_data,
252                                      STATUS_TOTAL_LINES_HELP,
253                                      (char *) NULL);
254             break;
255         case DtEDITOR_HELP_STATUS_MESSAGE:
256             SetHelpVolAndDisplayHelp((Editor *)client_data,
257                                      STATUS_MESSAGE_HELP,
258                                      (char *) NULL);
259             break;
260         case DtEDITOR_HELP_STATUS_OVERSTRIKE:
261             SetHelpVolAndDisplayHelp((Editor *)client_data,
262                                      STATUS_OVERSTRIKE_HELP,
263                                      (char *) NULL);
264             break;
265
266         /* -----> Format Settings dialog and dialog fields */
267         case DtEDITOR_HELP_FORMAT_DIALOG:
268             SetHelpVolAndDisplayHelp((Editor *)client_data,
269                                      FORMAT_SETTINGS_HELP,
270                                      (char *) NULL);
271             break;
272         case DtEDITOR_HELP_FORMAT_LEFT_MARGIN:
273             SetHelpVolAndDisplayHelp((Editor *)client_data,
274                                      FORMAT_LEFT_MARGIN_HELP,
275                                      (char *) NULL);
276             break;
277         case DtEDITOR_HELP_FORMAT_RIGHT_MARGIN:
278             SetHelpVolAndDisplayHelp((Editor *)client_data,
279                                      FORMAT_RIGHT_MARGIN_HELP,
280                                      (char *) NULL);
281             break;
282         case DtEDITOR_HELP_FORMAT_ALIGNMENT:
283             SetHelpVolAndDisplayHelp((Editor *)client_data,
284                                      FORMAT_ALIGNMENT_HELP,
285                                      (char *) NULL);
286             break;
287
288         /* -----> Find/Change dialog and dialog fields */
289         case DtEDITOR_HELP_CHANGE_DIALOG:
290             SetHelpVolAndDisplayHelp((Editor *)client_data,
291                                      FINDCHANGE_HELP,
292                                      (char *) NULL);
293             break;
294         case DtEDITOR_HELP_CHANGE_FIND:
295             SetHelpVolAndDisplayHelp((Editor *)client_data,
296                                      FINDCHANGE_FIND_HELP,
297                                      (char *) NULL);
298             break;
299         case DtEDITOR_HELP_CHANGE_CHANGE:
300             SetHelpVolAndDisplayHelp((Editor *)client_data,
301                                      FINDCHANGE_CHANGETO_HELP,
302                                      (char *) NULL);
303             break;
304
305         /* -----> Check Spelling dialog and dialog fields */
306         case DtEDITOR_HELP_SPELL_DIALOG:
307             SetHelpVolAndDisplayHelp((Editor *)client_data,
308                                      SPELL_HELP,
309                                      (char *) NULL);
310             break;
311         case DtEDITOR_HELP_SPELL_MISSPELLED_WORDS:
312             SetHelpVolAndDisplayHelp((Editor *)client_data,
313                                      SPELL_MISSPELLED_WORDS_HELP,
314                                      (char *) NULL);
315             break;
316         case DtEDITOR_HELP_SPELL_CHANGE:
317             SetHelpVolAndDisplayHelp((Editor *)client_data,
318                                      SPELL_CHANGETO_HELP,
319                                      (char *) NULL);
320             break;
321
322         default:
323             ;
324
325     } /* switch (editorHelp->reason) */
326
327 }
328
329
330 /************************************************************************
331  * The following callbacks are set as the 'XmNhelpCallback' on the print
332  * setup dialogs accessible from the [File] [Print...] menu button.
333  ************************************************************************/
334
335 void
336 HelpPrintSetupDialogCB(
337         Widget w,
338         XtPointer client_data,
339         XtPointer call_data )
340 {
341     SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_SETUP_DIALOG_HELP,
342                              (char *) NULL);
343 }
344
345 void
346 HelpPrintSetupAppSpecificCB(
347         Widget w,
348         XtPointer client_data,
349         XtPointer call_data )
350 {
351     SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_APP_SPECIFIC_OPTIONS,
352                              (char *) NULL);
353 }
354
355 void
356 HelpPrintSetupGenericCB(
357         Widget w,
358         XtPointer client_data,
359         XtPointer call_data )
360 {
361     SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_GENERIC_OPTIONS,
362                              (char *) NULL);
363 }
364
365 void
366 HelpPrintSetupPageHeadersFootersCB(
367         Widget w,
368         XtPointer client_data,
369         XtPointer call_data )
370 {
371     SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_PAGE_HEADERS_FOOTERS,
372                              (char *) NULL);
373 }
374
375 void
376 HelpPrintSetupPageMargins(
377         Widget w,
378         XtPointer client_data,
379         XtPointer call_data )
380 {
381     SetHelpVolAndDisplayHelp((Editor *)client_data, PRINT_PAGE_MARGINS,
382                              (char *) NULL);
383 }
384
385
386
387 /************************************************************************
388  * The following callbacks are set (in dtpad.c:CreateHelpMenu) as the
389  * 'XmNactivateCallback' for each of the items in the Help menu:
390  *
391  *      Overview...
392  *      ----------
393  *      Table of Contents...
394  *      Tasks...
395  *      Reference...
396  *      On Item
397  *      ----------
398  *      Using Help...
399  *      ----------
400  *      About Text Editor...
401  *
402  ************************************************************************/
403
404 void
405 HelpOverviewCB(
406         Widget w,
407         caddr_t client_data,
408         caddr_t call_data )
409 {
410     SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_OVERVIEW_HELP,
411                              (char *) NULL);
412 }
413
414 void
415 HelpTasksCB(
416         Widget w,
417         caddr_t client_data,
418         caddr_t call_data )
419 {
420     SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_TASKS_HELP,
421                              (char *) NULL);
422 }
423
424 void
425 HelpTOCCB(
426         Widget w,
427         caddr_t client_data,
428         caddr_t call_data )
429 {
430     SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_TOC_HELP,
431                              (char *) NULL);
432 }
433
434 void
435 HelpReferenceCB(
436         Widget w,
437         caddr_t client_data,
438         caddr_t call_data )
439 {
440     SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_REFERENCE_HELP,
441                              (char *) NULL);
442 }
443
444 void
445 HelpOnItemCB(
446         Widget w,
447         caddr_t client_data,
448         caddr_t call_data )
449 {
450     Editor *pPad = (Editor *)client_data;
451     Widget widget;
452
453    switch(DtHelpReturnSelectedWidgetId(pPad->app_shell, (Cursor)NULL, &widget))
454    {
455         /*
456          * There are additional cases (e.g. user aborts request) but I
457          * don't feel they warrant an error dialog.
458          */
459         case DtHELP_SELECT_VALID:
460             while (!XtIsShell(widget)) {
461                 if (XtHasCallbacks(widget, XmNhelpCallback) == XtCallbackHasSome) {
462                     XtCallCallbacks(widget, XmNhelpCallback, (XtPointer)pPad);
463                         return;
464                 }
465                 widget = XtParent(widget);
466             }
467             break;
468         case DtHELP_SELECT_INVALID:
469             Warning(pPad, 
470               GETMESSAGE(12, 1, "You must select an item within the Text Editor."),
471             XmDIALOG_INFORMATION);
472             break;
473     }
474 }
475
476 void
477 HelpUsingHelpCB(
478         Widget w,
479         caddr_t client_data,
480         caddr_t call_data )
481 {
482     SetHelpVolAndDisplayHelp((Editor *)client_data, HELP_MENU_USING_HELP_HELP,
483                              HELP_ON_HELP_VOLUME);
484 }
485
486 void
487 HelpAboutCB(
488         Widget w,
489         caddr_t client_data,
490         caddr_t call_data )
491 {
492     SetHelpVolAndDisplayHelp((Editor *) client_data, HELP_MENU_ABOUT_HELP,
493                              (char *) NULL);
494 }
495
496
497
498 /************************************************************************
499  * HelpHyperlinkCB - is the 'DtNhyperLinkCallback' passed to
500  *      DtCreateHelpDialog (in CreateHelpDialog).
501  ************************************************************************/
502 void
503 HelpHyperlinkCB(
504         Widget w,
505         caddr_t client_data,
506         caddr_t call_data )
507 {
508     DtHelpDialogCallbackStruct *pHyper = 
509             (DtHelpDialogCallbackStruct *) call_data;
510
511     switch(pHyper->hyperType)
512     {
513         case DtHELP_LINK_JUMP_NEW:
514             DisplayNewHelpWindow((Editor *)client_data, pHyper->helpVolume,
515                         pHyper->locationId);
516             break;
517         default:
518             ;
519             /* application defined link code goes here */
520     }
521 }
522
523
524
525 /************************************************************************
526  * HelpCloseCB - is the 'DtNcloseCallback' passed to DtCreateHelpDialog
527  *      (in CreateHelpDialog) to close/unmap all help dialogs, both cached
528  *      and uncached.  It checks to see if the referenced dialog is in the
529  *      uncached help for the current pad.
530  ************************************************************************/
531 void
532 HelpCloseCB(
533         Widget w,
534         caddr_t client_data,
535         caddr_t call_data )
536 {
537     Editor *pPad = (Editor *)client_data;
538     HelpStruct *pHelp;
539     
540     if(w != pPad->MainHelp)
541     {
542         /*
543          * empty for loop just marches pHelp to the right place
544          */
545         for(pHelp = pPad->pHelpCache; 
546             pHelp != (HelpStruct *)NULL && pHelp->dialog != w;
547             pHelp = pHelp->pNext)
548             ;
549
550         if(pHelp != (HelpStruct *)NULL)
551         {
552             /* this should always happen */
553             pHelp->inUse = False;
554         }
555     }
556
557     XtUnmanageChild(w);
558 }