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/objects/bitmap.c b/objects/bitmap.c
index fc59250..7d8a36d 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -42,7 +42,7 @@
 
 static int XPutImage_wrapper( const struct XPutImage_descr *descr )
 {
-    return TSXPutImage( display, descr->bmp->pixmap, BITMAP_GC(descr->bmp),
+    return XPutImage( display, descr->bmp->pixmap, BITMAP_GC(descr->bmp),
                       descr->image, 0, 0, 0, 0, descr->width, descr->height );
 }
 
@@ -235,7 +235,7 @@
  */
 XImage *BITMAP_GetXImage( const BITMAPOBJ *bmp )
 {
-    return TSXGetImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
+    return XGetImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
                       bmp->bitmap.bmHeight, AllPlanes, ZPixmap );
 }
 
@@ -284,6 +284,8 @@
       return 0;
     }
 
+    EnterCriticalSection( &X11DRV_CritSection );
+
     /* Hack: change the bitmap height temporarily to avoid */
     /*       getting unnecessary bitmap rows. */
     old_height = bmp->bitmap.bmHeight;
@@ -304,7 +306,7 @@
             {
                 if ((w%8) == 0)
                     *tbuf = 0;
-                *tbuf |= TSXGetPixel(image,w,h)<<(7-(w&7));
+                *tbuf |= XGetPixel(image,w,h)<<(7-(w&7));
                 if ((w&7) == 7) ++tbuf;
             }
             tbuf += pad;
@@ -315,8 +317,8 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-                if (!(w & 1)) *tbuf = TSXGetPixel( image, w, h) << 4;
-	    	else *tbuf++ |= TSXGetPixel( image, w, h) & 0x0f;
+                if (!(w & 1)) *tbuf = XGetPixel( image, w, h) << 4;
+	    	else *tbuf++ |= XGetPixel( image, w, h) & 0x0f;
             }
             tbuf += pad;
         }
@@ -325,7 +327,7 @@
         for (h=0;h<height;h++)
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
-                *tbuf++ = TSXGetPixel(image,w,h);
+                *tbuf++ = XGetPixel(image,w,h);
             tbuf += pad;
         }
         break;
@@ -335,7 +337,7 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-	    	long pixel = TSXGetPixel(image,w,h);
+	    	long pixel = XGetPixel(image,w,h);
 
 		*tbuf++ = pixel & 0xff;
 		*tbuf++ = (pixel>>8) & 0xff;
@@ -347,7 +349,7 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-	    	long pixel = TSXGetPixel(image,w,h);
+	    	long pixel = XGetPixel(image,w,h);
 
 		*tbuf++ = pixel & 0xff;
 		*tbuf++ = (pixel>> 8) & 0xff;
@@ -356,7 +358,9 @@
             tbuf += pad;
 	}
     }
-    TSXDestroyImage( image );
+    XDestroyImage( image );
+    LeaveCriticalSection( &X11DRV_CritSection );
+
     GDI_HEAP_UNLOCK( hbitmap );
     return height * bmp->bitmap.bmWidthBytes;
 }
@@ -411,10 +415,11 @@
 
     widthbytes	= DIB_GetXImageWidthBytes(bmp->bitmap.bmWidth,bmp->bitmap.bmBitsPixel);
     tmpbuffer	= (LPBYTE)xmalloc(widthbytes*height);
-    image = TSXCreateImage( display, DefaultVisualOfScreen(screen),
-		  bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
-		  bmp->bitmap.bmWidth,height,32,widthbytes
-    );
+
+    EnterCriticalSection( &X11DRV_CritSection );
+    image = XCreateImage( display, DefaultVisualOfScreen(screen),
+                          bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
+                          bmp->bitmap.bmWidth,height,32,widthbytes );
     
     /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
     sbuf = (LPBYTE)buffer;
@@ -425,7 +430,7 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-                TSXPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1);
+                XPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1);
                 if ((w&7) == 7)
                     sbuf++;
             }
@@ -437,8 +442,8 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-                if (!(w & 1)) TSXPutPixel( image, w, h, *sbuf >> 4 );
-                else TSXPutPixel( image, w, h, *sbuf++ & 0xf );
+                if (!(w & 1)) XPutPixel( image, w, h, *sbuf >> 4 );
+                else XPutPixel( image, w, h, *sbuf++ & 0xf );
             }
             sbuf += pad;
         }
@@ -447,7 +452,7 @@
         for (h=0;h<height;h++)
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
-                TSXPutPixel(image,w,h,*sbuf++);
+                XPutPixel(image,w,h,*sbuf++);
             sbuf += pad;
         }
         break;
@@ -457,7 +462,7 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-                TSXPutPixel(image,w,h,sbuf[1]*256+sbuf[0]);
+                XPutPixel(image,w,h,sbuf[1]*256+sbuf[0]);
                 sbuf+=2;
             }
         }
@@ -467,7 +472,7 @@
         {
             for (w=0;w<bmp->bitmap.bmWidth;w++)
             {
-                TSXPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]);
+                XPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]);
                 sbuf += 3;
             }
             sbuf += pad;
@@ -480,8 +485,9 @@
     descr.width  = bmp->bitmap.bmWidth;
     descr.height = height;
     CALL_LARGE_STACK( XPutImage_wrapper, &descr );
-
-    TSXDestroyImage( image ); /* frees tmpbuffer too */
+    XDestroyImage( image ); /* frees tmpbuffer too */
+    LeaveCriticalSection( &X11DRV_CritSection );
+    
     GDI_HEAP_UNLOCK( hbitmap );
     return height * bmp->bitmap.bmWidthBytes;
 }
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index e2a183a..888e95e 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -969,6 +969,7 @@
  *           CURSORICON_SetCursor
  *
  * Change the X cursor. Helper function for SetCursor() and ShowCursor().
+ * The Xlib critical section must be entered before calling this function.
  */
 static BOOL32 CURSORICON_SetCursor( HCURSOR16 hCursor )
 {
@@ -981,12 +982,12 @@
         static const char data[] = { 0 };
 
         bg.red = bg.green = bg.blue = 0x0000;
-        pixmapBits = TSXCreateBitmapFromData( display, rootWindow, data, 1, 1 );
+        pixmapBits = XCreateBitmapFromData( display, rootWindow, data, 1, 1 );
         if (pixmapBits)
         {
-            cursor = TSXCreatePixmapCursor( display, pixmapBits, pixmapBits,
+            cursor = XCreatePixmapCursor( display, pixmapBits, pixmapBits,
                                           &bg, &bg, 0, 0 );
-            TSXFreePixmap( display, pixmapBits );
+            XFreePixmap( display, pixmapBits );
         }
     }
     else  /* Create the X cursor from the bits */
@@ -1008,9 +1009,9 @@
 	 *	 as the Windows cursor data). Perhaps use a more generic
 	 *	 algorithm here.
 	 */
-        pixmapAll = TSXCreatePixmap( display, rootWindow,
+        pixmapAll = XCreatePixmap( display, rootWindow,
                                    ptr->nWidth, ptr->nHeight * 2, 1 );
-        image = TSXCreateImage( display, DefaultVisualOfScreen(screen),
+        image = XCreateImage( display, DefaultVisualOfScreen(screen),
                               1, ZPixmap, 0, (char *)(ptr + 1), ptr->nWidth,
                               ptr->nHeight * 2, 16, ptr->nWidthBytes);
         if (image)
@@ -1018,19 +1019,19 @@
             image->byte_order = MSBFirst;
             image->bitmap_bit_order = MSBFirst;
             image->bitmap_unit = 16;
-            TS_XInitImageFuncPtrs(image);
+            _XInitImageFuncPtrs(image);
             if (pixmapAll)
-                TSXPutImage( display, pixmapAll, BITMAP_monoGC, image,
+                XPutImage( display, pixmapAll, BITMAP_monoGC, image,
                            0, 0, 0, 0, ptr->nWidth, ptr->nHeight * 2 );
             image->data = NULL;
-            TSXDestroyImage( image );
+            XDestroyImage( image );
         }
 
         /* Now create the 2 pixmaps for bits and mask */
 
-        pixmapBits = TSXCreatePixmap( display, rootWindow,
+        pixmapBits = XCreatePixmap( display, rootWindow,
                                     ptr->nWidth, ptr->nHeight, 1 );
-        pixmapMask = TSXCreatePixmap( display, rootWindow,
+        pixmapMask = XCreatePixmap( display, rootWindow,
                                     ptr->nWidth, ptr->nHeight, 1 );
 
         /* Make sure everything went OK so far */
@@ -1059,39 +1060,39 @@
              * I don't know if it's correct per the X spec, but maybe
              * we ought to take advantage of it.  -- AJ
              */
-            TSXCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
+            XCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
                        0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
-            TSXCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
+            XCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
                        0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
-            TSXSetFunction( display, BITMAP_monoGC, GXandReverse );
-            TSXCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
+            XSetFunction( display, BITMAP_monoGC, GXandReverse );
+            XCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
                        0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
-            TSXSetFunction( display, BITMAP_monoGC, GXorReverse );
-            TSXCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
+            XSetFunction( display, BITMAP_monoGC, GXorReverse );
+            XCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
                        0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
-            TSXSetFunction( display, BITMAP_monoGC, GXcopy );
+            XSetFunction( display, BITMAP_monoGC, GXcopy );
             fg.red = fg.green = fg.blue = 0xffff;
             bg.red = bg.green = bg.blue = 0x0000;
-            cursor = TSXCreatePixmapCursor( display, pixmapBits, pixmapMask,
+            cursor = XCreatePixmapCursor( display, pixmapBits, pixmapMask,
                                 &fg, &bg, ptr->ptHotSpot.x, ptr->ptHotSpot.y );
         }
 
         /* Now free everything */
 
-        if (pixmapAll) TSXFreePixmap( display, pixmapAll );
-        if (pixmapBits) TSXFreePixmap( display, pixmapBits );
-        if (pixmapMask) TSXFreePixmap( display, pixmapMask );
+        if (pixmapAll) XFreePixmap( display, pixmapAll );
+        if (pixmapBits) XFreePixmap( display, pixmapBits );
+        if (pixmapMask) XFreePixmap( display, pixmapMask );
         GlobalUnlock16( hCursor );
     }
 
     if (cursor == None) return FALSE;
-    if (CURSORICON_XCursor != None) TSXFreeCursor( display, CURSORICON_XCursor );
+    if (CURSORICON_XCursor != None) XFreeCursor( display, CURSORICON_XCursor );
     CURSORICON_XCursor = cursor;
 
     if (rootWindow != DefaultRootWindow(display))
     {
         /* Set the cursor on the desktop window */
-        TSXDefineCursor( display, rootWindow, cursor );
+        XDefineCursor( display, rootWindow, cursor );
     }
     else
     {
@@ -1100,7 +1101,7 @@
         while(hwnd)
         {
             Window win = WIN_GetXWindow( hwnd );
-            if (win) TSXDefineCursor( display, win, cursor );
+            if (win) XDefineCursor( display, win, cursor );
             hwnd = GetWindow32( hwnd, GW_HWNDNEXT );
         }
     }
@@ -1130,7 +1131,11 @@
     hActiveCursor = hCursor;
     /* Change the cursor shape only if it is visible */
     if (CURSOR_ShowCount >= 0)
+    {
+        EnterCriticalSection( &X11DRV_CritSection );
         CALL_LARGE_STACK( CURSORICON_SetCursor, hActiveCursor );
+        LeaveCriticalSection( &X11DRV_CritSection );
+    }
     return hOldCursor;
 }
 
@@ -1172,6 +1177,7 @@
     dprintf_cursor( stddeb, "ShowCursor: %d, count=%d\n",
                     bShow, CURSOR_ShowCount );
 
+    EnterCriticalSection( &X11DRV_CritSection );
     if (bShow)
     {
         if (++CURSOR_ShowCount == 0)  /* Show it */
@@ -1182,6 +1188,7 @@
         if (--CURSOR_ShowCount == -1)  /* Hide it */
             CALL_LARGE_STACK( CURSORICON_SetCursor, 0 );
     }
+    LeaveCriticalSection( &X11DRV_CritSection );
     return CURSOR_ShowCount;
 }
 
diff --git a/objects/dc.c b/objects/dc.c
index b2041ef..a0ccb3f 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -276,15 +276,17 @@
         {
             register int x, y;
             XImage *image;
-            pixmap = TSXCreatePixmap( display, rootWindow, 8, 8, screenDepth );
-            image = TSXGetImage( display, dc->u.x.brush.pixmap, 0, 0, 8, 8,
+            EnterCriticalSection( &X11DRV_CritSection );
+            pixmap = XCreatePixmap( display, rootWindow, 8, 8, screenDepth );
+            image = XGetImage( display, dc->u.x.brush.pixmap, 0, 0, 8, 8,
                                AllPlanes, ZPixmap );
             for (y = 0; y < 8; y++)
                 for (x = 0; x < 8; x++)
-                    TSXPutPixel( image, x, y,
-                               COLOR_PixelToPalette[TSXGetPixel( image, x, y)] );
-            TSXPutImage( display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
-            TSXDestroyImage( image );
+                    XPutPixel( image, x, y,
+                               COLOR_PixelToPalette[XGetPixel( image, x, y)] );
+            XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
+            XDestroyImage( image );
+            LeaveCriticalSection( &X11DRV_CritSection );
             val.tile = pixmap;
         }
         else val.tile = dc->u.x.brush.pixmap;
diff --git a/objects/dib.c b/objects/dib.c
index f802f14..c4227ef 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -252,25 +252,25 @@
     for (i = dstwidth/8, x = left&~7; (i > 0); i--)
     {
 	pix = *bits++;
-	TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] );
-	TSXPutPixel( bmpImage, x++, h, colors[(pix >> 6) & 1] );
-	TSXPutPixel( bmpImage, x++, h, colors[(pix >> 5) & 1] );
-	TSXPutPixel( bmpImage, x++, h, colors[(pix >> 4) & 1] );
-	TSXPutPixel( bmpImage, x++, h, colors[(pix >> 3) & 1] );
-	TSXPutPixel( bmpImage, x++, h, colors[(pix >> 2) & 1] );
-	TSXPutPixel( bmpImage, x++, h, colors[(pix >> 1) & 1] );
-	TSXPutPixel( bmpImage, x++, h, colors[pix & 1] );
+	XPutPixel( bmpImage, x++, h, colors[pix >> 7] );
+	XPutPixel( bmpImage, x++, h, colors[(pix >> 6) & 1] );
+	XPutPixel( bmpImage, x++, h, colors[(pix >> 5) & 1] );
+	XPutPixel( bmpImage, x++, h, colors[(pix >> 4) & 1] );
+	XPutPixel( bmpImage, x++, h, colors[(pix >> 3) & 1] );
+	XPutPixel( bmpImage, x++, h, colors[(pix >> 2) & 1] );
+	XPutPixel( bmpImage, x++, h, colors[(pix >> 1) & 1] );
+	XPutPixel( bmpImage, x++, h, colors[pix & 1] );
     }
     pix = *bits;
     switch(dstwidth & 7)
     {
-    case 7: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
-    case 6: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
-    case 5: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
-    case 4: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
-    case 3: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
-    case 2: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
-    case 1: TSXPutPixel( bmpImage, x++, h, colors[pix >> 7] );
+    case 7: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
+    case 6: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
+    case 5: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
+    case 4: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
+    case 3: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
+    case 2: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
+    case 1: XPutPixel( bmpImage, x++, h, colors[pix >> 7] );
     }
 }
 
@@ -326,10 +326,10 @@
 	for (h = lines-1; h >= 0; h--) {
 	    for (i = dstwidth/2, x = left&~1; i > 0; i--) {
 		BYTE pix = *bits++;
-		TSXPutPixel( bmpImage, x++, h, colors[pix >> 4] );
-		TSXPutPixel( bmpImage, x++, h, colors[pix & 0x0f] );
+		XPutPixel( bmpImage, x++, h, colors[pix >> 4] );
+		XPutPixel( bmpImage, x++, h, colors[pix & 0x0f] );
 	    }
-	    if (dstwidth & 1) TSXPutPixel( bmpImage, x, h, colors[*bits >> 4] );
+	    if (dstwidth & 1) XPutPixel( bmpImage, x, h, colors[*bits >> 4] );
 	    srcbits += linebytes;
 	    bits	 = srcbits + (left >> 1);
 	}
@@ -338,10 +338,10 @@
 	for (h = 0; h < lines; h++) {
 	    for (i = dstwidth/2, x = left&~1; i > 0; i--) {
 		BYTE pix = *bits++;
-		TSXPutPixel( bmpImage, x++, h, colors[pix >> 4] );
-		TSXPutPixel( bmpImage, x++, h, colors[pix & 0x0f] );
+		XPutPixel( bmpImage, x++, h, colors[pix >> 4] );
+		XPutPixel( bmpImage, x++, h, colors[pix & 0x0f] );
 	    }
-	    if (dstwidth & 1) TSXPutPixel( bmpImage, x, h, colors[*bits >> 4] );
+	    if (dstwidth & 1) XPutPixel( bmpImage, x, h, colors[*bits >> 4] );
 	    srcbits += linebytes;
 	    bits	 = srcbits + (left >> 1);
 	}
@@ -375,11 +375,11 @@
 		if (length) {	/* encoded */
 			c = *bits++;
 			while (length--) {
-				TSXPutPixel(bmpImage, x++, lines, colors[c >> 4]);
+				XPutPixel(bmpImage, x++, lines, colors[c >> 4]);
 				check_xy(x, y);
 				if (length) {
 					length--;
-					TSXPutPixel(bmpImage, x++, lines, colors[c & 0xf]);
+					XPutPixel(bmpImage, x++, lines, colors[c & 0xf]);
 					check_xy(x, y);
 				}
 			}
@@ -402,11 +402,11 @@
 				default: /* absolute */
 					while (length--) {
 						c = *bits++;
-						TSXPutPixel(bmpImage, x++, lines, colors[c >> 4]);
+						XPutPixel(bmpImage, x++, lines, colors[c >> 4]);
 						check_xy(x, y);
 						if (length) {
 							length--;
-							TSXPutPixel(bmpImage, x++, lines, colors[c & 0xf]);
+							XPutPixel(bmpImage, x++, lines, colors[c & 0xf]);
 							check_xy(x, y);
 						}
 					}
@@ -438,7 +438,7 @@
     if (lines > 0) {
 	for (h = lines - 1; h >= 0; h--) {
 	    for (x = left; x < dstwidth; x++, bits++) {
-		TSXPutPixel( bmpImage, x, h, colors[*bits] );
+		XPutPixel( bmpImage, x, h, colors[*bits] );
 	    }
 	    bits = (srcbits += linebytes) + left;
 	}
@@ -446,7 +446,7 @@
 	lines = -lines;
 	for (h = 0; h < lines; h++) {
 	    for (x = left; x < dstwidth; x++, bits++) {
-		TSXPutPixel( bmpImage, x, h, colors[*bits] );
+		XPutPixel( bmpImage, x, h, colors[*bits] );
 	    }
 	    bits = (srcbits += linebytes) + left;
 	}
@@ -530,7 +530,7 @@
 		color = colors[color_index];
 
 		while(length--)
-		  TSXPutPixel(bmpImage, x++, line, color);
+		  XPutPixel(bmpImage, x++, line, color);
 	    }
 	  else 
 	    {    
@@ -595,7 +595,7 @@
 			  while(length--)
 			    {
 				color_index = (*pIn++);
-				TSXPutPixel(bmpImage, x++, line, 
+				XPutPixel(bmpImage, x++, line, 
 					  colors[color_index]);
 			    }
 			  
@@ -662,7 +662,7 @@
 		r = (BYTE) ((val & 0x7c00) >> 7);
 		g = (BYTE) ((val & 0x03e0) >> 2);
 		b = (BYTE) ((val & 0x001f) << 3);
-		TSXPutPixel( bmpImage, x, h,
+		XPutPixel( bmpImage, x, h,
 			   COLOR_ToPhysical(dc, RGB(r,g,b)) );
 	    }
 	    ptr = (LPWORD) (srcbits += linebytes) + left;
@@ -675,7 +675,7 @@
 		r = (BYTE) ((val & 0x7c00) >> 7);
 		g = (BYTE) ((val & 0x03e0) >> 2);
 		b = (BYTE) ((val & 0x001f) << 3);
-		TSXPutPixel( bmpImage, x, h,
+		XPutPixel( bmpImage, x, h,
 			   COLOR_ToPhysical(dc, RGB(r,g,b)) );
 	    }
 	    ptr = (LPWORD) (srcbits += linebytes) + left;
@@ -707,7 +707,7 @@
     if (lines > 0) {
 	for (h = lines - 1; h >= 0; h--) {
 	    for (x = left; x < dstwidth; x++, bits += 3) {
-		TSXPutPixel( bmpImage, x, h, 
+		XPutPixel( bmpImage, x, h, 
 			   COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
 	    }
 	    bits = (srcbits += linebytes) + left * 3;
@@ -716,7 +716,7 @@
 	lines = -lines;
 	for (h = 0; h < lines; h++) {
 	    for (x = left; x < dstwidth; x++, bits += 3) {
-		TSXPutPixel( bmpImage, x, h,
+		XPutPixel( bmpImage, x, h,
 			   COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
 	    }
 	    bits = (srcbits += linebytes) + left * 3;
@@ -745,7 +745,7 @@
     if (lines > 0) {
 	for (h = lines - 1; h >= 0; h--) {
 	    for (x = left; x < dstwidth; x++, bits += 4) {
-		TSXPutPixel( bmpImage, x, h, 
+		XPutPixel( bmpImage, x, h, 
 			   COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
 	    }
 	    bits = (srcbits += linebytes) + left * 4;
@@ -754,7 +754,7 @@
 	lines = -lines;
 	for (h = 0; h < lines; h++) {
 	    for (x = left; x < dstwidth; x++, bits += 4) {
-		TSXPutPixel( bmpImage, x, h,
+		XPutPixel( bmpImage, x, h,
 			   COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
 	    }
 	    bits = (srcbits += linebytes) + left * 4;
@@ -768,6 +768,7 @@
  *
  * Transfer the bits to an X image.
  * Helper function for SetDIBits() and SetDIBitsToDevice().
+ * The Xlib critical section must be entered before calling this function.
  */
 static int DIB_SetImageBits( const DIB_SETIMAGEBITS_DESCR *descr )
 {
@@ -831,10 +832,10 @@
         break;
     }
     if (colorMapping) HeapFree( GetProcessHeap(), 0, colorMapping );
-    TSXPutImage( display, descr->drawable, descr->gc, bmpImage,
+    XPutImage( display, descr->drawable, descr->gc, bmpImage,
                descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
                descr->width, descr->height );
-    TSXDestroyImage( bmpImage );
+    XDestroyImage( bmpImage );
     return lines;
 }
 
@@ -944,7 +945,10 @@
     descr.width     = bmp->bitmap.bmWidth;
     descr.height    = lines;
 
+    EnterCriticalSection( &X11DRV_CritSection );
     result = CALL_LARGE_STACK( DIB_SetImageBits, &descr );
+    LeaveCriticalSection( &X11DRV_CritSection );
+
     GDI_HEAP_UNLOCK( hdc );
     GDI_HEAP_UNLOCK( hbitmap );
     return result;
@@ -975,6 +979,7 @@
     DIB_SETIMAGEBITS_DESCR descr;
     DC * dc;
     DWORD width, oldcy = cy;
+    INT32 result;
     int height, tmpheight;
 
       /* Check parameters */
@@ -1018,7 +1023,10 @@
     descr.width     = cx;
     descr.height    = cy;
 
-    return CALL_LARGE_STACK( DIB_SetImageBits, &descr );
+    EnterCriticalSection( &X11DRV_CritSection );
+    result = CALL_LARGE_STACK( DIB_SetImageBits, &descr );
+    LeaveCriticalSection( &X11DRV_CritSection );
+    return result;
 }
 
 /***********************************************************************
@@ -1199,6 +1207,7 @@
             xend = info->bmiHeader.biWidth;
 	}
 
+        EnterCriticalSection( &X11DRV_CritSection );
 	bmpImage = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
 
 	switch( info->bmiHeader.biBitCount )
@@ -1209,7 +1218,7 @@
 		for( y = yend - 1; (int)y >= (int)startscan; y-- )
 		{
 		   for( x = 0; x < xend; x++ )
-			*bbits++ = TSXGetPixel( bmpImage, x, y );
+			*bbits++ = XGetPixel( bmpImage, x, y );
 		   bbits += pad;
 		}
 		break;
@@ -1220,7 +1229,7 @@
 		   *bbits = 0;
 		   for( x = 0; x < xend; x++ ) {
 		   	
-			*bbits |= TSXGetPixel( bmpImage, x, y)<<(7-(x&7));
+			*bbits |= XGetPixel( bmpImage, x, y)<<(7-(x&7));
 			if ((x&7)==7) {
 			    bbits++;
 			    *bbits=0;
@@ -1236,7 +1245,7 @@
 		   *bbits = 0;
 		   for( x = 0; x < xend; x++ ) {
 		   	
-			*bbits |= TSXGetPixel( bmpImage, x, y)<<(4*(1-(x&1)));
+			*bbits |= XGetPixel( bmpImage, x, y)<<(4*(1-(x&1)));
 			if ((x&1)==1) {
 			    bbits++;
 			    *bbits=0;
@@ -1252,7 +1261,7 @@
 		{
 		   *bbits = 0;
 		   for( x = 0; x < xend; x++ ) {
-		   	unsigned long pixel=TSXGetPixel( bmpImage, x, y);
+		   	unsigned long pixel=XGetPixel( bmpImage, x, y);
 			*bbits++ = pixel & 0xff;
 			*bbits++ = (pixel >> 8) & 0xff;
 		   }
@@ -1265,7 +1274,7 @@
 		{
 		   *bbits = 0;
 		   for( x = 0; x < xend; x++ ) {
-		   	unsigned long pixel=TSXGetPixel( bmpImage, x, y);
+		   	unsigned long pixel=XGetPixel( bmpImage, x, y);
 			*bbits++ = (pixel >>16) & 0xff;
 			*bbits++ = (pixel >> 8) & 0xff;
 			*bbits++ =  pixel       & 0xff;
@@ -1278,7 +1287,7 @@
 		{
 		   *bbits = 0;
 		   for( x = 0; x < xend; x++ ) {
-		   	unsigned long pixel=TSXGetPixel( bmpImage, x, y);
+		   	unsigned long pixel=XGetPixel( bmpImage, x, y);
 			*bbits++ = (pixel >>16) & 0xff;
 			*bbits++ = (pixel >> 8) & 0xff;
 			*bbits++ =  pixel       & 0xff;
@@ -1292,7 +1301,8 @@
 	   	break;
 	}
 
-	TSXDestroyImage( bmpImage );
+	XDestroyImage( bmpImage );
+        LeaveCriticalSection( &X11DRV_CritSection );
 
 	info->bmiHeader.biCompression = 0;
     }
diff --git a/objects/font.c b/objects/font.c
index 124663e..b1ac08d 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -1136,11 +1136,9 @@
  */
 BOOL32 WINAPI GetRasterizerCaps32( LPRASTERIZER_STATUS lprs, UINT32 cbNumBytes)
 {
-  RASTERIZER_STATUS rs;
-
-  rs.nSize = sizeof(rs);
-  rs.wFlags = 0;
-  rs.nLanguageID = 0;
+  lprs->nSize = sizeof(RASTERIZER_STATUS);
+  lprs->wFlags = TT_AVAILABLE|TT_ENABLED;
+  lprs->nLanguageID = 0;
   return TRUE;
 }
 
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index fe3c6f9..0557012 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -850,6 +850,28 @@
 
 
 /***********************************************************************
+ *           GdiSeeGdiDo   (GDI.452)
+ */
+DWORD WINAPI GdiSeeGdiDo( WORD wReqType, WORD wParam1, WORD wParam2,
+                          WORD wParam3 )
+{
+    switch (wReqType)
+    {
+    case 0x0001:  /* LocalAlloc */
+        return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
+    case 0x0002:  /* LocalFree */
+        return LOCAL_Free( GDI_HeapSel, wParam1 );
+    case 0x0003:  /* LocalCompact */
+        return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
+    case 0x0103:  /* LocalHeap */
+        return GDI_HeapSel;
+    default:
+        fprintf(stderr, "GdiSeeGdiDo: wReqType %04x (unknown)", wReqType);
+        return (DWORD)-1;
+    }
+}
+
+/***********************************************************************
  *           MulDiv16   (GDI.128)
  */
 INT16 WINAPI MulDiv16( INT16 foo, INT16 bar, INT16 baz )
diff --git a/objects/metafile.c b/objects/metafile.c
index b390b04..4d426d7 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -15,6 +15,7 @@
 #include "heap.h"
 #include "metafile.h"
 #include "metafiledrv.h"
+#include "toolhelp.h"
 #include "stddebug.h"
 #include "debug.h"
 
@@ -365,9 +366,9 @@
     METARECORD *mr;
     HANDLETABLE16 *ht;
     HGLOBAL16 hHT;
-    SEGPTR spht, spRecord;
+    SEGPTR spht;
     int offset = 0;
-    WORD i;
+    WORD i, seg;
     HPEN32 hPen;
     HBRUSH32 hBrush;
     HFONT32 hFont;
@@ -389,19 +390,20 @@
 		     sizeof(HANDLETABLE16) * mh->mtNoObjects);
     spht = WIN16_GlobalLock16(hHT);
    
+    seg = GlobalHandleToSel(hmf);
     offset = mh->mtHeaderSize * 2;
     
     /* loop through metafile records */
     
-    spRecord = WIN16_GlobalLock16(hmf);
     while (offset < (mh->mtSize * 2))
     {
 	mr = (METARECORD *)((char *)mh + offset);
         if (!lpEnumFunc( hdc, (HANDLETABLE16 *)spht,
-                         (METARECORD *)((UINT32)spRecord + offset),
-                         mh->mtNoObjects, (LONG)lpData)) {
-	  result = FALSE;
-	  break;
+			 (METARECORD *) PTR_SEG_OFF_TO_HUGEPTR(seg, offset),
+                         mh->mtNoObjects, (LONG)lpData ))
+	{
+	    result = FALSE;
+	    break;
 	}
 	
 
@@ -421,7 +423,7 @@
 
     /* free handle table */
     GlobalFree16(hHT);
-
+    GlobalUnlock16(hmf);
     return result;
 }
 
@@ -1025,7 +1027,7 @@
  * Warning: this function can change the metafile handle.
  */
 
-static BOOL32 MF_WriteRecord( DC *dc, METARECORD *mr, WORD rlen)
+static BOOL32 MF_WriteRecord( DC *dc, METARECORD *mr, DWORD rlen)
 {
     DWORD len;
     METAHEADER *mh;
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index 9fb5881..700e9fe 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -322,6 +322,8 @@
  *           OBM_CreateBitmaps
  *
  * Create the 2 bitmaps from XPM data.
+ *
+ * The Xlib critical section must be entered before calling this function.
  */
 static BOOL32 OBM_CreateBitmaps( OBM_BITMAP_DESCR *descr )
 {
@@ -330,14 +332,14 @@
     int err;
 
     attrs = (XpmAttributes *)HEAP_xalloc( GetProcessHeap(), 0,
-                                          TSXpmAttributesSize() );
+                                          XpmAttributesSize() );
     attrs->valuemask    = XpmColormap | XpmDepth | XpmColorSymbols |XpmHotspot;
     attrs->colormap     = COLOR_GetColormap();
     attrs->depth        = descr->color ? screenDepth : 1;
     attrs->colorsymbols = (attrs->depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
     attrs->numsymbols   = (attrs->depth > 1) ? NB_COLOR_SYMBOLS : 2;
         
-    err = TSXpmCreatePixmapFromData( display, rootWindow, descr->data,
+    err = XpmCreatePixmapFromData( display, rootWindow, descr->data,
                                    &pixmap, &pixmask, attrs );
 
     if (err != XpmSuccess)
@@ -355,8 +357,8 @@
     HeapFree( GetProcessHeap(), 0, attrs );
     if (!descr->bitmap)
     {
-        if (pixmap) TSXFreePixmap( display, pixmap );
-        if (pixmask) TSXFreePixmap( display, pixmask );
+        if (pixmap) XFreePixmap( display, pixmap );
+        if (pixmask) XFreePixmap( display, pixmask );
         if (descr->bitmap) GDI_FreeObject( descr->bitmap );
         if (descr->need_mask && descr->mask) GDI_FreeObject( descr->mask );
         return FALSE;
@@ -381,11 +383,14 @@
     descr.color     = OBM_Pixmaps_Data[id].color;
     descr.need_mask = FALSE;
 
+    EnterCriticalSection( &X11DRV_CritSection );
     if (!CALL_LARGE_STACK( OBM_CreateBitmaps, &descr ))
     {
+        LeaveCriticalSection( &X11DRV_CritSection );
         fprintf( stderr, "Error creating OEM bitmap %d\n", OBM_FIRST+id );
         return 0;
     }
+    LeaveCriticalSection( &X11DRV_CritSection );
     return descr.bitmap;
 }
 
@@ -424,11 +429,14 @@
     descr.color     = !fCursor;
     descr.need_mask = TRUE;
 
+    EnterCriticalSection( &X11DRV_CritSection );
     if (!CALL_LARGE_STACK( OBM_CreateBitmaps, &descr ))
     {
+        LeaveCriticalSection( &X11DRV_CritSection );
         fprintf( stderr, "Error creating OEM cursor/icon %d\n", id );
         return 0;
     }
+    LeaveCriticalSection( &X11DRV_CritSection );
 
     bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( descr.bitmap, BITMAP_MAGIC );
     bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( descr.mask, BITMAP_MAGIC );