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