1 /*
2  * XMapEdit, the XPilot Map Editor.  Copyright (C) 1993 by
3  *
4  *      Aaron Averill           <averila@oes.orst.edu>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * Modifications to XMapEdit
21  * 1996:
22  *      Robert Templeman        <mbcaprt@mphhpd.ph.man.ac.uk>
23  * 1997:
24  *      William Docter          <wad2@lehigh.edu>
25  *
26  * $Id: events.c,v 5.0 2001/04/07 20:01:00 dik Exp $
27  */
28 
29 #include                 "main.h"
30 
31 /***************************************************************************/
32 /* MainEventLoop                                                           */
33 /* Arguments :                                                             */
34 /* Purpose :                                                               */
35 /***************************************************************************/
MainEventLoop(void)36 void MainEventLoop(void)
37 {
38    XEvent                report;
39 
40    while (1) {
41       XNextEvent( display, &report);
42 
43       if ( (report.type == Expose) && (report.xexpose.window == mapwin) &&
44            (report.xexpose.count == 0) ) {
45          T_ClearArea(mapwin,0,0,TOOLSWIDTH,mapwin_height);
46       }
47 
48       T_FormEventCheck(&report);
49 
50       switch (report.type) {
51 
52          case ConfigureNotify:
53             if (report.xconfigure.window == mapwin) {
54                mapwin_width = report.xconfigure.width;
55                mapwin_height = report.xconfigure.height;
56                T_FormScrollArea(mapwin,"draw_map_icon",T_SCROLL_UNBOUND,
57                TOOLSWIDTH,0,mapwin_width-TOOLSWIDTH,mapwin_height,DrawMapIcon);
58                break;
59             }
60 
61          case Expose:
62             if (report.xexpose.window == mapwin) {
63                if ( report.xexpose.count == 0)
64                DrawTools();
65                DrawMap(report.xexpose.x,report.xexpose.y,report.xexpose.width,
66                     report.xexpose.height);
67                DrawSelectArea();
68                break;
69             } else if ( (report.xexpose.window == helpwin) &&
70                  (report.xexpose.count == 0) ) {
71                DrawHelpWin();
72                break;
73             }
74 
75          case KeyPress:
76             MapwinKeyPress(&report);
77             break;
78 
79 	 case ClientMessage:
80 	    if (report.xclient.message_type == ProtocolAtom
81 	       && report.xclient.format == 32
82 	       && report.xclient.data.l[0] == KillAtom) {
83 		    if (report.xclient.window == mapwin) {
84 				XDestroyWindow(display, mapwin);
85 				XSync(display, True);
86 				XCloseDisplay(display);
87 		       		exit(0);
88 		    }
89 		    else {
90 				XUnmapWindow(display, report.xclient.window);
91 			}
92 	   }
93       } /* end switch */
94    }
95 
96 }
97 
98 /***************************************************************************/
99 /* MapwinKeyPres                                                           */
100 /* Arguments :                                                             */
101 /*    report                                                               */
102 /* Purpose : If keypress is number or letter, draw numbered base or        */
103 /*           checkpoint.                                                   */
104 /***************************************************************************/
MapwinKeyPress(XEvent * report)105 void MapwinKeyPress(XEvent *report)
106 {
107    int                   x,y;
108    char                  buffer[1],icon;
109    int                   bufsize=1;
110    KeySym                keysym;
111    XComposeStatus        compose;
112    int                   count;
113 
114    if ( (report->xkey.x < TOOLSWIDTH) || (report->xkey.window != mapwin) ) {
115       return;
116    }
117    x = report->xkey.x - TOOLSWIDTH;
118    y = report->xkey.y;
119    x /= map.view_zoom;
120    y /= map.view_zoom;
121    x += map.view_x;
122    y += map.view_y;
123    count = XLookupString(&report->xkey, buffer, bufsize, &keysym, &compose);
124    icon = buffer[0];
125    if ((icon >= 'a') && (icon <= 'z')) {
126       ChangeMapData(x,y,toupper(icon),1);
127    } else if  ((icon >= '0') && (icon <= '9')) {
128       ChangeMapData(x,y,icon,1);
129    }
130 }
131