2
/* Copyright (c) Nate Robins, 1997. */
3
/* portions Copyright (c) Mark Kilgard, 1998. */
5
/* This program is freely distributable without licensing fees
6
and is provided without guarantee or warrantee expressed or
7
implied. This program is -not- in the public domain. */
10
#include "win32_x11.h"
12
/* global variable that must be set for some functions to operate
17
XGetVisualInfo(Display* display, long mask, XVisualInfo* xtemplate, int* nitems)
19
/* KLUDGE: this function needs XHDC to be set to the HDC currently
20
being operated on before it is invoked! */
22
PIXELFORMATDESCRIPTOR* pfds;
25
n = DescribePixelFormat(XHDC, 0, 0, NULL);
26
pfds = (PIXELFORMATDESCRIPTOR*)malloc(sizeof(PIXELFORMATDESCRIPTOR) * n);
27
memset(pfds, 0, sizeof(PIXELFORMATDESCRIPTOR) * n);
29
for (i = 0; i < n; i++) {
30
DescribePixelFormat(XHDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfds[i]);
38
XCreateColormap(Display* display, Window root, Visual* visual, int alloc)
40
/* KLUDGE: this function needs XHDC to be set to the HDC currently
41
being operated on before it is invoked! */
43
PIXELFORMATDESCRIPTOR pfd;
48
/* grab the pixel format */
49
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
50
DescribePixelFormat(XHDC, GetPixelFormat(XHDC),
51
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
53
if (!(pfd.dwFlags & PFD_NEED_PALETTE ||
54
pfd.iPixelType == PFD_TYPE_COLORINDEX))
59
n = 1 << pfd.cColorBits;
61
/* allocate a bunch of memory for the logical palette (assume 256
62
colors in a Win32 palette */
63
logical = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +
64
sizeof(PALETTEENTRY) * n);
65
memset(logical, 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * n);
67
/* set the entries in the logical palette */
68
logical->palVersion = 0x300;
69
logical->palNumEntries = n;
71
/* start with a copy of the current system palette */
72
GetSystemPaletteEntries(XHDC, 0, 256, &logical->palPalEntry[0]);
74
if (pfd.iPixelType == PFD_TYPE_RGBA) {
75
int redMask = (1 << pfd.cRedBits) - 1;
76
int greenMask = (1 << pfd.cGreenBits) - 1;
77
int blueMask = (1 << pfd.cBlueBits) - 1;
80
/* fill in an RGBA color palette */
81
for (i = 0; i < n; ++i) {
82
logical->palPalEntry[i].peRed =
83
(((i >> pfd.cRedShift) & redMask) * 255) / redMask;
84
logical->palPalEntry[i].peGreen =
85
(((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
86
logical->palPalEntry[i].peBlue =
87
(((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
88
logical->palPalEntry[i].peFlags = 0;
92
palette = CreatePalette(logical);
95
SelectPalette(XHDC, palette, FALSE);
102
XAllocColorCells(Display* display, Colormap colormap, Bool contig,
103
unsigned long plane_masks_return[], unsigned int nplanes,
104
unsigned long pixels_return[], unsigned int npixels)
106
/* NOP -- we did all the allocating in XCreateColormap! */
110
XStoreColor(Display* display, Colormap colormap, XColor* color)
112
/* KLUDGE: set XHDC to 0 if the palette should NOT be realized after
113
setting the color. set XHDC to the correct HDC if it should. */
117
/* X11 stores color from 0-65535, Win32 expects them to be 0-256, so
118
twiddle the bits ( / 256). */
119
pe.peRed = color->red / 256;
120
pe.peGreen = color->green / 256;
121
pe.peBlue = color->blue / 256;
123
/* make sure we use this flag, otherwise the colors might get mapped
124
to another place in the colormap, and when we glIndex() that
125
color, it may have moved (argh!!) */
126
pe.peFlags = PC_NOCOLLAPSE;
128
/* the pixel field of the XColor structure is the index into the
130
SetPaletteEntries(colormap, color->pixel, 1, &pe);
133
UnrealizeObject(colormap);
134
SelectPalette(XHDC, colormap, FALSE);
135
RealizePalette(XHDC);
140
XSetWindowColormap(Display* display, Window window, Colormap colormap)
142
HDC hdc = GetDC(window);
144
/* if the third parameter is FALSE, the logical colormap is copied
145
into the device palette when the application is in the
146
foreground, if it is TRUE, the colors are mapped into the current
147
palette in the best possible way. */
148
SelectPalette(hdc, colormap, FALSE);
151
/* note that we don't have to release the DC, since our window class
152
uses the WC_OWNDC flag! */
156
XTranslateCoordinates(Display *display, Window src, Window dst,
157
int src_x, int src_y,
158
int* dest_x_return, int* dest_y_return,
159
Window* child_return)
161
/* KLUDGE: this isn't really a translate coordinates into some other
162
windows coordinate system...it only translates coordinates into the
163
root window (screen) coordinate system. */
170
ClientToScreen(src, &point);
172
*dest_x_return = point.x;
173
*dest_y_return = point.y;
175
/* just to make compilers happy...we don't use the return value. */
180
XGetGeometry(Display* display, Window window, Window* root_return,
181
int* x_return, int* y_return,
182
unsigned int* width_return, unsigned int* height_return,
183
unsigned int *border_width_return, unsigned int* depth_return)
185
/* KLUDGE: doesn't return the border_width or depth or root, x & y
186
are in screen coordinates. */
191
GetClientRect(window, &rect);
195
ClientToScreen(window, &point);
199
*width_return = rect.right;
200
*height_return = rect.bottom;
202
/* just to make compilers happy...we don't use the return value. */
207
DisplayWidthMM(Display* display, int screen)
210
HWND hwnd = GetDesktopWindow();
211
HDC hdc = GetDC(hwnd);
213
width = GetDeviceCaps(hdc, HORZSIZE);
215
/* make sure to release this DC (it's the desktops, not ours) */
216
ReleaseDC(hwnd, hdc);
222
DisplayHeightMM(Display* display, int screen)
225
HWND hwnd = GetDesktopWindow();
226
HDC hdc = GetDC(hwnd);
228
height = GetDeviceCaps(hdc, VERTSIZE);
230
/* make sure to release this DC (it's the desktops, not ours) */
231
ReleaseDC(hwnd, hdc);
237
XWarpPointer(Display* display, Window src, Window dst,
238
int src_x, int src_y, int src_width, int src_height,
239
int dst_x, int dst_y)
241
/* KLUDGE: this isn't really a warp pointer into some other windows
242
coordinate system...it only warps the pointer into the root window
243
(screen) coordinate system. */
249
ClientToScreen(dst, &point);
251
SetCursorPos(point.x, point.y);
255
XPending(Display* display)
257
/* similar functionality...I don't think that it is exact, but this
261
return PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
264
/* the following function was stolen from the X sources as indicated. */
266
/* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */
267
/* $XConsortium: XParseGeom.c,v 11.18 91/02/21 17:23:05 rws Exp $ */
270
Permission to use, copy, modify, distribute, and sell this software and its
271
documentation for any purpose is hereby granted without fee, provided that
272
the above copyright notice appear in all copies and that both that
273
copyright notice and this permission notice appear in supporting
274
documentation, and that the name of M.I.T. not be used in advertising or
275
publicity pertaining to distribution of the software without specific,
276
written prior permission. M.I.T. makes no representations about the
277
suitability of this software for any purpose. It is provided "as is"
278
without express or implied warranty.
282
* XParseGeometry parses strings of the form
283
* "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
284
* width, height, xoffset, and yoffset are unsigned integers.
285
* Example: "=80x24+300-49"
286
* The equal sign is optional.
287
* It returns a bitmask that indicates which of the four values
288
* were actually found in the string. For each value found,
289
* the corresponding argument is updated; for each value
290
* not found, the corresponding argument is left unchanged.
294
ReadInteger(char *string, char **NextString)
296
register int Result = 0;
301
else if (*string == '-')
306
for (; (*string >= '0') && (*string <= '9'); string++)
308
Result = (Result * 10) + (*string - '0');
310
*NextString = string;
317
int XParseGeometry(char *string, int *x, int *y, unsigned int *width, unsigned int *height)
320
register char *strind;
321
unsigned int tempWidth, tempHeight;
325
if ( (string == NULL) || (*string == '\0')) return(mask);
327
string++; /* ignore possible '=' at beg of geometry spec */
329
strind = (char *)string;
330
if (*strind != '+' && *strind != '-' && *strind != 'x') {
331
tempWidth = ReadInteger(strind, &nextCharacter);
332
if (strind == nextCharacter)
334
strind = nextCharacter;
338
if (*strind == 'x' || *strind == 'X') {
340
tempHeight = ReadInteger(strind, &nextCharacter);
341
if (strind == nextCharacter)
343
strind = nextCharacter;
347
if ((*strind == '+') || (*strind == '-')) {
348
if (*strind == '-') {
350
tempX = -ReadInteger(strind, &nextCharacter);
351
if (strind == nextCharacter)
353
strind = nextCharacter;
359
tempX = ReadInteger(strind, &nextCharacter);
360
if (strind == nextCharacter)
362
strind = nextCharacter;
365
if ((*strind == '+') || (*strind == '-')) {
366
if (*strind == '-') {
368
tempY = -ReadInteger(strind, &nextCharacter);
369
if (strind == nextCharacter)
371
strind = nextCharacter;
378
tempY = ReadInteger(strind, &nextCharacter);
379
if (strind == nextCharacter)
381
strind = nextCharacter;
387
/* If strind isn't at the end of the string the it's an invalid
388
geometry specification. */
390
if (*strind != '\0') return (0);
396
if (mask & WidthValue)
398
if (mask & HeightValue)
399
*height = tempHeight;