1 /*
2 // read.c
3 //
4 */
5 
6 #include "xbook.h"
7 
8 #define	INV_MAX_BUTTONS 5
9 
10 
11 struct {
12 	Display	*display;
13 	Window	w;
14 	int x, y, largura, altura;
15 	int (*function) ();
16 	} InvButtons[ INV_MAX_BUTTONS + 1 ];
17 
18 int		inv_used = 0;
19 int		qual=1;
20 
InvButton(display,window,x,y,c,a,function)21 InvButton( display, window, x, y, c, a, function )
22 Display		*display;
23 Window		window;
24 int		x, y, c, a;
25 int		(*function) ();
26 {
27 	if( inv_used < ( INV_MAX_BUTTONS - 1) )
28 	{
29  		InvButtons[ inv_used ].display	= display;
30 		InvButtons[ inv_used ].w		= window;
31 		InvButtons[ inv_used ].x		= x;
32 		InvButtons[ inv_used ].y		= y;
33 		InvButtons[ inv_used ].largura	= c;
34 		InvButtons[ inv_used ].altura	= a;
35 		InvButtons[ inv_used ].function	= function;
36  		inv_used++;
37 		return( True );
38 	}
39 	return( False);
40 }
41 
InvEvent(display,event)42 InvEvent( display, event )
43 Display	*display;
44 XEvent	*event;
45 {
46 	int	which_button;
47 
48 	switch( event->type )
49 	{
50 		case ButtonPress:
51 			if(event->xbutton.button ==1) qual=1; else qual=10;
52 			which_button = InvFind( display,
53 			    event->xbutton.window,
54 			    event->xbutton.x,
55 			    event->xbutton.y );
56 			if( which_button >= 0 )
57 			{
58  				(InvButtons[ which_button ].function)(display,
59 				  InvButtons[ which_button ].w, qual );
60 				return( True );
61 			}
62 			break;
63 	}
64 	return( False );
65 }
66 
InvFind(display,window,p1,p2)67 InvFind( display, window, p1, p2 )
68 Display *display;
69 Window	window;
70 int p1, p2;
71 {
72 	int which_button;
73 	int x, y, c, a;
74 
75 	for( which_button = 0; which_button < inv_used; which_button++ )
76 	{
77 		if( ( window == InvButtons[ which_button ].w ) &&
78 		  ( display == InvButtons[ which_button ].display ) )
79 		{
80 			x= InvButtons[ which_button ].x;
81 			y= InvButtons[ which_button ].y;
82 			c= InvButtons[ which_button ].largura;
83 			a= InvButtons[ which_button ].altura;
84 			if((p1>=x) && (p1<=(x+c)) && (p2>=y) && (p2<=(y+a)))
85 				return( which_button );
86 		}
87 	}
88 	return ( -1 );
89 }
90