1 /* SCCS-info %W% %E% */
2
3 /*--------------------------------------------------------------------*/
4 /* */
5 /* VCG : Visualization of Compiler Graphs */
6 /* -------------------------------------- */
7 /* */
8 /* file: X11devfe.c */
9 /* version: 1.00.00 */
10 /* creation: 29.12.94 */
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: Follow Edge and Edge History Dialog Box */
16 /* status: in work */
17 /* */
18 /*--------------------------------------------------------------------*/
19
20 #ifndef lint
21 static char *id_string="$Id: X11devfe.c,v 1.2 1995/02/08 18:38:09 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: X11devfe.c,v $
48 * Revision 1.2 1995/02/08 18:38:09 sander
49 * Small bug for K&R C solved.
50 *
51 * Revision 1.1 1995/02/08 11:11:14 sander
52 * Initial revision
53 *
54 */
55
56 /************************************************************************
57 * Device driver for X11: Follow Edge Management and History Dialog Box
58 * --------------------------------------------------------------------
59 *
60 * This module contains the management of the dialog box that appears
61 * if we want to select a node from the follow edge history.
62 *
63 * This file provides the following functions:
64 * ------------------------------------------
65 *
66 * x11_init_fedge_dialog(rd,rs) initialize the dialogbox.
67 * x11_destroy_fedge_dialog(rd,rs) destroys the dialogbox.
68 *
69 * x11_print_fedge_dialog()
70 *
71 * This function opens the dialog box that allows to enter the
72 * title of a node to be centered. Alternatively, we can also
73 * look at the label, etc.
74 *
75 ************************************************************************/
76
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <string.h>
80 #include "globals.h"
81
82 #ifdef X11
83
84 /*#include <X11/Xos.h>*/
85 #include <X11/Xlib.h>
86 #include <X11/Xutil.h>
87 #include <X11/cursorfont.h>
88 #include <X11/Xproto.h>
89 #include <ctype.h>
90 #include <math.h>
91 #include "main.h"
92 #include "options.h"
93 #include "grammar.h"
94 #include "alloc.h"
95 #include "steps.h"
96 #include "X11devfe.h"
97
98
99 /*--------------------------------------------------------------------*/
100
101 #undef EVENT_DEBUG
102
103
104 /* Types
105 * =====
106 */
107
108 /* Selection points: On/Off-Buttons, Radio/Buttons, Touch Buttons
109 * Radio-Buttons are On-buttons, i.e. they don't go off, if we retouch
110 * them. Further, all radio buttons of one section have the same glob.
111 */
112
113 typedef struct gs_selection_point {
114 Window w; /* Window of the point */
115 char *t; /* Text of the point */
116 int x; /* X-Position */
117 int y; /* Y-Position */
118 int is; /* actual value */
119 int sel; /* value, if the point is selected */
120 int *glob; /* corresponding global value */
121 char key; /* key action */
122 } GS_SEL_POINT;
123
124
125 /* Horizontal integer scroll bars
126 */
127
128
129 typedef struct gs_scroll_bar {
130 Window ws; /* Window of the bar itself */
131 Window wt; /* Window of the scroll thumb */
132 char *t; /* Text of the scroll bar */
133 char *f; /* Format of the value */
134 int yt; /* Y-Position of the text */
135 int yv; /* Y-Position of the value */
136 int yb; /* Y-Position of the bar */
137 int x; /* X-Position */
138 int len; /* Length of scrollbar */
139 int is; /* actual value */
140 int *glob; /* corresponding global value */
141 #ifdef ANSI_C
142 void (*rf)(int); /* read function */
143 void (*sf)(void); /* set function */
144 #else
145 void (*rf)();
146 void (*sf)();
147 #endif
148 } GS_SCROLL_BAR;
149
150
151
152
153 /* Prototypes
154 * ==========
155 */
156
157 /* from X11dev.c */
158 void gs_exit _PP((int x));
159 void do_gblExpose _PP((XEvent *eventp));
160 void do_gblConfigureNotify _PP((XEvent *eventp));
161
162 void set_act_follow_node _PP((GNODE v,int i));
163 void set_next_follow_edge _PP((void));
164 void do_act_follow_edge _PP((void));
165 extern int act_follow_edge_visible;
166
167
168
169 static void allocateDialogBox _PP((void));
170 static Window allocate_selection_point _PP((int x,int y));
171 static Window allocate_button _PP((int x,int y));
172 static Window allocate_general_button _PP((int x,int y,int w,int h));
173 static Window allocate_scroll_bar _PP((int x,int y,int len));
174
175 static void draw_dialog_box _PP((void));
176 static void draw_text _PP(( int x, int y, char *m));
177 static void draw_underl_text _PP(( int x, int y, char *m));
178 static void draw_dialog_point _PP((Window w, int color));
179 static void draw_sizes _PP((void));
180 static void draw_textwin _PP((void));
181 static void normalize_point _PP((Window w));
182
183
184 #ifdef EVENT_DEBUG
185 static void prologue _PP((XEvent *eventp, char *event_name));
186 #else
187 #define prologue(a,b)
188 #endif
189
190 static void dialog_main_loop _PP((void));
191 static void do_KeyPress _PP((XEvent *eventp));
192 static void do_ButtonPress _PP((XEvent *eventp));
193 static void do_ButtonRelease _PP((XEvent *eventp));
194 static void do_EnterNotify _PP((XEvent *eventp));
195 static void do_LeaveNotify _PP((XEvent *eventp));
196 static void do_Expose _PP((XEvent *eventp));
197 static void do_ConfigureNotify _PP((XEvent *eventp));
198 static void do_MotionNotify _PP((XEvent *eventp));
199
200 static void read_fedge_scrollbar _PP((int val));
201 static void set_fedge_scrollbar _PP((void));
202
203
204 /* Positions and Sizes
205 * ===================
206 */
207
208 /* Size of a normal point */
209
210 #define POINT_W 10
211
212 /* Size of a normal button */
213
214 #define BUTTON_W 130
215
216 /* Sizes of a scrollbar and its thumb */
217
218 #define SCROLL_W 250
219 #define SCROLLBAR_LEN 20
220
221 /* Sizes of the scroll window */
222
223 #define SCROLLW_W 350
224 #define SCROLLW_H SCROLL_W
225
226
227 /* Positions of the radio points */
228
229 #define SEL_POS SCROLLW_W+35
230
231 /* Position of the input text */
232
233 #define TEXT_POS 55+SCROLLW_H
234
235 /* Size of the dialog box */
236
237 #define DIAL_W 530
238 #define DIAL_H TEXT_POS+10
239
240
241 /* Variables
242 * =========
243 */
244
245 #define MAXHISTORY 50
246
247 static GNODE fedge_history[MAXHISTORY];
248 static int fedge_top = 0;
249
250 static int fedge_pos;
251
252
253 /* Dialog handling: On success (i.e. Okay-Button), success becomes 1 */
254
255 static int dialog_notready = 1;
256
257 static GNODE act_node;
258
259 static char act_title[256];
260 static int act_selection = 0;
261
262
263 /* Radio buttons are partitioned into those that have the same global
264 * variable. If a radio-button is selected, all other radio buttons
265 * of the same partition became unselected.
266 */
267
268 static int sel_mode = 0;
269
270 #define MAX_RADIO_POINTS 5
271 static GS_SEL_POINT radio_point[MAX_RADIO_POINTS] = {
272
273 /* window, text , xpos, ypos, isval, selval , globvar , key */
274 { 0 , "title" , SEL_POS, 41, 0, 0 , &sel_mode , 't' },
275 { 0 , "label" , SEL_POS, 59, 0, 1 , &sel_mode , 'l' },
276 { 0 , "info field 1" , SEL_POS, 77, 0, 2 , &sel_mode , '1' },
277 { 0 , "info_field 2" , SEL_POS, 95, 0, 3 , &sel_mode , '2' },
278 { 0 , "info field 3" , SEL_POS, 113, 0, 4 , &sel_mode , '3' }
279
280 };
281
282
283 /* Horizontal integer scrollbars are used to change a value by the read and
284 * set functions. Here, these values must be integer values.
285 */
286
287 static int my_scroll_val = 0;
288
289 #define MAX_VSCROLLBARS 1
290
291 #ifdef ANSI_C
292 static GS_SCROLL_BAR vscrollbar[MAX_VSCROLLBARS] = {
293
294 { 0, 0, "" ,"", 27 , 27, 27, SCROLLW_W+5, SCROLL_W,
295 0, &my_scroll_val , &read_fedge_scrollbar, &set_fedge_scrollbar }
296 };
297 #else
298 static GS_SCROLL_BAR vscrollbar[MAX_VSCROLLBARS] = {
299
300 { 0, 0, "" ,"", 27 , 27, 27, SCROLLW_W+5, SCROLL_W,
301 0, &my_scroll_val , read_fedge_scrollbar, set_fedge_scrollbar }
302 };
303 #endif
304
305
306 /* Root displays */
307
308 static Display *root_display; /* Root display */
309 static int root_screen; /* and its screen number */
310
311
312 /* Windows */
313
314 static Window dialog_window;
315 static Window scroll_show_window;
316 static Window text_window;
317
318 static Window snode_button;
319 static Window nedge_button;
320 static Window fedge_button;
321 static Window cancel_button;
322 static Window next_button;
323 static Window prev_button;
324
325
326 /* Cursors */
327
328 static Cursor scrollCursor;
329
330 /* Mouse Buttons */
331
332 #define G_MOUSE_LEFT 1
333 #define G_MOUSE_RIGHT 3
334
335
336 /* the panel font */
337
338 extern char Xfontname[512];
339 static XFontStruct *dialog_font = NULL;
340
341 /* Flag wheter the dialog_box is initialized */
342
343 static int dialog_box_there = 0;
344
345
346 /*--------------------------------------------------------------------*/
347 /* Follow Edge Operations */
348 /*--------------------------------------------------------------------*/
349
350
351
352 #ifdef ANSI_C
do_follow_node(GNODE v)353 static void do_follow_node(GNODE v)
354 #else
355 static void do_follow_node(v)
356 GNODE v;
357 #endif
358 {
359 GEDGE afe;
360 XEvent event;
361 int notready;
362 int x,y,width,height;
363 int i;
364
365 if (!v) return;
366 set_act_follow_node(v,2);
367 act_selection = 0;
368 fedge_pos = 0;
369 set_fedge_scrollbar();
370 draw_sizes();
371
372 }
373
374
375 #ifdef ANSI_C
do_next_follow_edge(void)376 static void do_next_follow_edge(void)
377 #else
378 static void do_next_follow_edge()
379 #endif
380 {
381 set_next_follow_edge();
382 }
383
384
385 #ifdef ANSI_C
do_apply_follow_edge(void)386 static void do_apply_follow_edge(void)
387 #else
388 static void do_apply_follow_edge()
389 #endif
390 {
391 do_act_follow_edge();
392 act_selection = 0;
393 fedge_pos = 0;
394 set_fedge_scrollbar();
395 draw_sizes();
396 }
397
398
399
400
401 /*--------------------------------------------------------------------*/
402 /* History Management functions */
403 /*--------------------------------------------------------------------*/
404
405 /* Initialize the history
406 * ----------------------
407 */
408
409 #ifdef ANSI_C
init_fedge_history(void)410 void init_fedge_history(void)
411 #else
412 void init_fedge_history()
413 #endif
414 {
415 fedge_top = 0;
416 }
417
418
419 /* Add a node to the top of the history
420 * ------------------------------------
421 */
422
423 #ifdef ANSI_C
add_fedge_history(GNODE v)424 void add_fedge_history(GNODE v)
425 #else
426 void add_fedge_history(v)
427 GNODE v;
428 #endif
429 {
430 int i;
431
432 for (i=MAXHISTORY-1; i>0; i--)
433 fedge_history[i] = fedge_history[i-1];
434 fedge_history[0] = v;
435 fedge_top++;
436 if (fedge_top > MAXHISTORY) fedge_top = MAXHISTORY;
437 }
438
439
440
441 /*--------------------------------------------------------------------*/
442 /* Dialog box initialization and entry points */
443 /*--------------------------------------------------------------------*/
444
445 static Window myframe_win;
446 static Window mypix_win;
447
448
449 /* Initialize the dialog box
450 * -------------------------
451 * This is done once at the beginning.
452 */
453
454 #ifdef ANSI_C
x11_init_fedge_dialog(Display * rd,int rs,Window mf,Window mp)455 void x11_init_fedge_dialog(Display *rd, int rs, Window mf, Window mp)
456 #else
457 void x11_init_fedge_dialog(rd, rs, mf, mp)
458 Display *rd;
459 int rs;
460 Window mf;
461 Window mp;
462 #endif
463 {
464 if (dialog_box_there) return;
465 myframe_win = mf;
466 mypix_win = mp;
467 root_display = rd;
468 root_screen = rs;
469 dialog_font = XLoadQueryFont(root_display,Xfontname);
470 if (!dialog_font) {
471 Fatal_error("Font not found. Please use option -font","");
472 }
473
474 allocateDialogBox();
475
476 dialog_box_there = 1;
477 }
478
479
480
481 /* Destroy the dialog box
482 * ----------------------
483 * This is done once on ExitDevice.
484 */
485
486 #ifdef ANSI_C
x11_destroy_fedge_dialog(Display * rd,int rs)487 void x11_destroy_fedge_dialog(Display *rd, int rs)
488 #else
489 void x11_destroy_fedge_dialog(rd, rs)
490 Display *rd;
491 int rs;
492 #endif
493 {
494 if (!dialog_box_there) return;
495 XDestroyWindow(root_display,dialog_window);
496 dialog_box_there = 0;
497 }
498
499
500
501 /* Allocate the Dialog Box
502 * -----------------------
503 * Scrollbar-Thumbs are returned in last_tmb;
504 */
505
506 static Window last_tmb;
507 static char x11_win_label[1024];
508
509 #ifdef ANSI_C
allocateDialogBox(void)510 static void allocateDialogBox(void)
511 #else
512 static void allocateDialogBox()
513 #endif
514 {
515 Window rret1, rret2;
516 XSetWindowAttributes attr;
517 unsigned long mask = 0L;
518 int i;
519 unsigned int j;
520 int xpos, ypos;
521 XSizeHints hints;
522
523 /* select for all events */
524 attr.event_mask = KeyPressMask |
525 ButtonPressMask | ButtonReleaseMask |
526 EnterWindowMask |
527 ExposureMask | StructureNotifyMask |
528 SubstructureNotifyMask |
529 FocusChangeMask | OwnerGrabButtonMask;
530
531 attr.background_pixel = XWhitePixel(root_display,root_screen);
532 attr.border_pixel = XBlackPixel(root_display,root_screen);
533
534 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
535
536 (void)XQueryPointer(root_display,RootWindow(root_display, root_screen),
537 &rret1, &rret2,&xpos, &ypos, &i, &i, &j);
538
539 dialog_window = XCreateWindow(root_display,
540 RootWindow(root_display, root_screen),
541 xpos, ypos,
542 DIAL_W, DIAL_H,
543 Xmyborderwidth, (int)CopyFromParent,
544 InputOutput,
545 (Visual *)CopyFromParent,
546 mask, &attr);
547
548 hints.flags = PPosition;
549 hints.x = xpos;
550 hints.y = ypos;
551
552 strcpy(x11_win_label, "VCG ");
553 strcat(x11_win_label, Dataname);
554 strcat(x11_win_label, " FEdge");
555
556
557 XStoreName(root_display, dialog_window, x11_win_label);
558 XSetNormalHints(root_display, dialog_window, &hints);
559
560 text_window = XCreateWindow(root_display, dialog_window,
561 5, TEXT_POS-22,
562 DIAL_W-10, 25,
563 1, (int)CopyFromParent,
564 InputOutput,
565 (Visual *)CopyFromParent,
566 mask, &attr);
567
568 scroll_show_window = XCreateWindow(root_display, dialog_window,
569 5, 27,
570 SCROLLW_W, SCROLLW_H,
571 1, (int)CopyFromParent,
572 InputOutput,
573 (Visual *)CopyFromParent,
574 mask, &attr);
575
576 XDefineCursor(root_display,text_window,
577 XCreateFontCursor(root_display,XC_xterm));
578 XDefineCursor(root_display,dialog_window,
579 XCreateFontCursor(root_display,XC_left_ptr));
580
581 scrollCursor = XCreateFontCursor(root_display,XC_sb_v_double_arrow);
582
583 for (i=0; i<MAX_RADIO_POINTS; i++)
584 radio_point[i].w = allocate_selection_point(
585 radio_point[i].x,
586 radio_point[i].y-10);
587
588 for (i=0; i<MAX_VSCROLLBARS; i++) {
589 vscrollbar[i].ws = allocate_scroll_bar(vscrollbar[i].x,
590 vscrollbar[i].yb,
591 vscrollbar[i].len);
592 vscrollbar[i].wt = last_tmb;
593 }
594
595
596 snode_button = allocate_button(SEL_POS,160);
597 nedge_button = allocate_button(SEL_POS,160+30);
598 fedge_button = allocate_button(SEL_POS,160+60);
599 cancel_button = allocate_button(SEL_POS,160+90);
600 next_button = allocate_general_button(SEL_POS,125,60,20);
601 prev_button = allocate_general_button(SEL_POS+70,125,60,20);
602 }
603
604
605
606 /* Allocate a selection point (button or radio button)
607 * ---------------------------------------------------
608 */
609
610 #ifdef ANSI_C
allocate_selection_point(int x,int y)611 static Window allocate_selection_point(int x,int y)
612 #else
613 static Window allocate_selection_point(x,y)
614 int x, y;
615 #endif
616 {
617 return(allocate_general_button(x,y,POINT_W,POINT_W));
618 }
619
620
621
622 /* Allocate an normal button
623 * -------------------------
624 */
625
626 #ifdef ANSI_C
allocate_button(int x,int y)627 static Window allocate_button(int x,int y)
628 #else
629 static Window allocate_button(x,y)
630 int x, y;
631 #endif
632 {
633 return(allocate_general_button(x,y,BUTTON_W,25));
634 }
635
636
637
638 /* Allocate a general button or point
639 * ----------------------------------
640 */
641
642 #ifdef ANSI_C
allocate_general_button(int x,int y,int w,int h)643 static Window allocate_general_button(int x,int y,int w,int h)
644 #else
645 static Window allocate_general_button(x,y,w,h)
646 int x, y, w, h;
647 #endif
648 {
649 Window ww;
650 XSetWindowAttributes attr;
651 unsigned long mask = 0L;
652
653 /* select for all events */
654 attr.event_mask = KeyPressMask |
655 ButtonPressMask | ButtonReleaseMask |
656 EnterWindowMask | LeaveWindowMask |
657 ExposureMask | StructureNotifyMask |
658 SubstructureNotifyMask |
659 FocusChangeMask | OwnerGrabButtonMask;
660
661 attr.background_pixel = XWhitePixel(root_display,root_screen);
662 attr.border_pixel = XBlackPixel(root_display,root_screen);
663
664 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
665
666 ww = XCreateWindow(root_display,
667 dialog_window,
668 x,y,
669 w,h,
670 1, (int)CopyFromParent,
671 InputOutput,
672 (Visual *)CopyFromParent,
673 mask, &attr);
674
675 return(ww);
676 }
677
678
679 /* Allocate a scroll bar
680 * ---------------------
681 */
682
683 #ifdef ANSI_C
allocate_scroll_bar(int x,int y,int len)684 static Window allocate_scroll_bar(int x,int y,int len)
685 #else
686 static Window allocate_scroll_bar(x,y,len)
687 int x, y, len;
688 #endif
689 {
690 Window w, wt;
691 XSetWindowAttributes attr;
692 unsigned long mask = 0L;
693
694 /* select for all events */
695 attr.event_mask = KeyPressMask | ButtonMotionMask |
696 ButtonPressMask | ButtonReleaseMask |
697 EnterWindowMask | LeaveWindowMask |
698 ExposureMask | ResizeRedirectMask |
699 SubstructureNotifyMask |
700 FocusChangeMask | OwnerGrabButtonMask;
701
702 attr.background_pixel = XWhitePixel(root_display,root_screen);
703 attr.border_pixel = XBlackPixel(root_display,root_screen);
704
705 mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
706
707 w = XCreateWindow (root_display, dialog_window, x,y,
708 8, len,
709 1, (int)CopyFromParent,
710 InputOutput,
711 (Visual *)CopyFromParent,
712 mask, &attr);
713 wt = XCreateSimpleWindow (root_display, w, 0,0,
714 6, SCROLLBAR_LEN,
715 1,
716 XWhitePixel(root_display,root_screen),
717 XBlackPixel(root_display,root_screen));
718
719 XDefineCursor(root_display,w,scrollCursor);
720
721 last_tmb = wt;
722 return(w);
723 }
724
725
726 /*--------------------------------------------------------------------*/
727 /* Entry point for the dialog */
728 /*--------------------------------------------------------------------*/
729
730 static int box_exposed;
731 static int first_exposed = 1;
732
733 #ifdef ANSI_C
x11_print_fedge_dialog(void)734 GNODE x11_print_fedge_dialog(void)
735 #else
736 GNODE x11_print_fedge_dialog()
737 #endif
738 {
739 XEvent event;
740 int i, x, y;
741 Window rret1, rret2;
742 unsigned int j;
743
744 if (first_exposed) {
745 first_exposed = 0;
746 (void)XQueryPointer(root_display,RootWindow(root_display, root_screen),
747 &rret1, &rret2,&x, &y, &i, &i, &j);
748 XMoveWindow(root_display,dialog_window, x, y);
749 }
750
751
752 act_node = NULL;
753 act_title[0] = 0;
754 act_selection = 0;
755 strcpy(act_title,"Enter title: _");
756 my_scroll_val = sel_mode = 0;
757 box_exposed = 0;
758
759 for (i=0; i<MAX_RADIO_POINTS; i++)
760 radio_point[i].is = *(radio_point[i].glob);
761
762 for (i=0; i<MAX_VSCROLLBARS; i++)
763 vscrollbar[i].is = *(vscrollbar[i].glob);
764
765 XMapRaised(root_display, dialog_window);
766 XMapRaised(root_display, scroll_show_window);
767 XMapRaised(root_display, text_window);
768
769 for (i=0; i<MAX_RADIO_POINTS; i++) {
770 XMapRaised(root_display, radio_point[i].w);
771 normalize_point(radio_point[i].w);
772 }
773 for (i=0; i<MAX_VSCROLLBARS; i++) {
774 XMapRaised(root_display, vscrollbar[i].ws);
775 XMapRaised(root_display, vscrollbar[i].wt);
776 }
777
778 XMapRaised(root_display, snode_button);
779 XMapRaised(root_display, nedge_button);
780 XMapRaised(root_display, fedge_button);
781 XMapRaised(root_display, cancel_button);
782 XMapRaised(root_display, next_button);
783 XMapRaised(root_display, prev_button);
784 normalize_point(snode_button);
785 normalize_point(nedge_button);
786 normalize_point(fedge_button);
787 normalize_point(cancel_button);
788 normalize_point(next_button);
789 normalize_point(prev_button);
790
791 for (i=0; i<MAX_VSCROLLBARS; i++) (*(vscrollbar[i].sf))();
792
793 XFlush(root_display);
794
795 /*
796 * Wait for Exposure event.
797 */
798 #ifndef ULTRIX
799 #ifndef AIX
800 do { XNextEvent(root_display, &event);
801 } while (event.type != Expose && event.type != MapNotify);
802 #endif
803 #endif
804
805 if (event.type == Expose) do_Expose(&event);
806 dialog_main_loop();
807
808 XUnmapWindow(root_display, dialog_window);
809
810 return(NULL);
811 }
812
813
814
815 /*--------------------------------------------------------------------*/
816 /* Redraw routine */
817 /*--------------------------------------------------------------------*/
818
819 /* Draw dialog box
820 * ---------------
821 */
822
823 #ifdef ANSI_C
draw_dialog_box(void)824 static void draw_dialog_box(void)
825 #else
826 static void draw_dialog_box()
827 #endif
828 {
829 int i;
830
831 XSetForeground(root_display,
832 XDefaultGC(root_display, root_screen),
833 XWhitePixel(root_display, root_screen));
834 XFillRectangle(root_display,
835 (Drawable)dialog_window,
836 XDefaultGC(root_display, root_screen),
837 0,0, DIAL_W, DIAL_H);
838
839 XSetForeground(root_display,
840 XDefaultGC(root_display, root_screen),
841 XBlackPixel(root_display, root_screen));
842
843 i = XTextWidth(dialog_font,"Cancel (Esc)",strlen("Cancel (Esc)"));
844 i = (BUTTON_W-i)/2;
845 XDrawString(root_display,
846 (Drawable)cancel_button,
847 XDefaultGC(root_display, root_screen),
848 i,18,"Cancel (Esc)",strlen("Cancel (Esc)"));
849
850 i = XTextWidth(dialog_font,"Next Edge",strlen("Next Edge"));
851 i = (BUTTON_W-i)/2;
852 XDrawString(root_display,
853 (Drawable)nedge_button,
854 XDefaultGC(root_display, root_screen),
855 i,18,"Next Edge",strlen("Next Edge"));
856
857 i = XTextWidth(dialog_font,"Follow Edge",strlen("Follow Edge"));
858 i = (BUTTON_W-i)/2;
859 XDrawString(root_display,
860 (Drawable)fedge_button,
861 XDefaultGC(root_display, root_screen),
862 i,18,"Follow Edge",strlen("Follow Edge"));
863
864 i = XTextWidth(dialog_font,"Select Node",strlen("Select Node"));
865 i = (BUTTON_W-i)/2;
866 XDrawString(root_display,
867 (Drawable)snode_button,
868 XDefaultGC(root_display, root_screen),
869 i,18,"Select Node",strlen("Select Node"));
870
871 i = XTextWidth(dialog_font,"next",strlen("next"));
872 i = (60-i)/2;
873 XDrawString(root_display,
874 (Drawable)next_button,
875 XDefaultGC(root_display, root_screen),
876 i,16,"next",strlen("next"));
877
878 i = XTextWidth(dialog_font,"prev.",strlen("prev."));
879 i = (60-i)/2;
880 XDrawString(root_display,
881 (Drawable)prev_button,
882 XDefaultGC(root_display, root_screen),
883 i,16,"prev.",strlen("prev."));
884
885 draw_underl_text(5,18,"Select a graph node to follow its edges");
886
887 for (i=0; i<MAX_RADIO_POINTS; i++)
888 draw_text(radio_point[i].x+20,radio_point[i].y,
889 radio_point[i].t);
890
891 /* for (i=0; i<MAX_VSCROLLBARS; i++)
892 * draw_text(vscrollbar[i].x, vscrollbar[i].yt, vscrollbar[i].t);
893 */
894
895 for (i=0; i<MAX_RADIO_POINTS; i++)
896 if (radio_point[i].is == radio_point[i].sel)
897 draw_dialog_point(radio_point[i].w,1);
898 else draw_dialog_point(radio_point[i].w,0);
899
900 XSetForeground(root_display,
901 XDefaultGC(root_display, root_screen),
902 XWhitePixel(root_display, root_screen));
903 XFillRectangle(root_display,
904 (Drawable)text_window,
905 XDefaultGC(root_display, root_screen),
906 0,0, DIAL_W, 25);
907 draw_sizes();
908
909 for (i=0; i<MAX_VSCROLLBARS; i++) (*(vscrollbar[i].sf))();
910
911 XSync(root_display, 0);
912 }
913
914
915 static char mxbuffer[128];
916
917 #ifdef ANSI_C
draw_sizes(void)918 static void draw_sizes(void)
919 #else
920 static void draw_sizes()
921 #endif
922 {
923 int i, j, yp;
924 GNODE h;
925 char *c;
926
927 XSetForeground(root_display,
928 XDefaultGC(root_display, root_screen),
929 XWhitePixel(root_display, root_screen));
930 XFillRectangle(root_display,
931 (Drawable)scroll_show_window,
932 XDefaultGC(root_display, root_screen),
933 0,0, SCROLLW_W, SCROLLW_H);
934
935 fedge_pos = vscrollbar[0].is;
936
937 yp = 18;
938 if (fedge_pos+act_selection>=fedge_top)
939 act_selection = fedge_top-1-fedge_pos;
940 if (act_selection<0) act_selection = 0;
941 if (act_selection>SCROLLW_H/18) act_selection = SCROLLW_H/18;
942
943 for (i=0; i<(SCROLLW_H/18+1); i++) {
944 if (fedge_pos+i<fedge_top)
945 h = fedge_history[fedge_pos+i];
946 else h = NULL;
947
948 XSetForeground(root_display,
949 XDefaultGC(root_display, root_screen),
950 XBlackPixel(root_display, root_screen));
951 if (i==act_selection) {
952 XFillRectangle(root_display,
953 (Drawable)scroll_show_window,
954 XDefaultGC(root_display, root_screen),
955 0,yp-16, SCROLLW_W, 19);
956 XSetForeground(root_display,
957 XDefaultGC(root_display, root_screen),
958 XWhitePixel(root_display, root_screen));
959 if (h) SPRINTF(act_title,"Enter title: %s_",NTITLE(h));
960 else SPRINTF(act_title,"Enter title: _");
961 XFillRectangle(root_display,
962 (Drawable)text_window,
963 XDefaultGC(root_display, root_screen),
964 0, 0, DIAL_W, 25);
965 }
966
967 if (!h) strcpy(mxbuffer,"");
968 else { for (j=0; j<MAX_RADIO_POINTS; j++)
969 if (radio_point[j].is == radio_point[j].sel)
970 break;
971
972 switch(j) {
973 case 0: c = NTITLE(h); break;
974 case 1: c = NLABEL(h); break;
975 case 2: c = NINFO1(h); break;
976 case 3: c = NINFO2(h); break;
977 case 4: c = NINFO3(h); break;
978 }
979
980 j = 0;
981 while ((*c)&&(j<127)) {
982 switch (*c) {
983 case '\n': mxbuffer[j++]='|'; break;
984 case '\t': mxbuffer[j++]=' '; break;
985 case '\r': break;
986 case '\v': break;
987 #ifdef ANSI_C
988 case '\a': break;
989 #endif
990 case '\b': break;
991 case '\f':
992 c++;
993 if (!*c) break;
994 if (*c=='u');
995 else if (*c=='n');
996 else { c++; if (!*c) break; }
997 break;
998 default : mxbuffer[j++] = *c;
999 }
1000 c++;
1001 }
1002 mxbuffer[j] = 0;
1003 }
1004
1005 XDrawString(root_display,
1006 (Drawable)scroll_show_window,
1007 XDefaultGC(root_display, root_screen),
1008 2,yp,mxbuffer,strlen(mxbuffer));
1009 yp += 18;
1010 }
1011 draw_textwin();
1012
1013 /* XSync(root_display, 0); */
1014 }
1015
1016
1017 #ifdef ANSI_C
draw_textwin(void)1018 static void draw_textwin(void)
1019 #else
1020 static void draw_textwin()
1021 #endif
1022 {
1023 int i;
1024
1025 i=0;
1026 while ((act_title[i]) && (i<253)) i++;
1027 if (act_title[i-1]=='_') i--;
1028 act_title[i]=0;
1029 XSetForeground(root_display,
1030 XDefaultGC(root_display, root_screen),
1031 XWhitePixel(root_display, root_screen));
1032 XFillRectangle(root_display,
1033 (Drawable)text_window,
1034 XDefaultGC(root_display, root_screen),
1035 5+XTextWidth(dialog_font,act_title,strlen(act_title)),
1036 0, DIAL_W, 25);
1037 act_title[i]='_';
1038 act_title[i+1]=0;
1039 XSetForeground(root_display,
1040 XDefaultGC(root_display, root_screen),
1041 XBlackPixel(root_display, root_screen));
1042 XDrawString(root_display,
1043 (Drawable)text_window,
1044 XDefaultGC(root_display, root_screen),
1045 5,18,act_title,strlen(act_title));
1046 XSync(root_display, 0);
1047 }
1048
1049
1050
1051 /* Draw text m into the dialog box at position x, y
1052 * ------------------------------------------------
1053 */
1054
1055 #ifdef ANSI_C
draw_text(int x,int y,char * m)1056 static void draw_text(int x,int y,char *m)
1057 #else
1058 static void draw_text(x,y, m)
1059 int x, y;
1060 char *m;
1061 #endif
1062 {
1063 XSetForeground(root_display,
1064 XDefaultGC(root_display, root_screen),
1065 XBlackPixel(root_display, root_screen));
1066 XDrawString(root_display,
1067 (Drawable)dialog_window,
1068 XDefaultGC(root_display, root_screen),
1069 x,y,m,strlen(m));
1070 }
1071
1072
1073 /* Draw underlined text m into the dialog box at position x, y
1074 * -----------------------------------------------------------
1075 */
1076
1077 #ifdef ANSI_C
draw_underl_text(int x,int y,char * m)1078 static void draw_underl_text(int x,int y,char *m)
1079 #else
1080 static void draw_underl_text(x,y, m)
1081 int x, y;
1082 char *m;
1083 #endif
1084 {
1085 int len;
1086
1087 XSetForeground(root_display,
1088 XDefaultGC(root_display, root_screen),
1089 XBlackPixel(root_display, root_screen));
1090 XDrawString(root_display,
1091 (Drawable)dialog_window,
1092 XDefaultGC(root_display, root_screen),
1093 x,y,m,strlen(m));
1094 len = XTextWidth(dialog_font,m,strlen(m));
1095 XDrawLine(root_display,(Drawable)dialog_window,
1096 XDefaultGC(root_display, root_screen),
1097 x,y+2,x+len,y+2);
1098 }
1099
1100
1101 /* Draw a dialog point in a color
1102 * ------------------------------
1103 */
1104
1105 #ifdef ANSI_C
draw_dialog_point(Window w,int color)1106 static void draw_dialog_point(Window w, int color)
1107 #else
1108 static void draw_dialog_point(w, color)
1109 Window w;
1110 int color;
1111 #endif
1112 {
1113 if (color==0) {
1114 XSetForeground(root_display,
1115 XDefaultGC(root_display, root_screen),
1116 XWhitePixel(root_display, root_screen));
1117 }
1118 else {
1119 XSetForeground(root_display,
1120 XDefaultGC(root_display, root_screen),
1121 XBlackPixel(root_display, root_screen));
1122 }
1123 XFillRectangle(root_display,(Drawable)w,
1124 XDefaultGC(root_display, root_screen),
1125 1,1,
1126 POINT_W-2,POINT_W-2);
1127 /* XSync(root_display, 0); */
1128 XFlush(root_display);
1129 }
1130
1131
1132 /* Normalize a button or point
1133 * ---------------------------
1134 */
1135
1136 #ifdef ANSI_C
normalize_point(Window w)1137 static void normalize_point(Window w)
1138 #else
1139 static void normalize_point(w)
1140 Window w;
1141 #endif
1142 {
1143 XWindowAttributes retWinAttr;
1144
1145 if (!XGetWindowAttributes(root_display,w,&retWinAttr)) {
1146 FPRINTF(stderr,"Can't get window attributes.");
1147 gs_exit(1);
1148 }
1149 if (retWinAttr.border_width==3) {
1150 XMoveWindow(root_display,w,
1151 retWinAttr.x+2, retWinAttr.y+2);
1152 }
1153 XSetWindowBorderWidth(root_display, w, 1L);
1154 }
1155
1156
1157
1158 /*--------------------------------------------------------------------*/
1159 /* Event handling */
1160 /*--------------------------------------------------------------------*/
1161
1162 /* The main loop for interaction
1163 * =============================
1164 */
1165
1166 #ifdef ANSI_C
dialog_main_loop(void)1167 static void dialog_main_loop(void)
1168 #else
1169 static void dialog_main_loop()
1170 #endif
1171 {
1172 XEvent event;
1173
1174 dialog_notready = 1;
1175 while (dialog_notready) {
1176
1177 XNextEvent (root_display, &event);
1178
1179 if (event.type != Expose)
1180 box_exposed = 0;
1181
1182 switch (event.type) {
1183 case KeyPress:
1184 prologue (&event, "KeyPress");
1185 do_KeyPress (&event);
1186 break;
1187 case ButtonPress:
1188 prologue (&event, "ButtonPress");
1189 do_ButtonPress (&event);
1190 break;
1191 case ButtonRelease:
1192 prologue (&event, "ButtonRelease");
1193 do_ButtonRelease (&event);
1194 break;
1195 case EnterNotify:
1196 prologue (&event, "EnterNotify");
1197 do_EnterNotify(&event);
1198 break;
1199 case LeaveNotify:
1200 prologue (&event, "LeaveNotify");
1201 do_LeaveNotify(&event);
1202 break;
1203 case FocusIn:
1204 prologue (&event, "FocusIn");
1205 break;
1206 case FocusOut:
1207 prologue (&event, "FocusOut");
1208 break;
1209 case Expose:
1210 prologue (&event, "Expose");
1211 do_Expose (&event);
1212 break;
1213 case ConfigureNotify:
1214 prologue (&event, "ConfigureNotify");
1215 do_ConfigureNotify (&event);
1216 break;
1217 case MotionNotify:
1218 prologue (&event, "MotionNotify");
1219 do_MotionNotify(&event);
1220 break;
1221 case GravityNotify:
1222 case CirculateRequest:
1223 case PropertyNotify:
1224 case SelectionClear:
1225 case SelectionRequest:
1226 case SelectionNotify:
1227 case ColormapNotify:
1228 case ClientMessage:
1229 case MappingNotify:
1230 case CreateNotify:
1231 case DestroyNotify:
1232 case CirculateNotify:
1233 case VisibilityNotify:
1234 case KeyRelease:
1235 case KeymapNotify:
1236 case NoExpose:
1237 case GraphicsExpose:
1238 prologue (&event, "Unhandled");
1239 break;
1240 }
1241 }
1242 }
1243
1244
1245 #ifdef EVENT_DEBUG
1246
1247 /* For debugging only: Print event message
1248 * ---------------------------------------
1249 */
1250
1251 #ifdef ANSI_C
prologue(XEvent * eventp,char * event_name)1252 static void prologue (XEvent *eventp, char *event_name)
1253 #else
1254 static void prologue (eventp, event_name)
1255 XEvent *eventp;
1256 char *event_name;
1257 #endif
1258 {
1259 XAnyEvent *e = (XAnyEvent *) eventp;
1260
1261 PRINTF ("\n%s event, serial %ld, synthetic %s, window 0x%lx,\n",
1262 event_name, e->serial, e->send_event ? "Yes" : "No", e->window);
1263 }
1264
1265 #endif /* EVENT_DEBUG */
1266
1267
1268
1269 /* Keypress Events
1270 * ---------------
1271 */
1272
1273 #ifdef ANSI_C
do_KeyPress(XEvent * eventp)1274 static void do_KeyPress (XEvent *eventp)
1275 #else
1276 static void do_KeyPress (eventp)
1277 XEvent *eventp;
1278 #endif
1279 {
1280 XKeyEvent *e = (XKeyEvent *) eventp;
1281 KeySym ks;
1282 int nbytes, i, j, old_sel_mode;
1283 char str[256+1];
1284 char lk, uk;
1285
1286 old_sel_mode = sel_mode;
1287
1288 nbytes = XLookupString (e, str, 256, &ks, NULL);
1289 if (nbytes < 0) nbytes = 0;
1290 if (nbytes > 256) nbytes = 256;
1291 str[nbytes] = '\0';
1292
1293 if (ks==0xff54) { /* Down */
1294 if (vscrollbar[0].is<fedge_top-1) vscrollbar[0].is++;
1295 set_fedge_scrollbar();
1296 draw_sizes();
1297 return;
1298 }
1299 else if (ks==0xff53) { /* Right */
1300 if (vscrollbar[0].is<fedge_top-1) vscrollbar[0].is++;
1301 set_fedge_scrollbar();
1302 draw_sizes();
1303 return;
1304 }
1305 else if (ks==0xff52) { /* Up */
1306 if (vscrollbar[0].is>0) vscrollbar[0].is--;
1307 else act_selection--;
1308 set_fedge_scrollbar();
1309 draw_sizes();
1310 return;
1311 }
1312 else if (ks==0xff51) { /* Left */
1313 if (vscrollbar[0].is>0) vscrollbar[0].is--;
1314 else act_selection--;
1315 set_fedge_scrollbar();
1316 draw_sizes();
1317 return;
1318 }
1319
1320 if (nbytes==1) {
1321
1322 if (e->window == text_window) {
1323 i = 0;
1324 while ((act_title[i]) && (i<253)) i++;
1325 if (act_title[i-1]=='_') i--;
1326 act_title[i]=0;
1327 XSetForeground(root_display,
1328 XDefaultGC(root_display, root_screen),
1329 XWhitePixel(root_display, root_screen));
1330 XFillRectangle(root_display,
1331 (Drawable)text_window,
1332 XDefaultGC(root_display, root_screen),
1333 5+XTextWidth(dialog_font,act_title,strlen(act_title)),
1334 0, DIAL_W, 25);
1335 if ((ks==0xff08)||(ks==0xffff)) {
1336 i--;
1337 if (i<13) i=13;
1338 act_title[i]=0;
1339 }
1340 else if ((ks==0xff0a)||(ks==0xff0d)) {
1341 dialog_notready = 0;
1342 i=0;
1343 while ((act_title[i]) && (i<253)) i++;
1344 if (act_title[i-1]=='_') i--;
1345 act_title[i]=0;
1346 act_node = search_visible_node(&(act_title[13]));
1347 do_follow_node(act_node);
1348 return;
1349 }
1350 else if (str[0]==27) {
1351 dialog_notready = 0;
1352 }
1353 else { /* assert((i<=253)); */
1354 act_title[i] = str[0];
1355 act_title[i+1]= 0;
1356 }
1357 act_title[255] = 0;
1358 draw_textwin();
1359 return;
1360 }
1361 /* No operation on ' ' */
1362 if (str[0]==' ') return;
1363
1364 for (i=0; i<MAX_RADIO_POINTS; i++) {
1365 lk = uk = radio_point[i].key;
1366 lk = tolower(lk);
1367 uk = toupper(uk);
1368 if ((lk==str[0])||(uk==str[0])) {
1369 radio_point[i].is = radio_point[i].sel;
1370 *(radio_point[i].glob) = radio_point[i].sel;
1371 break;
1372 }
1373 }
1374
1375 if (i<MAX_RADIO_POINTS) {
1376 for (j=0; j<MAX_RADIO_POINTS; j++) {
1377 if ((i!=j) && (radio_point[i].glob==radio_point[j].glob))
1378 radio_point[j].is = radio_point[j].sel-1
1379 ;
1380 }
1381 draw_dialog_box();
1382 return;
1383 }
1384
1385 switch (str[0]) {
1386 case '_' :
1387 case '-' :
1388 case 'p' :
1389 case 'P' :
1390 if (vscrollbar[0].is>0) vscrollbar[0].is--;
1391 else act_selection--;
1392 set_fedge_scrollbar();
1393 draw_sizes();
1394 return;
1395 case '*' :
1396 case '+' :
1397 case 'n' :
1398 case 'N' :
1399 if (vscrollbar[0].is<fedge_top-1) vscrollbar[0].is++;
1400 set_fedge_scrollbar();
1401 draw_sizes();
1402 return;
1403
1404 case '\r': /* Carriage Return */
1405 case '\n': /* Carriage Return */
1406 case 's':
1407 case 'S':
1408 i=0;
1409 while ((act_title[i]) && (i<253)) i++;
1410 if (act_title[i-1]=='_') i--;
1411 act_title[i]=0;
1412 act_node = search_visible_node(&(act_title[13]));
1413 do_follow_node(act_node);
1414 return;
1415 case 'E':
1416 case 'e':
1417 do_next_follow_edge();
1418 return;
1419
1420 case 'F':
1421 case 'f':
1422 do_apply_follow_edge();
1423 return;
1424
1425 case 'q':
1426 case 'Q':
1427 case 27: /* Cancel */
1428 dialog_notready = 0;
1429 return;
1430 }
1431 draw_dialog_box();
1432 }
1433 }
1434
1435
1436
1437
1438 /* Button Press
1439 * ------------
1440 */
1441
1442 static Window act_scroll_window = 0;
1443
1444 #ifdef ANSI_C
do_ButtonPress(XEvent * eventp)1445 static void do_ButtonPress (XEvent *eventp)
1446 #else
1447 static void do_ButtonPress (eventp)
1448 XEvent *eventp;
1449 #endif
1450 {
1451 XButtonEvent *e = (XButtonEvent *) eventp;
1452 Window w;
1453 int i,j, old_sel_mode;
1454
1455 w = e->window;
1456
1457 act_scroll_window = w;
1458 old_sel_mode = sel_mode;
1459
1460 for (i=0; i<MAX_RADIO_POINTS; i++) {
1461 if (w == radio_point[i].w) {
1462 radio_point[i].is = radio_point[i].sel;
1463 *(radio_point[i].glob) = radio_point[i].sel;
1464 break;
1465 }
1466 }
1467
1468 if (i<MAX_RADIO_POINTS) {
1469 for (j=0; j<MAX_RADIO_POINTS; j++) {
1470 if ((i!=j) && (radio_point[i].glob==radio_point[j].glob))
1471 radio_point[j].is = radio_point[j].sel-1;
1472 }
1473 draw_sizes();
1474 }
1475
1476 for (i=0; i<MAX_RADIO_POINTS; i++)
1477 if (radio_point[i].is == radio_point[i].sel)
1478 draw_dialog_point(radio_point[i].w,1);
1479 else draw_dialog_point(radio_point[i].w,0);
1480
1481
1482 for (i=0; i<MAX_VSCROLLBARS; i++) {
1483 if (act_scroll_window==vscrollbar[i].ws) {
1484 (*(vscrollbar[i].rf))(e->y);
1485 draw_sizes();
1486 }
1487 }
1488
1489 if (w==nedge_button) {
1490 do_next_follow_edge();
1491 }
1492 else if (w==fedge_button) {
1493 do_apply_follow_edge();
1494 }
1495 else if (w==cancel_button) {
1496 dialog_notready = 0;
1497 }
1498 else if (w==snode_button) {
1499 i=0;
1500 while ((act_title[i]) && (i<253)) i++;
1501 if (act_title[i-1]=='_') i--;
1502 act_title[i]=0;
1503 act_node = search_visible_node(&(act_title[13]));
1504 do_follow_node(act_node);
1505 }
1506 else if (w==next_button) {
1507 if (vscrollbar[0].is<fedge_top-1) vscrollbar[0].is++;
1508 set_fedge_scrollbar();
1509 draw_sizes();
1510 }
1511 else if (w==prev_button) {
1512 if (vscrollbar[0].is>0) vscrollbar[0].is--;
1513 else act_selection--;
1514 set_fedge_scrollbar();
1515 draw_sizes();
1516 }
1517 else if (w==scroll_show_window) {
1518 act_selection = (e->y)/18;
1519 draw_sizes();
1520 }
1521 else if ((w==myframe_win) || (w==mypix_win)) {
1522
1523 if (e->button==G_MOUSE_LEFT) {
1524 do_next_follow_edge();
1525 }
1526 if (e->button==G_MOUSE_RIGHT) {
1527 if (!act_follow_edge_visible) dialog_notready = 0;
1528 else do_apply_follow_edge();
1529 }
1530 }
1531 }
1532
1533
1534
1535 /* Button Release
1536 * --------------
1537 */
1538
1539 #ifdef ANSI_C
do_ButtonRelease(XEvent * eventp)1540 static void do_ButtonRelease (XEvent *eventp)
1541 #else
1542 static void do_ButtonRelease (eventp)
1543 XEvent *eventp;
1544 #endif
1545 {
1546 XButtonEvent *e = (XButtonEvent *) eventp;
1547 int i;
1548
1549 if (act_scroll_window && (e->window!=act_scroll_window)) {
1550 for (i=0; i<MAX_VSCROLLBARS; i++) (*(vscrollbar[i].sf))();
1551 draw_dialog_box();
1552 act_scroll_window = 0;
1553 return;
1554 }
1555
1556 for (i=0; i<MAX_VSCROLLBARS; i++) {
1557 if (act_scroll_window==vscrollbar[i].ws) {
1558 (*(vscrollbar[i].rf))(e->y);
1559 break;
1560 }
1561 }
1562 if (i<MAX_VSCROLLBARS) draw_sizes();
1563 act_scroll_window = 0;
1564 }
1565
1566
1567
1568 /* Mark a selection point as selectable
1569 * ------------------------------------
1570 */
1571
1572 #ifdef ANSI_C
do_EnterNotify(XEvent * eventp)1573 static void do_EnterNotify (XEvent *eventp)
1574 #else
1575 static void do_EnterNotify (eventp)
1576 XEvent *eventp;
1577 #endif
1578 {
1579 XCrossingEvent *e = (XCrossingEvent *) eventp;
1580 Window w;
1581 XWindowAttributes retWinAttr;
1582 int i, is_point;
1583
1584 is_point = 0;
1585 w = e->window;
1586
1587 for (i=0; i<MAX_RADIO_POINTS; i++)
1588 if (w==radio_point[i].w) is_point = 1;
1589
1590 if ( (w==nedge_button)||(w==cancel_button)||(w==snode_button)
1591 ||(w==fedge_button)||(w==next_button)||(w==prev_button))
1592 is_point = 1;
1593
1594 if (is_point) {
1595 if (!XGetWindowAttributes(root_display,w,&retWinAttr)) {
1596 FPRINTF(stderr,"Can't get window attributes.");
1597 gs_exit(1);
1598 }
1599 if (retWinAttr.border_width==1) {
1600 XMoveWindow(root_display,w,
1601 retWinAttr.x-2, retWinAttr.y-2);
1602 }
1603 XSetWindowBorderWidth(root_display, w, 3L);
1604 }
1605 }
1606
1607
1608 /* Unmark a selection point
1609 * ------------------------
1610 * The menupoint is not anymore selected.
1611 */
1612
1613 #ifdef ANSI_C
do_LeaveNotify(XEvent * eventp)1614 static void do_LeaveNotify (XEvent *eventp)
1615 #else
1616 static void do_LeaveNotify (eventp)
1617 XEvent *eventp;
1618 #endif
1619 {
1620 XCrossingEvent *e = (XCrossingEvent *) eventp;
1621 Window w;
1622 int i, is_point;
1623
1624 is_point = 0;
1625 w = e->window;
1626
1627 for (i=0; i<MAX_RADIO_POINTS; i++)
1628 if (w==radio_point[i].w) is_point = 1;
1629
1630 if ( (w==nedge_button)||(w==cancel_button)||(w==snode_button)
1631 ||(w==fedge_button)||(w==next_button)||(w==prev_button))
1632 is_point = 1;
1633
1634 if (is_point) normalize_point(w);
1635 }
1636
1637
1638 /* Expose a window
1639 * ---------------
1640 */
1641
1642 #ifdef ANSI_C
do_Expose(XEvent * eventp)1643 static void do_Expose (XEvent *eventp)
1644 #else
1645 static void do_Expose (eventp)
1646 XEvent *eventp;
1647 #endif
1648 {
1649 XExposeEvent *e = (XExposeEvent *) eventp;
1650
1651 if (e->window==dialog_window) {
1652 if ((e->width>12)&&(e->height>12)&&(!box_exposed)) {
1653 draw_dialog_box();
1654 box_exposed = 1;
1655 }
1656 }
1657 else box_exposed = 0;
1658 do_gblExpose(eventp);
1659 }
1660
1661
1662 /* Resize or move a window
1663 * -----------------------
1664 */
1665
1666 #ifdef ANSI_C
do_ConfigureNotify(XEvent * eventp)1667 static void do_ConfigureNotify (XEvent *eventp)
1668 #else
1669 static void do_ConfigureNotify (eventp)
1670 XEvent *eventp;
1671 #endif
1672 {
1673 XConfigureEvent *e = (XConfigureEvent *) eventp;
1674
1675 if (e->window==dialog_window) {
1676 XResizeWindow(root_display,dialog_window,DIAL_W,DIAL_H);
1677 draw_dialog_box();
1678 }
1679 else do_gblConfigureNotify(eventp);
1680 }
1681
1682
1683 /* Motion with pressed button
1684 * --------------------------
1685 */
1686
1687 #ifdef ANSI_C
do_MotionNotify(XEvent * eventp)1688 static void do_MotionNotify (XEvent *eventp)
1689 #else
1690 static void do_MotionNotify (eventp)
1691 XEvent *eventp;
1692 #endif
1693 {
1694 int i;
1695
1696 XMotionEvent *e = (XMotionEvent *) eventp;
1697
1698 for (i=0; i<MAX_VSCROLLBARS; i++) {
1699 if (act_scroll_window==vscrollbar[i].ws) {
1700 (*(vscrollbar[i].rf))(e->y);
1701 break;
1702 }
1703 }
1704 if (i<MAX_VSCROLLBARS) draw_sizes();
1705 }
1706
1707
1708 /*--------------------------------------------------------------------*/
1709 /* Scrollbar handling */
1710 /*--------------------------------------------------------------------*/
1711
1712
1713 #ifdef ANSI_C
read_fedge_scrollbar(int val)1714 static void read_fedge_scrollbar(int val)
1715 #else
1716 static void read_fedge_scrollbar(val)
1717 int val;
1718 #endif
1719 {
1720 if (val<0) val = 0;
1721 if (val+SCROLLBAR_LEN >= vscrollbar[0].len)
1722 val = vscrollbar[0].len - SCROLLBAR_LEN;
1723 XMoveResizeWindow(root_display,vscrollbar[0].wt,0,val,6,SCROLLBAR_LEN);
1724 vscrollbar[0].is = fedge_top*val/(vscrollbar[0].len-SCROLLBAR_LEN);
1725 }
1726
1727
1728 #ifdef ANSI_C
set_fedge_scrollbar(void)1729 static void set_fedge_scrollbar(void)
1730 #else
1731 static void set_fedge_scrollbar()
1732 #endif
1733 {
1734 int val;
1735
1736 val = (vscrollbar[0].is)*(vscrollbar[0].len-SCROLLBAR_LEN)/fedge_top;
1737 if (val<0) val = 0;
1738 if (val+SCROLLBAR_LEN >= vscrollbar[0].len)
1739 val = vscrollbar[0].len - SCROLLBAR_LEN;
1740 XMoveResizeWindow(root_display, vscrollbar[0].wt,0,val,6,SCROLLBAR_LEN);
1741 }
1742
1743
1744 /*--------------------------------------------------------------------*/
1745
1746 #endif /* X11 */
1747
1748