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 libraries 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>
47 #define DIALOG_MWM_FUNC MWM_FUNC_MOVE | MWM_FUNC_CLOSE
49 extern char *base_str[] ; /* Strings for each base value. */
50 extern char *dtype_str[] ; /* Strings for each display mode value. */
51 extern char *mode_str[] ; /* Strings for each mode value. */
52 extern char *ttype_str[] ; /* Strings for each trig type value. */
53 extern Vars v ; /* Calctool variables and options. */
54 extern struct button buttons[] ; /* Calculator button values. */
57 extern Boolean ignore_event;
58 extern XtIntervalId timerId;
59 extern void _DtChildPosition P((Widget, Widget, Position *, Position *)) ;
61 typedef struct _helpStruct {
62 struct _helpStruct *pNext;
63 struct _helpStruct *pPrev;
68 static Widget GetHelpDialog P(()) ;
69 static void UnmanageCB P(()) ;
72 Help(char *helpVolume, char *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 widget, caddr_t client_data, caddr_t call_data)
125 HelpStruct *pHelpCache = (HelpStruct *)client_data;
128 for (pHelp = pHelpCache; pHelp != (HelpStruct *)NULL && pHelp->dialog !=widget;
129 pHelp = pHelp->pNext);
130 if (pHelp != (HelpStruct *)NULL)
132 pHelp->inUse = False;
134 XtUnmapWidget(XtParent(widget));
135 X->helpMapped = False;
139 HelpHyperlinkCB(Widget widget, caddr_t client_data, caddr_t call_data)
141 DtHelpDialogCallbackStruct *pHyper = (DtHelpDialogCallbackStruct *) call_data;
143 switch(pHyper->hyperType)
145 case DtHELP_LINK_TOPIC:
146 DisplayHelp(pHyper->helpVolume, pHyper->locationId);
155 HelpRequestCB(Widget widget, caddr_t client_data, caddr_t call_data)
157 char *helpVolume, *locationId;
160 topic = ((intptr_t) client_data) & 0xFFFF;
161 helpVolume = HELP_VOLUME;
168 locationId = HELP_BLANK_STR;
171 locationId = HELP_ACC_STR;
174 if(v->modetype == LOGICAL)
175 locationId = HELP_LSHIFT_STR;
177 locationId = buttons[topic].str;
180 if(v->modetype == LOGICAL)
181 locationId = HELP_RSHIFT_STR;
182 else if(v->modetype == FINANCIAL)
183 locationId = HELP_INT_STR;
185 locationId = buttons[topic].str;
188 if(v->modetype == LOGICAL)
189 locationId = HELP_TRUNC16_STR;
190 else if(v->modetype == SCIENTIFIC)
191 locationId = HELP_ETOX_STR;
193 locationId = buttons[topic].str;
196 if(v->modetype == LOGICAL)
197 locationId = HELP_TRUNC32_STR;
198 else if(v->modetype == SCIENTIFIC)
199 locationId = HELP_TENTOX_STR;
201 locationId = buttons[topic].str;
204 if(v->modetype == SCIENTIFIC)
205 locationId = HELP_YTOX_STR;
207 locationId = buttons[topic].str;
210 if(v->modetype == SCIENTIFIC)
211 locationId = HELP_XFACT_STR;
212 else if(v->modetype == FINANCIAL)
213 locationId = HELP_PAYPYR_STR;
215 locationId = buttons[topic].str;
218 if(v->modetype == LOGICAL)
219 locationId = HELP_BLANK_STR;
221 locationId = buttons[topic].str;
224 if(v->modetype == LOGICAL)
225 locationId = HELP_BLANK_STR;
227 locationId = buttons[topic].str;
230 if(v->modetype == LOGICAL || v->modetype == FINANCIAL)
231 locationId = HELP_BLANK_STR;
233 locationId = buttons[topic].str;
236 locationId = HELP_RECIP_STR;
239 locationId = HELP_SQUARE_STR;
242 locationId = HELP_SQRT_STR;
245 locationId = HELP_PERCENT_STR;
248 locationId = HELP_LPAREN_STR;
251 locationId = HELP_RPAREN_STR;
254 locationId = HELP_CHGSIGN_STR;
257 locationId = HELP_TIMES_STR;
260 locationId = HELP_SEVEN_STR;
263 locationId = HELP_EIGHT_STR;
266 locationId = HELP_NINE_STR;
269 locationId = HELP_DIVIDE_STR;
272 locationId = HELP_FOUR_STR;
275 locationId = HELP_FIVE_STR;
278 locationId = HELP_SIX_STR;
281 locationId = HELP_MINUS_STR;
284 locationId = HELP_ONE_STR;
287 locationId = HELP_TWO_STR;
290 locationId = HELP_THREE_STR;
293 locationId = HELP_PLUS_STR;
296 locationId = HELP_ZERO_STR;
299 locationId = HELP_DECIMAL_STR;
302 locationId = HELP_EQUAL_STR;
305 locationId = buttons[topic].str;
313 locationId = HELP_HELP_MENU_STR;
315 case HELP_INTRODUCTION:
316 locationId = HELP_INTRODUCTION_STR;
318 case HELP_TABLEOFCONTENTS:
319 locationId = HELP_TABLEOFCONTENTS_STR;
322 locationId = HELP_TASKS_STR;
325 locationId = HELP_REFERENCE_STR;
328 locationId = HELP_ITEM_STR;
331 locationId = HELP_USING_STR;
332 helpVolume = HELP_USING_HELP_VOLUME;
335 locationId = HELP_VERSION_STR;
338 locationId = HELP_ASCII_STR;
341 locationId = HELP_CONSTANT_STR;
344 locationId = HELP_FUNCTION_STR;
347 locationId = HELP_DISPLAY_STR;
350 locationId = HELP_MODELINE_STR;
353 locationId = mode_str[(int) v->modetype];
356 locationId = base_str[(int) v->base];
359 locationId = dtype_str[(int) v->dtype];
362 locationId = ttype_str[(int) v->ttype];
365 locationId = HELP_MENUBAR_STR;
368 locationId = HELP_INTRODUCTION_STR;
371 Help(helpVolume, locationId);
373 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
374 (XtTimerCallbackProc) TimerEvent, (XtPointer) NULL);
378 HelpModeCB(Widget w, caddr_t client_data, caddr_t call_data)
381 char *errorMsg, *tmp;
383 switch(DtHelpReturnSelectedWidgetId(X->mainWin, (Cursor)NULL, &widget))
385 case DtHELP_SELECT_VALID:
386 while (!XtIsShell(widget))
388 if(XtHasCallbacks(widget, XmNhelpCallback) == XtCallbackHasSome)
390 XtCallCallbacks(widget, XmNhelpCallback,
391 (XtPointer)client_data);
394 widget = XtParent(widget);
398 case DtHELP_SELECT_INVALID:
399 errorMsg = GETMESSAGE(4, 2, "You must select an item within Calculator");
400 tmp = XtNewString(errorMsg);
401 ErrDialog((char *) tmp, X->mainWin);
408 DisplayHelp(char *helpVolume, char *locationId)
413 X->helpDialog = GetHelpDialog();
416 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
417 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
418 XtSetArg(args[n], DtNlocationId, locationId); n++;
419 XtSetValues(X->helpDialog, args, n);
421 XtManageChild(X->helpDialog);
422 XtMapWidget(XtParent(X->helpDialog));
423 X->helpMapped = True;
430 static HelpStruct *pHelpCache;
435 if(pHelpCache == (HelpStruct *)NULL)
437 pHelp = pHelpCache = (HelpStruct *)XtMalloc(sizeof(HelpStruct));
438 pHelp->pNext = (HelpStruct *)NULL;
439 pHelp->pPrev = (HelpStruct *)NULL;
442 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
443 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
445 DtWsmRemoveWorkspaceFunctions(X->dpy,
446 XtWindow(XtParent(pHelp->dialog)));
447 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
448 (XtCallbackProc)HelpHyperlinkCB, NULL);
449 XtAddCallback(pHelp->dialog, DtNcloseCallback,
450 (XtCallbackProc)HelpCloseCB, pHelpCache);
451 return pHelp->dialog;
455 for(pHelp = pHelpCache;
456 pHelp != (HelpStruct *)NULL;
457 pHelp = pHelp->pNext)
459 if(pHelp->inUse == False)
462 return pHelp->dialog;
465 pHelp = (HelpStruct *) XtMalloc(sizeof(HelpStruct));
466 pHelpCache->pPrev = pHelp;
467 pHelp->pNext = pHelpCache;
469 pHelp->pPrev = (HelpStruct *)NULL;
472 XtSetArg(args[0], XmNtitle, GETMESSAGE(4, 1, "Calculator - Help"));
473 pHelp->dialog = DtCreateHelpDialog(X->mainWin, "helpDlg", args, 1);
474 DtWsmRemoveWorkspaceFunctions(X->dpy,
475 XtWindow(XtParent(pHelp->dialog)));
476 XtAddCallback(pHelp->dialog, DtNhyperLinkCallback,
477 (XtCallbackProc)HelpHyperlinkCB, NULL);
478 XtAddCallback(pHelp->dialog, DtNcloseCallback,
479 (XtCallbackProc)HelpCloseCB, pHelpCache);
480 return pHelp->dialog;
485 ErrDialog(char *errString, Widget visualParent)
491 label = XmStringCreateLocalized(errString) ;
492 X->errParent = visualParent;
494 if (X->errDialog == NULL)
496 ok = XmStringCreateLocalized(GETMESSAGE(4, 4, "OK"));
499 XtSetArg (args[n], XmNokLabelString, ok); n++;
500 XtSetArg (args[n], XmNmessageString, label); n++;
501 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
502 XtSetArg (args[n], XmNautoUnmanage, FALSE); n++;
503 XtSetArg (args[n], XmNdefaultPosition, FALSE); n++;
505 X->errDialog = XmCreateErrorDialog (X->mainWin, "ErroNotice", args, n);
507 XtAddCallback (X->errDialog, XmNokCallback, UnmanageCB, NULL);
508 XtAddCallback (X->errDialog, XmNmapCallback, CenterMsgCB, NULL);
510 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog,
511 XmDIALOG_CANCEL_BUTTON));
513 XtUnmanageChild (XmMessageBoxGetChild (X->errDialog, XmDIALOG_HELP_BUTTON));
516 XtSetArg (args[n], XmNmwmInputMode,
517 MWM_INPUT_PRIMARY_APPLICATION_MODAL);n++;
518 XtSetArg (args[n], XmNuseAsyncGeometry, TRUE); n++;
519 XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 3, "Error")); n++;
520 XtSetValues (XtParent(X->errDialog), args, n);
524 XtSetArg (args[0], XmNmessageString, label);
525 XtSetValues (X->errDialog, args, 1);
527 XmStringFree (label);
528 XtManageChild(X->errDialog);
532 UnmanageCB(Widget widget, XtPointer client_data, XtPointer call_data)
534 XtUnmanageChild(widget);
538 CenterMsgCB (Widget widget, XtPointer client_data, XtPointer call_data)
545 shell = (Widget)client_data;
548 if (!X->errParent || !XtParent(X->errParent) ||
549 !XtIsManaged(X->errParent))
552 shell = XtParent(X->errParent);
555 shell = XtParent (shell);
557 newX = XtX(shell) + XtWidth(shell)/2 - XtWidth(widget)/2;
558 newY = XtY(shell) + XtHeight(shell)/2 - XtHeight(widget)/2;
560 if (newX < 0) newX = 0;
561 if (newY < 0) newY = 0;
564 XtSetArg (args[n], XmNx, newX); n++;
565 XtSetArg (args[n], XmNy, newY); n++;
566 XtSetValues(widget, args, n);