1c041511dScube#ifndef __win32_x11_h__
2c041511dScube#define __win32_x11_h__
3c041511dScube
4c041511dScube/* Copyright (c) Nate Robins, 1997. */
5c041511dScube
6c041511dScube/* This program is freely distributable without licensing fees
7c041511dScube   and is provided without guarantee or warrantee expressed or
8c041511dScube   implied. This program is -not- in the public domain. */
9c041511dScube#ifdef __MINGW32__
10c041511dScube#include <GL/gl.h>
11c041511dScube#endif
12c041511dScube#include <stdlib.h>
13c041511dScube#include <windows.h>
14c041511dScube
15c041511dScube/* These definitions are missing from windows.h */
16c041511dScube
17c041511dScube
18c041511dScube/* Type definitions (conversions) */
19c041511dScubetypedef int Visual;			/* Win32 equivalent of X11 type */
20c041511dScubetypedef HWND Window;
21c041511dScubetypedef HPALETTE Colormap;
22c041511dScubetypedef PIXELFORMATDESCRIPTOR XVisualInfo;
23c041511dScubetypedef BOOL Bool;
24c041511dScubetypedef MSG XEvent;
25c041511dScubetypedef HDC Display;
26c041511dScubetypedef HCURSOR Cursor;
27c041511dScube
28c041511dScubetypedef int Atom;			/* dummies */
29c041511dScubetypedef int XDevice;
30c041511dScubetypedef int Status;
31c041511dScube
32c041511dScube#define True  TRUE			/* Win32 equivalents of X11 booleans */
33c041511dScube#define False FALSE
34c041511dScube
35c041511dScube#define None                 0L	/* universal null resource or null atom */
36c041511dScube
37c041511dScube/* Input Event Masks. Used as event-mask window attribute and as arguments
38c041511dScube   to Grab requests.  Not to be confused with event names.  */
39c041511dScube
40c041511dScube#define NoEventMask			0L
41c041511dScube#define KeyPressMask			(1L<<0)
42c041511dScube#define KeyReleaseMask			(1L<<1)
43c041511dScube#define ButtonPressMask			(1L<<2)
44c041511dScube#define ButtonReleaseMask		(1L<<3)
45c041511dScube#define EnterWindowMask			(1L<<4)
46c041511dScube#define LeaveWindowMask			(1L<<5)
47c041511dScube#define PointerMotionMask		(1L<<6)
48c041511dScube#define PointerMotionHintMask		(1L<<7)
49c041511dScube#define Button1MotionMask		(1L<<8)
50c041511dScube#define Button2MotionMask		(1L<<9)
51c041511dScube#define Button3MotionMask		(1L<<10)
52c041511dScube#define Button4MotionMask		(1L<<11)
53c041511dScube#define Button5MotionMask		(1L<<12)
54c041511dScube#define ButtonMotionMask		(1L<<13)
55c041511dScube#define KeymapStateMask			(1L<<14)
56c041511dScube#define ExposureMask			(1L<<15)
57c041511dScube#define VisibilityChangeMask		(1L<<16)
58c041511dScube#define StructureNotifyMask		(1L<<17)
59c041511dScube#define ResizeRedirectMask		(1L<<18)
60c041511dScube#define SubstructureNotifyMask		(1L<<19)
61c041511dScube#define SubstructureRedirectMask	(1L<<20)
62c041511dScube#define FocusChangeMask			(1L<<21)
63c041511dScube#define PropertyChangeMask		(1L<<22)
64c041511dScube#define ColormapChangeMask		(1L<<23)
65c041511dScube#define OwnerGrabButtonMask		(1L<<24)
66c041511dScube
67c041511dScube/* Key masks. Used as modifiers to GrabButton and GrabKey, results of
68c041511dScube   QueryPointer, state in various key-, mouse-, and button-related
69c041511dScube   events. */
70c041511dScube
71c041511dScube#define ShiftMask		(1<<0)
72c041511dScube#define LockMask		(1<<1)
73c041511dScube#define ControlMask		(1<<2)
74c041511dScube#define Mod1Mask		(1<<3)
75c041511dScube#define Mod2Mask		(1<<4)
76c041511dScube#define Mod3Mask		(1<<5)
77c041511dScube#define Mod4Mask		(1<<6)
78c041511dScube#define Mod5Mask		(1<<7)
79c041511dScube
80c041511dScube/* Window classes used by CreateWindow */
81c041511dScube/* Note that CopyFromParent is already defined as 0 above */
82c041511dScube
83c041511dScube#define InputOutput		1
84c041511dScube#define InputOnly		2
85c041511dScube
86c041511dScube/* Window attributes for CreateWindow and ChangeWindowAttributes */
87c041511dScube
88c041511dScube#define CWBackPixmap		(1L<<0)
89c041511dScube#define CWBackPixel		(1L<<1)
90c041511dScube#define CWBorderPixmap		(1L<<2)
91c041511dScube#define CWBorderPixel           (1L<<3)
92c041511dScube#define CWBitGravity		(1L<<4)
93c041511dScube#define CWWinGravity		(1L<<5)
94c041511dScube#define CWBackingStore          (1L<<6)
95c041511dScube#define CWBackingPlanes	        (1L<<7)
96c041511dScube#define CWBackingPixel	        (1L<<8)
97c041511dScube#define CWOverrideRedirect	(1L<<9)
98c041511dScube#define CWSaveUnder		(1L<<10)
99c041511dScube#define CWEventMask		(1L<<11)
100c041511dScube#define CWDontPropagate	        (1L<<12)
101c041511dScube#define CWColormap		(1L<<13)
102c041511dScube#define CWCursor	        (1L<<14)
103c041511dScube
104c041511dScube/* ConfigureWindow structure */
105c041511dScube
106c041511dScube#define CWX			(1<<0)
107c041511dScube#define CWY			(1<<1)
108c041511dScube#define CWWidth			(1<<2)
109c041511dScube#define CWHeight		(1<<3)
110c041511dScube#define CWBorderWidth		(1<<4)
111c041511dScube#define CWSibling		(1<<5)
112c041511dScube#define CWStackMode		(1<<6)
113c041511dScube
114c041511dScube
115c041511dScube/* Used in GetWindowAttributes reply */
116c041511dScube
117c041511dScube#define IsUnmapped		0
118c041511dScube#define IsUnviewable		1
119c041511dScube#define IsViewable		2
120c041511dScube
121c041511dScube/* Window stacking method (in configureWindow) */
122c041511dScube
123c041511dScube#define Above                   0
124c041511dScube#define Below                   1
125c041511dScube#define TopIf                   2
126c041511dScube#define BottomIf                3
127c041511dScube#define Opposite                4
128c041511dScube
129c041511dScube/* For CreateColormap */
130c041511dScube
131c041511dScube#define AllocNone		0	/* create map with no entries */
132c041511dScube#define AllocAll		1	/* allocate entire map writeable */
133c041511dScube
134c041511dScube
135c041511dScube/* Flags used in StoreNamedColor, StoreColors */
136c041511dScube
137c041511dScube#define DoRed			(1<<0)
138c041511dScube#define DoGreen			(1<<1)
139c041511dScube#define DoBlue			(1<<2)
140c041511dScube
141c041511dScube/*
142c041511dScube * Bitmask returned by XParseGeometry().  Each bit tells if the corresponding
143c041511dScube * value (x, y, width, height) was found in the parsed string.
144c041511dScube */
145c041511dScube#define NoValue		0x0000
146c041511dScube#define XValue  	0x0001
147c041511dScube#define YValue		0x0002
148c041511dScube#define WidthValue  	0x0004
149c041511dScube#define HeightValue  	0x0008
150c041511dScube#define AllValues 	0x000F
151c041511dScube#define XNegative 	0x0010
152c041511dScube#define YNegative 	0x0020
153c041511dScube
154c041511dScube/* flags argument in size hints */
155c041511dScube#define USPosition	(1L << 0) /* user specified x, y */
156c041511dScube#define USSize		(1L << 1) /* user specified width, height */
157c041511dScube
158c041511dScube/* definitions for initial window state */
159c041511dScube#define WithdrawnState 0	/* for windows that are not mapped */
160c041511dScube#define NormalState 1	/* most applications want to start this way */
161c041511dScube#define IconicState 3	/* application wants to start as an icon */
162c041511dScube#define GameModeState 4  /* Win32 GLUT only (not in Xlib!). */
163c041511dScube
164c041511dScube/* Type definitions */
165c041511dScube
166c041511dScubetypedef struct {
167c041511dScube    unsigned int background_pixmap;	/* background pixmap */
168c041511dScube    unsigned long background_pixel;	/* background pixel */
169c041511dScube    unsigned long border_pixel;	/* border pixel value */
170c041511dScube    long event_mask;		/* set of events that should be saved */
171c041511dScube    long do_not_propagate_mask;	/* set of events that should not propagate */
172c041511dScube    Bool override_redirect;	   /* boolean value for override-redirect */
173c041511dScube    Colormap colormap;		   /* color map to be associated with window */
174c041511dScube} XSetWindowAttributes;
175c041511dScube
176c041511dScubetypedef struct {
177c041511dScube  unsigned long pixel;
178c041511dScube  unsigned short red, green, blue;
179c041511dScube  char flags;  /* do_red, do_green, do_blue */
180c041511dScube} XColor;
181c041511dScube
182c041511dScubetypedef struct {
183c041511dScube  unsigned char *value;	   /* same as Property routines */
184c041511dScube  Atom encoding;	   /* prop type */
185c041511dScube  int format;		   /* prop data format: 8, 16, or 32 */
186c041511dScube  unsigned long nitems;	   /* number of data items in value */
187c041511dScube} XTextProperty;
188c041511dScube
189c041511dScubetypedef struct {
190c041511dScube  long flags;	        /* marks which fields in this structure are defined */
191c041511dScube  int x, y;		/* obsolete for new window mgrs, but clients */
192c041511dScube  int width, height;	/* should set so old wm's don't mess up */
193c041511dScube} XSizeHints;
194c041511dScube
195c041511dScube/* Functions emulated by macros. */
196c041511dScube
197c041511dScube#define XFreeColormap(display, colormap) \
198c041511dScube  DeleteObject(colormap)
199c041511dScube
200c041511dScube#define XCreateFontCursor(display, shape) \
201c041511dScube  LoadCursor(NULL, shape)
202c041511dScube
203c041511dScube#define XDefineCursor(display, window, cursor) \
204c041511dScube  SetCursor(cursor)
205c041511dScube
206c041511dScube#define XFlush(display) \
207c041511dScube  /* Nothing. */
208c041511dScube
209c041511dScube#define DisplayWidth(display, screen) \
210c041511dScube  GetSystemMetrics(SM_CXSCREEN)
211c041511dScube
212c041511dScube#define DisplayHeight(display, screen) \
213c041511dScube  GetSystemMetrics(SM_CYSCREEN)
214c041511dScube
215c041511dScube#define XMapWindow(display, window) \
216c041511dScube  ShowWindow(window, SW_SHOWNORMAL)
217c041511dScube
218c041511dScube#define XUnmapWindow(display, window) \
219c041511dScube  ShowWindow(window, SW_HIDE)
220c041511dScube
221c041511dScube#define XIconifyWindow(display, window, screen) \
222c041511dScube  ShowWindow(window, SW_MINIMIZE)
223c041511dScube
224c041511dScube#define XWithdrawWindow(display, window, screen) \
225c041511dScube  ShowWindow(window, SW_HIDE)
226c041511dScube
227c041511dScube#define XLowerWindow(display, window) \
228c041511dScube  SetWindowPos(window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)
229c041511dScube
230c041511dScube#define XSetWMName(display, window, tp) \
2312590f9beSmrg  SetWindowText(window, (const char *)(tp)->value)
232c041511dScube
233c041511dScube/* There really isn't a way to set the icon name separate from the
234c041511dScube   windows name in Win32, so, just set the windows name. */
235c041511dScube#define XSetWMIconName(display, window, tp) \
236c041511dScube  XSetWMName(display, window, tp)
237c041511dScube
238c041511dScube#define XDestroyWindow(display, window) \
239c041511dScube  DestroyWindow(window)
240c041511dScube
241c041511dScube/* Anything that needs to be freed was allocated with malloc in our
242c041511dScube   fake X windows library for Win32, so free it with plain old
243c041511dScube   free(). */
244c041511dScube#define XFree(data) \
245c041511dScube  free(data)
246c041511dScube
247c041511dScube/* Nothing to be done for this...the pointer is always 'ungrabbed'
248c041511dScube   in Win32. */
249c041511dScube#define XUngrabPointer(display, time) \
250c041511dScube  /* Nothing. */
251c041511dScube
252c041511dScube/* Function prototypes. */
253c041511dScube
254c041511dScubeextern XVisualInfo* XGetVisualInfo(
255c041511dScube  Display* display,
256c041511dScube  long mask,
257c041511dScube  XVisualInfo* ttemplate,  /* Avoid class with C++ keyword. */
258c041511dScube  int*nitems);
259c041511dScube
260c041511dScubeextern Colormap XCreateColormap(
261c041511dScube  Display* display,
262c041511dScube  Window root,
263c041511dScube  Visual* visual,
264c041511dScube  int alloc);
265c041511dScube
266c041511dScubeextern void XAllocColorCells(
267c041511dScube  Display* display,
268c041511dScube  Colormap colormap,
269c041511dScube  Bool contig,
270c041511dScube  unsigned long plane_masks_return[],
271c041511dScube  unsigned int nplanes,
272c041511dScube  unsigned long pixels_return[],
273c041511dScube  unsigned int npixels);
274c041511dScube
275c041511dScubeextern void XStoreColor(
276c041511dScube  Display* display,
277c041511dScube  Colormap colormap,
278c041511dScube  XColor* color);
279c041511dScube
280c041511dScubeextern void XSetWindowColormap(
281c041511dScube  Display* display,
282c041511dScube  Window window,
283c041511dScube  Colormap colormap);
284c041511dScube
285c041511dScubeextern Bool XTranslateCoordinates(
286c041511dScube  Display *display,
287c041511dScube  Window src, Window dst,
288c041511dScube  int src_x, int src_y,
289c041511dScube  int* dest_x_return, int* dest_y_return,
290c041511dScube  Window* child_return);
291c041511dScube
292c041511dScubeextern Status XGetGeometry(
293c041511dScube  Display* display,
294c041511dScube  Window window,
295c041511dScube  Window* root_return,
296c041511dScube  int* x_return, int* y_return,
297c041511dScube  unsigned int* width_return, unsigned int* height_return,
298c041511dScube  unsigned int *border_width_return,
299c041511dScube  unsigned int* depth_return);
300c041511dScube
301c041511dScubeextern int DisplayWidthMM(
302c041511dScube  Display* display,
303c041511dScube  int screen);
304c041511dScube
305c041511dScubeextern int DisplayHeightMM(
306c041511dScube  Display* display,
307c041511dScube  int screen);
308c041511dScube
309c041511dScubeextern void XWarpPointer(
310c041511dScube  Display* display,
311c041511dScube  Window src, Window dst,
312c041511dScube  int src_x, int src_y,
313c041511dScube  int src_width, int src_height,
314c041511dScube  int dst_x, int dst_y);
315c041511dScube
316c041511dScubeextern int XParseGeometry(
317c041511dScube  char* string,
318c041511dScube  int* x, int* y,
319c041511dScube  unsigned int* width, unsigned int* height);
320c041511dScube
321c041511dScubeextern int XPending(
322c041511dScube  Display* display);
323c041511dScube
324c041511dScube#endif /* __win32_x11_h__ */
325