2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: help.c /main/4 1996/03/25 13:12:20 ageorge $ */
26 * Contains all support for help in the Calculator. *
28 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
29 * (c) Copyright 1993, 1994 International Business Machines Corp. *
30 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
31 * (c) Copyright 1993, 1994 Novell, Inc. *
36 #include <Xm/MwmUtil.h>
37 #include <Xm/MessageB.h>
40 #include <Dt/HelpDialog.h>
45 #define DIALOG_MWM_FUNC MWM_FUNC_MOVE | MWM_FUNC_CLOSE
47 extern char *base_str[] ; /* Strings for each base value. */
48 extern char *dtype_str[] ; /* Strings for each display mode value. */
49 extern char *mode_str[] ; /* Strings for each mode value. */
50 extern char *ttype_str[] ; /* Strings for each trig type value. */
51 extern Vars v ; /* Calctool variables and options. */
52 extern struct button buttons[] ; /* Calculator button values. */
55 extern Boolean ignore_event;
56 extern XtIntervalId timerId;
57 extern void _DtChildPosition P((Widget, Widget, Position *, Position *)) ;
59 typedef struct _helpStruct {
60 struct _helpStruct *pNext;
61 struct _helpStruct *pPrev;
66 static Widget GetHelpDialog P(()) ;
67 static void UnmanageCB P(()) ;
70 Help(helpVolume, locationId)
78 if(X->helpDialog == NULL)
81 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
82 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
83 XtSetArg(args[n], DtNlocationId, locationId); n++;
84 XtSetArg(args[n], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help")); n++;
85 X->helpDialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, n);
87 DtWsmRemoveWorkspaceFunctions(X->dpy,
88 XtWindow(XtParent(X->helpDialog)));
89 XtAddCallback(X->helpDialog, DtNhyperLinkCallback,
90 (XtCallbackProc)HelpHyperlinkCB, NULL);
91 XtAddCallback(X->helpDialog, DtNcloseCallback,
92 (XtCallbackProc)HelpCloseCB, NULL);
97 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
98 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
99 XtSetArg(args[n], DtNlocationId, locationId); n++;
100 XtSetValues(X->helpDialog, args, n);
103 XtSetMappedWhenManaged(XtParent(X->helpDialog), False);
104 XSync(X->dpy, False);
106 XtManageChild(X->helpDialog) ;
108 _DtChildPosition(X->helpDialog, X->kframe, &newX, &newY);
109 XtSetArg(args[0], XmNx, newX);
110 XtSetArg(args[1], XmNy, newY);
111 XtSetValues(X->helpDialog, args, 2);
113 XtSetMappedWhenManaged(XtParent(X->helpDialog), True);
114 XSync(X->dpy, False);
116 XtMapWidget(XtParent(X->helpDialog));
117 X->helpMapped = True;
122 HelpCloseCB(widget, client_data, call_data)
124 caddr_t client_data, call_data;
128 HelpStruct *pHelpCache = (HelpStruct *)client_data;
131 for (pHelp = pHelpCache; pHelp != (HelpStruct *)NULL && pHelp->dialog !=widget;
132 pHelp = pHelp->pNext);
133 if (pHelp != (HelpStruct *)NULL)
135 pHelp->inUse = False;
137 XtUnmapWidget(XtParent(widget));
138 X->helpMapped = False;
142 HelpHyperlinkCB(widget, client_data, call_data)
144 caddr_t client_data, call_data;
146 DtHelpDialogCallbackStruct *pHyper = (DtHelpDialogCallbackStruct *) call_data;
148 switch(pHyper->hyperType)
150 case DtHELP_LINK_TOPIC:
151 DisplayHelp(pHyper->helpVolume, pHyper->locationId);
160 HelpRequestCB(widget, client_data, call_data)
162 caddr_t client_data, call_data;
164 char *helpVolume, *locationId;
167 topic = ((int) client_data) & 0xFFFF;
168 helpVolume = HELP_VOLUME;
175 locationId = HELP_BLANK_STR;
178 locationId = HELP_ACC_STR;
181 if(v->modetype == LOGICAL)
182 locationId = HELP_LSHIFT_STR;
184 locationId = buttons[topic].str;
187 if(v->modetype == LOGICAL)
188 locationId = HELP_RSHIFT_STR;
189 else if(v->modetype == FINANCIAL)
190 locationId = HELP_INT_STR;
192 locationId = buttons[topic].str;
195 if(v->modetype == LOGICAL)
196 locationId = HELP_TRUNC16_STR;
197 else if(v->modetype == SCIENTIFIC)
198 locationId = HELP_ETOX_STR;
200 locationId = buttons[topic].str;
203 if(v->modetype == LOGICAL)
204 locationId = HELP_TRUNC32_STR;
205 else if(v->modetype == SCIENTIFIC)
206 locationId = HELP_TENTOX_STR;
208 locationId = buttons[topic].str;
211 if(v->modetype == SCIENTIFIC)
212 locationId = HELP_YTOX_STR;
214 locationId = buttons[topic].str;
217 if(v->modetype == SCIENTIFIC)
218 locationId = HELP_XFACT_STR;
219 else if(v->modetype == FINANCIAL)
220 locationId = HELP_PAYPYR_STR;
222 locationId = buttons[topic].str;
225 if(v->modetype == LOGICAL)
226 locationId = HELP_BLANK_STR;
228 locationId = buttons[topic].str;
231 if(v->modetype == LOGICAL)
232 locationId = HELP_BLANK_STR;
234 locationId = buttons[topic].str;
237 if(v->modetype == LOGICAL || v->modetype == FINANCIAL)
238 locationId = HELP_BLANK_STR;
240 locationId = buttons[topic].str;
243 locationId = HELP_RECIP_STR;
246 locationId = HELP_SQUARE_STR;
249 locationId = HELP_SQRT_STR;
252 locationId = HELP_PERCENT_STR;
255 locationId = HELP_LPAREN_STR;
258 locationId = HELP_RPAREN_STR;
261 locationId = HELP_CHGSIGN_STR;
264 locationId = HELP_TIMES_STR;
267 locationId = HELP_SEVEN_STR;
270 locationId = HELP_EIGHT_STR;
273 locationId = HELP_NINE_STR;
276 locationId = HELP_DIVIDE_STR;
279 locationId = HELP_FOUR_STR;
282 locationId = HELP_FIVE_STR;
285 locationId = HELP_SIX_STR;
288 locationId = HELP_MINUS_STR;
291 locationId = HELP_ONE_STR;
294 locationId = HELP_TWO_STR;
297 locationId = HELP_THREE_STR;
300 locationId = HELP_PLUS_STR;
303 locationId = HELP_ZERO_STR;
306 locationId = HELP_DECIMAL_STR;
309 locationId = HELP_EQUAL_STR;
312 locationId = buttons[topic].str;
320 locationId = HELP_HELP_MENU_STR;
322 case HELP_INTRODUCTION:
323 locationId = HELP_INTRODUCTION_STR;
325 case HELP_TABLEOFCONTENTS:
326 locationId = HELP_TABLEOFCONTENTS_STR;
329 locationId = HELP_TASKS_STR;
332 locationId = HELP_REFERENCE_STR;
335 locationId = HELP_ITEM_STR;
338 locationId = HELP_USING_STR;
339 helpVolume = HELP_USING_HELP_VOLUME;
342 locationId = HELP_VERSION_STR;
345 locationId = HELP_ASCII_STR;
348 locationId = HELP_CONSTANT_STR;
351 locationId = HELP_FUNCTION_STR;
354 locationId = HELP_DISPLAY_STR;
357 locationId = HELP_MODELINE_STR;
360 locationId = mode_str[(int) v->modetype];
363 locationId = base_str[(int) v->base];
366 locationId = dtype_str[(int) v->dtype];
369 locationId = ttype_str[(int) v->ttype];
372 locationId = HELP_MENUBAR_STR;
375 locationId = HELP_INTRODUCTION_STR;
378 Help(helpVolume, locationId);
380 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
381 (XtTimerCallbackProc) TimerEvent, (XtPointer) NULL);
385 HelpModeCB(w, client_data, call_data)
387 caddr_t client_data, call_data;
390 char *errorMsg, *tmp;
392 switch(DtHelpReturnSelectedWidgetId(X->mainWin, (Cursor)NULL, &widget))
394 case DtHELP_SELECT_VALID:
395 while (!XtIsShell(widget))
397 if(XtHasCallbacks(widget, XmNhelpCallback) == XtCallbackHasSome)
399 XtCallCallbacks(widget, XmNhelpCallback,
400 (XtPointer)client_data);
403 widget = XtParent(widget);
407 case DtHELP_SELECT_INVALID:
408 errorMsg = GETMESSAGE(4, 2, "You must select an item within Calculator");
409 tmp = XtNewString(errorMsg);
410 ErrDialog((char *) tmp, X->mainWin);
417 DisplayHelp( helpVolume, locationId)
424 X->helpDialog = GetHelpDialog();
427 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
428 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
429 XtSetArg(args[n], DtNlocationId, locationId); n++;
430 XtSetValues(X->helpDialog, args, n);
432 XtManageChild(X->helpDialog);
433 XtMapWidget(XtParent(X->helpDialog));
434 X->helpMapped = True;
441 static HelpStruct *pHelpCache;
447 if(pHelpCache == (HelpStruct *)NULL)
449 pHelp = pHelpCache = (HelpStruct *)XtMalloc(sizeof(HelpStruct));
450 pHelp->pNext = (HelpStruct *)NULL;
451 pHelp->pPrev = (HelpStruct *)NULL;
454 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
455 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
457 DtWsmRemoveWorkspaceFunctions(X->dpy,
458 XtWindow(XtParent(pHelp->dialog)));
459 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
460 (XtCallbackProc)HelpHyperlinkCB, NULL);
461 XtAddCallback(pHelp->dialog, DtNcloseCallback,
462 (XtCallbackProc)HelpCloseCB, pHelpCache);
463 return pHelp->dialog;
467 for(pHelp = pHelpCache;
468 pHelp != (HelpStruct *)NULL;
469 pHelp = pHelp->pNext)
471 if(pHelp->inUse == False)
474 return pHelp->dialog;
477 pHelp = (HelpStruct *) XtMalloc(sizeof(HelpStruct));
478 pHelpCache->pPrev = pHelp;
479 pHelp->pNext = pHelpCache;
481 pHelp->pPrev = (HelpStruct *)NULL;
484 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
485 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
486 DtWsmRemoveWorkspaceFunctions(X->dpy,
487 XtWindow(XtParent(pHelp->dialog)));
488 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
489 (XtCallbackProc)HelpHyperlinkCB, NULL);
490 XtAddCallback(pHelp->dialog, DtNcloseCallback,
491 (XtCallbackProc)HelpCloseCB, pHelpCache);
492 return pHelp->dialog;
497 ErrDialog( errString, visualParent )
499 Widget visualParent ;
505 label = XmStringCreateLocalized(errString) ;
506 X->errParent = visualParent;
508 if (X->errDialog == NULL)
510 ok = XmStringCreateLocalized(GETMESSAGE(4, 4, "OK"));
513 XtSetArg (args[n], XmNokLabelString, ok); n++;
514 XtSetArg (args[n], XmNmessageString, label); n++;
515 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
516 XtSetArg (args[n], XmNautoUnmanage, FALSE); n++;
517 XtSetArg (args[n], XmNdefaultPosition, FALSE); n++;
519 X->errDialog = XmCreateErrorDialog (X->mainWin, "ErroNotice", args, n);
521 XtAddCallback (X->errDialog, XmNokCallback, UnmanageCB, NULL);
522 XtAddCallback (X->errDialog, XmNmapCallback, CenterMsgCB, NULL);
524 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog,
525 XmDIALOG_CANCEL_BUTTON));
527 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog, XmDIALOG_HELP_BUTTON));
530 XtSetArg (args[n], XmNmwmInputMode,
531 MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++;
532 XtSetArg (args[n], XmNuseAsyncGeometry, TRUE); n++;
533 XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 3, "Error")); n++;
534 XtSetValues (XtParent(X->errDialog), args, n);
538 XtSetArg (args[0], XmNmessageString, label);
539 XtSetValues (X->errDialog, args, 1);
541 XmStringFree (label);
542 XtManageChild(X->errDialog);
546 UnmanageCB(widget, client_data, call_data)
548 XtPointer client_data, call_data;
550 XtUnmanageChild(widget);
554 CenterMsgCB (widget, client_data, call_data)
556 XtPointer client_data, call_data;
563 shell = (Widget)client_data;
566 if (!X->errParent || !XtParent(X->errParent) ||
567 !XtIsManaged(X->errParent))
570 shell = XtParent(X->errParent);
573 shell = XtParent (shell);
575 newX = XtX(shell) + XtWidth(shell)/2 - XtWidth(widget)/2;
576 newY = XtY(shell) + XtHeight(shell)/2 - XtHeight(widget)/2;
578 if (newX < 0) newX = 0;
579 if (newY < 0) newY = 0;
582 XtSetArg (args[n], XmNx, newX); n++;
583 XtSetArg (args[n], XmNy, newY); n++;
584 XtSetValues(widget, args, n);