1b3307321Smrg/** ------------------------------------------------------------------------
2b3307321Smrg	This file contains routines for manipulating generic lists.
3b3307321Smrg	Lists are implemented with a "harness".  In other words, each
4b3307321Smrg	node in the list consists of two pointers, one to the data item
5b3307321Smrg	and one to the next node in the list.  The head of the list is
6b3307321Smrg	the same struct as each node, but the "item" ptr is used to point
7b3307321Smrg	to the current member of the list (used by the first_in_list and
8b3307321Smrg	next_in_list functions).
9b3307321Smrg
10b3307321SmrgCopyright 1994 Hewlett-Packard Co.
11b3307321SmrgCopyright 1996, 1998  The Open Group
12b3307321Smrg
13b3307321SmrgPermission to use, copy, modify, distribute, and sell this software and its
14b3307321Smrgdocumentation for any purpose is hereby granted without fee, provided that
15b3307321Smrgthe above copyright notice appear in all copies and that both that
16b3307321Smrgcopyright notice and this permission notice appear in supporting
17b3307321Smrgdocumentation.
18b3307321Smrg
19b3307321SmrgThe above copyright notice and this permission notice shall be included
20b3307321Smrgin all copies or substantial portions of the Software.
21b3307321Smrg
22b3307321SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23b3307321SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24b3307321SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25b3307321SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
26b3307321SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27b3307321SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28b3307321SmrgOTHER DEALINGS IN THE SOFTWARE.
29b3307321Smrg
30b3307321SmrgExcept as contained in this notice, the name of The Open Group shall
31b3307321Smrgnot be used in advertising or otherwise to promote the sale, use or
32b3307321Smrgother dealings in this Software without prior written authorization
33b3307321Smrgfrom The Open Group.
34b3307321Smrg
35b3307321Smrg    ------------------------------------------------------------------------ **/
36b3307321Smrg
37b3307321Smrg/******************************************************************************
38b3307321Smrg *
39b3307321Smrg * This file contains various typedef's, macros and procedure declarations for
40b3307321Smrg * a set of example utility procedures contained in the file "wsutils.c".
41b3307321Smrg *
42b3307321Smrg ******************************************************************************/
43b3307321Smrg
4474a3f230Smrgtypedef unsigned long Pixel;
4574a3f230Smrg
46b3307321Smrg/* This is the actual structure returned by the X server describing the
47b3307321Smrg * SERVER_OVERLAY_VISUAL property.
48b3307321Smrg */
49b3307321Smrgtypedef struct
50b3307321Smrg{
51b3307321Smrg  VisualID	visualID;		/* The VisualID of the overlay visual */
52b3307321Smrg  int		transparentType;	/* Can be None, TransparentPixel or
53b3307321Smrg					 * TransparentMask */
54320e696bSmrg  Pixel		value;			/* Pixel value */
55b3307321Smrg  int		layer;			/* Overlay planes will always be in
56b3307321Smrg					 * layer 1 */
57b3307321Smrg} OverlayVisualPropertyRec;
58b3307321Smrg
59b3307321Smrg
60b3307321Smrg/* This is structure also describes the SERVER_OVERLAY_VISUAL property, but
61b3307321Smrg * should be more useful than the one actually returned by the X server
62b3307321Smrg * because it actually points to the visual's XVisualInfo struct rather than
636728f30eSmrg * referring to the visual's ID.
64b3307321Smrg */
65b3307321Smrgtypedef struct
66b3307321Smrg{
67b3307321Smrg  XVisualInfo	*pOverlayVisualInfo;	/* Pointer to the XVisualInfo struct */
68b3307321Smrg  int		transparentType;	/* Can be None, TransparentPixel or
69b3307321Smrg					 * TransparentMask */
70320e696bSmrg  Pixel		value;			/* Pixel value */
71b3307321Smrg  int		layer;			/* Overlay planes will always be in
72b3307321Smrg					 * layer 1 */
73b3307321Smrg} OverlayInfo;
74b3307321Smrg
75b3307321Smrg
76b3307321Smrg/* These macros are the values of the "transparentType" above: */
77b3307321Smrg#ifndef None
78b3307321Smrg#define None 0
79b3307321Smrg#endif
80b3307321Smrg#ifndef TransparentPixel
81b3307321Smrg#define TransparentPixel	1
82b3307321Smrg#endif
83b3307321Smrg
84b3307321Smrg
85b3307321Smrg/* These macros define how flexible a program is when it requests a window's
86b3307321Smrg * creation with either the CreateImagePlanesWindow() or
87b3307321Smrg * CreateOverlayPlanesWindow():
88b3307321Smrg */
89b3307321Smrg#ifndef NOT_FLEXIBLE
90b3307321Smrg#define NOT_FLEXIBLE		0
91b3307321Smrg#define FLEXIBLE		1
92b3307321Smrg#endif
93b3307321Smrg
94b3307321Smrg
95b3307321Smrg/* These macros define the values of the "sbCmapHint" parameter of the
96b3307321Smrg * CreateImagePlanesWindow():
97b3307321Smrg */
98b3307321Smrg#ifndef SB_CMAP_TYPE_NORMAL
99b3307321Smrg#define SB_CMAP_TYPE_NORMAL	1
100b3307321Smrg#endif
101b3307321Smrg
102b3307321Smrg#ifndef SB_CMAP_TYPE_MONOTONIC
103b3307321Smrg#define SB_CMAP_TYPE_MONOTONIC	2
104b3307321Smrg#endif
105b3307321Smrg
106b3307321Smrg#ifndef SB_CMAP_TYPE_FULL
107b3307321Smrg#define SB_CMAP_TYPE_FULL	4
108b3307321Smrg#endif
109b3307321Smrg
110b3307321Smrg
111b3307321Smrg/******************************************************************************
112b3307321Smrg *
113b3307321Smrg * GetXVisualInfo()
114b3307321Smrg *
115b3307321Smrg * This routine takes an X11 Display, screen number, and returns whether the
116b3307321Smrg * screen supports transparent overlays and three arrays:
117b3307321Smrg *
118b3307321Smrg *	1) All of the XVisualInfo struct's for the screen.
119b3307321Smrg *	2) All of the OverlayInfo struct's for the screen.
120b3307321Smrg *	3) An array of pointers to the screen's image plane XVisualInfo
121b3307321Smrg *	   structs.
122b3307321Smrg *
123b3307321Smrg * The code below obtains the array of all the screen's visuals, and obtains
124b3307321Smrg * the array of all the screen's overlay visual information.  It then processes
125b3307321Smrg * the array of the screen's visuals, determining whether the visual is an
126b3307321Smrg * overlay or image visual.
127b3307321Smrg *
1286728f30eSmrg * If the routine successfully obtained the visual information, it returns zero.
129b3307321Smrg * If the routine didn't obtain the visual information, it returns non-zero.
130b3307321Smrg *
131b3307321Smrg ******************************************************************************/
132b3307321Smrg
133b3307321Smrgextern int GetXVisualInfo(
134b3307321Smrg    Display	*display,		/* Which X server (aka "display"). */
135b3307321Smrg    int		screen,			/* Which screen of the "display". */
136b3307321Smrg    int		*transparentOverlays,	/* Non-zero if there's at least one
137b3307321Smrg					 * overlay visual and if at least one
138b3307321Smrg					 * of those supports a transparent
139b3307321Smrg					 * pixel. */
140b3307321Smrg    int		*numVisuals,		/* Number of XVisualInfo struct's
141b3307321Smrg					 * pointed to to by pVisuals. */
142b3307321Smrg    XVisualInfo	**pVisuals,		/* All of the device's visuals. */
143b3307321Smrg    int		*numOverlayVisuals,	/* Number of OverlayInfo's pointed
144b3307321Smrg					 * to by pOverlayVisuals.  If this
145b3307321Smrg					 * number is zero, the device does
146b3307321Smrg					 * not have overlay planes. */
147b3307321Smrg    OverlayInfo	**pOverlayVisuals,	/* The device's overlay plane visual
148b3307321Smrg					 * information. */
149b3307321Smrg    int		*numImageVisuals,	/* Number of XVisualInfo's pointed
150b3307321Smrg					 * to by pImageVisuals. */
151b3307321Smrg    XVisualInfo	***pImageVisuals	/* The device's image visuals. */
152b3307321Smrg		    );
153b3307321Smrg
154b3307321Smrg
155b3307321Smrg/******************************************************************************
156b3307321Smrg *
157b3307321Smrg * FreeXVisualInfo()
158b3307321Smrg *
159b3307321Smrg * This routine frees the data that was allocated by GetXVisualInfo().
160b3307321Smrg *
161b3307321Smrg ******************************************************************************/
162b3307321Smrg
163b3307321Smrgextern void FreeXVisualInfo(
164b3307321Smrg    XVisualInfo	*pVisuals,
165b3307321Smrg    OverlayInfo	*pOverlayVisuals,
166b3307321Smrg    XVisualInfo	**pImageVisuals
167b3307321Smrg		     );
168b3307321Smrg
169b3307321Smrg
170b3307321Smrg/******************************************************************************
171b3307321Smrg *
172b3307321Smrg * FindImagePlanesVisual()
173b3307321Smrg *
174b3307321Smrg * This routine attempts to find a visual to use to create an image planes
175b3307321Smrg * window based upon the information passed in.
176b3307321Smrg *
177b3307321Smrg * The "Hint" values give guides to the routine as to what the program wants.
178b3307321Smrg * The "depthFlexibility" value tells the routine how much the program wants
179b3307321Smrg * the actual "depthHint" specified.  If the program can't live with the
180b3307321Smrg * screen's image planes visuals, the routine returns non-zero, and the
181b3307321Smrg * "depthObtained" and "pImageVisualToUse" return parameters are NOT valid.
182b3307321Smrg * Otherwise, the "depthObtained" and "pImageVisualToUse" return parameters
183b3307321Smrg * are valid and the routine returns zero.
184b3307321Smrg *
185b3307321Smrg * NOTE: This is just an example of what can be done.  It may or may not be
186b3307321Smrg * useful for any specific application.
187b3307321Smrg *
188b3307321Smrg ******************************************************************************/
189b3307321Smrg
190b3307321Smrgextern int FindImagePlanesVisual(
191b3307321Smrg    Display	*display,		/* Which X server (aka "display"). */
192b3307321Smrg    int		screen,			/* Which screen of the "display". */
193b3307321Smrg    int		numImageVisuals,	/* Number of XVisualInfo's pointed
194b3307321Smrg					 * to by pImageVisuals. */
195b3307321Smrg    XVisualInfo	**pImageVisuals,	/* The device's image visuals. */
196b3307321Smrg    int		sbCmapHint,		/* What Starbase cmap modes will be
197b3307321Smrg					 * used with the visual.  NOTE: This
198b3307321Smrg					 * is a mask of the possible values. */
199b3307321Smrg    int		depthHint,		/* Desired depth. */
200b3307321Smrg    int		depthFlexibility,	/* How much the actual value in
201b3307321Smrg					 * "depthHint" is desired. */
202b3307321Smrg    Visual	**pImageVisualToUse,	/* The screen's image visual to use. */
203b3307321Smrg    int		*depthObtained		/* Actual depth of the visual. */
204b3307321Smrg				     );
205b3307321Smrg
206b3307321Smrg
207b3307321Smrg/******************************************************************************
208b3307321Smrg *
209b3307321Smrg * FindOverlayPlanesVisual()
210b3307321Smrg *
211b3307321Smrg * This routine attempts to find a visual to use to create an overlay planes
212b3307321Smrg * window based upon the information passed in.
213b3307321Smrg *
214b3307321Smrg * While the CreateImagePlanesWindow() routine took a sbCmapHint, this
215b3307321Smrg * routine doesn't.  Starbase's CMAP_FULL shouldn't be used in overlay planes
216b3307321Smrg * windows.  This is partially because this functionality is better suited in
217b3307321Smrg * the image planes where there are generally more planes, and partially
218b3307321Smrg * because the overlay planes generally have PseudoColor visuals with one
219b3307321Smrg * color being transparent (the transparent normally being the "white" color
220b3307321Smrg * for CMAP_FULL).
221b3307321Smrg *
222b3307321Smrg * The "depthHint" values give guides to the routine as to what depth the
223b3307321Smrg * program wants the window to be.  The "depthFlexibility" value tells the
224b3307321Smrg * routine how much the program wants the actual "depthHint" specified.  If
225b3307321Smrg * the program can't live with the screen's overlay planes visuals, the
226b3307321Smrg * routine returns non-zero, and the "depthObtained" and "pOverlayVisualToUse"
227b3307321Smrg * return parameters are NOT valid.  Otherwise, the "depthObtained" and
228b3307321Smrg * "pOverlayVisualToUse" return parameters are valid and the routine returns
229b3307321Smrg * zero.
230b3307321Smrg *
231b3307321Smrg * NOTE: This is just an example of what can be done.  It may or may not be
232b3307321Smrg * useful for any specific application.
233b3307321Smrg *
234b3307321Smrg ******************************************************************************/
235b3307321Smrg
236b3307321Smrgextern int FindOverlayPlanesVisual(
237b3307321Smrg    Display	*display,		/* Which X server (aka "display"). */
238b3307321Smrg    int		screen,			/* Which screen of the "display". */
239b3307321Smrg    int		numOverlayVisuals,	/* Number of OverlayInfo's pointed
240b3307321Smrg					 * to by pOverlayVisuals. */
241b3307321Smrg    OverlayInfo	*pOverlayVisuals,	/* The device's overlay plane visual
242b3307321Smrg					 * information. */
243b3307321Smrg    int		depthHint,		/* Desired depth. */
244b3307321Smrg    int		depthFlexibility,	/* How much the actual value in
245b3307321Smrg					 * "depthHint" is desired. */
246b3307321Smrg    int		transparentBackground,	/* Non-zero if the visual must have
247b3307321Smrg					 * a transparent color. */
248b3307321Smrg    Visual	**pOverlayVisualToUse,	/* The screen's overlay visual to
249b3307321Smrg					 * use. */
250b3307321Smrg    int		*depthObtained,		/* Actual depth of the visual. */
251b3307321Smrg    int		*transparentColor	/* The transparent color the program
252b3307321Smrg					 * can use with the visual. */
253b3307321Smrg				);
254b3307321Smrg
255b3307321Smrg
256b3307321Smrg/******************************************************************************
257b3307321Smrg *
258b3307321Smrg * CreateImagePlanesWindow()
259b3307321Smrg *
260b3307321Smrg * This routine creates an image planes window, potentially creates a colormap
261b3307321Smrg * for the window to use, and sets the window's standard properties, based
262b3307321Smrg * upon the information passed in to the routine.  While "created," the window
263b3307321Smrg * has not been mapped.
264b3307321Smrg *
2656728f30eSmrg * If the routine succeeds, it returns zero and the return parameters
266b3307321Smrg * "imageWindow", "imageColormap" and "mustFreeImageColormap" are valid.
267b3307321Smrg * Otherwise, the routine returns non-zero and the return parameters are
268b3307321Smrg * NOT valid.
269b3307321Smrg *
270b3307321Smrg * NOTE: This is just an example of what can be done.  It may or may not be
271b3307321Smrg * useful for any specific application.
272b3307321Smrg *
273b3307321Smrg ******************************************************************************/
274b3307321Smrg
275b3307321Smrgextern int CreateImagePlanesWindow(
276b3307321Smrg    Display	*display,		/* Which X server (aka "display"). */
277b3307321Smrg    int		screen,			/* Which screen of the "display". */
278b3307321Smrg    Window	parentWindow,		/* Window ID of the parent window for
279b3307321Smrg					 * the created window. */
280b3307321Smrg    int		windowX,		/* Desired X coord. of the window. */
281b3307321Smrg    int		windowY,		/* Desired Y coord of the window. */
282b3307321Smrg    int		windowWidth,		/* Desired width of the window. */
283b3307321Smrg    int		windowHeight,		/* Desired height of the window. */
284b3307321Smrg    int		windowDepth,		/* Desired depth of the window. */
285b3307321Smrg    Visual	*pImageVisualToUse,	/* The window's image planes visual. */
286b3307321Smrg    int		argc,			/* Program's argc parameter. */
287b3307321Smrg    char	*argv[],		/* Program's argv parameter. */
288b3307321Smrg    char	*windowName,		/* Name to put on window's border. */
289b3307321Smrg    char	*iconName,		/* Name to put on window's icon. */
290b3307321Smrg    Window	*imageWindow,		/* Window ID of the created window. */
291b3307321Smrg    Colormap	*imageColormap,		/* The window's colormap. */
292b3307321Smrg    int		*mustFreeImageColormap	/* Non-zero if the program must call
293b3307321Smrg					 * XFreeColormap() for imageColormap. */
294b3307321Smrg				);
295b3307321Smrg
296b3307321Smrg
297b3307321Smrg/******************************************************************************
298b3307321Smrg *
299b3307321Smrg * CreateOverlayPlanesWindow()
300b3307321Smrg *
301b3307321Smrg * This routine creates an overlay planes window, potentially creates a colormap
302b3307321Smrg * for the window to use, and sets the window's standard properties, based
303b3307321Smrg * upon the information passed in to the routine.  While "created," the window
304b3307321Smrg * has not been mapped.
305b3307321Smrg *
3066728f30eSmrg * If the routine succeeds, it returns zero and the return parameters
307b3307321Smrg * "overlayWindow", "overlayColormap" and "mustFreeOverlayColormap" are valid.
308b3307321Smrg * Otherwise, the routine returns non-zero and the return parameters are
309b3307321Smrg * NOT valid.
310b3307321Smrg *
311b3307321Smrg * NOTE: This is just an example of what can be done.  It may or may not be
312b3307321Smrg * useful for any specific application.
313b3307321Smrg *
314b3307321Smrg ******************************************************************************/
315b3307321Smrg
316b3307321Smrgint CreateOverlayPlanesWindow(
317b3307321Smrg    Display	*display,		/* Which X server (aka "display"). */
318b3307321Smrg    int		screen,			/* Which screen of the "display". */
319b3307321Smrg    Window	parentWindow,		/* Window ID of the parent window for
320b3307321Smrg					 * the created window. */
321b3307321Smrg    int		windowX,		/* Desired X coord. of the window. */
322b3307321Smrg    int		windowY,		/* Desired Y coord of the window. */
323b3307321Smrg    int		windowWidth,		/* Desired width of the window. */
324b3307321Smrg    int		windowHeight,		/* Desired height of the window. */
325b3307321Smrg    int		windowDepth,		/* Desired depth of the window. */
326b3307321Smrg    Visual	*pOverlayVisualToUse,	/* The window's overlay planes visual.*/
327b3307321Smrg    int		argc,			/* Program's argc parameter. */
328b3307321Smrg    char	*argv[],		/* Program's argv parameter. */
329b3307321Smrg    char	*windowName,		/* Name to put on window's border. */
330b3307321Smrg    char	*iconName,		/* Name to put on window's icon. */
331b3307321Smrg    int		transparentBackground,	/* Non-zero if the window's background
332b3307321Smrg					 * should be a transparent color. */
333b3307321Smrg    int		*transparentColor,	/* The transparent color to use as the
334b3307321Smrg					 * window's background. */
335b3307321Smrg    Window	*overlayWindow,		/* Window ID of the created window. */
336b3307321Smrg    Colormap	*overlayColormap,	/* The window's colormap. */
337b3307321Smrg    int		*mustFreeOverlayColormap/* Non-zero if the program must call
338b3307321Smrg					  * XFreeColormap() for
339b3307321Smrg					  * overlayColormap. */
340b3307321Smrg				);
341