summaryrefslogtreecommitdiff
path: root/dviware/dvipage/message.c
blob: 343bfbf145e981de3625479f3611ac81d266214e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/*
 * dvipage: DVI Previewer Program for Suns
 *
 * Neil Hunt (hunt@spar.slb.com)
 *
 * This program is based, in part, upon the program dvisun,
 * distributed by the UnixTeX group, extensively modified by
 * Neil Hunt at the Schlumberger Palo Alto Research Laboratories
 * of Schlumberger Technologies, Inc.
 *
 * Copyright (c) 1988 Schlumberger Technologies, Inc 1988.
 * Anyone can use this software in any manner they choose,
 * including modification and redistribution, provided they make
 * no charge for it, and these conditions remain unchanged.
 *
 * This program is distributed as is, with all faults (if any), and
 * without any warranty. No author or distributor accepts responsibility
 * to anyone for the consequences of using it, or for whether it serves any
 * particular purpose at all, or any other reason.
 *
 * $Log:	message.c,v $
 * Revision 1.2  88/12/07  18:48:27  hunt
 * Fixed typo left from previous mods.
 * 
 * Revision 1.1  88/11/28  18:41:13  hunt
 * Initial revision
 * 
 * Stripped from dvipage.c 1.4.
 */

#include <stdio.h>
#include <strings.h>
#include <varargs.h>
#include <sys/param.h>		/* For MAXPATHLEN */
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <suntool/panel.h>
#include "dvipage.h"

/*
 * Forward functions.
 * =================
 */

forward void		mess_done();

/*
 * These are here rather than in dvipage.h because
 * they cause problems unless a whole raft of other includes
 * go in front.
 */
extern Frame		disp_frame;
extern Canvas		disp_canvas;

Frame			mess_frame;		/* Frame for message window. */
Panel			mess_panel;		/* Panel for message window. */

static int		errors_displayed = 0;

/*
 * message:
 *	Pops up a message window (if one is not already displayed)
 *	Formats a message (using fmt and args) and displays it into the window.
 *	Repeated calls to this function result in multiple lines of messages.
 */

void
message(fmt, va_alist)
char *fmt;
va_dcl
{
	va_list args;
	static char string[100];

	if(silent)
		return;

	va_start(args);
	vsprintf(string, fmt, args);
	va_end(args);

	/*
	 * If there are no errors displayed,
	 * then build a window..
	 */
	if(errors_displayed == 0)
	{
		mess_frame = window_create(disp_frame, FRAME,
		  FRAME_NO_CONFIRM, TRUE,
		  0);
		mess_panel = window_create(mess_frame, PANEL,
		  0);
		panel_create_item(mess_panel, PANEL_BUTTON,
		  PANEL_LABEL_IMAGE,
		    panel_button_image(mess_panel, "OK", 0, 0),
		  PANEL_ITEM_X, ATTR_COL(1),
		  PANEL_ITEM_Y, ATTR_ROW(0),
		  PANEL_NOTIFY_PROC, mess_done,
		  0);
	}
	else
		window_set(mess_frame,
		  WIN_SHOW, FALSE,
		  0);

	panel_create_item(mess_panel, PANEL_MESSAGE,
	  PANEL_LABEL_STRING, string,
	  PANEL_ITEM_X, ATTR_COL(1),
	  PANEL_ITEM_Y, ATTR_ROW(++errors_displayed)+5,
	  0);

	window_fit(mess_panel);
	window_fit(mess_frame);

	window_set(mess_frame,
	  WIN_SHOW, TRUE,
	  0);
}

/*
 * mess_done:
 *	This function is called when the OK button is pressed on the message
 *	window; the window is closed, and displayed messages are cleared.
 */

void
mess_done()
{
	window_destroy(mess_frame);

	errors_displayed = 0;
}

/*
 * Pop up prompts:
 * ==============
 */

static bool				prompt_return_value = TRUE;

static Pixrect				*ok_button = NULL;
static Pixrect				*abort_button = NULL;

static Panel_setting			prompt_ok_proc();
static Panel_setting			prompt_abort_proc();
static Panel_setting			prompt_notify_proc();

/*
 * strings_prompt: eg.
 *	strings_prompt(1152/2, 900/2,
 *	  "Directory: ", &dir[0],
 *	  "Filename: ", &fname[0],
 *	  0);
 */

#define MAX_STRING_ITEMS	10

bool
strings_prompt(x, y, va_alist)
int x, y;
va_dcl
{
	Frame frame;
	Panel panel;
	Panel_item string_item[MAX_STRING_ITEMS], ok_item, abort_item;
	Event *event;
	int w, h;
	int i;
	char *prompt;
	char *value;
	va_list ap;

	/*
	 * Create the frame and panel.
	 */
	frame = window_create(NULL, FRAME,
	  FRAME_SHOW_LABEL, FALSE,
	  FRAME_NO_CONFIRM, TRUE,
	  0);

	panel = window_create(frame, PANEL,
	  PANEL_ITEM_X_GAP, 1000, /* Enforces vertical layout */
	  0);

	va_start(ap);
	{
		for(i = 0; i < MAX_STRING_ITEMS; i++)
		{
			/*
			 * Stop if no more strings.
			 */
			if((prompt = va_arg(ap, char *)) == NULL ||
			   (value = va_arg(ap, char *)) == NULL)
				break;

			/*
			 * Create a text item for the string.
			 */
			string_item[i] = panel_create_item(panel, PANEL_TEXT,
			  PANEL_LABEL_STRING, prompt,
			  PANEL_VALUE, value,
			  PANEL_VALUE_DISPLAY_LENGTH, 20,
			  PANEL_VALUE_STORED_LENGTH, 132,
			  PANEL_NOTIFY_LEVEL, PANEL_ALL,
			  PANEL_NOTIFY_PROC, prompt_notify_proc,
			  0);
		}
	}
	va_end(ap);

	/*
	 * Create an OK button.
	 */
	if(ok_button == NULL)
		ok_button = panel_button_image(panel, "OK", 0, 0);

	ok_item = panel_create_item(panel, PANEL_BUTTON,
	  PANEL_LABEL_IMAGE, ok_button,
	  PANEL_NOTIFY_PROC, prompt_ok_proc,
	  0);

	/*
	 * Create an abort button.
	 */
	if(abort_button == NULL)
		abort_button = panel_button_image(panel, "Abort", 0, 0);

	abort_item = panel_create_item(panel, PANEL_BUTTON,
	  PANEL_LABEL_IMAGE, abort_button,
	  PANEL_NOTIFY_PROC, prompt_abort_proc,
	  0);

	/*
	 * Make them windows fit.
	 */
	window_fit(panel);
	window_fit(frame);

	/*
	 * Centre the prompt
	 */
	w = (int)window_get(frame, WIN_WIDTH);
	h = (int)window_get(frame, WIN_HEIGHT);
	x -= w/2;
	y -= h/2;
	window_set(frame,
	  WIN_X, x,
	  WIN_Y, y,
	  0);

	/*
	 * Set the flag to TRUE to indicate not aborted.
	 */
	prompt_return_value = TRUE;

	/*
	 * Display and wait for done.
	 */
	(void)window_loop(frame);

	/*
	 * If OK, then retrieve the window values and store them.
	 */
	if(prompt_return_value)
	{
		/*
		 * Loop through the items copying back values.
		 */
		va_start(ap);
		{
			for(i = 0; i < MAX_STRING_ITEMS; i++)
			{
				/*
				 * Stop if no more strings.
				 */
				if((prompt = va_arg(ap, char *)) == NULL ||
				   (value = va_arg(ap, char *)) == NULL)
					break;

				/*
				 * Get the value of this item.
				 */
				strcpy(value, panel_get_value(string_item[i]));
			}
		}
		va_end(ap);
	}

	/*
	 * Destroy the window.
	 */
	window_destroy(frame);

	return prompt_return_value;
}

/*
 * integers_prompt: eg.
 *	integers_prompt(1152/2, 900/2,
 *	  "Width: ", &w,
 *	  "Height: ", &h,
 *	  0);
 */

#define MAX_INTEGER_ITEMS	MAX_STRING_ITEMS

bool
integers_prompt(x, y, va_alist)
int x, y;
va_dcl
{
	Frame frame;
	Panel panel;
	Panel_item integer_item[MAX_INTEGER_ITEMS], ok_item, abort_item;
	Event *event;
	int w, h;
	int i;
	char *prompt;
	int *value;
	va_list ap;
	char value_string[20];

	/*
	 * Create the frame and panel.
	 */
	frame = window_create(NULL, FRAME,
	  FRAME_SHOW_LABEL, FALSE,
	  FRAME_NO_CONFIRM, TRUE,
	  0);

	panel = window_create(frame, PANEL,
	  PANEL_ITEM_X_GAP, 1000, /* Enforces vertical layout */
	  0);

	va_start(ap);
	{
		for(i = 0; i < MAX_INTEGER_ITEMS; i++)
		{
			/*
			 * Stop if no more strings.
			 */
			if((prompt = va_arg(ap, char *)) == NULL ||
			   (value = va_arg(ap, int *)) == NULL)
				break;

			/*
			 * Create a text item for the string.
			 */
			sprintf(value_string, "%d", *value);
			integer_item[i] = panel_create_item(panel, PANEL_TEXT,
			  PANEL_LABEL_STRING, prompt,
			  PANEL_VALUE, value_string,
			  PANEL_VALUE_DISPLAY_LENGTH, 20,
			  PANEL_VALUE_STORED_LENGTH, 20,
			  PANEL_NOTIFY_STRING, "\033",
			  PANEL_NOTIFY_LEVEL, PANEL_ALL,
			  PANEL_NOTIFY_PROC, prompt_notify_proc,
			  0);

		}
	}
	va_end(ap);

	/*
	 * Create an OK button.
	 */
	if(ok_button == NULL)
		ok_button = panel_button_image(panel, "OK", 0, 0);

	ok_item = panel_create_item(panel, PANEL_BUTTON,
	  PANEL_LABEL_IMAGE, ok_button,
	  PANEL_NOTIFY_PROC, prompt_ok_proc,
	  0);

	/*
	 * Create an abort button.
	 */
	if(abort_button == NULL)
		abort_button = panel_button_image(panel, "Abort", 0, 0);

	abort_item = panel_create_item(panel, PANEL_BUTTON,
	  PANEL_LABEL_IMAGE, abort_button,
	  PANEL_NOTIFY_PROC, prompt_abort_proc,
	  0);

	/*
	 * Make them windows fit.
	 */
	window_fit(panel);
	window_fit(frame);

	/*
	 * Centre the prompt
	 */
	w = (int)window_get(frame, WIN_WIDTH);
	h = (int)window_get(frame, WIN_HEIGHT);
	x -= w/2;
	y -= h/2;
	window_set(frame,
	  WIN_X, x,
	  WIN_Y, y,
	  0);

	/*
	 * Set the flag to TRUE to indicate not aborted.
	 */
	prompt_return_value = TRUE;

	/*
	 * Display and wait for done.
	 */
	(void)window_loop(frame);

	/*
	 * If OK, then retrieve the window values and store them.
	 */
	if(prompt_return_value)
	{
		/*
		 * Loop through the items copying back values.
		 */
		va_start(ap);
		{
			for(i = 0; i < MAX_INTEGER_ITEMS; i++)
			{
				/*
				 * Stop if no more strings.
				 */
				if((prompt = va_arg(ap, char *)) == NULL ||
				   (value = va_arg(ap, int *)) == NULL)
					break;

				/*
				 * Get the value of this item.
				 */
				*value = atoi(panel_get_value(integer_item[i]));
			}
		}
		va_end(ap);
	}

	/*
	 * Destroy the window.
	 */
	window_destroy(frame);

	return prompt_return_value;
}

/*
 * doubles_prompt: eg.
 *	doubles_prompt(1152/2, 900/2,
 *	  "Width: ", &w,
 *	  "Height: ", &h,
 *	  0);
 */

#define MAX_DOUBLE_ITEMS	MAX_INTEGER_ITEMS

bool
doubles_prompt(x, y, va_alist)
int x, y;
va_dcl
{
	Frame frame;
	Panel panel;
	Panel_item double_item[MAX_DOUBLE_ITEMS], ok_item, abort_item;
	Event *event;
	int w, h;
	int i;
	char *prompt;
	double *value;
	va_list ap;
	char value_string[20];

	/*
	 * Create the frame and panel.
	 */
	frame = window_create(NULL, FRAME,
	  FRAME_SHOW_LABEL, FALSE,
	  FRAME_NO_CONFIRM, TRUE,
	  0);

	panel = window_create(frame, PANEL,
	  PANEL_ITEM_X_GAP, 1000, /* Enforces vertical layout */
	  0);

	va_start(ap);
	{
		for(i = 0; i < MAX_DOUBLE_ITEMS; i++)
		{
			/*
			 * Stop if no more strings.
			 */
			if((prompt = va_arg(ap, char *)) == NULL ||
			   (value = va_arg(ap, double *)) == NULL)
				break;

			/*
			 * Create a text item for the string.
			 */
			sprintf(value_string, "%g", *value);
			double_item[i] = panel_create_item(panel, PANEL_TEXT,
			  PANEL_LABEL_STRING, prompt,
			  PANEL_VALUE, value_string,
			  PANEL_VALUE_DISPLAY_LENGTH, 20,
			  PANEL_VALUE_STORED_LENGTH, 40,
			  PANEL_NOTIFY_STRING, "\033",
			  PANEL_NOTIFY_LEVEL, PANEL_ALL,
			  PANEL_NOTIFY_PROC, prompt_notify_proc,
			  0);
		}
	}
	va_end(ap);

	/*
	 * Create an OK button.
	 */
	if(ok_button == NULL)
		ok_button = panel_button_image(panel, "OK", 0, 0);

	ok_item = panel_create_item(panel, PANEL_BUTTON,
	  PANEL_LABEL_IMAGE, ok_button,
	  PANEL_NOTIFY_PROC, prompt_ok_proc,
	  0);

	/*
	 * Create an abort button.
	 */
	if(abort_button == NULL)
		abort_button = panel_button_image(panel, "Abort", 0, 0);

	abort_item = panel_create_item(panel, PANEL_BUTTON,
	  PANEL_LABEL_IMAGE, abort_button,
	  PANEL_NOTIFY_PROC, prompt_abort_proc,
	  0);

	/*
	 * Make them windows fit.
	 */
	window_fit(panel);
	window_fit(frame);

	/*
	 * Centre the prompt
	 */
	w = (int)window_get(frame, WIN_WIDTH);
	h = (int)window_get(frame, WIN_HEIGHT);
	x -= w/2;
	y -= h/2;
	window_set(frame,
	  WIN_X, x,
	  WIN_Y, y,
	  0);

	/*
	 * Set the flag to FALSE to indicate not aborted.
	 */
	prompt_return_value = FALSE;

	/*
	 * Display and wait for done.
	 */
	(void)window_loop(frame);

	/*
	 * If OK, then retrieve the window values and store them.
	 */
	if(prompt_return_value)
	{
		/*
		 * Loop through the items copying back values.
		 */
		va_start(ap);
		{
			for(i = 0; i < MAX_DOUBLE_ITEMS; i++)
			{
				/*
				 * Stop if no more strings.
				 */
				if((prompt = va_arg(ap, char *)) == NULL ||
				   (value = va_arg(ap, double *)) == NULL)
					break;

				/*
				 * Get the value of this item.
				 */
				*value = atof(panel_get_value(double_item[i]));
			}
		}
		va_end(ap);
	}

	/*
	 * Destroy the window.
	 */
	window_destroy(frame);

	return prompt_return_value;
}

/*
 * prompt_notify_proc:
 */

static Panel_setting
prompt_notify_proc(item, event)
Panel_item item;
Event *event;
{
	if(event_id(event) == ESC)
	{
		prompt_return_value = TRUE;
		window_return(NULL);
		return PANEL_NONE;
	}
	else if(event_id(event) == Control('C'))
	{
		prompt_return_value = FALSE;
		window_return(NULL);
		return PANEL_NONE;
	}
	else
		return panel_text_notify(item, event);
}

/*
 * prompt_ok_proc:
 *	Normal return from string prompt.
 */

static Panel_setting
prompt_ok_proc(item, event) 
Panel_item item; 
Event *event;
{ 
	prompt_return_value = TRUE;

	window_return(NULL);

	return PANEL_NONE;
}

/*
 * prompt_abort_proc:
 *	Return from prompt with null string.
 */

static Panel_setting
prompt_abort_proc(item, event)
Panel_item item;
Event *event;
{
	prompt_return_value = FALSE;

	window_return(NULL);

	return PANEL_NONE;
}