Fixed compiler warnings
[AXE.git] / src / xappl.cpp
1 /**************************************************************************
2 **  (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : xappl.cpp
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      : Implementation of xapplication class 
11 **
12 **  EXPORTED OBJECTS : 
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 06, 1998
20 **      LAST UPDATE     : Feb 22, 1998
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: xappl.cpp,v $
26    Revision 1.1  2002-07-25 08:01:27  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 static const char *RCSID = "$Id: xappl.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
32
33 #include "xappl.h"
34
35 #include <stdio.h>
36
37 static char dim_bits[] =
38 {
39    '\x55', '\xAA', '\x55', '\xAA', '\x55', '\xAA', '\x55', '\xAA'
40 };
41
42 extern "C"
43 {
44 #include "nopicture.xpm"
45 }
46
47 xapplication *XApp;
48 display     stddpy;
49
50 color       menu_normal("light grey"), menu_highlight("slate grey");
51 color       inside_3D(0xB000, 0xC000, 0xD000),
52             light_rim_3D(0xEF00, 0xF000, 0xFFFF),
53             dark_rim_3D(0x7000, 0x8000, 0x9000);
54 color       Black("black"), White("white");
55 color       _Red("red"), _Green("green");
56
57 font        default_font("variable");
58 font        fixed("fixed");
59
60 cursor      hand_cursor(XC_hand1);
61 cursor      text_cursor(XC_xterm);
62 cursor      busy_cursor(XC_watch);
63
64 stipple     dim_pattern(dim_bits, 8, 8);
65
66 gc          menu_normal_gc(default_font, Black);
67 gc          menu_dimmed_gc(default_font, Black, dim_pattern);
68 gc          inside_3D_gc(inside_3D),
69             light_3D_gc(light_rim_3D), dark_3D_gc(dark_rim_3D);
70
71 gc          red_gc(default_font, _Red), green_gc(default_font, _Green);
72 gc          white_gc(White);
73
74 gc          text_normal_gc(fixed, Black);
75 gc          edit_cursor_gc(fixed, Black);
76
77 pixmap      nopicture(nopicture_xpm);
78
79 xapplication::xapplication()
80 {
81    XApp = this;
82    Pgrab_window = None;
83
84 }
85
86 void xapplication::add_window(XID w_id, window *w_ptr)
87 {
88    wintab.xh_add(w_id, w_ptr);
89 }
90
91 void xapplication::remove_window(XID w_id)
92 {
93    wintab.xh_del(w_id);
94 }
95
96 void xapplication::Pgrab(window *w_ptr)
97 {
98    Pgrab_window = w_ptr;
99 }
100
101 void xapplication::Topwin(managed_window *w_ptr)
102 {
103    Top_window = w_ptr;
104 }
105
106 /*=========================================================================
107 **  NAME           : 
108 **  SYNOPSIS       :
109 **  PARAMETERS     :
110 **  RETURN VALUE   :
111 **
112 **  DESCRIPTION    : 
113 **
114 **  VARS USED      :
115 **  VARS CHANGED   :
116 **  FUNCTIONS USED :
117 **  SEE ALSO       :
118 **  LAST MODIFIED  : 
119 **=========================================================================
120 */
121
122 void xapplication::Initialize(void)
123 {
124    XSetFont(stddpy, stddpy.gc(), default_font);
125    edit_cursor_gc.SetFunction(GXxor);
126    edit_cursor_gc.SetForeground(stddpy.Black() ^ stddpy.White());
127 }
128
129 /*=========================================================================
130 **  NAME           : 
131 **  SYNOPSIS       :
132 **  PARAMETERS     :
133 **  RETURN VALUE   :
134 **
135 **  DESCRIPTION    : 
136 **
137 **  VARS USED      :
138 **  VARS CHANGED   :
139 **  FUNCTIONS USED :
140 **  SEE ALSO       :
141 **  LAST MODIFIED  : 
142 **=========================================================================
143 */
144
145 void xapplication::ParseArguments(int argc, char *argv[])
146 {
147 }
148
149 void xapplication::SetupResources(void)
150 {
151 }
152
153 void xapplication::UserInit(void)
154 {
155 }
156
157 void xapplication::Cleanup(void)
158 {
159 }
160
161 int xapplication::DoCommand(int code)
162 {
163    return 1;
164 }
165
166 int  xapplication::DispatchEvent(XEvent ev)
167 {
168    window   *target_win;
169    int      go_on;
170
171    target_win = wintab[ev.xany.window];
172
173    switch (ev.type)
174    {
175    case Expose:
176       go_on = target_win->EV_Expose(ev.xexpose);
177       break;
178
179    case NoExpose:
180       go_on = target_win->EV_NoExpose(ev.xnoexpose);
181       break;
182
183    case KeyPress:
184       go_on = target_win->EV_KeyPress(ev.xkey);
185       break;
186
187    case ButtonPress:
188       if (Pgrab_window == None || target_win->SelectInput() & GrabPointerMask)
189          go_on = target_win->EV_ButtonPress(ev.xbutton);
190       else
191          go_on = Pgrab_window->EV_ButtonPress(ev.xbutton);
192       break;
193
194    case ButtonRelease:
195       if (Pgrab_window == None || target_win->SelectInput() & GrabPointerMask)
196          go_on = target_win->EV_ButtonRelease(ev.xbutton);
197       else
198          go_on = Pgrab_window->EV_ButtonRelease(ev.xbutton);
199       break;
200
201    case MotionNotify:
202       go_on = target_win->EV_MotionNotify(ev.xmotion);
203       break;
204
205    case EnterNotify:
206       go_on = target_win->EV_EnterNotify(ev.xcrossing);
207       break;
208
209    case LeaveNotify:
210       go_on = target_win->EV_LeaveNotify(ev.xcrossing);
211       break;
212
213    case FocusOut:
214       go_on = target_win->EV_FocusOut(ev.xfocus);
215       break;
216
217    case FocusIn:
218       go_on = target_win->EV_FocusIn(ev.xfocus);
219       break;
220
221    case ConfigureNotify:
222       go_on = target_win->EV_ConfigureNotify(ev.xconfigure);
223       break;
224
225    case ClientMessage:
226       go_on = target_win->EV_ClientMessage(ev.xclient);
227       break;
228
229    default:
230       go_on = target_win->EV_Default(ev);
231       break;
232    }
233
234    return go_on;
235 }
236
237
238 int xapplication::SendCommand(int code)
239 {
240    int  result;
241
242    result = Top_window->DoCommand(code);
243    if (result < 0)
244    {
245       result = DoCommand(code);
246    }
247
248    return result;
249 }
250
251 /*=========================================================================
252 **  NAME           : 
253 **  SYNOPSIS       :
254 **  PARAMETERS     :
255 **  RETURN VALUE   :
256 **
257 **  DESCRIPTION    : 
258 **
259 **  VARS USED      :
260 **  VARS CHANGED   :
261 **  FUNCTIONS USED :
262 **  SEE ALSO       :
263 **  LAST MODIFIED  : 
264 **=========================================================================
265 */
266
267 int main(int argc, char *argv[])
268 {
269    XEvent ev;
270
271    XApp->Initialize();
272    XApp->ParseArguments(argc, argv);
273    XApp->SetupResources();
274    XApp->UserInit();
275
276    do
277    {
278       stddpy >> ev;
279    }
280    while (XApp->DispatchEvent(ev));
281 };
282
283