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 /* $TOG: motif.c /main/28 1998/07/21 16:17:00 samborn $ */
25 * (c) Copyright 1997, The Open Group
29 * Contains the user interface portion of the Desktop *
32 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
33 * (c) Copyright 1993, 1994 International Business Machines Corp. *
34 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
35 * (c) Copyright 1993, 1994 Novell, Inc. *
43 #include <sys/param.h>
47 #include <X11/keysym.h>
48 #include <X11/Xatom.h>
57 #include <X11/XHPlib.h>
58 #include <X11/HPkeysym.h>
59 #include <X11/Xutil.h>
64 #include <Xm/DrawingA.h>
65 #include <Xm/DrawingAP.h>
66 #include <Xm/MessageB.h>
67 #include <Xm/RowColumn.h>
68 #include <Xm/MwmUtil.h>
69 #include <Xm/ManagerP.h>
71 #include <Xm/ColorObjP.h>
73 #include <Xm/MenuShell.h>
76 #include <Xm/PushBP.h>
77 #include <Xm/PushBG.h>
78 #include <Xm/CascadeB.h>
79 #include <Xm/CascadeBG.h>
80 #include <Xm/MwmUtil.h>
81 #include <Xm/Protocols.h>
82 #include <Xm/VendorSEP.h>
83 #include <Xm/SeparatoG.h>
84 /* Copied from BaseClassI.h */
85 extern XmWidgetExtData _XmGetWidgetExtData(
87 #if NeedWidePrototypes
88 unsigned int extType) ;
90 unsigned char extType) ;
91 #endif /* NeedWidePrototypes */
93 #include <X11/CoreP.h>
95 #include <X11/ShellP.h>
96 #include <X11/Shell.h>
97 #include <X11/IntrinsicP.h>
98 #include <X11/Intrinsic.h>
99 #include <X11/Shell.h>
100 #include <X11/Xatom.h>
101 #include <Xm/Protocols.h>
102 #include <X11/keysymdef.h>
104 #include <Dt/Session.h>
106 #include <Dt/Connect.h>
107 #include <Dt/FileM.h>
108 #include <Dt/Indicator.h>
110 #include <Dt/Message.h>
112 #include <Dt/CommandM.h>
113 #include <Dt/EnvControlP.h>
116 #include <X11/Xmu/Editres.h>
121 #include "ds_widget.h"
122 #include "ds_common.h"
123 #include "ds_popup.h"
128 static XtResource resources[] =
131 "postMenuBar", "PostMenuBar", XmRBoolean, sizeof (Boolean),
132 XtOffset (ApplicationArgsPtr, menuBar), XmRImmediate, (XtPointer) True,
136 "accuracy", "Accuracy", XmRInt, sizeof (int),
137 XtOffset (ApplicationArgsPtr, accuracy), XmRImmediate, (XtPointer) 2,
141 "base", "Base", XmRString, sizeof (char *),
142 XtOffset (ApplicationArgsPtr, base), XmRImmediate, (XtPointer) "decimal",
146 "displayNotation", "DisplayNotation", XmRString, sizeof (char *),
147 XtOffset (ApplicationArgsPtr, display), XmRImmediate, (XtPointer) "fixed",
151 "mode", "Mode", XmRString, sizeof (char *),
152 XtOffset (ApplicationArgsPtr, mode), XmRImmediate, (XtPointer)"scientific",
156 "trigType", "TrigType", XmRString, sizeof (char *),
157 XtOffset (ApplicationArgsPtr, trigType), XmRImmediate,
158 (XtPointer)"degrees",
162 char DTCALC_CLASS_NAME[] = "Dtcalc";
164 extern char *opts[] ; /* Command line option strings. */
167 XmPixelSet pixels[XmCO_MAX_NUM_COLORS];
170 Boolean BlackWhite = False;
172 char * dt_path = NULL;
174 static Widget funBtn = NULL;
175 static Widget constBtn = NULL;
176 static Widget accBtn = NULL;
177 static Widget stoBtn = NULL;
178 static Widget rclBtn = NULL;
179 static Widget exchBtn = NULL;
181 static Atom saveatom ;
182 static Atom command_atom ;
183 static Atom wm_state_atom;
185 Boolean ignore_event = False;
186 XtIntervalId timerId = 0;
188 static int lastArmed[10];
189 static int countArmed = 0;
191 /* Structure used on a save session to see if a dt is iconic */
198 void menu_proc P((Widget, XtPointer, XtPointer)) ;
199 void show_ascii P((Widget, XtPointer, XtPointer)) ;
200 void write_cf_value P((Widget, XtPointer, XtPointer)) ;
201 void close_cf P((Widget, XtPointer, XtPointer)) ;
202 void close_ascii P((Widget, XtPointer, XtPointer)) ;
203 void move_cf P((Widget, XtPointer, XtPointer)) ;
204 void FocusInCB P((Widget, XtPointer, XtPointer)) ;
205 void map_popup P((Widget, XtPointer, XtPointer)) ;
209 static int GetKeyboardID P(()) ;
212 static int event_is_keypad P((XEvent *)) ;
213 static int get_next_event P((Widget, int, XEvent *)) ;
214 static int is_window_showing P((Widget)) ;
216 static KeySym keypad_keysym P((XEvent *)) ;
218 static void modelineValueChanged P((Widget, XtPointer, XtPointer)) ;
219 static void dtcalc_kkeyboard_create P((Widget)) ;
220 static void dtcalc_kpanel_create P((Widget)) ;
221 static void confirm_callback P((Widget, XtPointer, XtPointer)) ;
222 static void create_cfframe P(()) ;
223 static void create_menu P((enum menu_type, Widget, int)) ;
224 static void do_button P((Widget, XtPointer, XtPointer)) ;
225 static void do_confirm_notice P((Widget, char *)) ;
226 static void do_continue_notice P((Widget, char *)) ;
227 static void close_reg P((Widget, XtPointer, XtPointer)) ;
228 static void event_proc P((Widget, XtPointer, XEvent *, Boolean *)) ;
229 static void frame_interpose P((Widget, XtPointer, XEvent *, Boolean *)) ;
230 static void menu_handler P((Widget, XtPointer, XEvent *, Boolean *)) ;
231 static void popupHandler P((Widget, XtPointer, XEvent *, Boolean *)) ;
232 static void make_mode_frame P((enum mode_type)) ;
233 static void new_cf_value P((Widget, XtPointer, XtPointer)) ;
234 static void do_memory P((Widget, XtPointer, XtPointer)) ;
235 static void switch_mode P((enum mode_type)) ;
236 static void update_cf_value P(()) ;
237 static void xerror_interpose P((Display *, XErrorEvent *)) ;
239 static Widget button_create P((Widget, int, int, int, int)) ;
240 static void save_state P((Widget, XtPointer, XtPointer)) ;
241 static void SaveSession P(( char *, char * )) ;
242 static void setCalcHints P(()) ;
244 static char * _DtcalcStripSpaces P(( char * )) ;
246 static void ProcessMotifSelection(Widget);
248 extern char **environ ;
250 extern char *base_str[] ; /* Strings for each base value. */
251 extern char *calc_res[] ; /* Calctool X resources. */
252 extern char *dtype_str[] ; /* Strings for each display mode value. */
253 extern char *lstrs[] ; /* Labels for various Motif items. */
254 extern char *mess[] ; /* Message strings. */
255 extern char *mode_str[] ; /* Strings for each mode value. */
256 extern char *pstrs[] ; /* Property sheet strings. */
257 extern char *ttype_str[] ; /* Strings for each trig type value. */
258 extern char *vstrs[] ; /* Various strings. */
260 extern struct button buttons[] ; /* Calculator button values. */
261 extern struct button mode_buttons[] ; /* Calculator mode button values. */
262 extern struct menu cmenus[] ; /* Calculator menus. */
263 extern struct menu_entry menu_entries[] ; /* All the menu strings. */
265 extern Vars v ; /* Calctool variables and options. */
267 char translations_return[] = "<Key>Return:ManagerGadgetSelect()";
268 static Boolean NoDisplay=False;
270 extern XtPointer _XmStringUngenerate (
274 XmTextType output_type);
281 char bind_home[MAXPATHLEN], **new_environ ;
285 XtSetLanguageProc(NULL, NULL, NULL);
286 _DtEnvControl(DT_ENV_SET);
287 signal (SIGHUP, SIG_IGN);
289 signal (SIGFPE, SIG_IGN);
292 X = (XVars) LINT_CAST(calloc(1, sizeof(XObject))) ;
293 X->home = getenv("HOME") ;
295 X->kframe = XtVaAppInitialize (&X->app,
296 DTCALC_CLASS_NAME, /* app class */
297 NULL, /* options list */
301 NULL, /* fallback resources */
302 XtNiconName, "dtcalc",
303 XtNiconPixmap, X->icon,
304 XtNiconMask, X->iconmask,
307 X->dpy = XtDisplay (X->kframe);
313 tmpStr = GETMESSAGE(2, 31, "Could not open display.\n");
314 msg = XtNewString(tmpStr);
315 FPRINTF(stderr, "%s", msg) ;
319 X->screen = DefaultScreen(X->dpy) ;
320 X->root = RootWindow(X->dpy, X->screen) ;
321 white_pixel = WhitePixel(X->dpy, X->screen);
322 black_pixel = BlackPixel(X->dpy, X->screen);
327 X->helpMapped = False;
329 if (DtInitialize (X->dpy, X->kframe, argv[0], DTCALC_CLASS_NAME) == False)
331 /* Fatal Error: could not connect to the messaging system. */
332 /* DtInitialize() has already logged an appropriate error msg */
336 /* Get the application defined resources */
337 XtGetApplicationResources(X->kframe, &application_args, resources, 6, NULL,0);
339 v = (Vars) LINT_CAST(calloc(1, sizeof(CalcVars))) ;
341 /* Get the dt path created and initialized */
342 dt_path = _DtCreateDtDirs (X->dpy);
346 v->keybdID = GetKeyboardID();
349 init_colors() ; /* get the pixels for the default colors in DT */
350 if(pixels[0].bg == white_pixel || pixels[0].bg == black_pixel)
353 if(colorSrv && !BlackWhite)
355 /* first get the Calculator's Icon */
356 pixmap = XmGetPixmap (DefaultScreenOfDisplay(X->dpy), CALC_ICON_NAME,
357 pixels[1].fg, pixels[1].bg);
358 if( pixmap != XmUNSPECIFIED_PIXMAP)
361 X->icon = XmUNSPECIFIED_PIXMAP;
363 /* now let's get the mask for the Calculator */
364 pixmap = _DtGetMask (DefaultScreenOfDisplay(X->dpy), CALC_ICON_NAME);
365 if( pixmap != XmUNSPECIFIED_PIXMAP)
366 X->iconmask = pixmap;
368 X->iconmask = XmUNSPECIFIED_PIXMAP;
372 /* first get the Calculator's Icon */
373 pixmap = XmGetPixmap (DefaultScreenOfDisplay(X->dpy), CALC_ICON_NAME_BM,
374 white_pixel, black_pixel);
375 if( pixmap != XmUNSPECIFIED_PIXMAP)
378 X->icon = XmUNSPECIFIED_PIXMAP;
380 /* now let's get the mask for the Calculator */
381 pixmap = _DtGetMask (DefaultScreenOfDisplay(X->dpy), CALC_ICON_NAME_BM);
382 if( pixmap != XmUNSPECIFIED_PIXMAP)
383 X->iconmask = pixmap;
385 X->iconmask = XmUNSPECIFIED_PIXMAP;
388 do_dtcalc(argc, argv) ;
401 button_create(owner, row, column, maxrows, maxcols)
403 int row, column, maxrows, maxcols ;
405 int n = row * maxcols + column ;
407 enum menu_type mtype = buttons[n].mtype ;
414 lstr = XmStringCreateLocalized(v->pstr) ;
420 else if(row >= 3 && row < 6)
422 else if(((row == 7 && column == 3) || (row == 13 && column == 3)) &&
425 else if((row >= 6 && row < 8) || (row >= 8 && row < 13 && column == 3) ||
426 (row == 13 && column == 2))
431 button = XtVaCreateManagedWidget(buttons[n].resname,
432 xmPushButtonWidgetClass,
434 XmNtopAttachment, XmATTACH_POSITION,
435 XmNtopPosition, row * maxcols,
436 XmNleftAttachment, XmATTACH_POSITION,
437 XmNleftPosition, column * maxrows,
438 XmNrightAttachment, XmATTACH_POSITION,
439 XmNrightPosition, (column+1) * maxrows,
440 XmNbottomAttachment, XmATTACH_POSITION,
441 XmNbottomPosition, (row+1) * maxcols,
442 XmNlabelString, lstr,
444 XmNtraversalOn, TRUE,
445 XmNalignment, XmALIGNMENT_CENTER,
446 XmNrecomputeSize, False,
447 XmNnavigationType, XmNONE,
451 button = XtVaCreateManagedWidget(buttons[n].resname,
452 xmPushButtonWidgetClass,
454 XmNtopAttachment, XmATTACH_POSITION,
455 XmNtopPosition, row * maxcols,
456 XmNleftAttachment, XmATTACH_POSITION,
457 XmNleftPosition, column * maxrows,
458 XmNrightAttachment, XmATTACH_POSITION,
459 XmNrightPosition, (column+1) * maxrows,
460 XmNbottomAttachment, XmATTACH_POSITION,
461 XmNbottomPosition, (row+1) * maxcols,
462 XmNlabelString, lstr,
463 XmNtraversalOn, TRUE,
464 XmNalignment, XmALIGNMENT_CENTER,
465 XmNrecomputeSize, False,
466 XmNnavigationType, XmNONE,
471 if (mtype != M_NONE) create_menu(mtype, button, n) ;
472 val = (v->curwin << 16) + n ;
473 XtAddCallback(button, XmNactivateCallback, do_button, (XtPointer) val) ;
474 XtAddCallback(button, XmNhelpCallback, HelpRequestCB, (XtPointer) val) ;
475 XtAddEventHandler(button, KeyPressMask | KeyReleaseMask,
476 FALSE, event_proc, NULL) ;
478 if( funBtn == NULL && strcmp(v->pstr, GETMESSAGE(3, 5, "Functions")) == 0)
480 else if( constBtn == NULL && strcmp(v->pstr,
481 GETMESSAGE(3, 6, "Constants")) == 0)
483 else if( accBtn == NULL && strcmp(v->pstr,
484 GETMESSAGE(3, 12, "Accuracy")) == 0)
486 else if( stoBtn == NULL && strcmp(v->pstr, GETMESSAGE(3, 13, "Store")) == 0)
488 else if( rclBtn == NULL && strcmp(v->pstr, GETMESSAGE(3, 14, "Recall")) == 0)
490 else if( exchBtn == NULL && strcmp(v->pstr,
491 GETMESSAGE(3, 15, "Exchange")) == 0)
499 dtcalc_initialize_rframe(owner, type)
506 XmString label_string;
507 Widget sep, button, frame, form;
511 if (X->rframe) return ;
513 X->rframe = XmCreateFormDialog(owner, "rframe", NULL, 0) ;
515 /* Adjust the decorations for the dialog shell of the dialog */
516 XtSetArg (args[0], XmNmwmFunctions, MWM_FUNC_MOVE);
517 XtSetArg (args[1], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE);
518 XtSetValues (XtParent(X->rframe), args, 2);
520 set_title(FCP_REG, lstrs[(int) L_MEMT]) ;
522 frame = XmCreateFrame(X->rframe, "frame", NULL, 0);
523 XtManageChild(frame);
524 form = (Widget) XmCreateForm(frame, "form", NULL, 0) ;
530 XmNallowShellResize, TRUE,
531 XmNdefaultPosition, FALSE,
534 SPRINTF(str, "register%1d", 0) ;
535 X->registers[0] = XtVaCreateManagedWidget(str,
538 XmNtopAttachment, XmATTACH_FORM,
540 XmNleftAttachment, XmATTACH_FORM,
546 for (i = 1; i < MAXREGS; i++)
548 SPRINTF(str, "register%1d", i) ;
549 X->registers[i] = XtVaCreateManagedWidget(str,
552 XmNtopAttachment, XmATTACH_WIDGET,
553 XmNtopWidget, X->registers[i - 1],
555 XmNleftAttachment, XmATTACH_FORM,
562 XtSetArg (args[0], XmNtopAttachment, XmATTACH_WIDGET);
563 XtSetArg (args[1], XmNtopWidget, X->registers[i - 1]);
564 XtSetArg (args[2], XmNtopOffset, 3);
565 XtSetArg (args[3], XmNleftAttachment, XmATTACH_FORM);
566 XtSetArg (args[4], XmNrightAttachment, XmATTACH_FORM);
567 sep = XmCreateSeparator(form, "sep", args, 5);
570 label_string = XmStringCreateLocalized (GETMESSAGE(2, 32, "Close") );
571 XtSetArg (args[0], XmNmarginHeight, 0);
572 XtSetArg (args[1], XmNmarginWidth, 10);
573 XtSetArg (args[2], XmNlabelString, label_string);
574 XtSetArg (args[3], XmNtopAttachment, XmATTACH_WIDGET);
575 XtSetArg (args[4], XmNtopWidget, sep);
576 XtSetArg (args[5], XmNtopOffset, 5);
577 XtSetArg (args[6], XmNleftAttachment, XmATTACH_POSITION);
578 XtSetArg (args[7], XmNleftPosition, 25);
579 XtSetArg (args[8], XmNbottomAttachment, XmATTACH_FORM);
580 XtSetArg (args[9], XmNbottomOffset, 5);
581 XtSetArg (args[10], XmNshowAsDefault, True);
582 button = XmCreatePushButton(form, "button", args, 11);
583 XmStringFree(label_string);
585 XtAddCallback(button, XmNactivateCallback, close_reg, (XtPointer)type) ;
587 XtSetArg (args[0], XmNcancelButton, button);
588 XtSetArg (args[1], XmNdefaultButton, button);
589 XtSetValues (X->rframe, args, 2);
591 XtManageChild(button);
595 if (X->frframe) return ;
596 X->frframe = XmCreateFormDialog(owner, "frframe", NULL, 0) ;
598 /* Adjust the decorations for the dialog shell of the dialog */
599 XtSetArg (args[0], XmNmwmFunctions, MWM_FUNC_MOVE);
600 XtSetArg (args[1], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE);
601 XtSetValues (XtParent(X->frframe), args, 2);
603 set_title(FCP_FIN_REG, GETMESSAGE(2, 18, lstrs[(int) L_FINMEMT] ));
605 frame = XmCreateFrame(X->frframe, "frame", NULL, 0);
606 XtManageChild(frame);
607 form = (Widget) XmCreateForm(frame, "form", NULL, 0) ;
613 XmNallowShellResize, TRUE,
614 XmNdefaultPosition, FALSE,
617 SPRINTF(str, "fregister%1d", 0) ;
618 X->fregisters[0] = XtVaCreateManagedWidget(str,
621 XmNtopAttachment, XmATTACH_FORM,
623 XmNleftAttachment, XmATTACH_FORM,
629 for (i = 1; i < FINREGS; i++)
631 SPRINTF(str, "fregister%1d", i) ;
632 X->fregisters[i] = XtVaCreateManagedWidget(str,
635 XmNtopAttachment, XmATTACH_WIDGET,
636 XmNtopWidget, X->fregisters[i - 1],
638 XmNleftAttachment, XmATTACH_FORM,
645 SPRINTF(str, "fregistervals%1d", 0) ;
646 X->fregistersvals[0] = XtVaCreateManagedWidget(str,
649 XmNtopAttachment, XmATTACH_FORM,
651 XmNleftAttachment, XmATTACH_WIDGET,
652 XmNleftWidget, X->fregisters[0],
654 XmNrightAttachment, XmATTACH_FORM,
660 for (i = 1; i < FINREGS; i++)
662 SPRINTF(str, "fregistervals%1d", i) ;
663 X->fregistersvals[i] = XtVaCreateManagedWidget(str,
666 XmNtopAttachment, XmATTACH_WIDGET,
667 XmNtopWidget, X->fregistersvals[i - 1],
669 XmNleftAttachment, XmATTACH_WIDGET,
670 XmNleftWidget, X->fregisters[i],
672 XmNrightAttachment, XmATTACH_FORM,
679 XtSetArg (args[0], XmNtopAttachment, XmATTACH_WIDGET);
680 XtSetArg (args[1], XmNtopWidget, X->fregisters[i - 1]);
681 XtSetArg (args[2], XmNtopOffset, 3);
682 XtSetArg (args[3], XmNleftAttachment, XmATTACH_FORM);
683 XtSetArg (args[4], XmNrightAttachment, XmATTACH_FORM);
684 sep = XmCreateSeparator(form, "sep", args, 5);
687 label_string = XmStringCreateLocalized (GETMESSAGE(2, 32, "Close") );
688 XtSetArg (args[0], XmNmarginHeight, 0);
689 XtSetArg (args[1], XmNmarginWidth, 10);
690 XtSetArg (args[2], XmNlabelString, label_string);
691 XtSetArg (args[3], XmNtopAttachment, XmATTACH_WIDGET);
692 XtSetArg (args[4], XmNtopWidget, sep);
693 XtSetArg (args[5], XmNtopOffset, 5);
694 XtSetArg (args[6], XmNleftAttachment, XmATTACH_POSITION);
695 XtSetArg (args[7], XmNleftPosition, 30);
696 XtSetArg (args[8], XmNbottomAttachment, XmATTACH_FORM);
697 XtSetArg (args[9], XmNbottomOffset, 5);
698 XtSetArg (args[10], XmNshowAsDefault, True);
699 button = XmCreatePushButton(form, "button", args, 11);
700 XmStringFree(label_string);
702 XtSetArg (args[0], XmNcancelButton, button);
703 XtSetArg (args[1], XmNdefaultButton, button);
704 XtSetValues (X->frframe, args, 2);
706 XtAddCallback(button, XmNactivateCallback, close_reg, NULL) ;
708 XtManageChild(button);
714 dtcalc_kkeyboard_create(owner)
720 buttonFrame = XtVaCreateManagedWidget("buttonFrame",
723 XmNshadowThickness, 0,
726 XmNtopAttachment, XmATTACH_WIDGET,
727 XmNtopWidget, X->modeFrame,
728 XmNrightAttachment, XmATTACH_FORM,
729 XmNleftAttachment, XmATTACH_FORM,
730 XmNbottomAttachment, XmATTACH_FORM,
733 X->kkeyboard = XtVaCreateManagedWidget("kkeyboard",
736 XmNfractionBase, BROWS * BCOLS,
737 XmNnavigationType, XmSTICKY_TAB_GROUP,
740 v->curwin = FCP_KEY ;
741 for (row = 0; row < BROWS; row++)
742 for (column = 0; column < BCOLS; column++)
744 X->kbuttons[row][column] = button_create(X->kkeyboard, row, column,
746 XtManageChild(X->kbuttons[row][column]) ;
748 grey_buttons(v->base) ;
753 dtcalc_kpanel_create(owner)
756 static char *mnames[] = { "base", "ttype", "num", "hyp",
757 "inv", "op", "mode" } ;
759 Widget basePulldown, numPulldown, modePulldown, trigPulldown, dummyText;
761 XmString label_string;
762 Pixel tmp_pixelbg, tmp_pixelfg;
763 XtTranslations trans_table;
765 trans_table = XtParseTranslationTable(translations_return);
771 if(pixels[2].bg == black_pixel)
773 tmp_pixelbg = black_pixel;
774 tmp_pixelfg = white_pixel;
778 tmp_pixelbg = white_pixel;
779 tmp_pixelfg = black_pixel;
784 tmp_pixelbg = pixels[6].bg;
785 tmp_pixelfg = white_pixel;
790 tmp_pixelbg = white_pixel;
791 tmp_pixelfg = black_pixel;
794 X->mainWin = XtVaCreateManagedWidget("mainWin",
795 xmMainWindowWidgetClass,
800 XtAddEventHandler(owner, 0, True,
801 (XtEventHandler) _XEditResCheckMessages,
805 if(application_args.menuBar)
806 create_menu_bar(X->mainWin);
808 X->kFrame = XtVaCreateManagedWidget("kFrame", xmFrameWidgetClass,
810 XmNshadowThickness, 1,
811 XmNshadowType, XmSHADOW_OUT,
816 X->kpanel = XtVaCreateManagedWidget("kpanel",
819 XmNshadowThickness, 0,
820 XmNbackground, tmp_pixelbg,
821 XmNforeground, tmp_pixelfg,
824 create_popup(X->kpanel);
826 X->textFrame = XtVaCreateManagedWidget("textFrame",
829 XmNshadowThickness, 2,
830 XmNshadowType, XmSHADOW_IN,
833 XmNtopAttachment, XmATTACH_FORM,
834 XmNrightAttachment, XmATTACH_FORM,
835 XmNleftAttachment, XmATTACH_FORM,
836 XmNnavigationType, XmTAB_GROUP,
838 XtAddCallback(X->textFrame, XmNhelpCallback, HelpRequestCB,
839 (XtPointer)HELP_DISPLAY) ;
841 X->textForm = XtVaCreateManagedWidget("textForm",
844 XmNshadowThickness, 0,
845 XmNbackground, tmp_pixelbg,
846 XmNforeground, tmp_pixelfg,
848 XtAddCallback(X->textForm, XmNhelpCallback, HelpRequestCB,
849 (XtPointer)HELP_DISPLAY) ;
851 X->modevals[(int) DISPLAYITEM] = XtVaCreateManagedWidget("display",
854 XmNtopAttachment, XmATTACH_FORM,
855 XmNrightAttachment, XmATTACH_FORM,
856 XmNbottomAttachment, XmATTACH_FORM,
857 XmNresizeWidth, TRUE,
858 XmNshadowThickness, 0,
859 XmNhighlightThickness, 0,
861 XmNverifyBell, FALSE,
862 XmNbackground, tmp_pixelbg,
863 XmNforeground, tmp_pixelfg,
865 XtAddCallback(X->modevals[(int) DISPLAYITEM], XmNhelpCallback, HelpRequestCB,
866 (XtPointer) HELP_DISPLAY) ;
867 XtAddEventHandler(X->modevals[(int) DISPLAYITEM],
868 KeyPressMask | KeyReleaseMask, FALSE, event_proc, NULL) ;
871 X->modeFrame = XtVaCreateManagedWidget("modeFrame",
874 XmNshadowThickness, 0,
877 XmNtopAttachment, XmATTACH_WIDGET,
878 XmNtopWidget, X->textFrame,
879 XmNrightAttachment, XmATTACH_FORM,
880 XmNleftAttachment, XmATTACH_FORM,
881 XmNnavigationType, XmTAB_GROUP,
883 XtAddCallback(X->modeFrame, XmNhelpCallback, HelpRequestCB,
884 (XtPointer) HELP_MODELINE) ;
886 X->modeline = XtVaCreateManagedWidget("modeline",
889 XmNshadowThickness, 0,
891 XtAddCallback(X->modeline, XmNhelpCallback, HelpRequestCB,
892 (XtPointer) HELP_MODELINE) ;
894 label_string = XmStringCreateLocalized (" ");
896 X->modevals[i] = XtVaCreateManagedWidget(mnames[i],
899 XmNtopAttachment, XmATTACH_FORM,
900 XmNrightAttachment, XmATTACH_FORM,
901 XmNrecomputeSize, False,
902 XmNalignment, XmALIGNMENT_CENTER,
903 XmNlabelString, label_string,
905 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
906 (XtPointer) HELP_MODELINE) ;
909 X->modevals[i] = XtVaCreateManagedWidget(mnames[i],
912 XmNrightAttachment, XmATTACH_WIDGET,
913 XmNrightWidget, X->modevals[(int) OPITEM],
914 XmNtopAttachment, XmATTACH_FORM,
915 XmNrecomputeSize, False,
916 XmNalignment, XmALIGNMENT_CENTER,
917 XmNlabelString, label_string,
919 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
920 (XtPointer) HELP_MODELINE) ;
923 X->modevals[i] = XtVaCreateManagedWidget(mnames[i],
926 XmNrightAttachment, XmATTACH_WIDGET,
927 XmNrightWidget, X->modevals[(int) HYPITEM],
928 XmNtopAttachment, XmATTACH_FORM,
929 XmNrecomputeSize, False,
930 XmNalignment, XmALIGNMENT_CENTER,
931 XmNlabelString, label_string,
933 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
934 (XtPointer) HELP_MODELINE) ;
935 XmStringFree(label_string);
939 modePulldown = XmCreatePulldownMenu(X->modeline, "modePD", args, 0);
941 XtSetArg(args[0], XmNmarginHeight, 0);
942 XtSetArg(args[1], XmNmarginWidth, 0);
943 val = (v->curwin << 16) +
944 menu_entries[cmenus[(int) M_MODE].mindex + 1].val ;
945 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 9, "Financial") );
946 XtSetArg(args[2], XmNlabelString, label_string);
947 XtSetArg(args[3], XmNuserData, val);
948 modeArry[0] = XmCreatePushButtonGadget(modePulldown, "fin", args, 4);
949 XmStringFree(label_string);
950 XtAddCallback(modeArry[0], XmNactivateCallback, modelineValueChanged,
953 val = (v->curwin << 16) +
954 menu_entries[cmenus[(int) M_MODE].mindex + 2].val ;
955 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 10, "Logical") );
956 XtSetArg(args[2], XmNlabelString, label_string);
957 XtSetArg(args[3], XmNuserData, val);
958 modeArry[1] = XmCreatePushButtonGadget(modePulldown, "logic", args, 4);
959 XmStringFree(label_string);
960 XtAddCallback(modeArry[1], XmNactivateCallback, modelineValueChanged,
963 val = (v->curwin << 16) +
964 menu_entries[cmenus[(int) M_MODE].mindex + 3].val ;
965 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 11, "Scientific") );
966 XtSetArg(args[2], XmNlabelString, label_string);
967 XtSetArg(args[3], XmNuserData, val);
968 modeArry[2] = XmCreatePushButtonGadget(modePulldown, "Sci", args, 4);
969 XmStringFree(label_string);
970 XtAddCallback(modeArry[2], XmNactivateCallback, modelineValueChanged,
973 XtManageChildren(modeArry, 3);
975 /* create the Option Menu and attach it to the Pulldown MenuPane */
977 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
978 XtSetArg (args[n], XmNtopWidget, X->modevals[(int)HYPITEM]); n++;
979 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
980 XtSetArg(args[n], XmNsubMenuId, modePulldown); n++;
981 XtSetArg(args[n], XmNmenuHistory, modeArry[(int)v->modetype]); n++;
982 X->modevals[i] = XmCreateOptionMenu(X->modeline, "mode", args, n);
983 XtManageChild (X->modevals[i]);
984 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
985 (XtPointer) HELP_MODE) ;
987 XtOverrideTranslations(X->modevals[i], trans_table);
989 XtAddEventHandler(X->modevals[i], KeyPressMask | KeyReleaseMask,
990 FALSE, event_proc, NULL) ;
993 basePulldown = XmCreatePulldownMenu(X->modeline, "basePD", args, 0);
995 val = (v->curwin << 16) +
996 menu_entries[cmenus[(int) M_BASE].mindex].val ;
997 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 1, "Bin") );
998 XtSetArg(args[0], XmNmarginHeight, 0);
999 XtSetArg(args[1], XmNmarginWidth, 0);
1000 XtSetArg(args[2], XmNlabelString, label_string);
1001 XtSetArg(args[3], XmNuserData, val);
1002 X->baseWidgArry[0] = XmCreatePushButtonGadget(basePulldown, "bin", args, 4);
1003 XmStringFree(label_string);
1004 XtAddCallback(X->baseWidgArry[0], XmNactivateCallback,
1005 modelineValueChanged, (XtPointer) M_BASE);
1007 val = (v->curwin << 16) +
1008 menu_entries[cmenus[(int) M_BASE].mindex + 1].val ;
1009 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 2, "Oct") );
1010 XtSetArg(args[2], XmNlabelString, label_string);
1011 XtSetArg(args[3], XmNuserData, val);
1012 X->baseWidgArry[1] = XmCreatePushButtonGadget(basePulldown, "oct", args, 4);
1013 XmStringFree(label_string);
1014 XtAddCallback(X->baseWidgArry[1], XmNactivateCallback,
1015 modelineValueChanged, (XtPointer) M_BASE);
1017 val = (v->curwin << 16) +
1018 menu_entries[cmenus[(int) M_BASE].mindex + 2].val ;
1019 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 3, "Dec") );
1020 XtSetArg(args[2], XmNlabelString, label_string);
1021 XtSetArg(args[3], XmNuserData, val);
1022 X->baseWidgArry[2] = XmCreatePushButtonGadget(basePulldown, "dec", args, 4);
1023 XmStringFree(label_string);
1024 XtAddCallback(X->baseWidgArry[2], XmNactivateCallback,
1025 modelineValueChanged, (XtPointer) M_BASE);
1027 val = (v->curwin << 16) +
1028 menu_entries[cmenus[(int) M_BASE].mindex + 3].val ;
1029 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 4, "Hex") );
1030 XtSetArg(args[2], XmNlabelString, label_string);
1031 XtSetArg(args[3], XmNuserData, val);
1032 X->baseWidgArry[3] = XmCreatePushButtonGadget(basePulldown, "hex", args, 4);
1033 XmStringFree(label_string);
1034 XtAddCallback(X->baseWidgArry[3], XmNactivateCallback,
1035 modelineValueChanged, (XtPointer) M_BASE);
1037 XtManageChildren(X->baseWidgArry, 4);
1039 /* create the Option Menu and attach it to the Pulldown MenuPane */
1041 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1042 XtSetArg (args[n], XmNtopWidget, X->modevals[(int)HYPITEM]); n++;
1043 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1044 XtSetArg(args[n], XmNsubMenuId, basePulldown); n++;
1045 XtSetArg(args[n], XmNmenuHistory, X->baseWidgArry[(int)v->base]); n++;
1046 X->modevals[i] = XmCreateOptionMenu(X->modeline, "base", args, n);
1047 XtManageChild (X->modevals[i]);
1048 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
1049 (XtPointer) HELP_BASE) ;
1051 XtOverrideTranslations(X->modevals[i], trans_table);
1052 XtAddEventHandler(X->modevals[i], KeyPressMask | KeyReleaseMask,
1053 FALSE, event_proc, NULL) ;
1057 numPulldown = XmCreatePulldownMenu(X->modeline, "numPD", args, 0);
1059 val = (v->curwin << 16) +
1060 menu_entries[cmenus[(int) M_NUM].mindex].val ;
1061 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 5, "Eng") );
1062 XtSetArg(args[0], XmNmarginHeight, 0);
1063 XtSetArg(args[1], XmNmarginWidth, 0);
1064 XtSetArg(args[2], XmNlabelString, label_string);
1065 XtSetArg(args[3], XmNuserData, val);
1066 X->numWidgArry[0] = XmCreatePushButtonGadget(numPulldown, "eng", args, 4);
1067 XmStringFree(label_string);
1068 XtAddCallback(X->numWidgArry[0], XmNactivateCallback, modelineValueChanged,
1071 val = (v->curwin << 16) +
1072 menu_entries[cmenus[(int) M_NUM].mindex + 1].val ;
1073 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 6, "Fix") );
1074 XtSetArg(args[2], XmNlabelString, label_string);
1075 XtSetArg(args[3], XmNuserData, val);
1076 X->numWidgArry[1] = XmCreatePushButtonGadget(numPulldown, "fix", args, 4);
1077 XmStringFree(label_string);
1078 XtAddCallback(X->numWidgArry[1], XmNactivateCallback, modelineValueChanged,
1081 val = (v->curwin << 16) +
1082 menu_entries[cmenus[(int) M_NUM].mindex + 2].val ;
1083 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 7, "Sci") );
1084 XtSetArg(args[2], XmNlabelString, label_string);
1085 XtSetArg(args[3], XmNuserData, val);
1086 X->numWidgArry[2] = XmCreatePushButtonGadget(numPulldown, "sci", args, 4);
1087 XmStringFree(label_string);
1088 XtAddCallback(X->numWidgArry[2], XmNactivateCallback, modelineValueChanged,
1091 XtManageChildren(X->numWidgArry, 3);
1093 /* create the Option Menu and attach it to the Pulldown MenuPane */
1095 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1096 XtSetArg (args[n], XmNtopWidget, X->modevals[(int)HYPITEM]); n++;
1097 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1098 XtSetArg(args[n], XmNsubMenuId, numPulldown); n++;
1099 XtSetArg(args[n], XmNmenuHistory, X->numWidgArry[(int)v->dtype]); n++;
1100 X->modevals[i] = XmCreateOptionMenu(X->modeline, "num", args, n);
1101 XtManageChild (X->modevals[i]);
1102 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
1103 (XtPointer) HELP_NOTATION) ;
1105 XtOverrideTranslations(X->modevals[i], trans_table);
1106 XtAddEventHandler(X->modevals[i], KeyPressMask | KeyReleaseMask,
1107 FALSE, event_proc, NULL) ;
1110 i = (int) TTYPEITEM;
1111 trigPulldown = XmCreatePulldownMenu(X->modeline, "trigPD", args, 0);
1113 XtSetArg(args[0], XmNmarginHeight, 0);
1114 XtSetArg(args[1], XmNmarginWidth, 0);
1115 val = (v->curwin << 16) +
1116 menu_entries[cmenus[(int) M_TRIG].mindex].val ;
1117 label_string = XmStringCreateLocalized ( ttype_str[(int) DEG] );
1118 XtSetArg(args[2], XmNlabelString, label_string);
1119 XtSetArg(args[3], XmNuserData, val);
1120 X->ttypeWidgArry[0] =
1121 XmCreatePushButtonGadget(trigPulldown, "deg", args, 4);
1122 XmStringFree(label_string);
1123 XtAddCallback(X->ttypeWidgArry[0], XmNactivateCallback,
1124 modelineValueChanged, (XtPointer) M_TRIG);
1126 val = (v->curwin << 16) +
1127 menu_entries[cmenus[(int) M_TRIG].mindex + 1].val ;
1128 label_string = XmStringCreateLocalized ( ttype_str[(int) GRAD] );
1129 XtSetArg(args[2], XmNlabelString, label_string);
1130 XtSetArg(args[3], XmNuserData, val);
1131 X->ttypeWidgArry[1] =
1132 XmCreatePushButtonGadget(trigPulldown, "grd", args, 4);
1133 XmStringFree(label_string);
1134 XtAddCallback(X->ttypeWidgArry[1], XmNactivateCallback,
1135 modelineValueChanged, (XtPointer) M_TRIG);
1137 val = (v->curwin << 16) +
1138 menu_entries[cmenus[(int) M_TRIG].mindex + 2].val ;
1139 label_string = XmStringCreateLocalized ( ttype_str[(int) RAD] );
1140 XtSetArg(args[2], XmNlabelString, label_string);
1141 XtSetArg(args[3], XmNuserData, val);
1142 X->ttypeWidgArry[2] =
1143 XmCreatePushButtonGadget(trigPulldown, "rad", args, 4);
1144 XmStringFree(label_string);
1145 XtAddCallback(X->ttypeWidgArry[2], XmNactivateCallback,
1146 modelineValueChanged, (XtPointer) M_TRIG);
1148 XtManageChildren(X->ttypeWidgArry, 3);
1150 /* create the Option Menu and attach it to the Pulldown MenuPane */
1152 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1153 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1154 XtSetArg (args[n], XmNtopWidget, X->modevals[(int) HYPITEM]); n++;
1155 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1156 XtSetArg(args[n], XmNsubMenuId, trigPulldown); n++;
1157 XtSetArg(args[n], XmNmenuHistory, X->ttypeWidgArry[(int)v->ttype]); n++;
1158 X->modevals[i] = XmCreateOptionMenu(X->modeline, "trig", args, n);
1159 XtManageChild (X->modevals[i]);
1160 XtAddCallback(X->modevals[i], XmNhelpCallback, HelpRequestCB,
1161 (XtPointer) HELP_TRIG) ;
1163 XtOverrideTranslations(X->modevals[i], trans_table);
1164 XtSetSensitive(X->modevals[i], True);
1166 XtSetArg (args[0], XmNrightAttachment, XmATTACH_WIDGET);
1167 XtSetArg (args[1], XmNrightWidget, X->modevals[(int)BASEITEM]);
1168 XtSetValues (X->modevals[(int)MODEITEM], args, 2);
1170 XtSetArg (args[0], XmNrightAttachment, XmATTACH_WIDGET);
1171 XtSetArg (args[1], XmNrightWidget, X->modevals[(int)NUMITEM]);
1172 XtSetValues (X->modevals[(int)BASEITEM], args, 2);
1174 XtSetArg (args[0], XmNrightAttachment, XmATTACH_WIDGET);
1175 XtSetArg (args[1], XmNrightWidget, X->modevals[(int)TTYPEITEM]);
1176 XtSetValues (X->modevals[(int)NUMITEM], args, 2);
1179 XtAddEventHandler(X->modevals[i], KeyPressMask | KeyReleaseMask,
1180 FALSE, event_proc, NULL) ;
1187 confirm_callback(widget, client_data, call_data)
1189 XtPointer client_data, call_data ;
1196 create_cfframe() /* Create auxiliary frame for CON/FUN key. */
1201 Widget sep, frame, form;
1202 XmString label_string;
1204 X->CFframe = (Widget) XmCreateFormDialog(X->kframe, "cfframe", NULL, 0) ;
1205 tstr = XmStringCreateLocalized(lstrs[(int) L_NEWCON]) ;
1206 XtVaSetValues(X->CFframe,
1207 XmNdialogTitle, tstr,
1208 XmNautoUnmanage, FALSE,
1209 XmNallowShellResize, FALSE,
1210 XmNdefaultPosition, FALSE,
1212 XmStringFree(tstr) ;
1214 /* Adjust the decorations for the dialog shell of the dialog */
1216 XtSetArg (args[j], XmNmwmFunctions, MWM_FUNC_MOVE); j++;
1217 XtSetArg (args[j], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE); j++;
1218 XtSetValues (XtParent(X->CFframe), args, j);
1220 frame = (Widget) XmCreateFrame(X->CFframe, "frame", NULL, 0) ;
1221 XtManageChild(frame);
1222 form = (Widget) XmCreateForm(frame, "form", NULL, 0) ;
1223 XtManageChild(form);
1226 X->CFpi_cftext = make_textW(form, lstrs[(int) L_CONNO]) ;
1227 X->CFpi_dtext = make_textW(form, lstrs[(int) L_DESC]) ;
1228 X->CFpi_vtext = make_textW(form, lstrs[(int) L_VALUE]) ;
1231 XtSetArg (args[j], XmNtopAttachment, XmATTACH_FORM); j++;
1232 XtSetArg (args[j], XmNtopOffset, 5); j++;
1233 XtSetArg (args[j], XmNrightAttachment, XmATTACH_FORM); j++;
1234 XtSetArg (args[j], XmNrightOffset, 5); j++;
1235 XtSetValues(X->CFpi_cftext->manager, args, j);
1238 XtSetArg (args[j], XmNtopAttachment, XmATTACH_WIDGET); j++;
1239 XtSetArg (args[j], XmNtopWidget, X->CFpi_cftext->manager); j++;
1240 XtSetArg (args[j], XmNtopOffset, 5); j++;
1241 XtSetArg (args[j], XmNrightAttachment, XmATTACH_FORM); j++;
1242 XtSetArg (args[j], XmNrightOffset, 5); j++;
1243 XtSetValues(X->CFpi_dtext->manager, args, j);
1246 XtSetArg (args[j], XmNtopAttachment, XmATTACH_WIDGET); j++;
1247 XtSetArg (args[j], XmNtopWidget, X->CFpi_dtext->manager); j++;
1248 XtSetArg (args[j], XmNtopOffset, 5); j++;
1249 XtSetArg (args[j], XmNrightAttachment, XmATTACH_FORM); j++;
1250 XtSetArg (args[j], XmNrightOffset, 5); j++;
1251 XtSetValues(X->CFpi_vtext->manager, args, j);
1254 XtSetArg (args[j], XmNtopAttachment, XmATTACH_WIDGET); j++;
1255 XtSetArg (args[j], XmNtopWidget, X->CFpi_vtext->manager); j++;
1256 XtSetArg (args[j], XmNtopOffset, 3); j++;
1257 XtSetArg (args[j], XmNleftAttachment, XmATTACH_FORM); j++;
1258 XtSetArg (args[j], XmNrightAttachment, XmATTACH_FORM); j++;
1259 sep = XmCreateSeparator(form, "sep", args, j);
1263 label_string = XmStringCreateLocalized ( GETMESSAGE(4, 4, "OK") );
1264 XtSetArg (args[j], XmNmarginHeight, 2); j++;
1265 XtSetArg (args[j], XmNmarginWidth, 15); j++;
1266 XtSetArg (args[j], XmNlabelString, label_string); j++;
1267 XtSetArg (args[j], XmNtopAttachment, XmATTACH_WIDGET); j++;
1268 XtSetArg (args[j], XmNtopWidget, sep); j++;
1269 XtSetArg (args[j], XmNtopOffset, 5); j++;
1270 XtSetArg (args[j], XmNleftAttachment, XmATTACH_FORM); j++;
1271 XtSetArg (args[j], XmNleftOffset, 15); j++;
1272 XtSetArg (args[j], XmNbottomAttachment, XmATTACH_FORM); j++;
1273 XtSetArg (args[j], XmNbottomOffset, 5); j++;
1274 XtSetArg (args[j], XmNshowAsDefault, True); j++;
1275 XtSetArg (args[j], XmNtraversalOn, True); j++;
1276 X->CFpi_butOK = XmCreatePushButton(form, "button", args, j);
1277 XmStringFree(label_string);
1278 XtManageChild(X->CFpi_butOK);
1281 label_string = XmStringCreateLocalized ( GETMESSAGE(3, 361, "Cancel") );
1282 XtSetArg (args[j], XmNmarginHeight, 2); j++;
1283 XtSetArg (args[j], XmNmarginWidth, 10); j++;
1284 XtSetArg (args[j], XmNlabelString, label_string); j++;
1285 XtSetArg (args[j], XmNtopAttachment, XmATTACH_WIDGET); j++;
1286 XtSetArg (args[j], XmNtopWidget, sep); j++;
1287 XtSetArg (args[j], XmNtopOffset, 10); j++;
1288 XtSetArg (args[j], XmNleftAttachment, XmATTACH_WIDGET); j++;
1289 XtSetArg (args[j], XmNleftWidget, X->CFpi_butOK); j++;
1290 XtSetArg (args[j], XmNleftOffset, 33); j++;
1291 XtSetArg (args[j], XmNbottomAttachment, XmATTACH_FORM); j++;
1292 XtSetArg (args[j], XmNbottomOffset, 10); j++;
1293 XtSetArg (args[j], XmNtraversalOn, True); j++;
1294 X->CFpi_butClose = XmCreatePushButton(form, "button", args, j);
1295 XmStringFree(label_string);
1296 XtManageChild(X->CFpi_butClose);
1299 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 18, "Help") );
1300 XtSetArg (args[j], XmNmarginHeight, 2); j++;
1301 XtSetArg (args[j], XmNmarginWidth, 10); j++;
1302 XtSetArg (args[j], XmNlabelString, label_string); j++;
1303 XtSetArg (args[j], XmNtopAttachment, XmATTACH_WIDGET); j++;
1304 XtSetArg (args[j], XmNtopWidget, sep); j++;
1305 XtSetArg (args[j], XmNtopOffset, 10); j++;
1306 XtSetArg (args[j], XmNrightAttachment, XmATTACH_FORM); j++;
1307 XtSetArg (args[j], XmNrightOffset, 15); j++;
1308 XtSetArg (args[j], XmNleftAttachment, XmATTACH_WIDGET); j++;
1309 XtSetArg (args[j], XmNleftWidget, X->CFpi_butClose); j++;
1310 XtSetArg (args[j], XmNleftOffset, 33); j++;
1311 XtSetArg (args[j], XmNbottomAttachment, XmATTACH_FORM); j++;
1312 XtSetArg (args[j], XmNbottomOffset, 10); j++;
1313 XtSetArg (args[j], XmNtraversalOn, True); j++;
1314 X->CFpi_butHelp = XmCreatePushButton(form, "button", args, j);
1315 XmStringFree(label_string);
1316 XtManageChild(X->CFpi_butHelp);
1318 XtAddCallback(X->CFpi_butOK, XmNactivateCallback, write_cf_value,
1319 (XtPointer) X->CFpi_butOK) ;
1320 XtAddCallback(X->CFpi_butClose, XmNactivateCallback, close_cf,
1323 XtAddCallback(X->CFpi_cftext->textfield, XmNactivateCallback, move_cf,
1324 (XtPointer) X->CFpi_butOK) ;
1325 XtAddCallback(X->CFpi_dtext->textfield, XmNactivateCallback, move_cf,
1326 (XtPointer) X->CFpi_butOK) ;
1327 XtAddCallback(X->CFpi_vtext->textfield, XmNactivateCallback, move_cf,
1328 (XtPointer) X->CFpi_butOK) ;
1330 XtAddCallback(X->CFpi_cftext->textfield, XmNfocusCallback, FocusInCB,
1332 XtAddCallback(X->CFpi_dtext->textfield, XmNactivateCallback, FocusInCB,
1335 XtSetArg (args[j], XmNcancelButton, X->CFpi_butClose); j++;
1336 XtSetValues (X->CFframe, args, j);
1339 XtSetArg (args[j], XmNdefaultButton, X->CFpi_butOK); j++;
1340 XtSetValues (form, args, j);
1342 /* Make the first prompt automatically get the focus. */
1343 XmProcessTraversal(X->CFpi_cftext->textfield, XmTRAVERSE_CURRENT);
1348 create_menu(mtype, button, n) /* Create popup menu for dtcalc button. */
1349 enum menu_type mtype ;
1353 char *mstr, *tmpStr, *ptr ;
1354 int i, invalid, val ;
1356 Boolean isAFunction = False;
1358 if ((mtype != M_CON && mtype != M_FUN) &&
1359 X->menus[(int) mtype] != NULL) return ; /* Already created? */
1361 X->menus[(int) mtype] = menu = XmCreatePopupMenu(button,
1364 X->mrec[(int) mtype] = n ;
1366 XtCreateManagedWidget(cmenus[(int) mtype].title, xmLabelWidgetClass,
1368 XtCreateManagedWidget("separator", xmSeparatorWidgetClass, menu, NULL, 0) ;
1369 XtCreateManagedWidget("separator", xmSeparatorWidgetClass, menu, NULL, 0) ;
1372 for (i = 0; i < cmenus[(int) mtype].total; i++)
1377 case M_CON : if (strlen(v->con_names[i])) /* Constants. */
1378 mstr = v->con_names[i] ;
1381 case M_FUN : if (strlen(v->fun_names[i])) /* Functions. */
1384 mstr = v->fun_names[i] ;
1388 default : mstr = menu_entries[cmenus[(int) mtype].mindex + i].str ;
1393 tmpStr = GETMESSAGE(3, 45, ".");
1394 if(strcmp(tmpStr, ".") != 0)
1396 /* if it's not a "." let's go change it to what it should be */
1397 ptr = DtStrchr(mstr, '.');
1401 mi = XtCreateManagedWidget(mstr, xmPushButtonWidgetClass,
1403 val = (v->curwin << 16) +
1404 menu_entries[cmenus[(int) mtype].mindex + i].val ;
1405 XtAddCallback(mi, XmNactivateCallback, menu_proc, (XtPointer) val) ;
1408 if( !isAFunction && mtype == M_FUN)
1410 mi = XtCreateManagedWidget(GETMESSAGE(2, 35, "No Functions Defined"),
1411 xmPushButtonWidgetClass, menu, NULL, 0) ;
1418 do_button(widget, client_data, call_data)
1420 XtPointer client_data, call_data ;
1425 int n = ((int) client_data) & 0xFFFF ;
1427 XtSetArg(args[0], XmNlabelString, &cstr);
1428 XtGetValues(X->modevals[OPITEM], args, 1);
1430 str = (char *) _XmStringUngenerate(cstr,
1431 XmFONTLIST_DEFAULT_TAG,
1432 XmCHARSET_TEXT, XmCHARSET_TEXT);
1434 if(strcmp(vstrs[(int) V_CLR], str) == 0 &&
1435 (buttons[n].value != KEY_CLR && buttons[n].value != KEY_QUIT))
1441 ProcessMotifSelection(X->modevals[(int) DISPLAYITEM]);
1442 v->curwin = ((int) client_data) >> 16 ;
1445 v->current = buttons[n].value ;
1448 else if (n >= 0 && n <= NOBUTTONS) process_item(n) ;
1455 do_continue_notice(parent, str)
1459 XmString contstr, message, cstr ;
1462 X->notice = (Widget) XmCreateInformationDialog(X->kframe, "continue",
1464 contstr = XmStringCreateLocalized(vstrs[(int) V_CONTINUE]) ;
1465 message = XmStringCreateLocalized( str );
1466 XtVaSetValues(X->notice,
1467 XmNautoUnmanage, FALSE,
1468 XmNcancelLabelString, contstr,
1469 XmNmessageString, message,
1470 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1472 XmStringFree(contstr) ;
1473 XmStringFree(message) ;
1474 XtUnmanageChild((Widget) XmMessageBoxGetChild(X->notice,
1475 XmDIALOG_OK_BUTTON)) ;
1476 XtUnmanageChild((Widget) XmMessageBoxGetChild(X->notice,
1477 XmDIALOG_HELP_BUTTON)) ;
1479 tmpStr = GETMESSAGE(2, 36, "Continue Notice");
1480 cstr = XmStringCreateLocalized(tmpStr) ;
1481 XtVaSetValues(X->notice, XmNdialogTitle, cstr, NULL) ;
1482 XmStringFree(cstr) ;
1484 XtManageChild(X->notice) ;
1490 do_confirm_notice(parent, str)
1494 XmString confirm, cancel, message, cstr ;
1498 X->notice = (Widget) XmCreateInformationDialog(X->kframe, "continue",
1500 confirm = XmStringCreateLocalized(vstrs[(int) V_CONFIRM]) ;
1501 cancel = XmStringCreateLocalized(vstrs[(int) V_CANCEL]) ;
1502 message = XmStringCreateLocalized( str );
1503 XtVaSetValues(X->notice,
1504 XmNautoUnmanage, FALSE,
1505 XmNcancelLabelString, cancel,
1506 XmNokLabelString, confirm,
1507 XmNmessageString, message,
1508 XmNdialogStyle, XmDIALOG_APPLICATION_MODAL,
1510 XmStringFree(confirm) ;
1511 XmStringFree(cancel) ;
1512 XmStringFree(message) ;
1513 XtUnmanageChild((Widget) XmMessageBoxGetChild(X->notice,
1514 XmDIALOG_HELP_BUTTON)) ;
1515 XtAddCallback(X->notice, XmNokCallback, confirm_callback, NULL) ;
1517 tmpStr = GETMESSAGE(2, 37, "Confirmation Notice");
1518 cstr = XmStringCreateLocalized(tmpStr) ;
1519 XtVaSetValues(X->notice, XmNdialogTitle, cstr, NULL) ;
1520 XmStringFree(cstr) ;
1522 XtManageChild(X->notice) ;
1529 close_reg(widget, client_data, call_data)
1531 XtPointer client_data, call_data ;
1533 int type = (int)client_data;
1537 XtUnmanageChild(X->rframe);
1538 XtUnmapWidget(XtParent(X->rframe));
1543 XtUnmanageChild(X->frframe);
1544 XtUnmapWidget(XtParent(X->frframe));
1552 * This routine causes the calculator buttons to looked depressed (armed)
1553 * and undepressed (disarmed) when the user uses the keyboard to select a
1554 * button on the keyboard. It's pretty straight forward:
1555 * The user pressess a key from the keyboard
1556 * The routine event_proc() gets called.
1557 * It determines whether the key from the keyboard is a valid key.
1558 * If it is, it sends that key to process_event()
1559 * This routines then determines whether the key is an active key.
1560 * If it is then it calls this routine to set the key to either armed
1561 * or disarmed. This state is determined by whether it is a keyboard
1562 * up event or a keyboard down event.
1563 * There is some special case code in here also. There was a bug where
1564 * if a user pressed a CNTL character key, the event order could cause
1565 * the key to stay depressed. The typical order is:
1570 * When this typical order was pressed things worked fine. But the problem
1571 * arose when the order was:
1576 * The problem was that when the last "KEY key up" was processed it is not
1577 * recognized as a control key, so the calculator thought is was a "normal"
1578 * key and disarmed that "normal" key button rather then the Control
1579 * key button. This is what the lastArmed and count static variables are
1580 * used for. They check to see if the last "KEY key up" corresponds to
1581 * the last "Control key down" button that was armed. If it doesn't then
1582 * we know we need to disarm the "Control key" button rather then the
1583 * "normal" button that was passed in.
1587 draw_button(n, fcptype, row, column, inverted)
1589 enum fcp_type fcptype ;
1590 int row, column, inverted ;
1594 XmPushButtonWidget pb;
1595 int i, j, row2, column2;
1596 static XtIntervalId timerId = 0;
1600 widget = X->kbuttons[row][column] ;
1601 lastArmed[countArmed] = n;
1608 for(i = 0; i < countArmed; i++)
1610 if(lastArmed[i] == n)
1613 if(countArmed == i && countArmed != 0)
1616 row2 = lastArmed[i] / MAXCOLS ;
1617 column2 = lastArmed[i] - (row2 * MAXCOLS) ;
1618 widget = X->kbuttons[row2][column2] ;
1619 for(j = i; j < countArmed; j++)
1620 lastArmed[j] = lastArmed[j + 1];
1627 strcpy(str, "Disarm");
1629 /* go call the correct arm/disarm function from Motif */
1630 XtCallActionProc(widget, str, X->event, NULL, 0) ;
1636 event_is_keypad(xevent)
1639 if (xevent->type != KeyPress && xevent->type != KeyRelease) return(0) ;
1640 return(X->kparray[xevent->xkey.keycode - X->kcmin] > 0) ;
1646 * This routine is called any time a key on the keyboard is pressed. It
1647 * then determines whether the key is a valid key or whether it is to
1648 * be ignore. If it is a valid key it passes it on to be processed.
1653 event_proc(widget, client_data, event, continue_to_dispatch)
1655 XtPointer client_data ;
1657 Boolean *continue_to_dispatch ;
1664 static char count = 0;
1666 /* If the ASCII convert dialog, or the Help dialog
1667 is up and managed, we don't want the keystrokes to go to the calculator
1668 main, just those dialogs
1669 if ((X->Aframe != NULL && XtIsManaged(X->Aframe)) ||
1670 (X->helpDialog != NULL && X->helpMapped))
1682 ignore_event = False;
1683 XtRemoveTimeOut(timerId);
1689 v->event_type = get_next_event(widget, 0, event) ;
1691 /* first check to see if there is an error condition, if there is we
1692 want to beep and return.
1695 XtSetArg(args[0], XmNlabelString, &label);
1696 XtGetValues(X->modevals[OPITEM], args, 1);
1698 str = (char *) _XmStringUngenerate(label,
1699 XmFONTLIST_DEFAULT_TAG,
1700 XmCHARSET_TEXT, XmCHARSET_TEXT);
1702 if(strcmp(vstrs[(int) V_CLR], str) == 0 &&
1703 (v->cur_ch != KEY_CLR && v->cur_ch != KEY_QUIT))
1705 if(v->event_type == KEYBOARD_DOWN)
1709 index = get_index(v->cur_ch);
1711 draw_button(index, v->curwin, v->row, v->column, FALSE);
1716 /* Now lets check to see if the input was for the Constants/Functions
1717 dialog. If it was process it.
1719 if(X->CFframe != NULL && XtIsManaged(X->CFframe))
1721 w = XmGetFocusWidget(X->CFframe);
1722 if(w == X->CFpi_butOK)
1724 if(v->cur_ch == KEY_EQ)
1726 XtCallCallbacks(X->CFpi_butOK, XmNarmCallback, (XtPointer) NULL);
1727 XtCallCallbacks(X->CFpi_butOK, XmNactivateCallback,
1730 if(v->event_type == ARROW || v->event_type == TAB)
1732 XtSetArg(args[0], XmNdefaultButton, X->CFpi_butOK);
1733 XtSetValues(X->CFframe, args, 1);
1738 else if(w == X->CFpi_butClose)
1740 if(v->cur_ch == KEY_EQ)
1742 XtCallCallbacks(X->CFpi_butClose, XmNarmCallback, (XtPointer) NULL);
1743 XtCallCallbacks(X->CFpi_butClose, XmNactivateCallback,
1746 if(v->event_type == ARROW || v->event_type == TAB)
1748 XtSetArg(args[0], XmNdefaultButton, NULL);
1749 XtSetValues(X->CFframe, args, 1);
1754 else if(w == X->CFpi_butHelp)
1756 if(v->cur_ch == KEY_EQ)
1758 XtCallCallbacks(X->CFpi_butHelp, XmNarmCallback, (XtPointer) NULL);
1759 XtCallCallbacks(X->CFpi_butHelp, XmNactivateCallback,
1760 (XtPointer) HELP_CONSTANT);
1762 if(v->event_type == ARROW || v->event_type == TAB)
1764 XtSetArg(args[0], XmNdefaultButton, NULL);
1765 XtSetValues(X->CFframe, args, 1);
1772 index = get_index(v->cur_ch);
1773 if (index != TITEMS)
1774 draw_button(index, v->curwin, v->row, v->column, FALSE);
1776 /* don't worry about this if there is something pending */
1777 if (v->pending == 0) {
1778 /* if the key is an "inactive" key (i.e. desensitized) then we want to
1783 if(v->cur_ch == KEY_2 ||
1784 v->cur_ch == KEY_3 ||
1785 v->cur_ch == KEY_4 ||
1786 v->cur_ch == KEY_5 ||
1787 v->cur_ch == KEY_6 ||
1791 if(v->cur_ch == KEY_8 ||
1795 if(v->cur_ch == KEY_A ||
1796 v->cur_ch == KEY_B ||
1797 v->cur_ch == KEY_C ||
1798 v->cur_ch == KEY_D ||
1799 v->cur_ch == KEY_E ||
1805 /* finally, check to see if it is a key we wish to ignore and motif
1808 if(v->event_type == F4_PRESS || v->event_type == ARROW ||
1809 v->event_type == TAB || v->event_type == CONTROL ||
1810 v->event_type == SHIFT || v->event_type == SPACE ||
1811 v->event_type == ESCAPE || v->event_type == META || v->event_type == ALT)
1813 else if(v->event_type == NUM_LOCK)
1815 v->num_lock = !v->num_lock;
1817 else if (v->cur_ch == CTL('/'))
1821 ProcessMotifSelection(X->modevals[(int) DISPLAYITEM]);
1822 process_event(v->event_type);
1826 if (v->num_lock == True)
1828 draw_button(0, v->curwin, 0, 0, TRUE);
1834 /* ------------------------------------------------------------- */
1835 /* Primarily handles the selection in the display text widget. */
1836 /* Update the display before the event is processed for dtcalc. */
1837 /* ------------------------------------------------------------- */
1840 ProcessMotifSelection(Widget W)
1845 char *display = NULL;
1846 XmTextPosition left, right;
1848 if (XmTextGetSelectionPosition (W, &left, &right) == True)
1851 display = XmTextGetString(W);
1853 bound = ( (long)strlen(display) - right + 1);
1855 for (i = 0; i < bound; i++)
1857 display[i+left] = display[i+right];
1860 index = get_index(v->cur_ch);
1861 key = buttons[index].value;
1863 /* ------------------------------------------------------------ */
1864 /* Append an extra character to be handled by do_delete func. */
1865 /* ------------------------------------------------------------ */
1870 display[i+1] = '\0';
1873 STRCPY(v->display, display);
1883 frame_interpose(widget, clientData, event, continue_to_dispatch)
1885 XtPointer clientData ;
1887 Boolean *continue_to_dispatch ;
1889 if (!v->started) return ;
1890 if (event->type == MapNotify)
1892 if (v->rstate) win_display(FCP_REG, TRUE) ;
1893 else if (v->frstate) win_display(FCP_FIN_REG, TRUE) ;
1896 else if (event->type == UnmapNotify) v->iconic = TRUE ;
1902 get_next_event(widget, ev_action, xevent)
1907 char *tmpStr, chs[2] ;
1908 int cval, down, nextc, up ;
1910 XKeyPressedEvent *key_event ;
1912 if (!v->started) return(LASTEVENTPLUSONE) ;
1913 nextc = xevent->type ;
1915 down = xevent->type == ButtonPress || xevent->type == KeyPress ;
1916 up = xevent->type == ButtonRelease || xevent->type == KeyRelease ;
1918 if (nextc == KeyPress || nextc == KeyRelease)
1920 key_event = (XKeyPressedEvent *) xevent ;
1921 chs[0] = chs[1] = (char)0;
1923 * If the user enters a multibyte character, XLookupString()
1924 * will return zero because it only handles Latin-1 characters.
1925 * We can just return then because we're only looking for
1926 * Latin-1 characters anyway (see CDExc15419).
1928 if (!XLookupString(key_event, chs, 1, &ksym,
1929 (XComposeStatus *) NULL))
1931 if (key_event->keycode == NUM_LOCK)
1934 return(LASTEVENTPLUSONE);
1938 Here's how the fix solves the problem:
1940 When you press ctrl-space, the input method converts your composed
1941 input to a Kanji character and sends a keyboard event to dtcalc with
1942 a keycode of 0. The keycode of 0 is the X convention that the
1943 application should call XmbLookupString() to get the Kanji character
1944 from the input method.
1946 dtcalc calls XLookupString() instead though, which being a much older
1947 interface, doesn't know about this convention. XLookupString() isn't
1948 able to map the keycode to anything and just returns 0.
1950 The fix catches this and returns immediately. Otherwise, the code
1951 would go on to call event_is_keypad() to see if the event was a keypad
1952 event like '+', '=', etc. That function would core dump at the
1953 following line because of the negative array index:
1955 return(X->kparray[xevent->xkey.keycode - X->kcmin] > 0) ;
1957 Returning immediately from get_next_event() avoids the core dump and
1958 doesn't hurt anything because dtcalc doesn't actually use any Kanji
1959 characters for its keypad characters, just ASCII ones.
1961 An alternative fix would be to use XmbLookupString() instead of
1962 XLookupString(). That fix would be more complex though, and as
1963 CDExc15419 points out, XLookupString() is fine here (as long as you
1964 check its return value).
1968 XLookupString(key_event, chs, 1, &ksym, (XComposeStatus *) NULL) ;
1970 if (ksym == XK_F4 && down) return(F4_PRESS) ;
1971 else if (ksym == XK_F4 && up) return(F4_PRESS) ;
1972 else if (ksym == XK_Right && down)
1974 if (!event_is_keypad(xevent))
1977 else if (ksym == XK_Left && down)
1979 if (!event_is_keypad(xevent))
1982 else if (ksym == XK_Up && down)
1984 if (!event_is_keypad(xevent))
1987 else if (ksym == XK_Down && down)
1989 if (!event_is_keypad(xevent))
1992 else if (ksym == XK_F10 && down) return(F4_PRESS);
1993 else if (ksym == XK_F10 && up) return(F4_PRESS);
1994 else if (ksym == XK_Tab && down) return(TAB);
1995 else if (ksym == XK_Tab && up) return(TAB);
1997 #ifdef HP_EXTENSIONS
1998 else if (ksym == XK_BackTab && down) return(SHIFT);
1999 else if (ksym == XK_BackTab && up) return(SHIFT);
2000 else if (ksym == hpXK_DeleteChar && down) cval = 127;
2001 else if (ksym == hpXK_DeleteChar && up) cval = 127;
2003 else if (ksym == XK_Return && down) cval = KEY_EQ;
2004 else if (ksym == XK_Return && up) cval = KEY_EQ;
2005 else if (ksym == XK_Escape && down) return(ESCAPE);
2006 else if (ksym == XK_Escape && up) return(ESCAPE);
2007 else if (ksym == XK_Control_L && down) return(CONTROL);
2008 else if (ksym == XK_Control_L && up) return(CONTROL);
2009 else if (ksym == XK_Control_R && down) return(CONTROL);
2010 else if (ksym == XK_Control_R && up) return(CONTROL);
2011 else if (ksym == XK_Meta_L && down) return(META);
2012 else if (ksym == XK_Meta_R && up) return(META);
2013 else if (ksym == XK_Meta_L && down) return(META);
2014 else if (ksym == XK_Meta_R && up) return(META);
2015 else if (ksym == XK_Alt_L && down) return(ALT);
2016 else if (ksym == XK_Alt_R && up) return(ALT);
2017 else if (ksym == XK_Alt_L && down) return(ALT);
2018 else if (ksym == XK_Alt_R && up) return(ALT);
2019 else if (ksym == XK_Select && down) return(SPACE);
2020 else if (ksym == XK_Select && up) return(SPACE);
2021 else if (ksym == XK_space && down) return(SPACE);
2022 else if (ksym == XK_space && up) return(SPACE);
2023 else if (ksym == XK_Shift_L || ksym == XK_Shift_R)
2024 return(LASTEVENTPLUSONE) ;
2025 else cval = chs[0] ;
2028 tmpStr = GETMESSAGE(3, 45, ".");
2029 if (event_is_keypad(xevent))
2033 * In keypad_keysym(), KeySym associated with xevent->xkey.keycode
2034 * is extracted by calling XKeycodeToKeysym(). But the current
2035 * implementation doesn't care of the modifires state. In this moment,
2036 * we can still use ksym which is got in the above XLookupString().
2037 * Sun's implementation seems to need an attention for this. But AIX
2039 * Still JP kbd NumLock state cannot be handled correctly.
2043 switch (keypad_keysym(xevent))
2046 case XK_KP_0 : v->cur_ch = '0' ;
2048 case XK_KP_1 : v->cur_ch = '1' ;
2050 case XK_KP_2 : v->cur_ch = '2' ;
2052 case XK_KP_3 : v->cur_ch = '3' ;
2054 case XK_KP_4 : v->cur_ch = '4' ;
2056 case XK_KP_5 : v->cur_ch = '5' ;
2058 case XK_KP_6 : v->cur_ch = '6' ;
2060 case XK_KP_7 : v->cur_ch = '7' ;
2062 case XK_KP_8 : v->cur_ch = '8' ;
2064 case XK_KP_9 : v->cur_ch = '9' ;
2066 case XK_KP_Add : v->cur_ch = '+' ;
2068 case XK_KP_Subtract : v->cur_ch = '-' ;
2070 case XK_KP_Multiply : v->cur_ch = 'x' ;
2072 case XK_KP_Divide : v->cur_ch = '/' ;
2075 case XK_KP_Enter : v->cur_ch = '=' ;
2077 case XK_KP_Decimal : v->cur_ch = tmpStr[0] ;
2079 if (down) return(KEYBOARD_DOWN) ;
2080 else if (up) return(KEYBOARD_UP) ;
2082 else if ((nextc == KeyPress || nextc == KeyRelease) &&
2083 (IS_KEY(cval, KEY_BSP) || IS_KEY(cval, KEY_CLR)))
2085 v->cur_ch = cval ; /* Delete and Back Space keys. */
2086 if (down) return(KEYBOARD_DOWN) ;
2087 else if (up) return(KEYBOARD_UP) ;
2090 if ((nextc == KeyPress || nextc == KeyRelease) && cval >= 0 && cval <= 127)
2093 /* If this is a '*' or Return key press, then map to their better known
2094 * equivalents, so that button highlighting works correctly.
2097 if (cval == '*') cval = KEY_MUL ;
2099 /* All the rest of the ASCII characters. */
2102 if (down) return(KEYBOARD_DOWN) ;
2103 else if (up) return(KEYBOARD_UP) ;
2106 return(LASTEVENTPLUSONE) ;
2111 get_resource(rtype) /* Get dtcalc resource from merged database. */
2112 enum res_type rtype ;
2116 STRCPY(str, calc_res[(int) rtype]) ;
2117 return(ds_get_resource(X->rDB, v->appname, str)) ;
2122 grey_button(row, column, state)
2123 int row, column, state ;
2125 XtSetSensitive(X->kbuttons[row][column], !state) ;
2132 char *tmpStr, *tmpStr1;
2134 tmpStr = GETMESSAGE(2, 12, "Calculator");
2135 tmpStr1 = XtNewString(tmpStr);
2136 XtVaSetValues(X->kframe,
2137 XmNiconName, tmpStr1,
2140 dtcalc_kpanel_create(X->kframe) ;
2141 dtcalc_kkeyboard_create(X->kpanel) ;
2143 XtSetMappedWhenManaged(X->kframe, False);
2144 XtRealizeWidget(X->kframe) ;
2145 XSync(X->dpy, False);
2147 XtSetMappedWhenManaged(X->kframe, True);
2148 XtMapWidget( X->kframe );
2149 XSync(X->dpy, False);
2159 is_window_showing(widget)
2162 return(XtIsManaged(widget)) ;
2173 XDisplayKeycodes(X->dpy, &X->kcmin, &X->kcmax) ;
2174 tmp = XGetKeyboardMapping(X->dpy, X->kcmin, 1, &X->keysyms_per_key) ;
2175 XFree((char *) tmp) ;
2177 X->kparray = (unsigned char *) malloc(X->kcmax - X->kcmin + 1) ;
2179 /* For each key, run through its list of keysyms. If this keysym is a
2180 * keypad keysym, we know this key is on the keypad. Mark it as such in
2184 for (i = X->kcmin; i <= X->kcmax; ++i)
2186 X->kparray[i - X->kcmin] = 0 ;
2187 for (j = 0; j < X->keysyms_per_key; ++j)
2189 ks = XKeycodeToKeysym(X->dpy, i, j) ;
2190 if (IsKeypadKey(ks))
2192 X->kparray[i - X->kcmin] = 1 ;
2201 keypad_keysym(xevent)
2205 int keycode = xevent->xkey.keycode ;
2208 for (i = 0; i < X->keysyms_per_key; ++i)
2210 ks = XKeycodeToKeysym(X->dpy, keycode, i) ;
2211 if (IsKeypadKey(ks))
2214 if(ks != XK_KP_Insert)
2225 X->rDB = ds_load_resources(X->dpy) ;
2232 char *tool_label = NULL ;
2235 if (v->titleline == NULL)
2237 tool_label = (char *) calloc(1, strlen(lstrs[(int) L_UCALC]) + 3);
2239 SPRINTF(tool_label, "%s", lstrs[(int) L_UCALC]);
2241 else read_str(&tool_label, v->titleline) ;
2243 X->clipboard = XInternAtom(X->dpy, "CLIPBOARD", FALSE) ;
2244 X->length_atom = XInternAtom(X->dpy, "LENGTH", FALSE) ;
2245 XtAddEventHandler(X->kframe, StructureNotifyMask, FALSE,
2246 frame_interpose, NULL) ;
2247 XtVaSetValues(X->kframe,
2248 XmNtitle, tool_label,
2251 XtVaGetValues(X->kframe,
2255 if(v->titleline == NULL)
2260 make_modewin() /* Draw special mode frame plus buttons. */
2262 switch_mode(v->modetype) ;
2266 make_registers(type) /* Calculate memory register frame values. */
2269 char line[MAXLINE] ; /* Current memory register line. */
2270 char *ptr, *tmp, *tmpStr;
2272 XmString str, numStr ;
2273 int MPtemp[MP_SIZE];
2277 if (!v->rstate) return ;
2279 else if(type == FIN)
2281 if (!v->frstate) return ;
2284 dtcalc_initialize_rframe(X->kframe, type) ;
2286 tmpStr = GETMESSAGE(3, 45, ".");
2289 for (i = 0; i < MAXREGS; i++)
2291 SPRINTF(line, "%s: %s", menu_entries[i + 10].str,
2292 make_number(v->MPmvals[i], FALSE)) ;
2295 /* if it's not a "." let's go change it to what it should be */
2296 ptr = DtStrrchr(line, '.');
2300 str = XmStringCreateLocalized(line) ;
2301 XtVaSetValues(X->registers[i], XmNlabelString, str, NULL) ;
2307 for (i = 0; i < FINREGS; i++)
2311 mpcdm(&(v->MPfvals[i]), MPtemp);
2312 tmp = make_number(MPtemp, FALSE);
2313 ptr = DtStrchr(tmp, 'e');
2316 ptr = DtStrchr(tmp, '.');
2319 ptr = DtStrchr(tmp, ',');
2330 savAcc = v->accuracy;
2332 mpcdm(&(v->MPfvals[i]), MPtemp);
2333 tmp = make_number(MPtemp, FALSE);
2334 v->accuracy = savAcc;
2339 mpcdm(&(v->MPfvals[i]), MPtemp);
2340 tmp = make_number(MPtemp, FALSE);
2342 if(strcmp(tmpStr, ".") != 0)
2344 /* if it's not a "." let's go change it to what it should be */
2345 ptr = DtStrrchr(tmp, '.');
2349 str = XmStringCreateLocalized(menu_entries[i + 34].str) ;
2350 numStr = XmStringCreateLocalized(tmp);
2351 XtVaSetValues(X->fregisters[i], XmNlabelString, str, NULL) ;
2352 XtVaSetValues(X->fregistersvals[i], XmNlabelString, numStr,
2353 XmNalignment, XmALIGNMENT_END, NULL) ;
2355 XmStringFree(numStr) ;
2363 menu_handler(widget, client_data, event, continue_to_dispatch)
2365 XtPointer client_data ;
2367 Boolean *continue_to_dispatch ;
2372 X->mtype = (enum menu_type) client_data ;
2373 menu = X->menus[(int) X->mtype] ;
2374 XtVaGetValues(menu, XmNwhichButton, &button, NULL) ;
2375 if (event->xbutton.button == button)
2377 XmMenuPosition(menu, (XButtonPressedEvent *) event) ;
2378 XtManageChild(menu) ;
2385 menu_proc(widget, client_data, call_data)
2387 XtPointer client_data, call_data ;
2389 int choice = ((int) client_data) & 0xFFFF ;
2391 v->curwin = ((int) client_data) >> 16 ;
2392 handle_menu_selection(X->mrec[(int) X->mtype], choice) ;
2398 new_cf_value(widget, client_data, call_data)
2400 XtPointer client_data, call_data ;
2403 for hard testing when there is no Input Method available
2404 wchar_t *wch = (wchar_t *) "wide";
2405 mbchar_t *mbch = (mbchar_t *) "MBYTE";
2408 enum menu_type mtype = (enum menu_type) client_data;
2411 if (X->CFframe == NULL) create_cfframe() ;
2415 set_text_str(X->CFpi_cftext, T_LABEL, lstrs[(int) L_CONNO]) ;
2417 cstr = XmStringCreateLocalized(lstrs[(int) L_NEWCON]) ;
2418 XtVaSetValues(X->CFframe, XmNdialogTitle, cstr, NULL) ;
2419 XmStringFree(cstr) ;
2421 XtRemoveAllCallbacks(X->CFpi_butHelp, XmNactivateCallback);
2422 XtAddCallback(X->CFpi_butHelp, XmNactivateCallback, HelpRequestCB,
2423 (XtPointer) HELP_CONSTANT);
2428 set_text_str(X->CFpi_cftext, T_LABEL, lstrs[(int) L_FUNNO]) ;
2430 cstr = XmStringCreateLocalized(lstrs[(int) L_NEWFUN]) ;
2431 XtVaSetValues(X->CFframe, XmNdialogTitle, cstr, NULL) ;
2432 XmStringFree(cstr) ;
2434 XtRemoveAllCallbacks(X->CFpi_butHelp, XmNactivateCallback);
2435 XtAddCallback(X->CFpi_butHelp, XmNactivateCallback, HelpRequestCB,
2436 (XtPointer) HELP_FUNCTION);
2439 /* Clear text fields. */
2441 set_text_str(X->CFpi_cftext, T_VALUE, "") ;
2442 set_text_str(X->CFpi_dtext, T_VALUE, "") ;
2443 set_text_str(X->CFpi_vtext, T_VALUE, "") ;
2446 for hard testing when there is no Input Method available
2447 XmTextFieldSetStringWcs(X->CFpi_vtext->textfield, wch);
2448 XmTextFieldSetStringWcs(X->CFpi_vtext->textfield, mbch);
2451 XmProcessTraversal(X->CFpi_cftext->textfield, XmTRAVERSE_CURRENT) ;
2453 if (!is_window_showing(X->CFframe))
2454 _DtGenericMapWindow (X->kframe, X->CFframe);
2456 XtManageChild(X->CFframe) ;
2458 /* lets set the focus in the first text widget */
2459 XmProcessTraversal(X->CFpi_cftext->textfield, XmTRAVERSE_CURRENT);
2460 ignore_event = True;
2461 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
2462 TimerEvent, (XtPointer) NULL);
2467 put_resource(rtype, value) /* Put calc resource into database. */
2468 enum res_type rtype ;
2471 ds_put_resource(&(X->dtcalcDB), v->appname, calc_res[(int) rtype], value) ;
2478 enum fcp_type scurwin ;
2479 int column, n, row ;
2482 scurwin = v->curwin ;
2483 v->curwin = FCP_KEY ;
2484 for (row = 0; row < BROWS; row++)
2485 for (column = 0; column < BCOLS; column++)
2487 n = row * MAXCOLS + column ;
2489 lstr = XmStringCreateLocalized(v->pstr) ;
2490 XtVaSetValues(X->kbuttons[row][column], XmNlabelString, lstr, NULL);
2491 XmStringFree(lstr) ;
2493 v->curwin = scurwin ;
2498 save_cmdline(argc, argv)
2502 ds_save_cmdline(X->dpy, XtWindow(X->kframe), argc, argv) ;
2507 save_resources(filename)
2510 int reply = ds_save_resources(X->dtcalcDB, filename) ;
2512 if (reply) _DtSimpleError (v->appname, DtWarning, NULL, vstrs[(int) V_NORSAVE]);
2519 ErrDialog(string, X->mainWin);
2523 set_item(itemno, str)
2524 enum item_type itemno ;
2529 char *tmpStr, *ptr, displayStr[50];
2531 if (itemno == DISPLAYITEM)
2535 if(str != NULL && (strcmp(str, "") != 0))
2537 /* Let's get the decimal point, in some languages it's a , */
2538 strcpy(displayStr, str);
2539 tmpStr = GETMESSAGE(3, 45, ".");
2540 if(strcmp(tmpStr, ".") != 0)
2542 /* if it's not a "." let's go change it to what it should be */
2543 ptr = DtStrrchr(displayStr, '.');
2547 w = X->modevals[(int) DISPLAYITEM] ;
2548 XmTextSetString(w, displayStr) ;
2549 XmTextSetInsertionPosition(w, XmTextGetLastPosition(w)) ;
2550 XSync(X->dpy, False);
2559 cstr = XmStringCreateLocalized(str) ;
2560 XtVaSetValues(X->modevals[(int) itemno], XmNlabelString, cstr, NULL) ;
2561 XmStringFree(cstr) ;
2567 set_title(fcptype, str) /* Set new title for a window. */
2568 enum fcp_type fcptype ;
2575 if (fcptype == FCP_KEY)
2577 else if (fcptype == FCP_REG)
2579 else if (fcptype == FCP_FIN_REG)
2581 else if (fcptype == FCP_MODE)
2582 w = X->mframe[(int) v->modetype] ;
2584 if (fcptype == FCP_KEY)
2585 XtVaSetValues(w, XmNtitle, str, NULL) ;
2588 cstr = XmStringCreateLocalized(str) ;
2589 XtVaSetValues(w, XmNdialogTitle, cstr, NULL) ;
2590 XmStringFree(cstr) ;
2597 show_ascii(widget, client_data, call_data)
2599 XtPointer client_data, call_data ;
2604 str = XmTextFieldGetString(X->Api_text->textfield);
2605 val = str[strlen(str) - 1] ;
2606 mpcim(&val, v->MPdisp_val) ;
2607 show_display(v->MPdisp_val) ;
2613 show_ascii_frame() /* Display ASCII popup. */
2617 Widget sep, frame, form;
2619 XmString label_string;
2621 if (X->Aframe == NULL)
2623 X->Aframe = (Widget) XmCreateFormDialog(X->kframe, "aframe", NULL, 0) ;
2624 tstr = XmStringCreateLocalized(pstrs[(int) P_ASCIIT]) ;
2625 XtVaSetValues(X->Aframe,
2626 XmNdialogTitle, tstr,
2627 XmNautoUnmanage, FALSE,
2628 XmNallowShellResize, TRUE,
2629 XmNdefaultPosition, FALSE,
2631 XmStringFree(tstr) ;
2633 /* Adjust the decorations for the dialog shell of the dialog */
2634 XtSetArg (args[0], XmNmwmFunctions, MWM_FUNC_MOVE);
2635 XtSetArg (args[1], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE);
2636 XtSetValues (XtParent(X->Aframe), args, 2);
2638 X->Api_text = make_textW(X->Aframe, pstrs[(int) P_CHAR]) ;
2640 XtSetArg (args[0], XmNtopAttachment, XmATTACH_FORM);
2641 XtSetArg (args[1], XmNtopOffset, 5);
2642 XtSetArg (args[2], XmNleftAttachment, XmATTACH_FORM);
2643 XtSetArg (args[3], XmNleftOffset, 5);
2644 XtSetValues(X->Api_text->manager, args, 4);
2646 XtSetArg (args[0], XmNmaxLength, 1);
2647 XtSetValues(X->Api_text->textfield, args, 1);
2649 XtSetArg (args[0], XmNtopAttachment, XmATTACH_WIDGET);
2650 XtSetArg (args[1], XmNtopWidget, X->Api_text->manager);
2651 XtSetArg (args[2], XmNtopOffset, 3);
2652 XtSetArg (args[3], XmNleftAttachment, XmATTACH_FORM);
2653 XtSetArg (args[4], XmNrightAttachment, XmATTACH_FORM);
2654 sep = XmCreateSeparator(X->Aframe, "sep", args, 5);
2657 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 33, "Apply") );
2658 XtSetArg (args[0], XmNmarginHeight, 2);
2659 XtSetArg (args[1], XmNmarginWidth, 15);
2660 XtSetArg (args[2], XmNlabelString, label_string);
2661 XtSetArg (args[3], XmNtopAttachment, XmATTACH_WIDGET);
2662 XtSetArg (args[4], XmNtopWidget, sep);
2663 XtSetArg (args[5], XmNtopOffset, 5);
2664 XtSetArg (args[6], XmNleftAttachment, XmATTACH_FORM);
2665 XtSetArg (args[7], XmNleftOffset, 10);
2666 XtSetArg (args[8], XmNbottomAttachment, XmATTACH_FORM);
2667 XtSetArg (args[9], XmNbottomOffset, 5);
2668 X->Api_butOK = XmCreatePushButton(X->Aframe, "button", args, 10);
2669 XmStringFree(label_string);
2670 XtManageChild(X->Api_butOK);
2672 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 32, "Close") );
2673 XtSetArg (args[0], XmNmarginHeight, 2);
2674 XtSetArg (args[1], XmNmarginWidth, 10);
2675 XtSetArg (args[2], XmNlabelString, label_string);
2676 XtSetArg (args[3], XmNtopAttachment, XmATTACH_WIDGET);
2677 XtSetArg (args[4], XmNtopWidget, sep);
2678 XtSetArg (args[5], XmNtopOffset, 5);
2679 XtSetArg (args[6], XmNleftAttachment, XmATTACH_WIDGET);
2680 XtSetArg (args[7], XmNleftWidget, X->Api_butOK);
2681 XtSetArg (args[8], XmNleftOffset, 10);
2682 XtSetArg (args[9], XmNbottomAttachment, XmATTACH_FORM);
2683 XtSetArg (args[10], XmNbottomOffset, 5);
2684 X->Api_butClose = XmCreatePushButton(X->Aframe, "button", args, 11);
2685 XmStringFree(label_string);
2686 XtManageChild(X->Api_butClose);
2688 label_string = XmStringCreateLocalized ( GETMESSAGE(2, 18, "Help") );
2689 XtSetArg (args[0], XmNmarginHeight, 2);
2690 XtSetArg (args[1], XmNmarginWidth, 10);
2691 XtSetArg (args[2], XmNlabelString, label_string);
2692 XtSetArg (args[3], XmNtopAttachment, XmATTACH_WIDGET);
2693 XtSetArg (args[4], XmNtopWidget, sep);
2694 XtSetArg (args[5], XmNtopOffset, 5);
2695 XtSetArg (args[6], XmNleftAttachment, XmATTACH_WIDGET);
2696 XtSetArg (args[7], XmNleftWidget, X->Api_butClose);
2697 XtSetArg (args[8], XmNleftOffset, 10);
2698 XtSetArg (args[9], XmNrightAttachment, XmATTACH_FORM);
2699 XtSetArg (args[10], XmNrightOffset, 10);
2700 XtSetArg (args[11], XmNbottomAttachment, XmATTACH_FORM);
2701 XtSetArg (args[12], XmNbottomOffset, 5);
2702 X->Api_butHelp = XmCreatePushButton(X->Aframe, "button", args, 13);
2703 XmStringFree(label_string);
2704 XtManageChild(X->Api_butHelp);
2706 XtAddCallback(X->Api_text->textfield, XmNactivateCallback,
2708 XtAddCallback(X->Api_butOK, XmNactivateCallback, show_ascii, NULL) ;
2709 XtAddCallback(X->Api_butClose, XmNactivateCallback, close_ascii,
2711 XtAddCallback(X->Api_butHelp, XmNactivateCallback, HelpRequestCB,
2712 (XtPointer) HELP_ASCII) ;
2715 XtSetArg (args[j], XmNcancelButton, X->Api_butClose); j++;
2716 XtSetArg (args[j], XmNdefaultButton, X->Api_butOK); j++;
2717 XtSetValues (X->Aframe, args, j);
2720 if (!is_window_showing(X->Aframe))
2721 _DtGenericMapWindow (X->kframe, X->Aframe);
2723 XtManageChild(X->Aframe) ;
2725 XmProcessTraversal(X->Api_text->textfield, XmTRAVERSE_CURRENT);
2726 ignore_event = True;
2727 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
2728 TimerEvent, (XtPointer) NULL);
2735 saveatom = XmInternAtom(X->dpy, "WM_SAVE_YOURSELF", FALSE) ;
2736 command_atom = XA_WM_COMMAND;
2737 wm_state_atom = XmInternAtom (X->dpy, "WM_STATE", False);
2739 XmAddWMProtocols(X->kframe, &saveatom, 1) ;
2740 XmAddWMProtocolCallback(X->kframe, saveatom, save_state, (XtPointer)NULL) ;
2743 XSetErrorHandler((int (*)())xerror_interpose) ;
2744 XtAddEventHandler(X->kframe, KeyPressMask | KeyReleaseMask,
2745 FALSE, event_proc, NULL) ;
2746 XmProcessTraversal( X->kbuttons[0][0], XmTRAVERSE_CURRENT );
2750 XtAppMainLoop(X->app) ;
2754 clear_buttons( start )
2761 static Boolean first = True;
2766 if(buttons[i].str != NULL)
2768 XtFree(buttons[i].str);
2769 XtFree(buttons[i].str2);
2770 XtFree(buttons[i].resname);
2772 buttons[i].str = XtNewString("");
2773 buttons[i].str2 = XtNewString("");
2774 buttons[i].resname = XtNewString("blank");
2775 buttons[i].value = 0;
2776 buttons[i].opdisp = OP_SET;
2777 buttons[i].mtype = M_NONE;
2780 lstr = XmStringCreateLocalized(buttons[i].str);
2781 XtSetArg (args[n], XmNlabelString, lstr); n++;
2784 XtSetArg (args[n], XmNbackground, pixels[1].bg); n++;
2785 XtSetArg (args[n], XmNforeground, pixels[1].fg); n++;
2786 XtSetArg (args[n], XmNtopShadowColor, pixels[1].ts); n++;
2787 XtSetArg (args[n], XmNbottomShadowColor, pixels[1].bs); n++;
2788 XtSetArg (args[n], XmNarmColor, pixels[1].sc); n++;
2790 XtSetValues( X->kbuttons[0][0], args, n);
2791 XmStringFree(lstr) ;
2795 row = (start / BCOLS) + 3;
2796 column = start % BCOLS;
2797 for(i = start + 12; i < 24; i++)
2799 XtFree(buttons[i].str);
2800 XtFree(buttons[i].resname);
2801 buttons[i].str = XtNewString("");
2802 buttons[i].resname = XtNewString("blank");
2803 buttons[i].value = 0;
2804 buttons[i].opdisp = OP_SET;
2805 buttons[i].mtype = M_NONE;
2808 lstr = XmStringCreateLocalized(buttons[i].str);
2809 XtSetArg (args[n], XmNlabelString, lstr); n++;
2812 XtSetArg (args[n], XmNbackground, pixels[1].bg); n++;
2813 XtSetArg (args[n], XmNforeground, pixels[1].fg); n++;
2814 XtSetArg (args[n], XmNtopShadowColor, pixels[1].ts); n++;
2815 XtSetArg (args[n], XmNbottomShadowColor, pixels[1].bs); n++;
2816 XtSetArg (args[n], XmNarmColor, pixels[1].sc); n++;
2818 XtSetValues( X->kbuttons[row][column], args, n);
2819 XmStringFree(lstr) ;
2822 if(column % BCOLS == 0)
2840 for(i = 12; i < 24; i++)
2842 if(buttons[i].str != NULL)
2844 XtFree(buttons[i].str);
2845 XtFree(buttons[i].str2);
2846 XtFree(buttons[i].resname);
2848 buttons[i].str = XtNewString(mode_buttons[i - 12].str);
2849 buttons[i].str2 = XtNewString(mode_buttons[i - 12].str2);
2850 buttons[i].resname = XtNewString(mode_buttons[i - 12].resname);
2851 buttons[i].value = mode_buttons[i - 12].value;
2852 buttons[i].opdisp = mode_buttons[i - 12].opdisp;
2853 buttons[i].mtype = mode_buttons[i - 12].mtype;
2854 buttons[i].func = mode_buttons[i - 12].func;
2858 lstr = XmStringCreateLocalized(buttons[i].str2);
2860 lstr = XmStringCreateLocalized(buttons[i].str);
2861 XtSetArg (args[n], XmNlabelString, lstr); n++;
2864 XtSetArg (args[n], XmNbackground, pixels[7].bg); n++;
2865 XtSetArg (args[n], XmNforeground, pixels[7].fg); n++;
2866 XtSetArg (args[n], XmNtopShadowColor, pixels[7].ts); n++;
2867 XtSetArg (args[n], XmNbottomShadowColor, pixels[7].bs); n++;
2868 XtSetArg (args[n], XmNarmColor, pixels[7].sc); n++;
2870 XtSetValues( X->kbuttons[row][column], args, n);
2871 XmStringFree(lstr) ;
2874 if(column % BCOLS == 0)
2893 for(i = 12; i < 24; i++)
2895 if(buttons[i].str != NULL)
2897 XtFree(buttons[i].str);
2898 XtFree(buttons[i].str2);
2899 XtFree(buttons[i].resname);
2901 buttons[i].str = XtNewString(mode_buttons[i + 4].str);
2902 buttons[i].str2 = XtNewString(mode_buttons[i + 4].str2);
2903 buttons[i].resname = XtNewString(mode_buttons[i + 4].resname);
2904 buttons[i].value = mode_buttons[i + 4].value;
2905 buttons[i].opdisp = mode_buttons[i + 4].opdisp;
2906 buttons[i].mtype = mode_buttons[i + 4].mtype;
2907 buttons[i].func = mode_buttons[i + 4].func;
2911 lstr = XmStringCreateLocalized(buttons[i].str2);
2913 lstr = XmStringCreateLocalized(buttons[i].str);
2914 XtSetArg (args[n], XmNlabelString, lstr); n++;
2917 XtSetArg (args[n], XmNbackground, pixels[7].bg); n++;
2918 XtSetArg (args[n], XmNforeground, pixels[7].fg); n++;
2919 XtSetArg (args[n], XmNtopShadowColor, pixels[7].ts); n++;
2920 XtSetArg (args[n], XmNbottomShadowColor, pixels[7].bs); n++;
2921 XtSetArg (args[n], XmNarmColor, pixels[7].sc); n++;
2923 XtSetValues( X->kbuttons[row][column], args, n);
2924 XmStringFree(lstr) ;
2927 if(column % BCOLS == 0)
2946 for(i = 12; i < 24; i++)
2948 if(buttons[i].str != NULL)
2950 XtFree(buttons[i].str);
2951 XtFree(buttons[i].str2);
2952 XtFree(buttons[i].resname);
2954 buttons[i].str = XtNewString(mode_buttons[i + 20].str);
2955 buttons[i].str2 = XtNewString(mode_buttons[i + 20].str2);
2956 buttons[i].resname = XtNewString(mode_buttons[i + 20].resname);
2957 buttons[i].value = mode_buttons[i + 20].value;
2958 buttons[i].opdisp = mode_buttons[i + 20].opdisp;
2959 buttons[i].mtype = mode_buttons[i + 20].mtype;
2960 buttons[i].func = mode_buttons[i + 20].func;
2964 lstr = XmStringCreateLocalized(buttons[i].str2);
2966 lstr = XmStringCreateLocalized(buttons[i].str);
2967 XtSetArg (args[n], XmNlabelString, lstr); n++;
2970 XtSetArg (args[n], XmNbackground, pixels[7].bg); n++;
2971 XtSetArg (args[n], XmNforeground, pixels[7].fg); n++;
2972 XtSetArg (args[n], XmNtopShadowColor, pixels[7].ts); n++;
2973 XtSetArg (args[n], XmNbottomShadowColor, pixels[7].bs); n++;
2974 XtSetArg (args[n], XmNarmColor, pixels[7].sc); n++;
2976 XtSetValues( X->kbuttons[row][column], args, n);
2977 XmStringFree(lstr) ;
2980 if(column % BCOLS == 0)
2991 switch_mode(curmode)
2992 enum mode_type curmode ;
2998 v->modetype = curmode ;
2999 XtSetArg(args[0], XmNmenuHistory, modeArry[(int)curmode]);
3000 XtSetValues( X->modevals[(int)MODEITEM], args, 1);
3001 if((int)curmode == (int)FINANCIAL)
3004 XtSetSensitive(X->modevals[(int)TTYPEITEM], False);
3005 set_item(HYPITEM, " ") ;
3006 set_item(INVITEM, " ") ;
3009 else if((int)curmode == (int)LOGICAL)
3012 XtSetSensitive(X->modevals[(int)TTYPEITEM], False);
3013 set_item(HYPITEM, " ") ;
3014 set_item(INVITEM, " ") ;
3019 XtSetSensitive(X->modevals[(int)TTYPEITEM], True);
3020 set_item(HYPITEM, " ") ;
3021 set_item(INVITEM, " ") ;
3030 char message[MAXLINE] ;
3031 char str[MAXLINE] ; /* Temporary buffer for various strings. */
3032 char result[MAXLINE] ;
3034 double tmp ; /* For converting constant value. */
3036 int n ; /* Set to 1, if constant value is valid. */
3037 char cur_op, current, display[MAXLINE], old_cal_value, fnum[MAX_DIGITS+1];
3038 int cur_ch, toclear, tstate, pending, accuracy;
3039 int MPdisp_val[MP_SIZE], MPlast_input[MP_SIZE], MPresult[MP_SIZE] ;
3043 case M_CON : tmpStr = GETMESSAGE(3, 45, ".");
3044 if(strcmp(tmpStr, ".") != 0)
3046 /* if it's not a "." let's go change it to what it
3048 ptr = DtStrchr(X->vval, tmpStr[0]);
3052 ptr = DtStrchr(X->vval, tmpStr[0]);
3055 /* need to run a "compute" of what was typed in */
3056 len = strlen(X->vval) ;
3057 STRCPY(str, X->vval);
3058 if(X->vval[len - 1] != '=')
3060 /* need to add an '=' at the end of the string so it
3061 computes correctly */
3066 if(strncmp(str, "-", 1) == 0)
3069 for(i=0; i < len -1; i++)
3071 str[i] = str[i+inc];
3072 if(inc == 0 || isdigit((int)str[i]) || str[i] == '.')
3081 /* now let's compute it, first save off some state */
3083 current = v->current;
3084 old_cal_value = v->old_cal_value;
3086 toclear = v->toclear;
3088 pending = v->pending;
3089 STRCPY(display, v->display);
3090 STRCPY(fnum, v->fnum);
3091 mpstr(v->MPdisp_val, MPdisp_val);
3092 mpstr(v->MPlast_input, MPlast_input);
3093 mpstr(v->MPresult, MPresult);
3095 mpcim(&i, v->MPdisp_val) ;
3096 mpcim(&i, v->MPlast_input) ;
3097 mpcim(&i, v->MPresult) ;
3101 process_str(str, M_CON);
3104 /* get the computed value */
3105 accuracy = v->accuracy;
3107 STRCPY(result, make_number(v->MPresult, FALSE)) ;
3108 v->accuracy = accuracy ;
3110 /* return to previous state */
3112 v->current = current;
3113 v->old_cal_value = old_cal_value;
3115 v->toclear = toclear;
3117 v->pending = pending;
3118 STRCPY(v->display, display);
3119 STRCPY(v->fnum, fnum);
3120 mpstr(MPdisp_val, v->MPdisp_val);
3121 mpstr(MPlast_input, v->MPlast_input);
3122 mpstr(MPresult, v->MPresult);
3124 set_item(DISPLAYITEM, v->display);
3126 n = sscanf(result, "%lf", &tmp) ;
3127 ptr = DtStrchr(result, 'e');
3128 if (n != 1 || ptr != NULL || v->error == TRUE)
3130 SPRINTF(message, "%s\n%s", vstrs[(int) V_INVCON],
3131 vstrs[(int) V_NOCHANGE]) ;
3132 do_continue_notice(X->CFframe, message) ;
3133 set_item(OPITEM, "") ;
3134 if(v->cur_op != '?')
3135 set_item(OPITEM, buttons[get_index(v->cur_op)].str);
3140 if(v->cur_op != '?')
3141 set_item(OPITEM, buttons[get_index(v->cur_op)].str);
3143 /* now let's compute it, first save off some state */
3144 if(strncmp(result, "-", 1) == 0)
3146 len = strlen(result);
3148 STRCPY(str, result);
3149 for(i=0; i < len; i++)
3151 MPstr_to_num(str, DEC, v->MPcon_vals[X->cfno]) ;
3152 mpneg(v->MPcon_vals[X->cfno], v->MPcon_vals[X->cfno]) ;
3155 MPstr_to_num(result, DEC, v->MPcon_vals[X->cfno]) ;
3157 if(strncmp(result, "0.", 2) == 0 ||
3158 strncmp(result, "-0.", 3) == 0 )
3160 len = strlen(result);
3161 while(result[len - 1] == '0')
3163 result[len - 1] = '\0';
3167 SPRINTF(v->con_names[X->cfno], "%1d: %s [%s]",
3168 X->cfno, result, X->dval) ;
3170 case M_FUN : tmpStr = GETMESSAGE(3, 45, ".");
3171 if(strcmp(tmpStr, ".") != 0)
3173 /* if it's not a "." let's go change it to what it
3175 ptr = DtStrchr(X->vval, tmpStr[0]);
3179 ptr = DtStrchr(X->vval, tmpStr[0]);
3182 STRCPY(v->fun_vals[X->cfno], convert(X->vval)) ;
3183 if(strcmp(X->vval, "") != 0)
3185 SPRINTF(v->fun_names[X->cfno], "%1d: %s [%s]",
3186 X->cfno, X->vval, X->dval) ;
3189 STRCPY(v->fun_names[X->cfno], "");
3192 XtDestroyWidget(X->menus[(int) X->CFtype]) ;
3193 for (i = 0; i < NOBUTTONS; i++)
3194 if (buttons[i].mtype == X->CFtype)
3195 create_menu(X->CFtype, X->kbuttons[i / BCOLS][i % BCOLS], i) ;
3199 write_rcfile(X->CFtype, X->cfexists, X->cfno,
3203 write_rcfile(X->CFtype, X->cfexists, X->cfno,
3207 ignore_event = True;
3208 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
3209 TimerEvent, (XtPointer) NULL);
3215 win_display(fcptype, state)
3216 enum fcp_type fcptype ;
3220 Position newX, newY;
3223 if (fcptype == FCP_REG) widget = X->rframe ;
3224 else if (fcptype == FCP_MODE) widget = X->mframe[(int) v->modetype] ;
3225 else if (fcptype == FCP_FIN_REG) widget = X->frframe;
3230 if (state && !is_window_showing(widget))
3232 if (fcptype == FCP_REG || fcptype == FCP_FIN_REG)
3234 XtSetMappedWhenManaged(XtParent(widget), False);
3235 XSync(X->dpy, False);
3237 XtManageChild(widget) ;
3239 _DtChildPosition(widget, X->kframe, &newX, &newY);
3240 XtSetArg(args[0], XmNx, newX);
3241 XtSetArg(args[1], XmNy, newY);
3242 XtSetValues(widget, args, 2);
3244 XtSetMappedWhenManaged(XtParent(widget), True);
3245 XSync(X->dpy, False);
3247 XtMapWidget(XtParent(widget));
3249 else if (fcptype == FCP_MODE)
3250 _DtGenericMapWindow (X->kframe, widget);
3252 if (state) XtManageChild(widget) ;
3253 else XtUnmanageChild(widget) ;
3259 write_cf_value(widget, client_data, call_data)
3261 XtPointer client_data, call_data ;
3263 char message[MAXLINE] ;
3264 char str[MAXLINE] ; /* Temporary buffer for various strings. */
3265 Widget focus_widget;
3268 focus_widget = XmGetFocusWidget(widget);
3271 if(focus_widget != X->CFpi_vtext->textfield && focus_widget != X->CFpi_butOK)
3275 if(focus_widget == X->CFpi_vtext->textfield)
3277 X->vval = XmTextFieldGetString(X->CFpi_vtext->textfield);
3278 if(strcmp(X->vval, "") == 0)
3286 if(X->cfval != NULL)
3288 X->dval = XmTextFieldGetString(X->CFpi_dtext->textfield);
3289 if(strlen(X->dval) > 41)
3291 X->vval = XmTextFieldGetString(X->CFpi_vtext->textfield);
3292 X->cfval = XmTextFieldGetString(X->CFpi_cftext->textfield);
3293 SSCANF(X->cfval, "%d", &X->cfno) ;
3294 if ((strcmp(X->cfval, "") == 0) || X->cfval[0] < '0' || X->cfval[0] > '9' ||
3295 X->cfno < 0 || X->cfno > 9)
3297 SPRINTF(str, "%s", (X->CFtype == M_CON) ? vstrs[(int) V_LCON]
3298 : vstrs[(int) V_LFUN]) ;
3299 SPRINTF(message, "%s\n%s", str, vstrs[(int) V_RANGE]) ;
3300 do_continue_notice(X->CFframe, message) ;
3304 X->vval = (char *)_DtcalcStripSpaces((char *)X->vval);
3308 case M_CON : X->cfexists = 1 ; /* Always the default constants. */
3310 case M_FUN : if (strlen(v->fun_vals[X->cfno])) X->cfexists = 1 ;
3314 SPRINTF(str, mess[(int) MESS_CON],
3315 (X->CFtype == M_CON) ? vstrs[(int) V_UCON]
3316 : vstrs[(int) V_UFUN], X->cfno) ;
3317 SPRINTF(message, "%s\n%s", str, vstrs[(int) V_OWRITE]) ;
3318 XtUnmanageChild(X->CFframe) ;
3319 do_confirm_notice(X->CFframe, message) ;
3324 XtUnmanageChild(X->CFframe) ;
3327 XtSetArg (args[0], XmNdefaultButton, NULL);
3328 XtSetValues (X->CFframe, args, 1);
3333 xerror_interpose(display, error)
3335 XErrorEvent *error ;
3340 XGetErrorText(display, error->error_code, msg1, 80) ;
3341 sprintf(msg, "\nX Error (intercepted): %s\nMajor Request Code : %d\nMinor Request Code : %d\nResource ID (XID) : %lu\nError Serial Number : %lu\n", msg1, error->request_code, error->minor_code, error->resourceid, error->serial);
3342 _DtSimpleError (v->appname, DtError, NULL, msg);
3347 modelineValueChanged(widget, client_data, call_data)
3349 XtPointer client_data, call_data ;
3352 int position, val, choice;
3354 X->mtype = (enum menu_type) client_data ;
3355 XtSetArg (args[0], XmNuserData, &val);
3356 XtGetValues (widget, args, 1);
3358 choice = val & 0xFFFF ;
3359 v->curwin = ((int) val) >> 16 ;
3360 if(X->mtype == M_BASE)
3361 handle_menu_selection(56, choice) ;
3362 else if(X->mtype == M_NUM)
3363 handle_menu_selection(57, choice) ;
3364 else if(X->mtype == M_MODE)
3365 handle_menu_selection(58, choice) ;
3367 handle_menu_selection(59, choice) ;
3370 create_menu_bar(parent)
3374 int i, j, val, count;
3375 Widget WidgList[10];
3378 XmString labelString;
3379 Widget child, mem_reg;
3380 Widget lastCascadeButtonGadget;
3381 Widget lastCascadeButton;
3382 Widget lastMenuPane;
3383 Widget helpPulldown;
3384 Widget lastCascadeMenuPane;
3387 /* Create the pulldown menu */
3389 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
3390 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
3391 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
3392 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3393 X->menubar = XmCreateMenuBar(parent, "mainMenu", args, n);
3394 XtManageChild(X->menubar);
3395 XtAddCallback(X->menubar, XmNhelpCallback, HelpRequestCB,
3396 (XtPointer)HELP_MENUBAR);
3398 mnemonic = GETMESSAGE(2, 13, "O");
3399 mnemonic = XtNewString(mnemonic);
3401 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 14, "Options") );
3402 XtSetArg(args[n], XmNlabelString, labelString); n++;
3403 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3404 XtSetArg(args[n], XmNmarginWidth, 6); n++;
3405 lastCascadeButtonGadget =
3406 XmCreateCascadeButtonGadget(X->menubar, "options", args, n);
3407 XtManageChild(lastCascadeButtonGadget);
3408 XmStringFree(labelString);
3411 lastMenuPane = XmCreatePulldownMenu(X->menubar, "optionMenu", NULL, 0);
3413 XtSetArg(args[0], XmNsubMenuId, lastMenuPane);
3414 XtSetValues(lastCascadeButtonGadget, args, 1);
3416 mnemonic = GETMESSAGE(2, 40, "R");
3417 mnemonic = XtNewString(mnemonic);
3419 XmStringCreateLocalized( GETMESSAGE(2, 15, "Memory Registers") );
3420 XtSetArg(args[0], XmNlabelString, labelString );
3421 XtSetArg(args[1], XmNmnemonic, XStringToKeysym( mnemonic ) );
3422 mem_reg = XmCreatePushButtonGadget (lastMenuPane, "memR", args, 2);
3423 XtManageChild(mem_reg);
3424 XmStringFree(labelString);
3425 XtAddCallback(mem_reg, XmNactivateCallback, (XtCallbackProc)do_memory,
3428 mnemonic = GETMESSAGE(2, 45, "g");
3429 mnemonic = XtNewString(mnemonic);
3431 XmStringCreateLocalized ( GETMESSAGE(3, 138, "Financial Registers") );
3432 XtSetArg(args[0], XmNlabelString, labelString );
3433 XtSetArg(args[1], XmNmnemonic, XStringToKeysym( mnemonic ) );
3434 mem_reg = XmCreatePushButtonGadget (lastMenuPane, "finR", args, 2);
3435 XtManageChild(mem_reg);
3436 XmStringFree(labelString);
3437 XtAddCallback(mem_reg, XmNactivateCallback, (XtCallbackProc)do_memory,
3440 mnemonic = GETMESSAGE(2, 41, "A");
3441 mnemonic = XtNewString(mnemonic);
3442 labelString=XmStringCreateLocalized ( GETMESSAGE(2, 16, "ASCII Convert") );
3443 XtSetArg(args[0], XmNlabelString, labelString );
3444 XtSetArg(args[1], XmNmnemonic, XStringToKeysym( mnemonic ) );
3445 child = XmCreatePushButtonGadget (lastMenuPane, "asc", args, 2);
3446 XtManageChild(child);
3447 XmStringFree(labelString);
3448 XtAddCallback(child, XmNactivateCallback, (XtCallbackProc)do_ascii,
3451 if(_DtNl_is_multibyte)
3452 XtSetSensitive(child, False);
3454 child = (Widget)XmCreateSeparatorGadget(lastMenuPane, "separator",args,0);
3455 XtManageChild(child);
3457 mnemonic = GETMESSAGE(2, 42, "F");
3458 mnemonic = XtNewString(mnemonic);
3459 labelString = XmStringCreateLocalized ( vstrs[(int) V_FUNWNAME] );
3460 XtSetArg(args[0], XmNlabelString, labelString );
3461 XtSetArg(args[1], XmNmnemonic, XStringToKeysym( mnemonic ) );
3462 child = XmCreatePushButtonGadget (lastMenuPane, "enterFunc", args, 2);
3463 XtManageChild(child);
3464 XmStringFree(labelString);
3465 XtAddCallback(child, XmNactivateCallback, (XtCallbackProc)new_cf_value,
3466 (XtPointer)(int)M_FUN);
3468 mnemonic = GETMESSAGE(2, 43, "C");
3469 mnemonic = XtNewString(mnemonic);
3470 labelString = XmStringCreateLocalized ( vstrs[(int) V_CONWNAME] );
3471 XtSetArg(args[0], XmNlabelString, labelString );
3472 XtSetArg(args[1], XmNmnemonic, XStringToKeysym( mnemonic ) );
3473 child = XmCreatePushButtonGadget (lastMenuPane, "enterCons", args, 2);
3474 XtManageChild(child);
3475 XmStringFree(labelString);
3476 XtAddCallback(child, XmNactivateCallback, (XtCallbackProc)new_cf_value,
3477 (XtPointer)(int)M_CON);
3479 child = (Widget)XmCreateSeparatorGadget(lastMenuPane, "separator",args,0);
3480 XtManageChild(child);
3482 mnemonic = GETMESSAGE(2, 44, "x");
3483 mnemonic = XtNewString(mnemonic);
3484 labelString = XmStringCreateLocalized ( GETMESSAGE(3, 403, "Exit") );
3485 XtSetArg(args[0], XmNlabelString, labelString );
3486 XtSetArg(args[1], XmNmnemonic, XStringToKeysym( mnemonic ) );
3487 child = XmCreatePushButtonGadget (lastMenuPane, "exit", args, 2);
3488 XtManageChild(child);
3489 XmStringFree(labelString);
3490 XtAddCallback(child, XmNactivateCallback, (XtCallbackProc)do_frame,
3494 mnemonic = GETMESSAGE(2, 17, "H");
3495 mnemonic = XtNewString(mnemonic);
3496 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 18, "Help") );
3497 XtSetArg(args[n], XmNlabelString, labelString); n++;
3498 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3499 XtSetArg(args[n], XmNmarginWidth, 6); n++;
3500 lastCascadeButtonGadget =
3501 XmCreateCascadeButtonGadget(X->menubar, "help", args, n);
3502 XmStringFree(labelString);
3505 helpPulldown = XmCreatePulldownMenu(X->menubar, "helpMenu", NULL, 0);
3507 XtSetArg(args[0], XmNsubMenuId, helpPulldown);
3508 XtSetValues(lastCascadeButtonGadget, args, 1);
3510 XtSetArg(args[0], XmNmenuHelpWidget, lastCascadeButtonGadget);
3511 XtSetValues (X->menubar, args, 1);
3513 XtManageChild(lastCascadeButtonGadget);
3518 mnemonic = GETMESSAGE(2, 19, "v");
3519 mnemonic = XtNewString(mnemonic);
3520 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3521 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 20, "Overview") );
3522 XtSetArg(args[n], XmNlabelString, labelString); n++;
3524 XmCreatePushButton(helpPulldown, "introduction", args, n );
3525 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3526 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_INTRODUCTION);
3527 XmStringFree(labelString);
3530 WidgList[count++]= (Widget)XmCreateSeparatorGadget(helpPulldown,
3531 "separator",args,0);
3534 mnemonic = GETMESSAGE(2, 38, "C");
3535 mnemonic = XtNewString(mnemonic);
3536 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3538 XmStringCreateLocalized ( GETMESSAGE(2,39,"Table of Contents") );
3539 XtSetArg(args[n], XmNlabelString, labelString); n++;
3540 WidgList[count++]= XmCreatePushButton(helpPulldown, "toc", args, n );
3541 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3542 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_TABLEOFCONTENTS);
3543 XmStringFree(labelString);
3547 mnemonic = GETMESSAGE(2, 21, "T");
3548 mnemonic = XtNewString(mnemonic);
3549 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3550 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 22, "Tasks") );
3551 XtSetArg(args[n], XmNlabelString, labelString); n++;
3552 WidgList[count++]= XmCreatePushButton(helpPulldown, "tasks", args, n );
3553 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3554 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_TASKS);
3555 XmStringFree(labelString);
3559 mnemonic = GETMESSAGE(2, 23, "R");
3560 mnemonic = XtNewString(mnemonic);
3561 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3562 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 24, "Reference") );
3563 XtSetArg(args[n], XmNlabelString, labelString); n++;
3564 WidgList[count++]= XmCreatePushButton(helpPulldown, "reference", args, n );
3565 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3566 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_REFERENCE);
3567 XmStringFree(labelString);
3571 mnemonic = GETMESSAGE(2, 25, "O");
3572 mnemonic = XtNewString(mnemonic);
3573 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3574 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 26, "On Item") );
3575 XtSetArg(args[n], XmNlabelString, labelString); n++;
3576 WidgList[count++]= XmCreatePushButton(helpPulldown, "onItem", args, n );
3577 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3578 (XtCallbackProc)HelpModeCB, (XtPointer)NULL);
3579 XmStringFree(labelString);
3582 WidgList[count++]= (Widget)XmCreateSeparatorGadget(helpPulldown,
3583 "separator",args,0);
3586 mnemonic = GETMESSAGE(2, 27, "U");
3587 mnemonic = XtNewString(mnemonic);
3588 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3589 labelString = XmStringCreateLocalized ( GETMESSAGE(2, 28, "Using Help") );
3590 XtSetArg(args[n], XmNlabelString, labelString); n++;
3592 XmCreatePushButton(helpPulldown, "usingHelp", args, n );
3593 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3594 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_USING);
3595 XmStringFree(labelString);
3598 WidgList[count++]= (Widget)XmCreateSeparatorGadget(helpPulldown,
3599 "separator",args,0);
3602 mnemonic = GETMESSAGE(2, 29, "A");
3603 mnemonic = XtNewString(mnemonic);
3604 XtSetArg(args[n], XmNmnemonic, XStringToKeysym( mnemonic ) ); n++;
3606 XmStringCreateLocalized ( GETMESSAGE(2, 30, "About Calculator") );
3607 XtSetArg(args[n], XmNlabelString, labelString); n++;
3608 WidgList[count++]= XmCreatePushButton(helpPulldown, "about", args, n );
3609 XtAddCallback(WidgList[count-1], XmNactivateCallback,
3610 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_VERSION);
3611 XmStringFree(labelString);
3614 XtManageChildren(WidgList, count);
3616 /* Fine tune the menubar */
3617 XtSetArg(args[0], XmNmarginWidth, 2);
3618 XtSetArg(args[1], XmNmarginHeight, 2);
3619 XtSetValues(X->menubar, args, 2);
3627 short act, inact, prim, second;
3629 XmeGetPixelData (X->screen, &colorUse, pixels, &act, &inact,
3632 if(pixels[0].bg == pixels[1].bg && pixels[1].bg == pixels[2].bg &&
3633 pixels[2].bg == pixels[3].bg && pixels[3].bg == pixels[4].bg &&
3634 pixels[4].bg == pixels[5].bg && pixels[5].bg == pixels[6].bg &&
3635 pixels[6].bg == pixels[7].bg && pixels[7].bg == 0)
3643 do_memory( w, client_data, call_data )
3645 XtPointer client_data ;
3646 XtPointer call_data ;
3648 int type = (int)client_data;
3655 make_registers(MEM) ;
3657 win_display(FCP_REG, TRUE) ;
3664 make_registers(FIN) ;
3666 win_display(FCP_FIN_REG, TRUE) ;
3668 ignore_event = True;
3669 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
3670 TimerEvent, (XtPointer) NULL);
3674 read_resources() /* Read all possible resources from the database. */
3676 int boolval, i, intval ;
3680 /* set the accuracy variable */
3681 if(application_args.accuracy > 9)
3683 else if(application_args.accuracy < 0)
3686 v->accuracy = application_args.accuracy;
3689 if(strcmp(application_args.base, "binary") == 0 ||
3690 strcmp(application_args.base, "bin") == 0)
3691 v->base = (enum base_type) 0 ;
3692 else if(strcmp(application_args.base, "octal") == 0 ||
3693 strcmp(application_args.base, "oct") == 0)
3694 v->base = (enum base_type) 1 ;
3695 else if(strcmp(application_args.base, "decimal") == 0 ||
3696 strcmp(application_args.base, "dec") == 0)
3697 v->base = (enum base_type) 2 ;
3698 else if(strcmp(application_args.base, "hexadecimal") == 0 ||
3699 strcmp(application_args.base, "hex") == 0)
3700 v->base = (enum base_type) 3 ;
3703 msg = (char *) XtMalloc(strlen( opts[(int) O_BASE]) + 3);
3704 sprintf(msg, "%s", opts[(int) O_BASE]);
3705 _DtSimpleError (v->appname, DtWarning, NULL, msg);
3707 v->base = (enum base_type) 2;
3710 /* set the display numeration */
3711 if(strcmp(application_args.display, "fixed") == 0)
3712 v->dtype = (enum base_type) 1 ;
3713 else if(strcmp(application_args.display, "eng") == 0 ||
3714 strcmp(application_args.display, "engineering") == 0)
3715 v->dtype = (enum base_type) 0 ;
3716 else if(strcmp(application_args.display, "scientific") == 0 ||
3717 strcmp(application_args.display, "sci") == 0)
3718 v->dtype = (enum base_type) 2 ;
3721 msg = (char *) XtMalloc(strlen( opts[(int) O_DISPLAY]) + strlen(str) + 3);
3722 sprintf(msg, opts[(int) O_DISPLAY], str);
3723 _DtSimpleError (v->appname, DtWarning, NULL, msg);
3725 v->dtype = (enum base_type) 1;
3729 if(strcmp(application_args.mode, "scientific") == 0)
3730 v->modetype = (enum base_type) 2 ;
3731 else if(strcmp(application_args.mode, "financial") == 0)
3732 v->modetype = (enum base_type) 0 ;
3733 else if(strcmp(application_args.mode, "logical") == 0)
3734 v->modetype = (enum base_type) 1 ;
3737 msg = (char *) XtMalloc(strlen( opts[(int) O_MODE]) + strlen(str) + 3);
3738 sprintf(msg, opts[(int) O_MODE], str);
3739 _DtSimpleError (v->appname, DtWarning, NULL, msg);
3741 v->modetype = (enum base_type) 2;
3744 /* set the display numeration */
3745 if(strcmp(application_args.trigType, "deg") == 0 ||
3746 strcmp(application_args.trigType, "degrees") == 0)
3747 v->ttype = (enum base_type) 0 ;
3748 else if(strcmp(application_args.trigType, "rad") == 0 ||
3749 strcmp(application_args.trigType, "radians") == 0)
3750 v->ttype = (enum base_type) 2 ;
3751 else if(strcmp(application_args.trigType, "grad") == 0 ||
3752 strcmp(application_args.trigType, "gradients") == 0)
3753 v->ttype = (enum base_type) 1 ;
3756 msg = (char *) XtMalloc(strlen( opts[(int) O_TRIG]) + strlen(str) + 3);
3757 sprintf(msg, opts[(int) O_TRIG], str);
3758 _DtSimpleError (v->appname, DtWarning, NULL, msg);
3760 v->ttype = (enum base_type) 0;
3766 close_cf(widget, client_data, call_data)
3768 XtPointer client_data, call_data ;
3772 XtSetArg (args[0], XmNdefaultButton, NULL);
3773 XtSetValues (X->CFframe, args, 1);
3775 XtUnmanageChild(X->CFframe) ;
3776 ignore_event = True;
3777 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
3778 TimerEvent, (XtPointer) NULL);
3782 close_ascii(widget, client_data, call_data)
3784 XtPointer client_data, call_data ;
3786 XtUnmanageChild(X->Aframe) ;
3787 ignore_event = True;
3788 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
3789 TimerEvent, (XtPointer) NULL);
3793 FocusInCB(widget, client_data, call_data)
3795 XtPointer client_data, call_data ;
3799 XtSetArg (args[0], XmNdefaultButton, NULL);
3800 XtSetValues (X->CFframe, args, 1);
3802 XtSetArg(args[0], XmNshowAsDefault, True);
3803 XtSetValues(X->CFpi_butOK, args, 1);
3807 move_cf(widget, client_data, call_data)
3809 XtPointer client_data, call_data ;
3816 if(widget == X->CFpi_cftext->textfield)
3818 XtSetArg (args[0], XmNdefaultButton, NULL);
3819 XtSetValues (X->CFframe, args, 1);
3821 XtSetArg(args[0], XmNshowAsDefault, True);
3822 XtSetValues(X->CFpi_butOK, args, 1);
3824 input = XmTextFieldGetString(X->CFpi_cftext->textfield);
3825 if(strcmp(input, "") != 0)
3826 XmProcessTraversal(X->CFpi_dtext->textfield, XmTRAVERSE_CURRENT);
3828 else if(widget == X->CFpi_dtext->textfield)
3830 XtSetArg (args[0], XmNdefaultButton, NULL);
3831 XtSetValues (X->CFframe, args, 1);
3833 XtSetArg(args[0], XmNshowAsDefault, True);
3834 XtSetValues(X->CFpi_butOK, args, 1);
3836 XmProcessTraversal(X->CFpi_vtext->textfield, XmTRAVERSE_CURRENT);
3839 else if(widget == X->CFpi_vtext->textfield)
3841 input = XmTextFieldGetString(X->CFpi_vtext->textfield);
3843 ignore_event = True;
3844 timerId = XtAppAddTimeOut (XtWidgetToApplicationContext (X->kframe), 300,
3845 TimerEvent, (XtPointer) value);
3848 create_popup(parent)
3855 Widget dummyHelp1, dummyHelp2, memRegs;
3856 Widget help, helpI, helpToc, helpT, helpR, helpO, helpU, helpV;
3858 X->popupMenu = XmCreatePopupMenu(parent, "popup", NULL, 0) ;
3859 XtCreateManagedWidget(GETMESSAGE(2, 46,"Calculator Popup"),
3860 xmLabelWidgetClass, X->popupMenu, NULL, 0) ;
3861 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
3862 X->popupMenu, NULL, 0) ;
3863 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
3864 X->popupMenu, NULL, 0) ;
3867 /* The popup menu contains the following entries ......................*/
3868 /* 1. Memory Registers ... */
3869 memRegs = XtVaCreateManagedWidget( "memRegs1",
3870 xmPushButtonWidgetClass,
3872 XmNlabelString, XmStringCreateLocalized(
3873 GETMESSAGE(2, 15, "Memory Registers") ),
3874 XmNmnemonic, XStringToKeysym(
3875 GETMESSAGE(2, 40, "R") ),
3877 XtAddCallback(memRegs, XmNactivateCallback, (XtCallbackProc)do_memory,
3880 /* 2. Finacial Registers ... */
3881 memRegs = XtVaCreateManagedWidget( "memRegs2",
3882 xmPushButtonWidgetClass,
3884 XmNlabelString, XmStringCreateLocalized(
3885 GETMESSAGE(3, 138, "Financial Registers") ),
3886 XmNmnemonic, XStringToKeysym(
3887 GETMESSAGE( 2, 45, "g" ) ),
3889 XtAddCallback(memRegs, XmNactivateCallback, (XtCallbackProc)do_memory,
3892 /* 3. Ascii Converter ... */
3893 X->asciiConv = XtVaCreateManagedWidget("asciiConv",
3894 xmPushButtonWidgetClass,
3897 XmStringCreateLocalized( GETMESSAGE(2, 16, "ASCII Convert") ),
3898 XmNmnemonic, XStringToKeysym(
3899 GETMESSAGE(2, 41, "A") ),
3901 XtAddCallback(X->asciiConv, XmNactivateCallback, (XtCallbackProc)do_ascii,
3904 if(_DtNl_is_multibyte)
3905 XtSetSensitive(X->asciiConv, False);
3907 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
3908 X->popupMenu, NULL, 0) ;
3910 /* 4. Enter Functions ... */
3911 X->enterFun = XtVaCreateManagedWidget("enterFun",
3912 xmPushButtonWidgetClass,
3915 XmStringCreateLocalized( vstrs[(int) V_FUNWNAME] ),
3916 XmNmnemonic, XStringToKeysym(
3917 GETMESSAGE(2, 42, "F") ),
3919 XtAddCallback(X->enterFun, XmNactivateCallback, (XtCallbackProc)new_cf_value,
3920 (XtPointer)(int)M_FUN);
3922 /* 5. Enter Constants ... */
3923 X->enterConst = XtVaCreateManagedWidget("enterConst",
3924 xmPushButtonWidgetClass,
3927 XmStringCreateLocalized( vstrs[(int) V_CONWNAME] ),
3928 XmNmnemonic, XStringToKeysym(
3929 GETMESSAGE(2, 43, "C") ),
3931 XtAddCallback(X->enterConst, XmNactivateCallback,(XtCallbackProc)new_cf_value,
3932 (XtPointer)(int)M_CON);
3934 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
3935 X->popupMenu, NULL, 0) ;
3940 dummyHelp1 = XtVaCreatePopupShell ("dummyHelp1",
3941 xmMenuShellWidgetClass,
3947 dummyHelp2 = XtVaCreateWidget("dummyHelp2",
3948 xmRowColumnWidgetClass, dummyHelp1,
3949 XmNrowColumnType, XmMENU_PULLDOWN,
3953 label = XmStringCreateLocalized ( GETMESSAGE(2, 20, "Overview") );
3954 helpI = XtVaCreateManagedWidget ("introduction",
3955 xmPushButtonGadgetClass, dummyHelp2,
3956 XmNlabelString, label,
3957 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 19, "v") ),
3961 XtAddCallback(helpI, XmNactivateCallback,
3962 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_INTRODUCTION);
3963 XmStringFree (label);
3965 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
3966 dummyHelp2, NULL, 0);
3968 label = XmStringCreateLocalized ( GETMESSAGE(2, 39, "Table of Contents") );
3969 helpToc = XtVaCreateManagedWidget ("toc",
3970 xmPushButtonGadgetClass, dummyHelp2,
3971 XmNlabelString, label,
3972 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 38, "C") ),
3975 XtAddCallback(helpToc, XmNactivateCallback,
3976 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_TABLEOFCONTENTS);
3978 XmStringFree(label);
3981 label = XmStringCreateLocalized ( GETMESSAGE(2, 22, "Tasks") );
3982 helpT = XtVaCreateManagedWidget ("tasks",
3983 xmPushButtonGadgetClass, dummyHelp2,
3984 XmNlabelString, label,
3985 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 21, "T") ),
3988 XtAddCallback(helpT, XmNactivateCallback,
3989 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_TASKS);
3991 XmStringFree(label);
3994 label = XmStringCreateLocalized ( GETMESSAGE(2, 24, "Reference") );
3995 helpR = XtVaCreateManagedWidget ("reference",
3996 xmPushButtonGadgetClass, dummyHelp2,
3997 XmNlabelString, label,
3998 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 23, "R" ) ),
4002 XtAddCallback(helpR, XmNactivateCallback,
4003 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_REFERENCE);
4005 XmStringFree(label);
4007 label = XmStringCreateLocalized ( GETMESSAGE(2, 26, "On Item") );
4009 helpO = XtVaCreateManagedWidget ("onItem",
4010 xmPushButtonGadgetClass, dummyHelp2,
4011 XmNlabelString, label,
4012 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 25, "O") ),
4015 XtAddCallback(helpO, XmNactivateCallback,
4016 (XtCallbackProc)HelpModeCB, (XtPointer)NULL);
4018 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
4019 dummyHelp2, NULL, 0);
4020 XmStringFree (label);
4022 label = XmStringCreateLocalized ( GETMESSAGE(2, 28, "Using Help") );
4023 helpU = XtVaCreateManagedWidget ("useHelp",
4024 xmPushButtonGadgetClass, dummyHelp2,
4025 XmNlabelString, label,
4026 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 27, "U") ),
4030 XtAddCallback(helpU, XmNactivateCallback,
4031 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_USING);
4033 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
4034 dummyHelp2, NULL, 0);
4036 XmStringFree(label);
4038 label = XmStringCreateLocalized (GETMESSAGE(2, 30, "About Calculator") );
4039 helpV = XtVaCreateManagedWidget ("version",
4040 xmPushButtonGadgetClass, dummyHelp2,
4041 XmNlabelString, label,
4042 XmNmnemonic, XStringToKeysym( GETMESSAGE(2, 29, "A" ) ),
4045 XtAddCallback(helpV, XmNactivateCallback,
4046 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_VERSION);
4048 XmStringFree(label);
4051 mnemonic = GETMESSAGE(2, 17, "H");
4052 label = XmStringCreateLocalized ( GETMESSAGE(2, 18, "Help") );
4053 help = XtVaCreateManagedWidget("help",
4054 xmCascadeButtonGadgetClass, X->popupMenu,
4055 XmNsubMenuId, dummyHelp2,
4056 XmNmnemonic, XStringToKeysym( mnemonic ),
4057 XmNlabelString, label,
4059 XmStringFree(label);
4061 XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
4062 X->popupMenu, NULL, 0);
4065 label = XmStringCreateLocalized ( GETMESSAGE(3, 403, "Exit") );
4066 X->Close = XtVaCreateManagedWidget("close",
4067 xmPushButtonWidgetClass,
4069 XmNlabelString, label,
4071 XStringToKeysym(GETMESSAGE(2, 44, "X" )),
4073 XmStringFree(label);
4074 XtAddCallback(X->Close, XmNactivateCallback,(XtCallbackProc)do_frame,
4075 (XtPointer)(int)M_FUN);
4077 XtAddEventHandler(parent, ButtonPressMask, FALSE,
4078 popupHandler, (XtPointer) NULL) ;
4079 XtAddCallback(X->popupMenu, XmNmapCallback,(XtCallbackProc)map_popup,
4084 popupHandler(widget, client_data, event, continue_to_dispatch)
4086 XtPointer client_data ;
4088 Boolean *continue_to_dispatch ;
4090 XButtonPressedEvent *bevent;
4092 bevent = (XButtonPressedEvent *)event;
4094 if (event->type == ButtonPress && event->xbutton.button == Button3)
4096 if(bevent->x >= funBtn->core.x &&
4097 bevent->x <= funBtn->core.x + funBtn->core.width &&
4098 bevent->y >= funBtn->core.y +
4099 X->modeline->core.height + X->textForm->core.height &&
4100 bevent->y <= funBtn->core.y +funBtn->core.height +
4101 X->modeline->core.height + X->textForm->core.height)
4103 menu_handler(widget, (XtPointer)M_FUN, event, continue_to_dispatch);
4105 else if(bevent->x >= constBtn->core.x &&
4106 bevent->x <= constBtn->core.x + constBtn->core.width &&
4107 bevent->y >= constBtn->core.y +
4108 X->modeline->core.height + X->textForm->core.height &&
4109 bevent->y <= constBtn->core.y + constBtn->core.height +
4110 X->modeline->core.height + X->textForm->core.height)
4112 menu_handler(widget, (XtPointer)M_CON, event, continue_to_dispatch);
4114 else if(bevent->x >= accBtn->core.x &&
4115 bevent->x <= accBtn->core.x + accBtn->core.width &&
4116 bevent->y >= accBtn->core.y +
4117 X->modeline->core.height + X->textForm->core.height &&
4118 bevent->y <= accBtn->core.y + accBtn->core.height +
4119 X->modeline->core.height + X->textForm->core.height)
4121 menu_handler(widget, (XtPointer)M_ACC, event, continue_to_dispatch);
4123 else if(bevent->x >= rclBtn->core.x &&
4124 bevent->x <= rclBtn->core.x + rclBtn->core.width &&
4125 bevent->y >= rclBtn->core.y +
4126 X->modeline->core.height + X->textForm->core.height &&
4127 bevent->y <= rclBtn->core.y + rclBtn->core.height +
4128 X->modeline->core.height + X->textForm->core.height)
4130 menu_handler(widget, (XtPointer)M_RCL, event, continue_to_dispatch);
4132 else if(bevent->x >= stoBtn->core.x &&
4133 bevent->x <= stoBtn->core.x + stoBtn->core.width &&
4134 bevent->y >= stoBtn->core.y +
4135 X->modeline->core.height + X->textForm->core.height &&
4136 bevent->y <= stoBtn->core.y + stoBtn->core.height +
4137 X->modeline->core.height + X->textForm->core.height)
4139 menu_handler(widget, (XtPointer)M_STO, event, continue_to_dispatch);
4141 else if(bevent->x >= exchBtn->core.x &&
4142 bevent->x <= exchBtn->core.x + exchBtn->core.width &&
4143 bevent->y >= exchBtn->core.y +
4144 X->modeline->core.height + X->textForm->core.height &&
4145 bevent->y <= exchBtn->core.y + exchBtn->core.height +
4146 X->modeline->core.height + X->textForm->core.height)
4148 menu_handler(widget, (XtPointer)M_EXCH, event, continue_to_dispatch);
4152 XmMenuPosition(X->popupMenu, (XButtonPressedEvent *) event) ;
4153 XtManageChild(X->popupMenu) ;
4159 set_option_menu(type, base)
4165 if(type == BASEITEM)
4166 XtSetArg(args[0], XmNmenuHistory, X->baseWidgArry[base]);
4167 else if(type == NUMITEM)
4168 XtSetArg(args[0], XmNmenuHistory, X->numWidgArry[base]);
4170 XtSetArg(args[0], XmNmenuHistory, X->ttypeWidgArry[base]);
4171 XtSetValues( X->modevals[type], args, 1);
4175 map_popup(widget, client_data, call_data)
4177 XtPointer client_data, call_data ;
4179 XmAnyCallbackStruct * callback;
4181 XKeyPressedEvent *key_event ;
4183 callback = (XmAnyCallbackStruct *) call_data;
4184 event = (XEvent *) callback->event;
4185 key_event = (XKeyPressedEvent *) event ;
4187 if(event->type != KeyRelease)
4190 if (v->event_type == F4_PRESS)
4191 XmMenuPosition(widget, (XButtonPressedEvent *) event) ;
4196 save_state(widget, client_data, call_data)
4198 XtPointer client_data ;
4199 XtPointer call_data ;
4201 char *full_path = NULL;
4202 char *file_name = NULL;
4204 char *sessionFileName;
4206 char **restart_argv = NULL;
4207 static char **start_argv = NULL;
4209 int i, restart_argc;
4210 static int start_argc = 0;
4212 Boolean status = False;
4213 static Boolean first = True;
4215 status = DtSessionSavePath(widget, &full_path, &file_name);
4218 sessionFileName = file_name;
4221 XtFree( (char *)full_path);
4222 full_path = (char *) XtMalloc (sizeof (char) * MAX_PATH);
4223 sprintf( full_path, "%s/%s", dt_path, DTCALC_CLASS_NAME);
4224 sessionFileName = full_path;
4227 SaveSession(full_path, file_name);
4229 /* --------------------------------------------------------------- */
4230 /* Original commandline arguments were saved on the top window */
4231 /* They get reset here, take original and append them to restart */
4232 /* --------------------------------------------------------------- */
4237 XGetCommand(X->dpy, XtWindow(X->kframe), &start_argv, &start_argc);
4240 /* Generate the restart command and add it as the property value */
4242 restart_argc = start_argc + 3;
4243 restart_argv = (char **) XtMalloc(restart_argc * sizeof(char *));
4245 if (restart_argv == NULL)
4248 restart_argv[0] = XtNewString(v->progname);
4250 for ( i = 1 ; (i < start_argc && start_argv != NULL) ; i++ )
4252 restart_argv[i] = XtNewString(start_argv[i]);
4255 restart_argv[i] = XtNewString("-session"); i++;
4256 restart_argv[i] = XtNewString(sessionFileName); i++;
4258 XSetCommand(X->dpy, XtWindow(X->kframe), restart_argv, i);
4259 XSync(X->dpy, False);
4261 for ( i = 0 ; i < restart_argc -1 ; i++ )
4262 XtFree ((char *) restart_argv[i]);
4264 XtFree ((char *) full_path);
4265 XtFree ((char *) file_name);
4271 SaveSession( path, file_name )
4275 char workspaceNumber[5];
4277 Atom * ws_presence = NULL;
4278 char * workspace_name;
4279 unsigned long num_workspaces = 0;
4282 unsigned long nitems;
4283 unsigned long leftover;
4284 WM_STATE * wm_state;
4288 Dimension width, height;
4297 XmVendorShellExtObject vendorExt;
4298 XmWidgetExtData extData;
4303 /* Create the session file */
4305 if ((fd = creat (path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
4307 tmpStr = GETMESSAGE(2, 34, "Could not open the session file.");
4308 msg = XtNewString(tmpStr);
4309 _DtSimpleError (v->appname, DtError, NULL, msg);
4315 /* Getting the WM_STATE property to see if iconified or not */
4316 XGetWindowProperty (X->dpy, XtWindow (X->kframe),
4317 wm_state_atom, 0L, (long) BUFSIZ, False,
4318 wm_state_atom, &actual_type, &actual_format,
4319 &nitems, &leftover, (unsigned char **) &wm_state);
4321 /* Write out if iconified our not */
4322 if (wm_state->state == IconicState)
4323 put_resource(R_ICON, set_bool(True)) ;
4325 put_resource(R_ICON, set_bool(False)) ;
4327 /* does it have a menubar or not */
4328 if ( application_args.menuBar )
4329 put_resource(R_MENUBAR, set_bool(True)) ;
4331 put_resource(R_MENUBAR, set_bool(False)) ;
4333 /* is keys set to on/off */
4335 put_resource(R_KEYS, set_bool(True)) ;
4337 put_resource(R_KEYS, set_bool(False)) ;
4339 /* Get the workspaces for this dt by accessing the property. */
4341 if (DtWsmGetWorkspacesOccupied (X->dpy, XtWindow (X->kframe),
4342 &ws_presence, &num_workspaces) == Success)
4346 string = (char *)XtMalloc(num_workspaces * 40);
4347 for (j = 0; j < num_workspaces; j++)
4349 workspace_name = XGetAtomName (X->dpy, ws_presence[j]);
4351 strcpy(string, workspace_name);
4353 strcat(string, workspace_name);
4354 if(j + 1 != num_workspaces)
4355 strcat(string, " ");
4356 XtFree ((char *) workspace_name);
4358 put_resource(R_WORKSPACE, string) ;
4360 XFree((char *)ws_presence);
4361 XtFree((char *)string);
4366 XtSetArg(args[0], XmNwidth, &width);
4367 XtSetArg(args[1], XmNheight, &height);
4368 XtGetValues(X->kframe, args, 2);
4370 XTranslateCoordinates(XtDisplay(X->kframe),
4371 XtWindow(X->kframe),
4372 RootWindowOfScreen(XtScreen(X->kframe)),
4378 /* Modify x & y to take into account window mgr frames */
4379 extData=_XmGetWidgetExtData(X->kframe, XmSHELL_EXTENSION);
4380 vendorExt = (XmVendorShellExtObject)extData->widget;
4381 x -= vendorExt->vendor.xOffset;
4382 y -= vendorExt->vendor.yOffset;
4384 sprintf(tempStr, "%d", width);
4385 put_resource(R_WIDTH, tempStr) ;
4386 sprintf(tempStr, "%d", height);
4387 put_resource(R_HEIGHT, tempStr) ;
4388 sprintf(tempStr, "%d", x);
4389 put_resource(R_X, tempStr) ;
4390 sprintf(tempStr, "%d", y);
4391 put_resource(R_Y, tempStr) ;
4393 write_resources(path);
4399 Boolean status=False;
4402 char temp[MAXLINE] ;
4403 char * full_path = NULL;
4405 int boolval, i, intval ;
4407 int MPtemp[MP_SIZE];
4409 status = DtSessionRestorePath(X->kframe, &full_path,
4410 application_args.session);
4414 path = XtNewString(full_path);
4416 db = XrmGetFileDatabase(path) ;
4417 XrmMergeDatabases(db, &(X->rDB)) ;
4419 if (get_int_resource(R_ACCURACY, &intval))
4421 v->accuracy = intval ;
4422 if (v->accuracy < 0 || v->accuracy > 9)
4424 msg = (char *) XtMalloc(strlen( opts[(int) O_ACCRANGE]) + 3);
4425 sprintf(msg, "%s", opts[(int) O_ACCRANGE]);
4426 _DtSimpleError (v->appname, DtWarning, NULL, msg);
4432 if ((full_path = get_resource(R_BASE)) != NULL)
4434 for (i = 0; i < MAXBASES; i++)
4435 if (EQUAL(full_path, base_str[i])) break ;
4439 msg = (char *) XtMalloc(strlen( opts[(int) O_BASE]) + 3);
4440 sprintf(msg, "%s", opts[(int) O_BASE]);
4441 _DtSimpleError (v->appname, DtWarning, NULL, msg);
4446 v->base = (enum base_type) i ;
4450 if (get_str_resource(R_DISPLAY, str))
4452 for (i = 0; i < MAXDISPMODES; i++)
4453 if (EQUAL(str, dtype_str[i])) break ;
4455 if (i == MAXDISPMODES)
4457 msg = (char *) XtMalloc(strlen( opts[(int) O_DISPLAY]) +
4459 sprintf(msg, opts[(int) O_DISPLAY], str);
4460 _DtSimpleError (v->appname, DtWarning, NULL, msg);
4463 else v->dtype = (enum num_type) i ;
4466 if (get_str_resource(R_MODE, str))
4468 for (i = 0; i < MAXMODES; i++)
4469 if (EQUAL(str, mode_str[i])) break ;
4473 msg = (char *)XtMalloc(strlen( opts[(int) O_MODE]) + strlen(str) + 3);
4474 sprintf(msg, opts[(int) O_MODE], str);
4475 _DtSimpleError (v->appname, DtWarning, NULL, msg);
4478 else v->modetype = (enum mode_type) i ;
4481 if (get_str_resource(R_TRIG, str))
4483 for (i = 0; i < MAXTRIGMODES; i++)
4484 if (EQUAL(str, ttype_str[i])) break ;
4486 if (i == MAXTRIGMODES)
4488 msg = (char *)XtMalloc(strlen( opts[(int) O_TRIG]) + strlen(str) + 3);
4489 sprintf(msg, opts[(int) O_TRIG], str);
4490 _DtSimpleError (v->appname, DtWarning, NULL, msg);
4493 else v->ttype = (enum trig_type) i ;
4496 if (get_bool_resource(R_REGS, &boolval)) v->rstate = boolval ;
4498 /* Get the iconify state */
4499 if (get_bool_resource(R_ICON, &boolval)) v->iconic = boolval;
4501 /* Get the menubar state */
4502 if (get_bool_resource(R_MENUBAR, &boolval))
4503 application_args.menuBar = boolval;
4505 /* Get the keys state */
4506 if (get_bool_resource(R_KEYS, &boolval)) v->tstate = boolval;
4508 /* Get the proper workspaces if needed */
4509 if ((full_path = get_resource(R_WORKSPACE)) != NULL)
4510 v->workspaces = XtNewString(full_path);
4512 /* Get the x, y width, and height */
4513 if (get_int_resource(R_WIDTH, &intval))
4515 if (get_int_resource(R_HEIGHT, &intval))
4516 v->height = intval ;
4517 if (get_int_resource(R_X, &intval))
4519 if (get_int_resource(R_Y, &intval))
4522 if (get_str_resource(R_DISPLAYED, str))
4524 STRCPY(v->display, str);
4525 MPstr_to_num(str, v->base, v->MPdisp_val) ;
4528 if (get_str_resource(R_REG0, str))
4529 MPstr_to_num(str, v->base, v->MPmvals[0]) ;
4530 if (get_str_resource(R_REG1, str))
4531 MPstr_to_num(str, v->base, v->MPmvals[1]) ;
4532 if (get_str_resource(R_REG2, str))
4533 MPstr_to_num(str, v->base, v->MPmvals[2]) ;
4534 if (get_str_resource(R_REG3, str))
4535 MPstr_to_num(str, v->base, v->MPmvals[3]) ;
4536 if (get_str_resource(R_REG4, str))
4537 MPstr_to_num(str, v->base, v->MPmvals[4]) ;
4538 if (get_str_resource(R_REG5, str))
4539 MPstr_to_num(str, v->base, v->MPmvals[5]) ;
4540 if (get_str_resource(R_REG6, str))
4541 MPstr_to_num(str, v->base, v->MPmvals[6]) ;
4542 if (get_str_resource(R_REG7, str))
4543 MPstr_to_num(str, v->base, v->MPmvals[7]) ;
4544 if (get_str_resource(R_REG8, str))
4545 MPstr_to_num(str, v->base, v->MPmvals[8]) ;
4546 if (get_str_resource(R_REG9, str))
4547 MPstr_to_num(str, v->base, v->MPmvals[9]) ;
4549 if (get_str_resource(R_FREG0, str))
4551 MPstr_to_num(str, v->base, MPtemp) ;
4552 mpcmd(MPtemp, &(v->MPfvals[0]));
4554 if (get_str_resource(R_FREG1, str))
4556 MPstr_to_num(str, v->base, MPtemp) ;
4557 mpcmd(MPtemp, &(v->MPfvals[1]));
4559 if (get_str_resource(R_FREG2, str))
4561 MPstr_to_num(str, v->base, MPtemp) ;
4562 mpcmd(MPtemp, &(v->MPfvals[2]));
4564 if (get_str_resource(R_FREG3, str))
4566 MPstr_to_num(str, v->base, MPtemp) ;
4567 mpcmd(MPtemp, &(v->MPfvals[3]));
4569 if (get_str_resource(R_FREG4, str))
4571 MPstr_to_num(str, v->base, MPtemp) ;
4572 mpcmd(MPtemp, &(v->MPfvals[4]));
4574 if (get_str_resource(R_FREG5, str))
4576 MPstr_to_num(str, v->base, MPtemp) ;
4577 mpcmd(MPtemp, &(v->MPfvals[5]));
4586 Atom * workspace_atoms = NULL;
4587 int num_workspaces=0;
4591 if(v->width != 0 && v->height != 0)
4593 WMShellWidget wm = (WMShellWidget)(X->kframe);
4594 wm->wm.size_hints.flags |= USPosition;
4595 XtSetArg (args[0], XmNx, (Position)v->x);
4596 XtSetArg (args[1], XmNy, (Position)v->y);
4597 XtSetArg (args[2], XmNwidth, (Dimension)v->width);
4598 XtSetArg (args[3], XmNheight, (Dimension)v->height);
4599 XtSetValues (X->kframe, args, 4);
4604 /* add the iconify hint to the current shell */
4605 XtSetArg(args[0], XmNinitialState, IconicState);
4606 XtSetValues(X->kframe, args, 1);
4610 /* Remove the iconify hint from the current shell */
4611 wmhints = XGetWMHints(X->dpy, XtWindow(X->kframe));
4612 wmhints->flags |= IconWindowHint;
4613 wmhints->initial_state = NormalState;
4614 XSetWMHints(X->dpy, XtWindow(X->kframe), wmhints);
4622 ptr = DtStrchr (v->workspaces, ' ');
4624 if (ptr != NULL) *ptr = '\0';
4626 workspace_atoms = (Atom *) XtRealloc ((char *)workspace_atoms,
4627 sizeof (Atom) * (num_workspaces + 1));
4629 workspace_atoms[num_workspaces] =
4630 XmInternAtom (X->dpy, v->workspaces, True);
4637 v->workspaces = ptr + 1;
4639 } while (ptr != NULL);
4641 DtWsmSetWorkspacesOccupied (X->dpy, XtWindow (X->kframe),
4642 workspace_atoms, num_workspaces);
4644 XtFree ((char *) workspace_atoms);
4649 TimerEvent( client_data, id )
4650 XtPointer client_data;
4655 ignore_event = False;
4659 XtSetArg (args[0], XmNdefaultButton, X->CFpi_butOK);
4660 XtSetValues (X->CFframe, args, 1);
4665 #ifdef HP_EXTENSIONS
4669 XHPDeviceList *list, *slist;
4670 int ndevices = 0, i, kbd = 0;
4672 slist = XHPListInputDevices(X->dpy, &ndevices);
4673 for (i = 0, list = slist; i < ndevices; i++, list++)
4675 if (list->type != KEYBOARD && strcmp(list->name, PS2_DIN_NAME))
4677 if (list->detailed_id & (HP_ITF_KBD | HP_HIL) == (HP_ITF_KBD | HP_HIL))
4682 else if (list->detailed_id & (PC101_KBD|HP_HIL) == (PC101_KBD|HP_HIL))
4684 kbd = HIL_PC101_KBD;
4687 else if (list->detailed_id & (PC101_KBD|SERIAL) == (PC101_KBD|SERIAL))
4689 kbd = SERIAL_PC101_KBD;
4695 if (strcmp(list->name, PS2_DIN_NAME) == 0)
4697 kbd = SERIAL_PC101_KBD;
4700 else if (list->hil_id >= FIRST_HIL_KBD &&
4701 list->hil_id <= LAST_HIL_KBD)
4703 if (list->io_byte & LED_BITS)
4705 kbd = HIL_PC101_KBD;
4716 XHPFreeDeviceList (slist);
4722 _DtcalcStripSpaces(file)
4730 for (i = 0; i < strlen(file); i++)
4732 if (isspace(file[i]))
4734 for(j = i; file[j] != '\0'; j++)
4735 file[j] = file[j + 1];