1 /**************************************************************************
2 ** (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.1 $
10 ** DESCRIPTION : Definition of xapplication class
12 ** EXPORTED OBJECTS : class xapplication
13 ** LOCAL OBJECTS : class xw_list, class xw_hash
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Feb 06, 1998
20 ** LAST UPDATE : Feb 23, 1998
22 **************************************************************************/
24 /*****************************
26 Revision 1.1 2002-07-25 08:01:27 arjen
27 First checkin, AXE release 0.2
29 *****************************/
31 /* static const char *RCSID = "$Id: xappl.h,v 1.1 2002-07-25 08:01:27 arjen Exp $"; */
42 ///////////////////////////////////////////////////////////////////////////
45 // MEMBERS : id : X id of the window
46 // win : Pointer to the window object
47 // next : Pointer to next xw_list
49 // METHODS : xw_list(XID, window *, xw_list *)
50 // Insert at the start of the list.
52 // DESCRIPTION : Linked list of X-Window ID and window pointers.
53 // Is used in the hash table of windows.
57 // LAST MODIFIED : Feb 07, 1998
58 ///////////////////////////////////////////////////////////////////////////
68 xw_list(XID win_id, window *win_ptr, xw_list *list)
78 ///////////////////////////////////////////////////////////////////////////
81 // MEMBERS : tabsize : Size of the hash table.
82 // table : Array of xw_list entries.
83 // OPERATORS : window * [XID]
84 // METHODS : xw_hash(unsigned size)
85 // Create a hash table of specific size.
86 // xh_add(XID, window *)
87 // Add a new entry to the hash table.
89 // Delete an entry from the hash table.
91 // DESCRIPTION : The hash table associates a window's XID with a pointer
92 // to the window object. The xapplication object uses the
93 // hash table for dispatching events to windows.
95 // Each entry in the hash table, a xw_list pointer, is
96 // a linked list of these ID-pointer associations. The hash
97 // function is a simple modulo.
99 // RELATIONS : xw_list
100 // SEE ALSO : xapplication
101 // LAST MODIFIED : Feb 08, 1998
102 ///////////////////////////////////////////////////////////////////////////
107 xw_list **table; // The actual hash table.
108 unsigned tabsize; // Nr. of entries in the hash table.
110 unsigned Hash(XID win)
112 return win % tabsize;
121 table = new (xw_list *)[tabsize];
122 for (unsigned i=0; i < tabsize; i++)
128 xw_hash(unsigned size)
132 table = new (xw_list *)[size];
133 for (unsigned i=0; i < tabsize; i++)
144 // Add a new entry in the hash table.
146 void xh_add(XID win_id, window *win_ptr)
148 unsigned h; // The hash value;
151 table[h] = new xw_list(win_id, win_ptr, table[h]);
154 // Delete an entry from the hash table.
156 void xh_del(XID win_id)
158 unsigned h; // The hash value;
159 xw_list *entry; // The one we want to remove.
160 xw_list *previous; // The one just before entry.
164 // find the window's entry in the list.
167 while (entry && entry->id != win_id)
175 // Re-link the list, thus excluding entry.
176 previous->next = entry->next;
180 // It was the first entry.
181 table[h] = entry->next;
186 window * operator[](XID win_id)
188 unsigned h; // The hash value;
192 for (entry = table[h]; entry && entry->id != win_id; entry = entry->next);
206 ///////////////////////////////////////////////////////////////////////////
207 // NAME : xapplication
209 // MEMBERS : wintab : The table of maintained windows.
211 // METHODS : Initialize
220 // DESCRIPTION : Each X Windows application MUST have one object of a
221 // class derived from xapplication.
222 // The xapplication class implements the main thread of
223 // control: initialization, event-loop and termination.
224 // It maintains a list of all windows that are created by
227 // RELATIONS : xw_hash
229 // LAST MODIFIED : Feb 23, 1998
230 ///////////////////////////////////////////////////////////////////////////
237 window *Pgrab_window;
239 managed_window *Top_window;
245 virtual ~xapplication() {}
247 void add_window(XID w_id, window *w_ptr);
249 void remove_window(XID w_id);
251 void Pgrab(window *w_ptr);
252 void Topwin(managed_window *w_ptr);
254 virtual void Initialize(void);
256 virtual void ParseArguments(int argc, char *argv[]);
258 virtual void SetupResources(void);
260 virtual void UserInit(void);
262 virtual int DoCommand(int code);
264 virtual void Cleanup(void);
266 int DispatchEvent(XEvent ev);
267 int SendCommand(int code);
271 extern xapplication *XApp;
273 extern color Black, White;
274 extern color menu_normal, menu_highlight;
275 extern color inside_3D, light_rim_3D, dark_rim_3D;
277 extern font default_font;
280 extern stipple dim_pattern;
282 extern cursor hand_cursor;
283 extern cursor text_cursor;
284 extern cursor busy_cursor;
286 extern gc menu_normal_gc;
287 extern gc menu_dimmed_gc;
288 extern gc inside_3D_gc, light_3D_gc, dark_3D_gc;
289 extern gc red_gc, green_gc;
291 extern gc text_normal_gc;
292 extern gc edit_cursor_gc;
294 extern pixmap nopicture;