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>
41 #include <Dt/HelpDialog.h>
46 #define DIALOG_MWM_FUNC MWM_FUNC_MOVE | MWM_FUNC_CLOSE
48 extern char *base_str[] ; /* Strings for each base value. */
49 extern char *dtype_str[] ; /* Strings for each display mode value. */
50 extern char *mode_str[] ; /* Strings for each mode value. */
51 extern char *ttype_str[] ; /* Strings for each trig type value. */
52 extern Vars v ; /* Calctool variables and options. */
53 extern struct button buttons[] ; /* Calculator button values. */
56 extern Boolean ignore_event;
57 extern XtIntervalId timerId;
58 extern void _DtChildPosition P((Widget, Widget, Position *, Position *)) ;
60 typedef struct _helpStruct {
61 struct _helpStruct *pNext;
62 struct _helpStruct *pPrev;
67 static Widget GetHelpDialog P(()) ;
68 static void UnmanageCB P(()) ;
71 Help(char *helpVolume, char *locationId)
77 if(X->helpDialog == NULL)
80 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
81 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
82 XtSetArg(args[n], DtNlocationId, locationId); n++;
83 XtSetArg(args[n], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help")); n++;
84 X->helpDialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, n);
86 DtWsmRemoveWorkspaceFunctions(X->dpy,
87 XtWindow(XtParent(X->helpDialog)));
88 XtAddCallback(X->helpDialog, DtNhyperLinkCallback,
89 (XtCallbackProc)HelpHyperlinkCB, NULL);
90 XtAddCallback(X->helpDialog, DtNcloseCallback,
91 (XtCallbackProc)HelpCloseCB, NULL);
96 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
97 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
98 XtSetArg(args[n], DtNlocationId, locationId); n++;
99 XtSetValues(X->helpDialog, args, n);
102 XtSetMappedWhenManaged(XtParent(X->helpDialog), False);
103 XSync(X->dpy, False);
105 XtManageChild(X->helpDialog) ;
107 _DtChildPosition(X->helpDialog, X->kframe, &newX, &newY);
108 XtSetArg(args[0], XmNx, newX);
109 XtSetArg(args[1], XmNy, newY);
110 XtSetValues(X->helpDialog, args, 2);
112 XtSetMappedWhenManaged(XtParent(X->helpDialog), True);
113 XSync(X->dpy, False);
115 XtMapWidget(XtParent(X->helpDialog));
116 X->helpMapped = True;
121 HelpCloseCB(Widget widget, caddr_t client_data, caddr_t call_data)
124 HelpStruct *pHelpCache = (HelpStruct *)client_data;
127 for (pHelp = pHelpCache; pHelp != (HelpStruct *)NULL && pHelp->dialog !=widget;
128 pHelp = pHelp->pNext);
129 if (pHelp != (HelpStruct *)NULL)
131 pHelp->inUse = False;
133 XtUnmapWidget(XtParent(widget));
134 X->helpMapped = False;
138 HelpHyperlinkCB(Widget widget, caddr_t client_data, caddr_t call_data)
140 DtHelpDialogCallbackStruct *pHyper = (DtHelpDialogCallbackStruct *) call_data;
142 switch(pHyper->hyperType)
144 case DtHELP_LINK_TOPIC:
145 DisplayHelp(pHyper->helpVolume, pHyper->locationId);
154 HelpRequestCB(Widget widget, caddr_t client_data, caddr_t call_data)
156 char *helpVolume, *locationId;
159 topic = ((intptr_t) client_data) & 0xFFFF;
160 helpVolume = HELP_VOLUME;
167 locationId = HELP_BLANK_STR;
170 locationId = HELP_ACC_STR;
173 if(v->modetype == LOGICAL)
174 locationId = HELP_LSHIFT_STR;
176 locationId = buttons[topic].str;
179 if(v->modetype == LOGICAL)
180 locationId = HELP_RSHIFT_STR;
181 else if(v->modetype == FINANCIAL)
182 locationId = HELP_INT_STR;
184 locationId = buttons[topic].str;
187 if(v->modetype == LOGICAL)
188 locationId = HELP_TRUNC16_STR;
189 else if(v->modetype == SCIENTIFIC)
190 locationId = HELP_ETOX_STR;
192 locationId = buttons[topic].str;
195 if(v->modetype == LOGICAL)
196 locationId = HELP_TRUNC32_STR;
197 else if(v->modetype == SCIENTIFIC)
198 locationId = HELP_TENTOX_STR;
200 locationId = buttons[topic].str;
203 if(v->modetype == SCIENTIFIC)
204 locationId = HELP_YTOX_STR;
206 locationId = buttons[topic].str;
209 if(v->modetype == SCIENTIFIC)
210 locationId = HELP_XFACT_STR;
211 else if(v->modetype == FINANCIAL)
212 locationId = HELP_PAYPYR_STR;
214 locationId = buttons[topic].str;
217 if(v->modetype == LOGICAL)
218 locationId = HELP_BLANK_STR;
220 locationId = buttons[topic].str;
223 if(v->modetype == LOGICAL)
224 locationId = HELP_BLANK_STR;
226 locationId = buttons[topic].str;
229 if(v->modetype == LOGICAL || v->modetype == FINANCIAL)
230 locationId = HELP_BLANK_STR;
232 locationId = buttons[topic].str;
235 locationId = HELP_RECIP_STR;
238 locationId = HELP_SQUARE_STR;
241 locationId = HELP_SQRT_STR;
244 locationId = HELP_PERCENT_STR;
247 locationId = HELP_LPAREN_STR;
250 locationId = HELP_RPAREN_STR;
253 locationId = HELP_CHGSIGN_STR;
256 locationId = HELP_TIMES_STR;
259 locationId = HELP_SEVEN_STR;
262 locationId = HELP_EIGHT_STR;
265 locationId = HELP_NINE_STR;
268 locationId = HELP_DIVIDE_STR;
271 locationId = HELP_FOUR_STR;
274 locationId = HELP_FIVE_STR;
277 locationId = HELP_SIX_STR;
280 locationId = HELP_MINUS_STR;
283 locationId = HELP_ONE_STR;
286 locationId = HELP_TWO_STR;
289 locationId = HELP_THREE_STR;
292 locationId = HELP_PLUS_STR;
295 locationId = HELP_ZERO_STR;
298 locationId = HELP_DECIMAL_STR;
301 locationId = HELP_EQUAL_STR;
304 locationId = buttons[topic].str;
312 locationId = HELP_HELP_MENU_STR;
314 case HELP_INTRODUCTION:
315 locationId = HELP_INTRODUCTION_STR;
317 case HELP_TABLEOFCONTENTS:
318 locationId = HELP_TABLEOFCONTENTS_STR;
321 locationId = HELP_TASKS_STR;
324 locationId = HELP_REFERENCE_STR;
327 locationId = HELP_ITEM_STR;
330 locationId = HELP_USING_STR;
331 helpVolume = HELP_USING_HELP_VOLUME;
334 locationId = HELP_VERSION_STR;
337 locationId = HELP_ASCII_STR;
340 locationId = HELP_CONSTANT_STR;
343 locationId = HELP_FUNCTION_STR;
346 locationId = HELP_DISPLAY_STR;
349 locationId = HELP_MODELINE_STR;
352 locationId = mode_str[(int) v->modetype];
355 locationId = base_str[(int) v->base];
358 locationId = dtype_str[(int) v->dtype];
361 locationId = ttype_str[(int) v->ttype];
364 locationId = HELP_MENUBAR_STR;
367 locationId = HELP_INTRODUCTION_STR;
370 Help(helpVolume, locationId);
372 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
373 (XtTimerCallbackProc) TimerEvent, (XtPointer) NULL);
377 HelpModeCB(Widget w, caddr_t client_data, caddr_t call_data)
380 char *errorMsg, *tmp;
382 switch(DtHelpReturnSelectedWidgetId(X->mainWin, (Cursor)NULL, &widget))
384 case DtHELP_SELECT_VALID:
385 while (!XtIsShell(widget))
387 if(XtHasCallbacks(widget, XmNhelpCallback) == XtCallbackHasSome)
389 XtCallCallbacks(widget, XmNhelpCallback,
390 (XtPointer)client_data);
393 widget = XtParent(widget);
397 case DtHELP_SELECT_INVALID:
398 errorMsg = GETMESSAGE(4, 2, "You must select an item within Calculator");
399 tmp = XtNewString(errorMsg);
400 ErrDialog((char *) tmp, X->mainWin);
407 DisplayHelp(char *helpVolume, char *locationId)
412 X->helpDialog = GetHelpDialog();
415 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
416 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
417 XtSetArg(args[n], DtNlocationId, locationId); n++;
418 XtSetValues(X->helpDialog, args, n);
420 XtManageChild(X->helpDialog);
421 XtMapWidget(XtParent(X->helpDialog));
422 X->helpMapped = True;
429 static HelpStruct *pHelpCache;
434 if(pHelpCache == (HelpStruct *)NULL)
436 pHelp = pHelpCache = (HelpStruct *)XtMalloc(sizeof(HelpStruct));
437 pHelp->pNext = (HelpStruct *)NULL;
438 pHelp->pPrev = (HelpStruct *)NULL;
441 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
442 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
444 DtWsmRemoveWorkspaceFunctions(X->dpy,
445 XtWindow(XtParent(pHelp->dialog)));
446 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
447 (XtCallbackProc)HelpHyperlinkCB, NULL);
448 XtAddCallback(pHelp->dialog, DtNcloseCallback,
449 (XtCallbackProc)HelpCloseCB, pHelpCache);
450 return pHelp->dialog;
454 for(pHelp = pHelpCache;
455 pHelp != (HelpStruct *)NULL;
456 pHelp = pHelp->pNext)
458 if(pHelp->inUse == False)
461 return pHelp->dialog;
464 pHelp = (HelpStruct *) XtMalloc(sizeof(HelpStruct));
465 pHelpCache->pPrev = pHelp;
466 pHelp->pNext = pHelpCache;
468 pHelp->pPrev = (HelpStruct *)NULL;
471 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
472 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
473 DtWsmRemoveWorkspaceFunctions(X->dpy,
474 XtWindow(XtParent(pHelp->dialog)));
475 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
476 (XtCallbackProc)HelpHyperlinkCB, NULL);
477 XtAddCallback(pHelp->dialog, DtNcloseCallback,
478 (XtCallbackProc)HelpCloseCB, pHelpCache);
479 return pHelp->dialog;
484 ErrDialog(char *errString, Widget visualParent)
490 label = XmStringCreateLocalized(errString) ;
491 X->errParent = visualParent;
493 if (X->errDialog == NULL)
495 ok = XmStringCreateLocalized(GETMESSAGE(4, 4, "OK"));
498 XtSetArg (args[n], XmNokLabelString, ok); n++;
499 XtSetArg (args[n], XmNmessageString, label); n++;
500 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
501 XtSetArg (args[n], XmNautoUnmanage, FALSE); n++;
502 XtSetArg (args[n], XmNdefaultPosition, FALSE); n++;
504 X->errDialog = XmCreateErrorDialog (X->mainWin, "ErroNotice", args, n);
506 XtAddCallback (X->errDialog, XmNokCallback, UnmanageCB, NULL);
507 XtAddCallback (X->errDialog, XmNmapCallback, CenterMsgCB, NULL);
509 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog,
510 XmDIALOG_CANCEL_BUTTON));
512 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog, XmDIALOG_HELP_BUTTON));
515 XtSetArg (args[n], XmNmwmInputMode,
516 MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++;
517 XtSetArg (args[n], XmNuseAsyncGeometry, TRUE); n++;
518 XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 3, "Error")); n++;
519 XtSetValues (XtParent(X->errDialog), args, n);
523 XtSetArg (args[0], XmNmessageString, label);
524 XtSetValues (X->errDialog, args, 1);
526 XmStringFree (label);
527 XtManageChild(X->errDialog);
531 UnmanageCB(Widget widget, XtPointer client_data, XtPointer call_data)
533 XtUnmanageChild(widget);
537 CenterMsgCB (Widget widget, XtPointer client_data, XtPointer call_data)
544 shell = (Widget)client_data;
547 if (!X->errParent || !XtParent(X->errParent) ||
548 !XtIsManaged(X->errParent))
551 shell = XtParent(X->errParent);
554 shell = XtParent (shell);
556 newX = XtX(shell) + XtWidth(shell)/2 - XtWidth(widget)/2;
557 newY = XtY(shell) + XtHeight(shell)/2 - XtHeight(widget)/2;
559 if (newX < 0) newX = 0;
560 if (newY < 0) newY = 0;
563 XtSetArg (args[n], XmNx, newX); n++;
564 XtSetArg (args[n], XmNy, newY); n++;
565 XtSetValues(widget, args, n);