1 /***********************************************************
2 
3 Copyright 1987, 1988, 1994, 1998  The Open Group
4 
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24 
25 
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
27 
28                         All Rights Reserved
29 
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
37 
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
45 
46 ******************************************************************/
47 
48 #ifndef _XtinitialI_h
49 #define _XtinitialI_h
50 
51 /****************************************************************
52  *
53  * Displays
54  *
55  ****************************************************************/
56 
57 #ifndef X_NOT_POSIX
58 #ifdef _POSIX_SOURCE
59 #include <limits.h>
60 #else
61 #define _POSIX_SOURCE
62 #include <limits.h>
63 #undef _POSIX_SOURCE
64 #endif
65 #endif
66 #ifndef PATH_MAX
67 #ifdef WIN32
68 #define PATH_MAX 512
69 #else
70 #include <sys/param.h>
71 #endif
72 #ifndef PATH_MAX
73 #ifdef MAXPATHLEN
74 #define PATH_MAX MAXPATHLEN
75 #else
76 #define PATH_MAX 1024
77 #endif
78 #endif
79 #endif
80 
81 #include <X11/Xos.h>
82 #include <X11/Xpoll.h>
83 
84 _XFUNCPROTOBEGIN
85 
86 typedef struct _TimerEventRec {
87         struct timeval        te_timer_value;
88 	struct _TimerEventRec *te_next;
89 	XtTimerCallbackProc   te_proc;
90 	XtAppContext	      app;
91 	XtPointer	      te_closure;
92 } TimerEventRec;
93 
94 typedef struct _InputEvent {
95 	XtInputCallbackProc   ie_proc;
96 	XtPointer	      ie_closure;
97 	struct _InputEvent    *ie_next;
98 	struct _InputEvent    *ie_oq;
99 	XtAppContext	      app;
100 	int		      ie_source;
101 	XtInputMask	      ie_condition;
102 } InputEvent;
103 
104 typedef struct _SignalEventRec {
105 	XtSignalCallbackProc  se_proc;
106 	XtPointer	      se_closure;
107 	struct _SignalEventRec *se_next;
108 	XtAppContext	      app;
109 	Boolean		      se_notice;
110 } SignalEventRec;
111 
112 typedef struct _WorkProcRec {
113 	XtWorkProc proc;
114 	XtPointer closure;
115 	struct _WorkProcRec *next;
116 	XtAppContext app;
117 } WorkProcRec;
118 
119 
120 typedef struct
121 {
122 #ifndef USE_POLL
123   	fd_set rmask;
124 	fd_set wmask;
125 	fd_set emask;
126 #endif
127 	int	nfds;
128 } FdStruct;
129 
130 typedef struct _LangProcRec {
131     XtLanguageProc	proc;
132     XtPointer		closure;
133 } LangProcRec;
134 
135 typedef struct _ProcessContextRec {
136     XtAppContext	defaultAppContext;
137     XtAppContext	appContextList;
138     ConverterTable	globalConverterTable;
139     LangProcRec		globalLangProcRec;
140 } ProcessContextRec, *ProcessContext;
141 
142 typedef struct {
143     char*	start;
144     char*	current;
145     int		bytes_remaining;
146 } Heap;
147 
148 typedef struct _DestroyRec DestroyRec;
149 
150 
151 typedef struct _XtAppStruct {
152     XtAppContext next;		/* link to next app in process context */
153     ProcessContext process;	/* back pointer to our process context */
154     InternalCallbackList destroy_callbacks;
155     Display **list;
156     TimerEventRec *timerQueue;
157     WorkProcRec *workQueue;
158     InputEvent **input_list;
159     InputEvent *outstandingQueue;
160     SignalEventRec *signalQueue;
161     XrmDatabase errorDB;
162     XtErrorMsgHandler errorMsgHandler, warningMsgHandler;
163     XtErrorHandler errorHandler, warningHandler;
164     struct _ActionListRec *action_table;
165     ConverterTable converterTable;
166     unsigned long selectionTimeout;
167     FdStruct fds;
168     short count;			/* num of assigned entries in list */
169     short max;				/* allocate size of list */
170     short last;
171     short input_count;
172     short input_max;			/* elts input_list init'd with */
173     Boolean sync, being_destroyed, error_inited;
174 #ifndef NO_IDENTIFY_WINDOWS
175     Boolean identify_windows;		/* debugging hack */
176 #endif
177     Heap heap;
178     String * fallback_resources;	/* Set by XtAppSetFallbackResources. */
179     struct _ActionHookRec* action_hook_list;
180     struct _BlockHookRec* block_hook_list;
181     int destroy_list_size;		/* state data for 2-phase destroy */
182     int destroy_count;
183     int dispatch_level;
184     DestroyRec* destroy_list;
185     Widget in_phase2_destroy;
186     LangProcRec langProcRec;
187     struct _TMBindCacheRec * free_bindings;
188     _XtString display_name_tried;
189     Display **dpy_destroy_list;
190     int dpy_destroy_count;
191     Boolean exit_flag;
192     Boolean rebuild_fdlist;
193 #ifdef XTHREADS
194     LockPtr lock_info;
195     ThreadAppProc lock;
196     ThreadAppProc unlock;
197     ThreadAppYieldLockProc yield_lock;
198     ThreadAppRestoreLockProc restore_lock;
199     ThreadAppProc free_lock;
200 #endif
201 } XtAppStruct;
202 
203 extern void _XtHeapInit(Heap* heap);
204 extern void _XtHeapFree(Heap* heap);
205 
206 #ifdef XTTRACEMEMORY
207 
208 
209 extern char *_XtHeapMalloc(
210     Heap*	/* heap */,
211     Cardinal	/* size */,
212     const char */* file */,
213     int		/* line */
214 );
215 
216 #define _XtHeapAlloc(heap,bytes) _XtHeapMalloc(heap, bytes, __FILE__, __LINE__)
217 
218 #else /* XTTRACEMEMORY */
219 
220 extern char* _XtHeapAlloc(
221     Heap*	/* heap */,
222     Cardinal	/* size */
223 );
224 
225 #endif /* XTTRACEMEMORY */
226 
227 extern void _XtSetDefaultErrorHandlers(
228     XtErrorMsgHandler*	/* errMsg */,
229     XtErrorMsgHandler*	/* warnMsg */,
230     XtErrorHandler*	/* err */,
231     XtErrorHandler*	/* warn */
232 );
233 
234 extern void _XtSetDefaultSelectionTimeout(
235     unsigned long* /* timeout */
236 );
237 
238 extern XtAppContext _XtDefaultAppContext(
239     void
240 );
241 
242 extern ProcessContext _XtGetProcessContext(
243     void
244 );
245 
246 Display *
247 _XtAppInit(
248     XtAppContext*	/* app_context_return */,
249     String		/* application_class */,
250     XrmOptionDescRec*	/* options */,
251     Cardinal		/* num_options */,
252     int*		/* argc_in_out */,
253     _XtString**		/* argv_in_out */,
254     String*		/* fallback_resources */
255 );
256 
257 extern void _XtDestroyAppContexts(
258     void
259 );
260 
261 extern void _XtCloseDisplays(
262     XtAppContext	/* app */
263 );
264 
265 extern int _XtAppDestroyCount;
266 
267 extern int _XtWaitForSomething(
268     XtAppContext	/* app */,
269     _XtBoolean 		/* ignoreEvents */,
270     _XtBoolean 		/* ignoreTimers */,
271     _XtBoolean 		/* ignoreInputs */,
272     _XtBoolean		/* ignoreSignals */,
273     _XtBoolean 		/* block */,
274 #ifdef XTHREADS
275     _XtBoolean		/* drop_lock */,
276 #endif
277     unsigned long*	/* howlong */
278 );
279 
280 typedef struct _CaseConverterRec *CaseConverterPtr;
281 typedef struct _CaseConverterRec {
282     KeySym		start;		/* first KeySym valid in converter */
283     KeySym		stop;		/* last KeySym valid in converter */
284     XtCaseProc		proc;		/* case converter function */
285     CaseConverterPtr	next;		/* next converter record */
286 } CaseConverterRec;
287 
288 typedef struct _ExtensionSelectorRec {
289     XtExtensionSelectProc proc;
290     int min, max;
291     XtPointer client_data;
292 } ExtSelectRec;
293 
294 typedef struct _XtPerDisplayStruct {
295     InternalCallbackList destroy_callbacks;
296     Region region;
297     CaseConverterPtr case_cvt;		/* user-registered case converters */
298     XtKeyProc defaultKeycodeTranslator;
299     XtAppContext appContext;
300     unsigned long keysyms_serial;      /* for tracking MappingNotify events */
301     KeySym *keysyms;                   /* keycode to keysym table */
302     int keysyms_per_keycode;           /* number of keysyms for each keycode*/
303     int min_keycode, max_keycode;      /* range of keycodes */
304     KeySym *modKeysyms;                /* keysym values for modToKeysysm */
305     ModToKeysymTable *modsToKeysyms;   /* modifiers to Keysysms index table*/
306     unsigned char isModifier[32];      /* key-is-modifier-p bit table */
307     KeySym lock_meaning;	       /* Lock modifier meaning */
308     Modifiers mode_switch;	       /* keyboard group modifiers */
309     Modifiers num_lock;		       /* keyboard numlock modifiers */
310     Boolean being_destroyed;
311     Boolean rv;			       /* reverse_video resource */
312     XrmName name;		       /* resolved app name */
313     XrmClass class;		       /* application class */
314     Heap heap;
315     struct _GCrec *GClist;	       /* support for XtGetGC */
316     Drawable **pixmap_tab;             /* ditto for XtGetGC */
317     String language;		       /* XPG language string */
318     XEvent last_event;		       /* last event dispatched */
319     Time last_timestamp;	       /* from last event dispatched */
320     int multi_click_time;	       /* for XtSetMultiClickTime */
321     struct _TMKeyContextRec* tm_context;     /* for XtGetActionKeysym */
322     InternalCallbackList mapping_callbacks;  /* special case for TM */
323     XtPerDisplayInputRec pdi;	       /* state for modal grabs & kbd focus */
324     struct _WWTable *WWtable;	       /* window to widget table */
325     XrmDatabase *per_screen_db;        /* per screen resource databases */
326     XrmDatabase cmd_db;		       /* db from command line, if needed */
327     XrmDatabase server_db;	       /* resource property else .Xdefaults */
328     XtEventDispatchProc* dispatcher_list;
329     ExtSelectRec* ext_select_list;
330     int ext_select_count;
331     Widget hook_object;
332 #ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
333     Atom rcm_init;			/* ResConfig - initialize */
334     Atom rcm_data;			/* ResConfig - data atom */
335 #endif
336 } XtPerDisplayStruct, *XtPerDisplay;
337 
338 typedef struct _PerDisplayTable {
339 	Display *dpy;
340 	XtPerDisplayStruct perDpy;
341 	struct _PerDisplayTable *next;
342 } PerDisplayTable, *PerDisplayTablePtr;
343 
344 extern PerDisplayTablePtr _XtperDisplayList;
345 
346 extern XtPerDisplay _XtSortPerDisplayList(
347     Display* /* dpy */
348 );
349 
350 extern XtPerDisplay _XtGetPerDisplay(
351     Display*		/* dpy */
352 );
353 
354 extern XtPerDisplayInputRec* _XtGetPerDisplayInput(
355     Display* 		/* dpy */
356 );
357 
358 #if 0
359 #ifdef DEBUG
360 #define _XtGetPerDisplay(display) \
361     ((_XtperDisplayList != NULL && (_XtperDisplayList->dpy == (display))) \
362      ? &_XtperDisplayList->perDpy \
363      : _XtSortPerDisplayList(display))
364 #define _XtGetPerDisplayInput(display) \
365     ((_XtperDisplayList != NULL && (_XtperDisplayList->dpy == (display))) \
366      ? &_XtperDisplayList->perDpy.pdi \
367      : &_XtSortPerDisplayList(display)->pdi)
368 #else
369 #define _XtGetPerDisplay(display) \
370     ((_XtperDisplayList->dpy == (display)) \
371      ? &_XtperDisplayList->perDpy \
372      : _XtSortPerDisplayList(display))
373 #define _XtGetPerDisplayInput(display) \
374     ((_XtperDisplayList->dpy == (display)) \
375      ? &_XtperDisplayList->perDpy.pdi \
376      : &_XtSortPerDisplayList(display)->pdi)
377 #endif /*DEBUG*/
378 #endif
379 
380 extern void _XtDisplayInitialize(
381     Display*		/* dpy */,
382     XtPerDisplay	/* pd */,
383     _Xconst char*	/* name */,
384     XrmOptionDescRec*	/* urlist */,
385     Cardinal 		/* num_urs */,
386     int*		/* argc */,
387     _XtString* 		/* argv */
388 );
389 
390 extern void _XtCacheFlushTag(
391     XtAppContext /* app */,
392     XtPointer	 /* tag */
393 );
394 
395 extern void _XtFreeActions(
396     struct _ActionListRec* /* action_table */
397 );
398 
399 extern void _XtDoPhase2Destroy(
400     XtAppContext /* app */,
401     int		 /* dispatch_level */
402 );
403 
404 extern void _XtDoFreeBindings(
405     XtAppContext /* app */
406 );
407 
408 extern void _XtExtensionSelect(
409     Widget /* widget */
410 );
411 
412 #define _XtSafeToDestroy(app) ((app)->dispatch_level == 0)
413 
414 extern void _XtAllocWWTable(
415     XtPerDisplay pd
416 );
417 
418 extern void _XtFreeWWTable(
419     XtPerDisplay pd
420 );
421 
422 extern String _XtGetUserName(_XtString dest, int len);
423 extern XrmDatabase _XtPreparseCommandLine(XrmOptionDescRec *urlist,
424 			Cardinal num_urs, int argc, _XtString *argv,
425 			String *applName, String *displayName,
426 			String *language);
427 
428 _XFUNCPROTOEND
429 
430 #endif /* _XtinitialI_h */
431