2
* Copyright 1991 Massachusetts Institute of Technology
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
* documentation for any purpose is hereby granted without fee, provided that
6
* the above copyright notice appear in all copies and that both that
7
* copyright notice and this permission notice appear in supporting
8
* documentation, and that the name of M.I.T. not be used in advertising or
9
* publicity pertaining to distribution of the software without specific,
10
* written prior permission. M.I.T. makes no representations about the
11
* suitability of this software for any purpose. It is provided "as is"
12
* without express or implied warranty.
14
* M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
16
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
* Display ditroff output in an X window
30
static char rcsid[] = "$XConsortium: xditview.c,v 1.17 89/12/10 17:05:08 rws Exp $";
34
#include <X11/Xatom.h>
37
#include <X11/Intrinsic.h>
38
#include <X11/StringDefs.h>
39
#include <X11/Shell.h>
40
#include <X11/Xaw/Paned.h>
41
#include <X11/Xaw/Viewport.h>
42
#include <X11/Xaw/Box.h>
43
#include <X11/Xaw/Command.h>
44
#include <X11/Xaw/Dialog.h>
45
#include <X11/Xaw/Label.h>
46
#include <X11/Xaw/SimpleMenu.h>
47
#include <X11/Xaw/SmeBSB.h>
54
#include "xdit_mask.bm"
60
static String fallback_resources[] = {
61
#include "GXditview-ad.h"
65
static struct app_resources {
70
#define offset(field) XtOffset(struct app_resources *, field)
72
/* Application resources. */
74
static XtResource resources[] = {
75
{"printCommand", "PrintCommand", XtRString, sizeof(char*),
76
offset(print_command), XtRString, NULL},
77
{"filename", "Filename", XtRString, sizeof(char*),
78
offset(filename), XtRString, NULL},
83
/* Command line options table. Only resources are entered here...there is a
84
pass over the remaining options after XtParseCommand is let loose. */
86
static XrmOptionDescRec options[] = {
87
{"-page", "*dvi.pageNumber", XrmoptionSepArg, NULL},
88
{"-backingStore", "*dvi.backingStore", XrmoptionSepArg, NULL},
89
{"-resolution", "*dvi.resolution", XrmoptionSepArg, NULL},
90
{"-printCommand", ".printCommand", XrmoptionSepArg, NULL},
91
{"-filename", ".filename", XrmoptionSepArg, NULL},
92
{"-noPolyText", "*dvi.noPolyText", XrmoptionNoArg, "TRUE"},
95
static char current_print_command[1024];
97
static char current_file_name[1024];
98
static FILE *current_file;
101
* Report the syntax for calling xditview.
108
(void) printf ("Usage: %s [-fg <color>] [-bg <color>]\n", call);
109
(void) printf (" [-bd <color>] [-bw <pixels>] [-help]\n");
110
(void) printf (" [-display displayname] [-geometry geom]\n");
111
(void) printf (" [-page <page-number>] [-backing <backing-store>]\n");
112
(void) printf (" [-resolution <res>] [-print <command>]\n");
113
(void) printf (" [-filename <file>] [filename]\n\n");
117
static void NewFile (), SetPageNumber ();
118
static Widget toplevel, paned, viewport, dvi;
120
static Widget simpleMenu;
122
static void NextPage(), PreviousPage(), SelectPage(), OpenFile(), Quit();
125
static struct menuEntry {
129
"nextPage", NextPage,
130
"previousPage", PreviousPage,
131
"selectPage", SelectPage,
133
"openFile", OpenFile,
137
static void NextPageAction(), PreviousPageAction(), SelectPageAction();
138
static void OpenFileAction(), QuitAction();
139
static void AcceptAction(), CancelAction();
140
static void PrintAction();
141
static void RerasterizeAction();
143
XtActionsRec xditview_actions[] = {
144
"NextPage", NextPageAction,
145
"PreviousPage", PreviousPageAction,
146
"SelectPage", SelectPageAction,
147
"Print", PrintAction,
148
"OpenFile", OpenFileAction,
149
"Rerasterize", RerasterizeAction,
151
"Accept", AcceptAction,
152
"Cancel", CancelAction,
155
#define MenuNextPage 0
156
#define MenuPreviousPage 1
157
#define MenuSelectPage 2
159
#define MenuOpenFile 4
162
static char pageLabel[256] = "Page <none>";
170
static Arg labelArgs[] = {
171
{XtNlabel, (XtArgVal) pageLabel},
173
XtAppContext xtcontext;
176
Arg pageNumberArgs[1];
179
toplevel = XtAppInitialize(&xtcontext, "GXditview",
180
options, XtNumber (options),
181
&argc, argv, fallback_resources, NULL, 0);
185
XtGetApplicationResources(toplevel, (XtPointer)&app_resources,
186
resources, XtNumber(resources),
188
if (app_resources.print_command)
189
strcpy(current_print_command, app_resources.print_command);
191
XtAppAddActions(xtcontext, xditview_actions, XtNumber (xditview_actions));
193
XtSetArg (topLevelArgs[0], XtNiconPixmap,
194
XCreateBitmapFromData (XtDisplay (toplevel),
195
XtScreen(toplevel)->root,
196
xdit_bits, xdit_width, xdit_height));
198
XtSetArg (topLevelArgs[1], XtNiconMask,
199
XCreateBitmapFromData (XtDisplay (toplevel),
200
XtScreen(toplevel)->root,
202
xdit_mask_width, xdit_mask_height));
203
XtSetValues (toplevel, topLevelArgs, 2);
208
* create the menu and insert the entries
210
simpleMenu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, toplevel,
212
for (i = 0; i < XtNumber (menuEntries); i++) {
213
entry = XtCreateManagedWidget(menuEntries[i].name,
214
smeBSBObjectClass, simpleMenu,
216
XtAddCallback(entry, XtNcallback, menuEntries[i].function, NULL);
219
paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
221
viewport = XtCreateManagedWidget("viewport", viewportWidgetClass, paned,
223
dvi = XtCreateManagedWidget ("dvi", dviWidgetClass, viewport, NULL, 0);
224
page = XtCreateManagedWidget ("label", labelWidgetClass, paned,
225
labelArgs, XtNumber (labelArgs));
226
XtSetArg (pageNumberArgs[0], XtNpageNumber, &page_number);
227
XtGetValues (dvi, pageNumberArgs, 1);
230
/* NewFile modifies current_file_name, so do this here. */
231
if (app_resources.filename)
232
strcpy(current_file_name, app_resources.filename);
233
XtRealizeWidget (toplevel);
235
SetPageNumber (page_number);
236
XtAppMainLoop(xtcontext);
241
SetPageNumber (number)
244
int actual_number, last_page;
246
XtSetArg (arg[0], XtNpageNumber, number);
247
XtSetValues (dvi, arg, 1);
248
XtSetArg (arg[0], XtNpageNumber, &actual_number);
249
XtSetArg (arg[1], XtNlastPageNumber, &last_page);
250
XtGetValues (dvi, arg, 2);
251
if (actual_number == 0)
252
sprintf (pageLabel, "Page <none>");
253
else if (last_page > 0)
254
sprintf (pageLabel, "Page %d of %d", actual_number, last_page);
256
sprintf (pageLabel, "Page %d", actual_number);
257
XtSetArg (arg[0], XtNlabel, pageLabel);
258
XtSetValues (page, arg, 1);
262
SelectPageNumber (number_string)
265
SetPageNumber (atoi(number_string));
268
static int hadFile = 0;
280
if (!strcmp (current_file_name, "-"))
282
else if (current_file_name[0] == '|')
283
pclose (current_file);
285
fclose (current_file);
287
if (!strcmp (name, "-"))
289
else if (name[0] == '|')
290
new_file = popen (name+1, "r");
292
new_file = fopen (name, "r");
296
/* XXX display error message */
299
XtSetArg (arg[0], XtNfile, new_file);
300
XtSetArg (arg[1], XtNseek, seek);
301
XtSetValues (dvi, arg, 2);
302
if (hadFile || name[0] != '-' || name[1] != '\0') {
303
XtSetArg (arg[0], XtNtitle, name);
304
if (name[0] != '/' && (n = strrchr (name, '/')))
308
XtSetArg (arg[1], XtNiconName, n);
309
XtSetValues (toplevel, arg, 2);
312
SelectPageNumber ("1");
313
strcpy (current_file_name, name);
314
current_file = new_file;
317
static char fileBuf[1024];
319
ResetMenuEntry (entry)
324
XtSetArg (arg[0], XtNpopupOnEntry, entry);
325
XtSetValues (XtParent(entry) , arg, (Cardinal) 1);
331
NextPage (entry, name, data)
336
ResetMenuEntry (entry);
345
XtSetArg (args[0], XtNpageNumber, &number);
346
XtGetValues (dvi, args, 1);
347
SetPageNumber (number+1);
353
PreviousPage (entry, name, data)
357
PreviousPageAction ();
358
ResetMenuEntry (entry);
362
PreviousPageAction ()
367
XtSetArg (args[0], XtNpageNumber, &number);
368
XtGetValues (dvi, args, 1);
369
SetPageNumber (number-1);
375
SelectPage (entry, name, data)
380
ResetMenuEntry (entry);
386
MakePrompt (toplevel, "Page number", SelectPageNumber, "");
395
#ifdef SIGNALRETURNSINT
400
/* Avoid dieing because of an invalid command. */
401
handler = signal(SIGPIPE, SIG_IGN);
403
print_file = popen(name, "w");
405
/* XXX print error message */
407
DviSaveToFile(dvi, print_file);
409
signal(SIGPIPE, handler);
410
strcpy(current_print_command, name);
419
if (current_file_name[0] == 0) {
420
/* XXX display an error message */
423
XtSetArg (args[0], XtNpageNumber, &number);
424
XtGetValues (dvi, args, 1);
425
NewFile(current_file_name);
426
SetPageNumber (number);
432
Print (entry, name, data)
437
ResetMenuEntry (entry);
443
if (current_print_command[0])
444
strcpy (fileBuf, current_print_command);
447
MakePrompt (toplevel, "Print command:", DoPrint, fileBuf);
454
OpenFile (entry, name, data)
459
ResetMenuEntry (entry);
465
if (current_file_name[0])
466
strcpy (fileBuf, current_file_name);
469
MakePrompt (toplevel, "File to open:", NewFile, fileBuf);
475
Quit (entry, closure, data)
477
caddr_t closure, data;
488
Widget promptShell, promptDialog;
489
void (*promptfunction)();
493
void CancelAction (widget, event, params, num_params)
497
Cardinal *num_params;
500
XtSetKeyboardFocus(toplevel, (Widget) None);
501
XtDestroyWidget(promptShell);
502
promptShell = (Widget) 0;
507
void AcceptAction (widget, event, params, num_params)
511
Cardinal *num_params;
513
(*promptfunction)(XawDialogGetValueString(promptDialog));
514
CancelAction (widget, event, params, num_params);
517
MakePrompt(centerw, prompt, func, def)
523
static Arg dialogArgs[] = {
529
Position source_x, source_y;
530
Position dest_x, dest_y;
531
Dimension center_width, center_height;
532
Dimension prompt_width, prompt_height;
535
CancelAction ((Widget)NULL, (XEvent *) 0, (String *) 0, (Cardinal *) 0);
536
promptShell = XtCreatePopupShell ("promptShell", transientShellWidgetClass,
537
toplevel, NULL, (Cardinal) 0);
538
dialogArgs[0].value = (XtArgVal)prompt;
539
dialogArgs[1].value = (XtArgVal)def;
540
promptDialog = XtCreateManagedWidget( "promptDialog", dialogWidgetClass,
541
promptShell, dialogArgs, XtNumber (dialogArgs));
542
XawDialogAddButton(promptDialog, "accept", NULL, (caddr_t) 0);
543
XawDialogAddButton(promptDialog, "cancel", NULL, (caddr_t) 0);
544
valueWidget = XtNameToWidget (promptDialog, "value");
546
XtSetArg (valueArgs[0], XtNresizable, TRUE);
547
XtSetValues (valueWidget, valueArgs, 1);
549
* as resizable isn't set until just above, the
550
* default value will be displayed incorrectly.
551
* rectify the situation by resetting the values
553
XtSetValues (promptDialog, dialogArgs, XtNumber (dialogArgs));
555
XtSetKeyboardFocus (promptDialog, valueWidget);
556
XtSetKeyboardFocus (toplevel, valueWidget);
557
XtRealizeWidget (promptShell);
559
* place the widget in the center of the "parent"
561
XtSetArg (centerArgs[0], XtNwidth, ¢er_width);
562
XtSetArg (centerArgs[1], XtNheight, ¢er_height);
563
XtGetValues (centerw, centerArgs, 2);
564
XtSetArg (centerArgs[0], XtNwidth, &prompt_width);
565
XtSetArg (centerArgs[1], XtNheight, &prompt_height);
566
XtGetValues (promptShell, centerArgs, 2);
567
source_x = (center_width - prompt_width) / 2;
568
source_y = (center_height - prompt_height) / 3;
569
XtTranslateCoords (centerw, source_x, source_y, &dest_x, &dest_y);
570
XtSetArg (centerArgs[0], XtNx, dest_x);
571
XtSetArg (centerArgs[1], XtNy, dest_y);
572
XtSetValues (promptShell, centerArgs, 2);
573
XtMapWidget(promptShell);
574
promptfunction = func;
588
c-continued-statement-offset: 4
592
c-tab-always-indent: nil