File: printer_options.c

package info (click to toggle)
ncview 1.93g-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 20,508 kB
  • ctags: 4,237
  • sloc: ansic: 60,844; f90: 437; sed: 361; sh: 153; makefile: 138
file content (564 lines) | stat: -rw-r--r-- 15,942 bytes parent folder | download | duplicates (2)
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
/*
 * Ncview by David W. Pierce.  A visual netCDF file viewer.
 * Copyright (C) 1993 through 2008 David W. Pierce
 *
 * This program  is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, Version 3, as 
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License, version 3, for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * David W. Pierce
 * 6259 Caminito Carrena
 * San Diego, CA  92122
 * pierce@cirrus.ucsd.edu
 */

/*    define DEBUG */

#include "../ncview.includes.h"
#include "../ncview.defines.h"
#include "../ncview.protos.h"

#define PO_MAR_TEXT_WIDTH 	40
#define FIRST_LABEL_WIDTH	80
#define FONTNAME_WIDTH		100

extern Widget		topLevel;
extern XtAppContext	x_app_context;
extern Options		options;

static Widget
	po_popup_widget,
		po_popupcanvas_widget,
			po_outdev_box_widget,
				po_outdev_label_widget,
				po_outdev_printer_widget,
				po_outdev_file_widget,
				po_outf_label_widget,
				po_outf_text_widget,
			po_margin_box_widget,
				po_margin_label_widget,
				po_xmar_label_widget,
				po_xmar_text_widget,
				po_ymar_top_label_widget,
				po_ymar_top_text_widget,
				po_ymar_bot_label_widget,
				po_ymar_bot_text_widget,
				po_margin_endlabel_widget,
			po_font_box_widget,
				po_font_label_widget,
				po_font_name_label_widget,
				po_font_name_text_widget,
				po_font_headsize_label_widget,
				po_font_headsize_text_widget,
				po_font_size_label_widget,
				po_font_size_text_widget,
				po_font_endlabel_widget,
			po_include_box_widget,
				po_include_label_widget,
				po_include_outline_widget,
				po_include_title_widget,
				po_include_axis_labels_widget,
				po_include_extra_info_widget,
				po_include_id_widget,
				po_test_only_widget,
			po_action_box_widget,
				po_ok_widget,
				po_cancel_widget;

static int po_popup_done = FALSE, po_popup_result;

static XEvent	po_event;

void po_popup_callback		( Widget widget, XtPointer client_data, XtPointer call_data);
void po_outdev_printer_callback ( Widget widget, XtPointer client_data, XtPointer call_data);
void po_outdev_file_callback	( Widget widget, XtPointer client_data, XtPointer call_data);

/*****************************************************************************/

	int
printer_options( PrintOptions *po )
{
	int	llx, lly, urx, ury;
	char	tstr[1024], *tstr2;
	 Boolean t_or_f;

#ifdef DEBUG
	fprintf(stderr, "entering printer_options\n" );
#endif

	/******* Set current values of everything *******/

	/*** Output Device ***/
	XawToggleSetCurrent( po_outdev_printer_widget, (XtPointer)po->output_device );
	if( po->output_device == DEVICE_PRINTER )
		XtVaSetValues( po_outf_text_widget, XtNsensitive, FALSE, NULL );
	XtVaSetValues( po_outf_text_widget, XtNstring, po->out_file_name, NULL );

	/*** Margins ***/
	sprintf( tstr, "%g", po->page_x_margin );
	XtVaSetValues( po_xmar_text_widget, XtNstring, tstr, NULL );

	sprintf( tstr, "%g", po->page_upper_y_margin );
	XtVaSetValues( po_ymar_top_text_widget, XtNstring, tstr, NULL );

	sprintf( tstr, "%g", po->page_lower_y_margin );
	XtVaSetValues( po_ymar_bot_text_widget, XtNstring, tstr, NULL );

	/*** Fonts ***/
	XtVaSetValues( po_font_name_text_widget, XtNstring, po->font_name, NULL );

	sprintf( tstr, "%d", po->header_font_size );
	XtVaSetValues( po_font_headsize_text_widget, XtNstring, tstr, NULL );

	sprintf( tstr, "%d", po->font_size );
	XtVaSetValues( po_font_size_text_widget, XtNstring, tstr, NULL );

	/*** Includes ***/
	XtVaSetValues( po_include_title_widget,       XtNstate, po->include_title,       NULL );
	XtVaSetValues( po_include_axis_labels_widget, XtNstate, po->include_axis_labels, NULL );
	XtVaSetValues( po_include_extra_info_widget,  XtNstate, po->include_extra_info,  NULL );
	XtVaSetValues( po_include_outline_widget,     XtNstate, po->include_outline,     NULL );
	XtVaSetValues( po_include_id_widget,          XtNstate, po->include_id,          NULL );
	XtVaSetValues( po_test_only_widget,           XtNstate, po->test_only,           NULL );

#ifdef DEBUG
	fprintf(stderr, "printer_options: popping up window\n" );
#endif
	/********** Pop up the window **********/
	x_get_window_position( &llx, &lly, &urx, &ury );
	XtVaSetValues( po_popup_widget, XtNx, llx+10, XtNy, (ury+lly)/2, NULL );
	XtPopup      ( po_popup_widget, XtGrabExclusive );

	if( options.display_type == PseudoColor )
		x_set_windows_colormap_to_current( po_popup_widget );

	/**********************************************
	 * Main loop for the printer options popup widget
	 */
	while( ! po_popup_done ) {
		/* An event will cause range_popup_done to become TRUE */
		XtAppNextEvent( x_app_context, &po_event );
		XtDispatchEvent( &po_event );
		}
	po_popup_done = FALSE;

	/**********************************************/

#ifdef DEBUG
	fprintf(stderr, "printer_options: done with popup window\n" );
#endif

	if( po_popup_result != MESSAGE_CANCEL ) {
		/* get the values in the widges, put them back into the printer
		 * options structure.
		 */

		/*** Margins ***/
		XtVaGetValues( po_xmar_text_widget, XtNstring, &tstr2, NULL );
		sscanf( tstr2, "%g", &(po->page_x_margin) );
		XtVaGetValues( po_ymar_top_text_widget, XtNstring, &tstr2, NULL );
		sscanf( tstr2, "%g", &(po->page_upper_y_margin) );
		XtVaGetValues( po_ymar_bot_text_widget, XtNstring, &tstr2, NULL );
		sscanf( tstr2, "%g", &(po->page_lower_y_margin) );

		/*** Fonts ***/
		XtVaGetValues( po_font_name_text_widget, XtNstring, &tstr2, NULL );
		strcpy( po->font_name, tstr2 );
		XtVaGetValues( po_font_size_text_widget, XtNstring, &tstr2, NULL );
		sscanf( tstr2, "%d", &(po->font_size) );
		XtVaGetValues( po_font_headsize_text_widget, XtNstring, &tstr2, NULL );
		sscanf( tstr2, "%d", &(po->header_font_size) );

		/*** Device ***/
		po->output_device = (int)XawToggleGetCurrent(po_outdev_printer_widget); 
		XtVaGetValues( po_outf_text_widget, XtNstring, &tstr2, NULL );
		strcpy( po->out_file_name, tstr2 );

		/*** Includes ***/
		XtVaGetValues( po_include_title_widget,       XtNstate, &t_or_f, NULL );
		po->include_title       = ( (t_or_f == TRUE) ? 1 : 0 );

		XtVaGetValues( po_include_axis_labels_widget, XtNstate, &t_or_f, NULL );
		po->include_axis_labels = ( (t_or_f == TRUE) ? 1 : 0 );

		XtVaGetValues( po_include_extra_info_widget,  XtNstate, &t_or_f, NULL );
		po->include_extra_info  = ( (t_or_f == TRUE) ? 1 : 0 );

		XtVaGetValues( po_include_outline_widget,     XtNstate, &t_or_f, NULL );
		po->include_outline     = ( (t_or_f == TRUE) ? 1 : 0 );

		XtVaGetValues( po_include_id_widget,          XtNstate, &t_or_f, NULL );
		po->include_id          = ( (t_or_f == TRUE) ? 1 : 0 );

		XtVaGetValues( po_test_only_widget,           XtNstate, &t_or_f, NULL );
		po->test_only           = ( (t_or_f == TRUE) ? 1 : 0 );
		}
	XtPopdown( po_popup_widget );
#ifdef DEBUG
	fprintf(stderr, "printer_options: exiting\n" );
#endif
	return( po_popup_result );
}

	void
printer_options_init()
{
	po_popup_widget = XtVaCreatePopupShell(
		"Printer Options",
		transientShellWidgetClass,
		topLevel,
		NULL );

	po_popupcanvas_widget = XtVaCreateManagedWidget(
		"po_popupcanvas",
		formWidgetClass,
		po_popup_widget,
		NULL);

	po_outdev_box_widget = XtVaCreateManagedWidget(
		"po_outdev_box_widget",	
		boxWidgetClass,	
		po_popupcanvas_widget,
		XtNorientation, XtorientHorizontal,
		NULL );

		po_outdev_label_widget = XtVaCreateManagedWidget(
			"po_outdev_label",	
			labelWidgetClass,	
			po_outdev_box_widget,
			XtNlabel, "Device:",
			XtNwidth, FIRST_LABEL_WIDTH,
			XtNborderWidth, 0,
			NULL );
	
		po_outdev_printer_widget = XtVaCreateManagedWidget(
			"po_outdev_printer_widget",	
			toggleWidgetClass,	
			po_outdev_box_widget,
			XtNlabel, "Printer",
			XtNfromHoriz, po_outdev_label_widget,
			XtNradioData, DEVICE_PRINTER,
			NULL );
	
       		 XtAddCallback( po_outdev_printer_widget, XtNcallback,
			po_outdev_printer_callback, (XtPointer)NULL );
	
		po_outdev_file_widget = XtVaCreateManagedWidget(
			"po_outdev_file_widget",	
			toggleWidgetClass,	
			po_outdev_box_widget,
			XtNlabel, "File",
			XtNradioGroup, po_outdev_printer_widget,
			XtNfromHoriz, po_outdev_printer_widget,
			XtNradioData, DEVICE_FILE,
			NULL );
	
       	 	XtAddCallback( po_outdev_file_widget, XtNcallback,
			po_outdev_file_callback, (XtPointer)NULL );
	
		po_outf_label_widget = XtVaCreateManagedWidget(
			"po_outf_label",	
			labelWidgetClass,	
			po_outdev_box_widget,
			XtNlabel, "Filename:",
			XtNsensitive, False,
			XtNborderWidth, 0,
			NULL );
	
		po_outf_text_widget = XtVaCreateManagedWidget(
			"po_outf_text",	
			asciiTextWidgetClass,	
			po_outdev_box_widget,
			XtNeditType, XawtextEdit,
			XtNfromHoriz, po_outf_label_widget,
			XtNlength, 128,
			XtNborderWidth, 3,
			XtNwidth, 200,
			NULL );

	po_margin_box_widget = XtVaCreateManagedWidget(
		"po_margin_box_widget",	
		boxWidgetClass,	
		po_popupcanvas_widget,
		XtNorientation, XtorientHorizontal,
		XtNfromVert, po_outdev_box_widget,
		NULL );

		po_margin_label_widget = XtVaCreateManagedWidget(
			"po_margin_label",	
			labelWidgetClass,	
			po_margin_box_widget,
			XtNlabel, "Margins:",
			XtNwidth, FIRST_LABEL_WIDTH,
			XtNborderWidth, 0,
			NULL );

		po_xmar_label_widget = XtVaCreateManagedWidget(
			"po_xmargin_label",	
			labelWidgetClass,	
			po_margin_box_widget,
			XtNlabel, "X:",
			XtNborderWidth, 0,
			NULL );

		po_xmar_text_widget = XtVaCreateManagedWidget(
			"po_xmargin_text",	
			asciiTextWidgetClass,	
			po_margin_box_widget,
			XtNeditType, XawtextEdit,
			XtNlength, 128,
			XtNwidth, PO_MAR_TEXT_WIDTH,
			NULL );
	
		po_ymar_top_label_widget = XtVaCreateManagedWidget(
			"po_ymargin_top_label",	
			labelWidgetClass,	
			po_margin_box_widget,
			XtNlabel, "Y top:",
			XtNborderWidth, 0,
			NULL );
	
		po_ymar_top_text_widget = XtVaCreateManagedWidget(
			"po_ymargin_top_text",	
			asciiTextWidgetClass,	
			po_margin_box_widget,
			XtNeditType, XawtextEdit,
			XtNlength, 128,
			XtNwidth, PO_MAR_TEXT_WIDTH,
			NULL );

		po_ymar_bot_label_widget = XtVaCreateManagedWidget(
			"po_ymargin_bot_label",	
			labelWidgetClass,	
			po_margin_box_widget,
			XtNlabel, "Y bottom:",
			XtNborderWidth, 0,
			NULL );
	
		po_ymar_bot_text_widget = XtVaCreateManagedWidget(
			"po_ymargin_bot_text",	
			asciiTextWidgetClass,	
			po_margin_box_widget,
			XtNeditType, XawtextEdit,
			XtNlength, 128,
			XtNwidth, PO_MAR_TEXT_WIDTH,
			NULL );

		po_margin_endlabel_widget = XtVaCreateManagedWidget(
			"po_margin_label",	
			labelWidgetClass,	
			po_margin_box_widget,
			XtNlabel, "(inches)",
			XtNborderWidth, 0,
			NULL );

	po_font_box_widget = XtVaCreateManagedWidget(
		"po_font_box_widget",	
		boxWidgetClass,	
		po_popupcanvas_widget,
		XtNorientation, XtorientHorizontal,
		XtNfromVert, po_margin_box_widget,
		NULL );

		po_font_label_widget = XtVaCreateManagedWidget(
			"po_font_label",	
			labelWidgetClass,	
			po_font_box_widget,
			XtNlabel, "Fonts:",
			XtNwidth, FIRST_LABEL_WIDTH,
			XtNborderWidth, 0,
			NULL );

		po_font_name_label_widget = XtVaCreateManagedWidget(
			"po_font_name_label",	
			labelWidgetClass,	
			po_font_box_widget,
			XtNlabel, "Name:",
			XtNborderWidth, 0,
			NULL );

		po_font_name_text_widget = XtVaCreateManagedWidget(
			"po_font_name_text",	
			asciiTextWidgetClass,	
			po_font_box_widget,
			XtNeditType, XawtextEdit,
			XtNlength, 128,
			XtNwidth, FONTNAME_WIDTH,
			NULL );

		po_font_size_label_widget = XtVaCreateManagedWidget(
			"po_font_size_label",	
			labelWidgetClass,	
			po_font_box_widget,
			XtNlabel, "Size:",
			XtNborderWidth, 0,
			NULL );

		po_font_size_text_widget = XtVaCreateManagedWidget(
			"po_font_size_text",	
			asciiTextWidgetClass,	
			po_font_box_widget,
			XtNeditType, XawtextEdit,
			XtNlength, 128,
			XtNwidth, PO_MAR_TEXT_WIDTH,
			NULL );
	
		po_font_headsize_label_widget = XtVaCreateManagedWidget(
			"po_font_headsize_label",	
			labelWidgetClass,	
			po_font_box_widget,
			XtNlabel, "Header Size:",
			XtNborderWidth, 0,
			NULL );

		po_font_headsize_text_widget = XtVaCreateManagedWidget(
			"po_font_headsize_text",	
			asciiTextWidgetClass,	
			po_font_box_widget,
			XtNeditType, XawtextEdit,
			XtNlength, 128,
			XtNwidth, PO_MAR_TEXT_WIDTH,
			NULL );
	
		po_font_endlabel_widget = XtVaCreateManagedWidget(
			"po_font_label",	
			labelWidgetClass,	
			po_font_box_widget,
			XtNlabel, "(points)",
			XtNborderWidth, 0,
			NULL );

	po_include_box_widget = XtVaCreateManagedWidget(
		"po_include_box_widget",	
		boxWidgetClass,	
		po_popupcanvas_widget,
		XtNorientation, XtorientHorizontal,
		XtNfromVert, po_font_box_widget,
		NULL );
	
		po_include_label_widget = XtVaCreateManagedWidget(
			"po_include_label",	
			labelWidgetClass,	
			po_include_box_widget,
			XtNlabel, "Options:",
			XtNborderWidth, 0,
			XtNwidth, FIRST_LABEL_WIDTH,
			NULL );

		po_include_title_widget = XtVaCreateManagedWidget(
			"po_include_title_widget",	
			toggleWidgetClass,	
			po_include_box_widget,
			XtNlabel, "Title",
			NULL );

		po_include_axis_labels_widget = XtVaCreateManagedWidget(
			"po_include_axis_labels_widget",	
			toggleWidgetClass,	
			po_include_box_widget,
			XtNlabel, "Axis Labels",
			NULL );

		po_include_extra_info_widget = XtVaCreateManagedWidget(
			"po_include_extra_info_widget",	
			toggleWidgetClass,	
			po_include_box_widget,
			XtNlabel, "Extra Info",
			NULL );

		po_include_outline_widget = XtVaCreateManagedWidget(
			"po_include_outline_widget",	
			toggleWidgetClass,	
			po_include_box_widget,
			XtNlabel, "Outline",
			NULL );

		po_include_id_widget = XtVaCreateManagedWidget(
			"po_include_id_widget",	
			toggleWidgetClass,	
			po_include_box_widget,
			XtNlabel, "ID",
			NULL );

		po_test_only_widget = XtVaCreateManagedWidget(
			"po_test_only_widget",	
			toggleWidgetClass,	
			po_include_box_widget,
			XtNlabel, "No Image",
			NULL );

	po_action_box_widget = XtVaCreateManagedWidget(
		"po_action_box_widget",	
		boxWidgetClass,	
		po_popupcanvas_widget,
		XtNorientation, XtorientHorizontal,
		XtNfromVert, po_include_box_widget,
		NULL );
	
		po_ok_widget = XtVaCreateManagedWidget(
			"OK",	
			commandWidgetClass,	
			po_action_box_widget,
			NULL );
	
       	 	XtAddCallback( po_ok_widget, XtNcallback, 
			po_popup_callback, (XtPointer)MESSAGE_OK );
	
		po_cancel_widget = XtVaCreateManagedWidget(
			"Cancel",	
			commandWidgetClass,	
			po_action_box_widget,
			NULL );

       	 	XtAddCallback( po_cancel_widget, XtNcallback, 
			po_popup_callback, (XtPointer)MESSAGE_CANCEL );

}

        void
po_popup_callback( Widget widget, XtPointer client_data, XtPointer call_data)
{
#ifdef DEBUG
	fprintf( stderr, "entering po_popup_callback\n" );
#endif
	po_popup_result = (int)client_data;
	po_popup_done   = TRUE;
#ifdef DEBUG
	fprintf( stderr, "exiting po_popup_callback\n" );
#endif
}

        void
po_outdev_printer_callback( Widget widget, XtPointer client_data, XtPointer call_data)
{
#ifdef DEBUG
	fprintf( stderr, "entering po_outdev_printer_callback\n" );
#endif
	XtVaSetValues( po_outf_label_widget, XtNsensitive, False, NULL );
	XtVaSetValues( po_outf_text_widget, XtNsensitive, False, NULL );
#ifdef DEBUG
	fprintf( stderr, "exiting po_outdev_printer_callback\n" );
#endif
}

        void
po_outdev_file_callback( Widget widget, XtPointer client_data, XtPointer call_data)
{
#ifdef DEBUG
	fprintf( stderr, "entering po_outdev_file_callback\n" );
#endif
	XtVaSetValues( po_outf_label_widget, XtNsensitive, True, NULL );
	XtVaSetValues( po_outf_text_widget, XtNsensitive, True, NULL );
#ifdef DEBUG
	fprintf( stderr, "exiting po_outdev_file_callback\n" );
#endif
}