1f80a6dcdSmrg/* 2f80a6dcdSmrg 3f80a6dcdSmrgCopyright (c) 1991 X Consortium 4f80a6dcdSmrg 5f80a6dcdSmrgPermission is hereby granted, free of charge, to any person obtaining 6f80a6dcdSmrga copy of this software and associated documentation files (the 7f80a6dcdSmrg"Software"), to deal in the Software without restriction, including 8f80a6dcdSmrgwithout limitation the rights to use, copy, modify, merge, publish, 9f80a6dcdSmrgdistribute, sublicense, and/or sell copies of the Software, and to 10f80a6dcdSmrgpermit persons to whom the Software is furnished to do so, subject to 11f80a6dcdSmrgthe following conditions: 12f80a6dcdSmrg 13f80a6dcdSmrgThe above copyright notice and this permission notice shall be included 14f80a6dcdSmrgin all copies or substantial portions of the Software. 15f80a6dcdSmrg 16f80a6dcdSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17f80a6dcdSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18f80a6dcdSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19f80a6dcdSmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 20f80a6dcdSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21f80a6dcdSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22f80a6dcdSmrgOTHER DEALINGS IN THE SOFTWARE. 23f80a6dcdSmrg 24f80a6dcdSmrgExcept as contained in this notice, the name of the X Consortium shall 25f80a6dcdSmrgnot be used in advertising or otherwise to promote the sale, use or 26f80a6dcdSmrgother dealings in this Software without prior written authorization 27f80a6dcdSmrgfrom the X Consortium. 28f80a6dcdSmrg 29f80a6dcdSmrg*/ 30f80a6dcdSmrg/* 31f80a6dcdSmrg * xditview -- 32f80a6dcdSmrg * 33f80a6dcdSmrg * Display ditroff output in an X window 34f80a6dcdSmrg */ 35f80a6dcdSmrg 3600994698Smrg#ifdef HAVE_CONFIG_H 3700994698Smrg# include "config.h" 3800994698Smrg#endif 3900994698Smrg 40f80a6dcdSmrg#include <X11/Intrinsic.h> 41f80a6dcdSmrg#include <X11/StringDefs.h> 42f80a6dcdSmrg#include <X11/Xatom.h> 43f80a6dcdSmrg#include <X11/Shell.h> 448c7c3c7eSmrg#include <X11/Xos.h> 45f80a6dcdSmrg#include <X11/Xaw/Paned.h> 46f80a6dcdSmrg#include <X11/Xaw/Panner.h> 47f80a6dcdSmrg#include <X11/Xaw/Porthole.h> 48f80a6dcdSmrg#include <X11/Xaw/Viewport.h> 49f80a6dcdSmrg#include <X11/Xaw/Box.h> 50f80a6dcdSmrg#include <X11/Xaw/Command.h> 51f80a6dcdSmrg#include <X11/Xaw/Dialog.h> 52f80a6dcdSmrg#include <X11/Xaw/Label.h> 53f80a6dcdSmrg#include <X11/Xaw/MenuButton.h> 54f80a6dcdSmrg#include <X11/Xaw/SimpleMenu.h> 55f80a6dcdSmrg#include <X11/Xaw/SmeBSB.h> 56f80a6dcdSmrg#include <X11/Xaw/AsciiText.h> 57f80a6dcdSmrg 58f80a6dcdSmrg#include "Dvi.h" 59f80a6dcdSmrg 60f80a6dcdSmrg#include "xdit.bm" 61f80a6dcdSmrg#include "xdit_mask.bm" 62f80a6dcdSmrg#include <stdio.h> 63f80a6dcdSmrg#include <stdlib.h> 6409bee7c9Smrg#include <sys/stat.h> 65f80a6dcdSmrg 66f80a6dcdSmrg/* Command line options table. Only resources are entered here...there is a 67f80a6dcdSmrg pass over the remaining options after XtParseCommand is let loose. */ 68f80a6dcdSmrg 69f80a6dcdSmrgstatic XrmOptionDescRec options[] = { 7000994698Smrg {"-page", "*dvi.pageNumber", XrmoptionSepArg, NULL}, 7100994698Smrg {"-backingStore", "*dvi.backingStore", XrmoptionSepArg, NULL}, 7200994698Smrg {"-noPolyText", "*dvi.noPolyText", XrmoptionNoArg, "TRUE"}, 7300994698Smrg {"-resolution", "*dvi.screenResolution", XrmoptionSepArg, NULL}, 74f80a6dcdSmrg}; 75f80a6dcdSmrg 7600994698Smrgstatic char current_file_name[1024]; 7700994698Smrgstatic FILE *current_file; 78f80a6dcdSmrg 79c166fba9Smrgstatic void MakePrompt(Widget, const char *, void (*)(char *), char *); 80f80a6dcdSmrg 81f80a6dcdSmrg/* 82f80a6dcdSmrg * Report the syntax for calling xditview. 83f80a6dcdSmrg */ 84f80a6dcdSmrg 85f80a6dcdSmrgstatic void 8600994698SmrgSyntax(const char *call, int exitval) 87f80a6dcdSmrg{ 8800994698Smrg (void) printf("Usage: %s [-fg <color>] [-bg <color>]\n%s\n", call, 8900994698Smrg " [-bd <color>] [-bw <pixels>] [-help] [-version]\n" 9000994698Smrg " [-display displayname] [-geometry geom]\n" 9100994698Smrg " [-page <page-number>] [-backing <backing-store>]\n" 9200994698Smrg " [-resolution <screen-resolution>]\n"); 9300994698Smrg exit(exitval); 94f80a6dcdSmrg} 95f80a6dcdSmrg 9600994698Smrgstatic void NewResolution(char *resString); 9700994698Smrgstatic void NewFile(char *name); 9800994698Smrgstatic void DisplayPageNumber(void); 9900994698Smrgstatic void VisitFile(char *name, Boolean resetPage); 10000994698Smrg 10100994698Smrgstatic Widget toplevel, paned, porthole, dvi; 10200994698Smrgstatic Widget popupMenu; 10300994698Smrgstatic Widget menuBar; 10400994698Smrgstatic Widget fileMenuButton, fileMenu; 10500994698Smrgstatic Widget pageNumber; 10600994698Smrg 10700994698Smrgstatic void NextPage(Widget entry, XtPointer name, XtPointer data); 10800994698Smrgstatic void PreviousPage(Widget entry, XtPointer name, XtPointer data); 10900994698Smrgstatic void SetResolution(Widget entry, XtPointer name, XtPointer data); 11000994698Smrgstatic void OpenFile(Widget entry, XtPointer name, XtPointer data); 11100994698Smrgstatic void RevisitFile(Widget entry, XtPointer name, XtPointer data); 11200994698Smrgstatic void Quit(Widget entry, XtPointer closure, XtPointer data); 113f80a6dcdSmrg 114f80a6dcdSmrgstruct menuEntry { 11500994698Smrg char *name; 11600994698Smrg void (*function)(Widget entry, XtPointer name, XtPointer data); 117f80a6dcdSmrg}; 118f80a6dcdSmrg 119f80a6dcdSmrgstatic struct menuEntry popupMenuEntries[] = { 12000994698Smrg {"nextPage", NextPage}, 12100994698Smrg {"previousPage", PreviousPage}, 12200994698Smrg {"setResolution", SetResolution}, 12300994698Smrg {"openFile", OpenFile}, 12400994698Smrg {"revisitFile", RevisitFile}, 12500994698Smrg {"quit", Quit} 126f80a6dcdSmrg}; 127f80a6dcdSmrg 128f80a6dcdSmrgstatic struct menuEntry fileMenuEntries[] = { 12900994698Smrg {"openFile", OpenFile}, 13000994698Smrg {"revisitFile", RevisitFile}, 13100994698Smrg {"setResolution", SetResolution}, 13200994698Smrg {"quit", Quit} 133f80a6dcdSmrg}; 134f80a6dcdSmrg 13500994698Smrgstatic void NextPageAction(Widget, XEvent *, String *, Cardinal *); 13600994698Smrgstatic void PreviousPageAction(Widget, XEvent *, String *, Cardinal *); 13700994698Smrgstatic void SetResolutionAction(Widget, XEvent *, String *, Cardinal *); 13800994698Smrgstatic void OpenFileAction(Widget, XEvent *, String *, Cardinal *); 13900994698Smrgstatic void RevisitFileAction(Widget, XEvent *, String *, Cardinal *); 14000994698Smrgstatic void QuitAction(Widget, XEvent *, String *, Cardinal *); 14100994698Smrgstatic void AcceptAction(Widget, XEvent *, String *, Cardinal *); 14200994698Smrgstatic void CancelAction(Widget, XEvent *, String *, Cardinal *); 14300994698Smrgstatic void UpdatePageNumber(Widget, XEvent *, String *, Cardinal *); 14400994698Smrgstatic void Noop(Widget, XEvent *, String *, Cardinal *); 145f80a6dcdSmrg 14665912f00Smrgstatic XtActionsRec xditview_actions[] = { 14700994698Smrg {"NextPage", NextPageAction}, 14800994698Smrg {"PreviousPage", PreviousPageAction}, 14900994698Smrg {"SetResolution", SetResolutionAction}, 15000994698Smrg {"OpenFile", OpenFileAction}, 15100994698Smrg {"Quit", QuitAction}, 15200994698Smrg {"Accept", AcceptAction}, 15300994698Smrg {"Cancel", CancelAction}, 15400994698Smrg {"SetPageNumber", UpdatePageNumber}, 15500994698Smrg {"Noop", Noop} 156f80a6dcdSmrg}; 157f80a6dcdSmrg 158f80a6dcdSmrgstatic Atom wm_delete_window; 159f80a6dcdSmrg 160f80a6dcdSmrg 161f80a6dcdSmrgint 162f80a6dcdSmrgmain(int argc, char **argv) 163f80a6dcdSmrg{ 16400994698Smrg char * file_name = NULL; 165f80a6dcdSmrg XtAppContext xtcontext; 16600994698Smrg Arg topLevelArgs[2]; 167f80a6dcdSmrg 168f80a6dcdSmrg XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); 169f80a6dcdSmrg 17000994698Smrg /* Handle args that don't require opening a display */ 17100994698Smrg for (int n = 1; n < argc; n++) { 17200994698Smrg const char *argn = argv[n]; 17300994698Smrg /* accept single or double dash for -help & -version */ 17400994698Smrg if (argn[0] == '-' && argn[1] == '-') { 17500994698Smrg argn++; 17600994698Smrg } 17700994698Smrg if (strcmp(argn, "-help") == 0) { 17800994698Smrg Syntax(argv[0], 0); 17900994698Smrg } 18000994698Smrg if (strcmp(argn, "-version") == 0) { 18100994698Smrg puts(PACKAGE_STRING); 18200994698Smrg exit(0); 18300994698Smrg } 18400994698Smrg } 18500994698Smrg 186f80a6dcdSmrg toplevel = XtAppInitialize(&xtcontext, "Xditview", 18700994698Smrg options, XtNumber(options), 18800994698Smrg &argc, argv, NULL, NULL, 0); 18900994698Smrg if (argc > 2) { 19000994698Smrg fputs("Unknown argument(s):", stderr); 19100994698Smrg for (int n = 1; n < argc; n++) { 19200994698Smrg if ((n < (argc -1)) || (argv[n][0] == '-')) { 19300994698Smrg fprintf(stderr, " %s", argv[n]); 19400994698Smrg } 19500994698Smrg } 19600994698Smrg fputs("\n\n", stderr); 19700994698Smrg Syntax(argv[0], 1); 19800994698Smrg } 199f80a6dcdSmrg 20000994698Smrg XtAppAddActions(xtcontext, xditview_actions, XtNumber(xditview_actions)); 201f80a6dcdSmrg XtOverrideTranslations 20200994698Smrg (toplevel, XtParseTranslationTable("<Message>WM_PROTOCOLS: Quit()")); 20300994698Smrg 20400994698Smrg XtSetArg(topLevelArgs[0], XtNiconPixmap, 20500994698Smrg XCreateBitmapFromData(XtDisplay(toplevel), 20600994698Smrg XtScreen(toplevel)->root, 20700994698Smrg (char *) xdit_bits, 20800994698Smrg xdit_width, xdit_height)); 20900994698Smrg 21000994698Smrg XtSetArg(topLevelArgs[1], XtNiconMask, 21100994698Smrg XCreateBitmapFromData(XtDisplay(toplevel), 21200994698Smrg XtScreen(toplevel)->root, 21300994698Smrg (char *) xdit_mask_bits, 21400994698Smrg xdit_mask_width, xdit_mask_height)); 21500994698Smrg XtSetValues(toplevel, topLevelArgs, 2); 216f80a6dcdSmrg if (argc > 1) 21700994698Smrg file_name = argv[1]; 218f80a6dcdSmrg 219f80a6dcdSmrg /* 220f80a6dcdSmrg * create the popup menu and insert the entries 221f80a6dcdSmrg */ 22200994698Smrg popupMenu = XtCreatePopupShell("popupMenu", simpleMenuWidgetClass, toplevel, 22300994698Smrg NULL, 0); 22400994698Smrg for (Cardinal i = 0; i < XtNumber(popupMenuEntries); i++) { 22500994698Smrg Widget entry = XtCreateManagedWidget(popupMenuEntries[i].name, 22600994698Smrg smeBSBObjectClass, popupMenu, 22700994698Smrg NULL, (Cardinal) 0); 22800994698Smrg XtAddCallback(entry, XtNcallback, popupMenuEntries[i].function, NULL); 229f80a6dcdSmrg } 230f80a6dcdSmrg 231f80a6dcdSmrg paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, 23200994698Smrg NULL, (Cardinal) 0); 23300994698Smrg menuBar = XtCreateManagedWidget("menuBar", boxWidgetClass, paned, NULL, 0); 23400994698Smrg 23500994698Smrg fileMenuButton = 23600994698Smrg XtCreateManagedWidget("fileMenuButton", menuButtonWidgetClass, menuBar, 23700994698Smrg NULL, (Cardinal) 0); 23800994698Smrg fileMenu = 23900994698Smrg XtCreatePopupShell("fileMenu", simpleMenuWidgetClass, fileMenuButton, 24000994698Smrg NULL, (Cardinal) 0); 24100994698Smrg for (Cardinal i = 0; i < XtNumber(fileMenuEntries); i++) { 24200994698Smrg Widget entry = XtCreateManagedWidget(fileMenuEntries[i].name, 24300994698Smrg smeBSBObjectClass, fileMenu, 24400994698Smrg NULL, (Cardinal) 0); 24500994698Smrg XtAddCallback(entry, XtNcallback, fileMenuEntries[i].function, NULL); 246f80a6dcdSmrg } 247f80a6dcdSmrg 24800994698Smrg (void) XtCreateManagedWidget("prevButton", commandWidgetClass, 24900994698Smrg menuBar, NULL, (Cardinal) 0); 250f80a6dcdSmrg 251f80a6dcdSmrg pageNumber = XtCreateManagedWidget("pageNumber", asciiTextWidgetClass, 25200994698Smrg menuBar, NULL, (Cardinal) 0); 25300994698Smrg 25400994698Smrg (void) XtCreateManagedWidget("nextButton", commandWidgetClass, 25500994698Smrg menuBar, NULL, (Cardinal) 0); 25600994698Smrg 25700994698Smrg porthole = XtCreateManagedWidget("viewport", viewportWidgetClass, 25800994698Smrg paned, NULL, 0); 25900994698Smrg dvi = XtCreateManagedWidget("dvi", dviWidgetClass, porthole, NULL, 0); 260f80a6dcdSmrg if (file_name) 26100994698Smrg VisitFile(file_name, FALSE); 26200994698Smrg XtRealizeWidget(toplevel); 263f80a6dcdSmrg wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 26400994698Smrg False); 26500994698Smrg (void) XSetWMProtocols(XtDisplay(toplevel), XtWindow(toplevel), 26600994698Smrg &wm_delete_window, 1); 267f80a6dcdSmrg XtAppMainLoop(xtcontext); 268f80a6dcdSmrg 269f80a6dcdSmrg return 0; 270f80a6dcdSmrg} 271f80a6dcdSmrg 272f80a6dcdSmrgstatic void 27300994698SmrgDisplayPageNumber(void) 274f80a6dcdSmrg{ 27500994698Smrg Arg arg[2]; 27600994698Smrg int actual_number, last_page; 27700994698Smrg XawTextBlock text; 27800994698Smrg int length; 27900994698Smrg char value[128]; 28000994698Smrg char * cur; 28100994698Smrg 28200994698Smrg XtSetArg(arg[0], XtNpageNumber, &actual_number); 28300994698Smrg XtSetArg(arg[1], XtNlastPageNumber, &last_page); 28400994698Smrg XtGetValues(dvi, arg, 2); 285f80a6dcdSmrg if (actual_number == 0) 28600994698Smrg snprintf(value, sizeof(value), "<none>"); 287f80a6dcdSmrg else if (last_page > 0) 28800994698Smrg snprintf(value, sizeof(value), "%d of %d", actual_number, last_page); 289f80a6dcdSmrg else 29000994698Smrg snprintf(value, sizeof(value), "%d", actual_number); 291f80a6dcdSmrg text.firstPos = 0; 29200994698Smrg text.length = strlen(value); 293f80a6dcdSmrg text.ptr = value; 294f80a6dcdSmrg text.format = FMT8BIT; 29500994698Smrg XtSetArg(arg[0], XtNstring, &cur); 29600994698Smrg XtGetValues(XawTextGetSource(pageNumber), arg, 1); 29700994698Smrg length = strlen(cur); 29800994698Smrg XawTextReplace(pageNumber, 0, length, &text); 299f80a6dcdSmrg} 300f80a6dcdSmrg 301f80a6dcdSmrgstatic void 30200994698SmrgSetPageNumber(int number) 303f80a6dcdSmrg{ 30400994698Smrg Arg arg[1]; 305f80a6dcdSmrg 30600994698Smrg XtSetArg(arg[0], XtNpageNumber, number); 30700994698Smrg XtSetValues(dvi, arg, 1); 30800994698Smrg DisplayPageNumber(); 309f80a6dcdSmrg} 310f80a6dcdSmrg 311f80a6dcdSmrgstatic void 31200994698SmrgUpdatePageNumber(Widget w, XEvent *xev, String *s, Cardinal *c) 313f80a6dcdSmrg{ 31400994698Smrg char *string; 31500994698Smrg Arg arg[1]; 316f80a6dcdSmrg 31700994698Smrg XtSetArg(arg[0], XtNstring, &string); 31800994698Smrg XtGetValues(XawTextGetSource(pageNumber), arg, 1); 31900994698Smrg SetPageNumber(atoi(string)); 320f80a6dcdSmrg} 321f80a6dcdSmrg 322f80a6dcdSmrgstatic void 32365912f00SmrgNewResolution(char *resString) 324f80a6dcdSmrg{ 32500994698Smrg int res; 32600994698Smrg Arg arg[1]; 32700994698Smrg 32800994698Smrg res = atoi(resString); 329f80a6dcdSmrg if (res <= 0) 33000994698Smrg return; 33100994698Smrg XtSetArg(arg[0], XtNscreenResolution, res); 33200994698Smrg XtSetValues(dvi, arg, 1); 333f80a6dcdSmrg} 334f80a6dcdSmrg 335f80a6dcdSmrgstatic void 33600994698SmrgVisitFile(char *name, Boolean resetPage) 337f80a6dcdSmrg{ 33800994698Smrg Arg arg[3]; 33900994698Smrg char *n; 34000994698Smrg FILE *new_file; 341f80a6dcdSmrg Boolean seek = 0; 34200994698Smrg int i; 343f80a6dcdSmrg 344f80a6dcdSmrg if (current_file) { 34500994698Smrg if (!strcmp(current_file_name, "-")) 34600994698Smrg ; 34700994698Smrg else if (current_file_name[0] == '|') 34800994698Smrg pclose(current_file); 34900994698Smrg else 35000994698Smrg fclose(current_file); 351f80a6dcdSmrg } 35200994698Smrg if (!strcmp(name, "-")) 35300994698Smrg new_file = stdin; 354f80a6dcdSmrg else if (name[0] == '|') 35500994698Smrg new_file = popen(name + 1, "r"); 356f80a6dcdSmrg else { 35709bee7c9Smrg struct stat stbuf; 35809bee7c9Smrg 35900994698Smrg new_file = fopen(name, "r"); 36009bee7c9Smrg 36109bee7c9Smrg if (!new_file) { 36209bee7c9Smrg perror(name); 36309bee7c9Smrg return; 36409bee7c9Smrg } 36509bee7c9Smrg /* Make sure it is a regular file */ 36609bee7c9Smrg if (fstat(fileno(new_file), &stbuf) != 0) { 36709bee7c9Smrg perror(name); 3688c7c3c7eSmrg fclose(new_file); 36909bee7c9Smrg return; 37009bee7c9Smrg } 37100994698Smrg if (!S_ISREG(stbuf.st_mode)) { 37209bee7c9Smrg fprintf(stderr, "%s is not a regular file.\n", name); 3738c7c3c7eSmrg fclose(new_file); 37409bee7c9Smrg return; 37509bee7c9Smrg } 37609bee7c9Smrg 37700994698Smrg seek = 1; 378f80a6dcdSmrg } 379f80a6dcdSmrg if (!new_file) { 38000994698Smrg /* XXX display error message */ 38100994698Smrg return; 382f80a6dcdSmrg } 383f80a6dcdSmrg i = 0; 38400994698Smrg XtSetArg(arg[i], XtNfile, new_file); 38500994698Smrg i++; 38600994698Smrg XtSetArg(arg[i], XtNseek, seek); 38700994698Smrg i++; 388f80a6dcdSmrg if (resetPage) { 38900994698Smrg XtSetArg(arg[i], XtNpageNumber, 1); 39000994698Smrg i++; 391f80a6dcdSmrg } 39200994698Smrg XtSetValues(dvi, arg, i); 39300994698Smrg XtSetArg(arg[0], XtNtitle, name); 39400994698Smrg if (name[0] != '/' && (n = strrchr(name, '/'))) 39500994698Smrg n = n + 1; 396f80a6dcdSmrg else 39700994698Smrg n = name; 39800994698Smrg XtSetArg(arg[1], XtNiconName, n); 39900994698Smrg XtSetValues(toplevel, arg, 2); 40000994698Smrg strncpy(current_file_name, name, sizeof(current_file_name)); 40100994698Smrg current_file_name[sizeof(current_file_name) - 1] = '\0'; 402f80a6dcdSmrg current_file = new_file; 40300994698Smrg DisplayPageNumber(); 404f80a6dcdSmrg} 405f80a6dcdSmrg 406f80a6dcdSmrgstatic void 40700994698SmrgNewFile(char *name) 408f80a6dcdSmrg{ 40900994698Smrg VisitFile(name, TRUE); 410f80a6dcdSmrg} 411f80a6dcdSmrg 412f80a6dcdSmrgstatic char fileBuf[1024]; 413f80a6dcdSmrgstatic char resolutionBuf[1024]; 414f80a6dcdSmrg 415f80a6dcdSmrgstatic void 41600994698SmrgResetMenuEntry(Widget entry) 417f80a6dcdSmrg{ 41800994698Smrg Arg arg[1]; 419f80a6dcdSmrg 42000994698Smrg XtSetArg(arg[0], XtNpopupOnEntry, entry); 42100994698Smrg XtSetValues(XtParent(entry), arg, (Cardinal) 1); 422f80a6dcdSmrg} 423f80a6dcdSmrg 424f80a6dcdSmrg/*ARGSUSED*/ 425f80a6dcdSmrgstatic void 42600994698SmrgNextPage(Widget entry, XtPointer name, XtPointer data) 427f80a6dcdSmrg{ 428f80a6dcdSmrg NextPageAction(entry, NULL, NULL, NULL); 42900994698Smrg ResetMenuEntry(entry); 430f80a6dcdSmrg} 431f80a6dcdSmrg 432f80a6dcdSmrgstatic void 43300994698SmrgNextPageAction(Widget w, XEvent *xev, String *s, Cardinal *c) 434f80a6dcdSmrg{ 43500994698Smrg Arg args[1]; 43600994698Smrg int number; 437f80a6dcdSmrg 43800994698Smrg XtSetArg(args[0], XtNpageNumber, &number); 43900994698Smrg XtGetValues(dvi, args, 1); 44000994698Smrg SetPageNumber(number + 1); 441f80a6dcdSmrg} 442f80a6dcdSmrg 443f80a6dcdSmrg/*ARGSUSED*/ 444f80a6dcdSmrgstatic void 44500994698SmrgPreviousPage(Widget entry, XtPointer name, XtPointer data) 446f80a6dcdSmrg{ 44700994698Smrg PreviousPageAction(entry, NULL, NULL, NULL); 44800994698Smrg ResetMenuEntry(entry); 449f80a6dcdSmrg} 450f80a6dcdSmrg 451f80a6dcdSmrgstatic void 45200994698SmrgPreviousPageAction(Widget w, XEvent *xev, String *s, Cardinal *c) 453f80a6dcdSmrg{ 45400994698Smrg Arg args[1]; 45500994698Smrg int number; 456f80a6dcdSmrg 45700994698Smrg XtSetArg(args[0], XtNpageNumber, &number); 45800994698Smrg XtGetValues(dvi, args, 1); 45900994698Smrg SetPageNumber(number - 1); 460f80a6dcdSmrg} 461f80a6dcdSmrg 462f80a6dcdSmrg/*ARGSUSED*/ 463f80a6dcdSmrgstatic void 46400994698SmrgSetResolution(Widget entry, XtPointer name, XtPointer data) 465f80a6dcdSmrg{ 46600994698Smrg SetResolutionAction(entry, NULL, NULL, NULL); 46700994698Smrg ResetMenuEntry(entry); 468f80a6dcdSmrg} 469f80a6dcdSmrg 470f80a6dcdSmrgstatic void 47100994698SmrgSetResolutionAction(Widget w, XEvent *xev, String *s, Cardinal *c) 472f80a6dcdSmrg{ 47300994698Smrg Arg args[1]; 47400994698Smrg int cur; 475f80a6dcdSmrg 47600994698Smrg XtSetArg(args[0], XtNscreenResolution, &cur); 47700994698Smrg XtGetValues(dvi, args, 1); 47800994698Smrg snprintf(resolutionBuf, sizeof(resolutionBuf), "%d", cur); 47900994698Smrg MakePrompt(toplevel, "Screen resolution:", NewResolution, resolutionBuf); 480f80a6dcdSmrg} 481f80a6dcdSmrg 482f80a6dcdSmrg/*ARGSUSED*/ 483f80a6dcdSmrgstatic void 48400994698SmrgOpenFile(Widget entry, XtPointer name, XtPointer data) 485f80a6dcdSmrg{ 48600994698Smrg OpenFileAction(entry, NULL, NULL, NULL); 48700994698Smrg ResetMenuEntry(entry); 488f80a6dcdSmrg} 489f80a6dcdSmrg 490f80a6dcdSmrgstatic void 49100994698SmrgOpenFileAction(Widget w, XEvent *xev, String *s, Cardinal *c) 492f80a6dcdSmrg{ 49300994698Smrg if (current_file_name[0]) { 49400994698Smrg strncpy(fileBuf, current_file_name, sizeof(fileBuf)); 49500994698Smrg fileBuf[sizeof(fileBuf) - 1] = '\0'; 49600994698Smrg } 497f80a6dcdSmrg else 49800994698Smrg fileBuf[0] = '\0'; 49900994698Smrg MakePrompt(toplevel, "File to open:", NewFile, fileBuf); 500f80a6dcdSmrg} 501f80a6dcdSmrg 502f80a6dcdSmrg/*ARGSUSED*/ 503f80a6dcdSmrgstatic void 50400994698SmrgRevisitFile(Widget entry, XtPointer name, XtPointer data) 505f80a6dcdSmrg{ 50600994698Smrg RevisitFileAction(entry, NULL, NULL, NULL); 50700994698Smrg ResetMenuEntry(entry); 508f80a6dcdSmrg} 509f80a6dcdSmrg 510f80a6dcdSmrgstatic void 51100994698SmrgRevisitFileAction(Widget w, XEvent *xev, String *s, Cardinal *c) 512f80a6dcdSmrg{ 513f80a6dcdSmrg if (current_file_name[0]) 51400994698Smrg VisitFile(current_file_name, FALSE); 515f80a6dcdSmrg} 516f80a6dcdSmrg 517f80a6dcdSmrg/*ARGSUSED*/ 518f80a6dcdSmrgstatic void 51900994698SmrgQuit(Widget entry, XtPointer closure, XtPointer data) 520f80a6dcdSmrg{ 52100994698Smrg QuitAction(entry, NULL, NULL, NULL); 522f80a6dcdSmrg} 523f80a6dcdSmrg 524f80a6dcdSmrgstatic void 52500994698SmrgQuitAction(Widget w, XEvent *xev, String *s, Cardinal *c) 526f80a6dcdSmrg{ 52700994698Smrg exit(0); 528f80a6dcdSmrg} 529f80a6dcdSmrg 53065912f00Smrgstatic Widget promptShell, promptDialog; 53165912f00Smrgstatic void (*promptfunction)(char *); 532f80a6dcdSmrg 533f80a6dcdSmrg/* ARGSUSED */ 53400994698Smrgstatic void 53500994698SmrgCancelAction(Widget widget, XEvent *event, 53600994698Smrg String *params, Cardinal *num_params) 537f80a6dcdSmrg{ 538f80a6dcdSmrg if (promptShell) { 53900994698Smrg XtSetKeyboardFocus(toplevel, (Widget) None); 54000994698Smrg XtDestroyWidget(promptShell); 54100994698Smrg promptShell = (Widget) 0; 542f80a6dcdSmrg } 543f80a6dcdSmrg} 544f80a6dcdSmrg 545f80a6dcdSmrg/* ARGSUSED */ 54600994698Smrgstatic void 54700994698SmrgAcceptAction(Widget widget, XEvent *event, 54800994698Smrg String *params, Cardinal *num_params) 549f80a6dcdSmrg{ 55000994698Smrg (*promptfunction) (XawDialogGetValueString(promptDialog)); 55100994698Smrg CancelAction(widget, event, params, num_params); 552f80a6dcdSmrg} 553f80a6dcdSmrg 55400994698Smrgstatic void 55500994698SmrgNoop(Widget w, XEvent *xev, String *s, Cardinal *c) 556f80a6dcdSmrg{ 557f80a6dcdSmrg} 558f80a6dcdSmrg 559f80a6dcdSmrgstatic void 560c166fba9SmrgMakePrompt(Widget centerw, const char *prompt, void (*func)(char *), char *def) 561f80a6dcdSmrg{ 562f80a6dcdSmrg static Arg dialogArgs[] = { 56300994698Smrg {XtNlabel,(XtArgVal) 0}, 56400994698Smrg {XtNvalue,(XtArgVal) 0}, 565f80a6dcdSmrg }; 566f80a6dcdSmrg Arg centerArgs[2]; 56700994698Smrg Position source_x, source_y; 56800994698Smrg Position dest_x, dest_y; 569f80a6dcdSmrg Dimension center_width, center_height; 570f80a6dcdSmrg Dimension prompt_width, prompt_height; 57100994698Smrg Widget valueWidget; 57200994698Smrg 57300994698Smrg CancelAction((Widget) NULL, (XEvent *) 0, (String *) 0, (Cardinal *) 0); 57400994698Smrg promptShell = XtCreatePopupShell("promptShell", transientShellWidgetClass, 57500994698Smrg toplevel, NULL, (Cardinal) 0); 57600994698Smrg dialogArgs[0].value = (XtArgVal) prompt; 57700994698Smrg dialogArgs[1].value = (XtArgVal) def; 57800994698Smrg promptDialog = XtCreateManagedWidget("promptDialog", dialogWidgetClass, 57900994698Smrg promptShell, dialogArgs, 58000994698Smrg XtNumber(dialogArgs)); 581f80a6dcdSmrg XawDialogAddButton(promptDialog, "accept", NULL, NULL); 582f80a6dcdSmrg XawDialogAddButton(promptDialog, "cancel", NULL, NULL); 58300994698Smrg valueWidget = XtNameToWidget(promptDialog, "value"); 584f80a6dcdSmrg if (valueWidget) { 58500994698Smrg Arg valueArgs[1]; 58600994698Smrg 58700994698Smrg XtSetArg(valueArgs[0], XtNresizable, TRUE); 58800994698Smrg XtSetValues(valueWidget, valueArgs, 1); 58900994698Smrg /* 59000994698Smrg * as resizable isn't set until just above, the 59100994698Smrg * default value will be displayed incorrectly. 59200994698Smrg * rectify the situation by resetting the values 59300994698Smrg */ 59400994698Smrg XtSetValues(promptDialog, dialogArgs, XtNumber(dialogArgs)); 595f80a6dcdSmrg } 59600994698Smrg XtSetKeyboardFocus(promptDialog, valueWidget); 59700994698Smrg XtSetKeyboardFocus(toplevel, valueWidget); 59800994698Smrg XtRealizeWidget(promptShell); 599f80a6dcdSmrg /* 600f80a6dcdSmrg * place the widget in the center of the "parent" 601f80a6dcdSmrg */ 60200994698Smrg XtSetArg(centerArgs[0], XtNwidth, ¢er_width); 60300994698Smrg XtSetArg(centerArgs[1], XtNheight, ¢er_height); 60400994698Smrg XtGetValues(centerw, centerArgs, 2); 60500994698Smrg XtSetArg(centerArgs[0], XtNwidth, &prompt_width); 60600994698Smrg XtSetArg(centerArgs[1], XtNheight, &prompt_height); 60700994698Smrg XtGetValues(promptShell, centerArgs, 2); 60800994698Smrg source_x = (int) (center_width - prompt_width) / 2; 60900994698Smrg source_y = (int) (center_height - prompt_height) / 3; 61000994698Smrg XtTranslateCoords(centerw, source_x, source_y, &dest_x, &dest_y); 61100994698Smrg XtSetArg(centerArgs[0], XtNx, dest_x); 61200994698Smrg XtSetArg(centerArgs[1], XtNy, dest_y); 61300994698Smrg XtSetValues(promptShell, centerArgs, 2); 614f80a6dcdSmrg XtMapWidget(promptShell); 615f80a6dcdSmrg promptfunction = func; 616f80a6dcdSmrg} 617