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