-fpermissive to allow GCC to compile old C++
[oweals/cde.git] / cde / programs / dtmail / MotifApp / Help.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 /*
24  *+SNOTICE
25  *
26  *      $XConsortium: Help.C /main/7 1996/10/11 20:04:16 cde-hp $
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *
30  *      The information in this document is subject to special
31  *      restrictions in a confidential disclosure agreement between
32  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
33  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
34  *      Sun's specific written approval.  This document and all copies
35  *      and derivative works thereof must be returned or destroyed at
36  *      Sun's request.
37  *
38  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42  
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <ctype.h>
46 #include <Xm/Xm.h>
47 #include <Dt/HelpDialog.h>
48 #include <Dt/HelpQuickD.h>
49 #include <Dt/Help.h>
50 #include <Dt/Editor.h>
51 #include "Help.hh"
52
53 #include <nl_types.h>
54 extern nl_catd catd;
55
56 #include "NLS.hh"
57
58 void DisplayMain( Widget, char *, char *);
59 static Widget helpMain = NULL;
60 static Widget helpError = NULL;
61 static Widget versionMain = NULL;
62
63 Widget
64 getErrorHelpWidget(void)
65 {
66     return (helpError);
67 }
68
69 void
70 clearErrorHelpWidget(void)
71 {
72     helpError = NULL;
73 }
74
75 char *
76 getHelpId (Widget w)
77 {
78     char *helpId;
79     char *buf;
80     char *index;
81     int i = 0, j = 0;
82  
83     if (XtParent(w) == NULL) {
84         helpId = (char *) malloc(1000);
85         index = helpId;
86         buf = XtName(w);
87         while(*buf) {
88             if (isalnum(*buf)) {
89                 *index++ = toupper(*buf);
90             } else if ('_' == *buf) {
91                 *index++ = '-';
92             }
93             buf++;
94         }
95         *index++ = '\0';
96         return (helpId);
97     } else {
98         helpId = getHelpId (XtParent(w));
99         i = strlen(helpId);
100         buf = XtName(w);
101         while(*buf) {
102             if (isalnum(*buf)) {
103                 helpId[i++] = toupper(*buf);
104             } else if ('_' == *buf) {
105                 helpId[i++] = '-';
106             }
107             buf++;
108         }
109         helpId[i++] = '\0';
110         return (helpId);
111     }
112  
113 }
114
115
116 void
117 DisplayVersion (
118         Widget parent,
119         char *helpVolume,
120         char *locationId )
121 {
122     Arg         args[10];
123     int         n;
124     Widget      printWidget;
125     Widget      helpWidget;
126
127     if (versionMain != NULL) {
128         n = 0;
129         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 4,
130           "DtMail Version Dialog")); n++;
131         if (helpVolume != NULL) {
132             XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
133         }
134         XtSetArg (args[n], DtNlocationId, locationId); n++;
135         XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
136         XtSetValues(versionMain, args, n);
137         XtManageChild(versionMain);
138     } else {
139         while (!XtIsSubclass(parent, applicationShellWidgetClass))
140             parent = XtParent(parent);
141
142         // Build a new one in our cached list
143         n = 0;
144         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 5,
145           "DtMail Version Dialog")); n++;
146         if (helpVolume != NULL) {
147             XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
148         }
149         XtSetArg (args[n], DtNlocationId, locationId); n++;
150         XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
151         versionMain = DtCreateQuickHelpDialog(parent, "versionWidget", args, n);
152         XtAddCallback(versionMain, XmNokCallback,
153                     CloseMainCB, (XtPointer) versionMain);
154         
155         // We do not want a print button for now so we unmap it
156         printWidget = DtHelpQuickDialogGetChild (versionMain,
157                                             DtHELP_QUICK_PRINT_BUTTON);
158         XtUnmanageChild (printWidget);
159
160         // We do not want a help button for now so we unmap it 
161
162         helpWidget = DtHelpQuickDialogGetChild (versionMain,
163                                             DtHELP_QUICK_PRINT_BUTTON);
164         XtUnmanageChild (helpWidget);
165         XtManageChild(versionMain);
166     }
167 }
168
169
170 #ifdef DEAD_WOOD
171 // The callback for the Help Menu in the combo window.
172
173 void
174 HelpMenuCB (
175         Widget widget,
176         XtPointer       clientdata,
177         XtPointer)
178 {
179     Widget selWidget = NULL;
180     int status = DtHELP_SELECT_ERROR;
181
182     // Determine which help button was activated and display the
183     // appropriate help information.
184
185     switch ((long) clientdata) {
186         case HELP_ON_ITEM:
187             while (!XtIsSubclass(widget, applicationShellWidgetClass))
188                 widget = XtParent(widget);
189             status = DtHelpReturnSelectedWidgetId(widget, NULL, &selWidget);
190
191             switch ((int) status) {
192                 case DtHELP_SELECT_ERROR:
193                     printf(GETMSG(catd, 2, 1, "Selection Error, cannot continue\n"));
194                     break;
195                 case DtHELP_SELECT_VALID:
196                     while (selWidget != NULL) {
197                         if ((XtHasCallbacks(selWidget, XmNhelpCallback)
198                                         == XtCallbackHasSome)) {
199                             XtCallCallbacks((Widget)selWidget,
200                                         XmNhelpCallback, NULL);
201                             break;
202                         } else {
203                             selWidget = XtParent(selWidget);
204                         }
205                     }
206                     break;
207                 case DtHELP_SELECT_ABORT:
208                     printf(GETMSG(catd, 2, 2, "Selection aborted by user.\n"));
209                     break;
210                 case DtHELP_SELECT_INVALID:
211                     printf(GETMSG(catd, 1, 6, 
212                            "You must select a component withing your app.\n"));
213                     break;
214             }
215             break;
216         case HELP_ON_TOPIC:
217             DisplayMain(widget, NULL, APP_MENU_ID);
218             break;
219         case HELP_ON_VERSION:
220             DisplayVersion(widget, NULL, VER_MENU_ID);
221             break;
222         default:
223             break;
224     }
225 }
226 #endif /* DEAD_WOOD */
227
228         
229 // Callback to process JUMP-NEW and APP-LINK hypertext requests in a
230 // given Help Dialog Window.
231 //
232 // This is the callback used for the DtNhyperLinkCallback
233 // on each of the help dialog widgets created.
234
235 static void
236 ProcessLinkCB (
237         Widget,
238         XtPointer,
239         XtPointer callData)
240 {
241 //    Arg       args[20];
242 //    Position  xPos, yPos;
243     int         appLinkNum = 0;
244
245     DtHelpDialogCallbackStruct * hyperData =
246                 (DtHelpDialogCallbackStruct *) callData;
247     
248 }
249
250
251 void
252 DisplayMain(
253         Widget parent,
254         char *helpVolume,
255         char *locationId)
256 {
257     Arg args[10];
258     int n;
259
260     if (helpMain != NULL) {
261         n = 0;
262 #ifdef undef
263         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 7, "DtMail Help")); n++;
264 #endif
265         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
266         if (helpVolume != NULL) {
267             XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
268         }
269         XtSetArg (args[n], DtNlocationId, locationId); n++;
270         XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
271         XtSetValues (helpMain, args, n);
272         XtUnmanageChild(helpMain);
273         XtManageChild(helpMain);
274     } else {
275         while (!XtIsSubclass(parent, applicationShellWidgetClass))
276             parent = XtParent(parent);
277         
278         // Build a new one in our cached list
279         n = 0;
280         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
281         if (helpVolume != NULL) {
282             XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
283         }
284         XtSetArg (args[n], DtNlocationId, locationId); n++;
285         XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
286         helpMain = DtCreateHelpDialog(parent, "Mailer", args, n);
287
288         XtAddCallback(helpMain, DtNhyperLinkCallback, ProcessLinkCB, NULL);
289         XtAddCallback(
290                 helpMain,
291                 DtNcloseCallback, CloseMainCB, (XtPointer) helpMain);
292         
293         XtManageChild(helpMain);
294     }
295 }
296
297 void
298 DisplayErrorHelp(
299         Widget parent,
300         char *helpVolume,
301         char *locationId)
302 {
303     Arg args[10];
304     int n;
305
306     if (helpError) {
307         n = 0;
308 #ifdef undef
309         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 7, "DtMail Help")); n++;
310 #endif
311         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
312         if (helpVolume != NULL) {
313             XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
314         }
315         XtSetArg (args[n], DtNlocationId, locationId); n++;
316         XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
317         //XtSetArg (args[n], DtNlocationId, "DTMAILVIEWMAINWINDOWWORK-AREA"); n++;
318         XtSetValues (helpError, args, n);
319         XtManageChild(helpError);
320     } else {
321     
322         // Create a new help on the error dialogs each time, destroy it
323         // when done.
324         n = 0;
325 #ifdef undef
326         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 8, "DtMail Help")); n++;
327 #endif
328         XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
329         if (helpVolume != NULL) {
330         XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
331         }
332         //XtSetArg (args[n], DtNlocationId, "DTMAILVIEWMAINWINDOWWORK-AREAPANEDWFORM2ROWCOLUMNPREVIOUS"); n++;
333         XtSetArg (args[n], DtNlocationId, locationId); n++;
334         XtSetArg (args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
335         helpError = DtCreateHelpDialog(parent, "Mailer", args, n);
336
337         XtAddCallback(helpError, DtNhyperLinkCallback, ProcessLinkCB, NULL);
338
339         XtAddCallback(helpError, DtNcloseCallback, 
340                 CloseMainCB, (XtPointer) helpError);
341
342         XtUnmanageChild(helpError);
343         XtManageChild(helpError);
344     }
345 }
346
347
348 // The Help Callback for when the F1 key is pressed or when On Item
349 // Help is selected from the Help menu.
350
351 void
352 HelpCB (
353         Widget w,
354         XtPointer clientData,
355         XtPointer)
356 {
357     char *locationId = (char *) clientData;
358
359     // printf("locationId = %s\n", locationId);
360     // Just display the proper help based on the id string passed in.
361
362     // We pass in a NULL for our helpVolume and let the value defined
363     // in the app-defaults file be used.
364
365     DisplayMain (w, "Mailer", locationId);
366 }
367
368 void
369 HelpErrorCB (
370         Widget w,
371         XtPointer clientData,
372         XtPointer)
373 {
374     char *locationId = (char *) clientData;
375
376     // printf("locationId = %s\n", locationId);
377     // Just display the proper help based on the id string passed in.
378
379     // We pass in a NULL for our helpVolume and let the value defined
380     // in the app-defaults file be used.
381
382     DisplayErrorHelp (w, "Mailer", locationId);
383 }
384
385 void
386 HelpTexteditCB (
387         Widget w,
388         XtPointer clientData,
389         XtPointer callData )
390 {
391
392      char *locationId = NULL;
393      Widget wEditor = (Widget) clientData;
394      DtEditorHelpCallbackStruct *editorHelp =
395                          (DtEditorHelpCallbackStruct *) callData;
396  
397      switch (editorHelp->reason) {
398  
399         /* -----> edit area */
400         case DtEDITOR_HELP_EDIT_WINDOW:
401             locationId = EDIT_AREA_HELP;
402             break;
403  
404         /* -----> status line area and fields */
405         case DtEDITOR_HELP_STATUS_LINE:
406             locationId = STATUS_LINE_HELP;
407             break;
408         case DtEDITOR_HELP_STATUS_CURRENT_LINE:
409             locationId = STATUS_CURRENT_LINE_HELP;
410             break;
411         case DtEDITOR_HELP_STATUS_TOTAL_LINES:
412             locationId = STATUS_TOTAL_LINES_HELP;
413             break;
414         case DtEDITOR_HELP_STATUS_MESSAGE:
415             locationId = STATUS_MESSAGE_HELP;
416             break;
417         case DtEDITOR_HELP_STATUS_OVERSTRIKE:
418             locationId = STATUS_OVERSTRIKE_HELP;
419  
420         /* -----> Format Settings dialog and dialog fields */
421         case DtEDITOR_HELP_FORMAT_DIALOG:
422             locationId = FORMAT_SETTINGS_HELP;
423             break;
424         case DtEDITOR_HELP_FORMAT_LEFT_MARGIN:
425             locationId = FORMAT_LEFT_MARGIN_HELP;
426             break;
427         case DtEDITOR_HELP_FORMAT_RIGHT_MARGIN:
428             locationId = FORMAT_RIGHT_MARGIN_HELP;
429             break;
430         case DtEDITOR_HELP_FORMAT_ALIGNMENT:
431             locationId = FORMAT_ALIGNMENT_HELP;
432             break;
433  
434         /* -----> Find/Change dialog and dialog fields */
435         case DtEDITOR_HELP_CHANGE_DIALOG:
436             locationId = FINDCHANGE_HELP;
437             break;
438         case DtEDITOR_HELP_CHANGE_FIND:
439             locationId = FINDCHANGE_FIND_HELP;
440             break;
441         case DtEDITOR_HELP_CHANGE_CHANGE:
442             locationId = FINDCHANGE_CHANGETO_HELP;
443             break;
444  
445         /* -----> Check Spelling dialog and dialog fields */
446         case DtEDITOR_HELP_SPELL_DIALOG:
447             locationId = SPELL_HELP;
448             break;
449         case DtEDITOR_HELP_SPELL_MISSPELLED_WORDS:
450             locationId = SPELL_MISSPELLED_WORDS_HELP;
451             break;
452         case DtEDITOR_HELP_SPELL_CHANGE:
453             locationId = SPELL_CHANGETO_HELP;
454             break;
455  
456         default:
457             ;
458  
459      } /* switch (editorHelp->reason) */
460  
461    DisplayMain (w, "Textedit", locationId);
462 }
463   
464
465 // Callback to process close requests on our main help dialog.
466
467 static void
468 CloseMainCB (
469         Widget,
470         XtPointer       clientData,
471         XtPointer)
472 {
473     Widget currentDialog = (Widget) clientData;
474
475     // Unmap and clean up help widget
476
477     XtUnmanageChild(currentDialog);
478 }
479
480 #if defined(PRINT_HELPIDS)
481
482 void
483 printHelpId (char *w_name, Widget w)
484 {
485     char *helpId;
486  
487     helpId = getHelpId (w);
488     printf("%s = %s\n", w_name, helpId);
489     free(helpId);
490  
491 }
492
493 #else
494
495 void
496 printHelpId (char *, Widget)
497 {
498 }
499
500 #endif