684bbbaf82b2098b147b8392cb10c1891cd10499
[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    0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA
40 };
41
42 #include "nopicture.xpm"
43
44 xapplication *XApp;
45 display     stddpy;
46
47 color       menu_normal("light grey"), menu_highlight("slate grey");
48 color       inside_3D(0xB000, 0xC000, 0xD000),
49             light_rim_3D(0xEF00, 0xF000, 0xFFFF),
50             dark_rim_3D(0x7000, 0x8000, 0x9000);
51 color       Black("black"), White("white");
52 color       _Red("red"), _Green("green");
53
54 font        default_font("variable");
55 font        fixed("fixed");
56
57 cursor      hand_cursor(XC_hand1);
58 cursor      text_cursor(XC_xterm);
59 cursor      busy_cursor(XC_watch);
60
61 stipple     dim_pattern(dim_bits, 8, 8);
62
63 gc          menu_normal_gc(default_font, Black);
64 gc          menu_dimmed_gc(default_font, Black, dim_pattern);
65 gc          inside_3D_gc(inside_3D),
66             light_3D_gc(light_rim_3D), dark_3D_gc(dark_rim_3D);
67
68 gc          red_gc(default_font, _Red), green_gc(default_font, _Green);
69 gc          white_gc(White);
70
71 gc          text_normal_gc(fixed, Black);
72 gc          edit_cursor_gc(fixed, Black);
73
74 pixmap      nopicture(nopicture_xpm);
75
76 xapplication::xapplication()
77 {
78    XApp = this;
79    Pgrab_window = None;
80
81 }
82
83 void xapplication::add_window(XID w_id, window *w_ptr)
84 {
85    wintab.xh_add(w_id, w_ptr);
86 }
87
88 void xapplication::remove_window(XID w_id)
89 {
90    wintab.xh_del(w_id);
91 }
92
93 void xapplication::Pgrab(window *w_ptr)
94 {
95    Pgrab_window = w_ptr;
96 }
97
98 void xapplication::Topwin(managed_window *w_ptr)
99 {
100    Top_window = w_ptr;
101 }
102
103 /*=========================================================================
104 **  NAME           : 
105 **  SYNOPSIS       :
106 **  PARAMETERS     :
107 **  RETURN VALUE   :
108 **
109 **  DESCRIPTION    : 
110 **
111 **  VARS USED      :
112 **  VARS CHANGED   :
113 **  FUNCTIONS USED :
114 **  SEE ALSO       :
115 **  LAST MODIFIED  : 
116 **=========================================================================
117 */
118
119 void xapplication::Initialize(void)
120 {
121    XSetFont(stddpy, stddpy.gc(), default_font);
122    edit_cursor_gc.SetFunction(GXxor);
123    edit_cursor_gc.SetForeground(stddpy.Black() ^ stddpy.White());
124 }
125
126 /*=========================================================================
127 **  NAME           : 
128 **  SYNOPSIS       :
129 **  PARAMETERS     :
130 **  RETURN VALUE   :
131 **
132 **  DESCRIPTION    : 
133 **
134 **  VARS USED      :
135 **  VARS CHANGED   :
136 **  FUNCTIONS USED :
137 **  SEE ALSO       :
138 **  LAST MODIFIED  : 
139 **=========================================================================
140 */
141
142 void xapplication::ParseArguments(int argc, char *argv[])
143 {
144 }
145
146 void xapplication::SetupResources(void)
147 {
148 }
149
150 void xapplication::UserInit(void)
151 {
152 }
153
154 void xapplication::Cleanup(void)
155 {
156 }
157
158 int xapplication::DoCommand(int code)
159 {
160    return 1;
161 }
162
163 int  xapplication::DispatchEvent(XEvent ev)
164 {
165    window   *target_win;
166    int      go_on;
167
168    target_win = wintab[ev.xany.window];
169
170    switch (ev.type)
171    {
172    case Expose:
173       go_on = target_win->EV_Expose(ev.xexpose);
174       break;
175
176    case NoExpose:
177       go_on = target_win->EV_NoExpose(ev.xnoexpose);
178       break;
179
180    case KeyPress:
181       go_on = target_win->EV_KeyPress(ev.xkey);
182       break;
183
184    case ButtonPress:
185       if (Pgrab_window == None || target_win->SelectInput() & GrabPointerMask)
186          go_on = target_win->EV_ButtonPress(ev.xbutton);
187       else
188          go_on = Pgrab_window->EV_ButtonPress(ev.xbutton);
189       break;
190
191    case ButtonRelease:
192       if (Pgrab_window == None || target_win->SelectInput() & GrabPointerMask)
193          go_on = target_win->EV_ButtonRelease(ev.xbutton);
194       else
195          go_on = Pgrab_window->EV_ButtonRelease(ev.xbutton);
196       break;
197
198    case MotionNotify:
199       go_on = target_win->EV_MotionNotify(ev.xmotion);
200       break;
201
202    case EnterNotify:
203       go_on = target_win->EV_EnterNotify(ev.xcrossing);
204       break;
205
206    case LeaveNotify:
207       go_on = target_win->EV_LeaveNotify(ev.xcrossing);
208       break;
209
210    case FocusOut:
211       go_on = target_win->EV_FocusOut(ev.xfocus);
212       break;
213
214    case FocusIn:
215       go_on = target_win->EV_FocusIn(ev.xfocus);
216       break;
217
218    case ConfigureNotify:
219       go_on = target_win->EV_ConfigureNotify(ev.xconfigure);
220       break;
221
222    case ClientMessage:
223       go_on = target_win->EV_ClientMessage(ev.xclient);
224       break;
225
226    default:
227       go_on = target_win->EV_Default(ev);
228       break;
229    }
230
231    return go_on;
232 }
233
234
235 int xapplication::SendCommand(int code)
236 {
237    int  result;
238
239    result = Top_window->DoCommand(code);
240    if (result < 0)
241    {
242       result = DoCommand(code);
243    }
244
245    return result;
246 }
247
248 /*=========================================================================
249 **  NAME           : 
250 **  SYNOPSIS       :
251 **  PARAMETERS     :
252 **  RETURN VALUE   :
253 **
254 **  DESCRIPTION    : 
255 **
256 **  VARS USED      :
257 **  VARS CHANGED   :
258 **  FUNCTIONS USED :
259 **  SEE ALSO       :
260 **  LAST MODIFIED  : 
261 **=========================================================================
262 */
263
264 int main(int argc, char *argv[])
265 {
266    XEvent ev;
267
268    XApp->Initialize();
269    XApp->ParseArguments(argc, argv);
270    XApp->SetupResources();
271    XApp->UserInit();
272
273    do
274    {
275       stddpy >> ev;
276    }
277    while (XApp->DispatchEvent(ev));
278 };
279
280