Release 980215

Sun Feb 15 12:02:59 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [graphics/x11drv/*.c] [objects/*.c]
	A few X11 critical section optimizations, mostly with XGet/PutPixel.

	* [scheduler/sysdeps.c] [misc/main.c]
	Make sure X11 critical section is available before any Xlib call.

	* [if1632/relay.c] [tools/build.c]
	Yet another attempt at fixing Catch/Throw.

	* [loader/pe_image.c]
	Fixed broken PE DLL loading.

	* [include/winnt.h] [scheduler/handle.c] [scheduler/*.c]
	Implemented handle access rights.
	Added Get/SetHandleInformation.

Sun Feb 15 09:45:23 1997  Andreas Mohr <100.30936@germany.net>

	* [misc/winsock.c]
	Fixed bug in WSACleanup which lead to crashes in WINSOCK_HandleIO.

	* [graphics/fontengine.c] [include/font.h]
	Minor improvements.

	* [memory/global.c]
	Implemented GlobalEntryHandle.

	* [misc/toolhelp.c]
	Fixed a memory bug in Notify*register.

	* [misc/w32scomb.c]
	Improved Get16DLLAddress.

	* [objects/gdiobj.c]
	Implemented GdiSeeGdiDo.


Sat Feb 14 14:57:39 1998  John Richardson <jrichard@zko.dec.com>

	* [win32/console.c]
	Added the console implementation, AllocConsole, FreeConsole,
	CONSOLE_InheritConsole.

	* [documentation/console]
	Some documentation on the console.

	* [include/winerror.h]
	Added some error defines.

	* [scheduler/k32obj.c]
	Registered the scheduler ops.

Fri Feb 13 19:35:35 1998  James Moody  <013263m@dragon.acadiau.ca>

	* [ole/ole2nls.c]
	Some English language fixes for missing values.

	* [controls/listbox.c]
	Fix to allow an empty listbox to deselect all items.

	* [relay32/user32.spec] [windows/keyboard.c]
	CreateAcceleratorTableA stub method.

	* [windows/sysmetrics.c]
	Added missing SM_CXCURSOR & SM_CYCURSOR initializers.

	* [windows/message.c]
	PostThreadMessage32A stub method.

Fri Feb 13 17:12:24 1998  Jim Peterson <jspeter@roanoke.infi.net>

	* [libtest/hello3res.rc] [libtest/hello3.c] [libtest/Makefile.in]
	Updated the 'hello3' test so that it functions properly again.

Fri Feb 13 14:08:07 1998  Martin Boehme  <boehme@informatik.mu-luebeck.de>
	
	* [graphics/mapping.c]
	Fixed the embarrassing bugs I introduced into DPtoLP and
	LPtoDP.

	* [windows/scroll.c]
	Prevent ScrollWindow32 from sending WM_ERASEBKGND.

Thu Feb 12 22:46:53 1998  Huw D M Davies <h.davies1@physics.oxford.ac.uk>

	* [objects/metafile] [include/ldt.h]
	Fix to cope with records longer than 64K.

	* [windows/clipboard.c]
	Clean up bitmaps and metapicts properly.

Mon Feb  3 21:52:18 1998  Karl Backström <karl_b@geocities.com>

	* [programs/winhelp/Sw.rc] [resources/sysres_Sw.rc]
	Minor update of Swedish language support.
diff --git a/graphics/fontengine.c b/graphics/fontengine.c
index 5a118ac..f261b13 100644
--- a/graphics/fontengine.c
+++ b/graphics/fontengine.c
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "windows.h"
+#include "font.h"
 
 /* GDI 300 */
 WORD WINAPI EngineEnumerateFont(LPSTR fontname, FARPROC16 proc, DWORD data )
@@ -13,13 +14,31 @@
     fprintf(stderr,"EngineEnumerateFont(%s,%p,%lx),stub\n",fontname,proc,data);
     return 0;
 }
-#ifdef NOTDEF
+
 /* GDI 301 */
 WORD WINAPI EngineDeleteFont(LPFONTINFO16 lpFontInfo)
 {
-    return 0
+    WORD handle;
+
+    /*	untested, don't know if it works.
+	We seem to access some structure that is located after the
+	FONTINFO. The FONTINFO docu says that there may follow some char-width
+	table or font bitmap or vector info.
+	I think it is some kind of font bitmap that begins at offset 0x52,
+	as FONTINFO goes up to 0x51.
+	If this is correct, everything should be implemented correctly.
+    */
+    if ( ((lpFontInfo->dfType & (RASTER_FONTTYPE|DEVICE_FONTTYPE))
+      == (RASTER_FONTTYPE|DEVICE_FONTTYPE))
+	&& (LOWORD(lpFontInfo->dfFace) == LOWORD(lpFontInfo)+0x6e)
+	&& (handle = *(WORD *)(lpFontInfo+0x54)) )
+    {
+	*(WORD *)(lpFontInfo+0x54) = 0;
+	GlobalFree16(handle);
+    }
+    return 1;
 }
-#endif
+
 /* GDI 302 */
 WORD WINAPI EngineRealizeFont(LPLOGFONT16 lplogFont, LPTEXTXFORM16 lptextxform, LPFONTINFO16 lpfontInfo)
 {
@@ -27,27 +46,33 @@
     
     return 0;
 }
-#ifdef NOTDEF
+
 /* GDI 303 */
-WORD WINAPI EngineGetCharWidth(LPFONTINFO16 lpFontInfo, BYTE, BYTE, LPINT16)
+WORD WINAPI EngineGetCharWidth(LPFONTINFO16 lpFontInfo, BYTE firstChar, BYTE lastChar, LPINT16 buffer)
 {
-    return 0;
+    int i;
+
+    for (i = firstChar; i <= lastChar; i++)
+	*buffer++ = lpFontInfo->dfAvgWidth; /* insert some charwidth functionality here; use average width for now */
+    return 1;
 }
 
 /* GDI 304 */
-WORD WINAPI EngineSetFontContext(LPFONTINFO lpFontInfo, WORD data)
+WORD WINAPI EngineSetFontContext(LPFONTINFO16 lpFontInfo, WORD data)
 {
+	return 0;
 }
+
 /* GDI 305 */
-WORD WINAPI EngineGetGlyphBMP(WORD word, LPFONTINFO lpFontInfo, WORD, WORD, LPSTR string, DWORD dword, LPBITMAPMETRICS16 metrics)
+WORD WINAPI EngineGetGlyphBMP(WORD word, LPFONTINFO16 lpFontInfo, WORD w1, WORD w2, LPSTR string, DWORD dword, /*LPBITMAPMETRICS16*/ LPVOID metrics)
 {
     return 0;
 }
 
 /* GDI 306 */
-DWORD WINAPI EngineMakeFontDir(HDC16 hdc, LPFONTDIR fontdir, LPCSTR string)
+DWORD WINAPI EngineMakeFontDir(HDC16 hdc, LPFONTDIR16 fontdir, LPCSTR string)
 {
-    return 0;
+    return -1; /* error */
     
 }
 
@@ -55,6 +80,5 @@
 
 WORD WINAPI EngineExtTextOut()
 {
+    return 0;
 }
-
-#endif
diff --git a/graphics/mapping.c b/graphics/mapping.c
index 0ced954..b810a23 100644
--- a/graphics/mapping.c
+++ b/graphics/mapping.c
@@ -74,8 +74,8 @@
     {
 	if (dc->w.UseWorldXform)
 	{
-            x = (FLOAT)points->x - dc->w.WorldXform.eDx;
-	    y = (FLOAT)points->y - dc->w.WorldXform.eDy;
+            x = (FLOAT)XDPTOLP( dc, points->x ) - dc->w.WorldXform.eDx;
+	    y = (FLOAT)YDPTOLP( dc, points->y ) - dc->w.WorldXform.eDy;
 	    points->x = (INT32)( (x*dc->w.WorldXform.eM22 -
 	       y*dc->w.WorldXform.eM21) / determinant );
 	    points->y = (INT32)( (-x*dc->w.WorldXform.eM12 +
@@ -83,8 +83,8 @@
 	}
 	else
 	{
-	    points->x = XLPTODP( dc, points->x );
-	    points->y = YLPTODP( dc, points->y );
+	    points->x = XDPTOLP( dc, points->x );
+	    points->y = YDPTOLP( dc, points->y );
 	}
         points++;
     }
@@ -130,14 +130,14 @@
 	    y = (FLOAT)points->x * dc->w.WorldXform.eM12 +
 	        (FLOAT)points->y * dc->w.WorldXform.eM22 +
 		dc->w.WorldXform.eDy;
-	    points->x = XDPTOLP( dc, (INT32)x );
-	    points->y = YDPTOLP( dc, (INT32)y );
+	    points->x = XLPTODP( dc, (INT32)x );
+	    points->y = YLPTODP( dc, (INT32)y );
 	    
 	}
 	else
 	{
-	    points->x = XDPTOLP( dc, points->x );
-	    points->y = YDPTOLP( dc, points->y );
+	    points->x = XLPTODP( dc, points->x );
+	    points->y = YLPTODP( dc, points->y );
 	}
         points++;
     }
diff --git a/graphics/win16drv/init.c b/graphics/win16drv/init.c
index e81e565..91d0c30 100644
--- a/graphics/win16drv/init.c
+++ b/graphics/win16drv/init.c
@@ -471,7 +471,7 @@
 
     PROFILE_GetWineIniString( "spooler", pszOutput, "",
                               psCmd, sizeof(psCmd) );
-    printf("Got printerSpoolCommand \"%s\"\n",psCmd);
+    printf("Got printerSpoolCommand \"%s\" for output device \"%s\"\n",psCmd, pszOutput);
     if (!*psCmd)
         psCmdP = pszOutput;
     else
diff --git a/graphics/x11drv/bitblt.c b/graphics/x11drv/bitblt.c
index 95039c3..100d63e 100644
--- a/graphics/x11drv/bitblt.c
+++ b/graphics/x11drv/bitblt.c
@@ -7,7 +7,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "ts_xlib.h"
+#include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
 #include "bitmap.h"
 #include "callback.h"
@@ -596,14 +596,14 @@
     {
         if (COLOR_PixelToPalette && (depthDst != 1))
             if (swap) for (i = 0; i < width; i++)
-                *pdata-- = COLOR_PixelToPalette[TSXGetPixel( image, i, row )];
+                *pdata-- = COLOR_PixelToPalette[XGetPixel( image, i, row )];
             else for (i = 0; i < width; i++)
-                *pdata++ = COLOR_PixelToPalette[TSXGetPixel( image, i, row )];
+                *pdata++ = COLOR_PixelToPalette[XGetPixel( image, i, row )];
         else
             if (swap) for (i = 0; i < width; i++)
-                *pdata-- = TSXGetPixel( image, i, row );
+                *pdata-- = XGetPixel( image, i, row );
             else for (i = 0; i < width; i++)
-                *pdata++ = TSXGetPixel( image, i, row );
+                *pdata++ = XGetPixel( image, i, row );
     }
     else
     {
@@ -615,16 +615,16 @@
                 bg = COLOR_PixelToPalette[bg];
             }
             if (swap) for (i = 0; i < width; i++)
-                *pdata-- = TSXGetPixel( image, i, row ) ? bg : fg;
+                *pdata-- = XGetPixel( image, i, row ) ? bg : fg;
             else for (i = 0; i < width; i++)
-                *pdata++ = TSXGetPixel( image, i, row ) ? bg : fg;
+                *pdata++ = XGetPixel( image, i, row ) ? bg : fg;
         }
         else  /* color -> monochrome */
         {
             if (swap) for (i = 0; i < width; i++)
-                *pdata-- = (TSXGetPixel( image, i, row ) == bg) ? 1 : 0;
+                *pdata-- = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
             else for (i = 0; i < width; i++)
-                *pdata++ = (TSXGetPixel( image, i, row ) == bg) ? 1 : 0;
+                *pdata++ = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
         }
     }
 }
@@ -720,7 +720,7 @@
             pixel = rowDst + visRectDst->right - 1;
             y = ydst - visRectDst->top;
             for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
-                TSXPutPixel( dstImage, x, y, *pixel-- );
+                XPutPixel( dstImage, x, y, *pixel-- );
             if (mode != STRETCH_DELETESCANS)
                 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
                         widthDst*sizeof(int) );
@@ -794,7 +794,7 @@
             pixel = rowDst + visRectDst->right - 1;
             y = (ydst >> 16) - visRectDst->top;
             for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
-                TSXPutPixel( dstImage, x, y, *pixel-- );
+                XPutPixel( dstImage, x, y, *pixel-- );
             if (mode != STRETCH_DELETESCANS)
                 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
                         widthDst*sizeof(int) );
@@ -831,7 +831,7 @@
     OffsetRect32( &rectDst, -xDst, -yDst );
 
     /* FIXME: avoid BadMatch errors */
-    imageSrc = TSXGetImage( display, dcSrc->u.x.drawable,
+    imageSrc = XGetImage( display, dcSrc->u.x.drawable,
                           visRectSrc->left, visRectSrc->top,
                           visRectSrc->right - visRectSrc->left,
                           visRectSrc->bottom - visRectSrc->top,
@@ -843,10 +843,10 @@
                          dcDst->w.textPixel, dcDst->w.bitsPerPixel != 1 ?
                            dcDst->w.backgroundPixel : dcSrc->w.backgroundPixel,
                          dcDst->w.stretchBltMode );
-    TSXPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
+    XPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
                rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
-    TSXDestroyImage( imageSrc );
-    TSXDestroyImage( imageDst );
+    XDestroyImage( imageSrc );
+    XDestroyImage( imageDst );
 }
 
 
@@ -869,31 +869,31 @@
         if (!COLOR_PixelToPalette ||
             (dcDst->w.bitsPerPixel == 1))  /* monochrome -> monochrome */
         {
-            TSXCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
+            XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
                        visRectSrc->left, visRectSrc->top, width, height, 0, 0);
         }
         else  /* color -> color */
         {
             if (dcSrc->w.flags & DC_MEMORY)
-                imageSrc = TSXGetImage( display, dcSrc->u.x.drawable,
+                imageSrc = XGetImage( display, dcSrc->u.x.drawable,
                                       visRectSrc->left, visRectSrc->top,
                                       width, height, AllPlanes, ZPixmap );
             else
             {
                 /* Make sure we don't get a BadMatch error */
-                TSXCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
+                XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
                            visRectSrc->left, visRectSrc->top,
                            width, height, 0, 0);
-                imageSrc = TSXGetImage( display, pixmap, 0, 0, width, height,
+                imageSrc = XGetImage( display, pixmap, 0, 0, width, height,
                                       AllPlanes, ZPixmap );
             }
             for (y = 0; y < height; y++)
                 for (x = 0; x < width; x++)
-                    TSXPutPixel(imageSrc, x, y,
-                              COLOR_PixelToPalette[TSXGetPixel(imageSrc, x, y)]);
-            TSXPutImage( display, pixmap, gc, imageSrc,
+                    XPutPixel(imageSrc, x, y,
+                              COLOR_PixelToPalette[XGetPixel(imageSrc, x, y)]);
+            XPutImage( display, pixmap, gc, imageSrc,
                        0, 0, 0, 0, width, height );
-            TSXDestroyImage( imageSrc );
+            XDestroyImage( imageSrc );
         }
     }
     else
@@ -902,35 +902,35 @@
         {
             if (COLOR_PixelToPalette)
             {
-                TSXSetBackground( display, gc, 
+                XSetBackground( display, gc, 
                                COLOR_PixelToPalette[dcDst->w.textPixel] );
-                TSXSetForeground( display, gc,
+                XSetForeground( display, gc,
                                COLOR_PixelToPalette[dcDst->w.backgroundPixel]);
             }
             else
             {
-                TSXSetBackground( display, gc, dcDst->w.textPixel );
-                TSXSetForeground( display, gc, dcDst->w.backgroundPixel );
+                XSetBackground( display, gc, dcDst->w.textPixel );
+                XSetForeground( display, gc, dcDst->w.backgroundPixel );
             }
-            TSXCopyPlane( display, dcSrc->u.x.drawable, pixmap, gc,
+            XCopyPlane( display, dcSrc->u.x.drawable, pixmap, gc,
                         visRectSrc->left, visRectSrc->top,
                         width, height, 0, 0, 1 );
         }
         else  /* color -> monochrome */
         {
             /* FIXME: avoid BadMatch error */
-            imageSrc = TSXGetImage( display, dcSrc->u.x.drawable,
+            imageSrc = XGetImage( display, dcSrc->u.x.drawable,
                                   visRectSrc->left, visRectSrc->top,
                                   width, height, AllPlanes, ZPixmap );
             XCREATEIMAGE( imageDst, width, height, dcDst->w.bitsPerPixel );
             for (y = 0; y < height; y++)
                 for (x = 0; x < width; x++)
-                    TSXPutPixel(imageDst, x, y, (TSXGetPixel(imageSrc,x,y) ==
+                    XPutPixel(imageDst, x, y, (XGetPixel(imageSrc,x,y) ==
                                                dcSrc->w.backgroundPixel) );
-            TSXPutImage( display, pixmap, gc, imageDst,
+            XPutImage( display, pixmap, gc, imageDst,
                        0, 0, 0, 0, width, height );
-            TSXDestroyImage( imageSrc );
-            TSXDestroyImage( imageDst );
+            XDestroyImage( imageSrc );
+            XDestroyImage( imageDst );
         }
     }
 }
@@ -950,7 +950,7 @@
     if (!COLOR_PixelToPalette || (dc->w.bitsPerPixel == 1) ||
 	(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
     {
-        TSXCopyArea( display, dc->u.x.drawable, pixmap, gc,
+        XCopyArea( display, dc->u.x.drawable, pixmap, gc,
                    visRectDst->left, visRectDst->top, width, height, 0, 0 );
     }
     else
@@ -959,23 +959,23 @@
         XImage *image;
 
         if (dc->w.flags & DC_MEMORY)
-            image = TSXGetImage( display, dc->u.x.drawable,
+            image = XGetImage( display, dc->u.x.drawable,
                                visRectDst->left, visRectDst->top,
                                width, height, AllPlanes, ZPixmap );
         else
         {
             /* Make sure we don't get a BadMatch error */
-            TSXCopyArea( display, dc->u.x.drawable, pixmap, gc,
+            XCopyArea( display, dc->u.x.drawable, pixmap, gc,
                        visRectDst->left, visRectDst->top, width, height, 0, 0);
-            image = TSXGetImage( display, pixmap, 0, 0, width, height,
+            image = XGetImage( display, pixmap, 0, 0, width, height,
                                AllPlanes, ZPixmap );
         }
         for (y = 0; y < height; y++)
             for (x = 0; x < width; x++)
-                TSXPutPixel( image, x, y,
-                           COLOR_PixelToPalette[TSXGetPixel( image, x, y )]);
-        TSXPutImage( display, pixmap, gc, image, 0, 0, 0, 0, width, height );
-	TSXDestroyImage( image );
+                XPutPixel( image, x, y,
+                           COLOR_PixelToPalette[XGetPixel( image, x, y )]);
+        XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, width, height );
+	XDestroyImage( image );
     }
 }
 
@@ -996,23 +996,23 @@
     if (!COLOR_PaletteToPixel || (dc->w.bitsPerPixel == 1) || 
         (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
     {
-        TSXCopyArea( display, pixmap, dc->u.x.drawable, gc, 0, 0,
+        XCopyArea( display, pixmap, dc->u.x.drawable, gc, 0, 0,
                    width, height, visRectDst->left, visRectDst->top );
     }
     else
     {
         register INT32 x, y;
-        XImage *image = TSXGetImage( display, pixmap, 0, 0, width, height,
+        XImage *image = XGetImage( display, pixmap, 0, 0, width, height,
                                    AllPlanes, ZPixmap );
         for (y = 0; y < height; y++)
             for (x = 0; x < width; x++)
             {
-                TSXPutPixel( image, x, y,
-                           COLOR_PaletteToPixel[TSXGetPixel( image, x, y )]);
+                XPutPixel( image, x, y,
+                           COLOR_PaletteToPixel[XGetPixel( image, x, y )]);
             }
-        TSXPutImage( display, dc->u.x.drawable, gc, image, 0, 0,
+        XPutImage( display, dc->u.x.drawable, gc, image, 0, 0,
                    visRectDst->left, visRectDst->top, width, height );
-        TSXDestroyImage( image );
+        XDestroyImage( image );
     }
 }
 
@@ -1092,10 +1092,11 @@
  *
  * Implementation of PatBlt(), BitBlt() and StretchBlt().
  */
-BOOL32 BITBLT_InternalStretchBlt( DC *dcDst, INT32 xDst, INT32 yDst,
-                                  INT32 widthDst, INT32 heightDst,
-                                  DC *dcSrc, INT32 xSrc, INT32 ySrc,
-                                  INT32 widthSrc, INT32 heightSrc, DWORD rop )
+static BOOL32 BITBLT_InternalStretchBlt( DC *dcDst, INT32 xDst, INT32 yDst,
+                                         INT32 widthDst, INT32 heightDst,
+                                         DC *dcSrc, INT32 xSrc, INT32 ySrc,
+                                         INT32 widthSrc, INT32 heightSrc,
+                                         DWORD rop )
 {
     BOOL32 usePat, useSrc, useDst, destUsed, fStretch, fNullBrush;
     RECT32 visRectDst, visRectSrc;
@@ -1171,14 +1172,14 @@
     {
     case BLACKNESS:  /* 0x00 */
         if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
-            TSXSetFunction( display, dcDst->u.x.gc, GXclear );
+            XSetFunction( display, dcDst->u.x.gc, GXclear );
         else
         {
-            TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
-            TSXSetForeground( display, dcDst->u.x.gc, COLOR_PaletteToPixel[0] );
-            TSXSetFillStyle( display, dcDst->u.x.gc, FillSolid );
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+            XSetForeground( display, dcDst->u.x.gc, COLOR_PaletteToPixel[0] );
+            XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
         }
-        TSXFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
                         visRectDst.left, visRectDst.top, width, height );
         return TRUE;
 
@@ -1186,10 +1187,10 @@
         if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel ||
             !Options.perfectGraphics)
         {
-            TSXSetFunction( display, dcDst->u.x.gc, GXinvert );
+            XSetFunction( display, dcDst->u.x.gc, GXinvert );
 
             if( COLOR_GetSystemPaletteFlags() & (COLOR_PRIVATE | COLOR_VIRTUAL) )
-                TSXSetFunction( display, dcDst->u.x.gc, GXinvert);
+                XSetFunction( display, dcDst->u.x.gc, GXinvert);
             else
             {
                 /* Xor is much better when we do not have full colormap.   */
@@ -1197,11 +1198,11 @@
                 /* and white. */
                 Pixel xor_pix = (WhitePixelOfScreen(screen) ^
                                  BlackPixelOfScreen(screen));
-                TSXSetFunction( display, dcDst->u.x.gc, GXxor );
-                TSXSetForeground( display, dcDst->u.x.gc, xor_pix);
-                TSXSetFillStyle( display, dcDst->u.x.gc, FillSolid ); 
+                XSetFunction( display, dcDst->u.x.gc, GXxor );
+                XSetForeground( display, dcDst->u.x.gc, xor_pix);
+                XSetFillStyle( display, dcDst->u.x.gc, FillSolid ); 
             }
-            TSXFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+            XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
                             visRectDst.left, visRectDst.top, width, height ); 
             return TRUE;
         }
@@ -1211,8 +1212,8 @@
 	if (Options.perfectGraphics) break;
         if (DC_SetupGCForBrush( dcDst ))
         {
-            TSXSetFunction( display, dcDst->u.x.gc, GXxor );
-            TSXFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+            XSetFunction( display, dcDst->u.x.gc, GXxor );
+            XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
 			    visRectDst.left, visRectDst.top, width, height );
         }
         return TRUE;
@@ -1221,8 +1222,8 @@
 	if (Options.perfectGraphics) break;
 	if (DC_SetupGCForBrush( dcDst ))
 	{
-	    TSXSetFunction( display, dcDst->u.x.gc, GXequiv );
-	    TSXFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+	    XSetFunction( display, dcDst->u.x.gc, GXequiv );
+	    XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
 			    visRectDst.left, visRectDst.top, width, height );
 	}
 	return TRUE;
@@ -1230,58 +1231,58 @@
     case SRCCOPY:  /* 0xcc */
         if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
         {
-            TSXSetGraphicsExposures( display, dcDst->u.x.gc, True );
-            TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
-	    TSXCopyArea( display, dcSrc->u.x.drawable,
+            XSetGraphicsExposures( display, dcDst->u.x.gc, True );
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+	    XCopyArea( display, dcSrc->u.x.drawable,
                        dcDst->u.x.drawable, dcDst->u.x.gc,
                        visRectSrc.left, visRectSrc.top,
                        width, height, visRectDst.left, visRectDst.top );
-            TSXSetGraphicsExposures( display, dcDst->u.x.gc, False );
+            XSetGraphicsExposures( display, dcDst->u.x.gc, False );
             return TRUE;
         }
         if (dcSrc->w.bitsPerPixel == 1)
         {
-            TSXSetBackground( display, dcDst->u.x.gc, dcDst->w.textPixel );
-            TSXSetForeground( display, dcDst->u.x.gc, dcDst->w.backgroundPixel );
-            TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
-            TSXSetGraphicsExposures( display, dcDst->u.x.gc, True );
-	    TSXCopyPlane( display, dcSrc->u.x.drawable,
+            XSetBackground( display, dcDst->u.x.gc, dcDst->w.textPixel );
+            XSetForeground( display, dcDst->u.x.gc, dcDst->w.backgroundPixel );
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+            XSetGraphicsExposures( display, dcDst->u.x.gc, True );
+	    XCopyPlane( display, dcSrc->u.x.drawable,
                         dcDst->u.x.drawable, dcDst->u.x.gc,
                         visRectSrc.left, visRectSrc.top,
                         width, height, visRectDst.left, visRectDst.top, 1 );
-            TSXSetGraphicsExposures( display, dcDst->u.x.gc, False );
+            XSetGraphicsExposures( display, dcDst->u.x.gc, False );
             return TRUE;
         }
         break;
 
     case PATCOPY:  /* 0xf0 */
         if (!DC_SetupGCForBrush( dcDst )) return TRUE;
-        TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
-        TSXFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+        XSetFunction( display, dcDst->u.x.gc, GXcopy );
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
                         visRectDst.left, visRectDst.top, width, height );
         return TRUE;
 
     case WHITENESS:  /* 0xff */
         if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
-            TSXSetFunction( display, dcDst->u.x.gc, GXset );
+            XSetFunction( display, dcDst->u.x.gc, GXset );
         else
         {
-            TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
-            TSXSetForeground( display, dcDst->u.x.gc, 
+            XSetFunction( display, dcDst->u.x.gc, GXcopy );
+            XSetForeground( display, dcDst->u.x.gc, 
                             COLOR_PaletteToPixel[COLOR_GetSystemPaletteSize() - 1]);
-            TSXSetFillStyle( display, dcDst->u.x.gc, FillSolid );
+            XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
         }
-        TSXFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
                         visRectDst.left, visRectDst.top, width, height );
         return TRUE;
     }
 
-    tmpGC = TSXCreateGC( display, dcDst->u.x.drawable, 0, NULL );
-    pixmaps[DST] = TSXCreatePixmap( display, rootWindow, width, height,
+    tmpGC = XCreateGC( display, dcDst->u.x.drawable, 0, NULL );
+    pixmaps[DST] = XCreatePixmap( display, rootWindow, width, height,
                                   dcDst->w.bitsPerPixel );
     if (useSrc)
     {
-        pixmaps[SRC] = TSXCreatePixmap( display, rootWindow, width, height,
+        pixmaps[SRC] = XCreatePixmap( display, rootWindow, width, height,
                                       dcDst->w.bitsPerPixel );
         if (fStretch)
             BITBLT_GetSrcAreaStretch( dcSrc, dcDst, pixmaps[SRC], tmpGC,
@@ -1300,13 +1301,13 @@
     for (opcode = BITBLT_Opcodes[(rop >> 16) & 0xff]; *opcode; opcode++)
     {
         if (OP_DST(*opcode) == DST) destUsed = TRUE;
-        TSXSetFunction( display, tmpGC, OP_ROP(*opcode) );
+        XSetFunction( display, tmpGC, OP_ROP(*opcode) );
         switch(OP_SRCDST(*opcode))
         {
         case OP_ARGS(DST,TMP):
         case OP_ARGS(SRC,TMP):
             if (!pixmaps[TMP])
-                pixmaps[TMP] = TSXCreatePixmap( display, rootWindow,
+                pixmaps[TMP] = XCreatePixmap( display, rootWindow,
                                               width, height,
                                               dcDst->w.bitsPerPixel );
             /* fall through */
@@ -1314,32 +1315,32 @@
         case OP_ARGS(SRC,DST):
         case OP_ARGS(TMP,SRC):
         case OP_ARGS(TMP,DST):
-            TSXCopyArea( display, pixmaps[OP_SRC(*opcode)],
+            XCopyArea( display, pixmaps[OP_SRC(*opcode)],
                        pixmaps[OP_DST(*opcode)], tmpGC,
                        0, 0, width, height, 0, 0 );
             break;
 
         case OP_ARGS(PAT,TMP):
             if (!pixmaps[TMP] && !fNullBrush)
-                pixmaps[TMP] = TSXCreatePixmap( display, rootWindow,
+                pixmaps[TMP] = XCreatePixmap( display, rootWindow,
                                               width, height,
                                               dcDst->w.bitsPerPixel );
             /* fall through */
         case OP_ARGS(PAT,DST):
         case OP_ARGS(PAT,SRC):
             if (!fNullBrush)
-                TSXFillRectangle( display, pixmaps[OP_DST(*opcode)],
+                XFillRectangle( display, pixmaps[OP_DST(*opcode)],
                                 tmpGC, 0, 0, width, height );
             break;
         }
     }
-    TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
+    XSetFunction( display, dcDst->u.x.gc, GXcopy );
     BITBLT_PutDstArea( dcDst, pixmaps[destUsed ? DST : SRC],
                        dcDst->u.x.gc, &visRectDst );
-    TSXFreePixmap( display, pixmaps[DST] );
-    if (pixmaps[SRC]) TSXFreePixmap( display, pixmaps[SRC] );
-    if (pixmaps[TMP]) TSXFreePixmap( display, pixmaps[TMP] );
-    TSXFreeGC( display, tmpGC );
+    XFreePixmap( display, pixmaps[DST] );
+    if (pixmaps[SRC]) XFreePixmap( display, pixmaps[SRC] );
+    if (pixmaps[TMP]) XFreePixmap( display, pixmaps[TMP] );
+    XFreeGC( display, tmpGC );
     return TRUE;
 }
 
@@ -1380,7 +1381,11 @@
 {
     struct StretchBlt_params params = { dc, left, top, width, height,
                                         NULL, 0, 0, 0, 0, rop };
-    return (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
+    BOOL32 result;
+    EnterCriticalSection( &X11DRV_CritSection );
+    result = (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
+    LeaveCriticalSection( &X11DRV_CritSection );
+    return result;
 }
 
 
@@ -1393,7 +1398,11 @@
 {
     struct StretchBlt_params params = { dcDst, xDst, yDst, width, height,
                                         dcSrc, xSrc, ySrc, width, height, rop};
-    return (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
+    BOOL32 result;
+    EnterCriticalSection( &X11DRV_CritSection );
+    result = (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
+    LeaveCriticalSection( &X11DRV_CritSection );
+    return result;
 }
 
 
@@ -1408,5 +1417,9 @@
     struct StretchBlt_params params = { dcDst, xDst, yDst, widthDst, heightDst,
                                         dcSrc, xSrc, ySrc, widthSrc, heightSrc,
                                         rop };
-    return (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
+    BOOL32 result;
+    EnterCriticalSection( &X11DRV_CritSection );
+    result = (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
+    LeaveCriticalSection( &X11DRV_CritSection );
+    return result;
 }
diff --git a/graphics/x11drv/brush.c b/graphics/x11drv/brush.c
index efb7bb1..5c2fae1 100644
--- a/graphics/x11drv/brush.c
+++ b/graphics/x11drv/brush.c
@@ -107,6 +107,7 @@
     unsigned int x, y;
     Pixmap pixmap;
 
+    EnterCriticalSection( &X11DRV_CritSection );
     if (color != prevColor)
     {
 	int r = GetRValue( color ) * DITHER_LEVELS;
@@ -122,16 +123,17 @@
 		int dr = ((r + d) / MATRIX_SIZE_2) / 256;
 		int dg = ((g + d) / MATRIX_SIZE_2) / 256;
 		int db = ((b + d) / MATRIX_SIZE_2) / 256;
-		TSXPutPixel( ditherImage, x, y, PIXEL_VALUE(dr,dg,db) );
+		XPutPixel( ditherImage, x, y, PIXEL_VALUE(dr,dg,db) );
 	    }
 	}
 	prevColor = color;
     }
     
-    pixmap = TSXCreatePixmap( display, rootWindow,
-			    MATRIX_SIZE, MATRIX_SIZE, screenDepth );
-    TSXPutImage( display, pixmap, BITMAP_colorGC, ditherImage, 0, 0,
+    pixmap = XCreatePixmap( display, rootWindow,
+                            MATRIX_SIZE, MATRIX_SIZE, screenDepth );
+    XPutImage( display, pixmap, BITMAP_colorGC, ditherImage, 0, 0,
 	       0, 0, MATRIX_SIZE, MATRIX_SIZE );
+    LeaveCriticalSection( &X11DRV_CritSection );
     return pixmap;
 }
 
diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c
index cdb1073..da14d48 100644
--- a/graphics/x11drv/graphics.c
+++ b/graphics/x11drv/graphics.c
@@ -408,23 +408,25 @@
 
     x = dc->w.DCOrgX + XLPTODP( dc, x );
     y = dc->w.DCOrgY + YLPTODP( dc, y );
+    EnterCriticalSection( &X11DRV_CritSection );
     if (dc->w.flags & DC_MEMORY)
     {
-        image = TSXGetImage( display, dc->u.x.drawable, x, y, 1, 1,
+        image = XGetImage( display, dc->u.x.drawable, x, y, 1, 1,
                            AllPlanes, ZPixmap );
     }
     else
     {
         /* If we are reading from the screen, use a temporary copy */
         /* to avoid a BadMatch error */
-        if (!pixmap) pixmap = TSXCreatePixmap( display, rootWindow,
+        if (!pixmap) pixmap = XCreatePixmap( display, rootWindow,
                                              1, 1, dc->w.bitsPerPixel );
-        TSXCopyArea( display, dc->u.x.drawable, pixmap, BITMAP_colorGC,
+        XCopyArea( display, dc->u.x.drawable, pixmap, BITMAP_colorGC,
                    x, y, 1, 1, 0, 0 );
-        image = TSXGetImage( display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
+        image = XGetImage( display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
     }
-    pixel = TSXGetPixel( image, 0, 0 );
-    TSXDestroyImage( image );
+    pixel = XGetPixel( image, 0, 0 );
+    XDestroyImage( image );
+    LeaveCriticalSection( &X11DRV_CritSection );
     
     return COLOR_ToLogical(pixel);
 }
@@ -579,8 +581,8 @@
     int left, right;
 
 #define TO_FLOOD(x,y)  ((fillType == FLOODFILLBORDER) ? \
-                        (TSXGetPixel(image,x,y) != pixel) : \
-                        (TSXGetPixel(image,x,y) == pixel))
+                        (XGetPixel(image,x,y) != pixel) : \
+                        (XGetPixel(image,x,y) == pixel))
 
     if (!TO_FLOOD(x,y)) return;
 
@@ -589,15 +591,15 @@
     left = right = x;
     while ((left > 0) && TO_FLOOD( left-1, y )) left--;
     while ((right < image->width) && TO_FLOOD( right, y )) right++;
-    TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+    XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
                     xOrg + left, yOrg + y, right-left, 1 );
 
       /* Set the pixels of this line so we don't fill it again */
 
     for (x = left; x < right; x++)
     {
-        if (fillType == FLOODFILLBORDER) TSXPutPixel( image, x, y, pixel );
-        else TSXPutPixel( image, x, y, ~pixel );
+        if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
+        else XPutPixel( image, x, y, ~pixel );
     }
 
       /* Fill the line above */
@@ -637,6 +639,8 @@
  *          X11DRV_DoFloodFill
  *
  * Main flood-fill routine.
+ *
+ * The Xlib critical section must be entered before calling this function.
  */
 
 struct FloodFill_params
@@ -656,7 +660,7 @@
 
     if (GetRgnBox32( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
 
-    if (!(image = TSXGetImage( display, dc->u.x.drawable,
+    if (!(image = XGetImage( display, dc->u.x.drawable,
                              dc->w.DCOrgX + rect.left,
                              dc->w.DCOrgY + rect.top,
                              rect.right - rect.left,
@@ -666,7 +670,7 @@
     if (DC_SetupGCForBrush( dc ))
     {
           /* ROP mode is always GXcopy for flood-fill */
-        TSXSetFunction( display, dc->u.x.gc, GXcopy );
+        XSetFunction( display, dc->u.x.gc, GXcopy );
         X11DRV_InternalFloodFill(image, dc,
                                  XLPTODP(dc,params->x) - rect.left,
                                  YLPTODP(dc,params->y) - rect.top,
@@ -676,7 +680,7 @@
                                  params->fillType );
     }
 
-    TSXDestroyImage( image );
+    XDestroyImage( image );
     return TRUE;
 }
 
@@ -688,11 +692,15 @@
 X11DRV_ExtFloodFill( DC *dc, INT32 x, INT32 y, COLORREF color,
                      UINT32 fillType )
 {
+    BOOL32 result;
     struct FloodFill_params params = { dc, x, y, color, fillType };
 
     dprintf_graphics( stddeb, "X11DRV_ExtFloodFill %d,%d %06lx %d\n",
                       x, y, color, fillType );
 
     if (!PtVisible32( dc->hSelf, x, y )) return FALSE;
-    return CALL_LARGE_STACK( X11DRV_DoFloodFill, &params );
+    EnterCriticalSection( &X11DRV_CritSection );
+    result = CALL_LARGE_STACK( X11DRV_DoFloodFill, &params );
+    LeaveCriticalSection( &X11DRV_CritSection );
+    return result;
 }
diff --git a/graphics/x11drv/init.c b/graphics/x11drv/init.c
index 80ea04c..600c980 100644
--- a/graphics/x11drv/init.c
+++ b/graphics/x11drv/init.c
@@ -5,11 +5,11 @@
  */
 
 #include <string.h>
-#include "tsx11defs.h"
 #include "x11drv.h"
 #include "color.h"
 #include "bitmap.h"
 
+
 static BOOL32 X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
                                LPCSTR output, const DEVMODE16* initData );
 static BOOL32 X11DRV_DeleteDC( DC *dc );
@@ -109,8 +109,6 @@
  */
 BOOL32 X11DRV_Init(void)
 {
-    if (!TSX11_Init()) return FALSE;
-
     /* FIXME: colormap management should be merged with the X11DRV */
 
     if( !COLOR_Init() ) return FALSE;