1 /*
2 //
3 // send.c
4 //
5 //
6 */
7 
8 #include "xbook.h"
9 
10 #include "sendev.xb"
11 
12 #define MESSAGE "XSendEvent() Exemplo..."
13 #define PRESS_MESSAGE "Precione o botao do mouse na janela desejada..."
14 
15 int 	RefreshFlag 	=	False;
16 int 	QuitFlag	=	False;
17 GC	AppGC;
18 char	SendText[ BUFSIZE + 1 ];
19 
main(argc,argv)20 main( argc, argv )
21 int	argc;
22 char	*argv[];
23 {
24 	Display		*display;
25 	int		screen;
26 	Window		window;
27 	int		x, y, width, height;
28 	XFontStruct	*font;
29 	Pixmap		icon;
30 	int		font_height;
31 	unsigned long	black, white;
32 
33 	display	= SetUpDisplay( argc, argv, &screen );
34 	black	= BlackPixel( display, screen );
35 	white	= WhitePixel( display, screen );
36 	x	= 10;
37 	y	= 10;
38 	width	= 510;
39 	height	= 80;
40 	CheckGeometry( argc, argv,
41 		DisplayWidth( display, screen ),
42 		DisplayHeight( display, screen ),
43 		&x, &y, &width, &height );
44 	window	= TopWindow( display, x, y, width, height,
45 			sendev_bits, sendev_width, sendev_height,
46 			&icon,  &AppGC );
47 	font 	= LoadFont( display, AppGC, argc, argv, "variable" );
48 	font_height	= (font->ascent + font->descent);
49 	SetNormalHints( display, window,
50 		x, y, width, height );
51 	SetWMHints( display, window, icon );
52 	NameWindow( display, window, "envia", "envia", "Envia" );
53 	SetICCCM( display, window, argc, argv );
54 	SendText[ 0 ] = '\0';
55 	XFlush( display );
56 	MakeButtons( display, window, black, white, font->fid );
57 	MapWindow( display, window );
58 	while( QuitFlag == False )
59 	{
60 		EventLoop( display,
61 			window, AppGC, font,
62 			&width, &height );
63 		if( RefreshFlag == True )
64 		{
65 			Refresh( display, window, AppGC, font_height );
66 			RefreshFlag	= False;
67 		}
68 	}
69 	XFreeFont( display, font );
70 	XFreePixmap( display, icon );
71 	CloseDisplay( display, window, AppGC );
72 	exit( 0 );
73 }
74 
SendData(display,window)75 SendData( display, window )
76 Display		*display;
77 Window		window;
78 {
79 	Window	send_window;
80 
81 	send_window	= FindSendWindow( display, window );
82 	if( send_window != (Window) None )
83 	{
84 		SendString( display, send_window, SendText );
85 	}
86 	RefreshFlag = True;
87 	XFlush( display );
88 	XClearWindow( display, window );
89 }
90 
ClearData(display,window)91 ClearData( display, window )
92 Display		*display;
93 Window		window;
94 {
95 	SendText[ 0 ] = '\0';
96 	XClearWindow( display, window );
97 	RefreshFlag	= True;
98 }
99 
EventLoop(display,window,gc,font,width,height)100 EventLoop( display, window, gc, font, width, height )
101 Display		*display;
102 Window		window;
103 GC		gc;
104 XFontStruct	*font;
105 int		*width, *height;
106 {
107 	XEvent	event;
108 	KeySym	keysym;
109 
110 	NextEvent( display, False, *width, *height, &event, &keysym );
111 	if( ButtonEvent( display, &event ) == True )
112 	{
113 		return( True );
114 	}
115 	switch( event.type )
116 	{
117 		case ClientMessage:
118 			if( IsDeleteWindow( display, &event ) == True )
119 			{
120 				QuitFlag = True;
121 			}
122 			break;
123 		case Expose:
124 			RefreshFlag	= True;
125 			break;
126 		case ConfigureNotify:
127 			*width = event.xconfigure.width;
128 			*height= event.xconfigure.height;
129 			break;
130 		case KeyPress:
131 			TextEdit( display, window, gc, font,
132 				5, 2 * BUTTON_HEIGHT, keysym,
133 				SendText, BUFSIZE );
134 			break;
135 	}
136 	return ( True );
137 }
138 
QuitApplication(display,window)139 QuitApplication( display, window )
140 Display	*display;
141 Window	window;
142 {
143 	QuitFlag = True;
144 }
145 
MakeButtons(display,window,fore,back,font_id)146 MakeButtons( display, window, fore, back, font_id )
147 Display		*display;
148 Window		window;
149 unsigned long	fore, back;
150 Font		font_id;
151 {
152 	int	QuitApplication();
153 	int	SendData();
154 	int	ClearData();
155 	int	x;
156 
157 	x = 1;
158 	CreateButton( display, window, x, 2, fore, back,
159 		font_id, "Sair", QuitApplication );
160 	x = BUTTON_WIDTH + 5;
161 	CreateButton( display, window, x, 2, fore, back,
162 		font_id, "Envia", SendData );
163 	x += BUTTON_WIDTH + 5;
164 	CreateButton( display, window, x, 2, fore, back,
165 		font_id, "Apaga", ClearData );
166 }
167 
Refresh(display,window,gc,font_height)168 Refresh( display, window, gc, font_height )
169 Display		*display;
170 Window		window;
171 GC		gc;
172 int		font_height;
173 {
174 	XDrawImageString( display, window, gc,
175 		( 3 * (BUTTON_WIDTH + 5) ) + 5,
176 		BUTTON_HEIGHT - 5,
177 		MESSAGE, strlen( MESSAGE ) );
178 	XDrawImageString( display, window, gc,
179 		5, ( 2 * BUTTON_HEIGHT ),
180 		SendText, strlen( SendText ) );
181 	XFlush( display );
182 }
183 
FindSendWindow(display,window)184 Window FindSendWindow( display, window )
185 Display	*display;
186 Window	window;
187 {
188 	int	screen;
189 	Window	rootwindow, send_window;
190 	Cursor	cursor;
191 
192 	XDrawImageString( display, window, AppGC,
193 		( 3 * ( BUTTON_WIDTH + 5 ) ) + 5,
194 		BUTTON_HEIGHT - 5,
195 		PRESS_MESSAGE, strlen( PRESS_MESSAGE ) );
196 	XFlush( display );
197 	screen		= DefaultScreen( display );
198 	rootwindow	= RootWindow( display, screen );
199 	cursor		= XCreateFontCursor( display, XC_gumby );
200 	send_window	= PickWindow( display, rootwindow, cursor );
201 	XFreeCursor( display, cursor );
202 	return( send_window );
203 }
204 
205