1 /* SCCS-info %W% %E% */
2
3 /*--------------------------------------------------------------------*/
4 /* */
5 /* VCG : Visualization of Compiler Graphs */
6 /* -------------------------------------- */
7 /* */
8 /* file: X11devpb.c */
9 /* version: 1.00.00 */
10 /* creation: 9.4.93 */
11 /* author: I. Lemke (...-Version 0.99.99) */
12 /* G. Sander (Version 1.00.00-...) */
13 /* Universitaet des Saarlandes, 66041 Saarbruecken */
14 /* ESPRIT Project #5399 Compare */
15 /* description: Device driver for X11, Export Dialog Box */
16 /* status: in work */
17 /* */
18 /*--------------------------------------------------------------------*/
19
20 #ifndef lint
21 static char *id_string="$Id: X11devpb.c,v 1.9 1995/02/08 11:11:14 sander Exp $";
22 #endif
23
24 /*
25 * Copyright (C) 1993-2005 Saarland University
26 *
27 * This program and documentation is free software; you can redistribute
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation; either version 2 of the License, or
30 * (at your option) any later version.
31 *
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License
38 * along with this program; if not, write to the Free Software
39 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40 *
41 * The software is available per anonymous ftp at ftp.cs.uni-sb.de.
42 * Contact sander@cs.uni-sb.de for additional information.
43 */
44
45
46 /*
47 * $Log: X11devpb.c,v $
48 * Revision 1.9 1995/02/08 11:11:14 sander
49 * Distribution version 1.3.
50 *
51 * Revision 1.8 1994/12/23 18:12:45 sander
52 * Manhatten layout added.
53 * Option interface cleared.
54 * infobox behaviour improved.
55 * First version of fisheye (carthesian).
56 * Options Noedge and nonode.
57 *
58 * Revision 1.7 1994/11/25 15:43:29 sander
59 * Printer interface added to allow to use VCG as a converter.
60 *
61 * Revision 1.6 1994/11/23 14:50:47 sander
62 * Drawing speed improved by removing some superfluous XSyncs.
63 *
64 * Revision 1.5 1994/08/03 13:58:44 sander
65 * Horizontal order mechanism changed.
66 * Attribute horizontal_order for edges added.
67 *
68 * Revision 1.4 1994/06/07 14:09:59 sander
69 * Splines implemented.
70 * HP-UX, Linux, AIX, Sun-Os, IRIX compatibility tested.
71 * The tool is now ready to be distributed.
72 *
73 * Revision 1.3 1994/05/16 08:56:03 sander
74 * shape attribute (boxes, rhombs, ellipses, triangles) added.
75 *
76 * Revision 1.2 1994/05/05 08:20:30 sander
77 * Small corrections: Flickering of the box removed.
78 *
79 * Revision 1.1 1994/04/27 16:05:19 sander
80 * Initial revision
81 *
82 *
83 */
84
85 /************************************************************************
86 * Device driver for X11: Export Dialog Box
87 * ----------------------------------------
88 *
89 * This module contains the management of the dialog box that appears
90 * if we export the graph to pbm, ppm or PostScript.
91 *
92 * This file provides the following functions:
93 * ------------------------------------------
94 *
95 * x11_init_dialog(rd,rs) initialize the dialogbox.
96 * x11_destroy_dialog(rd,rs) destroys the dialogbox.
97 *
98 * x11_print_dialog(rminx, rminy, rmaxx, rmaxy)
99 *
100 * This function takes the region border lines, opens the dialog
101 * box and asks for information about the type of output.
102 * It returns the scale factor, output size etc. in global
103 * variables.
104 *
105 ************************************************************************/
106
107 #include <stdio.h>
108 #include <stdlib.h>
109 #include <string.h>
110 #include "globals.h"
111
112 #ifdef X11
113
114 /*#include <X11/Xos.h>*/
115 #include <X11/Xlib.h>
116 #include <X11/Xutil.h>
117 #include <X11/cursorfont.h>
118 #include <X11/Xproto.h>
119 #include <ctype.h>
120 #include <math.h>
121 #include "main.h"
122 #include "options.h"
123 #include "X11devpb.h"
124
125
126 /*--------------------------------------------------------------------*/
127
128 #undef EVENT_DEBUG
129
130
131 /* Prototypes
132 * ----------
133 */
134
135 void gs_exit _PP((int x));
136 void do_gblExpose _PP((XEvent *eventp));
137 void do_gblConfigureNotify _PP((XEvent *eventp));
138
139
140 static void allocateDialogBox _PP((void));
141 static Window allocate_selection_point _PP((int x,int y));
142 static Window allocate_button _PP((int x,int y));
143 static Window allocate_general_button _PP((int x,int y,int w,int h));
144 static Window allocate_scroll_bar _PP((int x,int y));
145
146 static void draw_dialog_box _PP((void));
147 static void draw_text _PP(( int x, int y, char *m));
148 static void draw_dialog_point _PP((Window w, int color));
149 static void draw_sizes _PP((void));
150
151
152 #ifdef EVENT_DEBUG
153 static void prologue _PP((XEvent *eventp, char *event_name));
154 #else
155 #define prologue(a,b)
156 #endif
157
158 static void dialog_main_loop _PP((void));
159 static void do_KeyPress _PP((XEvent *eventp));
160 static void do_ButtonPress _PP((XEvent *eventp));
161 static void do_ButtonRelease _PP((XEvent *eventp));
162 static void do_EnterNotify _PP((XEvent *eventp));
163 static void do_LeaveNotify _PP((XEvent *eventp));
164 static void do_Expose _PP((XEvent *eventp));
165 static void do_ConfigureNotify _PP((XEvent *eventp));
166 static void do_MotionNotify _PP((XEvent *eventp));
167
168 static void read_xdpiscrollbar _PP((int val));
169 static void set_xdpiscrollbar _PP((void));
170 static void set_xdpi _PP((int val));
171 static void read_ydpiscrollbar _PP((int val));
172 static void set_ydpiscrollbar _PP((void));
173 static void set_ydpi _PP((int val));
174 static void read_scalescrollbar _PP((int val));
175 static void set_scalescrollbar _PP((void));
176 static void read_widthscrollbar _PP((int val));
177 static void set_widthscrollbar _PP((void));
178 static void read_heightscrollbar _PP((int val));
179 static void set_heightscrollbar _PP((void));
180
181 static void read_marginpanner _PP((int valx,int valy));
182 static void read_marginxpanner _PP((int valx,int valy));
183 static void set_marginpanner _PP((void));
184
185 #endif /* X11 */
186
187 static void calc_paper_size _PP((void));
188 static int refocus_dpi _PP((int x));
189 static float refocus_scale _PP((float x));
190
191
192
193 /* Variables
194 * ---------
195 */
196
197
198 /* Actual output type: 1 = PBM, 2 = PPM, 3 = PS */
199
200 int act_output_type = 1;
201
202 /* Actual color: 1 = color, 2 = grey, 3 = bw */
203
204 int act_color_type = 3;
205
206 /* Actual orientation: 1 = portrait, 2 = landscape */
207
208 int act_ori_type = 1;
209
210 /* Actual paper size: 1 = A4, 2 = B5, 3 = A5, 4 = 11x17,
211 * 5 = 8.5x11, 6 = 8.5x14
212 */
213
214 int act_paper_type = 1;
215
216 static float maxx, maxy;
217
218 /* Actual page repetitor */
219
220 int act_paper_num = 1;
221
222 /* Actual size (cm) */
223
224 float act_width = 20.0;
225 float act_height = 20.0;
226
227 /* Margins (cm) */
228
229 float act_left_margin = 0.0;
230 float act_right_margin = 0.0;
231 float act_top_margin = 0.0;
232 float act_bottom_margin = 0.0;
233
234 /* Dpi */
235
236 int act_xdpi;
237 int act_ydpi;
238
239 /* Scaling */
240
241 float act_scaling = 1.0;
242
243 /* Region */
244
245 static int rgx1, rgy1, rgx2, rgy2;
246
247 /* Bounding box: yes or no (?) */
248
249 int act_bbox = 1;
250
251
252 #ifdef X11
253
254 /* Dialog handling */
255
256 static int dialog_notready = 1;
257 static int dialog_success = 0;
258
259 /* Root displays */
260
261 static Display *root_display; /* Root display */
262 static int root_screen; /* and its screen number */
263
264
265 /* Windows */
266
267 static Window dialog_window;
268
269 static Window pbm_point;
270 static Window ppm_point;
271 static Window ps_point;
272 static Window color_point;
273 static Window grey_point;
274 static Window bw_point;
275 static Window portr_point;
276 static Window landsc_point;
277 static Window pa4_point;
278 static Window pb5_point;
279 static Window pa5_point;
280 static Window p11x17_point;
281 static Window p8x11_point;
282 static Window p8x14_point;
283 static Window scale1_point;
284 static Window maxspect_point;
285 static Window center_point;
286 static Window centerx_point;
287 static Window centery_point;
288 static Window dpi300_point;
289 static Window dpi400_point;
290 static Window dpi180_point;
291 static Window bbox_point;
292
293 static Window okay_button;
294 static Window cancel_button;
295
296 static Window pn1_point;
297 static Window pn2_point;
298 static Window pn3_point;
299 static Window pn4_point;
300 static Window pn5_point;
301
302 static Window xdpiscrollbar;
303 static Window ydpiscrollbar;
304 static Window scalescrollbar;
305 static Window widthscrollbar;
306 static Window heightscrollbar;
307
308 static Window xdpiscrolltmb;
309 static Window ydpiscrolltmb;
310 static Window scalescrolltmb;
311 static Window widthscrolltmb;
312 static Window heightscrolltmb;
313
314 static Window marginpanner;
315 static Window marginmiddle;
316 static Window margintmb;
317
318
319 /* Cursors */
320
321 static Cursor scrollCursor;
322
323 /* Mouse Buttons */
324
325 #define G_MOUSE_LEFT 1
326 #define G_MOUSE_RIGHT 3
327
328
329 /* the panel font */
330
331 extern char Xfontname[512];
332 static XFontStruct *dialog_font = NULL;
333
334 /* Flag wheter the dialog_box is initialized */
335
336 static int dialog_box_there = 0;
337
338
339 #define DIAL_W 540
340 #define DIAL_H 410
341
342 #define POINT_W 10
343
344 #define SCROLL_W 240
345 #define SCROLLBAR_LEN 20
346
347 #define PANNER_W 150
348 #define PANNER_H 150
349
350 /*--------------------------------------------------------------------*/
351 /* Dialog box initialization and entry points */
352 /*--------------------------------------------------------------------*/
353
354 /* Initialize the dialog box
355 * -------------------------
356 * This is done once at the beginning.
357 */
358
359 #ifdef ANSI_C
x11_init_dialog(Display * rd,int rs)360 void x11_init_dialog(Display *rd, int rs)
361 #else
362 void x11_init_dialog(rd, rs)
363 Display *rd;
364 int rs;
365 #endif
366 {
367 if (dialog_box_there) return;
368 root_display = rd;
369 root_screen = rs;
370 dialog_font = XLoadQueryFont(root_display,Xfontname);
371 if (!dialog_font) {
372 Fatal_error("Font not found. Please use option -font","");
373 }
374
375 allocateDialogBox();
376
377 dialog_box_there = 1;
378
379 }
380
381
382
383 /* Destroy the dialog box
384 * ----------------------
385 * This is done once on ExitDevice.
386 */
387
388 #ifdef ANSI_C
x11_destroy_dialog(Display * rd,int rs)389 void x11_destroy_dialog(Display *rd, int rs)
390 #else
391 void x11_destroy_dialog(rd, rs)
392 Display *rd;
393 int rs;
394 #endif
395 {
396 if (!dialog_box_there) return;
397 XDestroyWindow(root_display,dialog_window);
398 dialog_box_there = 0;
399 }
400
401
402
403 /* Allocate the Dialog Box
404 * -----------------------
405 * Scrollbar-Thumbs are returned in last_tmb;
406 */
407
408 static Window last_tmb;
409 static char x11_win_label[1024];
410
411 #ifdef ANSI_C
allocateDialogBox(void)412 static void allocateDialogBox(void)
413 #else
414 static void allocateDialogBox()
415 #endif
416 {
417 Window rret1, rret2;
418 XSetWindowAttributes attr;
419 unsigned long mask = 0L;
420 int i;
421 unsigned int j;
422 int xpos, ypos;
423 XSizeHints hints;
424
425 /* select for all events */
426 attr.event_mask = KeyPressMask |
427 ButtonPressMask | ButtonReleaseMask |
428 EnterWindowMask |
429 ExposureMask | StructureNotifyMask |
430 SubstructureNotifyMask |
431 FocusChangeMask | OwnerGrabButtonMask;
432
433 attr.background_pixel = XWhitePixel(root_display,root_screen);
434 attr.border_pixel = XBlackPixel(root_display,root_screen);
435
436 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
437
438 (void)XQueryPointer(root_display,RootWindow(root_display, root_screen),
439 &rret1, &rret2,&xpos, &ypos, &i, &i, &j);
440
441 xpos = xpos;
442 ypos = ypos;
443
444 dialog_window = XCreateWindow(root_display,
445 RootWindow(root_display, root_screen),
446 xpos, ypos,
447 DIAL_W, DIAL_H,
448 Xmyborderwidth, (int)CopyFromParent,
449 InputOutput,
450 (Visual *)CopyFromParent,
451 mask, &attr);
452
453 hints.flags = PPosition;
454 hints.x = xpos;
455 hints.y = ypos;
456
457 strcpy(x11_win_label, "VCG ");
458 strcat(x11_win_label, Dataname);
459 strcat(x11_win_label, " Export");
460
461 XStoreName(root_display, dialog_window, x11_win_label);
462 XSetNormalHints(root_display, dialog_window, &hints);
463
464 XDefineCursor(root_display,dialog_window,
465 XCreateFontCursor(root_display,XC_left_ptr));
466
467 scrollCursor = XCreateFontCursor(root_display,XC_sb_h_double_arrow);
468
469 pbm_point = allocate_selection_point(120,8);
470 ppm_point = allocate_selection_point(240,8);
471 ps_point = allocate_selection_point(360,8);
472 bw_point = allocate_selection_point(120,26);
473 color_point = allocate_selection_point(240,26);
474 grey_point = allocate_selection_point(360,26);
475 portr_point = allocate_selection_point(120,44);
476 landsc_point = allocate_selection_point(240,44);
477 pa4_point = allocate_selection_point(120,62);
478 pb5_point = allocate_selection_point(240,62);
479 pa5_point = allocate_selection_point(360,62);
480 p11x17_point = allocate_selection_point(120,80);
481 p8x11_point = allocate_selection_point(240,80);
482 p8x14_point = allocate_selection_point(360,80);
483
484 pn1_point = allocate_selection_point(350,268);
485 pn2_point = allocate_selection_point(400,268);
486 pn3_point = allocate_selection_point(450,268);
487 pn4_point = allocate_selection_point(350,286);
488 pn5_point = allocate_selection_point(400,286);
489
490 scale1_point = allocate_selection_point(180,250);
491 maxspect_point = allocate_selection_point(180,268);
492 center_point = allocate_selection_point(180,286);
493 centerx_point = allocate_selection_point(180,304);
494 centery_point = allocate_selection_point(180,322);
495 dpi300_point = allocate_selection_point(180,340);
496 dpi400_point = allocate_selection_point(180,358);
497 dpi180_point = allocate_selection_point(180,376);
498 bbox_point = allocate_selection_point(180,340);
499
500 cancel_button = allocate_button(350,320);
501 okay_button = allocate_button(350,365);
502
503 xdpiscrollbar = allocate_scroll_bar(280,152);
504 xdpiscrolltmb = last_tmb;
505 ydpiscrollbar = allocate_scroll_bar(280,170);
506 ydpiscrolltmb = last_tmb;
507 scalescrollbar = allocate_scroll_bar(280,188);
508 scalescrolltmb = last_tmb;
509 widthscrollbar = allocate_scroll_bar(280,206);
510 widthscrolltmb = last_tmb;
511 heightscrollbar = allocate_scroll_bar(280,224);
512 heightscrolltmb = last_tmb;
513
514 /* select for all events */
515 attr.event_mask = KeyPressMask | ButtonMotionMask |
516 ButtonPressMask | ButtonReleaseMask |
517 EnterWindowMask | LeaveWindowMask |
518 ExposureMask | ResizeRedirectMask |
519 SubstructureNotifyMask |
520 FocusChangeMask | OwnerGrabButtonMask;
521
522 attr.background_pixel = XBlackPixel(root_display,root_screen);
523 attr.border_pixel = XBlackPixel(root_display,root_screen);
524
525 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
526
527 marginpanner = XCreateWindow (root_display, dialog_window,
528 5,246,
529 PANNER_W+1, PANNER_H+1,
530 1, (int)CopyFromParent,
531 InputOutput,
532 (Visual *)CopyFromParent,
533 mask, &attr);
534
535 attr.background_pixel = XWhitePixel(root_display,root_screen);
536 attr.border_pixel = XBlackPixel(root_display,root_screen);
537
538 marginmiddle = XCreateWindow (root_display, marginpanner,
539 0,0,
540 PANNER_W-5, PANNER_H-5,
541 1, (int)CopyFromParent,
542 InputOutput,
543 (Visual *)CopyFromParent,
544 mask, &attr);
545 margintmb = XCreateWindow (root_display, marginmiddle,
546 5,5, 20, 20,
547 1, (int)CopyFromParent,
548 InputOutput,
549 (Visual *)CopyFromParent,
550 mask, &attr);
551
552 }
553
554
555
556 /* Allocate an selection point (button or radio button)
557 * ----------------------------------------------------
558 */
559
560 #ifdef ANSI_C
allocate_selection_point(int x,int y)561 static Window allocate_selection_point(int x,int y)
562 #else
563 static Window allocate_selection_point(x,y)
564 int x, y;
565 #endif
566 {
567 return(allocate_general_button(x,y,POINT_W,POINT_W));
568 }
569
570
571
572 /* Allocate an selection point (button or radio button)
573 * ----------------------------------------------------
574 */
575
576 #ifdef ANSI_C
allocate_button(int x,int y)577 static Window allocate_button(int x,int y)
578 #else
579 static Window allocate_button(x,y)
580 int x, y;
581 #endif
582 {
583 return(allocate_general_button(x,y,170,25));
584 }
585
586
587
588 /* Allocate a general button or point
589 * ----------------------------------
590 */
591
592 #ifdef ANSI_C
allocate_general_button(int x,int y,int w,int h)593 static Window allocate_general_button(int x,int y,int w,int h)
594 #else
595 static Window allocate_general_button(x,y,w,h)
596 int x, y, w, h;
597 #endif
598 {
599 Window ww;
600 XSetWindowAttributes attr;
601 unsigned long mask = 0L;
602
603 /* select for all events */
604 attr.event_mask = KeyPressMask |
605 ButtonPressMask | ButtonReleaseMask |
606 EnterWindowMask | LeaveWindowMask |
607 ExposureMask | StructureNotifyMask |
608 SubstructureNotifyMask |
609 FocusChangeMask | OwnerGrabButtonMask;
610
611 attr.background_pixel = XWhitePixel(root_display,root_screen);
612 attr.border_pixel = XBlackPixel(root_display,root_screen);
613
614 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
615
616 ww = XCreateWindow(root_display,
617 dialog_window,
618 x,y,
619 w,h,
620 1, (int)CopyFromParent,
621 InputOutput,
622 (Visual *)CopyFromParent,
623 mask, &attr);
624
625 return(ww);
626 }
627
628
629 /* Allocate a scroll bar
630 * ---------------------
631 */
632
633 #ifdef ANSI_C
allocate_scroll_bar(int x,int y)634 static Window allocate_scroll_bar(int x,int y)
635 #else
636 static Window allocate_scroll_bar(x,y)
637 int x, y;
638 #endif
639 {
640 Window w, wt;
641 XSetWindowAttributes attr;
642 unsigned long mask = 0L;
643
644 /* select for all events */
645 attr.event_mask = KeyPressMask | ButtonMotionMask |
646 ButtonPressMask | ButtonReleaseMask |
647 EnterWindowMask | LeaveWindowMask |
648 ExposureMask | ResizeRedirectMask |
649 SubstructureNotifyMask |
650 FocusChangeMask | OwnerGrabButtonMask;
651
652 attr.background_pixel = XWhitePixel(root_display,root_screen);
653 attr.border_pixel = XBlackPixel(root_display,root_screen);
654
655 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
656
657 w = XCreateWindow (root_display, dialog_window, x,y,
658 SCROLL_W, 8,
659 1, (int)CopyFromParent,
660 InputOutput,
661 (Visual *)CopyFromParent,
662 mask, &attr);
663 wt = XCreateSimpleWindow (root_display, w, 0,0,
664 SCROLLBAR_LEN, 6,
665 1,
666 XWhitePixel(root_display,root_screen),
667 XBlackPixel(root_display,root_screen));
668
669 XDefineCursor(root_display,w,scrollCursor);
670
671 last_tmb = wt;
672 return(w);
673 }
674
675
676 /*--------------------------------------------------------------------*/
677 /* Entry point for the dialog */
678 /*--------------------------------------------------------------------*/
679
680 static int box_exposed;
681 static int first_exposed = 1;
682
683 #ifdef ANSI_C
x11_print_dialog(int rminx,int rminy,int rmaxx,int rmaxy)684 void x11_print_dialog(int rminx,int rminy,int rmaxx,int rmaxy)
685 #else
686 void x11_print_dialog(rminx, rminy, rmaxx, rmaxy)
687 int rminx, rminy, rmaxx, rmaxy;
688 #endif
689 {
690 XEvent event;
691 int i, x, y;
692 Window rret1, rret2;
693 unsigned int j;
694
695 if (first_exposed) {
696 first_exposed = 0;
697 (void)XQueryPointer(root_display,RootWindow(root_display, root_screen),
698 &rret1, &rret2,&x, &y, &i, &i, &j);
699 XMoveWindow(root_display,dialog_window, x, y);
700 }
701
702 box_exposed = 0;
703 act_output_type = 0;
704 if ((rminx==0)&&(rminy==0)&&(rmaxx==0)&&(rmaxy==0)) return;
705
706 set_of_region(rminx, rminy, rmaxx, rmaxy);
707
708 XMapRaised(root_display, dialog_window);
709 XMapRaised(root_display, pbm_point);
710 XMapRaised(root_display, ppm_point);
711 XMapRaised(root_display, ps_point);
712 XMapRaised(root_display, color_point);
713 XMapRaised(root_display, grey_point);
714 XMapRaised(root_display, bw_point);
715 XMapRaised(root_display, portr_point);
716 XMapRaised(root_display, landsc_point);
717 XMapRaised(root_display, pa4_point);
718 XMapRaised(root_display, pb5_point);
719 XMapRaised(root_display, pa5_point);
720 XMapRaised(root_display, p11x17_point);
721 XMapRaised(root_display, p8x11_point);
722 XMapRaised(root_display, p8x14_point);
723 XMapRaised(root_display, scale1_point);
724 XMapRaised(root_display, maxspect_point);
725 XMapRaised(root_display, center_point);
726 XMapRaised(root_display, centerx_point);
727 XMapRaised(root_display, centery_point);
728 XMapRaised(root_display, dpi300_point);
729 XMapRaised(root_display, dpi400_point);
730 XMapRaised(root_display, dpi180_point);
731 XMapRaised(root_display, bbox_point);
732 XMapRaised(root_display, pn1_point);
733 XMapRaised(root_display, pn2_point);
734 XMapRaised(root_display, pn3_point);
735 XMapRaised(root_display, pn4_point);
736 XMapRaised(root_display, pn5_point);
737
738 XMapRaised(root_display, cancel_button);
739 XMapRaised(root_display, okay_button);
740
741 XMapRaised(root_display, xdpiscrollbar);
742 XMapRaised(root_display, xdpiscrolltmb);
743 XMapRaised(root_display, ydpiscrollbar);
744 XMapRaised(root_display, ydpiscrolltmb);
745 XMapRaised(root_display, scalescrollbar);
746 XMapRaised(root_display, scalescrolltmb);
747 XMapRaised(root_display, widthscrollbar);
748 XMapRaised(root_display, widthscrolltmb);
749 XMapRaised(root_display, heightscrollbar);
750 XMapRaised(root_display, heightscrolltmb);
751
752 XMapRaised(root_display, marginpanner);
753 XMapRaised(root_display, marginmiddle);
754 XMapRaised(root_display, margintmb);
755
756
757 act_output_type = 3;
758 act_color_type = 3;
759 act_ori_type = 1;
760 act_paper_type = 1;
761 act_paper_num = 1;
762 act_scaling = 1.0;
763 set_xdpi(72);
764 set_ydpi(72);
765
766 set_xdpiscrollbar();
767 set_ydpiscrollbar();
768 set_scalescrollbar();
769 set_widthscrollbar();
770 set_heightscrollbar();
771 set_marginpanner();
772 XFlush(root_display);
773
774 /*
775 * Wait for Exposure event.
776 */
777 #ifndef ULTRIX
778 #ifndef AIX
779 do { XNextEvent(root_display, &event);
780 } while (event.type != Expose && event.type != MapNotify);
781 #endif
782 #endif
783
784 draw_dialog_box();
785 dialog_main_loop();
786
787 XUnmapWindow(root_display, dialog_window);
788
789 if (dialog_success == 0) act_output_type = 0;
790 }
791
792
793
794 /*--------------------------------------------------------------------*/
795 /* Redraw routine */
796 /*--------------------------------------------------------------------*/
797
798 /* Draw dialog box
799 * ---------------
800 */
801
802 static char mxbuffer[256];
803
804 #ifdef ANSI_C
draw_dialog_box(void)805 static void draw_dialog_box(void)
806 #else
807 static void draw_dialog_box()
808 #endif
809 {
810 XSetForeground(root_display,
811 XDefaultGC(root_display, root_screen),
812 XWhitePixel(root_display, root_screen));
813 XFillRectangle(root_display,
814 (Drawable)dialog_window,
815 XDefaultGC(root_display, root_screen),
816 0,0, DIAL_W, DIAL_H);
817
818 XSetForeground(root_display,
819 XDefaultGC(root_display, root_screen),
820 XBlackPixel(root_display, root_screen));
821 XDrawString(root_display,
822 (Drawable)cancel_button,
823 XDefaultGC(root_display, root_screen),
824 30,18,"Cancel (Esc)",strlen("Cancel (Esc)"));
825 XDrawString(root_display,
826 (Drawable)okay_button,
827 XDefaultGC(root_display, root_screen),
828 65,18,"Okay",strlen("Okay"));
829
830 draw_text(5,18,"Export to ");
831 draw_text(140,18,"PBM(1)");
832 draw_text(260,18,"PPM(2)");
833 draw_text(380,18,"PostScript(3)");
834
835 draw_text(5,36,"Color mode:");
836
837 draw_text(5,54,"Orientation:");
838 draw_text(140,54,"portrait");
839 draw_text(260,54,"landscape");
840
841 draw_text(5,72,"Paper size:");
842 draw_text(140,72,"A4");
843 draw_text(260,72,"B5");
844 draw_text(380,72,"A5");
845 draw_text(140,90,"11\"x17\"");
846 draw_text(260,90,"8.5\"x11\"");
847 draw_text(380,90,"8.5\"x14\"");
848
849 draw_text(5,108,"Region:");
850 SPRINTF(mxbuffer,"(%d,%d) - (%d,%d) => %d X %d pixels",
851 rgx1,rgy1,rgx2,rgy2,
852 (rgx2>rgx1?rgx2-rgx1:rgx1-rgx2),
853 (rgy2>rgy1?rgy2-rgy1:rgy1-rgy2));
854 draw_text(100,108,mxbuffer);
855
856
857 draw_dialog_point(scale1_point, 0);
858 draw_text(200,260,"Scaling: 100%");
859 draw_dialog_point(maxspect_point, 0);
860 draw_text(200,278,"Maxspect");
861 draw_dialog_point(center_point, 0);
862 draw_text(200,296,"Center");
863 draw_dialog_point(centerx_point, 0);
864 draw_text(200,314,"Center width");
865 draw_dialog_point(centery_point, 0);
866 draw_text(200,332,"Center height");
867
868 switch (act_output_type) {
869 case 1: draw_dialog_point(pbm_point,1);
870 draw_dialog_point(ppm_point,0);
871 draw_dialog_point(ps_point, 0);
872 XUnmapWindow(root_display, bbox_point);
873 XUnmapWindow(root_display, pn1_point);
874 XUnmapWindow(root_display, pn2_point);
875 XUnmapWindow(root_display, pn3_point);
876 XUnmapWindow(root_display, pn4_point);
877 XUnmapWindow(root_display, pn5_point);
878 XUnmapWindow(root_display, grey_point);
879 XUnmapWindow(root_display, color_point);
880 act_color_type=3;
881 XMapRaised(root_display, bw_point);
882 draw_text(140,36,"b&w");
883 XMapRaised(root_display, dpi300_point);
884 draw_dialog_point(dpi300_point, 0);
885 draw_text(200,350,"XY-dpi: 300");
886 XMapRaised(root_display, dpi400_point);
887 draw_dialog_point(dpi400_point, 0);
888 draw_text(200,368,"XY-dpi: 400");
889 XMapRaised(root_display, dpi180_point);
890 draw_dialog_point(dpi180_point, 0);
891 draw_text(200,386,"XY-dpi: 180");
892 break;
893 case 2: draw_dialog_point(pbm_point,0);
894 draw_dialog_point(ppm_point,1);
895 draw_dialog_point(ps_point, 0);
896 XUnmapWindow(root_display, bbox_point);
897 XUnmapWindow(root_display, pn1_point);
898 XUnmapWindow(root_display, pn2_point);
899 XUnmapWindow(root_display, pn3_point);
900 XUnmapWindow(root_display, pn4_point);
901 XUnmapWindow(root_display, pn5_point);
902 XUnmapWindow(root_display, grey_point);
903 XUnmapWindow(root_display, bw_point);
904 act_color_type=1;
905 XMapRaised(root_display, color_point);
906 draw_text(260,36,"full color");
907 XMapRaised(root_display, dpi300_point);
908 draw_dialog_point(dpi300_point, 0);
909 draw_text(200,350,"XY-dpi: 300");
910 XMapRaised(root_display, dpi400_point);
911 draw_dialog_point(dpi400_point, 0);
912 draw_text(200,368,"XY-dpi: 400");
913 XMapRaised(root_display, dpi180_point);
914 draw_dialog_point(dpi180_point, 0);
915 draw_text(200,386,"XY-dpi: 180");
916 break;
917 case 3: draw_dialog_point(pbm_point,0);
918 draw_dialog_point(ppm_point,0);
919 draw_dialog_point(ps_point, 1);
920 XMapRaised(root_display, pn1_point);
921 XMapRaised(root_display, pn2_point);
922 XMapRaised(root_display, pn3_point);
923 XMapRaised(root_display, pn4_point);
924 XMapRaised(root_display, pn5_point);
925 draw_text(350,260,"Split output into");
926 draw_text(370,278,"1");
927 draw_text(420,278,"4");
928 draw_text(470,278,"9");
929 draw_text(370,296,"16");
930 draw_text(420,296,"25 pages");
931 XMapRaised(root_display, grey_point);
932 XMapRaised(root_display, color_point);
933 XMapRaised(root_display, bw_point);
934 draw_text(380,36,"grey");
935 draw_text(260,36,"full color");
936 draw_text(140,36,"b&w");
937 set_xdpi(72);
938 set_ydpi(72);
939 XMapRaised(root_display, bbox_point);
940 draw_dialog_point(bbox_point, act_bbox);
941 draw_text(200,350,"Bounding Box");
942 XUnmapWindow(root_display, dpi300_point);
943 XUnmapWindow(root_display, dpi400_point);
944 XUnmapWindow(root_display, dpi180_point);
945 break;
946 }
947
948 switch (act_color_type) {
949 case 1: draw_dialog_point(color_point,1);
950 draw_dialog_point(grey_point, 0);
951 draw_dialog_point(bw_point, 0);
952 break;
953 case 2: draw_dialog_point(color_point,0);
954 draw_dialog_point(grey_point, 1);
955 draw_dialog_point(bw_point, 0);
956 break;
957 case 3: draw_dialog_point(color_point,0);
958 draw_dialog_point(grey_point, 0);
959 draw_dialog_point(bw_point, 1);
960 break;
961 }
962
963 switch (act_ori_type) {
964 case 1: draw_dialog_point(portr_point, 1);
965 draw_dialog_point(landsc_point,0);
966 break;
967 case 2: draw_dialog_point(portr_point, 0);
968 draw_dialog_point(landsc_point,1);
969 break;
970 }
971
972 switch (act_paper_type) {
973 case 1: draw_dialog_point(pa4_point, 1);
974 draw_dialog_point(pb5_point, 0);
975 draw_dialog_point(pa5_point, 0);
976 draw_dialog_point(p11x17_point, 0);
977 draw_dialog_point(p8x11_point, 0);
978 draw_dialog_point(p8x14_point, 0);
979 break;
980 case 2: draw_dialog_point(pa4_point, 0);
981 draw_dialog_point(pb5_point, 1);
982 draw_dialog_point(pa5_point, 0);
983 draw_dialog_point(p11x17_point, 0);
984 draw_dialog_point(p8x11_point, 0);
985 draw_dialog_point(p8x14_point, 0);
986 break;
987 case 3: draw_dialog_point(pa4_point, 0);
988 draw_dialog_point(pb5_point, 0);
989 draw_dialog_point(pa5_point, 1);
990 draw_dialog_point(p11x17_point, 0);
991 draw_dialog_point(p8x11_point, 0);
992 draw_dialog_point(p8x14_point, 0);
993 break;
994 case 4: draw_dialog_point(pa4_point, 0);
995 draw_dialog_point(pb5_point, 0);
996 draw_dialog_point(pa5_point, 0);
997 draw_dialog_point(p11x17_point, 1);
998 draw_dialog_point(p8x11_point, 0);
999 draw_dialog_point(p8x14_point, 0);
1000 break;
1001 case 5: draw_dialog_point(pa4_point, 0);
1002 draw_dialog_point(pb5_point, 0);
1003 draw_dialog_point(pa5_point, 0);
1004 draw_dialog_point(p11x17_point, 0);
1005 draw_dialog_point(p8x11_point, 1);
1006 draw_dialog_point(p8x14_point, 0);
1007 break;
1008 case 6: draw_dialog_point(pa4_point, 0);
1009 draw_dialog_point(pb5_point, 0);
1010 draw_dialog_point(pa5_point, 0);
1011 draw_dialog_point(p11x17_point, 0);
1012 draw_dialog_point(p8x11_point, 0);
1013 draw_dialog_point(p8x14_point, 1);
1014 break;
1015 }
1016
1017 switch (act_paper_num) {
1018 case 1: draw_dialog_point(pn1_point, 1);
1019 draw_dialog_point(pn2_point, 0);
1020 draw_dialog_point(pn3_point, 0);
1021 draw_dialog_point(pn4_point, 0);
1022 draw_dialog_point(pn5_point, 0);
1023 break;
1024 case 2: draw_dialog_point(pn1_point, 0);
1025 draw_dialog_point(pn2_point, 1);
1026 draw_dialog_point(pn3_point, 0);
1027 draw_dialog_point(pn4_point, 0);
1028 draw_dialog_point(pn5_point, 0);
1029 break;
1030 case 3: draw_dialog_point(pn1_point, 0);
1031 draw_dialog_point(pn2_point, 0);
1032 draw_dialog_point(pn3_point, 1);
1033 draw_dialog_point(pn4_point, 0);
1034 draw_dialog_point(pn5_point, 0);
1035 break;
1036 case 4: draw_dialog_point(pn1_point, 0);
1037 draw_dialog_point(pn2_point, 0);
1038 draw_dialog_point(pn3_point, 0);
1039 draw_dialog_point(pn4_point, 1);
1040 draw_dialog_point(pn5_point, 0);
1041 break;
1042 case 5: draw_dialog_point(pn1_point, 0);
1043 draw_dialog_point(pn2_point, 0);
1044 draw_dialog_point(pn3_point, 0);
1045 draw_dialog_point(pn4_point, 0);
1046 draw_dialog_point(pn5_point, 1);
1047 break;
1048 }
1049
1050 draw_text(5,126,"Margins:");
1051 draw_text(5,162,"X-dpi:");
1052 draw_text(5,180,"Y-dpi:");
1053 draw_text(5,198,"Scaling:");
1054 draw_text(5,216,"Width:");
1055 draw_text(5,234,"Height:");
1056
1057 draw_sizes();
1058 set_xdpiscrollbar();
1059 set_ydpiscrollbar();
1060 set_scalescrollbar();
1061 set_widthscrollbar();
1062 set_heightscrollbar();
1063 set_marginpanner();
1064
1065 XSync(root_display, 0);
1066 }
1067
1068
1069
1070 #ifdef ANSI_C
draw_sizes(void)1071 static void draw_sizes(void)
1072 #else
1073 static void draw_sizes()
1074 #endif
1075 {
1076 if (act_paper_num>1) {
1077 act_left_margin =1.0;
1078 act_bottom_margin =1.0;
1079 act_right_margin = maxx - act_width -act_left_margin;
1080 act_top_margin = maxy - act_height-act_bottom_margin;
1081 }
1082 if (act_output_type==3) {
1083 set_xdpi(72);
1084 set_ydpi(72);
1085 set_xdpiscrollbar();
1086 set_ydpiscrollbar();
1087 set_widthscrollbar();
1088 set_heightscrollbar();
1089 }
1090 XSetForeground(root_display,
1091 XDefaultGC(root_display, root_screen),
1092 XWhitePixel(root_display, root_screen));
1093 XFillRectangle(root_display,
1094 (Drawable)dialog_window,
1095 XDefaultGC(root_display, root_screen),
1096 100,112,DIAL_W-100,18);
1097 XFillRectangle(root_display,
1098 (Drawable)dialog_window,
1099 XDefaultGC(root_display, root_screen),
1100 100,130,DIAL_W-100,18);
1101
1102 XFillRectangle(root_display,
1103 (Drawable)dialog_window,
1104 XDefaultGC(root_display, root_screen),
1105 100,148,170,18);
1106 XFillRectangle(root_display,
1107 (Drawable)dialog_window,
1108 XDefaultGC(root_display, root_screen),
1109 100,166,170,18);
1110 XFillRectangle(root_display,
1111 (Drawable)dialog_window,
1112 XDefaultGC(root_display, root_screen),
1113 100,184,170,18);
1114 XFillRectangle(root_display,
1115 (Drawable)dialog_window,
1116 XDefaultGC(root_display, root_screen),
1117 100,202,170,18);
1118 XFillRectangle(root_display,
1119 (Drawable)dialog_window,
1120 XDefaultGC(root_display, root_screen),
1121 100,220,170,18);
1122
1123 calc_paper_size();
1124
1125 act_right_margin = maxx - act_width -act_left_margin;
1126 act_top_margin = maxy - act_height-act_bottom_margin;
1127
1128 if (act_right_margin<0) {
1129 act_right_margin = 0.0;
1130 act_left_margin = maxx - act_width -act_right_margin;
1131 }
1132 if (act_left_margin<0) {
1133 act_left_margin = 0.0;
1134 act_right_margin = maxx - act_width -act_left_margin;
1135 }
1136 if (act_bottom_margin<0) {
1137 act_bottom_margin = 0.0;
1138 act_top_margin = maxy - act_height-act_bottom_margin;
1139 }
1140 if (act_top_margin<0) {
1141 act_top_margin = 0.0;
1142 act_bottom_margin = maxy - act_height-act_top_margin;
1143 }
1144
1145 SPRINTF(mxbuffer, "Left: %3.2fcm/%3.2f\" ",
1146 act_left_margin, act_left_margin/2.54);
1147 draw_text(100,126,mxbuffer);
1148 SPRINTF(mxbuffer, "Right: %3.2fcm/%3.2f\" ",
1149 act_right_margin, act_right_margin/2.54);
1150 draw_text(320,126,mxbuffer);
1151 SPRINTF(mxbuffer, "Top: %3.2fcm/%3.2f\" ",
1152 act_top_margin, act_top_margin/2.54);
1153 draw_text(100,144,mxbuffer);
1154 SPRINTF(mxbuffer, "Bottom: %3.2fcm/%3.2f\" ",
1155 act_bottom_margin, act_bottom_margin/2.54);
1156 draw_text(320,144,mxbuffer);
1157
1158 if (act_output_type==3) SPRINTF(mxbuffer, "---");
1159 else SPRINTF(mxbuffer, "%d",act_xdpi);
1160 draw_text(100,162,mxbuffer);
1161 if (act_output_type==3) SPRINTF(mxbuffer, "---");
1162 else SPRINTF(mxbuffer, "%d",act_ydpi);
1163 draw_text(100,180,mxbuffer);
1164 SPRINTF(mxbuffer, "%3.2f %% ", act_scaling*100.0);
1165 draw_text(100,198,mxbuffer);
1166 SPRINTF(mxbuffer, "%3.2fcm/%3.2f\" ",
1167 act_width, act_width/2.54);
1168 draw_text(100,216,mxbuffer);
1169 SPRINTF(mxbuffer, "%3.2fcm/%3.2f\" ",
1170 act_height, act_height/2.54);
1171 draw_text(100,234,mxbuffer);
1172 /* XSync(root_display, 0); */
1173 }
1174
1175
1176
1177 /* Draw text m into the dialog box at position x, y
1178 * ------------------------------------------------
1179 */
1180
1181 #ifdef ANSI_C
draw_text(int x,int y,char * m)1182 static void draw_text(int x,int y,char *m)
1183 #else
1184 static void draw_text(x,y, m)
1185 int x, y;
1186 char *m;
1187 #endif
1188 {
1189 XSetForeground(root_display,
1190 XDefaultGC(root_display, root_screen),
1191 XBlackPixel(root_display, root_screen));
1192 XDrawString(root_display,
1193 (Drawable)dialog_window,
1194 XDefaultGC(root_display, root_screen),
1195 x,y,m,strlen(m));
1196 }
1197
1198
1199 /* Draw a dialog point in a color
1200 * ------------------------------
1201 */
1202
1203 #ifdef ANSI_C
draw_dialog_point(Window w,int color)1204 static void draw_dialog_point(Window w,int color)
1205 #else
1206 static void draw_dialog_point(w, color)
1207 Window w;
1208 int color;
1209 #endif
1210 {
1211 if (color==0) {
1212 XSetForeground(root_display,
1213 XDefaultGC(root_display, root_screen),
1214 XWhitePixel(root_display, root_screen));
1215 }
1216 else {
1217 XSetForeground(root_display,
1218 XDefaultGC(root_display, root_screen),
1219 XBlackPixel(root_display, root_screen));
1220 }
1221 XFillRectangle(root_display,(Drawable)w,
1222 XDefaultGC(root_display, root_screen),
1223 1,1,
1224 POINT_W-2,POINT_W-2);
1225 /* XSync(root_display, 0); */
1226 XFlush(root_display);
1227 }
1228
1229
1230 /*--------------------------------------------------------------------*/
1231 /* Event handling */
1232 /*--------------------------------------------------------------------*/
1233
1234 /* The main loop for interaction
1235 * =============================
1236 */
1237
1238 #ifdef ANSI_C
dialog_main_loop(void)1239 static void dialog_main_loop(void)
1240 #else
1241 static void dialog_main_loop()
1242 #endif
1243 {
1244 XEvent event;
1245
1246 dialog_notready = 1;
1247 dialog_success = 0;
1248 while (dialog_notready) {
1249
1250 XNextEvent (root_display, &event);
1251
1252 if (event.type != Expose)
1253 box_exposed = 0;
1254
1255 switch (event.type) {
1256 case KeyPress:
1257 prologue (&event, "KeyPress");
1258 do_KeyPress (&event);
1259 break;
1260 case ButtonPress:
1261 prologue (&event, "ButtonPress");
1262 do_ButtonPress (&event);
1263 break;
1264 case ButtonRelease:
1265 prologue (&event, "ButtonRelease");
1266 do_ButtonRelease (&event);
1267 break;
1268 case EnterNotify:
1269 prologue (&event, "EnterNotify");
1270 do_EnterNotify(&event);
1271 break;
1272 case LeaveNotify:
1273 prologue (&event, "LeaveNotify");
1274 do_LeaveNotify(&event);
1275 break;
1276 case FocusIn:
1277 prologue (&event, "FocusIn");
1278 break;
1279 case FocusOut:
1280 prologue (&event, "FocusOut");
1281 break;
1282 case Expose:
1283 prologue (&event, "Expose");
1284 do_Expose (&event);
1285 break;
1286 case ConfigureNotify:
1287 prologue (&event, "ConfigureNotify");
1288 do_ConfigureNotify (&event);
1289 break;
1290 case MotionNotify:
1291 prologue (&event, "MotionNotify");
1292 do_MotionNotify(&event);
1293 break;
1294 case GravityNotify:
1295 case CirculateRequest:
1296 case PropertyNotify:
1297 case SelectionClear:
1298 case SelectionRequest:
1299 case SelectionNotify:
1300 case ColormapNotify:
1301 case ClientMessage:
1302 case MappingNotify:
1303 case CreateNotify:
1304 case DestroyNotify:
1305 case CirculateNotify:
1306 case VisibilityNotify:
1307 case KeyRelease:
1308 case KeymapNotify:
1309 case NoExpose:
1310 case GraphicsExpose:
1311 prologue (&event, "Unhandled");
1312 break;
1313 }
1314 }
1315 }
1316
1317
1318 #ifdef EVENT_DEBUG
1319
1320 /* For debugging only: Print event message
1321 * ---------------------------------------
1322 */
1323
1324 #ifdef ANSI_C
prologue(XEvent * eventp,char * event_name)1325 static void prologue (XEvent *eventp, char *event_name)
1326 #else
1327 static void prologue (eventp, event_name)
1328 XEvent *eventp;
1329 char *event_name;
1330 #endif
1331 {
1332 XAnyEvent *e = (XAnyEvent *) eventp;
1333
1334 PRINTF ("\n%s event, serial %ld, synthetic %s, window 0x%lx,\n",
1335 event_name, e->serial, e->send_event ? "Yes" : "No", e->window);
1336 }
1337
1338 #endif /* EVENT_DEBUG */
1339
1340
1341
1342 /* Keypress Events
1343 * ---------------
1344 */
1345
1346 #ifdef ANSI_C
do_KeyPress(XEvent * eventp)1347 static void do_KeyPress (XEvent *eventp)
1348 #else
1349 static void do_KeyPress (eventp)
1350 XEvent *eventp;
1351 #endif
1352 {
1353 XKeyEvent *e = (XKeyEvent *) eventp;
1354 KeySym ks;
1355 int nbytes, i;
1356 char str[256+1];
1357
1358 nbytes = XLookupString (e, str, 256, &ks, NULL);
1359 if (nbytes < 0) nbytes = 0;
1360 if (nbytes > 256) nbytes = 256;
1361 str[nbytes] = '\0';
1362
1363 i = 0;
1364 if (nbytes==1) {
1365 switch (str[0]) {
1366 case '1': /* PBM */
1367 act_output_type = 1;
1368 break;
1369 case '2': /* PPM */
1370 act_output_type = 2;
1371 break;
1372 case '3': /* PostScript */
1373 act_output_type = 3;
1374 break;
1375 case 'F': /* full color */
1376 case 'f': /* full color */
1377 act_color_type = 1;
1378 break;
1379 case 'G': /* grey */
1380 case 'g': /* grey */
1381 act_color_type = 2;
1382 break;
1383 case 'B': /* b&w */
1384 case 'b': /* b&w */
1385 act_color_type = 3;
1386 break;
1387 case 'P': /* portrait */
1388 case 'p': /* portrait */
1389 act_ori_type = 1;
1390 break;
1391 case 'L': /* landscape */
1392 case 'l': /* landscape */
1393 act_ori_type = 2;
1394 break;
1395 case 'S': /* scaling: 1 */
1396 case 's': /* scaling: 1 */
1397 set_of_scaling(1.0);
1398 break;
1399 case 'M': /* maxspect */
1400 case 'm': /* maxspect */
1401 set_of_maxspect();
1402 break;
1403 case 'C': /* center */
1404 case 'c': /* center */
1405 set_of_centerx();
1406 set_of_centery();
1407 break;
1408 case '\r': /* Carriage Return */
1409 case '\n': /* Carriage Return */
1410 dialog_notready = 0;
1411 dialog_success = 1;
1412 return;
1413 case 27: /* Cancel */
1414 dialog_notready = 0;
1415 dialog_success = 0;
1416 return;
1417 case 'q': /* Quit */
1418 case 'Q': /* Quit */
1419 dialog_notready = 0;
1420 dialog_success = 0;
1421 return;
1422 }
1423 draw_dialog_box();
1424 }
1425 }
1426
1427
1428
1429
1430 /* Button Press
1431 * ------------
1432 */
1433
1434 static Window act_scroll_window = 0;
1435
1436 #ifdef ANSI_C
do_ButtonPress(XEvent * eventp)1437 static void do_ButtonPress (XEvent *eventp)
1438 #else
1439 static void do_ButtonPress (eventp)
1440 XEvent *eventp;
1441 #endif
1442 {
1443 XButtonEvent *e = (XButtonEvent *) eventp;
1444 Window w;
1445 int old_output_type, old_color_type, old_ori_type;
1446 int old_paper_type, old_paper_num;
1447
1448 w = e->window;
1449
1450 old_output_type = act_output_type;
1451 old_color_type = act_color_type;
1452 old_ori_type = act_ori_type;
1453 old_paper_type = act_paper_type;
1454 old_paper_num = act_paper_num;
1455
1456 act_scroll_window = w;
1457 if (act_scroll_window==xdpiscrollbar) {
1458 read_xdpiscrollbar(e->x);
1459 draw_sizes();
1460 }
1461 else if (act_scroll_window==ydpiscrollbar) {
1462 read_ydpiscrollbar(e->x);
1463 draw_sizes();
1464 }
1465 else if (act_scroll_window==scalescrollbar) {
1466 read_scalescrollbar(e->x);
1467 draw_sizes();
1468 }
1469 else if (act_scroll_window==widthscrollbar) {
1470 read_widthscrollbar(e->x);
1471 draw_sizes();
1472 }
1473 else if (act_scroll_window==heightscrollbar) {
1474 read_heightscrollbar(e->x);
1475 draw_sizes();
1476 }
1477 else if (act_scroll_window==margintmb) {
1478 read_marginpanner(e->x,e->y);
1479 draw_sizes();
1480 }
1481 else if (act_scroll_window==marginmiddle) {
1482 read_marginxpanner(e->x,e->y);
1483 draw_sizes();
1484 }
1485
1486 if (w==pbm_point) act_output_type = 1;
1487 else if (w==ppm_point) act_output_type = 2;
1488 else if (w==ps_point) act_output_type = 3;
1489 else if (w==pn1_point) act_paper_num = 1;
1490 else if (w==pn2_point) act_paper_num = 2;
1491 else if (w==pn3_point) act_paper_num = 3;
1492 else if (w==pn4_point) act_paper_num = 4;
1493 else if (w==pn5_point) act_paper_num = 5;
1494 else if (w==color_point) act_color_type = 1;
1495 else if (w==grey_point) act_color_type = 2;
1496 else if (w==bw_point) act_color_type = 3;
1497 else if (w==portr_point) act_ori_type = 1;
1498 else if (w==landsc_point) act_ori_type = 2;
1499 else if (w==pa4_point) act_paper_type = 1;
1500 else if (w==pb5_point) act_paper_type = 2;
1501 else if (w==pa5_point) act_paper_type = 3;
1502 else if (w==p11x17_point) act_paper_type = 4;
1503 else if (w==p8x11_point) act_paper_type = 5;
1504 else if (w==p8x14_point) act_paper_type = 6;
1505 else if (w==scale1_point) {
1506 set_of_scaling(1.0);
1507 draw_dialog_box();
1508 }
1509 else if (w==maxspect_point) {
1510 set_of_maxspect();
1511 draw_dialog_box();
1512 }
1513 else if (w==center_point) {
1514 set_of_centerx();
1515 set_of_centery();
1516 draw_dialog_box();
1517 }
1518 else if (w==centerx_point) {
1519 set_of_centerx();
1520 draw_dialog_box();
1521 }
1522 else if (w==centery_point) {
1523 set_of_centery();
1524 draw_dialog_box();
1525 }
1526 else if (w==dpi300_point) {
1527 set_xdpi(300);
1528 set_ydpi(300);
1529 draw_dialog_box();
1530 }
1531 else if (w==dpi400_point) {
1532 set_xdpi(400);
1533 set_ydpi(400);
1534 draw_dialog_box();
1535 }
1536 else if (w==dpi180_point) {
1537 set_xdpi(180);
1538 set_ydpi(180);
1539 draw_dialog_box();
1540 }
1541 else if (w==bbox_point) {
1542 act_bbox = 1-act_bbox;
1543 draw_dialog_box();
1544 }
1545 else if (w==okay_button) {
1546 dialog_notready = 0;
1547 dialog_success = 1;
1548 }
1549 else if (w==cancel_button) {
1550 dialog_notready = 0;
1551 dialog_success = 0;
1552 }
1553
1554 if (old_output_type != act_output_type) {
1555 switch (act_output_type) {
1556 case 1: draw_dialog_point(pbm_point,1);
1557 draw_dialog_point(ppm_point,0);
1558 draw_dialog_point(ps_point, 0);
1559 set_xdpi(300);
1560 set_ydpi(300);
1561 act_paper_num = 1;
1562 calc_paper_size();
1563 act_left_margin =0.0;
1564 act_top_margin =0.0;
1565 act_right_margin = maxx - act_width -act_left_margin;
1566 act_bottom_margin = maxy - act_height-act_top_margin;
1567 break;
1568 case 2: draw_dialog_point(pbm_point,0);
1569 draw_dialog_point(ppm_point,1);
1570 draw_dialog_point(ps_point, 0);
1571 set_xdpi(300);
1572 set_ydpi(300);
1573 act_paper_num = 1;
1574 calc_paper_size();
1575 act_left_margin =0.0;
1576 act_top_margin =0.0;
1577 act_right_margin = maxx - act_width -act_left_margin;
1578 act_bottom_margin = maxy - act_height-act_top_margin;
1579 break;
1580 case 3: draw_dialog_point(pbm_point,0);
1581 draw_dialog_point(ppm_point,0);
1582 draw_dialog_point(ps_point, 1);
1583 set_xdpi(72);
1584 set_ydpi(72);
1585 break;
1586 }
1587 }
1588 if (old_paper_num != act_paper_num) {
1589 switch (act_paper_num) {
1590 case 1: draw_dialog_point(pn1_point, 1);
1591 draw_dialog_point(pn2_point, 0);
1592 draw_dialog_point(pn3_point, 0);
1593 draw_dialog_point(pn4_point, 0);
1594 draw_dialog_point(pn5_point, 0);
1595 break;
1596 case 2: draw_dialog_point(pn1_point, 0);
1597 draw_dialog_point(pn2_point, 1);
1598 draw_dialog_point(pn3_point, 0);
1599 draw_dialog_point(pn4_point, 0);
1600 draw_dialog_point(pn5_point, 0);
1601 break;
1602 case 3: draw_dialog_point(pn1_point, 0);
1603 draw_dialog_point(pn2_point, 0);
1604 draw_dialog_point(pn3_point, 1);
1605 draw_dialog_point(pn4_point, 0);
1606 draw_dialog_point(pn5_point, 0);
1607 break;
1608 case 4: draw_dialog_point(pn1_point, 0);
1609 draw_dialog_point(pn2_point, 0);
1610 draw_dialog_point(pn3_point, 0);
1611 draw_dialog_point(pn4_point, 1);
1612 draw_dialog_point(pn5_point, 0);
1613 break;
1614 case 5: draw_dialog_point(pn1_point, 0);
1615 draw_dialog_point(pn2_point, 0);
1616 draw_dialog_point(pn3_point, 0);
1617 draw_dialog_point(pn4_point, 0);
1618 draw_dialog_point(pn5_point, 1);
1619 break;
1620 }
1621 }
1622 if (old_color_type != act_color_type) {
1623 switch (act_color_type) {
1624 case 1: draw_dialog_point(color_point,1);
1625 draw_dialog_point(grey_point, 0);
1626 draw_dialog_point(bw_point, 0);
1627 break;
1628 case 2: draw_dialog_point(color_point,0);
1629 draw_dialog_point(grey_point, 1);
1630 draw_dialog_point(bw_point, 0);
1631 break;
1632 case 3: draw_dialog_point(color_point,0);
1633 draw_dialog_point(grey_point, 0);
1634 draw_dialog_point(bw_point, 1);
1635 break;
1636 }
1637 }
1638 if (old_ori_type != act_ori_type) {
1639 switch (act_ori_type) {
1640 case 1: draw_dialog_point(portr_point, 1);
1641 draw_dialog_point(landsc_point,0);
1642 break;
1643 case 2: draw_dialog_point(portr_point, 0);
1644 draw_dialog_point(landsc_point,1);
1645 break;
1646 }
1647 }
1648 if (old_paper_type != act_paper_type) {
1649 switch (act_paper_type) {
1650 case 1: draw_dialog_point(pa4_point, 1);
1651 draw_dialog_point(pb5_point, 0);
1652 draw_dialog_point(pa5_point, 0);
1653 draw_dialog_point(p11x17_point, 0);
1654 draw_dialog_point(p8x11_point, 0);
1655 draw_dialog_point(p8x14_point, 0);
1656 break;
1657 case 2: draw_dialog_point(pa4_point, 0);
1658 draw_dialog_point(pb5_point, 1);
1659 draw_dialog_point(pa5_point, 0);
1660 draw_dialog_point(p11x17_point, 0);
1661 draw_dialog_point(p8x11_point, 0);
1662 draw_dialog_point(p8x14_point, 0);
1663 break;
1664 case 3: draw_dialog_point(pa4_point, 0);
1665 draw_dialog_point(pb5_point, 0);
1666 draw_dialog_point(pa5_point, 1);
1667 draw_dialog_point(p11x17_point, 0);
1668 draw_dialog_point(p8x11_point, 0);
1669 draw_dialog_point(p8x14_point, 0);
1670 break;
1671 case 4: draw_dialog_point(pa4_point, 0);
1672 draw_dialog_point(pb5_point, 0);
1673 draw_dialog_point(pa5_point, 0);
1674 draw_dialog_point(p11x17_point, 1);
1675 draw_dialog_point(p8x11_point, 0);
1676 draw_dialog_point(p8x14_point, 0);
1677 break;
1678 case 5: draw_dialog_point(pa4_point, 0);
1679 draw_dialog_point(pb5_point, 0);
1680 draw_dialog_point(pa5_point, 0);
1681 draw_dialog_point(p11x17_point, 0);
1682 draw_dialog_point(p8x11_point, 1);
1683 draw_dialog_point(p8x14_point, 0);
1684 break;
1685 case 6: draw_dialog_point(pa4_point, 0);
1686 draw_dialog_point(pb5_point, 0);
1687 draw_dialog_point(pa5_point, 0);
1688 draw_dialog_point(p11x17_point, 0);
1689 draw_dialog_point(p8x11_point, 0);
1690 draw_dialog_point(p8x14_point, 1);
1691 break;
1692 }
1693 }
1694 if ( (old_output_type != act_output_type)
1695 ||(old_paper_type != act_paper_type)
1696 ||(old_paper_num != act_paper_num)
1697 ||(old_ori_type != act_ori_type)) {
1698 draw_dialog_box();
1699 }
1700 }
1701
1702
1703
1704 /* Button Release
1705 * --------------
1706 */
1707
1708 #ifdef ANSI_C
do_ButtonRelease(XEvent * eventp)1709 static void do_ButtonRelease (XEvent *eventp)
1710 #else
1711 static void do_ButtonRelease (eventp)
1712 XEvent *eventp;
1713 #endif
1714 {
1715 XButtonEvent *e = (XButtonEvent *) eventp;
1716
1717 if (act_scroll_window && (e->window!=act_scroll_window)) {
1718 set_xdpiscrollbar();
1719 set_ydpiscrollbar();
1720 set_scalescrollbar();
1721 set_widthscrollbar();
1722 set_heightscrollbar();
1723 set_marginpanner();
1724 draw_dialog_box();
1725 act_scroll_window = 0;
1726 return;
1727 }
1728 if (act_scroll_window==xdpiscrollbar)
1729 read_xdpiscrollbar(e->x);
1730 else if (act_scroll_window==ydpiscrollbar)
1731 read_ydpiscrollbar(e->x);
1732 else if (act_scroll_window==scalescrollbar)
1733 read_scalescrollbar(e->x);
1734 else if (act_scroll_window==widthscrollbar)
1735 read_widthscrollbar(e->x);
1736 else if (act_scroll_window==heightscrollbar)
1737 read_heightscrollbar(e->x);
1738 else if (act_scroll_window==margintmb)
1739 read_marginpanner(e->x,e->y);
1740 else if (act_scroll_window==marginmiddle)
1741 read_marginxpanner(e->x,e->y);
1742 else return;
1743 draw_dialog_box();
1744 act_scroll_window = 0;
1745 }
1746
1747
1748
1749 /* Mark a selection point as selectable
1750 * ------------------------------------
1751 */
1752
1753 #ifdef ANSI_C
do_EnterNotify(XEvent * eventp)1754 static void do_EnterNotify (XEvent *eventp)
1755 #else
1756 static void do_EnterNotify (eventp)
1757 XEvent *eventp;
1758 #endif
1759 {
1760 XCrossingEvent *e = (XCrossingEvent *) eventp;
1761 Window w;
1762 XWindowAttributes retWinAttr;
1763
1764 w = e->window;
1765 if ( (w==pbm_point)
1766 ||(w==ppm_point)
1767 ||(w==ps_point)
1768 ||(w==pn1_point)
1769 ||(w==pn2_point)
1770 ||(w==pn3_point)
1771 ||(w==pn4_point)
1772 ||(w==pn5_point)
1773 ||(w==color_point)
1774 ||(w==grey_point)
1775 ||(w==bw_point)
1776 ||(w==pa4_point)
1777 ||(w==pb5_point)
1778 ||(w==pa5_point)
1779 ||(w==p11x17_point)
1780 ||(w==p8x11_point)
1781 ||(w==p8x14_point)
1782 ||(w==scale1_point)
1783 ||(w==maxspect_point)
1784 ||(w==center_point)
1785 ||(w==centerx_point)
1786 ||(w==centery_point)
1787 ||(w==okay_button)
1788 ||(w==cancel_button)
1789 ||(w==dpi180_point)
1790 ||(w==dpi300_point)
1791 ||(w==dpi400_point)
1792 ||(w==bbox_point)
1793 ||(w==portr_point)
1794 ||(w==landsc_point)) {
1795 if (!XGetWindowAttributes(root_display,w,&retWinAttr)) {
1796 FPRINTF(stderr,"Can't get window attributes.");
1797 gs_exit(1);
1798 }
1799 if (retWinAttr.border_width==1) {
1800 XMoveWindow(root_display,w,
1801 retWinAttr.x-2, retWinAttr.y-2);
1802 }
1803 XSetWindowBorderWidth(root_display, w, 3L);
1804 }
1805 }
1806
1807
1808 /* Unmark a selection point
1809 * ------------------------
1810 * The menupoint is not anymore selected.
1811 */
1812
1813 #ifdef ANSI_C
do_LeaveNotify(XEvent * eventp)1814 static void do_LeaveNotify (XEvent *eventp)
1815 #else
1816 static void do_LeaveNotify (eventp)
1817 XEvent *eventp;
1818 #endif
1819 {
1820 XCrossingEvent *e = (XCrossingEvent *) eventp;
1821 Window w;
1822 XWindowAttributes retWinAttr;
1823
1824 w = e->window;
1825 if ( (w==pbm_point)
1826 ||(w==ppm_point)
1827 ||(w==ps_point)
1828 ||(w==pn1_point)
1829 ||(w==pn2_point)
1830 ||(w==pn3_point)
1831 ||(w==pn4_point)
1832 ||(w==pn5_point)
1833 ||(w==color_point)
1834 ||(w==grey_point)
1835 ||(w==bw_point)
1836 ||(w==pa4_point)
1837 ||(w==pb5_point)
1838 ||(w==pa5_point)
1839 ||(w==p11x17_point)
1840 ||(w==p8x11_point)
1841 ||(w==p8x14_point)
1842 ||(w==scale1_point)
1843 ||(w==maxspect_point)
1844 ||(w==center_point)
1845 ||(w==centerx_point)
1846 ||(w==centery_point)
1847 ||(w==okay_button)
1848 ||(w==cancel_button)
1849 ||(w==dpi180_point)
1850 ||(w==dpi300_point)
1851 ||(w==dpi400_point)
1852 ||(w==bbox_point)
1853 ||(w==portr_point)
1854 ||(w==landsc_point)) {
1855 if (!XGetWindowAttributes(root_display,w,&retWinAttr)) {
1856 FPRINTF(stderr,"Can't get window attributes.");
1857 gs_exit(1);
1858 }
1859 if (retWinAttr.border_width==3) {
1860 XMoveWindow(root_display,w,
1861 retWinAttr.x+2, retWinAttr.y+2);
1862 }
1863 XSetWindowBorderWidth(root_display, w, 1L);
1864 }
1865 }
1866
1867
1868 /* Expose a window
1869 * ---------------
1870 */
1871
1872 #ifdef ANSI_C
do_Expose(XEvent * eventp)1873 static void do_Expose (XEvent *eventp)
1874 #else
1875 static void do_Expose (eventp)
1876 XEvent *eventp;
1877 #endif
1878 {
1879 XExposeEvent *e = (XExposeEvent *) eventp;
1880
1881 if (e->window==dialog_window) {
1882 if ((e->width>12)&&(e->height>12)&&(!box_exposed)) {
1883 draw_dialog_box();
1884 box_exposed = 1;
1885 }
1886 }
1887 else box_exposed = 0;
1888 do_gblExpose(eventp);
1889 }
1890
1891
1892 /* Resize or move a window
1893 * -----------------------
1894 */
1895
1896 #ifdef ANSI_C
do_ConfigureNotify(XEvent * eventp)1897 static void do_ConfigureNotify (XEvent *eventp)
1898 #else
1899 static void do_ConfigureNotify (eventp)
1900 XEvent *eventp;
1901 #endif
1902 {
1903 XConfigureEvent *e = (XConfigureEvent *) eventp;
1904
1905 if (e->window==dialog_window) {
1906 XResizeWindow(root_display,dialog_window,DIAL_W,DIAL_H);
1907 draw_dialog_box();
1908 }
1909 else do_gblConfigureNotify(eventp);
1910 }
1911
1912
1913 /* Motion with pressed button
1914 * --------------------------
1915 */
1916
1917 #ifdef ANSI_C
do_MotionNotify(XEvent * eventp)1918 static void do_MotionNotify (XEvent *eventp)
1919 #else
1920 static void do_MotionNotify (eventp)
1921 XEvent *eventp;
1922 #endif
1923 {
1924 XMotionEvent *e = (XMotionEvent *) eventp;
1925
1926 if (e->window == margintmb) act_scroll_window = e->window;
1927
1928 if (act_scroll_window==xdpiscrollbar)
1929 read_xdpiscrollbar(e->x);
1930 else if (act_scroll_window==ydpiscrollbar)
1931 read_ydpiscrollbar(e->x);
1932 else if (act_scroll_window==scalescrollbar)
1933 read_scalescrollbar(e->x);
1934 else if (act_scroll_window==widthscrollbar)
1935 read_widthscrollbar(e->x);
1936 else if (act_scroll_window==heightscrollbar)
1937 read_heightscrollbar(e->x);
1938 else if (act_scroll_window==margintmb)
1939 read_marginpanner(e->x,e->y);
1940 else if (act_scroll_window==marginmiddle)
1941 read_marginxpanner(e->x,e->y);
1942 else return;
1943 draw_sizes();
1944 }
1945
1946
1947 /*--------------------------------------------------------------------*/
1948 /* Scrollbar handling */
1949 /*--------------------------------------------------------------------*/
1950
1951 #ifdef ANSI_C
read_xdpiscrollbar(int val)1952 static void read_xdpiscrollbar(int val)
1953 #else
1954 static void read_xdpiscrollbar(val)
1955 int val;
1956 #endif
1957 {
1958 int z;
1959 double factor;
1960
1961 z = SCROLL_W/2;
1962 assert((z>0));
1963 if (val<0) val = 0;
1964 if (val+SCROLLBAR_LEN >= SCROLL_W)
1965 val = SCROLL_W - SCROLLBAR_LEN;
1966 XMoveResizeWindow(root_display,xdpiscrolltmb,val,0,SCROLLBAR_LEN,6);
1967 factor = 300.0 * exp((double)(3*(val-z))/(double)z);
1968 set_xdpi(refocus_dpi(gstoint(factor)));
1969 if (act_output_type == 3) set_xdpiscrollbar();
1970 set_widthscrollbar();
1971 }
1972
1973
1974 #ifdef ANSI_C
set_xdpi(int val)1975 static void set_xdpi(int val)
1976 #else
1977 static void set_xdpi(val)
1978 int val;
1979 #endif
1980 {
1981 set_of_xdpi(val);
1982 act_width =(float)((rgx1>rgx2)?rgx1-rgx2:rgx2-rgx1)*act_scaling
1983 *2.54/(float)act_xdpi;
1984 }
1985
1986
1987 #ifdef ANSI_C
set_xdpiscrollbar(void)1988 static void set_xdpiscrollbar(void)
1989 #else
1990 static void set_xdpiscrollbar()
1991 #endif
1992 {
1993 int z, val;
1994
1995 z = SCROLL_W/2;
1996 assert((z>0));
1997
1998 if (act_xdpi<=0) val = 0;
1999 else val = gstoint(log((double)act_xdpi/(double)300.0)*(double)z/3)+z;
2000
2001 if (val<0) val = 0;
2002 if (val+SCROLLBAR_LEN >= SCROLL_W)
2003 val = SCROLL_W - SCROLLBAR_LEN;
2004 XMoveResizeWindow(root_display, xdpiscrolltmb,val,0,SCROLLBAR_LEN,6);
2005 }
2006
2007
2008 #ifdef ANSI_C
read_ydpiscrollbar(int val)2009 static void read_ydpiscrollbar(int val)
2010 #else
2011 static void read_ydpiscrollbar(val)
2012 int val;
2013 #endif
2014 {
2015 int z;
2016 double factor;
2017
2018 z = SCROLL_W/2;
2019 assert((z>0));
2020 if (val<0) val = 0;
2021 if (val+SCROLLBAR_LEN >= SCROLL_W)
2022 val = SCROLL_W - SCROLLBAR_LEN;
2023 XMoveResizeWindow(root_display,ydpiscrolltmb,val,0,SCROLLBAR_LEN,6);
2024 factor = 300.0 * exp((double)(3*(val-z))/(double)z);
2025 set_ydpi(refocus_dpi(gstoint(factor)));
2026 if (act_output_type == 3) set_ydpiscrollbar();
2027 set_heightscrollbar();
2028 }
2029
2030 #ifdef ANSI_C
set_ydpi(int val)2031 static void set_ydpi(int val)
2032 #else
2033 static void set_ydpi(val)
2034 int val;
2035 #endif
2036 {
2037 set_of_ydpi(val);
2038 act_height=(float)((rgy1>rgy2)?rgy1-rgy2:rgy2-rgy1)*act_scaling
2039 *2.54/(float)act_ydpi;
2040 }
2041
2042
2043 #ifdef ANSI_C
set_ydpiscrollbar(void)2044 static void set_ydpiscrollbar(void)
2045 #else
2046 static void set_ydpiscrollbar()
2047 #endif
2048 {
2049 int z, val;
2050
2051 z = SCROLL_W/2;
2052 assert((z>0));
2053
2054 if (act_ydpi<=0) val = 0;
2055 else val = gstoint(log((double)act_ydpi/(double)300.0)*(double)z/3)+z;
2056
2057 if (val<0) val = 0;
2058 if (val+SCROLLBAR_LEN >= SCROLL_W)
2059 val = SCROLL_W - SCROLLBAR_LEN;
2060 XMoveResizeWindow(root_display, ydpiscrolltmb,val,0,SCROLLBAR_LEN,6);
2061 }
2062
2063
2064 #ifdef ANSI_C
read_scalescrollbar(int val)2065 static void read_scalescrollbar(int val)
2066 #else
2067 static void read_scalescrollbar(val)
2068 int val;
2069 #endif
2070 {
2071 int z;
2072
2073 z = SCROLL_W/2;
2074 assert((z>0));
2075 if (val<0) val = 0;
2076 if (val+SCROLLBAR_LEN >= SCROLL_W)
2077 val = SCROLL_W - SCROLLBAR_LEN;
2078 XMoveResizeWindow(root_display,scalescrolltmb,val,0,SCROLLBAR_LEN,6);
2079 set_of_scaling( exp((double)(3*(val-z))/(double)z));
2080 set_widthscrollbar();
2081 set_heightscrollbar();
2082 }
2083
2084
2085 #ifdef ANSI_C
set_scalescrollbar(void)2086 static void set_scalescrollbar(void)
2087 #else
2088 static void set_scalescrollbar()
2089 #endif
2090 {
2091 int z, val;
2092
2093 z = SCROLL_W/2;
2094 assert((z>0));
2095
2096 if (act_scaling<=0) val = 0;
2097 else val = gstoint(log((double)act_scaling)*(double)z/3)+z;
2098
2099 if (val<0) val = 0;
2100 if (val+SCROLLBAR_LEN >= SCROLL_W)
2101 val = SCROLL_W - SCROLLBAR_LEN;
2102 XMoveResizeWindow(root_display, scalescrolltmb,val,0,SCROLLBAR_LEN,6);
2103 }
2104
2105
2106
2107 #ifdef ANSI_C
read_widthscrollbar(int val)2108 static void read_widthscrollbar(int val)
2109 #else
2110 static void read_widthscrollbar(val)
2111 int val;
2112 #endif
2113 {
2114 calc_paper_size();
2115
2116 if (val<0) val = 0;
2117 if (val+SCROLLBAR_LEN >= SCROLL_W)
2118 val = SCROLL_W - SCROLLBAR_LEN;
2119 XMoveResizeWindow(root_display,widthscrolltmb,val,0,SCROLLBAR_LEN,6);
2120 set_of_width(maxx*val/(SCROLL_W-SCROLLBAR_LEN));
2121
2122 set_scalescrollbar();
2123 set_heightscrollbar();
2124 }
2125
2126
2127
2128 #ifdef ANSI_C
set_widthscrollbar(void)2129 static void set_widthscrollbar(void)
2130 #else
2131 static void set_widthscrollbar()
2132 #endif
2133 {
2134 int val;
2135
2136 calc_paper_size();
2137
2138 if (act_width<=0) val = 0;
2139 else val = (int)(act_width*(SCROLL_W-SCROLLBAR_LEN)/maxx);
2140
2141 if (val<0) val = 0;
2142 if (val+SCROLLBAR_LEN >= SCROLL_W)
2143 val = SCROLL_W - SCROLLBAR_LEN;
2144 XMoveResizeWindow(root_display, widthscrolltmb,val,0,SCROLLBAR_LEN,6);
2145 }
2146
2147
2148 #ifdef ANSI_C
read_heightscrollbar(int val)2149 static void read_heightscrollbar(int val)
2150 #else
2151 static void read_heightscrollbar(val)
2152 int val;
2153 #endif
2154 {
2155 calc_paper_size();
2156
2157 if (val<0) val = 0;
2158 if (val+SCROLLBAR_LEN >= SCROLL_W)
2159 val = SCROLL_W - SCROLLBAR_LEN;
2160 XMoveResizeWindow(root_display,heightscrolltmb,val,0,SCROLLBAR_LEN,6);
2161 set_of_height(maxy*val/(SCROLL_W-SCROLLBAR_LEN));
2162
2163 set_scalescrollbar();
2164 set_widthscrollbar();
2165 }
2166
2167
2168 #ifdef ANSI_C
set_heightscrollbar(void)2169 static void set_heightscrollbar(void)
2170 #else
2171 static void set_heightscrollbar()
2172 #endif
2173 {
2174 int val;
2175
2176 calc_paper_size();
2177
2178 if (act_height<=0) val = 0;
2179 else val = (int)(act_height*(SCROLL_W-SCROLLBAR_LEN)/maxy);
2180
2181 if (val<0) val = 0;
2182 if (val+SCROLLBAR_LEN >= SCROLL_W)
2183 val = SCROLL_W - SCROLLBAR_LEN;
2184 XMoveResizeWindow(root_display, heightscrolltmb,val,0,SCROLLBAR_LEN,6);
2185 }
2186
2187
2188 #ifdef ANSI_C
read_marginpanner(int x,int y)2189 static void read_marginpanner(int x,int y)
2190 #else
2191 static void read_marginpanner(x, y)
2192 int x;
2193 int y;
2194 #endif
2195 {
2196 float fac;
2197 int nx, ny;
2198 int aw, ah;
2199
2200 calc_paper_size();
2201
2202 fac = maxx/(PANNER_W-1);
2203 if (maxy/(PANNER_H-1) > fac) fac = maxy/(PANNER_H-1);
2204 aw = gstoint(act_width/fac);
2205 ah = gstoint(act_height/fac);
2206 if (aw<5) aw = 5;
2207 if (ah<5) ah = 5;
2208
2209 nx = gstoint(act_left_margin/fac) + (x - aw/2);
2210 ny = gstoint(act_top_margin/fac) + (y - ah/2);
2211
2212 if (nx+aw/2 < 0) nx = 0;
2213 if (nx+aw/2 > gstoint(maxx/fac)) nx = gstoint(maxx/fac)-aw/2;
2214 if (ny+ah/2 < 0) ny = 0;
2215 if (ny+ah/2 > gstoint(maxy/fac)) ny = gstoint(maxy/fac)-ah/2;
2216
2217 act_left_margin =fac*nx;
2218 act_top_margin =fac*ny;
2219 act_right_margin = maxx - act_width -act_left_margin;
2220 act_bottom_margin = maxy - act_height-act_top_margin;
2221 if (act_paper_num>1) {
2222 act_left_margin =1.0;
2223 act_bottom_margin =1.0;
2224 act_right_margin = maxx - act_width -act_left_margin;
2225 act_top_margin = maxy - act_height-act_bottom_margin;
2226 nx = (int)(act_left_margin/fac);
2227 ny = (int)(act_top_margin/fac);
2228 }
2229 draw_sizes();
2230
2231 XMoveResizeWindow(root_display,margintmb,
2232 nx,ny, aw, ah);
2233 XSetForeground(root_display,
2234 XDefaultGC(root_display, root_screen),
2235 XBlackPixel(root_display, root_screen));
2236 XDrawLine(root_display,(Drawable)margintmb,
2237 XDefaultGC(root_display, root_screen),
2238 0,0,aw,ah);
2239 XDrawLine(root_display,(Drawable)margintmb,
2240 XDefaultGC(root_display, root_screen),
2241 0,ah,aw,0);
2242 /* XSync(root_display, 0); */
2243 }
2244
2245
2246 #ifdef ANSI_C
read_marginxpanner(int x,int y)2247 static void read_marginxpanner(int x,int y)
2248 #else
2249 static void read_marginxpanner(x, y)
2250 int x;
2251 int y;
2252 #endif
2253 {
2254 float fac;
2255 int nx, ny;
2256 int aw, ah;
2257
2258 calc_paper_size();
2259
2260 fac = maxx/(PANNER_W-1);
2261 if (maxy/(PANNER_H-1) > fac) fac = maxy/(PANNER_H-1);
2262 aw = gstoint(act_width/fac);
2263 ah = gstoint(act_height/fac);
2264 if (aw<5) aw = 5;
2265 if (ah<5) ah = 5;
2266
2267 nx = (x - aw/2);
2268 ny = (y - ah/2);
2269
2270 if (nx+aw/2 < 0) nx = 0;
2271 if (nx+aw/2 > gstoint(maxx/fac)) nx = gstoint(maxx/fac)-aw/2;
2272 if (ny+ah/2 < 0) ny = 0;
2273 if (ny+ah/2 > gstoint(maxy/fac)) ny = gstoint(maxy/fac)-ah/2;
2274 act_left_margin =fac*nx;
2275 act_top_margin =fac*ny;
2276 act_right_margin = maxx - act_width -act_left_margin;
2277 act_bottom_margin = maxy - act_height-act_top_margin;
2278 if (act_paper_num>1) {
2279 act_left_margin =1.0;
2280 act_bottom_margin =1.0;
2281 act_right_margin = maxx - act_width -act_left_margin;
2282 act_top_margin = maxy - act_height-act_bottom_margin;
2283 nx = (int)(act_left_margin/fac);
2284 ny = (int)(act_top_margin/fac);
2285 }
2286 draw_sizes();
2287
2288 XMoveResizeWindow(root_display,margintmb,
2289 nx,ny, aw, ah);
2290 XSetForeground(root_display,
2291 XDefaultGC(root_display, root_screen),
2292 XBlackPixel(root_display, root_screen));
2293 XDrawLine(root_display,(Drawable)margintmb,
2294 XDefaultGC(root_display, root_screen),
2295 0,0,aw,ah);
2296 XDrawLine(root_display,(Drawable)margintmb,
2297 XDefaultGC(root_display, root_screen),
2298 0,ah,aw,0);
2299 /* XSync(root_display, 0); */
2300 }
2301
2302
2303 #ifdef ANSI_C
set_marginpanner(void)2304 static void set_marginpanner(void)
2305 #else
2306 static void set_marginpanner()
2307 #endif
2308 {
2309 float fac;
2310 int aw, ah;
2311
2312 calc_paper_size();
2313
2314 fac = maxx/(PANNER_W-1);
2315 if (maxy/(PANNER_H-1) > fac) fac = maxy/(PANNER_H-1);
2316 aw = gstoint(act_width/fac);
2317 ah = gstoint(act_height/fac);
2318 if (aw<5) aw = 5;
2319 if (ah<5) ah = 5;
2320
2321 XMoveResizeWindow(root_display,marginmiddle,
2322 (PANNER_W-1-gstoint(maxx/fac))/2,
2323 (PANNER_H-1-gstoint(maxy/fac))/2,
2324 gstoint(maxx/fac)+1, gstoint(maxy/fac)+1);
2325
2326 XMoveResizeWindow(root_display,margintmb,
2327 gstoint(act_left_margin/fac),
2328 gstoint(act_top_margin/fac),
2329 aw, ah);
2330 XSetForeground(root_display,
2331 XDefaultGC(root_display, root_screen),
2332 XBlackPixel(root_display, root_screen));
2333 XDrawLine(root_display,(Drawable)margintmb,
2334 XDefaultGC(root_display, root_screen),
2335 0,0,gstoint(act_width/fac), gstoint(act_height/fac));
2336 XDrawLine(root_display,(Drawable)margintmb,
2337 XDefaultGC(root_display, root_screen),
2338 0,gstoint(act_height/fac),gstoint(act_width/fac),0);
2339 /* XSync(root_display, 0); */
2340 }
2341
2342
2343 #endif /* X11 */
2344
2345
2346 /*--------------------------------------------------------------------*/
2347
2348 /* Global Interface Functions to set the form of output
2349 * ====================================================
2350 * These Interface Functions are independend of X11.
2351 */
2352
2353
2354
2355 /* Set the region coordinates
2356 * --------------------------
2357 */
2358
2359 #ifdef ANSI_C
set_of_region(int rminx,int rminy,int rmaxx,int rmaxy)2360 void set_of_region(int rminx,int rminy,int rmaxx,int rmaxy)
2361 #else
2362 void set_of_region(rminx, rminy, rmaxx, rmaxy)
2363 int rminx;
2364 int rminy;
2365 int rmaxx;
2366 int rmaxy;
2367 #endif
2368 {
2369 rgx1 = rminx;
2370 rgy1 = rminy;
2371 rgx2 = rmaxx;
2372 rgy2 = rmaxy;
2373 }
2374
2375
2376 /* Set the xdpi Value
2377 * ------------------
2378 */
2379
2380 #ifdef ANSI_C
set_of_xdpi(int val)2381 void set_of_xdpi(int val)
2382 #else
2383 void set_of_xdpi(val)
2384 int val;
2385 #endif
2386 {
2387 act_xdpi = val;
2388 if (act_output_type == 3) act_xdpi = 72;
2389 }
2390
2391
2392 /* Set the ydpi Value
2393 * ------------------
2394 */
2395
2396 #ifdef ANSI_C
set_of_ydpi(int val)2397 void set_of_ydpi(int val)
2398 #else
2399 void set_of_ydpi(val)
2400 int val;
2401 #endif
2402 {
2403 act_ydpi = val;
2404 if (act_output_type == 3) act_ydpi = 72;
2405 }
2406
2407
2408 /* Set the scaling value and calculate width and height from it
2409 * ------------------------------------------------------------
2410 */
2411
2412 #ifdef ANSI_C
set_of_scaling(float val)2413 void set_of_scaling(float val)
2414 #else
2415 void set_of_scaling(val)
2416 float val;
2417 #endif
2418 {
2419 act_scaling = refocus_scale(val);
2420 act_width =((rgx1>rgx2)?rgx1-rgx2:rgx2-rgx1)*act_scaling*2.54/act_xdpi;
2421 act_height=((rgy1>rgy2)?rgy1-rgy2:rgy2-rgy1)*act_scaling*2.54/act_ydpi;
2422 }
2423
2424
2425
2426 /* Set the width and calculate scaling and height from it
2427 * ------------------------------------------------------
2428 */
2429
2430 #ifdef ANSI_C
set_of_width(float val)2431 void set_of_width(float val)
2432 #else
2433 void set_of_width(val)
2434 float val;
2435 #endif
2436 {
2437 act_width = val;
2438 act_scaling = act_width*act_xdpi/2.54/((rgx1>rgx2)?rgx1-rgx2:rgx2-rgx1);
2439 act_height=((rgy1>rgy2)?rgy1-rgy2:rgy2-rgy1)*act_scaling*2.54/act_ydpi;
2440 }
2441
2442
2443 /* Set the height and calculate scaling and width from it
2444 * ------------------------------------------------------
2445 */
2446
2447 #ifdef ANSI_C
set_of_height(float val)2448 void set_of_height(float val)
2449 #else
2450 void set_of_height(val)
2451 float val;
2452 #endif
2453 {
2454 act_height=val;
2455 act_scaling = act_height*act_ydpi/2.54/((rgy1>rgy2)?rgy1-rgy2:rgy2-rgy1);
2456 act_width=((rgx1>rgx2)?rgx1-rgx2:rgx2-rgx1)*act_scaling*2.54/act_xdpi;
2457 }
2458
2459
2460 /* Fit into height/width box and calculate scaling
2461 * -----------------------------------------------
2462 */
2463
2464 #ifdef ANSI_C
fit_of_heightwidth(float h,float w)2465 void fit_of_heightwidth(float h, float w)
2466 #else
2467 void fit_of_heightwidth(h, w)
2468 float h;
2469 float w;
2470 #endif
2471 {
2472 float scale1, scale2;
2473
2474 scale1 = w*act_xdpi/2.54/((rgx1>rgx2)?rgx1-rgx2:rgx2-rgx1);
2475 scale2 = h*act_ydpi/2.54/((rgy1>rgy2)?rgy1-rgy2:rgy2-rgy1);
2476 if (scale1<scale2) set_of_width(w);
2477 else set_of_height(h);
2478 }
2479
2480
2481 /* Fit into paper at maximal aspect ratio
2482 * --------------------------------------
2483 */
2484
2485 #ifdef ANSI_C
set_of_maxspect(void)2486 void set_of_maxspect(void)
2487 #else
2488 void set_of_maxspect()
2489 #endif
2490 {
2491 float fac1,fac2;
2492
2493 calc_paper_size();
2494 fac1 = (maxx - 1.0)*(float)act_xdpi/2.54
2495 /((rgx1>rgx2)?rgx1-rgx2:rgx2-rgx1);
2496 fac2 = (maxy - 1.0)*(float)act_ydpi/2.54
2497 /((rgy1>rgy2)?rgy1-rgy2:rgy2-rgy1);
2498 if (fac1<fac2) set_of_scaling(fac1);
2499 else set_of_scaling(fac2);
2500
2501 set_of_centerx();
2502 set_of_centery();
2503 }
2504
2505
2506 /* Center paper in x orientation
2507 * -----------------------------
2508 */
2509
2510 #ifdef ANSI_C
set_of_centerx(void)2511 void set_of_centerx(void)
2512 #else
2513 void set_of_centerx()
2514 #endif
2515 {
2516 calc_paper_size();
2517 act_left_margin = (maxx-act_width)/2;
2518 act_right_margin = maxx - act_width - act_left_margin;
2519 if (act_paper_num>1) {
2520 act_left_margin =1.0;
2521 act_bottom_margin =1.0;
2522 act_right_margin = maxx - act_width -act_left_margin;
2523 act_top_margin = maxy - act_height-act_bottom_margin;
2524 }
2525 }
2526
2527
2528 /* Center paper in y orientation
2529 * -----------------------------
2530 */
2531
2532 #ifdef ANSI_C
set_of_centery(void)2533 void set_of_centery(void)
2534 #else
2535 void set_of_centery()
2536 #endif
2537 {
2538 calc_paper_size();
2539 act_top_margin = (maxy-act_height)/2;
2540 act_bottom_margin = maxy - act_height - act_top_margin;
2541 if (act_paper_num>1) {
2542 act_left_margin =1.0;
2543 act_bottom_margin =1.0;
2544 act_right_margin = maxx - act_width -act_left_margin;
2545 act_top_margin = maxy - act_height-act_bottom_margin;
2546 }
2547 }
2548
2549
2550 /* Set left margin of the paper
2551 * ----------------------------
2552 */
2553
2554 #ifdef ANSI_C
set_of_leftmargin(float val)2555 void set_of_leftmargin(float val)
2556 #else
2557 void set_of_leftmargin(val)
2558 float val;
2559 #endif
2560 {
2561 calc_paper_size();
2562 act_left_margin = val;
2563 act_right_margin = maxx - act_width - act_left_margin;
2564 if (act_paper_num>1) {
2565 act_left_margin =1.0;
2566 act_bottom_margin =1.0;
2567 act_right_margin = maxx - act_width -act_left_margin;
2568 act_top_margin = maxy - act_height-act_bottom_margin;
2569 }
2570 }
2571
2572
2573 /* Set right margin of the paper
2574 * -----------------------------
2575 */
2576
2577 #ifdef ANSI_C
set_of_rightmargin(float val)2578 void set_of_rightmargin(float val)
2579 #else
2580 void set_of_rightmargin(val)
2581 float val;
2582 #endif
2583 {
2584 calc_paper_size();
2585 act_right_margin = val;
2586 act_left_margin = maxx - act_width - act_right_margin;
2587 if (act_paper_num>1) {
2588 act_left_margin =1.0;
2589 act_bottom_margin =1.0;
2590 act_right_margin = maxx - act_width -act_left_margin;
2591 act_top_margin = maxy - act_height-act_bottom_margin;
2592 }
2593 }
2594
2595
2596 /* Set bottom margin of the paper
2597 * ------------------------------
2598 */
2599
2600 #ifdef ANSI_C
set_of_bottommargin(float val)2601 void set_of_bottommargin(float val)
2602 #else
2603 void set_of_bottommargin(val)
2604 float val;
2605 #endif
2606 {
2607 calc_paper_size();
2608 act_bottom_margin = val;
2609 act_top_margin = maxy - act_height - act_bottom_margin;
2610 if (act_paper_num>1) {
2611 act_left_margin =1.0;
2612 act_bottom_margin =1.0;
2613 act_right_margin = maxx - act_width -act_left_margin;
2614 act_top_margin = maxy - act_height-act_bottom_margin;
2615 }
2616 }
2617
2618
2619 /* Set top margin of the paper
2620 * ---------------------------
2621 */
2622
2623 #ifdef ANSI_C
set_of_topmargin(float val)2624 void set_of_topmargin(float val)
2625 #else
2626 void set_of_topmargin(val)
2627 float val;
2628 #endif
2629 {
2630 calc_paper_size();
2631 act_top_margin = val;
2632 act_bottom_margin = maxy - act_height - act_top_margin;
2633 if (act_paper_num>1) {
2634 act_left_margin =1.0;
2635 act_bottom_margin =1.0;
2636 act_right_margin = maxx - act_width -act_left_margin;
2637 act_top_margin = maxy - act_height-act_bottom_margin;
2638 }
2639 }
2640
2641
2642
2643 /*--------------------------------------------------------------------*/
2644
2645 /* Calc maximal paper sizes
2646 * ------------------------
2647 * and set the colbal variables maxx and maxy corresponmding.
2648 */
2649
2650 #ifdef ANSI_C
calc_paper_size(void)2651 static void calc_paper_size(void)
2652 #else
2653 static void calc_paper_size()
2654 #endif
2655 {
2656 switch (act_paper_type) {
2657 case 1:
2658 if (act_ori_type==1) { maxx = 21.0; maxy = 30.0; }
2659 else { maxx = 30.0; maxy = 21.0; }
2660 break;
2661 case 2:
2662 if (act_ori_type==1) { maxx = 18.5; maxy = 27.0; }
2663 else { maxx = 27.0; maxy = 18.5; }
2664 break;
2665 case 3:
2666 if (act_ori_type==1) { maxx = 15.0; maxy = 21.0; }
2667 else { maxx = 21.0; maxy = 15.0; }
2668 break;
2669 case 4:
2670 if (act_ori_type==1) { maxx = 27.94; maxy = 43.18; }
2671 else { maxx = 43.18; maxy = 27.94; }
2672 break;
2673 case 5:
2674 if (act_ori_type==1) { maxx = 21.59; maxy = 27.94; }
2675 else { maxx = 27.94; maxy = 21.59; }
2676 break;
2677 case 6:
2678 if (act_ori_type==1) { maxx = 21.59; maxy = 35.56; }
2679 else { maxx = 35.56; maxy = 21.59; }
2680 break;
2681 }
2682 if (act_paper_num > 1) {
2683 /* 2 cm margin for multipage output */
2684 maxx = (maxx-3.0) * (float)act_paper_num;
2685 maxy = (maxy-3.0) * (float)act_paper_num;
2686 }
2687 }
2688
2689 /*--------------------------------------------------------------------*/
2690
2691
2692 /* Refocus dpi values
2693 * ------------------
2694 * Some dpi values are more often used than others. Thus we recalculate
2695 * the dpi values such that these values can be selected easyer.
2696 */
2697
2698 #define m_abs(x) ((x>0)?(x):-(x))
2699
2700
2701 #ifdef ANSI_C
refocus_dpi(int x)2702 static int refocus_dpi(int x)
2703 #else
2704 static int refocus_dpi(x)
2705 int x;
2706 #endif
2707 {
2708 if (m_abs(x-2400)<95) return(2400);
2709 if (m_abs(x-1200)<65) return(1200);
2710 if (m_abs(x-720)<10) return(720);
2711 if (m_abs(x-700)<10) return(700);
2712 if (m_abs(x-600)<9) return(600);
2713 if (m_abs(x-500)<9) return(500);
2714 if (m_abs(x-400)<9) return(400);
2715 if (m_abs(x-360)<8) return(360);
2716 if (m_abs(x-300)<8) return(300);
2717 if (m_abs(x-288)<7) return(288);
2718 if (m_abs(x-240)<7) return(240);
2719 if (m_abs(x-200)<7) return(200);
2720 if (m_abs(x-100)<5) return(100);
2721 if (m_abs(x-180)<5) return(180);
2722 if (m_abs(x-144)<5) return(144);
2723 if (m_abs(x-120)<5) return(120);
2724 if (m_abs(x-100)<5) return(100);
2725 if (m_abs(x-90)<5) return(90);
2726 if (m_abs(x-72)<5) return(72);
2727 if (m_abs(x-50)<5) return(50);
2728 return(x);
2729 }
2730
2731
2732 /*--------------------------------------------------------------------*/
2733
2734 /* Refocus scale values
2735 * --------------------
2736 * Some scale values are more often used than others. Thus we recalculate
2737 * the scale values such that these values can be selected easyer.
2738 */
2739
2740
2741 #ifdef ANSI_C
refocus_scale(float x)2742 static float refocus_scale(float x)
2743 #else
2744 static float refocus_scale(x)
2745 float x;
2746 #endif
2747 {
2748 if (m_abs(x-12.0)<0.20) return(12.0);
2749 if (m_abs(x-11.0)<0.09) return(11.0);
2750 if (m_abs(x-10.0)<0.06) return(10.0);
2751 if (m_abs(x-9.00)<0.06) return(9.00);
2752 if (m_abs(x-8.00)<0.06) return(8.00);
2753 if (m_abs(x-7.00)<0.06) return(7.00);
2754 if (m_abs(x-6.00)<0.06) return(6.00);
2755 if (m_abs(x-5.00)<0.06) return(5.00);
2756 if (m_abs(x-4.00)<0.06) return(4.00);
2757 if (m_abs(x-3.00)<0.02) return(3.00);
2758 if (m_abs(x-2.00)<0.02) return(2.00);
2759 if (m_abs(x-0.75)<0.01) return(0.75);
2760 if (m_abs(x-0.50)<0.01) return(0.50);
2761 if (m_abs(x-0.25)<0.01) return(0.25);
2762 return(x);
2763 }
2764
2765
2766 /*--------------------------------------------------------------------*/
2767
2768