1 /* Loglan82 Compiler&Interpreter
2 Copyright (C) 1993 Institute of Informatics, University of Warsaw
3 Copyright (C) 1993, 1994 LITA, Pau
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 contacts: Andrzej.Salwicki@univ-pau.fr
22 LITA Departement d'Informatique
24 Avenue de l'Universite
26 tel. ++33 59923154 fax. ++33 59841696
28 =======================================================================
35 #include <X11/cursorfont.h>
36 #include <X11/keysym.h>
38 /*#include <X11/Xos.h>*/
40 #include <X11/Xutil.h>
41 #include <X11/Xatom.h>
43 #include <X11/MwmUtil.h>
51 int theDepth, theScreen, dispcells;
53 Window rootW, window, father;
55 unsigned long fcol,bcol,white,black,style=1;
60 XClientMessageEvent toFatherEv;
65 int mouse_x=0,mouse_y=0,mouse_l=0,mouse_r=0,mouse_c=0,
66 mouse_l_prs=0,mouse_r_prs=0,mouse_c_prs=0,
67 mouse_l_p_x=0,mouse_r_p_x=0,mouse_c_p_x=0,
68 mouse_l_p_y=0,mouse_r_p_y=0,mouse_c_p_y=0,
69 mouse_l_rel=0,mouse_r_rel=0,mouse_c_rel=0,
70 mouse_l_r_x=0,mouse_r_r_x=0,mouse_c_r_x=0,
71 mouse_l_r_y=0,mouse_r_r_y=0,mouse_c_r_y=0;
73 #define END_OF_TRACK -9999
77 #define get_shrt(w) w=(int)(*(pars++));
78 #define get_word(w) w=((int)(pars[0])&0xffff)|((int)pars[1]<<16); pars+=2;
80 #define put_shrt(w) toFatherEv.data.s[cnt++] = (short)(w);
81 #define put_word(w) toFatherEv.data.s[cnt++] = (short)((w) & 0xffff); \
82 toFatherEv.data.s[cnt++] = (short)(((w) >> 16) & 0xffff);
83 #define snd_father toFatherEv.type=ClientMessage; \
84 toFatherEv.format = 16; \
85 XSendEvent(theDisp,father,False,NoEventMask,&toFatherEv); \
89 void RealiseCmd(int,short *);
95 static char *application_name="IIUWGRAPH";
99 static KeySym keycodes[QSIZE];
100 static int keyhead=0,keytail=0;
110 father = atoi(argv[1]);
112 for( i=2; i<argc; i++ ) argv[i-1]=argv[i];
115 if ((theDisp = XOpenDisplay(NULL)) == NULL){
116 fprintf (stderr,"\n%s: Can't open display\n", argv[0]);
120 theScreen = DefaultScreen(theDisp);
121 theDepth = DefaultDepth(theDisp, theScreen);
122 rootW = RootWindow(theDisp,theScreen);
123 fcol=white= WhitePixel(theDisp,theScreen);
124 bcol=black= BlackPixel(theDisp,theScreen);
125 theVisual = DefaultVisual(theDisp,theScreen);
126 theCmap = XCreateColormap(theDisp,rootW,theVisual,AllocNone);
127 dispcells = DisplayCells(theDisp, theScreen);
128 theCursor = XCreateFontCursor(theDisp,XC_arrow);
130 iWIDE = 720; iHIGH = 348;
132 if ((mfinfo = XLoadQueryFont(theDisp,"fixed"))==NULL){
133 fprintf (stderr,"\n%s: Can't open 'fixed' font\n", argv[0]);
138 theHints.width =iWIDE;
139 theHints.height=iHIGH;
140 theHints.flags=PSize;
141 window = XCreateSimpleWindow(theDisp,rootW,10,10,iWIDE,iHIGH,3,fcol,bcol);
143 XSetStandardProperties(theDisp,window,"HERCULES","HERCULES",
144 None,argv,argc,theHints);
145 XDefineCursor(theDisp,window,theCursor);
147 XChangeProperty(theDisp,window,XA_WM_CLASS,XA_STRING,8,PropModeReplace,
148 application_name,strlen(application_name));
157 Atom a=XInternAtom(theDisp,_XA_MWM_HINTS,False);
158 hints.flags = MWM_HINTS_FUNCTIONS;
159 hints.functions = MWM_FUNC_CLOSE | MWM_FUNC_MOVE;
160 hints.decorations = 0;
161 hints.input_mode = 0;
162 XChangeProperty(theDisp,window,a,a,32,PropModeReplace,&hints,4);
165 theGC = XCreateGC(theDisp,window,0,0);
166 XSetFont(theDisp,theGC,mfont);
167 XSetForeground(theDisp,theGC,fcol);
168 XSetBackground(theDisp,theGC,bcol);
170 XSelectInput(theDisp,window,
177 XMapRaised(theDisp,window);
179 pixmap = XCreatePixmap(theDisp,window,iWIDE,iHIGH,theDepth);
183 XNextEvent(theDisp,&event);
189 int x=event.xexpose.x;
190 int y=event.xexpose.y;
191 int w=event.xexpose.width;
192 int h=event.xexpose.height;
194 XCopyArea(theDisp,pixmap,window,theGC,x,y,w,h,x,y);
204 RealiseCmd( (int)(event.xclient.message_type),event.xclient.data.s);
208 if( event.xmapping.request == MappingModifier ||
209 event.xmapping.request == MappingKeyboard )
210 XRefreshKeyboardMapping(&event);
217 int i=XLookupString( &(event.xkey), &ch, 1, &key, NULL );
220 if( ch == '\177' ) keycodes[ keytail++ ] = -83;
221 else keycodes[ keytail++ ] = (int)ch;
223 if( key == NoSymbol ) break;
225 if( IsModifierKey( key ) ) break;
230 case XK_F1 : to_return = -59; break;
231 case XK_F2 : to_return = -60; break;
232 case XK_F3 : to_return = -61; break;
233 case XK_F4 : to_return = -62; break;
234 case XK_F5 : to_return = -63; break;
235 case XK_F6 : to_return = -64; break;
236 case XK_F7 : to_return = -65; break;
237 case XK_F8 : to_return = -66; break;
238 case XK_F9 : to_return = -67; break;
239 case XK_F10 : to_return = -68; break;
240 case XK_Home : to_return = -71; break;
241 case XK_Left : to_return = -75; break;
242 case XK_Up : to_return = -72; break;
243 case XK_Right : to_return = -77; break;
244 case XK_Down : to_return = -80; break;
245 case XK_End : to_return = -79; break;
246 case XK_Insert: to_return = -82; break;
247 case XK_Break : to_return = -3; break;
248 case XK_Prior : to_return = -73; break;
249 case XK_Next : to_return = -81; break;
251 if( to_return!=0 ) keycodes[ keytail++ ] = to_return;
255 if( keytail == QSIZE ) keytail = 0;
256 if( keytail == keyhead ){
258 if( keytail < 0 ) keytail = QSIZE ;
266 mouse_x = event.xmotion.x;
267 mouse_y = event.xmotion.y;
268 if( event.type == ButtonPress ){
269 switch( event.xbutton.button ){
270 case Button1 : mouse_l=1; mouse_l_prs++;
271 mouse_l_p_x = mouse_x;
272 mouse_l_p_y = mouse_y;
275 RealiseCmd( END_OF_TRACK, NULL );
278 case Button2 : mouse_c=1; mouse_c_prs++;
279 mouse_c_p_x = mouse_x;
280 mouse_c_p_y = mouse_y;
282 case Button3 : mouse_r=1; mouse_r_prs++;
283 mouse_r_p_x = mouse_x;
284 mouse_r_p_y = mouse_y;
288 if( event.type == ButtonRelease ){
289 switch( event.xbutton.button ){
290 case Button1 : mouse_l=0; mouse_l_rel++;
291 mouse_l_r_x = mouse_x;
292 mouse_l_r_y = mouse_y;
294 case Button2 : mouse_c=0; mouse_c_rel++;
295 mouse_c_r_x = mouse_x;
296 mouse_c_r_y = mouse_y;
298 case Button3 : mouse_r=0; mouse_r_rel++;
299 mouse_r_r_x = mouse_x;
300 mouse_r_r_y = mouse_y;
306 } /* end of switch */
314 word cmd=0,w,h,x,y,curx,cury,kolb,wwyp,p,q,r,color;
315 word alfa,beta,aspect;
322 void RealiseCmd( cmd, pars ) int cmd; short *pars; {
330 XSetForeground(theDisp,theGC,bcol);
331 XFillRectangle(theDisp,pixmap,theGC,0,0,iWIDE,iHIGH);
332 XFillRectangle(theDisp,window,theGC,0,0,iWIDE,iHIGH);
333 XSetForeground(theDisp,theGC,fcol);
337 XFreePixmap(theDisp,pixmap);
338 XDestroyWindow(theDisp,window);
339 XCloseDisplay(theDisp);
346 if( keyhead != keytail ){
347 keycode = keycodes[ keyhead++ ];
348 if( keyhead == QSIZE ) keyhead = 0;
358 XDrawPoint(theDisp,pixmap,theGC,x,y);
359 XDrawPoint(theDisp,window,theGC,x,y);
367 XDrawLine(theDisp,pixmap,theGC,curx,cury,x,y);
368 XDrawLine(theDisp,window,theGC,curx,cury,x,y);
378 XDrawArc(theDisp,pixmap,theGC,x,y,r,aspect,alfa,beta);
379 XDrawArc(theDisp,window,theGC,x,y,r,aspect,alfa,beta);
386 XDrawLine(theDisp,pixmap,theGC,curx,cury,x,cury);
387 XDrawLine(theDisp,window,theGC,curx,cury,x,cury);
394 XDrawLine(theDisp,pixmap,theGC,curx,cury,curx,y);
395 XDrawLine(theDisp,window,theGC,curx,cury,curx,y);
401 image=XGetImage(theDisp,pixmap,x,y,1,1,0x7fffffffL,ZPixmap);
402 color = XGetPixel(image,0,0);
403 XDestroyImage(image);
415 if( w>iWIDE ) w=iWIDE;
416 if( h>iHIGH ) h=iHIGH;
417 map = XCreatePixmap(theDisp,window,w,h,theDepth);
418 XCopyArea(theDisp,pixmap,map,theGC,x,y,w,h,0,0);
430 case XORMAP: XSetFunction(theDisp,theGC,GXxor); break;
431 case ORMAP: XSetFunction(theDisp,theGC,GXor ); break;
438 if( w>iWIDE ) w=iWIDE;
439 if( h>iHIGH ) h=iHIGH;
440 XCopyArea(theDisp,map,pixmap,theGC,0,0,w,h,curx,cury);
441 XCopyArea(theDisp,map,window,theGC,0,0,w,h,curx,cury);
442 if( cmd != PUTMAP ) XSetFunction(theDisp,theGC,GXcopy);
448 if( color == 0 ) fcol = black ;
450 XSetForeground(theDisp,theGC,fcol);
455 if( color == 0 ) bcol = black ;
457 XSetBackground(theDisp,theGC,bcol);
462 static char style_2[]={ 6, 3 };
463 static char style_3[]={ 4, 6 };
464 static char style_4[]={ 2, 3 };
465 static char style_5[]={ 2, 9 };
470 XSetForeground(theDisp,theGC,bcol);
471 XSetLineAttributes(theDisp,theGC,0,LineSolid,CapButt,JoinMiter);
474 XSetForeground(theDisp,theGC,fcol);
475 XSetLineAttributes(theDisp,theGC,0,LineSolid,CapButt,JoinMiter);
478 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
480 XSetDashes(theDisp,theGC,0,style_2,2);
483 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
485 XSetDashes(theDisp,theGC,0,style_3,2);
488 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
490 XSetDashes(theDisp,theGC,0,style_4,2);
493 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
495 XSetDashes(theDisp,theGC,0,style_5,2);
506 XSetForeground(theDisp,theGC,bcol);
507 XFillRectangle(theDisp,pixmap,theGC,curx,cury,8,8);
508 XFillRectangle(theDisp,window,theGC,curx,cury,8,8);
509 XSetForeground(theDisp,theGC,fcol);
512 XDrawString(theDisp,pixmap,theGC,curx,cury+8,&c,1);
513 XDrawString(theDisp,window,theGC,curx,cury+8,&c,1);
531 if( cmd == GETPRESS )
535 put_shrt( mouse_l_p_x );
536 put_shrt( mouse_l_p_y );
537 put_shrt( mouse_l_prs );
542 put_shrt( mouse_r_p_x );
543 put_shrt( mouse_r_p_y );
544 put_shrt( mouse_r_prs );
549 put_shrt( mouse_c_p_x );
550 put_shrt( mouse_c_p_y );
551 put_shrt( mouse_c_prs );
555 default:put_shrt( 0 );
565 put_shrt( mouse_l_r_x );
566 put_shrt( mouse_l_r_y );
567 put_shrt( mouse_l_rel );
572 put_shrt( mouse_r_r_x );
573 put_shrt( mouse_r_r_y );
574 put_shrt( mouse_r_rel );
579 put_shrt( mouse_c_r_x );
580 put_shrt( mouse_c_r_y );
581 put_shrt( mouse_c_rel );
585 default:put_shrt( 0 );
612 get_shrt( x ) /* these parameters are not used */
615 /* now we wait to point and press left button */
626 fprintf(stderr,"UKNOWN COMMAND for HERCULES emulation - %d\n",cmd);
628 XFreePixmap(theDisp,pixmap);
629 XDestroyWindow(theDisp,window);
630 XCloseDisplay(theDisp);