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.2 $
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.2 2007-05-04 14:01:22 arjen
27 Added new arguments to configuration::find_parameter() to allow for a list of
28 sections and a list of parameters in sections.
29 The new arguments are section index and parameter index (default = 0).
31 Revision 1.1 2002/07/25 08:01:27 arjen
32 First checkin, AXE release 0.2
34 *****************************/
36 /* static const char *RCSID = "$Id: xappl.h,v 1.2 2007-05-04 14:01:22 arjen Exp $"; */
47 ///////////////////////////////////////////////////////////////////////////
50 // MEMBERS : id : X id of the window
51 // win : Pointer to the window object
52 // next : Pointer to next xw_list
54 // METHODS : xw_list(XID, window *, xw_list *)
55 // Insert at the start of the list.
57 // DESCRIPTION : Linked list of X-Window ID and window pointers.
58 // Is used in the hash table of windows.
62 // LAST MODIFIED : Feb 07, 1998
63 ///////////////////////////////////////////////////////////////////////////
73 xw_list(XID win_id, window *win_ptr, xw_list *list)
83 ///////////////////////////////////////////////////////////////////////////
86 // MEMBERS : tabsize : Size of the hash table.
87 // table : Array of xw_list entries.
88 // OPERATORS : window * [XID]
89 // METHODS : xw_hash(unsigned size)
90 // Create a hash table of specific size.
91 // xh_add(XID, window *)
92 // Add a new entry to the hash table.
94 // Delete an entry from the hash table.
96 // DESCRIPTION : The hash table associates a window's XID with a pointer
97 // to the window object. The xapplication object uses the
98 // hash table for dispatching events to windows.
100 // Each entry in the hash table, a xw_list pointer, is
101 // a linked list of these ID-pointer associations. The hash
102 // function is a simple modulo.
104 // RELATIONS : xw_list
105 // SEE ALSO : xapplication
106 // LAST MODIFIED : Feb 08, 1998
107 ///////////////////////////////////////////////////////////////////////////
112 xw_list **table; // The actual hash table.
113 unsigned tabsize; // Nr. of entries in the hash table.
115 unsigned Hash(XID win)
117 return win % tabsize;
126 table = new xw_list * [tabsize];
127 for (unsigned i=0; i < tabsize; i++)
133 xw_hash(unsigned size)
137 table = new xw_list * [size];
138 for (unsigned i=0; i < tabsize; i++)
149 // Add a new entry in the hash table.
151 void xh_add(XID win_id, window *win_ptr)
153 unsigned h; // The hash value;
156 table[h] = new xw_list(win_id, win_ptr, table[h]);
159 // Delete an entry from the hash table.
161 void xh_del(XID win_id)
163 unsigned h; // The hash value;
164 xw_list *entry; // The one we want to remove.
165 xw_list *previous; // The one just before entry.
169 // find the window's entry in the list.
172 while (entry && entry->id != win_id)
180 // Re-link the list, thus excluding entry.
181 previous->next = entry->next;
185 // It was the first entry.
186 table[h] = entry->next;
191 window * operator[](XID win_id)
193 unsigned h; // The hash value;
197 for (entry = table[h]; entry && entry->id != win_id; entry = entry->next);
211 ///////////////////////////////////////////////////////////////////////////
212 // NAME : xapplication
214 // MEMBERS : wintab : The table of maintained windows.
216 // METHODS : Initialize
225 // DESCRIPTION : Each X Windows application MUST have one object of a
226 // class derived from xapplication.
227 // The xapplication class implements the main thread of
228 // control: initialization, event-loop and termination.
229 // It maintains a list of all windows that are created by
232 // RELATIONS : xw_hash
234 // LAST MODIFIED : Feb 23, 1998
235 ///////////////////////////////////////////////////////////////////////////
242 window *Pgrab_window;
244 managed_window *Top_window;
250 virtual ~xapplication() {}
252 void add_window(XID w_id, window *w_ptr);
254 void remove_window(XID w_id);
256 void Pgrab(window *w_ptr);
257 void Topwin(managed_window *w_ptr);
259 virtual void Initialize(void);
261 virtual void ParseArguments(int argc, char *argv[]);
263 virtual void SetupResources(void);
265 virtual void UserInit(void);
267 virtual int DoCommand(int code);
269 virtual void Cleanup(void);
271 int DispatchEvent(XEvent ev);
272 int SendCommand(int code);
276 extern xapplication *XApp;
278 extern color Black, White;
279 extern color menu_normal, menu_highlight;
280 extern color inside_3D, light_rim_3D, dark_rim_3D;
282 extern font default_font;
285 extern stipple dim_pattern;
287 extern cursor hand_cursor;
288 extern cursor text_cursor;
289 extern cursor busy_cursor;
291 extern gc menu_normal_gc;
292 extern gc menu_dimmed_gc;
293 extern gc inside_3D_gc, light_3D_gc, dark_3D_gc;
294 extern gc red_gc, green_gc;
296 extern gc text_normal_gc;
297 extern gc edit_cursor_gc;
299 extern pixmap nopicture;