/* NewViewport is responsible for filling in graph->viewport */ int X11_NewViewport(GRAPH *graph) { char fontname[513]; /* who knows . . . */ char *p, *q; Cursor cursor; XSetWindowAttributes w_attrs; XGCValues gcvalues; static Arg formargs[ ] = { { XtNleft, (XtArgVal) XtChainLeft }, { XtNresizable, (XtArgVal) TRUE } }; static Arg bboxargs[ ] = { { XtNfromHoriz, (XtArgVal) NULL }, { XtNbottom, (XtArgVal) XtChainTop }, { XtNtop, (XtArgVal) XtChainTop }, { XtNleft, (XtArgVal) XtChainRight }, { XtNright, (XtArgVal) XtChainRight } }; static Arg buttonargs[ ] = { { XtNlabel, (XtArgVal) NULL }, { XtNfromVert, (XtArgVal) NULL }, { XtNbottom, (XtArgVal) XtChainTop }, { XtNtop, (XtArgVal) XtChainTop }, { XtNleft, (XtArgVal) XtRubber }, { XtNright, (XtArgVal) XtRubber }, { XtNresizable, (XtArgVal) TRUE } }; static Arg viewargs[] = { { XtNresizable, (XtArgVal) TRUE }, { XtNwidth, (XtArgVal) 300 }, { XtNheight, (XtArgVal) 300 }, { XtNright, (XtArgVal) XtChainRight } }; int trys; graph->devdep = TMALLOC(X11devdep, 1); /* set up new shell */ DEVDEP(graph).shell = XtCreateApplicationShell ("shell", topLevelShellWidgetClass, NULL, 0); XtVaSetValues(DEVDEP(graph).shell, XtNtitle, graph->plotname, NULL); /* set up form widget */ DEVDEP(graph).form = XtCreateManagedWidget ("form", formWidgetClass, DEVDEP(graph).shell, formargs, XtNumber(formargs)); /* set up viewport */ DEVDEP(graph).view = XtCreateManagedWidget ("viewport", widgetClass, DEVDEP(graph).form, viewargs, XtNumber(viewargs)); XtAddEventHandler(DEVDEP(graph).view, ButtonPressMask, FALSE, handlebuttonev, graph); XtAddEventHandler(DEVDEP(graph).view, KeyPressMask, FALSE, handlekeypressed, graph); XtAddEventHandler(DEVDEP(graph).view, StructureNotifyMask, FALSE, resize, graph); XtAddEventHandler(DEVDEP(graph).view, ExposureMask, FALSE, redraw, graph); /* set up button box */ XtSetArg(bboxargs[1], XtNfromHoriz, DEVDEP(graph).view); DEVDEP(graph).buttonbox = XtCreateManagedWidget ("buttonbox", boxWidgetClass, DEVDEP(graph).form, bboxargs, XtNumber(bboxargs)); /* set up buttons */ XtSetArg(buttonargs[0], XtNlabel, "quit"); XtSetArg(bboxargs[1], XtNfromVert, NULL); DEVDEP(graph).buttons[0] = XtCreateManagedWidget ("quit", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1); XtAddCallback(DEVDEP(graph).buttons[0], XtNcallback, killwin, graph); XtSetArg(buttonargs[0], XtNlabel, "hardcopy"); XtSetArg(bboxargs[1], XtNfromVert, DEVDEP(graph).buttons[0]); DEVDEP(graph).buttons[1] = XtCreateManagedWidget ("hardcopy", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1); XtAddCallback(DEVDEP(graph).buttons[1], XtNcallback, hardcopy, graph); /* set up fonts */ if (!cp_getvar("font", CP_STRING, fontname)) (void) strcpy(fontname, DEF_FONT); for (p = fontname; *p && *p <= ' '; p++) ; if (p != fontname) { for (q = fontname; *p; *q++ = *p++) ; *q = 0; } trys = 1; while (!(DEVDEP(graph).font = XLoadQueryFont(display, fontname))) { sprintf(ErrorMessage, "can't open font %s", fontname); strcpy(fontname, "fixed"); if (trys > 1) { internalerror(ErrorMessage); RECOVERNEWVIEWPORT(); return (1); } trys += 1; } graph->fontwidth = DEVDEP(graph).font->max_bounds.rbearing - DEVDEP(graph).font->min_bounds.lbearing + 1; graph->fontheight = DEVDEP(graph).font->max_bounds.ascent + DEVDEP(graph).font->max_bounds.descent + 1; XtRealizeWidget(DEVDEP(graph).shell); DEVDEP(graph).window = XtWindow(DEVDEP(graph).view); DEVDEP(graph).isopen = 0; w_attrs.bit_gravity = ForgetGravity; XChangeWindowAttributes(display, DEVDEP(graph).window, CWBitGravity, &w_attrs); /* have to note font and set mask GCFont in XCreateGC, p.w.h. */ gcvalues.font = DEVDEP(graph).font->fid; gcvalues.line_width = MW_LINEWIDTH; gcvalues.cap_style = CapNotLast; gcvalues.function = GXcopy; DEVDEP(graph).gc = XCreateGC(display, DEVDEP(graph).window, GCFont | GCLineWidth | GCCapStyle | GCFunction, &gcvalues); /* should absolute.positions really be shell.pos? */ graph->absolute.xpos = DEVDEP(graph).view->core.x; graph->absolute.ypos = DEVDEP(graph).view->core.y; graph->absolute.width = DEVDEP(graph).view->core.width; graph->absolute.height = DEVDEP(graph).view->core.height; initlinestyles(); initcolors(graph); /* set up cursor */ cursor = XCreateFontCursor(display, XC_left_ptr); XDefineCursor(display, DEVDEP(graph).window, cursor); /* WM_DELETE_WINDOW protocol */ atom_wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False); atom_wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False); XtAddEventHandler(DEVDEP(graph).shell, NoEventMask, True, handle_wm_messages, graph); XSetWMProtocols(display, XtWindow(DEVDEP(graph).shell), &atom_wm_delete_window, 1); return (0); }
Boolean CreateHelp() { struct stat fileinfo; /* file information from fstat. */ FILE * help_file; /* The stream of the help file. */ char * help_page; /* The help text strored in memory. */ int help_width; /* The width of the help window. (default). */ Arg arglist[10]; /* The arglist */ Cardinal num_args; /* The number of arguments. */ Widget pane; /* The Vpane, that will contain the help info. */ static XtCallbackRec Callbacks[] = { { PopdownHelp, NULL }, { NULL, NULL }, }; if (help_widget != NULL) /* If we already have a help widget. then do not create one. */ return(TRUE); /* Open help_file and read it into memory. */ /* * Get file size and allocate a chunk of memory for the file to be * copied into. */ if( (help_file = fopen(help_file_name, "r")) == NULL ) { PrintWarning("Could not open help file, NO HELP WILL BE AVALIABLE."); return(FALSE); } if ( stat(help_file_name, &fileinfo) ) { PrintWarning("Failure in fstat, NO HELP WILL BE AVALIABLE."); return(FALSE); } /* leave space for the NULL */ help_page = (char *) malloc(fileinfo.st_size + 1); if (help_page == NULL) { PrintWarning( "Could not allocate memory for help file, NO HELP WILL BE AVALIABLE."); return(FALSE); } /* * Copy the file into memory. */ fread(help_page,sizeof(char),fileinfo.st_size,help_file); fclose(help_file); /* put NULL at end of buffer. */ *(help_page + fileinfo.st_size) = '\0'; /* * Help file now loaded in to memory. Create widgets do display it. */ num_args = 0; XtSetArg(arglist[num_args], XtNallowShellResize, TRUE); num_args++; help_widget = XtCreateApplicationShell("help", applicationShellWidgetClass, arglist, num_args); num_args = 0; help_width = DisplayWidth(XtDisplay(help_widget), DefaultScreen(XtDisplay(help_widget))); help_width /= 2; XtSetArg(arglist[num_args], XtNwidth, help_width); num_args++; #if XtSpecificationRelease < 4 pane = XtCreateWidget("Help_VPaned",vPanedWidgetClass,help_widget, arglist,num_args); #else pane = XtCreateWidget("Help_Paned",panedWidgetClass,help_widget, arglist,num_args); #endif num_args = 0; XtSetArg(arglist[num_args], XtNborderWidth, 0); num_args++; XtSetArg(arglist[num_args], XtNlabel, "Done With Help"); num_args++; XtSetArg(arglist[num_args], XtNcallback, Callbacks); num_args++; (void) XtCreateManagedWidget("Help_Quit",commandWidgetClass, pane, arglist, num_args); num_args = 0; XtSetArg(arglist[num_args], XtNborderWidth, 0); num_args++; XtSetArg(arglist[num_args], XtNstring, help_page); num_args++; #if XtSpecificationRelease < 4 XtSetArg(arglist[num_args], XtNtextOptions, scrollVertical); num_args++; #else XtSetArg(arglist[num_args],XtNscrollVertical,XawtextScrollAlways); num_args++; XtSetArg(arglist[num_args],XtNscrollHorizontal,XawtextScrollWhenNeeded); num_args++; XtSetArg(arglist[num_args],XtNuseStringInPlace, TRUE); num_args++; #endif /* make the text shown a square box. */ XtSetArg(arglist[num_args], XtNheight, help_width); num_args++; #if XtSpecificationRelease < 4 (void) XtCreateManagedWidget("Help_Text",asciiStringWidgetClass, pane, arglist, num_args); #else (void) XtCreateManagedWidget("Help_Text",asciiTextWidgetClass, pane, arglist, num_args); #endif XtManageChild(pane); XtRealizeWidget(help_widget); AddCursor(help_widget,help_cursor); return(TRUE); }