diff options
Diffstat (limited to 'app/xlockmore/win32')
-rw-r--r-- | app/xlockmore/win32/Makefile.win32 | 40 | ||||
-rw-r--r-- | app/xlockmore/win32/Xapi.c | 2856 | ||||
-rw-r--r-- | app/xlockmore/win32/Xapi.h | 971 | ||||
-rw-r--r-- | app/xlockmore/win32/readme.txt | 334 | ||||
-rw-r--r-- | app/xlockmore/win32/todo.txt | 46 | ||||
-rw-r--r-- | app/xlockmore/win32/xlock.ico | bin | 0 -> 2238 bytes | |||
-rw-r--r-- | app/xlockmore/win32/xlock95.c | 225 | ||||
-rw-r--r-- | app/xlockmore/win32/xlock95.h | 13 | ||||
-rw-r--r-- | app/xlockmore/win32/xlockrc.rc | 31 |
9 files changed, 4516 insertions, 0 deletions
diff --git a/app/xlockmore/win32/Makefile.win32 b/app/xlockmore/win32/Makefile.win32 new file mode 100644 index 000000000..998d3b9b0 --- /dev/null +++ b/app/xlockmore/win32/Makefile.win32 @@ -0,0 +1,40 @@ +# build applications +CC=gcc +MAKE=make +RES=windres + +# compiler flags +CFLAGS=-DWIN32 -D_DEBUG -DSYSV -mno-cygwin -mwindows -O2 +#CFLAGS=-DWIN32 -DSYSV -mno-cygwin -mwindows -O2 + +# Include & Library directories +WIN32API=/usr/include/w32api +INCS=-I$(WIN32API) -I../xlock -I. + +# sources +SRC= xlockrc.rc \ + Xapi.c \ + xlock95.c \ + +# objects +OBJS = $(SRC:.rc=.o) +OBJS += $(SRC:.c=.o) + +# general rules +.rc.o: + $(RES) --include-dir $(WIN32API) -i $< -o $@ + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< $(INCS) + +# specific rules +all: $(OBJS) + +xlock95.o: xlock95.h +xlockrc.o: xlock95.h + +xlockrc.o: xlockrc.rc + $(RES) --include-dir $(WIN32API) -i $< -o $@ + +clean: + rm -f *.o *.scr core *~ *% *.bak *.rej *.orig *.patch *.pure diff --git a/app/xlockmore/win32/Xapi.c b/app/xlockmore/win32/Xapi.c new file mode 100644 index 000000000..fe22a9853 --- /dev/null +++ b/app/xlockmore/win32/Xapi.c @@ -0,0 +1,2856 @@ +/* -*- Mode: C; tab-width: 4 -*- */ +/* Xapi --- mapped X API calls */ + +#if !defined( lint ) && !defined( SABER ) +static const char sccsid[] = "@(#)Xapi.c 4.07 98/04/16 xlockmore"; + +#endif + +#ifdef WIN32 + +#include <stdlib.h> +#include <math.h> +#include "xlock.h" + +#define NUMBER_GC (1024) +#define NUMBER_BITMAP (1024) + +typedef struct { + unsigned long background; + unsigned long foreground; +} TColor; + +typedef struct { + int hasFillRule; + int value; +} TFillRule; + +typedef struct { + int hasFillStyle; + int value; +} TFillStyle; + +typedef struct { + int hasFont; + Font value; +} TFont; + +typedef struct { + int hasFunction; + int value; +} TFunction; + +typedef struct { + int hasLineAttributes; + unsigned int width; + int lineStyle; + int capStyle; + int joinStyle; +} TLineAttributes; + +typedef struct { + int hasStipple; + Pixmap graphic; +} TStipple; + +typedef struct { + int hasOrigin; + int x; + int y; +} TTSOrigin; + +typedef struct { + int isActive; + int needsReset; + TColor color; + TFillRule fillRule; + TFillStyle fillStyle; + TFunction function; + TLineAttributes lineAttributes; + TTSOrigin tsorigin; + TStipple stipple; + TFont font; +} TGCInfo; + +typedef struct { + int isActive; + int type; + int width; + int height; + HBITMAP bitmap; +} TBMInfo; + + +/* -------------------------------------------------------------------- */ + +int GCCreate(void); +HDC GCGetDC(Drawable d, GC gc); +int BMInfoCreate(void); +HBITMAP DrawableGetBitmap(Drawable d); + +/* -------------------------------------------------------------------- */ + +/*- + * global variables + */ +HWND hwnd; /* window handle */ +HDC hdc; /* device context */ +HGDIOBJ noPen = NULL; /* no pen used in fills */ +int cred, cgreen, cblue; /* color reference of the pen */ +unsigned char *red, *green, *blue; /* holds a list of colors */ +int colorcount; /* number of colors used */ +unsigned int randommode; /* number of mode to index */ +RECT rc; /* coords of the screen */ + +HANDLE thread; /* thread handle */ +DWORD thread_id; /* thread id number */ + +int numGCInfo = 0; /* number of GC Info */ +TGCInfo gcInfo[NUMBER_GC + 1] = { 0 }; /* information about GCs. Allow + NUMBER_GC GC's, + 1 as a spill + over for any modes that need + more */ +int numBMInfo = 0; /* number of Bitmap Info */ +TBMInfo bmInfo[NUMBER_BITMAP + 1] = { 0 }; /* information about Bitmaps/Pixmaps */ + +/* -------------------------------------------------------------------- */ + +/* the following functions are used to build up a graphic to display in + WIN32 + */ + +void SetByte(LPBYTE lpBMData, BYTE val, int loc, int maxLoc) +{ + if (loc < maxLoc) + { + lpBMData[loc] = val ^ 0xFF; + } +} + +void SetGraphic(LPBYTE lpBMData, XImage *image) +{ + const int w32bb = 4 * 8; + const int xbmbb = 1 * 8; + BYTE xbmval; + BYTE w32val; + int lineBitCnt = 0; + int w32BitsRemain; + int i, j, k; + int bmSize; + int loc = 0; + int actBytesPerLine; + int maxLoc; + + // initialise + actBytesPerLine = (image->width + 7) / 8; + bmSize = actBytesPerLine * image->height; + maxLoc = (actBytesPerLine + ((4 - (actBytesPerLine % 4)) % 4)) * + image->height; + + // for each byte in the xbm bit array + for (i=0; i<bmSize; i++) + { + xbmval = (image->data)[i]; + w32val = 0; + + // for each bit in the byte + for (j=0; j<8; j++) + { + w32val = (w32val << 1) | ((xbmval >> j) & 0x1); + + if (j == 7) /* we have processed all bits */ + { + SetByte(lpBMData, w32val, loc, maxLoc); + loc++; + } + + // check for a line of graphic + if (++lineBitCnt == image->width) + { + w32BitsRemain = (w32bb - (lineBitCnt % w32bb)) % w32bb; + + if (w32BitsRemain % 8) + { + w32val = w32val << (w32BitsRemain % 8); + SetByte(lpBMData, w32val, loc, maxLoc); + loc++; + } + if (w32BitsRemain / 8) + { + for (k=0; k<(w32BitsRemain / 8); k++) + { + SetByte(lpBMData, 0, loc, maxLoc); + loc++; + } + } + lineBitCnt = 0; + break; + } + } + } +} + +void +LCreateBitmap(XImage *image, HBITMAP *hBitmap, HPALETTE *hPalette) +{ + BYTE palette[2][3]; + LPBITMAPINFO lpbi; + HDC hScreenDC; + LPVOID lpBMData; + LPLOGPALETTE lpLogPal; + int i; + + /* setup color palette */ + palette[0][0] = 255; /* red */ + palette[0][1] = 255; /* green */ + palette[0][2] = 255; /* blue */ + + palette[1][0] = 000; /* red */ + palette[1][1] = 000; /* green */ + palette[1][2] = 000; /* blue */ + + /* allocate memory for the bitmap header */ + lpbi = (LPBITMAPINFO)LocalAlloc(LPTR, + sizeof(BITMAPINFOHEADER) + (2 * sizeof(RGBQUAD))); + if (lpbi == NULL) + { + return; + } + + /* set bitmap header info */ + lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + lpbi->bmiHeader.biWidth = image->width; + lpbi->bmiHeader.biHeight = -1 * image->height; + lpbi->bmiHeader.biPlanes = 1; + lpbi->bmiHeader.biBitCount = 1; + lpbi->bmiHeader.biCompression = BI_RGB; + + /* fill in bitmap palette */ + for (i=0; i<2; i++) + { + lpbi->bmiColors[i].rgbRed = palette[i][0]; + lpbi->bmiColors[i].rgbGreen = palette[i][1]; + lpbi->bmiColors[i].rgbBlue = palette[i][2]; + } + + /* create bitmap area */ + hScreenDC = CreateCompatibleDC(hdc); + *hBitmap = CreateDIBSection(hScreenDC, lpbi, DIB_RGB_COLORS, + &lpBMData, NULL, 0); + + if (*hBitmap == NULL && lpBMData == NULL) + { + DeleteDC(hScreenDC); + LocalFree(lpbi); + return; + } + + DeleteDC(hScreenDC); + if (LocalFree(lpbi) != NULL) + return; + + /* copy XBM to bitmap */ + SetGraphic(lpBMData, image); + + /* create logical palette header */ + lpLogPal = (LPLOGPALETTE)LocalAlloc(LPTR, + sizeof(LOGPALETTE) + (1 * sizeof(PALETTEENTRY))); + if (lpLogPal == NULL) + { + return; + } + + /* set logical palette info */ + lpLogPal->palVersion = 0x0300; + lpLogPal->palNumEntries = 2; + for (i=0; i < 2; i++) + { + lpLogPal->palPalEntry[i].peRed = palette[i][0]; + lpLogPal->palPalEntry[i].peGreen = palette[i][1]; + lpLogPal->palPalEntry[i].peBlue = palette[i][2]; + } + + /* create palette */ + *hPalette = CreatePalette(lpLogPal); + if (*hPalette == NULL) + { + return; + } + + /* clean up palette creation data */ + LocalFree(lpLogPal); +} + +/* -------------------------------------------------------------------- */ + +/* the following functions to create, destroy, modify and access the + GC Info structure + */ +int GCCreate(void) +{ + int retVal = 0; + + for (retVal=0; retVal<NUMBER_GC; retVal++) + { + if (gcInfo[retVal].isActive == FALSE) + { + numGCInfo++; + break; + } + } + + gcInfo[retVal].isActive = TRUE; + gcInfo[retVal].needsReset = TRUE; + gcInfo[retVal].color.background = NUMCOLORS+1; + gcInfo[retVal].color.foreground = NUMCOLORS; + gcInfo[retVal].fillRule.hasFillRule = FALSE; + gcInfo[retVal].fillRule.value = 0; + gcInfo[retVal].fillStyle.hasFillStyle = FALSE; + gcInfo[retVal].fillStyle.value = 0; + gcInfo[retVal].function.hasFunction = FALSE; + gcInfo[retVal].function.value = 0; + gcInfo[retVal].lineAttributes.hasLineAttributes = FALSE; + gcInfo[retVal].lineAttributes.width = 0; + gcInfo[retVal].lineAttributes.lineStyle = 0; + gcInfo[retVal].lineAttributes.capStyle = 0; + gcInfo[retVal].lineAttributes.joinStyle = 0; + gcInfo[retVal].tsorigin.hasOrigin = FALSE; + gcInfo[retVal].tsorigin.x = 0; + gcInfo[retVal].tsorigin.y = 0; + gcInfo[retVal].stipple.hasStipple = FALSE; + gcInfo[retVal].stipple.graphic = -1; + + return retVal; +} + +/* -------------------------------------------------------------------- */ +HDC GCGetDC(Drawable d, GC gc) +{ + HGDIOBJ brush; + int fillfunc; + int fillrule; + int i; + LOGBRUSH lb; + LPLOGPALETTE lpLogPal; + BYTE palarray[2][3]; + HPALETTE palette; + HGDIOBJ pen; + DWORD penstyle; + HBITMAP stipple; + HDC lhdc; + char message[80]; + + static GC lastGc = -1; + static HDC sbhdc = NULL; + static HDC dbhdc = NULL; + + if (gc < 0 || gc >= numGCInfo) + { + sprintf(message, "GC passed in not in range 0..%d, gc=%d", + numGCInfo-1, gc); + xlockmore_set_debug(message); + return NULL; + } + + /* get DC - try and determine if its a window or bitmap */ + if (d > 0 && d < NUMBER_BITMAP) + { + if (dbhdc == NULL) + /* create a compatible DC from the saved intial DC. To draw + to this DC we still need to put a HBITMAP into it (not + done in this function) + */ + if ((dbhdc = CreateCompatibleDC(hdc)) == NULL) + { + sprintf(message, "CreateCompatibleDC() returned NULL"); + xlockmore_set_debug(message); + return NULL; + } + lhdc = dbhdc; + } + else + { + if (sbhdc == NULL) + /* create a DC for the window. We don't (and cannot) put + * a HBITMAP into this. It is ready to draw to (straight to + * the screen) + */ + if ((sbhdc = GetDC(hwnd)) == NULL) + { + sprintf(message, "GetDC() returned NULL"); + xlockmore_set_debug(message); + return NULL; + } + lhdc = sbhdc; + } + + /* check if we have already set up the DC in a previous call */ + if (lastGc == gc && gcInfo[gc].needsReset == FALSE) + return lhdc; + + /* set the current color constants */ + cred = red[gcInfo[gc].color.foreground]; + cgreen = green[gcInfo[gc].color.foreground]; + cblue = blue[gcInfo[gc].color.foreground]; + + /* set the text color */ + if (SetTextColor(lhdc, RGB(cred,cgreen,cblue)) == CLR_INVALID) + { + sprintf(message, "text: SetTextColor() returned CLR_INVALID [%d %d %d]", cred, cgreen, cblue); + xlockmore_set_debug(message); + return NULL; + } + if (SetBkColor(lhdc, RGB(red[gcInfo[gc].color.background], + green[gcInfo[gc].color.background], + blue[gcInfo[gc].color.background])) == CLR_INVALID) + { + sprintf(message, "text: SetBkColor() returned CLR_INVALID"); + xlockmore_set_debug(message); + return NULL; + } + + /* set the pen to the new color and line attributes */ + if (gcInfo[gc].lineAttributes.hasLineAttributes == FALSE) + { + /* no line attributes, just create solid pen and put into the DC*/ + if ((pen = CreatePen(PS_SOLID, 0, RGB(cred, cgreen, cblue))) == NULL) + { + sprintf(message, "pen: CreatePen() returned NULL"); + xlockmore_set_debug(message); + return NULL; + } + else + { + if ((pen = SelectObject(lhdc, pen)) == NULL) + { + sprintf(message, "pen: Failed to select pen into DC"); + xlockmore_set_debug(message); + return NULL; + } + /* remove the old pen */ + if (DeleteObject(pen) == 0) + { + sprintf(message, "pen: Failed to delete old pen"); + xlockmore_set_debug(message); + return NULL; + } + } + } + else + { + /* line attributes need to be set, create a more complex pen */ + + /* set the brush info */ + lb.lbStyle = BS_SOLID; + lb.lbColor = RGB(cred, cgreen, cblue); + lb.lbHatch = 0; + + /* set the pen style */ + penstyle = PS_GEOMETRIC; + + switch (gcInfo[gc].lineAttributes.lineStyle) + { + case LineSolid: + penstyle |= PS_SOLID; break; + case LineOnOffDash: + penstyle |= PS_DASH; break; + case LineDoubleDash: + penstyle |= PS_DOT; break; + } + + switch (gcInfo[gc].lineAttributes.capStyle) + { + case CapNotLast: + penstyle |= PS_ENDCAP_FLAT; break; + case CapButt: + penstyle |= PS_ENDCAP_FLAT; break; + case CapRound: + penstyle |= PS_ENDCAP_ROUND; break; + case CapProjecting: + penstyle |= PS_ENDCAP_SQUARE; break; + } + + switch (gcInfo[gc].lineAttributes.joinStyle) + { + case JoinMiter: + penstyle |= PS_JOIN_MITER; break; + case JoinRound: + penstyle |= PS_JOIN_ROUND; break; + case JoinBevel: + penstyle |= PS_JOIN_BEVEL; break; + } + + /* create the pen, putting it in the DC */ + pen = SelectObject(lhdc, + ExtCreatePen(penstyle, gcInfo[gc].lineAttributes.width, + &lb, 0, NULL)); + /* remove the old pen */ + DeleteObject(pen); + } + + /* set the palette to the new colors */ + palarray[0][0] = cred; /* red */ + palarray[0][1] = cgreen; /* green */ + palarray[0][2] = cblue; /* blue */ + + palarray[1][0] = red[gcInfo[gc].color.background]; /* red */ + palarray[1][1] = green[gcInfo[gc].color.background]; /* green */ + palarray[1][2] = blue[gcInfo[gc].color.background]; /* blue */ + + /* create logical palette header */ + lpLogPal = (LPLOGPALETTE)LocalAlloc(LPTR, + sizeof(LOGPALETTE) + (1 * sizeof(PALETTEENTRY))); + if (lpLogPal == NULL) + { + sprintf(message, "palette: Cannot alloacte memory for logical palette"); + xlockmore_set_debug(message); + return NULL; + } + + /* set logical palette info */ + lpLogPal->palVersion = 0x0300; + lpLogPal->palNumEntries = 2; + for (i=0; i < 2; i++) + { + lpLogPal->palPalEntry[i].peRed = palarray[i][0]; + lpLogPal->palPalEntry[i].peGreen = palarray[i][1]; + lpLogPal->palPalEntry[i].peBlue = palarray[i][2]; + } + + /* create palette */ + palette = CreatePalette(lpLogPal); + if (palette == NULL) + { + sprintf(message, "palette: CreatePalette() returned NULL"); + xlockmore_set_debug(message); + LocalFree(lpLogPal); + return NULL; + } + + /* set palette color */ + palette = SelectPalette(lhdc, palette, FALSE); + + /* clean up palette creation data */ + DeleteObject(palette); + LocalFree(lpLogPal); + + /* set brush origin */ + if (gcInfo[gc].tsorigin.hasOrigin == TRUE) + { + if (SetBrushOrgEx(lhdc, gcInfo[gc].tsorigin.x, + gcInfo[gc].tsorigin.y, NULL) == 0) + { + sprintf(message, "brush origin: SetBrushOrgEx() failed"); + xlockmore_set_debug(message); + return NULL; + } + } + + /* check if we need a pattern brush or solid brush */ + if (gcInfo[gc].stipple.hasStipple == FALSE || + (gcInfo[gc].fillStyle.hasFillStyle == TRUE && + gcInfo[gc].fillStyle.value == FillSolid)) + { + /* solid brush */ + brush = SelectObject(lhdc, + CreateSolidBrush(RGB(cred, cgreen, cblue))); + DeleteObject(brush); + } + /* check if we need to FillStippled, and if so don't make a + * brush, we will deal with this later (see XFillRectangle) + */ + else if (gcInfo[gc].stipple.graphic != -1 && + ! (gcInfo[gc].fillStyle.hasFillStyle == TRUE && + gcInfo[gc].fillStyle.value == FillStippled)) + { + /* pattern brush */ + HBRUSH oldBrush; + HBRUSH brush; + HDC hStippleDC; + HBITMAP hOldBitmap; + RGBQUAD rgbQuad = { cblue, cgreen, cred, 0 }; + + if ((stipple = DrawableGetBitmap(gcInfo[gc].stipple.graphic)) == NULL) + { + sprintf(message, "pattern brush: DrawableGetBitmap() returned NULL"); + xlockmore_set_debug(message); + return NULL; + } + + /* create a device context for setting the stipples color */ + if ((hStippleDC = CreateCompatibleDC(lhdc)) == NULL) + { + sprintf(message, "pattern brush: CreateCompatibleDC() returned NULL"); + xlockmore_set_debug(message); + return NULL; + } + + /* put the stipple into the DC */ + if ((hOldBitmap = (HBITMAP)SelectObject(hStippleDC, stipple)) == NULL) + { + sprintf(message, "pattern brush: cannot select stipple in stippleDC"); + xlockmore_set_debug(message); + DeleteDC(hStippleDC); + return NULL; + } + + /* set the correct color table */ + SetDIBColorTable(hStippleDC, 0, 1, &rgbQuad); + + /* get the stipple back from the DC with the correct color table */ + if ((stipple = (HBITMAP)SelectObject(hStippleDC, hOldBitmap)) == NULL) + { + sprintf(message, "pattern brush: cannot select stipple out of stippleDC"); + xlockmore_set_debug(message); + DeleteDC(hStippleDC); + return NULL; + } + + /* create a pattern brush out of it */ + if ((brush = CreatePatternBrush(stipple)) == NULL) + { + sprintf(message, "pattern brush: CreatePatternBrush() returned NULL"); + xlockmore_set_debug(message); + DeleteDC(hStippleDC); + return NULL; + } + + /* put the pattern brush into the DC */ + if ((oldBrush = SelectObject(lhdc, brush)) == NULL) + { + sprintf(message, "pattern brush: cannot select brush into DC"); + xlockmore_set_debug(message); + DeleteDC(hStippleDC); + return NULL; + } + + /* clean up and return */ + DeleteDC(hStippleDC); + DeleteObject(oldBrush); + } + + /* check if we need to set the fill function */ + if (gcInfo[gc].function.hasFunction == TRUE) + { + switch (gcInfo[gc].function.value) + { + case GXclear: fillfunc = R2_BLACK; break; + case GXand: fillfunc = R2_MERGEPEN; break; + case GXandReverse: fillfunc = R2_MERGEPENNOT; break; + case GXcopy: fillfunc = R2_COPYPEN; break; + case GXandInverted: fillfunc = R2_MERGENOTPEN; break; + case GXnoop: fillfunc = R2_NOP; break; + case GXxor: fillfunc = R2_XORPEN; break; + case GXor: fillfunc = R2_MASKPEN; break; + case GXnor: fillfunc = R2_NOTMERGEPEN; break; + case GXequiv: fillfunc = R2_NOTXORPEN; break; + case GXinvert: fillfunc = R2_NOT; break; + case GXorReverse: fillfunc = R2_MASKPENNOT; break; + case GXcopyInverted: fillfunc = R2_NOTCOPYPEN; break; + case GXorInverted: fillfunc = R2_MASKNOTPEN; break; + case GXnand: fillfunc = R2_NOTMASKPEN; break; + case GXset: fillfunc = R2_WHITE; break; + default: fillfunc = R2_COPYPEN; break; + } + + SetROP2(lhdc, fillfunc); + } + + /* set fill rule */ + if (gcInfo[gc].fillRule.hasFillRule == TRUE) + { + switch (gcInfo[gc].fillRule.value) + { + case EvenOddRule: fillrule = ALTERNATE; break; + case WindingRule: fillrule = WINDING; break; + default: fillrule = WINDING; break; + } + if (SetPolyFillMode(lhdc, fillrule) == 0) + { + sprintf(message, "fill rule: cannot set fill mode in DC"); + xlockmore_set_debug(message); + return NULL; + } + } + + /* + * if we call this function again and there is no change to the DC + * that needs to be done, we want to just return the DC that had + * already been set up. Set the information to allow this + */ + gcInfo[gc].needsReset = FALSE; + lastGc = gc; + + /* ignoring setting font for now */ + /* TODO: font */ + + /* return the DC */ + return lhdc; +} + + +/* the following functions to create, destroy, modify and access the + BM Info structure + */ +int BMInfoCreate(void) +{ + int retVal = 0; + HBITMAP hBitmap; + + /* start at 1, not 0 as this will be None */ + for (retVal=1; retVal<NUMBER_BITMAP; retVal++) + { + if (bmInfo[retVal].isActive == FALSE) + { + numBMInfo++; + break; + } + } + + if (retVal == NUMBER_BITMAP) + return -1; + + /* set the bitmap info */ + bmInfo[retVal].isActive = TRUE; + bmInfo[retVal].width = 0; + bmInfo[retVal].height = 0; + bmInfo[retVal].bitmap = NULL; + + return retVal; +} + +HBITMAP DrawableGetBitmap(Drawable d) +{ + char message[80]; + + if (d < 0 || d >= NUMBER_BITMAP) + { + sprintf(message, "Drawable passed in not in range 0..%d, d=%d", + numBMInfo-1, d); + xlockmore_set_debug(message); + return NULL; + } + + /* check for id of 0 */ + if (d == None) + { + sprintf(message, "Drawable is None"); + xlockmore_set_debug(message); + return NULL; + } + + if (bmInfo[d].isActive == FALSE) + { + sprintf(message, "Drawable not active, d=%d", d); + xlockmore_set_debug(message); + return NULL; + } + + return bmInfo[d].bitmap; +} + +/* -------------------------------------------------------------------- */ + +/* the following are functions in UNIX but not WIN32 */ + +/*- + * nice + */ +int nice(int level) +{ + return 1; +} + +/*- + * sleep + */ +void sleep(int sec) +{ +} + +/*- + * sigmask + */ +int sigmask(int signum) +{ + return 0; +} + + +/* the following are macros in X, but I have implemented as functions */ + +/*- + * BlackPixel + * returns the color cell of Black + * NOTE: this is currently set to the end of the color + * palette table, + */ +unsigned long BlackPixel(Display *display, int screen_number) +{ + return colorcount+1; +} + +/*- + * WhitePixel + * returns the color cell of White + * NOTE: this is currently set to the end of the color + * palette table - 1 + */ +unsigned long WhitePixel(Display *display, int screen_number) +{ + return colorcount; +} + +/*- + * BlackPixelOfScreen + * returns the color cell of Black + * NOTE: currently is fixed to color array + 2 + */ +int BlackPixelOfScreen(Screen *screen) +{ + return NUMCOLORS+1; +} + +/*- + * WhitePixelOfScreen + * returns the color cell of White + * NOTE: currently is fixed to color array + 1 + */ +int WhitePixelOfScreen(Screen *screen) +{ + return NUMCOLORS; +} + +/*- + * CellsOfScreen + * returns number of entries the colormap can hold + */ +int CellsOfScreen(Screen *screen) +{ + return colorcount; +} + +/*- + * DefaultColormap + * not currently used, returns 0 + */ +Colormap DefaultColormap(Display *display, int screen_number) +{ + return 0; +} + +/*- + * DefaultColormapOfScreen + * not currently used, returns 0 + */ +Colormap DefaultColormapOfScreen(Screen *screen) +{ + return 0; +} + +/*- + * DefaultVisual + * not currently used, returns NULL + */ +Visual *DefaultVisual(Display *display, int screen_number) +{ + return NULL; +} + +/*- + * DisplayPlanes + * not currently used, returns 0 + */ +int DisplayPlanes(Display *display, int screen_number) +{ + return 0; +} + +/*- + * DisplayString + * not currently used, returns NULL + */ +char *DisplayString(Display *display) +{ + return NULL; +} + +/*- + * RootWindow + * not currently used, returns 0 + */ +Window RootWindow(Display *display, int screen_number) +{ + return 0; +} + +/*- + * ScreenCount + * not correct, just return 1 + */ +int ScreenCount(Display *display) +{ + return 1; +} + +/*- + * ScreenOfDisplay + * not currently used, returns NULL + */ +Screen *ScreenOfDisplay(Display *display, int screen_number) +{ + return NULL; +} + +/* -------------------------------------------------------------------- */ + +/* X function mappings */ + +/*- + * XAddHosts + * not currently used + */ +void XAddHosts(Display *display, XHostAddress *hosts, int num_hosts) +{ +} + +/*- + * XAllocColor + * not currently used + */ +Status XAllocColor(Display *display, Colormap colormap, + XColor *screen_in_out) +{ + screen_in_out->pixel = 0; + return 1; +} + +/*- + * XAllocColorCells + * not currently used + */ +Status XAllocColorCells(Display *display, Colormap colormap, + Bool contig, unsigned long plane_masks_return[], + unsigned int nplanes, unsigned long pixels_return[], + unsigned int npixels) +{ + return 0; +} + +/*- + * XAllocNamedColor + * not currently used + */ +Status XAllocNamedColor(Display *display, Colormap colormap, + char *color_name, XColor *screen_def_return, + XColor *exact_def_return) +{ + return 0; +} + +/*- + * XBell + * not currently used + */ +void XBell(Display *display, int percent) +{ +} + +/*- + * XChangeGC + * changes values of the graphics context + */ +void XChangeGC(Display *display, GC gc, unsigned long valuemask, + XGCValues *values) +{ + if (valuemask & GCBackground) + { + XSetBackground(display, gc, values->background); + } + if (valuemask & GCFillRule) + { + XSetFillRule(display, gc, values->fill_rule); + } + if (valuemask & GCFillStyle) + { + XSetFillStyle(display, gc, values->fill_style); + } + if (valuemask & GCForeground) + { + XSetForeground(display, gc, values->foreground); + } + if (valuemask & GCFunction) + { + XSetFunction(display, gc, values->function); + } + if (valuemask & GCLineWidth) + { + XSetLineAttributes(display, gc, + values->line_width, + gcInfo[gc].lineAttributes.lineStyle, + gcInfo[gc].lineAttributes.capStyle, + gcInfo[gc].lineAttributes.joinStyle); + } + if (valuemask & GCLineStyle) + { + XSetLineAttributes(display, gc, + gcInfo[gc].lineAttributes.width, + values->line_style, + gcInfo[gc].lineAttributes.capStyle, + gcInfo[gc].lineAttributes.joinStyle); + } + if (valuemask & GCCapStyle) + { + XSetLineAttributes(display, gc, + gcInfo[gc].lineAttributes.width, + gcInfo[gc].lineAttributes.lineStyle, + values->cap_style, + gcInfo[gc].lineAttributes.joinStyle); + } + if (valuemask & GCJoinStyle) + { + XSetLineAttributes(display, gc, + gcInfo[gc].lineAttributes.width, + gcInfo[gc].lineAttributes.lineStyle, + gcInfo[gc].lineAttributes.capStyle, + values->join_style); + } + if (valuemask & GCStipple) + { + XSetStipple(display, gc, values->stipple); + } + if (valuemask & GCFont) + { + XSetFont(display, gc, values->font); + } + if (valuemask & GCTileStipXOrigin) + { + XSetTSOrigin(display, gc, values->ts_x_origin, gcInfo[gc].tsorigin.y); + } + if (valuemask & GCTileStipYOrigin) + { + XSetTSOrigin(display, gc, gcInfo[gc].tsorigin.x, values->ts_y_origin); + } + + /* the above are the only attributes we can set at this stage */ +} + + +/*- + * XCheckMaskEvent + * not currently used, return True + */ +Bool XCheckMaskEvent(Display *display, long event_mask, + XEvent *event_return) +{ + return True; +} + +/*- + * XClearArea + * clears a rectangular area in a window/screen + */ +void XClearArea(Display *display, Window w, int x, int y, + unsigned int width, unsigned int height, Bool exposures) +{ + RECT lrc; + + lrc.left = x; + lrc.top = y; + lrc.right = x + width; + lrc.bottom = y + height; + + FillRect(hdc, &lrc, (struct HBRUSH__ *)GetStockObject(BLACK_BRUSH)); +} + +/*- + * XClearWindow + * sets the base window/screen to black + */ +void XClearWindow(Display *display, Window w) +{ + FillRect(hdc, &rc, (struct HBRUSH__ *)GetStockObject(BLACK_BRUSH)); +} + +/*- + * XCloseDisplay + * not currently used + */ +void XCloseDisplay(Display *display) +{ +} + +/*- + * XConfigureWindow + * not currently used + */ +void XConfigureWindow(Display *display, Window w, + unsigned int value_mask, + XWindowChanges *values) +{ +} + +/*- + * XCopyArea + * copies one drawable to another + */ +int XCopyArea(Display *display, Drawable src, Drawable dest, GC gc, + int src_x, int src_y, unsigned int width, unsigned height, + int dest_x, int dest_y) +{ + HBITMAP hBitmap; + HBITMAP hOldBitmapS; + HBITMAP hOldBitmapD; + HDC hDestDC; + HDC hSrcDC; + + /* create the destination resource */ + if ((hDestDC = GCGetDC(dest, gc)) == NULL) + { + xlockmore_set_debug("XCopyArea: Failed to get destination DC"); + return BadGC; + } + + if (dest > 0 && dest < NUMBER_BITMAP) + if (bmInfo[dest].isActive == TRUE) + hOldBitmapD = SelectObject(hDestDC, DrawableGetBitmap(dest)); + + /* create the source resource */ + if (src > 0 && src <= numBMInfo) + { + /* source is a bitmap */ + if ((hBitmap = DrawableGetBitmap(src)) == NULL) + { + xlockmore_set_debug("XCopyArea: Failed to get bitmap"); + return BadDrawable; + } + + if ((hSrcDC = CreateCompatibleDC(hdc)) == NULL) + { + xlockmore_set_debug("XCopyArea: Failed to create compatible DC"); + return BadDrawable; + } + + hOldBitmapS = SelectObject(hSrcDC, hBitmap); + } + else + { + /* source is a window */ + if ((hSrcDC = GetDC((HWND)src)) == NULL) + { + xlockmore_set_debug("XCopyArea: Failed to get source DC"); + return BadDrawable; + } + } + + /* copy src to destination */ + if (BitBlt(hDestDC, dest_x, dest_y, width, height, hSrcDC, + src_x, src_y, SRCCOPY) == 0) + { + xlockmore_set_debug("XCopyArea: BitBlt() failed"); + } + + /* clean up */ + if (hOldBitmapS) + SelectObject(hSrcDC, hOldBitmapS); + if (hOldBitmapD) + SelectObject(hSrcDC, hOldBitmapD); + if (src > 0 && src <= numBMInfo) + DeleteDC(hSrcDC); + else + ReleaseDC((HWND)src, hSrcDC); + return Success; +} + +/*- + * XCopyColormapAndFree + * not currently used, returns 0 + */ +Colormap XCopyColormapAndFree(Display *display, Colormap colormap) +{ + return 0; +} + +/*- + * XCopyPlane + * to be implemented + */ +int XCopyPlane(Display *display, Drawable src, Drawable dest, GC gc, + int src_x, int src_y, unsigned width, int height, + int dest_x, int dest_y, unsigned long plane) +{ + return 0; +} + +/*- + * XCreateBitmapFromData + * used to create a bitmap + */ +Pixmap XCreateBitmapFromData(Display *display, Drawable drawable, + char *data, unsigned int width, + unsigned int height) +{ + XImage image; + HBITMAP hBitmap; + HPALETTE hPalette; + Pixmap pm; + + pm = BMInfoCreate(); + if (pm < 0 || pm >= NUMBER_BITMAP) + return None; + + image.width = width; + image.height = height; + image.data = data; + + LCreateBitmap(&image, &hBitmap, &hPalette); + DeleteObject(hPalette); /* we don't need the palette */ + + if (hBitmap == NULL) + { + bmInfo[pm].isActive = FALSE; + return None; + } + + bmInfo[pm].bitmap = hBitmap; + bmInfo[pm].type = 1; + bmInfo[pm].width = width; + bmInfo[pm].height = height; + return pm; +} + +/*- + * XCreateColormap + * used to create the colormap + */ +Colormap XCreateColormap(Display *display, Window w, + Visual *visual, int alloc) +{ + return None; +} + +/*- + * XCreateFontCursor + * not currently used, returns 0 + */ +Cursor XCreateFontCursor(Display *display, unsigned int shape) +{ + return 0; +} + +/*- + * XCreateGC + * creates a copy of the GC + */ +GC XCreateGC(Display *display, Drawable drawable, + unsigned long valuemask, XGCValues *values) +{ + GC newGc; + char message[80]; + + if ((newGc = GCCreate()) == -1) + { + sprintf(message, "Failed to create a GC"); + xlockmore_set_debug(message); + } + else + { + /* check if drawable is a bitmap, and adjust the 1 and 0 colors + (white and black) to their proper win32 values */ + if (drawable > 0 && drawable < NUMBER_BITMAP) + if (bmInfo[drawable].isActive == TRUE && bmInfo[drawable].type == 1) + { + if (valuemask & GCBackground) + if (values->background == 0 || values->background == 1) + values->background = 256 + values->background; + if (valuemask & GCForeground) + if (values->foreground == 0 || values->foreground == 1) + values->foreground = 256 + values->foreground; + } + XChangeGC(display, newGc, valuemask, values); + } + + return newGc; +} + +/*- + * XCreateImage + * creates an XImage structure and populates it + */ +XImage *XCreateImage(Display *display, Visual *visual, + unsigned int depth, int format, int offset, + char *data, unsigned int width, + unsigned int height, int bitmap_pad, + int bytes_per_line) +{ + XImage *newImage; + + if ((newImage = malloc(sizeof(XImage))) == NULL) + return NULL; + + memset(newImage, 0, sizeof(XImage)); + + newImage->width = width; + newImage->height = height; + newImage->xoffset = offset; + newImage->format = format; + newImage->data = data; + newImage->bitmap_pad = bitmap_pad; + newImage->depth = depth; + newImage->bytes_per_line = (bytes_per_line != 0) ? bytes_per_line : (width + 7) / 8; + + return newImage; +} + +/*- + * XCreatePixmap + * creates a pixmap + */ +Pixmap XCreatePixmap(Display *display, Drawable d, unsigned int width, + unsigned int height, unsigned int depth) +{ + Pixmap pm; + HBITMAP hBitmap; + + pm = BMInfoCreate(); + if (pm < 0 || pm >= NUMBER_BITMAP) + return None; + + /* create the bitmap */ + if ((hBitmap = + (depth == 1) ? CreateBitmap(width, height, depth, 1, NULL) : + CreateCompatibleBitmap(hdc, width, height)) == NULL) + { + bmInfo[pm].isActive = FALSE; + return None; + } + + bmInfo[pm].bitmap = hBitmap; + bmInfo[pm].type = depth; + bmInfo[pm].width = width; + bmInfo[pm].height = height; + + return pm; +} + +/*- + * XCreatePixmapCursor + * not currently used, returns 0 + */ +Cursor XCreatePixmapCursor(Display *display, + Pixmap source, Pixmap mask, + XColor *foreground_color, XColor *background_color, + unsigned int x_hot, unsigned int y_hot) +{ + return None; +} + +/*- + * XCreatePixmapFromBitmapData + * Creates a pixmap from bitmap data + */ +Pixmap XCreatePixmapFromBitmapData(Display *display, Drawable drawable, + char *data, unsigned int width, unsigned int height, + unsigned long fg, unsigned long bg, unsigned int depth) +{ + HDC hBitmapDC; + HBITMAP hOldBitmap; + Pixmap pm; + RGBQUAD rgbQuad[2] = { 0 }; + + /* create the bitmap */ + if ((pm = XCreateBitmapFromData(display, drawable, data, width, height)) == None) + { + return None; + } + + /* if depth is 1 create the bitmap using black and white */ + if (depth == 1) + { + fg = 257; + bg = 256; + } + + /* set the correct colors in the color table */ + rgbQuad[0].rgbRed = red[fg]; + rgbQuad[0].rgbGreen = green[fg]; + rgbQuad[0].rgbBlue = blue[fg]; + rgbQuad[0].rgbReserved = 0; + rgbQuad[1].rgbRed = red[bg]; + rgbQuad[1].rgbGreen = green[bg]; + rgbQuad[1].rgbBlue = blue[bg]; + rgbQuad[1].rgbReserved = 0; + + /* create a DC so we can set the bitmaps colortable */ + hBitmapDC = CreateCompatibleDC(hdc); + hOldBitmap = SelectObject(hBitmapDC, DrawableGetBitmap(pm)); + + /* set the colortable */ + SetDIBColorTable(hBitmapDC, 0, 2, rgbQuad); + + /* clean up */ + SelectObject(hBitmapDC, hOldBitmap); + DeleteDC(hBitmapDC); + + return pm; +} + +/* + * XDefineCursor + * not currently used + */ +void XDefineCursor(Display *display, Window window, Cursor cursor) +{ +} + +/*- + * XDestroyImage + * not currently used + */ +void XDestroyImage(XImage *ximage) +{ +} + +/*- + * XDisableAccessControl + * not currently used + */ +void XDisableAccessControl(Display *display) +{ +} + +/*- + * XDrawArc + * draws an arc + */ +void XDrawArc(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height, + int angle1, int angle2) +{ + int xa1, ya1; + int xa2, ya2; + int cx, cy; + double a1, a2; + double rx, ry; + double ang_inc = M_PI * 2.0 / 23040.0; + HDC dc; + HBITMAP hOldBitmap = NULL; + + rx = width/2.0; + ry = height/2.0; + cx = x + width/2; + cy = y + height/2; + + a1 = (23040 - (angle1 % 23040)) * ang_inc; + + xa1 = (int)((rx * cos(a1)) + cx); + ya1 = (int)((ry * sin(a1)) + cy); + + if (angle2 == 0) { + /* Special case - In X this is a point but Arc in Windows would + do a complete elipse! Draw a (thick) line instead. */ + + XDrawLine(display, d, gc, xa1, ya1, xa1, ya1); + + } else { + + a2 = (23040 - ((angle1 + angle2) % 23040)) * ang_inc; + + xa2 = (int)((rx * cos(a2)) + cx); + ya2 = (int)((ry * sin(a2)) + cy); + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + Arc(dc, x, y, x + width, y + height, xa1, ya1, xa2, ya2); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); + } +} + +/*- + * XDrawImageString + * not currently used + */ +void XDrawImageString(Display *display, Drawable d, GC gc, + int x, int y, char *string, int length) +{ +} + +/*- + * XDrawLine + * draws a line on the screen in the current pen color + */ +void XDrawLine(Display *display, Drawable d, GC gc, + int x1, int y1, int x2, int y2) +{ + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + MoveToEx(dc, x1, y1, NULL); + LineTo(dc, x2, y2); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XDrawLines + * draws a series of lines on the screen. Liness may be + * specified as being (1) relative to the origin, or + * (2) relative to the previous line (with the first line + * relative to the origin). + */ +void XDrawLines(Display *display, Drawable d, GC gc, + XPoint *points, int npoints, int mode) +{ + int i; + int tx, ty; + HDC dc; + HBITMAP hOldBitmap = NULL; + POINT *lppt; + BYTE *lpbTypes; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + if (npoints > 1) { + lppt = (POINT*)malloc(npoints * sizeof(POINT)); + lpbTypes = (BYTE*)malloc(npoints * sizeof(BYTE)); + + lpbTypes[0] = PT_MOVETO; + lppt[0].x = points[0].x; + lppt[0].y = points[0].y; + + if (mode == CoordModeOrigin) { + for (i=1; i<npoints; i++) { + lpbTypes[i] = PT_LINETO; + lppt[i].x = points[i].x; + lppt[i].y = points[i].y; + } + } else if (mode == CoordModePrevious) { + tx = points[0].x; + ty = points[0].y; + for (i=1; i<npoints; i++) { + tx += points[i].x; + ty += points[i].y; + lpbTypes[i] = PT_LINETO; + lppt[i].x = tx; + lppt[i].y = ty; + } + } + PolyDraw(dc, lppt, lpbTypes, npoints); + free(lppt); + free(lpbTypes); + } + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XDrawPoint + * draws a point on the screen + */ +void XDrawPoint(Display *display, Drawable d, GC gc, int x, int y) +{ + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + SetPixelV(dc, x, y, RGB(cred, cgreen, cblue)); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XDrawPoints + * draws a series of points on the screen. Points may be + * specified as being (1) relative to the origin, or + * (2) relative to the previous point (with the first point + * relative to the origin). + */ +void XDrawPoints(Display *display, Drawable d, GC gc, + XPoint *pts, int numpts, int mode) +{ + int i; + int tx, ty; + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + if (mode == CoordModeOrigin) + { + for (i=0; i<numpts; i++) + { + SetPixelV(dc, pts[i].x, pts[i].y, RGB(cred, cgreen, cblue)); + } + } + else if (mode == CoordModePrevious) + { + if (numpts > 0) + { + tx = pts[0].x; + ty = pts[0].y; + SetPixelV(dc, tx, ty, RGB(cred, cgreen, cblue)); + for (i=1; i<numpts; i++) + { + tx += pts[i].x; + ty += pts[i].y; + SetPixelV(dc, tx, ty, RGB(cred, cgreen, cblue)); + } + } + } + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XDrawRectangle + * Draws an outline of a rectangle. + * Uses PolyDraw as Rectangle fills rectangle with brush + */ +void XDrawRectangle(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height) +{ + BYTE lpbTypes[6]; + POINT lppt[6]; + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + lpbTypes[0] = PT_MOVETO; + lppt[0].x = x, lppt[0].y = y; + lpbTypes[1] = PT_LINETO; + lppt[1].x = x + width, lppt[1].y = y; + lpbTypes[2] = PT_LINETO; + lppt[2].x = x + width, lppt[2].y = y + height; + lpbTypes[3] = PT_LINETO; + lppt[3].x = x, lppt[3].y = y + height; + lpbTypes[4] = PT_LINETO; + lppt[4].x = x, lppt[4].y = y; + /* overkill but need better closure */ + lpbTypes[5] = PT_LINETO; + lppt[5].x = x + width, lppt[5].y = y; + PolyDraw(dc, lppt, lpbTypes, 6); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XDrawSegments + * draws multiple disjoint lines. Lines do not have to be + * connected as each segment is one line. + */ +void XDrawSegments(Display *display, Drawable d, GC gc, + XSegment *segs, int numsegs) +{ + int i; + HDC dc; + HBITMAP hOldBitmap = NULL; + POINT *lppt; + BYTE *lpbTypes; + int cCount = 0; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + lppt = (POINT*)malloc(numsegs * 2 * sizeof(POINT)); + lpbTypes = (BYTE*)malloc(numsegs * 2 * sizeof(BYTE)); + + for (i=0; i<numsegs; i++) { + lpbTypes[cCount] = PT_MOVETO; + lppt[cCount].x = segs[i].x1; + lppt[cCount].y = segs[i].y1; + cCount++; + lpbTypes[cCount] = PT_LINETO; + lppt[cCount].x = segs[i].x2; + lppt[cCount].y = segs[i].y2; + cCount++; + } + + PolyDraw(dc, lppt, lpbTypes, cCount); + + free(lppt); + free(lpbTypes); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XDrawString + * Draws a string of characters at specified location + */ +void XDrawString(Display *display, Drawable d, GC gc, int x, int y, + char *string, int length) +{ + int prevMode; + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + prevMode = GetBkMode(dc); + SetBkMode(dc, TRANSPARENT); + TextOut(dc, x + 3, y - 15, string, length); + SetBkMode(dc, prevMode); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XEnableAccessControl + * not currently used + */ +void XEnableAccessControl(Display *display) +{ +} + +/*- + * XFillArc + * draws a filled arc on screen + */ +void XFillArc(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height, + int angle1, int angle2) +{ + int xa1, ya1; + int xa2, ya2; + int cx, cy; + double a1, a2; + double rx, ry; + double ang_inc = M_PI * 2.0 / 23040.0; + HPEN oldPen; + HDC dc; + HBITMAP hOldBitmap = NULL; + + /* set the size of the arc a little larger because + we won't be drawing a border around it */ + width++; + height++; + + rx = width/2.0; + ry = height/2.0; + cx = x + width/2; + cy = y + height/2; + + a1 = (23040 - (angle1 % 23040)) * ang_inc; + + xa1 = (int)((rx * cos(a1)) + cx); + ya1 = (int)((ry * sin(a1)) + cy); + + if (angle2 == 0) { + /* Special case - In X this is a point but Arc in Windows would + do a complete elipse! Draw a (thick) line instead. */ + + XDrawLine(display, d, gc, cx, cy, xa1, ya1); + + } else { + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + a2 = (23040 - ((angle1 + angle2) % 23040)) * ang_inc; + + xa2 = (int)((rx * cos(a2)) + cx); + ya2 = (int)((ry * sin(a2)) + cy); + + /* set the pen draw width to 1, and because its null it won't + use it, hence the reason we made the arc larger before */ + if (noPen == NULL) + if ((noPen = CreatePen(PS_NULL, 0, RGB(0,0,0))) == NULL) + { + xlockmore_set_debug("Failed to create pen"); + return; + } + oldPen = SelectObject(dc, noPen); + + /* should check for a pie or chord filled arc type, but + currently assuming pie filled arc */ + Pie(dc, x, y, x + width, y + height, xa1, ya1, xa2, ya2); + + /* reset back and clean up */ + SelectObject(dc, oldPen); + if (hOldBitmap) + SelectObject(dc, hOldBitmap); + } +} + +/*- + * XFillArcs + * draws a number of filled arcs on screen + */ +void XFillArcs(Display *display, Drawable d, GC gc, + XArc *arcs, int narcs) +{ + int i; + int xa1, ya1; + int xa2, ya2; + int cx, cy; + double a1, a2; + double rx, ry; + const double ang_inc = M_PI * 2.0 / 23040.0; + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + for (i=0; i<narcs; i++) { + rx = arcs[i].width/2.0; + ry = arcs[i].height/2.0; + cx = arcs[i].x + arcs[i].width/2; + cy = arcs[i].y + arcs[i].height/2; + + a1 = (23040 - (arcs[i].angle1 % 23040)) * ang_inc; + + xa1 = (int)((rx * cos(a1)) + cx); + ya1 = (int)((ry * sin(a1)) + cy); + + if (arcs[i].angle2 == 0) { + /* Special case - In X this is a point but Arc in Windows would + do a complete elipse! Draw a (thick) line instead. */ + + XDrawLine(display, d, gc, cx, cy, xa1, ya1); + + } else { + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + a2 = (23040 - ((arcs[i].angle1 + arcs[i].angle2) % 23040)) * ang_inc; + xa2 = (int)((rx * cos(a2)) + cx); + ya2 = (int)((ry * sin(a2)) + cy); + + /* should check for a pie or chord filled arc type, but + currently assuming pie filled arc */ + Pie(dc, arcs[i].x, arcs[i].y, arcs[i].x + arcs[i].width, + arcs[i].y + arcs[i].height, xa1, ya1, xa2, ya2); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); + } + } +} + + +/*- + * XFillPolygon + * draws a filled polygon on screen. Points can be specified as + * being relative to the origin, or relative to the previous + * point (with the first point relative to the origin) + */ +void XFillPolygon(Display *display, Drawable d, GC gc, XPoint *points, + int npoints, int shape, int mode) +{ + int i; + int tx, ty; + POINT *pts; + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (npoints <= 0) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + /* allocate memory */ + pts = calloc(npoints, sizeof(POINT)); + + if (mode == CoordModeOrigin) { + for (i=0; i<npoints; i++) { + pts[i].x = points[i].x; + pts[i].y = points[i].y; + } + } + else if (mode == CoordModePrevious) { + tx = pts[0].x = points[0].x; + ty = pts[0].y = points[0].y; + for (i=1; i<npoints; i++){ + tx += points[i].x; + ty += points[i].y; + pts[i].x = tx; + pts[i].y = ty; + } + } + + Polygon(dc, pts, npoints); + + /* free memory */ + free(pts); + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XFillRectangle + * draws a filled rectangle on screen + */ +void XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height) +{ + HPEN oldPen; + HDC dc; + HBITMAP hOldBitmap = NULL; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + if (d > 0 && d < NUMBER_BITMAP) + if (bmInfo[d].isActive == TRUE) + hOldBitmap = SelectObject(dc, DrawableGetBitmap(d)); + + /* check if we are doing a FillStippled fill or a normal rectangle */ + if (gcInfo[gc].fillStyle.hasFillStyle == TRUE && + gcInfo[gc].fillStyle.value == FillStippled) + { + HBITMAP hOldBitmapS = NULL; + HBITMAP hStipple = NULL; + HDC hStippleDC; + int i, j; + RGBQUAD rgbQuad = { cblue, cgreen, cred, 0 }; + int sHeight; + int sWidth; + + /* FillStippled fill */ + if ((hStipple = DrawableGetBitmap(gcInfo[gc].stipple.graphic)) == NULL) + { + xlockmore_set_debug("XFillRectangle: Failed to get stipple"); + if (hOldBitmap) + SelectObject(dc, hOldBitmap); + return; + } + sWidth = bmInfo[gcInfo[gc].stipple.graphic].width; + sHeight = bmInfo[gcInfo[gc].stipple.graphic].height; + if ((hStippleDC = CreateCompatibleDC(hdc)) == NULL) + { + xlockmore_set_debug("XFillRectangle: Failed to create stipple DC"); + if (hOldBitmap) + SelectObject(dc, hOldBitmap); + return; + } + hOldBitmapS = SelectObject(hStippleDC, hStipple); + + /* set the correct color table */ + SetDIBColorTable(hStippleDC, 0, 1, &rgbQuad); + + for (i=y; i<y+height; i+=sHeight) + for (j=x; j<x+width; j+=sWidth) + if (MaskBlt(dc, j, i, sWidth, sHeight, hStippleDC, 0, 0, hStipple, 0, 0, + MAKEROP4(0x00AA0029, SRCCOPY)) == 0) + xlockmore_set_debug("XFillRectangle: MaskBlt() failed"); + + /* clean up */ + if (hOldBitmapS) + SelectObject(hStippleDC, hOldBitmapS); + DeleteDC(hStippleDC); + } + else + { + /* normal rectangle */ + if (width == 1 && height == 1) + { + SetPixelV(dc, x, y, RGB(cred, cgreen, cblue)); + } + else + { + if (noPen == NULL) + if ((noPen = CreatePen(PS_NULL, 0, RGB(0,0,0))) == NULL) + { + xlockmore_set_debug("XFillRectangle: Failed to create pen"); + if (hOldBitmap) + SelectObject(dc, hOldBitmap); + return; + } + + oldPen = SelectObject(dc, noPen); + Rectangle(dc, x, y, x + width + 1, y + height + 1); + SelectObject(dc, oldPen); + } + } + + if (hOldBitmap) + SelectObject(dc, hOldBitmap); +} + +/*- + * XFillRectangles + * draws a number of filled rectangles on screen + */ +void XFillRectangles(Display *display, Drawable d, GC gc, + XRectangle *rectangles, int nrectangles) +{ + int i; + + for (i=0; i<nrectangles; i++) { + XFillRectangle(display, d, gc, rectangles[i].x, rectangles[i].y, + rectangles[i].width, rectangles[i].height); + } +} + +/*- + * XFlush + * not currently used + */ +void XFlush(Display *display) +{ +} + +/*- + * XFree + * not currently used + */ +void XFree(void *data) +{ +} + +/*- + * XFreeColormap + * not currently used + */ +void XFreeColormap(Display *display, Colormap colormap) +{ +} + +/*- + * XFreeColors + * not currently used + */ +void XFreeColors(Display *display, Colormap colormap, + unsigned long pixels[], int npixels, + unsigned long planes) +{ +} + +/*- + * XFreeCursor + * not currently used + */ +void XFreeCursor(Display *display, Cursor cursor) +{ +} + +/*- + * XFreeFont + * not currently used + */ +int XFreeFont(Display *display, XFontStruct *font_struct) +{ + return 0; +} + +/*- + * XFreeFontInfo + * not currently used + */ +int XFreeFontInfo(char** names, XFontStruct* free_info, int actual_count) +{ + return 0; +} + +/*- + * XFreeGC + * Free the memory for a GC (HDC) + */ +void XFreeGC(Display *display, GC gc) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + gcInfo[gc].isActive = FALSE; +} + +/*- + * XFreePixmap + * Free the memory allocated to a pixmap + */ +void XFreePixmap(Display *display, Pixmap pixmap) +{ + if (pixmap < 0 || pixmap >= NUMBER_BITMAP) + return; + + if (bmInfo[pixmap].isActive == FALSE) + return; + + if (bmInfo[pixmap].bitmap != NULL) + { + DeleteObject(bmInfo[pixmap].bitmap); + bmInfo[pixmap].isActive = FALSE; + bmInfo[pixmap].bitmap = NULL; + bmInfo[pixmap].width = 0; + bmInfo[pixmap].height = 0; + } +} + +/*- + * XGetGCValues + * not currently used + */ +Status XGetGCValues(Display* display, GC gc, + unsigned long valuemask, XGCValues* values_return) +{ + return None; +} + +/*- + * XGContextFromGC + * not currently used + */ +GContext XGContextFromGC(GC gc) +{ + return None; +} +/*- + * XGetVisualInfo + * not currently used + */ +XVisualInfo *XGetVisualInfo(Display *display, long vinfo_mask, + XVisualInfo *vinfo_template, + int *nitems_return) +{ + return NULL; +} + +/*- + * XGetWindowAttributes + * retrieves info about the window + */ +Status XGetWindowAttributes(Display *display, Window w, + XWindowAttributes *window_attr_return) +{ + memset(window_attr_return, 0, sizeof(XWindowAttributes)); + + window_attr_return->width = rc.right; + window_attr_return->height = rc.bottom; + window_attr_return->depth = 8; /* incorrect, but we'll set it to 8 */ + window_attr_return->root = (int)hwnd; + + return 0; +} + +/*- + * XGrabKeyboard + * not currently used + */ +int XGrabKeyboard(Display *display, Window grab_window, + Bool owner_events, int pointer_mode, + int keyboard_mode, Time time) +{ + return 0; +} + +/*- + * XGrabPointer + * not currently used + */ +int XGrabPointer(Display *display, Window grab_window, Bool owner_events, + unsigned int event_mask, int pointer_mode, + int keyboard_mode, Window confine_to, Cursor cursor, + Time time) +{ + return 0; +} + +/*- + * XGrabServer + * not currently used + */ +void XGrabServer(Display *display) +{ +} + +/*- + * XInstallColormap + * not currently used + */ +void XInstallColormap(Display *display, Colormap colormap) +{ +} + +/*- + * XListHosts + * not currently used, returns NULL + */ +XHostAddress *XListHosts(Display *display, int *nhosts_return, + Bool *state_return) +{ + return NULL; +} + +/*- + * XLoadQueryFont + * not currently used + */ +XFontStruct *XLoadQueryFont(Display *display, char *name) +{ + static XFontStruct fontStruct = { 0 }; + return &fontStruct; +} + +/*- + * XLookupString + * not currently used + */ +int XLookupString(XKeyEvent *event_struct, char *buffer_return, + int bytes_buffer, KeySym *keysym_return, + XComposeStatus *status_in_out) +{ + return 0; +} + +/*- + * XMapWindow + * not currently used + */ +void XMapWindow(Display *display, Window w) +{ +} + +/*- + * XNextEvent + * not currently used + */ +void XNextEvent(Display *display, XEvent *event_return) +{ +} + +/*- + * XOpenDisplay + * not currently used + */ +Display *XOpenDisplay(char *display_name) +{ + return NULL; +} + +/*- + * XParseColor + * not currently used + */ +Status XParseColor(Display *display, Colormap colormap, + char *spec, XColor *exact_def_return) +{ + return 0; +} + +/*- + * XPending + * not currently used, return 0 + */ +int XPending(Display *display) +{ + return 0; +} + +/*- + * XPutBackEvent + * not currently used + */ +void XPutBackEvent(Display *display, XEvent *event) +{ +} + +/*- + * XPutImage + * Draw an image in screen + */ +void XPutImage(Display *display, Drawable d, GC gc, XImage *image, int src_x, + int src_y, int dest_x, int dest_y, unsigned int width, + unsigned int height) +{ + HDC hBitmapDC; + HBITMAP hOldBitmap; + HBITMAP hBitmap; + HPALETTE hPalette; + RGBQUAD rgbQuad = { 0, 0, 0, 0 }; + HDC dc; + + if ((dc = GCGetDC(d, gc)) == NULL) + return; + + /* set the color table for the bitmap */ + rgbQuad.rgbRed = cred; + rgbQuad.rgbGreen = cgreen; + rgbQuad.rgbBlue = cblue; + + if (image->format == XYBitmap) + { + if (image->depth != 1) + return; + + if ((hBitmapDC = CreateCompatibleDC(dc)) == NULL) + return; + + LCreateBitmap(image, &hBitmap, &hPalette); + DeleteObject(hPalette); /* we don't need the palette */ + if (hBitmap == NULL) + { + DeleteObject(hBitmap); + DeleteDC(hBitmapDC); + return; + } + + if ((hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, hBitmap)) == NULL) + { + DeleteObject(hBitmap); + DeleteDC(hBitmapDC); + return; + } + + /* set the correct color table */ + SetDIBColorTable(hBitmapDC, 0, 1, &rgbQuad); + + BitBlt(dc, dest_x, dest_y, width, height, hBitmapDC, + src_x, src_y, SRCCOPY); + + SelectObject(hBitmapDC, hOldBitmap); + DeleteObject(hBitmap); + DeleteDC(hBitmapDC); + } +} + +/*- + * XPutPixel + * Set a pixels color value on an image + * + * NOTE: I'm not sure what this function returns. The header files + * under cygwin says it should return int, but some references out + * on the web indicate void. I've used int, and it returns 0 if + * it fails, otherwise 1 + */ +int XPutPixel(XImage *ximage, int x, int y, unsigned long pixel) +{ + int pos = 0; + unsigned long val = 0; + + /* check ximage points to an image */ + if (ximage == NULL) + { + return 0; + } + + /* check x & y are within range */ + if ((x < 0 || x > ximage->width - 1) || + (y < 0 || y > ximage->height - 1)) + { + return 0; + } + + /* only support images of bit depth 1 or > 8 */ + if (ximage->depth == 1) + { + int byte_pos = 0; + int oldval = 0; + int i = 0; + + pos = (ximage->bytes_per_line * y) + (x / 8); + byte_pos = x % 8; + oldval = ximage->data[pos]; + for (i=0; i<8; i++) + { + val <<= 1; + val = (val & 0xFE) + ((byte_pos != i) ? oldval >> i : pixel) & 0x01; + } + } + else + { + pos = (ximage->width * y) + x; + val = pixel; + } + + ximage->data[pos] = val; + + return 1; +} + +/*- + * XQueryColor + * not currently used + */ +void XQueryColor(Display *display, Colormap colormap, XColor *def_in_out) +{ +} + +/*- + * XQueryFont + * not currently used + */ +XFontStruct *XQueryFont(Display* display, XID font_ID) +{ + static XFontStruct dummy; + return &dummy; +} + +/*- + * XQueryPointer + * not currently used + */ +Bool XQueryPointer(Display *display, Window w, Window *root_return, + Window *child_return, int *root_x_return, int *root_y_return, + int *win_x_return, int *win_y_return, + unsigned int *mask_return) +{ + return FALSE; +} + +/*- + * XQueryTree + * not currently used + */ +Status XQueryTree(Display *display, Window w, Window *root_return, + Window *parent_return, Window **children_return, + unsigned int *nchildren_return) +{ + return 0; +} + +/*- + * XRaiseWindow + * not currently used + */ +void XRaiseWindow(Display *display, Window w) +{ +} + +/*- + * XReadBitmapFile + * not currently used + */ +int XReadBitmapFile(Display *display, Drawable d, char *filename, + unsigned int *width_return, unsigned int *height_return, + Pixmap *bitmap_return, int *x_hot_return, int *y_hot_return) +{ + char *data; + unsigned int height; + int rv; + unsigned int width; + + /* TODO: implement me */ + return BitmapOpenFailed; + + /* read the file into data structure */ + + /* create the bitmap */ + if ((*bitmap_return = XCreateBitmapFromData(display, d, data, width, height)) != None) + { + *width_return = width; + *height_return = height; + /* TODO:: hot spot */ + *x_hot_return = -1; + *y_hot_return = -1; + rv = BitmapSuccess; + } + else + rv = BitmapFileInvalid; + + return rv; +} + +/*- + * XRemoveHosts + * not currently used + */ +void XRemoveHosts(Display *display, XHostAddress *hosts, int num_hosts) +{ +} + +/*- + * XResourceManagerString + * not currently used, return NULL + */ +char *XResourceManagerString(Display *display) +{ + return NULL; +} + +/*- + * XrmDestroyDatabase + * not currently used + */ +void XrmDestroyDatabase(XrmDatabase database) +{ +} + +/*- + * XrmGetFileDatabase + * not currently used, return NULL + */ +XrmDatabase XrmGetFileDatabase(char *filename) +{ + return NULL; +} + +/*- + * XrmGetResource + * not currently used, return True + */ +Bool XrmGetResource(XrmDatabase database, char *str_name, + char *str_class, char **str_type_return, + XrmValue *value_return) +{ + return True; +} + +/*- + * XrmGetFileDatabase + * not currently used, return NULL + */ +XrmDatabase XrmGetStringDatabase(char *data) +{ + return NULL; +} + +/*- + * XrmInitialize + * not currently used + */ +void XrmInitialize(void) +{ +} + +/*- + * XrmMergeDatabases + * not currently used + */ +void XrmMergeDatabases(XrmDatabase source_db, XrmDatabase *target_db) +{ +} + +/*- + * XrmParseCommand + * not currently used + */ +void XrmParseCommand(XrmDatabase *database, XrmOptionDescList table, + int table_count, char *name, int *argc_in_out, + char **argv_in_out) +{ +} + +/*- + * XSetBackground + * sets the background color of pens, shapes, etc + */ +void XSetBackground(Display *display, GC gc, unsigned long background) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + /* check that the background is in range */ + if (background > (NUMCOLORS+1)) + gcInfo[gc].color.background = NUMCOLORS-1; + else + gcInfo[gc].color.background = background; + } +} + +/*- + * XSetFillRule + * sets the fill rule + */ +void XSetFillRule(Display *display, GC gc, int fill_rule) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].fillRule.hasFillRule = TRUE; + gcInfo[gc].fillRule.value = fill_rule; + } +} + +/*- + * XSetFillStyle + * sets the fill style + */ +void XSetFillStyle(Display *display, GC gc, int fill_style) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].fillStyle.hasFillStyle = TRUE; + gcInfo[gc].fillStyle.value = fill_style; + } +} + +/*- + * XSetFont + * sets the font to be used for text + */ +void XSetFont(Display *display, GC gc, Font font) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].font.hasFont = TRUE; + gcInfo[gc].font.value = font; + } +} + +/*- + * XSetForeground + * sets the color of the current color, forground pen and + * brush + */ +void XSetForeground(Display *display, GC gc, unsigned long foreground) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + /* check that the foreground is in range */ + if (foreground > (NUMCOLORS+1)) + gcInfo[gc].color.foreground = NUMCOLORS-1; + else + gcInfo[gc].color.foreground = foreground; + } +} + +/*- + * XSetFunction + * sets the logical operation applied between source pixel + * and destination pixel + * Not fully implemented yet. + */ + +void XSetFunction(Display *display, GC gc, int function) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].function.hasFunction = TRUE; + gcInfo[gc].function.value = function; + } +} + +/*- + * XSetGraphicsExposures + * Not implemented yet. + */ + +int XSetGraphicsExposures(Display *display, GC gc, Bool graphics_exposures) +{ + return 0; +} + +/*- + * XSetLineAttributes + * creates a new pen that has the attributes given + */ +void XSetLineAttributes(Display *display, GC gc, + unsigned int line_width, int line_style, + int cap_style, int join_style) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].lineAttributes.hasLineAttributes = TRUE; + gcInfo[gc].lineAttributes.width = line_width; + gcInfo[gc].lineAttributes.lineStyle = line_style; + gcInfo[gc].lineAttributes.capStyle = cap_style; + gcInfo[gc].lineAttributes.joinStyle = join_style; + } +} + +/*- + * XSetScreenSaver + * not currently used + */ +void XSetScreenSaver(Display *display, int timeout, int interval, + int prefer_blanking, int allow_exposures) +{ +} + +/*- + * XSetStipple + * Set the stipple for filled objects + */ +void XSetStipple(Display *display, GC gc, Pixmap stipple) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].stipple.hasStipple = TRUE; + gcInfo[gc].stipple.graphic = stipple; + } +} + +/*- + * XSetTSOrigin + * Set the tile or stipple origin + */ +void XSetTSOrigin(Display *display, GC gc, int ts_x_origin, int ts_y_origin) +{ + if (gc >= 0 && gc < numGCInfo && gcInfo[gc].isActive == TRUE) + { + gcInfo[gc].needsReset = TRUE; + gcInfo[gc].tsorigin.hasOrigin = TRUE; + gcInfo[gc].tsorigin.x = ts_x_origin; + gcInfo[gc].tsorigin.y = ts_y_origin; + } +} + +/*- + * XSetWindowColormap + * not currently used + */ +void XSetWindowColormap(Display *display, Window w, Colormap colormap) +{ +} + +/*- + * XSetWMName + * not currently used + */ +void XSetWMName(Display *display, Window w, XTextProperty *text_prop) +{ +} + +/*- + * XStoreColors + * not currently used + */ +void XStoreColors(Display *display, Colormap colormap, XColor color[], + int ncolors) +{ +} + +/*- + * XStringListToTextProperty + * not currently used + */ +Status XStringListToTextProperty(char **list, int count, + XTextProperty *text_prop_return) +{ + return 0; +} + +/*- + * XSync + * not currently used + */ +void XSync(Display *display, Bool discard) +{ +} + +/*- + * XTextWidth + * not currently used, returns 0 + */ +int XTextWidth(XFontStruct *font_struct, char *string, int count) +{ + return 0; +} + +/*- + * XTranslateCoordinates + * Simple implementation ignores source and destination and just + * reports position of global hdc relative to the screen. + */ +Bool XTranslateCoordinates(Display* display, Window src_w, Window dest_w, + int src_x, int src_y, + int* dest_x_return, int* dest_y_return, + Window* child_return) +{ + POINT p; + /* use global hdc */ + if (GetDCOrgEx(hdc, &p)) { + *dest_x_return = p.x + src_x; + *dest_y_return = p.y + src_y; + + } else { + *dest_x_return = src_x; + *dest_y_return = src_y; + } + *child_return = None; + return 1; +} + +/*- + * XUngrabKeyboard + * not currently used + */ +void XUngrabKeyboard(Display *display, Time time) +{ +} + +/*- + * XUngrabPointer + * not currently used + */ +void XUngrabPointer(Display *display, Time time) +{ +} + +/*- + * XUngrabServer + * not currently used + */ +void XUngrabServer(Display *display) +{ +} + +/*- + * XUnmapWindow + * not currently used + */ +void XUnmapWindow(Display *display, Window w) +{ +} + +#endif /* WIN32 */ + +/* -------------------------------------------------------------------- */ diff --git a/app/xlockmore/win32/Xapi.h b/app/xlockmore/win32/Xapi.h new file mode 100644 index 000000000..ccf000f49 --- /dev/null +++ b/app/xlockmore/win32/Xapi.h @@ -0,0 +1,971 @@ +#ifndef __XLOCK_XAPI_H__ +#define __XLOCK_XAPI_H__ + +/*- + * @(#)Xapi.h 4.00 98/04/16 xlockmore + * + * Xapi.h - X API interface for WIN32 (windows 95/NT) platforms + * + * Copyright (c) 1998 by Petey Leinonen. + * + * See xlock.c for copying information. + * + * Revision History: + * + * 16-Apr-98: Initially written. Based off code written by myself for + * an older version of xlockmore for win95/NT + * + */ +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN + +/*- + * includes + */ + +#include <windows.h> + +extern HWND hwnd; /* window handle */ +extern HDC hdc; /* device context */ +extern int cred, cgreen, cblue; /* color reference of the pen */ +extern unsigned char *red, *green, *blue; /* holds a list of colors */ +extern int colorcount; /* number of colors used */ +unsigned int randommode; /* number of mode to index */ +extern RECT rc; /* coords of the screen */ + +/*- + * defines + */ + +/* -------------------------------------------------------------------- */ + +/***************************************************************** + * ERROR CODES + *****************************************************************/ + +#define Success 0 /* everything's okay */ +#define BadRequest 1 /* bad request code */ +#define BadValue 2 /* int parameter out of range */ +#define BadWindow 3 /* parameter not a Window */ +#define BadPixmap 4 /* parameter not a Pixmap */ +#define BadAtom 5 /* parameter not an Atom */ +#define BadCursor 6 /* parameter not a Cursor */ +#define BadFont 7 /* parameter not a Font */ +#define BadMatch 8 /* parameter mismatch */ +#define BadDrawable 9 /* parameter not a Pixmap or Window */ +#define BadAccess 10 /* depending on context: + - key/button already grabbed + - attempt to free an illegal + cmap entry + - attempt to store into a read-only + color map entry. + - attempt to modify the access control + list from other than the local host. + */ +#define BadAlloc 11 /* insufficient resources */ +#define BadColor 12 /* no such colormap */ +#define BadGC 13 /* parameter not a GC */ +#define BadIDChoice 14 /* choice not in range or already used */ +#define BadName 15 /* font or color name doesn't exist */ +#define BadLength 16 /* Request length incorrect */ +#define BadImplementation 17 /* server is defective */ + +/* window attributes */ +#define InputOutput 1 +#define InputOnly 2 + +#define IsUnmapped 0 +#define IsUnviewable 1 +#define IsViewable 2 + +/* redefined functions */ +#define XWhitePixelOfScreen WhitePixelOfScreen + +/* define False/True */ +#define False (0) +#define True (!False) + +#define None (0L) +#define CurrentTime (0L) + +#define DoRed (0x1) +#define DoGreen (0x2) +#define DoBlue (0x4) + +#define XYBitmap (0x01) +#define XYPixmap (0x02) +#define ZPixmap (0x04) + +#define LSBFirst (0x00) +#define MSBFirst (0x01) + +#define AllocNone (0x00) +#define AllocAll (0x01) + +#define BitmapSuccess (0) +#define BitmapOpenFailed (1) +#define BitmapFileInvalid (2) +#define BitmapNoMemory (3) + +#define StaticGray (0) +#define GrayScale (1) +#define StaticColor (2) +#define PseudoColor (3) +#define TrueColor (4) +#define DirectColor (5) + +/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer, + state in various key-, mouse-, and button-related events. */ +#define ShiftMask (1<<0) +#define LockMask (1<<1) +#define ControlMask (1<<2) +#define Mod1Mask (1<<3) +#define Mod2Mask (1<<4) +#define Mod3Mask (1<<5) +#define Mod4Mask (1<<6) +#define Mod5Mask (1<<7) + +/* button masks. Used in same manner as Key masks above. Not to be confused + with button names below. */ +#define Button1Mask (1<<8) +#define Button2Mask (1<<9) +#define Button3Mask (1<<10) +#define Button4Mask (1<<11) +#define Button5Mask (1<<12) + + + +#define VisualNoMask (0x0) +#define VisualIDMask (0x1) +#define VisualScreenMask (0x2) +#define VisualDepthMask (0x4) +#define VisualClassMask (0x8) +#define VisualRedMaskMask (0x10) +#define VisualGreenMaskMask (0x20) +#define VisualBlueMaskMask (0x40) +#define VisualColormapMaskMask (0x80) +#define VisualBitsPerRGBMask (0x100) +#define VisualAllMask (0x1FF) + +#define GrabModeSync (0) +#define GrabModeAsync (1) + +#define GrabSuccess (0) +#define AlreadyGrabbed (1) +#define GrabInvalidTime (2) +#define GrabNotViewable (3) +#define GrabFrozen (4) + +#define NoEventMask 0L +#define KeyPressMask (1L<<0) +#define KeyReleaseMask (1L<<1) +#define ButtonPressMask (1L<<2) +#define ButtonReleaseMask (1L<<3) +#define EnterWindowMask (1L<<4) +#define LeaveWindowMask (1L<<5) +#define PointerMotionMask (1L<<6) +#define PointerMotionHintMask (1L<<7) +#define Button1MotionMask (1L<<8) +#define Button2MotionMask (1L<<9) +#define Button3MotionMask (1L<<10) +#define Button4MotionMask (1L<<11) +#define Button5MotionMask (1L<<12) +#define ButtonMotionMask (1L<<13) +#define KeymapStateMask (1L<<14) +#define ExposureMask (1L<<15) +#define VisibilityChangeMask (1L<<16) +#define StructureNotifyMask (1L<<17) +#define ResizeRedirectMask (1L<<18) +#define SubstructureNotifyMask (1L<<19) +#define SubstructureRedirectMask (1L<<20) +#define FocusChangeMask (1L<<21) +#define PropertyChangeMask (1L<<22) +#define ColormapChangeMask (1L<<23) +#define OwnerGrabButtonMask (1L<<24) + +#define KeyPress 2 +#define KeyRelease 3 +#define ButtonPress 4 +#define ButtonRelease 5 +#define MotionNotify 6 +#define EnterNotify 7 +#define LeaveNotify 8 +#define FocusIn 9 +#define FocusOut 10 +#define KeymapNotify 11 +#define Expose 12 +#define GraphicsExpose 13 +#define NoExpose 14 +#define VisibilityNotify 15 +#define CreateNotify 16 +#define DestroyNotify 17 +#define UnmapNotify 18 +#define MapNotify 19 +#define MapRequest 20 +#define ReparentNotify 21 +#define ConfigureNotify 22 +#define ConfigureRequest 23 +#define GravityNotify 24 +#define ResizeRequest 25 +#define CirculateNotify 26 +#define CirculateRequest 27 +#define PropertyNotify 28 +#define SelectionClear 29 +#define SelectionRequest 30 +#define SelectionNotify 31 +#define ColormapNotify 32 +#define ClientMessage 33 +#define MappingNotify 34 +#define LASTEvent 35 + +#define VisibilityUnobscured (0) +#define VisibilityPartiallyObscured (1) +#define VisibilityFullyObscured (2) + +#define XC_left_ptr (68) + +#define Button1 (1) +#define Button2 (2) +#define Button3 (3) +#define Button4 (4) +#define Button5 (5) + +#define SIGHUP (0) +#define SIGQUIT (1) +#define SIGBUS (2) + +#define CoordModeOrigin (0) +#define CoordModePrevious (1) + +#define Complex (0) +#define Nonconvex (1) +#define Convex (2) + +#define LineSolid (0) +#define LineOnOffDash (1) +#define LineDoubleDash (2) + +#define CapNotLast (0) +#define CapButt (1) +#define CapRound (2) +#define CapProjecting (3) + +#define JoinMiter (0) +#define JoinRound (1) +#define JoinBevel (2) + + +#define GCFunction (1L<<0) +#define GCPlaneMask (1L<<1) +#define GCForeground (1L<<2) +#define GCBackground (1L<<3) +#define GCLineWidth (1L<<4) +#define GCLineStyle (1L<<5) +#define GCCapStyle (1L<<6) +#define GCJoinStyle (1L<<7) +#define GCFillStyle (1L<<8) +#define GCFillRule (1L<<9) +#define GCTile (1L<<10) +#define GCStipple (1L<<11) +#define GCTileStipXOrigin (1L<<12) +#define GCTileStipYOrigin (1L<<13) +#define GCFont (1L<<14) +#define GCSubwindowMode (1L<<15) +#define GCGraphicsExposures (1L<<16) +#define GCClipXOrigin (1L<<17) +#define GCClipYOrigin (1L<<18) +#define GCClipMask (1L<<19) +#define GCDashOffset (1L<<20) +#define GCDashList (1L<<21) +#define GCArcMode (1L<<22) + +#define FillSolid (0) +#define FillTiled (1) +#define FillStippled (2) +#define FillOpaqueStippled (3) + +#define GXclear (0x0) +#define GXand (0x1) +#define GXandReverse (0x2) +#define GXcopy (0x3) +#define GXandInverted (0x4) +#define GXnoop (0x5) +#define GXxor (0x6) +#define GXor (0x7) +#define GXnor (0x8) +#define GXequiv (0x9) +#define GXinvert (0xa) +#define GXorReverse (0xb) +#define GXcopyInverted (0xc) +#define GXorInverted (0xd) +#define GXnand (0xe) +#define GXset (0xf) + +/* fillRule */ +#define EvenOddRule 0 +#define WindingRule 1 + +/*- + * types + */ + +/* -------------------------------------------------------------------- */ + +/* simple */ + +/* XPointer type: not needed for WIN32 */ +typedef void* XPointer; + +/* XID type */ +typedef unsigned long XID; + +/* Atom type: not needed for WIN32*/ +typedef unsigned long Atom; + +/* Bool type */ +typedef int Bool; + +/* Colormap type: not needed for WIN32 */ +typedef XID Colormap; + +/* Cursor type: not needed for WIN32 */ +typedef XID Cursor; + +/* Display type: not needed for WIN32 */ +typedef int Display; + +/* Drawable type, can be bitmap or window */ +typedef int Drawable; + +/* Font type: not needed for WIN32 */ +typedef XID Font; + +/* GC type: really a HDC */ +typedef int GC; + +/* GContext type: not needed for WIN32 */ +typedef XID GContext; + +/* Keysym type: not needed for WIN32 */ +typedef XID KeySym; + +/* Pixel type, from <X11/Intrinsic.h> */ +typedef unsigned long Pixel; + +/* Pixmap type, implemented a bitmap handler for WIN32 */ +typedef int Pixmap; + +/* Screen type: not needed for WIN32 */ +typedef int Screen; + +/* Status type: not needed for WIN32 */ +typedef int Status; + +/* Time type: not needed for WIN32 */ +typedef unsigned long Time; + +/* VisualID type: not needed for WIN32 */ +typedef unsigned long VisualID; + +/* Window type: really a HWND but typecasting to int, + * this is because a Window is also a Drawable. + * We don't use this anyway */ +typedef int Window; + +/* XExtData type: used below */ +typedef char XExtData; + +/* XrmQuark, XrmQuarkList: not needed */ +typedef int XrmQuark, *XrmQuarkList; + +/* complex */ + +/* Visual type: not needed for WIN32 */ +typedef struct { + XExtData *ext_data; + VisualID visualid; +#if defined(__cplusplus) || defined(c_plusplus) + int c_class; +#else + int class; +#endif + unsigned long red_mask; + unsigned long green_mask; + unsigned long blue_mask; + int bits_per_rgb; + int map_entries; +} Visual; + +/* XAnyEvent type: not needed for WIN32 */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window window; +} XAnyEvent; + +/* XArc */ +typedef struct { + short x,y; + unsigned short width, height; + short angle1, angle2; +} XArc; + +/* XCharStruct type: not needed for WIN32 */ +typedef struct { + short lbearing; + short rbearing; + short width; + short ascent; + short descent; + unsigned short attributes; +} XCharStruct; + +/* XClassHint type: not needed for WIN32 */ +typedef struct { + char *res_name; + char *res_class; +} XClassHint; + +/* XComposeStatus type: not needed for WIN32 */ +typedef struct { + XPointer compose_ptr; + int chars_matched; +} XComposeStatus; + +/* XKeyEvent type: */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window window; + Window root; + Window subwindow; + Time time; + int x, y; + int x_root, y_root; + unsigned int state; + unsigned int keycode; + Bool same_screen; +} XKeyEvent; + +/* XButtonEvent type: */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window window; + Window root; + Window subwindow; + Time time; + int x, y; + int x_root, y_root; + unsigned int state; + unsigned int button; + Bool same_screen; +} XButtonEvent; + +/* XMotionEvent type */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window window; + Window root; + Window subwindow; + Time time; + int x, y; + int x_root, y_root; + unsigned int state; + char is_hint; + Bool same_screen; +} XMotionEvent; + +/* XExposeEvent */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window window; + int x, y; + int width, height; + int count; +} XExposeEvent; + +/* XVisibilityEvent type */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window window; + int state; +} XVisibilityEvent; + +/* XConfigureEvent type */ +typedef struct { + int type; + unsigned long serial; + Bool send_event; + Display *display; + Window event; + Window window; + int x, y; + int width, height; + int border_width; + Window above; + Bool override_redirect; +} XConfigureEvent; + +/* XEvent type: not needed for WIN32 */ +typedef union _XEvent { + int type; + XAnyEvent xany; + XKeyEvent xkey; + XButtonEvent xbutton; + XMotionEvent xmotion; +// XCrossingEvent xcrossing; +// XFocusChangeEvent xfocus; + XExposeEvent xexpose; +// XGraphicsExposeEvent xgraphicsexpose; +// XNoExposeEvent xnoexpose; + XVisibilityEvent xvisibility; +// XCreateWindowEvent xcreatewindow; +// XDestroyWindowEvent xdestroywindow; +// XUnmapEvent xunmap; +// XMapEvent xmap; +// XMapRequestEvent xmaprequest; +// XReparentEvent xreparent; + XConfigureEvent xconfigure; +// XGravityEvent xgravity; +// XResizeRequestEvent xresizerequest; +// XConfigureRequestEvent xconfigurerequest; +// XCirculateEvent xcirculate; +// XCirculateRequestEvent xcirculaterequest; +// XPropertyEvent xproperty; +// XSelectionClearEvent xselectionclear; +// XSelectionRequestEvent xselectionrequest; +// XSelectionEvent xselection; +// XColormapEvent xcolormap; +// XClientMessageEvent xclient; +// XMappingEvent xmapping; +// XErrorEvent xerror; +// XKeymapEvent xkeymap; + long pad[24]; +} XEvent; + +/* XFontProp type: not needed for WIN32 */ +typedef struct { + Atom name; + unsigned long card32; +} XFontProp; + +/* XFontStruct type: not needed for WIN32 */ +typedef struct { + XExtData *ext_data; + Font fid; + unsigned direction; + unsigned min_char_or_byte2; + unsigned max_char_or_byte2; + unsigned min_byte1; + unsigned max_byte1; + Bool all_chars_exist; + unsigned default_char; + int n_properties; + XFontProp *properties; + XCharStruct min_bounds; + XCharStruct max_bounds; + XCharStruct *per_char; + int ascent; + int descent; +} XFontStruct; + +/* XColor type */ +typedef struct { + unsigned long pixel; + unsigned short red, green, blue; + char flags; + char pad; +} XColor; + +/* XGCValues type */ +typedef struct { + int function; + unsigned long plane_mask; + unsigned long foreground; + unsigned long background; + int line_width; + int line_style; + int cap_style; + int join_style; + int fill_style; + int fill_rule; + int arc_mode; + Pixmap tile; + Pixmap stipple; + int ts_x_origin; + int ts_y_origin; + Font font; + int subwindow_mode; + Bool graphics_exposures; + int clip_x_origin; + int clip_y_origin; + Pixmap clip_mask; + int dash_offset; + char dashes; +} XGCValues; + +/* XHostAddress type: not needed for WIN32 */ +typedef struct { + int family; + int length; + char *address; +} XHostAddress; + +/* XImage type */ +typedef struct { + int width, height; + int xoffset; + int format; + char *data; + int byte_order; + int bitmap_unit; + int bitmap_bit_order; + int bitmap_pad; + int depth; + int bytes_per_line; +} XImage; + +/* XPoint type */ +typedef struct { + int x, y; +} XPoint; + +/* XRectangle type */ +typedef struct { + short x,y; + unsigned short width, height; +} XRectangle; + +/* XrmBinding & XrmBindingList types: not needed for WIN32 */ +typedef enum { + XrmBindTightly, + XrmBindLoosely +} XrmBinding, *XrmBindingList; + +/* XrmDatabase type: not needed for WIN32 */ +typedef char** XrmDatabase; + +/* XrmOptionKind type: used by XrmOptionDescRec */ +typedef enum { + XrmoptionNoArg, + XrmoptionIsArg, + XrmoptionStickyArg, + XrmoptionSepArg, + XrmoptionResArg, + XrmoptionSkipArg, + XrmoptionSkipLine, + XrmoptionSkipNArgs +} XrmOptionKind; + +/* XrmOptionDescRec type: not needed for WIN32 */ +typedef struct { + char *option; + char *specifier; + XrmOptionKind argKind; + XPointer value; +} XrmOptionDescRec, *XrmOptionDescList; + +/* XrmValue type: not needed for WIN32 */ +typedef struct { + unsigned int size; + XPointer addr; +} XrmValue, *XrmValuePtr; + +/* XSegment type */ +typedef struct { + short x1, y1, x2, y2; +} XSegment; + +/* XTextProperty type: not needed for WIN32 */ +typedef struct { + unsigned char *value; + Atom encoding; + int format; + unsigned long nitems; +} XTextProperty; + +/* XVisualInfo type: not needed for WIN32 */ +typedef struct { + Visual *visual; + VisualID visualid; + int screen; + int depth; +#if defined(__cplusplus) || defined(c_plusplus) + int c_class; +#else + int class; +#endif + unsigned long red_mask; + unsigned long green_mask; + unsigned long blue_mask; + int colormap_size; + int bits_per_rgb; +} XVisualInfo; + +/* XWindowAttributes type: not needed for WIN32 */ +typedef struct { + int x, y; + int width, height; + int border_width; + int depth; + Visual *visual; + Window root; + int class; + int bit_gravity; + int win_gravity; + int backing_store; + unsigned long backing_planes; + unsigned long backing_pixels; + Bool save_under; + Colormap colormap; + Bool map_installed; + int map_state; + long all_events_masks; + long your_event_mask; + long do_not_propogate_mask; + Bool override_redirect; + Screen *screen; +} XWindowAttributes; + +/* XWindowChanges type: not needed for WIN32 */ +typedef struct { + int x, y; + int width, height; + int border_width; + Window sibling; + int stack_mode; +} XWindowChanges; + + +/* caddr_t type: char address type */ +typedef char *caddr_t; + +/* -------------------------------------------------------------------- */ + +/*- + * prototypes + */ + +int nice(int level); +void sleep(int sec); +int sigmask(int signum); + +unsigned long BlackPixel(Display *display, int screen_number); +int BlackPixelOfScreen(Screen *screen); +int CellsOfScreen(Screen *screen); +Colormap DefaultColormap(Display *display, int screen_number); +Colormap DefaultColormapOfScreen(Screen *screen); +Visual *DefaultVisual(Display *display, int screen_number); +int DisplayPlanes(Display *display, int screen_number); +char *DisplayString(Display *display); +Window RootWindow(Display *display, int screen_number); +int ScreenCount(Display *display); +Screen *ScreenOfDisplay(Display *display, int screen_number); +unsigned long WhitePixel(Display *display, int screen_number); +int WhitePixelOfScreen(Screen *screen); + + + +void XAddHosts(Display *display, XHostAddress *hosts, int num_hosts); +Status XAllocColor(Display *display, Colormap colormap, + XColor *screen_in_out); +Status XAllocColorCells(Display *display, Colormap colormap, + Bool contig, unsigned long plane_masks_return[], + unsigned int nplanes, unsigned long pixels_return[], + unsigned int npixels); +Status XAllocNamedColor(Display *display, Colormap colormap, + char *color_name, XColor *screen_def_return, + XColor *exact_def_return); +void XBell(Display *display, int percent); +void XChangeGC(Display *display, GC gc, unsigned long valuemask, + XGCValues *values); +Bool XCheckMaskEvent(Display *display, long event_mask, + XEvent *event_return); +void XClearArea(Display *display, Window w, int x, int y, + unsigned int width, unsigned int height, Bool exposures); +void XClearWindow(Display *display, Window w); +void XCloseDisplay(Display *display); +void XConfigureWindow(Display *display, Window w, + unsigned int value_mask, + XWindowChanges *values); +int XCopyArea(Display *display, Drawable src, Drawable dest, GC gc, + int src_x, int src_y, unsigned int width, unsigned height, + int dest_x, int dest_y); +int XCopyPlane(Display *display, Drawable src, Drawable dest, GC gc, + int src_x, int src_y, unsigned width, int height, int dest_x, + int dest_y, unsigned long plane); +Colormap XCopyColormapAndFree(Display *display, Colormap colormap); +Pixmap XCreateBitmapFromData(Display *display, Drawable drawable, + char *data, unsigned int width, + unsigned int height); +Colormap XCreateColormap(Display *display, Window w, + Visual *visual, int alloc); +Cursor XCreateFontCursor(Display *display, unsigned int shape); +GC XCreateGC(Display *display, Drawable drawable, + unsigned long valuemask, XGCValues *values); +XImage *XCreateImage(Display *display, Visual *visual, + unsigned int depth, int format, int offset, + char *data, unsigned int width, + unsigned int height, int bitmap_pad, + int bytes_per_line); +Pixmap XCreatePixmap(Display *display, Drawable d, unsigned int width, + unsigned int height, unsigned int depth); +Cursor XCreatePixmapCursor(Display *display, + Pixmap source, Pixmap mask, + XColor *foreground_color, XColor *background_color, + unsigned int x_hot, unsigned int y_hot); +Pixmap XCreatePixmapFromBitmapData(Display *display, Drawable drawable, + char *data, unsigned int width, unsigned int height, + unsigned long fg, unsigned long bg, unsigned int depth); +void XDefineCursor(Display *display, Window window, Cursor cursor); +void XDestroyImage(XImage *ximage); +void XDisableAccessControl(Display *display); +void XDrawArc(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height, + int angle1, int angle2); +void XDrawImageString(Display *display, Drawable d, GC gc, + int x, int y, char *string, int length); +void XDrawLine(Display *display, Drawable d, GC gc, + int x1, int y1, int x2, int y2); +void XDrawLines(Display *display, Drawable d, GC gc, + XPoint *points, int npoints, int mode); +void XDrawPoint(Display *display, Drawable d, GC gc, int x, int y); +void XDrawPoints(Display *display, Drawable d, GC gc, + XPoint *pts, int numpts, int mode); +void XDrawRectangle(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height); +void XDrawSegments(Display *display, Drawable d, GC gc, + XSegment *segs, int numsegs); +void XDrawString(Display *display, Drawable d, GC gc, int x, int y, + char *string, int length); +void XEnableAccessControl(Display *display); +void XFillArc(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height, + int angle1, int angle2); +void XFillArcs(Display *display, Drawable d, GC gc, + XArc *arcs, int narcs); +void XFillPolygon(Display *display, Drawable d, GC gc, XPoint *points, + int npoints, int shape, int mode); +void XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height); +void XFillRectangles(Display *display, Drawable d, GC gc, + XRectangle *rectangles, int nrectangles); +void XFlush(Display *display); +void XFree(void *data); +void XFreeColormap(Display *display, Colormap colormap); +void XFreeColors(Display *display, Colormap colormap, + unsigned long pixels[], int npixels, + unsigned long planes); +void XFreeCursor(Display *display, Cursor cursor); +int XFreeFont(Display *display, XFontStruct *font_struct); +int XFreeFontInfo(char** names, XFontStruct* free_info, int actual_count); +void XFreeGC(Display *display, GC gc); +void XFreePixmap(Display *display, Pixmap pixmap); +GContext XGContextFromGC(GC gc); +XVisualInfo *XGetVisualInfo(Display *display, long vinfo_mask, + XVisualInfo *vinfo_template, + int *nitems_return); +Status XGetWindowAttributes(Display *display, Window w, + XWindowAttributes *window_attr_return); +int XGrabKeyboard(Display *display, Window grab_window, + Bool owner_events, int pointer_mode, + int keyboard_mode, Time time); +int XGrabPointer(Display *display, Window grab_window, Bool owner_events, + unsigned int event_mask, int pointer_mode, + int keyboard_mode, Window confine_to, Cursor cursor, + Time time); +void XGrabServer(Display *display); +void XInstallColormap(Display *display, Colormap colormap); +XHostAddress *XListHosts(Display *display, int *nhosts_return, + Bool *state_return); +XFontStruct *XLoadQueryFont(Display *display, char *name); +int XLookupString(XKeyEvent *event_struct, char *buffer_return, + int bytes_buffer, KeySym *keysym_return, + XComposeStatus *status_in_out); +void XMapWindow(Display *display, Window w); +void XNextEvent(Display *display, XEvent *event_return); +Display *XOpenDisplay(char *display_name); +Status XParseColor(Display *display, Colormap colormap, + char *spec, XColor *exact_def_return); +int XPending(Display *display); +void XPutBackEvent(Display *display, XEvent *event); +void XPutImage(Display *display, Drawable d, GC gc, XImage *image, int src_x, + int src_y, int dest_x, int dest_y, unsigned int width, + unsigned int height); +int XPutPixel(XImage *ximage, int x, int y, unsigned long pixel); +void XQueryColor(Display *display, Colormap colormap, XColor *def_in_out); +XFontStruct *XQueryFont(Display* display, XID font_ID); +Bool XQueryPointer(Display *display, Window w, Window *root_return, + Window *child_return, int *root_x_return, int *root_y_return, + int *win_x_return, int *win_y_return, + unsigned int *mask_return); +Status XQueryTree(Display *display, Window w, Window *root_return, + Window *parent_return, Window **children_return, + unsigned int *nchildren_return); +void XRaiseWindow(Display *display, Window w); +int XReadBitmapFile(Display *display, Drawable d, char *filename, + unsigned int *width_return, unsigned int *height_return, + Pixmap *bitmap_return, int *x_hot_return, int *y_hot_return); +void XRemoveHosts(Display *display, XHostAddress *hosts, int num_hosts); +char *XResourceManagerString(Display *display); +void XrmDestroyDatabase(XrmDatabase database); +XrmDatabase XrmGetFileDatabase(char *filename); +Bool XrmGetResource(XrmDatabase database, char *str_name, + char *str_class, char **str_type_return, + XrmValue *value_return); +XrmDatabase XrmGetStringDatabase(char *data); +void XrmInitialize(void); +void XrmMergeDatabases(XrmDatabase source_db, XrmDatabase *target_db); +void XrmParseCommand(XrmDatabase *database, XrmOptionDescList table, + int table_count, char *name, int *argc_in_out, + char **argv_in_out); +void XSetBackground(Display *display, GC gc, unsigned long background); +void XSetFillRule(Display *display, GC gc, int fill_rule); +void XSetFillStyle(Display *display, GC gc, int fill_style); +void XSetFont(Display *display, GC gc, Font font); +void XSetForeground(Display *display, GC gc, unsigned long foreground); +void XSetFunction(Display *display, GC gc, int function); +int XSetGraphicsExposures(Display *display, GC gc, Bool graphics_exposures); +void XSetLineAttributes(Display *display, GC gc, + unsigned int line_width, int line_style, + int cap_style, int join_style); +void XSetScreenSaver(Display *display, int timeout, int interval, + int prefer_blanking, int allow_exposures); +void XSetStipple(Display *display, GC gc, Pixmap stipple); +void XSetTSOrigin(Display *display, GC gc, int ts_x_origin, int ts_y_origin); +void XSetWindowColormap(Display *display, Window w, Colormap colormap); +void XSetWMName(Display *display, Window w, XTextProperty *text_prop); +Status XStringListToTextProperty(char **list, int count, + XTextProperty *text_prop_return); +void XStoreColors(Display *display, Colormap colormap, XColor color[], + int ncolors); +void XSync(Display *display, Bool discard); +int XTextWidth(XFontStruct *font_struct, char *string, int count); +Bool XTranslateCoordinates(Display* display, Window src_w, Window dest_w, + int src_x, int src_y, + int* dest_x_return, int* dest_y_return, + Window* child_return); +void XUngrabKeyboard(Display *display, Time time); +void XUngrabPointer(Display *display, Time time); +void XUngrabServer(Display *display); +void XUnmapWindow(Display *display, Window w); +/* -------------------------------------------------------------------- */ + +#endif /* WIN32 */ +#endif /* __XLOCK_XAPI_H__ */ diff --git a/app/xlockmore/win32/readme.txt b/app/xlockmore/win32/readme.txt new file mode 100644 index 000000000..27e0d64cc --- /dev/null +++ b/app/xlockmore/win32/readme.txt @@ -0,0 +1,334 @@ +Xlock95 Readme.txt file. + +Version 0.11 + + +Requirements. +------------- + +Windows 95, 98, ME or Windows NT, 2000, XP running 256 colors or greater. +Don't know the minimum spec. machine, but I have run it on a +Pentium 166 (Win95), Pentium Pro 200 (Win NT), Pentium II 233 (Win95), +Pentium III 1000 (Win98) and Pentium 4 3Ghz (XP Pro). + +Building. +--------- +Cygwin - www.cygwin.com + (Gnu gcc compiler for windows) + +I no longer use MS VC++ to compile. It took about a day to +convert over to cygwin (and that was mainly setting up the +Makefiles). To compile under VC++ would take a little work +but it should be fairly painless. + +At top level +make -f Makefile.win32 + +Note: for other compilers things may be different. For VC++ there + were many more steps to set up. + + +Note2: When you use Debug configuration, you will only get one mode + working. When you want to debug a mode you will have to + change the mode you want. I set this up so when I debugged + any new mode that I have just added, the only mode displayed + was the one I set. To set debug mode, modify the Makefile in + the xlock sub-directory to define _DEBUG (ie -D_DEBUG) + + +Installation. +------------- + +Place the file "xlock95.scr" in either Windows system or Windows +directory ("C:\Windows\System\", "C:\Windows\", "C:\WINNT +which ever works, `cygpath -W` should tell you what this is) + +make -f Makefile.win32 install + +Set "xlock95" to be your screen saver. When you enter the +Screen Saver tab in the Display Properties it may take a little +while for control to come back to you if xlock95 is set. +If it does not show up the scr file is probably in the wrong directory. + +Alternatively you can just double click the .scr from +explorer and it should run fine (but thats not the +same as setting it up as a screen saver). + +Windows Screen Saver commandline arguments: + +xlock95.scr Runs screensaver's configuration window. +xlock95.scr /s Runs the screensaver on the full screen. +xlock95.scr /p 1234567 Runs the screensaver in windowid 1234567. + +The Scrnsave.lib clone provided by Cygwin/MinGW +(libscrnsave.a) doesn't appear to support multiple screens. +The source is available from Cygwin in the w32api package. +According to the MS screensaver docs, linking with the latest +scrnsaver.lib should handle multiple screens automatically. +See +http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/monitor_2eur.asp +xlock95 is also not yet coded to handle multiple screens. + +Notes. +------ + +If you have used an older version than 0.4, it was called +"xlock.scr". This is not needed anymore and can be deleted from +Windows system directory. Also timings from the older versions are +different than the versions 0.4 and above, so modes will be either +faster or slower. + +If you have used a version between 0.4 and 0.6, it was called +"xlockmore.scr". This is not needed anymore and can be deleted from +Windows system directory. + +When the screen saver is started, it randomly chooses a mode. At this +time, there are 86 modes. These are: + +Ant, Ant3D, Apollonian, Ball, Bat, Blot, Bouboule, Bounce, Braid, +Bug, Clock, Coral, Crystal, Daisy, Deco, Demon, Dilemma, Discrete, +Dragon, Drift, Euler2D, Eyes, Fadeplot, Fiberlamp, Flame, Flow, +Forest, Galaxy, Grav, Helix, Hop, Hyper, Ico, Image, Juggle, Julia, +Kaleid, Kumppa, Laser, Life, Life1D, Life3D, Lightning, Lisa, Lissie, +Loop, Lyapunov, Mandelbrot, Matrix, Maze, Mountain, Munch, Nose, +Pacman, Petal, Petri, Polyominoes, Pyro, Qix, Roll, Rotor, Scooter, +Shape, Sierpinski, Slip, Space, Sphere, Spiral, Spline, Star, +Starfish, Swarm, Tetris, Thornbird, Tik_tak, Toneclock, Triangle, +Tube, Turtle, Vines, Voters, Wator, Wire, World, Worm, Xjack + +In the X-Windows version it is possible to set variables that affect +how long certain things are done (eg how many vines or blots to be +drawn before clearing the screen). These variables are cycles, size and +batch counts, and every mode is affected by them. The Win95/NT version +currently isn't able to set these variables and therefore they use the +defaults. Also some modes read in settings from files (eg life3d reads +from file .life3d.rule3d). At the moment this isn't being done either. + +Running it from the commandline yields "Hello World!" and "Okie dokie". +These are the config dialogs. Eventually if +proper configuration is added, this is where it should +go. You'll get the same dialogs when you press the +settings button on the screensaver tab when +xlock95 is the active screensaver. + + +Future of Xlockmore95. +---------------------- + +At this stage I have done intermediate releases of Xlockmore95. I +know there are more modes I can add, but as to adding all the modes +that exist in Xlockmore, I'm not sure it is possible. There are modes +that use XPM images (X PixMap images), opengl, and there may be +X11 functions that just won't map easily to win32 functions (I've been +adding them on an as needed basis). + +This is a list of what I would like to do (but I'm not promising)... + . add more modes + . allowing users to set the cycles and batch count variables, probably + in the settings window. + . allowing users to set specific options to modes that require it, + probably in the settings window. + . allowing modes to read settings from files + . handle colors as X11 does + . add all modes (even opengl modes) + + +Differences with X11 & Bugs. +---------------------------- + +ball, crystal, munch, pyro, tik_tak: +XSetFunction() isn't drawing correctly. + +ant: truchet drawing messed up +ant3d and toneclock: double buffering ok but now label flashes +bouboule & some others: flickers. +crystal & tic_toc: xor errors in beginning +julia: red square dot +nose: text messed up +petri: only red germs +scooter: red rects +tube: needs closure for stars and triangles (does not handle sharp angles) +xjack: messed up when text gets to bottom + +There are small differences in Line Attributes between X11 and WIN32 + +Color model is totally different, so no color cycling occurs. + + +Change Log. +----------- + +version 0.1 +. initial release, Vines, Fadeplot, Sierpinski Triangles, Blot + +version 0.2 (not a public release) +. added Coral mode + +version 0.3 +. wasn't initialising some pointer variables, which could cause an + error if circumstances allowed. This is now fixed. + +. added the ability to redefine the color palette in a mode class. + This means it is possible to have modes that don't have a palette + saturation of 1.0 to recalculate the palette to how they require. + For example Blot mode now has a palette saturation of 0.4 + +. added Deco & Forest modes + +version 0.4 (debug build) +. added code for XDrawArc(), XFillArc() & XFillPolygon() + +. changed from using my own base source code to using the source code + for xlockmore 4.07. I still have to use some of my own code for + start-up and initialisation of the screen saver (cannot get around + this due to differences between X11 and Win32), and of course all + the X11 functions and structures. But the rest is xlockmore 4.07 + code. At some point I will see if David will integrate the Win32 + source code into the official distrubution. + +. As a result a lot more modes are now added. These are: + Braid, Clock, Daisy, Drift, Flame, Galaxy, Geometry, Grav, Helix, + Hop, Lightning, Lisa, Lissie, Petal, Qix, Roll, Rotor, Sphere, + Spiral, Spline, Triangle, Turtle + +version 0.5 +. determined that the problem with the Galaxy mode in the release + build was to do with VC++. When VC++ optimizes for speed, Galaxy + does not work. I now optimize for size. + +. life3d: added an extra check to life3dfile, to see if it was NULL + before doing the strlen() on it. This has fixed a crash I was + getting with it. This is the only mode I have changed. + +. added code for XCreateGC(), XChangeGC(), XDrawLines(), XFillArcs(), + XFillRectangles(), XSetFunction() so the following modes now work: + Ant, Ball, Bouboule, Bug, Crystal, Demon, Laser, Life3d, Loop, + Mountain, Munch, Pyro, Wire + +version 0.6 +. added code for XDrawSegments(), XClearArea() so the following modes + now work: Hyper, Ico, Kaleid, Worm + +. added code to set each modes default options (if there are any). + This affects every mode, but only boolean and string types are being + set at the moment. Ico refused to work until either edges or faces + were defined as true. This also allowed me to remove the code I + added to life3d. + +version 0.7 +. changed my build environment. Now using cygwin as my compiler. As a + result some small changes were needed to xlock.c. I am building it + with the -mno-cygwin option (mingw mode ???) so the cywin1.dll is + not used. Created Makefiles to build the screensaver. + +. no longer use the ScrPlus library, but the scrnsave library that + comes with cygwin. Initially used SetTimer(), but this was too slow, so + I created a thread, and use SendMessage() WM_TIMER from there. + +. modified XFillArc() so it now draws the Arc with a thin line before + it fills it. This fixes the minute and hour hands in clock. Other + modes may be affected (ball, bouboule, daisy, galaxy, grav), though + they looked OK. + +. added displaying the mode and its description in the top left hand + corner. + +. filled in code for XDrawString(), though it doesn't affect anything + (yet) + +. added code for XDrawRectangle(), XStoreColors() so the following + modes now works: mandelbrot, tube + +. added empty function calls to XPutImage(), XCreateBitmapFromData(), + XSetBackground(), XSetFillStyle(), XSetStipple() so Maze now works + (minus the operating system graphic) + +. fixed up XSetFunction so now it should utilise different drawing + functions. It does not seem to be 100% correct, but much better than + before. + +version 0.8 (8-Oct-2004) +. added code for XPutImage() so now the operating system graphic is + drawn in Maze. + +. added code for XCreateBitmapFromData(), XFreePixmap(), XCreateGC(), + XFreeGC() + +version 0.9 (15-May-2005) +. fixed XCreateGC() and XSetStipple() so the bad paths of Maze are + set properly (still a problem setting the stipple (brush) the right + color). Other modes are broken for now (such as Galaxy and Grav) as + they leave trails. + +version 0.10 (26-Jul-2005) +. fixed XDrawArc(), XFillArc() & XFillArcs so they draw fully the + complete angles. This was causing a graphical error in some modes, + for example clock. + +. fixed setting the stipple brush color on an XSetForeground. Now the + bad paths of Maze are the correct color. + +. fixed most of the broken modes. I think this had to do with + recreating the pen for a filled arc in XFillArc(). It wasn't always + creating the new pen. I create it now as null, so the border is not + drawn, and to make up for this I make the arc a little larger in the + function. This fixes Galaxy and Grav. Ball is still broken. + +. fixed ball. The problem had to do with XCreateGC(). The way I had + implemented this function meant only about 5 GCs could be created + before problems were occuring. This was fine for all other modes, + apart from ball which needs about 20 GCs. I now have totally + reorganised how GCs are created and are related back to a device + context (DC), which is what Windows uses. I now only have 1 DC, and + reset it when I use a different GC. This means that modes will run + slower. (31-Aug-2005) + +version 0.11 (29-Sep-2005) +. updated to use xlockmore-5.19. This is the first step of getting my + source code integrated into the offical source. A number of changes + had to be made to my code, but it was mostly OK. The following modes + are removed in this new version (removed in the official code): + geometry (14-Sep-2005) + +. many modes have changed, but some have now a few issues (maze - OS + graphic missing again, ico - not moving and artifacts left, + galaxy - awful flickering as there is no double buffering). + (29-Sep-2005) + +. there are many new modes but I have not attempted to implement any + just yet. (29-Sep-2005) + +[Now distributed with xlockmore... David changed back xlockmore95 back +to xlock95... David hopes this is OK with all concerned.] + +Download. +--------- + +Please don't email David with questions about Xlockmore95. +[Well actually David does not mind if you cc him :) ] +They can be directed to me: petey_leinonen@yahoo.com.au + +You can find the latest information about xlockmore from +David A. Bagley's site at http://www.tux.org/~bagleyd/xlockmore.html + + +Copyright. +---------- + +Copyright (c) 1988-91 by Patrick J. Naughton +Copyright (c) 1993-2005 by David A. Bagley +Copyright (c) 1998-2005 by Petey Leinonen (win95/NT version) + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. + +Please note that I do not provide any warranties, and that you use this +executable and/or source code at your own risk. I will not be held +responsible for any damage that is incurred by using the executable +and/or source code. + + +Petey Leinonen, 14 September 2005 diff --git a/app/xlockmore/win32/todo.txt b/app/xlockmore/win32/todo.txt new file mode 100644 index 000000000..b57636212 --- /dev/null +++ b/app/xlockmore/win32/todo.txt @@ -0,0 +1,46 @@ +anemone (requires ???, red screen) +atlantis (requires OpenGL) +atunnels (requires OpenGL) +biof (requires OpenGL) +bubble (requires XSetGraphicsExposures(), XCopyPlane()) +bubble3d (requires OpenGL) +cage (requires OpenGL) +cartoon (requires OpenGL) +dclock (requires XCopyPlane(), XSetGraphicsExposures(), + XSetFont(), XFreeFont()) +decay (requires ???, black screen) +deluxe (requires ???, red screen) +fire (requires OpenGL) +flag (requires utsname.h) +fzort +gears (requires OpenGL) +glplanet (requires OpenGL) +goop (requires XCopyPlane(), XSetPlaneMask()) +ifs (requires XSetGraphicsExposures(), XCopyPlane()) +invert (requires OpenGL, C++) +kaleid2 (requires OpenGL) +lament (requires OpenGL) +marquee (requires XTextExtents(), XSetFont(), XFreeFont()) +moebius (requires OpenGL) +molecule (requires OpenGL) +morph3d (requires OpenGL) +noof (requires OpenGL) +penrose (many errors) +pipes (requires OpenGL) +puzzle (requires ???, black screen) +rubik (requires OpenGL) +run (requires SIGKILL) +sballs (requires OpenGL) +sierpinski3d (requires OpenGL) +skewb (requires OpenGL) +solitare (requires C++) +sproingies (requires OpenGL) +stairs (requires OpenGL) +strange (requires XCopyPlane(), XSetGraphicsExposures()) +superquadrics (requires OpenGL) +swirl (requires XPutPixel(), ScreenCount(), BitmapPad()) +t3d (requires ???, black screen) +text3d (requires OpenGL, C++) +text3d2 (requires OpenGL, C++) +xcl (requires DefaultScreen(), gettimeofday()) + diff --git a/app/xlockmore/win32/xlock.ico b/app/xlockmore/win32/xlock.ico Binary files differnew file mode 100644 index 000000000..d89b75aaf --- /dev/null +++ b/app/xlockmore/win32/xlock.ico diff --git a/app/xlockmore/win32/xlock95.c b/app/xlockmore/win32/xlock95.c new file mode 100644 index 000000000..e7a476b7c --- /dev/null +++ b/app/xlockmore/win32/xlock95.c @@ -0,0 +1,225 @@ +#include <windows.h> +#include <scrnsave.h> +#include <stdlib.h> +#include <time.h> +#include "xlock.h" +#include "xlock95.h" + +/* Win95 specific globals */ +extern HWND hwnd; // window handle +extern HDC hdc; // device context +extern RECT rc; // coords of the screen + +unsigned int xlockmore_create(void); +void xlockmore_destroy(void); +void xlockmore_init(void); +unsigned int xlockmore_timer(void); + +static int *enabled = NULL; + +char *xlock95_get_modelist() { + int m; + HKEY skey; + char key[1024]; + static char modelist[1024] = ""; /* make this dynamic!! */ + if(enabled == NULL) { + enabled = (int*)malloc((numprocs-1)*sizeof(int)); + } + /* Populate enabled[] from registry */ + for(m=0; m<numprocs-1; m++) { /* last one is "random" */ + sprintf(key, "Control Panel\\Screen Saver.xlock95\\%s", + LockProcs[m].cmdline_arg); + if (RegOpenKeyEx(HKEY_CURRENT_USER, key, 0,KEY_READ,&skey) !=ERROR_SUCCESS) + enabled[m] = 1; /* Default is enabled */ + else { + TCHAR buf[10]; + DWORD size = sizeof(buf); + if (RegQueryValueEx(skey,"Enabled",NULL,NULL,(LPBYTE)buf, &size) + !=ERROR_SUCCESS) + enabled[m] = 1; /* Default is enabled */ + else + enabled[m] = (strncmp(buf, "1", 2) == 0); + RegCloseKey(skey); + } + /* Construct modelist suitable for random.c */ + if(enabled[m]) { + snprintf(modelist, sizeof(modelist), + "%s%s,", modelist, LockProcs[m].cmdline_arg); + } + } + return modelist; +} + +BOOL WINAPI ScreenSaverConfigureDialog(hDlg, message, wParam, lParam) + HWND hDlg; + UINT message; + WPARAM wParam; + LPARAM lParam; +{ + int m; + int nItem; + HWND hwndList; + TCHAR tchBuffer[100]; + HRESULT hr; + HKEY skey; + LONG res; + char key[1024]; + + switch(message) + { + case WM_INITDIALOG: + m=8; + SendDlgItemMessage(hDlg, MODE_LIST, LB_SETTABSTOPS, 1, (LPARAM)&m); + (void) xlock95_get_modelist(); /* Populate enabled[] list */ + for(m=0; m<numprocs-1; m++) { /* last one is "random" */ + sprintf(tchBuffer, "%s\t%s", + enabled[m]?"x":"", LockProcs[m].cmdline_arg); + SendDlgItemMessage(hDlg, MODE_LIST, LB_ADDSTRING, 0, + (LPARAM) tchBuffer); + } + break; + case WM_COMMAND: + switch(LOWORD(wParam)) + { + case MODE_LIST: + switch (HIWORD(wParam)) + { + case LBN_SELCHANGE: + m = SendDlgItemMessage(hDlg, MODE_LIST, LB_GETCURSEL, 0, 0); + if(m >= 0 && m < numprocs-1) { + SetDlgItemText(hDlg, DESC_LABEL, LockProcs[m].desc); + SetDlgItemText(hDlg, DELAY_TEXT, + _itoa(LockProcs[m].def_delay, tchBuffer, 10)); + SetDlgItemText(hDlg, COUNT_TEXT, + _itoa(LockProcs[m].def_count, tchBuffer, 10)); + SetDlgItemText(hDlg, CYCLES_TEXT, + _itoa(LockProcs[m].def_cycles,tchBuffer, 10)); + SendDlgItemMessage(hDlg, ENABLE_BUTTON, BM_SETCHECK, + (WPARAM)(enabled[m]? + BST_CHECKED:BST_UNCHECKED), 0); + } + return TRUE; + break; + case LBN_DBLCLK: + m = SendDlgItemMessage(hDlg, MODE_LIST, LB_GETCURSEL, 0, 0); + if(m >= 0 && m < numprocs-1) { + enabled[m] = !enabled[m]; + + SendDlgItemMessage(hDlg, ENABLE_BUTTON, BM_SETCHECK, + (WPARAM)(enabled[m]? + BST_CHECKED:BST_UNCHECKED), 0); + sprintf(tchBuffer, "%c\t%s", + enabled[m]?'x':' ', LockProcs[m].cmdline_arg); + SendDlgItemMessage(hDlg, MODE_LIST, LB_DELETESTRING, + (WPARAM)m, 0); + SendDlgItemMessage(hDlg, MODE_LIST, LB_INSERTSTRING, m, + (LPARAM) tchBuffer); + SendDlgItemMessage(hDlg, MODE_LIST, LB_SETCURSEL, m, 0); + } + } + break; + case ENABLE_BUTTON: + switch (HIWORD(wParam)) + { + case BN_CLICKED: + m = SendDlgItemMessage(hDlg, MODE_LIST, LB_GETCURSEL, 0, 0); + if(m >= 0 && m < numprocs-1) { + enabled[m] = !enabled[m]; + SendDlgItemMessage(hDlg, ENABLE_BUTTON, BM_SETCHECK, + (WPARAM)(enabled[m]? + BST_CHECKED:BST_UNCHECKED), 0); + sprintf(tchBuffer, "%c\t%s", + enabled[m]?'x':' ', LockProcs[m].cmdline_arg); + SendDlgItemMessage(hDlg, MODE_LIST, LB_DELETESTRING, m, 0); + SendDlgItemMessage(hDlg, MODE_LIST, LB_INSERTSTRING, m, + (LPARAM)tchBuffer); + SendDlgItemMessage(hDlg, MODE_LIST, LB_SETCURSEL, m, 0); + } + return TRUE; + } + break; + case IDOK: + { + HKEY skey; + char key[1024]; + char buf[20]; + for(m=0; m<numprocs-1; m++) { + sprintf(key, "Control Panel\\Screen Saver.xlock95\\%s", + LockProcs[m].cmdline_arg); + if (RegCreateKeyEx(HKEY_CURRENT_USER, key, + 0,0,0,KEY_ALL_ACCESS,0,&skey,0) + !=ERROR_SUCCESS) return; + sprintf(buf, "%d", enabled[m]); + RegSetValueEx(skey,"Enabled",0,REG_SZ,buf,1); + RegCloseKey(skey); + } + } + EndDialog(hDlg, IDOK); + return TRUE; + case IDCANCEL: + EndDialog(hDlg, IDCANCEL); + return TRUE; + } + } + return FALSE; +} + +LONG WINAPI ScreenSaverProc(HWND myhwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static UINT uTimer; // timer identifier + static UINT uHasInit = 0; + switch (msg) + { + case WM_ERASEBKGND: + { + HDC myhdc=(HDC) wParam; RECT myrc; GetClientRect(myhwnd,&myrc); + FillRect(myhdc, &myrc, (struct HBRUSH__ *)GetStockObject(BLACK_BRUSH)); + } + break; + + case WM_CREATE: + { + int delay; + hwnd = myhwnd; + GetClientRect(hwnd, &rc); // get window coords + hdc = GetDC(hwnd); // get device context + SetTextColor(hdc, RGB(255,255,255)); // set text foreground to white + SetBkColor(hdc, RGB(0,0,0)); // set text background to black + + delay = xlockmore_create(); + // start the timer + uTimer = SetTimer(hwnd, 1, delay/1000, NULL); + } + break; + + case WM_DESTROY: + { + // Stop the timer + if (uTimer) + KillTimer(hwnd, uTimer); + xlockmore_destroy(); + } + break; + + case WM_TIMER: + { + if (uHasInit == 0) + { + xlockmore_init(); + uHasInit = 1; + } + return xlockmore_timer(); + } + break; + + default: + return DefScreenSaverProc(myhwnd, msg, wParam, lParam); + } + return 0; +} + +BOOL WINAPI RegisterDialogClasses(HANDLE hInst) +{ + return TRUE; +} + diff --git a/app/xlockmore/win32/xlock95.h b/app/xlockmore/win32/xlock95.h new file mode 100644 index 000000000..8c4676725 --- /dev/null +++ b/app/xlockmore/win32/xlock95.h @@ -0,0 +1,13 @@ +#define MODE_BOX 1000 +#define MODE_LIST 1010 +#define DESC_LABEL 1020 +#define DELAY_LABEL 1030 +#define DELAY_TEXT 1040 +#define COUNT_LABEL 1050 +#define COUNT_TEXT 1060 +#define CYCLES_LABEL 1070 +#define CYCLES_TEXT 1080 +#define ENABLE_BUTTON 1090 + + + diff --git a/app/xlockmore/win32/xlockrc.rc b/app/xlockmore/win32/xlockrc.rc new file mode 100644 index 000000000..8674dea57 --- /dev/null +++ b/app/xlockmore/win32/xlockrc.rc @@ -0,0 +1,31 @@ +#include <windows.h> +#include <scrnsave.h> +#include "xlock95.h" + +STRINGTABLE +BEGIN + IDS_DESCRIPTION "xlock95 Screen Saver" +END + +ICON_APP ICON DISCARDABLE "xlock.ico" + +DLG_SCRNSAVECONFIGURE DIALOG 6, 18, 250, 120 +STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "xlock95 Screen Saver setup" +FONT 8, "MS Shell Dlg" +BEGIN + GROUPBOX "Mode", MODE_BOX, 5, 10, 80, 105 + LISTBOX MODE_LIST, 10, 20, 70, 100, WS_VSCROLL|LBS_USETABSTOPS + + GROUPBOX "", DESC_LABEL, 90, 10, 80, 80 + LTEXT "Delay", DELAY_LABEL, 100, 20, 20, 10 + LTEXT "", DELAY_TEXT, 130, 20, 20, 10 + LTEXT "Count", COUNT_LABEL, 100, 30, 20, 10 + LTEXT "", COUNT_TEXT, 130, 30, 20, 10 + LTEXT "Cycles", CYCLES_LABEL, 100, 40, 20, 10 + LTEXT "", CYCLES_TEXT, 130, 40, 20, 10 + CHECKBOX "Enabled", ENABLE_BUTTON,100, 50, 40, 10 + + PUSHBUTTON "OK", IDOK, 200, 20, 40, 14 + PUSHBUTTON "Cancel", IDCANCEL, 200, 60, 40, 14 +END |