1 /* $XConsortium: help.c /main/4 1996/03/25 13:12:20 ageorge $ */
4 * Contains all support for help in the Calculator. *
6 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
7 * (c) Copyright 1993, 1994 International Business Machines Corp. *
8 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
9 * (c) Copyright 1993, 1994 Novell, Inc. *
14 #include <Xm/MwmUtil.h>
15 #include <Xm/MessageB.h>
18 #include <Dt/HelpDialog.h>
23 #define DIALOG_MWM_FUNC MWM_FUNC_MOVE | MWM_FUNC_CLOSE
25 extern char *base_str[] ; /* Strings for each base value. */
26 extern char *dtype_str[] ; /* Strings for each display mode value. */
27 extern char *mode_str[] ; /* Strings for each mode value. */
28 extern char *ttype_str[] ; /* Strings for each trig type value. */
29 extern Vars v ; /* Calctool variables and options. */
30 extern struct button buttons[] ; /* Calculator button values. */
33 extern Boolean ignore_event;
34 extern XtIntervalId timerId;
35 extern void _DtChildPosition P((Widget, Widget, Position *, Position *)) ;
37 typedef struct _helpStruct {
38 struct _helpStruct *pNext;
39 struct _helpStruct *pPrev;
44 static Widget GetHelpDialog P(()) ;
45 static void UnmanageCB P(()) ;
48 Help(helpVolume, locationId)
56 if(X->helpDialog == NULL)
59 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
60 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
61 XtSetArg(args[n], DtNlocationId, locationId); n++;
62 XtSetArg(args[n], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help")); n++;
63 X->helpDialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, n);
65 DtWsmRemoveWorkspaceFunctions(X->dpy,
66 XtWindow(XtParent(X->helpDialog)));
67 XtAddCallback(X->helpDialog, DtNhyperLinkCallback,
68 (XtCallbackProc)HelpHyperlinkCB, NULL);
69 XtAddCallback(X->helpDialog, DtNcloseCallback,
70 (XtCallbackProc)HelpCloseCB, NULL);
75 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
76 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
77 XtSetArg(args[n], DtNlocationId, locationId); n++;
78 XtSetValues(X->helpDialog, args, n);
81 XtSetMappedWhenManaged(XtParent(X->helpDialog), False);
84 XtManageChild(X->helpDialog) ;
86 _DtChildPosition(X->helpDialog, X->kframe, &newX, &newY);
87 XtSetArg(args[0], XmNx, newX);
88 XtSetArg(args[1], XmNy, newY);
89 XtSetValues(X->helpDialog, args, 2);
91 XtSetMappedWhenManaged(XtParent(X->helpDialog), True);
94 XtMapWidget(XtParent(X->helpDialog));
100 HelpCloseCB(widget, client_data, call_data)
102 caddr_t client_data, call_data;
106 HelpStruct *pHelpCache = (HelpStruct *)client_data;
109 for (pHelp = pHelpCache; pHelp != (HelpStruct *)NULL && pHelp->dialog !=widget;
110 pHelp = pHelp->pNext);
111 if (pHelp != (HelpStruct *)NULL)
113 pHelp->inUse = False;
115 XtUnmapWidget(XtParent(widget));
116 X->helpMapped = False;
120 HelpHyperlinkCB(widget, client_data, call_data)
122 caddr_t client_data, call_data;
124 DtHelpDialogCallbackStruct *pHyper = (DtHelpDialogCallbackStruct *) call_data;
126 switch(pHyper->hyperType)
128 case DtHELP_LINK_TOPIC:
129 DisplayHelp(pHyper->helpVolume, pHyper->locationId);
138 HelpRequestCB(widget, client_data, call_data)
140 caddr_t client_data, call_data;
142 char *helpVolume, *locationId;
145 topic = ((int) client_data) & 0xFFFF;
146 helpVolume = HELP_VOLUME;
153 locationId = HELP_BLANK_STR;
156 locationId = HELP_ACC_STR;
159 if(v->modetype == LOGICAL)
160 locationId = HELP_LSHIFT_STR;
162 locationId = buttons[topic].str;
165 if(v->modetype == LOGICAL)
166 locationId = HELP_RSHIFT_STR;
167 else if(v->modetype == FINANCIAL)
168 locationId = HELP_INT_STR;
170 locationId = buttons[topic].str;
173 if(v->modetype == LOGICAL)
174 locationId = HELP_TRUNC16_STR;
175 else if(v->modetype == SCIENTIFIC)
176 locationId = HELP_ETOX_STR;
178 locationId = buttons[topic].str;
181 if(v->modetype == LOGICAL)
182 locationId = HELP_TRUNC32_STR;
183 else if(v->modetype == SCIENTIFIC)
184 locationId = HELP_TENTOX_STR;
186 locationId = buttons[topic].str;
189 if(v->modetype == SCIENTIFIC)
190 locationId = HELP_YTOX_STR;
192 locationId = buttons[topic].str;
195 if(v->modetype == SCIENTIFIC)
196 locationId = HELP_XFACT_STR;
197 else if(v->modetype == FINANCIAL)
198 locationId = HELP_PAYPYR_STR;
200 locationId = buttons[topic].str;
203 if(v->modetype == LOGICAL)
204 locationId = HELP_BLANK_STR;
206 locationId = buttons[topic].str;
209 if(v->modetype == LOGICAL)
210 locationId = HELP_BLANK_STR;
212 locationId = buttons[topic].str;
215 if(v->modetype == LOGICAL || v->modetype == FINANCIAL)
216 locationId = HELP_BLANK_STR;
218 locationId = buttons[topic].str;
221 locationId = HELP_RECIP_STR;
224 locationId = HELP_SQUARE_STR;
227 locationId = HELP_SQRT_STR;
230 locationId = HELP_PERCENT_STR;
233 locationId = HELP_LPAREN_STR;
236 locationId = HELP_RPAREN_STR;
239 locationId = HELP_CHGSIGN_STR;
242 locationId = HELP_TIMES_STR;
245 locationId = HELP_SEVEN_STR;
248 locationId = HELP_EIGHT_STR;
251 locationId = HELP_NINE_STR;
254 locationId = HELP_DIVIDE_STR;
257 locationId = HELP_FOUR_STR;
260 locationId = HELP_FIVE_STR;
263 locationId = HELP_SIX_STR;
266 locationId = HELP_MINUS_STR;
269 locationId = HELP_ONE_STR;
272 locationId = HELP_TWO_STR;
275 locationId = HELP_THREE_STR;
278 locationId = HELP_PLUS_STR;
281 locationId = HELP_ZERO_STR;
284 locationId = HELP_DECIMAL_STR;
287 locationId = HELP_EQUAL_STR;
290 locationId = buttons[topic].str;
298 locationId = HELP_HELP_MENU_STR;
300 case HELP_INTRODUCTION:
301 locationId = HELP_INTRODUCTION_STR;
303 case HELP_TABLEOFCONTENTS:
304 locationId = HELP_TABLEOFCONTENTS_STR;
307 locationId = HELP_TASKS_STR;
310 locationId = HELP_REFERENCE_STR;
313 locationId = HELP_ITEM_STR;
316 locationId = HELP_USING_STR;
317 helpVolume = HELP_USING_HELP_VOLUME;
320 locationId = HELP_VERSION_STR;
323 locationId = HELP_ASCII_STR;
326 locationId = HELP_CONSTANT_STR;
329 locationId = HELP_FUNCTION_STR;
332 locationId = HELP_DISPLAY_STR;
335 locationId = HELP_MODELINE_STR;
338 locationId = mode_str[(int) v->modetype];
341 locationId = base_str[(int) v->base];
344 locationId = dtype_str[(int) v->dtype];
347 locationId = ttype_str[(int) v->ttype];
350 locationId = HELP_MENUBAR_STR;
353 locationId = HELP_INTRODUCTION_STR;
356 Help(helpVolume, locationId);
358 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
359 (XtTimerCallbackProc) TimerEvent, (XtPointer) NULL);
363 HelpModeCB(w, client_data, call_data)
365 caddr_t client_data, call_data;
368 char *errorMsg, *tmp;
370 switch(DtHelpReturnSelectedWidgetId(X->mainWin, (Cursor)NULL, &widget))
372 case DtHELP_SELECT_VALID:
373 while (!XtIsShell(widget))
375 if(XtHasCallbacks(widget, XmNhelpCallback) == XtCallbackHasSome)
377 XtCallCallbacks(widget, XmNhelpCallback,
378 (XtPointer)client_data);
381 widget = XtParent(widget);
385 case DtHELP_SELECT_INVALID:
386 errorMsg = GETMESSAGE(4, 2, "You must select an item within Calculator");
387 tmp = XtNewString(errorMsg);
388 ErrDialog((char *) tmp, X->mainWin);
395 DisplayHelp( helpVolume, locationId)
402 X->helpDialog = GetHelpDialog();
405 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
406 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
407 XtSetArg(args[n], DtNlocationId, locationId); n++;
408 XtSetValues(X->helpDialog, args, n);
410 XtManageChild(X->helpDialog);
411 XtMapWidget(XtParent(X->helpDialog));
412 X->helpMapped = True;
419 static HelpStruct *pHelpCache;
425 if(pHelpCache == (HelpStruct *)NULL)
427 pHelp = pHelpCache = (HelpStruct *)XtMalloc(sizeof(HelpStruct));
428 pHelp->pNext = (HelpStruct *)NULL;
429 pHelp->pPrev = (HelpStruct *)NULL;
432 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
433 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
435 DtWsmRemoveWorkspaceFunctions(X->dpy,
436 XtWindow(XtParent(pHelp->dialog)));
437 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
438 (XtCallbackProc)HelpHyperlinkCB, NULL);
439 XtAddCallback(pHelp->dialog, DtNcloseCallback,
440 (XtCallbackProc)HelpCloseCB, pHelpCache);
441 return pHelp->dialog;
445 for(pHelp = pHelpCache;
446 pHelp != (HelpStruct *)NULL;
447 pHelp = pHelp->pNext)
449 if(pHelp->inUse == False)
452 return pHelp->dialog;
455 pHelp = (HelpStruct *) XtMalloc(sizeof(HelpStruct));
456 pHelpCache->pPrev = pHelp;
457 pHelp->pNext = pHelpCache;
459 pHelp->pPrev = (HelpStruct *)NULL;
462 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
463 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
464 DtWsmRemoveWorkspaceFunctions(X->dpy,
465 XtWindow(XtParent(pHelp->dialog)));
466 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
467 (XtCallbackProc)HelpHyperlinkCB, NULL);
468 XtAddCallback(pHelp->dialog, DtNcloseCallback,
469 (XtCallbackProc)HelpCloseCB, pHelpCache);
470 return pHelp->dialog;
475 ErrDialog( errString, visualParent )
477 Widget visualParent ;
483 label = XmStringCreateLocalized(errString) ;
484 X->errParent = visualParent;
486 if (X->errDialog == NULL)
488 ok = XmStringCreateLocalized(GETMESSAGE(4, 4, "OK"));
491 XtSetArg (args[n], XmNokLabelString, ok); n++;
492 XtSetArg (args[n], XmNmessageString, label); n++;
493 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
494 XtSetArg (args[n], XmNautoUnmanage, FALSE); n++;
495 XtSetArg (args[n], XmNdefaultPosition, FALSE); n++;
497 X->errDialog = XmCreateErrorDialog (X->mainWin, "ErroNotice", args, n);
499 XtAddCallback (X->errDialog, XmNokCallback, UnmanageCB, NULL);
500 XtAddCallback (X->errDialog, XmNmapCallback, CenterMsgCB, NULL);
502 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog,
503 XmDIALOG_CANCEL_BUTTON));
505 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog, XmDIALOG_HELP_BUTTON));
508 XtSetArg (args[n], XmNmwmInputMode,
509 MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++;
510 XtSetArg (args[n], XmNuseAsyncGeometry, TRUE); n++;
511 XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 3, "Error")); n++;
512 XtSetValues (XtParent(X->errDialog), args, n);
516 XtSetArg (args[0], XmNmessageString, label);
517 XtSetValues (X->errDialog, args, 1);
519 XmStringFree (label);
520 XtManageChild(X->errDialog);
524 UnmanageCB(widget, client_data, call_data)
526 XtPointer client_data, call_data;
528 XtUnmanageChild(widget);
532 CenterMsgCB (widget, client_data, call_data)
534 XtPointer client_data, call_data;
541 shell = (Widget)client_data;
544 if (!X->errParent || !XtParent(X->errParent) ||
545 !XtIsManaged(X->errParent))
548 shell = XtParent(X->errParent);
551 shell = XtParent (shell);
553 newX = XtX(shell) + XtWidth(shell)/2 - XtWidth(widget)/2;
554 newY = XtY(shell) + XtHeight(shell)/2 - XtHeight(widget)/2;
556 if (newX < 0) newX = 0;
557 if (newY < 0) newY = 0;
560 XtSetArg (args[n], XmNx, newX); n++;
561 XtSetArg (args[n], XmNy, newY); n++;
562 XtSetValues(widget, args, n);