Added new arguments to configuration::find_parameter() to allow for a list of
[AXE.git] / src / xappl.h
1 /**************************************************************************
2 **  (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : xappl.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.2 $
9 **
10 **  DESCRIPTION      : Definition of xapplication class 
11 **
12 **  EXPORTED OBJECTS : class xapplication
13 **  LOCAL    OBJECTS : class xw_list, class xw_hash
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 23, 1998
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: xappl.h,v $
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).
30
31    Revision 1.1  2002/07/25 08:01:27  arjen
32    First checkin, AXE release 0.2
33
34 *****************************/
35
36 /* static const char *RCSID = "$Id: xappl.h,v 1.2 2007-05-04 14:01:22 arjen Exp $"; */
37
38 #ifndef XAPPL_H
39 #define XAPPL_H
40
41 #include <X11/Xlib.h>
42 #include "display.h"
43 #include "xwindow.h"
44 #include "cursor.h"
45
46 /*
47 ///////////////////////////////////////////////////////////////////////////
48 //  NAME           : xw_list
49 //  BASECLASS      :
50 //  MEMBERS        : id   : X id of the window
51 //                   win  : Pointer to the window object
52 //                   next : Pointer to next xw_list
53 //  OPERATORS      :
54 //  METHODS        : xw_list(XID, window *, xw_list *)
55 //                      Insert at the start of the list.
56 //
57 //  DESCRIPTION    : Linked list of X-Window ID and window pointers.
58 //                   Is used in the hash table of windows.
59 //
60 //  RELATIONS      :
61 //  SEE ALSO       : xw_hash
62 //  LAST MODIFIED  : Feb 07, 1998
63 ///////////////////////////////////////////////////////////////////////////
64 */
65
66 class xw_list
67 {
68 public:
69    XID      id;
70    window   *win;
71    xw_list  *next;
72
73    xw_list(XID win_id, window *win_ptr, xw_list *list)
74    {
75       id   = win_id;
76       win  = win_ptr;
77       next = list;
78    }
79 };
80
81
82 /*
83 ///////////////////////////////////////////////////////////////////////////
84 //  NAME           : xw_hash
85 //  BASECLASS      :
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.
93 //                   xh_del(XID)
94 //                      Delete an entry from the hash table.
95 //
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.
99 //
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.
103 //
104 //  RELATIONS      : xw_list
105 //  SEE ALSO       : xapplication
106 //  LAST MODIFIED  : Feb 08, 1998
107 ///////////////////////////////////////////////////////////////////////////
108 */
109
110 class xw_hash
111 {
112    xw_list    **table;   //  The actual hash table.
113    unsigned   tabsize;   //  Nr. of entries in the hash table.
114
115    unsigned   Hash(XID win)
116    {
117       return win % tabsize;
118    }
119
120 public:
121
122    xw_hash()
123    {
124       tabsize = 100;
125
126       table = new xw_list * [tabsize];
127       for (unsigned i=0; i < tabsize; i++)
128       {
129          table[i] = 0;
130       }
131    }
132
133    xw_hash(unsigned size)
134    {
135       tabsize = size;
136
137       table = new xw_list * [size];
138       for (unsigned i=0; i < tabsize; i++)
139       {
140          table[i] = 0;
141       }
142    }
143
144    ~xw_hash()
145    {
146       delete[] table;
147    }
148
149    //   Add a new entry in the hash table.
150
151    void xh_add(XID win_id, window *win_ptr)
152    {
153       unsigned   h;   // The hash value;
154
155       h = Hash(win_id);
156       table[h] = new xw_list(win_id, win_ptr, table[h]);
157    }
158
159    //  Delete an entry from the hash table.
160
161    void xh_del(XID win_id)
162    {
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.
166
167       h = Hash(win_id);
168
169       //   find the window's entry in the list.
170       previous = 0;
171       entry = table[h];
172       while (entry && entry->id != win_id)
173       {
174          previous = entry;
175          entry = entry->next;
176       }
177
178       if (previous)
179       {
180          //   Re-link the list, thus excluding entry.
181          previous->next = entry->next;
182       }
183       else
184       {
185          //  It was the first entry.
186          table[h] = entry->next;
187       }
188       delete entry;
189    }
190
191    window * operator[](XID win_id)
192    {
193       unsigned   h;   // The hash value;
194       xw_list    *entry;
195
196       h = Hash(win_id);
197       for (entry = table[h]; entry && entry->id != win_id; entry = entry->next);
198       if (entry)
199       {
200          return entry->win;
201       }
202       else
203       {
204          return 0;
205       }
206    }
207 };
208
209
210 /*
211 ///////////////////////////////////////////////////////////////////////////
212 //  NAME           : xapplication
213 //  BASECLASS      :
214 //  MEMBERS        : wintab   : The table of maintained windows.
215 //  OPERATORS      :
216 //  METHODS        : Initialize
217 //                   ParseArguments
218 //                   SetupResources
219 //                   UserInit
220 //                   DispatchEvent
221 //                   Cleanup
222 //                   add_window
223 //                   remove_window
224 //
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
230 //                   the application.
231 //
232 //  RELATIONS      : xw_hash
233 //  SEE ALSO       :
234 //  LAST MODIFIED  : Feb 23, 1998
235 ///////////////////////////////////////////////////////////////////////////
236 */
237
238 class xapplication
239 {
240    xw_hash   wintab;
241
242    window    *Pgrab_window;
243
244    managed_window    *Top_window;
245
246 public:
247
248    xapplication();
249
250    virtual ~xapplication() {}
251
252    void add_window(XID w_id, window *w_ptr);
253
254    void remove_window(XID w_id);
255
256    void Pgrab(window *w_ptr);
257    void Topwin(managed_window *w_ptr);
258
259    virtual void Initialize(void);
260
261    virtual void ParseArguments(int argc, char *argv[]);
262
263    virtual void SetupResources(void);
264
265    virtual void UserInit(void);
266
267    virtual int DoCommand(int code);
268
269    virtual void Cleanup(void);
270
271    int  DispatchEvent(XEvent ev);
272    int  SendCommand(int code);
273
274 };
275
276 extern xapplication *XApp;
277
278 extern color Black, White;
279 extern color menu_normal, menu_highlight;
280 extern color inside_3D, light_rim_3D, dark_rim_3D;
281
282 extern font  default_font;
283 extern font  fixed;
284
285 extern stipple dim_pattern;
286
287 extern cursor  hand_cursor;
288 extern cursor  text_cursor;
289 extern cursor  busy_cursor;
290
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;
295 extern gc    white_gc;
296 extern gc    text_normal_gc;
297 extern gc    edit_cursor_gc;
298
299 extern pixmap nopicture;
300
301 #endif  /*  XAPPL_H */