Release 941030

Sun Oct 30 13:01:18 1994  Alexandre Julliard  (julliard@lamisun.epfl.ch)

	* [controls/static.c]
	Bug fix for SS_ICON controls.

	* [if1632/Imakefile]
	Fixed call.o dependencies.

	* [objects/clipping.c] [objects/dc.c]
	Fixed visible region handling. hVisRgn is always non-null now.

	* [windows/dce.c]
	Bug fix in GetDCEx for CS_OWNDC windows.

	* [windows/nonclient.c] [windows/painting.c]
	Fixes to icon window drawing.

	* [windows/winpos.c]
	A few fixes in SetWindowPos().

Sun Oct 30 12:50:24 1994  Michael Patra  <micky@marie.physik.tu-berlin.de>

	* [objects/bitblt.c]
	BitBlt(): BitBlt is now able to handle any raster operation. If
	the request can't be passed to XWindows directly, it's quite
	slow, though.

	* [*/*.c]
	  [misc/main.c]
	Improvements of the system for handling debug messages. Options are
	now also loaded from /usr/lib/X11/app-defaults/Wine (insert
	*debugoptions: +xxx there if you want to have turn messages xxx on).

	* [controls/menu.c]
	DestroyMenu(): The whole window won't be destroyed as a sideeffect
	any longer.

	* [misc/file.c]
	OpenFile(): Fixed bug in searching in system/window-directory.

Sun Oct 30 12:25:53 1994  Jimmy Tirtawangsa <j0t2527@tam2000.tamu.edu>

	* [include/windows.h]
	Bug fix for window related structures.
	DCB and COMSTAT are affected. They must be packed.

	* [misc/comm.c]
	Bug fix for COM ports:
	Dial and dialog window in terminal.exe now works.
	Non sequential COM assignments in wine.conf should not break now.
	Baudrate can be specified in wine.conf to overcome baudrate limitation
	in mswindow. See sample wine.ini

	* [include/comm.h]
	add baudrate field to DosDeviceStructre

	* [object/font.c]
	Bug fix for font assignment.
	Use pairs of foundry and family fontnames in X11 to correspond with
	window's fonts.
	Put font assignment ini wine.ini.

	* [wine.ini]
	Adding optional baudrate after port name in "serialports" section
	Add new section, "fonts".
	"default" is special key in "fonts" to match any unmatch window font.

Oct 29, 94 (new address) wine@trgcorp.mksinfo.qc.ca (Martin Ayotte)

	* [if1632/relay.c]
	* [if1632/commdlg.spec] 	New file.
	* [misc/commdlg.c] 			New file.
	* [include/commdlg.h] 		New file.
	Begin of an emulated COMMDLG DLL, built-in for now.
	(BTW, if you want to switch between built-in & 16bits CommDlg, only 
	thing you need to do is to put the real/dummy name in file relay.c)

	* [controls/scroll.c]
	* [controls/combo.c]
	* [controls/listbox.c]
	Few bug fixes and/or cosmetic.

	* [misc/audio.c]
	* [misc/mmaux.c]
	bug fixes and flags returned to emulate SB16.

	* [misc/midi.c] 			New file.
	skeleton for 'Midi' MMSYSTEM & MCI driver.

	* [misc/mcianim.c] 			New file.
	skeleton for 'Animation1' MCI driver.

	* [windows/win.c]
	Add new stub for GetLastActiveWindow().

Tue Oct 25 09:17:25 1994  Olaf Flebbe  (flebbe@tat.physik.uni-tuebingen.de)

	* [if1632/call.S] [tools/build.c]
           Support for ELF format. (Not complete)

Sun Oct 23 00:51:50 1994  Paul Falstad  (pf@zoof)

	* [if1632/user.spec]
	Add stubs for ArrangeIconicWindows(), etc.

	* [if1632/kernel.spec]
	Add IsBad*Ptr() functions.

	* [loader/signal.c]
	Add test_memory(), for use with IsBad*Ptr().

	* [windows/winpos.c]
	Add stubs for TileChildWindows(), etc.

	* [windows/win.c]
	IsWindow() shouldn't crash if it's given a bad handle.
	Add stub for GetLastActivePopup().

	* [memory/global.c]
	Implement the IsBad*Ptr() functions.

	* [controls/listbox.c]
	Return the full longword of the item data in LB_GETITEMDATA.

	* [controls/edit.c]
	Don't let the user select an area past the end of the text.

	* [objects/text.c]
	In DrawText(), the code to delete crlfs also removed multiple
	consecutive newlines.  Also, using DT_CALCRECT didn't return
	the right height, and the width wasn't returned at all.
	This caused MessageBoxes to be missing much of their text.

	* [windows/scroll.c]
	ScrollWindow[Ex] didn't work right with null LPRECT arguments.

Fri Oct 21 21:47:19 1994  Paul Falstad  (pf@zoof.cts.com)

	* [miscemu/int21.c]
	Fixed int21 0x42 handler to properly assemble 32-bit seek ptr.

	* [misc/property.c]
	Fixed inverted logic in EnumProps(), and changed CallBack16()
	call to use new arg format.

	* [windows/win.c]
	Fixed CallBack16() call in Enum[Child]Windows to use new arg
	format; this fixes crashes in enum procedures.

Wed Oct 19 21:30:00 PDT 1994		martin@cs.csufresno.edu

	* [misc/clipboard.c]
	  [windows/event.c]
	  [windows/message.c]
	Added cut and paste between Wine and other X clients via
	the PRIMARY selection. Text only this time.

	* [controls/edit.c]
	EDIT_LineLength, EDIT_TextLine return 0 for lines after last one.

	* [windows/defwnd.c]
	Send WM_SYSCOMMAND to overlapped ancestor window, 
	not the receiver of WM_SYSKEYDOWN

Sat Oct 22 15:01:02 1994  Thomas Sandford <t.d.g.sandford@bradford.ac.uk>

        * [controls/edit.c]
	ClientWidth()/ClientHeight() macros: return 0 if size would
	be negative
	EDIT_StrLength(): takes unsigned char* instead of char*

	* [controls/listbox.c]
	ListBoxWndProc(): in "case WM_MOUSEMOVE" - set lphl at start of
	case instead of in each place required (it was omitted in
	some places causing problems!)

	* [controls/menu.c]
	MENU_CalcItemSize(): don't try to find size of a text item
	if the pointer is NULL

	* [include/heap.h]
	added definition of HEAP_LocalInit()

	* [include/msdos.h]
	removed buggy pointer() macro (use SAFEMAKEPTR() from segmem.h
	instead)

	* [loader/selector.c]
	IPCCopySelector(): added missing flags to shmget() call
	? does this break linux - I added these flags in a previous
	patch but they were missing in the corresponding release ?

	* [loader/signal.c]
	win_fault(): added missing definitions of i, dump for those
	not running NetBSD or linux

	* [misc/dos_fs.c]
	DOS_GetCurrentDir(): made temp[] static so it can be safely
	returned

	* [miscemu/int21.c,int25.c,int26.c]
	Changed all invocations of pointer() to SAFEMAKEPTR(). Included
	segmem.h where necessary.

	* [windows/dialog.c]
	CreateDialogIndirectParam(): Changed HEAP_Init() call to 
	HEAP_LocalInit(), removed redundant variables

Sat Oct 22 00:29:41 MET 1994		  Dag Asheim (dash@ifi.uio.no)

	* [loader/library.c] [loader/main.c] [loader/ne_image.c]
	  [misc/exec.c] [miscemu/int10.c] [miscemu/int21.c]
	  [objects/bitblt.c] [objects/metafile.c]
	Rewritten more printf's to use the new debugging system, and
	made wine less verbose per default. Use "-debugmsg +module"
	to get (almost) the same behavior as before.
diff --git a/objects/bitblt.c b/objects/bitblt.c
index 47aa35c..0aa4e9a 100644
--- a/objects/bitblt.c
+++ b/objects/bitblt.c
@@ -15,11 +15,12 @@
 #include "metafile.h"
 #include "options.h"
 #include "stddebug.h"
-/* #define DEBUG_GDI /* */
-/* #undef  DEBUG_GDI /* */
+/* #define DEBUG_GDI */
+/* #undef  DEBUG_GDI */
 #include "debug.h"
 
 extern const int DC_XROPfunction[];
+extern Colormap COLOR_WinColormap;
 
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 #define MAX(a,b) ((a) > (b) ? (a) : (b))
@@ -41,7 +42,7 @@
 	return TRUE;
     }
 
-    dprintf_gdi(stddeb, "PatBlt: %d %d,%d %dx%d %06x\n",
+    dprintf_gdi(stddeb, "PatBlt: %d %d,%d %dx%d %06lx\n",
 	    hdc, left, top, width, height, rop );
 
       /* Convert ROP3 code to ROP2 code */
@@ -92,7 +93,7 @@
     DWORD saverop = rop;
     DC *dcDest, *dcSrc;
 
-    dprintf_gdi(stddeb, "BitBlt: %04x %d,%d %dx%d %04x %d,%d %08x\n",
+    dprintf_gdi(stddeb, "BitBlt: %04x %d,%d %dx%d %04x %d,%d %06lx\n",
                 hdcDest, xDest, yDest, width, height, hdcSrc, xSrc, ySrc, rop);
 
     if (width == 0 || height == 0) return FALSE;
@@ -100,12 +101,7 @@
 	return PatBlt( hdcDest, xDest, yDest, width, height, rop );
 
     rop >>= 16;
-    if ((rop & 0x0f) != (rop >> 4))
-    {
-	dprintf_gdi(stdnimp, "BitBlt: Unimplemented ROP %02x\n", rop );
-	return FALSE;
-    }
-    
+
     dcSrc = (DC *) GDI_GetObjPtr( hdcSrc, DC_MAGIC );
     if (!dcSrc) return FALSE;
     dcDest = (DC *) GDI_GetObjPtr( hdcDest, DC_MAGIC );
@@ -131,22 +127,128 @@
 	return FALSE;  /* Should call StretchBlt here */
     
     DC_SetupGCForText( dcDest );
-    XSetFunction( display, dcDest->u.x.gc, DC_XROPfunction[rop & 0x0f] );
-    if (dcSrc->w.bitsPerPixel == dcDest->w.bitsPerPixel)
-    {
-	XCopyArea( display, dcSrc->u.x.drawable,
-		   dcDest->u.x.drawable, dcDest->u.x.gc,
-		   min(xs1,xs2), min(ys1,ys2), abs(xs2-xs1), abs(ys2-ys1),
-		   min(xd1,xd2), min(yd1,yd2) );
-    }
+    if (((rop & 0x0f) == (rop >> 4))&&(rop!=0xbb))
+	/* FIXME: Test, whether more than just 0xbb has to be excluded */
+      {
+        XSetFunction( display, dcDest->u.x.gc, DC_XROPfunction[rop & 0x0f] );
+        if (dcSrc->w.bitsPerPixel == dcDest->w.bitsPerPixel)
+        {
+	    XCopyArea( display, dcSrc->u.x.drawable,
+	    	       dcDest->u.x.drawable, dcDest->u.x.gc,
+		       min(xs1,xs2), min(ys1,ys2), abs(xs2-xs1), abs(ys2-ys1),
+		       min(xd1,xd2), min(yd1,yd2) );
+        }
+        else
+        {
+	   if (dcSrc->w.bitsPerPixel != 1) return FALSE;
+	    XCopyPlane( display, dcSrc->u.x.drawable,
+	  	        dcDest->u.x.drawable, dcDest->u.x.gc,
+		        min(xs1,xs2), min(ys1,ys2), abs(xs2-xs1), abs(ys2-ys1),
+		        min(xd1,xd2), min(yd1,yd2), 1 );
+        }
+      }  
     else
-    {
-	if (dcSrc->w.bitsPerPixel != 1) return FALSE;
-	XCopyPlane( display, dcSrc->u.x.drawable,
-		    dcDest->u.x.drawable, dcDest->u.x.gc,
-		    min(xs1,xs2), min(ys1,ys2), abs(xs2-xs1), abs(ys2-ys1),
-		    min(xd1,xd2), min(yd1,yd2), 1 );
-    }
+      {
+        XImage *sxi, *dxi, *bxi;
+	int x,y,s,d,p,res,ofs,i,cp,cs,cd,cres;
+	XColor sentry,dentry,pentry,entry;
+	long colors[256];
+
+	/* HDC hdcBrush = CreateCompatibleDC(hdcDest);
+	DC *dcBrush;*/
+	RECT r = {min(xDest,xDest+width), min(yDest,yDest+height), 
+		  MAX(xDest,xDest+width), MAX(yDest,yDest+height)};
+	HBRUSH cur_brush=SelectObject(hdcDest, GetStockObject(BLACK_BRUSH));
+	SelectObject(hdcDest, cur_brush);
+        /* FillRect(hdcBrush, &r, cur_brush);*/
+        sxi=XGetImage(display, dcSrc->u.x.drawable, min(xs1,xs2), min(ys1,ys2), 
+             abs(xs2-xs1), abs(ys2-ys1), AllPlanes, ZPixmap);
+        dxi=XGetImage(display, dcDest->u.x.drawable, min(xd1,xd2),min(yd1,yd2), 
+             abs(xs2-xs1), abs(ys2-ys1), AllPlanes, ZPixmap);
+        /* dcBrush = (DC *) GDI_GetObjPtr( hdcBrush, DC_MAGIC );*/
+        /* bxi=XGetImage(display, dcBrush->u.x.drawable, min(xd1,xd2),min(yd1,yd2),
+             abs(xs2-xs1), abs(ys2-ys1), AllPlanes, ZPixmap);*/
+	/* FIXME: It's really not necessary to do this on the visible screen */
+        FillRect(hdcDest, &r, cur_brush);
+	bxi=XGetImage(display, dcDest->u.x.drawable, min(xd1,xd2),min(yd1,yd2),
+             abs(xs2-xs1), abs(ys2-ys1), AllPlanes, ZPixmap);
+        for (i=0; i<min(256,1<<(dcDest->w.bitsPerPixel)); i++)
+	{
+	  entry.pixel = i;
+	  XQueryColor ( display, COLOR_WinColormap, &entry);
+	  colors[i] = (int) RGB( entry.red>>8, entry.green>>8, entry.blue>>8 );
+	}
+	if (dcSrc->w.bitsPerPixel == dcDest->w.bitsPerPixel)
+        {
+ 	  for(x=0; x<abs(xs2-xs1); x++)
+	  {
+	    for(y=0; y<abs(ys2-ys1); y++)
+	    {
+	      s = XGetPixel(sxi, x, y);
+	      d = XGetPixel(dxi, x, y);
+	      p = XGetPixel(bxi, x, y);
+	      if (s<256)
+		cs=colors[s];
+	      else
+	      {
+	        sentry.pixel = s;
+		XQueryColor ( display, COLOR_WinColormap, &sentry);
+		cs = (int) RGB( sentry.red>>8,sentry.green>>8, sentry.blue>>8 );
+	      }
+	      if (d<256)
+		cd=colors[d];
+	      else
+	      {
+       		dentry.pixel = d;
+		XQueryColor ( display, COLOR_WinColormap, &dentry);
+		cd = (int) RGB( dentry.red>>8, dentry.green>>8,dentry.blue>>8 );
+	      }
+	      if (p<256)
+		cp=colors[p];
+	      else
+    	      {	      
+	        pentry.pixel = p;
+	        XQueryColor ( display, COLOR_WinColormap, &pentry);
+	        cp = (int) RGB( pentry.red>>8, pentry.green>>8,pentry.blue>>8 );
+	      }
+	      cres = 0;
+	      for(i=0; i<24; i++)
+ 	      {
+		ofs=1<<(((cp>>i)&1)*4+((cs>>i)&1)*2+((cd>>i)&1));
+		if (rop & ofs)
+		  cres |= (1<<i);
+	      }
+	      if (cres==cs)
+		res=s;
+	      else if (cres==cd)
+		res=d;
+	      else if (cres==cp)
+		res=p;
+	      else
+	      {
+		res = -1;
+	        for (i=0; i<min(256,1<<(dcDest->w.bitsPerPixel)); i++)
+		  if (colors[i]==cres)
+		  {
+		    res = i;
+		    break;
+	          }
+		if (res == -1)
+	          res = GetNearestPaletteIndex(dcDest->w.hPalette, res);
+	      } 	
+	      XPutPixel(dxi, x, y, res);
+	    }
+	  }
+        }
+	else
+	    fprintf(stderr,"BitBlt // depths different!\n");
+	XPutImage(display, dcDest->u.x.drawable, dcDest->u.x.gc,
+            dxi, 0, 0, min(xd1,xd2), min(yd1,yd2), abs(xs2-xs1), abs(ys2-ys1)+38);
+	XDestroyImage(sxi);
+        XDestroyImage(dxi);
+	XDestroyImage(bxi);
+	/*DeleteDC(hdcBrush);*/
+      }
     return TRUE;
 }
 
@@ -351,9 +453,8 @@
     XImage *sxi, *dxi;
     DWORD saverop = rop;
     WORD stretchmode;
-	BOOL	flg;
 
-    dprintf_gdi(stddeb, "StretchBlt: %d %d,%d %dx%d %d %d,%d %dx%d %08x\n",
+    dprintf_gdi(stddeb, "StretchBlt: %d %d,%d %dx%d %d %d,%d %dx%d %06lx\n",
            hdcDest, xDest, yDest, widthDest, heightDest, hdcSrc, xSrc, 
            ySrc, widthSrc, heightSrc, rop );
     dprintf_gdi(stddeb, "StretchMode is %x\n", 
@@ -376,7 +477,7 @@
     rop >>= 16;
     if ((rop & 0x0f) != (rop >> 4))
     {
-        dprintf_gdi(stdnimp, "StretchBlt: Unimplemented ROP %02x\n", rop );
+        fprintf(stdnimp, "StretchBlt: Unimplemented ROP %02lx\n", rop );
         return FALSE;
     }
 
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 0785559..2b540e6 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -27,7 +27,8 @@
   /* GCs used for B&W and color bitmap operations */
 GC BITMAP_monoGC = 0, BITMAP_colorGC = 0;
 
-extern void DC_InitDC( HDC hdc );  /* dc.c */
+extern void DC_InitDC( HDC hdc );                /* objects/dc.c */
+extern void CLIPPING_UpdateGCRegion( DC * dc );  /* objects/clipping.c */
 
 /***********************************************************************
  *           BITMAP_Init
@@ -296,12 +297,16 @@
 HBITMAP BITMAP_SelectObject( HDC hdc, DC * dc, HBITMAP hbitmap,
 			     BITMAPOBJ * bmp )
 {
+    HRGN hrgn;
     HBITMAP prevHandle = dc->w.hBitmap;
     
     if (!(dc->w.flags & DC_MEMORY)) return 0;
+    hrgn = CreateRectRgn( 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight );
+    if (!hrgn) return 0;
+
+    DeleteObject( dc->w.hVisRgn );
+    dc->w.hVisRgn    = hrgn;
     dc->u.x.drawable = bmp->pixmap;
-    dc->w.DCSizeX    = bmp->bitmap.bmWidth;
-    dc->w.DCSizeY    = bmp->bitmap.bmHeight;
     dc->w.hBitmap    = hbitmap;
 
       /* Change GC depth if needed */
@@ -313,6 +318,7 @@
 	dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
         DC_InitDC( hdc );
     }
+    else CLIPPING_UpdateGCRegion( dc );  /* Just update GC clip region */
     return prevHandle;
 }
 
diff --git a/objects/brush.c b/objects/brush.c
index 1a4ff72..6555d6c 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -232,6 +232,8 @@
     BITMAPINFO * bmpInfo;
     HBRUSH prevHandle = dc->w.hBrush;
 
+    dprintf_gdi(stddeb, "Brush_SelectObject   hdc=%04x  hbrush=%04x\n",
+		hdc,hbrush);
     if (dc->header.wMagic == METAFILE_DC_MAGIC)
     {
 	switch (brush->logbrush.lbStyle)
@@ -264,13 +266,16 @@
     switch(brush->logbrush.lbStyle)
     {
       case BS_NULL:
+	dprintf_gdi( stddeb,"BS_NULL\n" );
 	break;
 
       case BS_SOLID:
+        dprintf_gdi( stddeb,"BS_SOLID\n" );
 	BRUSH_SelectSolidBrush( dc, brush->logbrush.lbColor );
 	break;
 	
       case BS_HATCHED:
+	dprintf_gdi( stddeb, "BS_HATCHED\n" );
 	dc->u.x.brush.pixel = COLOR_ToPhysical( dc, brush->logbrush.lbColor );
 	dc->u.x.brush.pixmap = XCreateBitmapFromData( display, rootWindow,
 				 HatchBrushes[brush->logbrush.lbHatch], 8, 8 );
@@ -278,10 +283,12 @@
 	break;
 	
       case BS_PATTERN:
+	dprintf_gdi( stddeb, "BS_PATTERN\n");
 	BRUSH_SelectPatternBrush( dc, brush->logbrush.lbHatch );
 	break;
 
       case BS_DIBPATTERN:
+	dprintf_gdi( stddeb, "BS_DIBPATTERN\n");
 	if ((bmpInfo = (BITMAPINFO *) GlobalLock( brush->logbrush.lbHatch )))
 	{
 	    int size = DIB_BitmapInfoSize( bmpInfo, brush->logbrush.lbColor );
diff --git a/objects/clipping.c b/objects/clipping.c
index 26019dc..d6d8bba 100644
--- a/objects/clipping.c
+++ b/objects/clipping.c
@@ -10,8 +10,8 @@
 #include "gdi.h"
 #include "metafile.h"
 #include "stddebug.h"
-/* #define DEBUG_CLIPPING /* */
-/* #undef  DEBUG_CLIPPING /* */
+/* #define DEBUG_CLIPPING */
+/* #undef  DEBUG_CLIPPING */
 #include "debug.h"
 
 /***********************************************************************
@@ -19,32 +19,29 @@
  *
  * Set the clip region of the physical device.
  */
-void CLIPPING_SetDeviceClipping( DC * dc )
+static void CLIPPING_SetDeviceClipping( DC * dc )
 {
-    if (dc->w.hGCClipRgn)
+    RGNOBJ *obj = (RGNOBJ *) GDI_GetObjPtr(dc->w.hGCClipRgn, REGION_MAGIC);
+    if (!obj)
     {
-	RGNOBJ *obj = (RGNOBJ *) GDI_GetObjPtr(dc->w.hGCClipRgn, REGION_MAGIC);
-	if (obj->region.xrgn)
-	{
-	    XSetRegion( display, dc->u.x.gc, obj->region.xrgn );
-	    XSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
-	}
-	else if (obj->region.pixmap)
-	{
-	    XSetClipMask( display, dc->u.x.gc, obj->region.pixmap );
-	    XSetClipOrigin( display, dc->u.x.gc,
-			    dc->w.DCOrgX + obj->region.box.left,
-			    dc->w.DCOrgY + obj->region.box.top );
-	}
-	else  /* Clip everything */
-	{
-	    XSetClipRectangles( display, dc->u.x.gc, 0, 0, NULL, 0, 0 );
-	}
+        fprintf( stderr, "SetDeviceClipping: Rgn is 0. Please report this.\n");
+        exit(1);
     }
-    else
+    if (obj->region.xrgn)
     {
-	XSetClipMask( display, dc->u.x.gc, None );
-	XSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
+        XSetRegion( display, dc->u.x.gc, obj->region.xrgn );
+        XSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
+    }
+    else if (obj->region.pixmap)
+    {
+        XSetClipMask( display, dc->u.x.gc, obj->region.pixmap );
+        XSetClipOrigin( display, dc->u.x.gc,
+                       dc->w.DCOrgX + obj->region.box.left,
+                       dc->w.DCOrgY + obj->region.box.top );
+    }
+    else  /* Clip everything */
+    {
+        XSetClipRectangles( display, dc->u.x.gc, 0, 0, NULL, 0, 0 );
     }
 }
 
@@ -54,66 +51,47 @@
  *
  * Update the GC clip region when the ClipRgn or VisRgn have changed.
  */
-static void CLIPPING_UpdateGCRegion( DC * dc )
+void CLIPPING_UpdateGCRegion( DC * dc )
 {
-    if (!dc->w.hGCClipRgn) dc->w.hGCClipRgn = CreateRectRgn(0,0,0,0);
+    if (!dc->w.hGCClipRgn) dc->w.hGCClipRgn = CreateRectRgn( 0, 0, 0, 0 );
 
     if (!dc->w.hVisRgn)
     {
-	if (!dc->w.hClipRgn)
-	{
-	    DeleteObject( dc->w.hGCClipRgn );
-	    dc->w.hGCClipRgn = 0;
-	}
-	else
-	    CombineRgn( dc->w.hGCClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
+        fprintf( stderr, "UpdateGCRegion: hVisRgn is zero. Please report this.\n" );
+        exit(1);
     }
+    if (!dc->w.hClipRgn)
+        CombineRgn( dc->w.hGCClipRgn, dc->w.hVisRgn, 0, RGN_COPY );
     else
-    {
-	if (!dc->w.hClipRgn)
-	    CombineRgn( dc->w.hGCClipRgn, dc->w.hVisRgn, 0, RGN_COPY );
-	else
-	    CombineRgn( dc->w.hGCClipRgn, dc->w.hClipRgn, dc->w.hVisRgn, RGN_AND );
-    }
+        CombineRgn( dc->w.hGCClipRgn, dc->w.hClipRgn, dc->w.hVisRgn, RGN_AND );
     CLIPPING_SetDeviceClipping( dc );
 }
 
 
 /***********************************************************************
- *           CLIPPING_SelectRgn
- *
- * Helper function for SelectClipRgn() and SelectVisRgn().
- */
-static int CLIPPING_SelectRgn( DC * dc, HRGN * hrgnPrev, HRGN hrgn )
-{
-    int retval;
-    
-    if (hrgn)
-    {
-	if (!*hrgnPrev) *hrgnPrev = CreateRectRgn(0,0,0,0);
-	retval = CombineRgn( *hrgnPrev, hrgn, 0, RGN_COPY );
-    }
-    else
-    {
-	if (*hrgnPrev) DeleteObject( *hrgnPrev );
-	*hrgnPrev = 0;
-	retval = SIMPLEREGION; /* Clip region == client area */
-    }
-    CLIPPING_UpdateGCRegion( dc );
-    return retval;
-}
-
-
-/***********************************************************************
  *           SelectClipRgn    (GDI.44)
  */
 int SelectClipRgn( HDC hdc, HRGN hrgn )
 {
+    int retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;
-    
+
     dprintf_clipping(stddeb, "SelectClipRgn: %d %d\n", hdc, hrgn );
-    return CLIPPING_SelectRgn( dc, &dc->w.hClipRgn, hrgn );
+
+    if (hrgn)
+    {
+	if (!dc->w.hClipRgn) dc->w.hClipRgn = CreateRectRgn(0,0,0,0);
+	retval = CombineRgn( dc->w.hClipRgn, hrgn, 0, RGN_COPY );
+    }
+    else
+    {
+	if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
+	dc->w.hClipRgn = 0;
+	retval = SIMPLEREGION; /* Clip region == whole DC */
+    }
+    CLIPPING_UpdateGCRegion( dc );
+    return retval;
 }
 
 
@@ -122,11 +100,15 @@
  */
 int SelectVisRgn( HDC hdc, HRGN hrgn )
 {
+    int retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
-    if (!dc) return ERROR;
-    
+    if (!dc || !hrgn) return ERROR;
+
     dprintf_clipping(stddeb, "SelectVisRgn: %d %d\n", hdc, hrgn );
-    return CLIPPING_SelectRgn( dc, &dc->w.hVisRgn, hrgn );
+
+    retval = CombineRgn( dc->w.hVisRgn, hrgn, 0, RGN_COPY );
+    CLIPPING_UpdateGCRegion( dc );
+    return retval;
 }
 
 
@@ -161,62 +143,45 @@
  */
 int OffsetVisRgn( HDC hdc, short x, short y )
 {
+    int retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
     dprintf_clipping(stddeb, "OffsetVisRgn: %d %d,%d\n", hdc, x, y );
-
-    if (dc->w.hVisRgn)
-    {
-	int retval = OffsetRgn( dc->w.hVisRgn, x, y );
-	CLIPPING_UpdateGCRegion( dc );
-	return retval;
-    }
-    else return SIMPLEREGION; /* Clip region == client area */
+    retval = OffsetRgn( dc->w.hVisRgn, x, y );
+    CLIPPING_UpdateGCRegion( dc );
+    return retval;
 }
 
 
 /***********************************************************************
- *           CLIPPING_IntersectRect
+ *           CLIPPING_IntersectClipRect
  *
- * Helper function for {Intersect,Exclude}{Clip,Vis}Rect
+ * Helper function for {Intersect,Exclude}ClipRect
  */
-int CLIPPING_IntersectRect( DC * dc, HRGN * hrgn, short left, short top,
-			    short right, short bottom, int exclude )
+static int CLIPPING_IntersectClipRect( DC * dc, short left, short top,
+                                       short right, short bottom, BOOL exclude)
 {
-    HRGN tempRgn = 0, prevRgn = 0, newRgn = 0;
-    RGNOBJ *newObj, *prevObj;
-    int retval;
+    HRGN tempRgn, newRgn;
+    int ret;
 
-    if (!*hrgn)
+    if (!(newRgn = CreateRectRgn( 0, 0, 0, 0 ))) return ERROR;
+    if (!(tempRgn = CreateRectRgn( left, top, right, bottom )))
     {
-	if (!(*hrgn = CreateRectRgn( 0, 0, dc->w.DCSizeX, dc->w.DCSizeY )))
-	    goto Error;
-	prevRgn = *hrgn;
+        DeleteObject( newRgn );
+        return ERROR;
     }
-    if (!(newRgn = CreateRectRgn( 0, 0, 0, 0))) goto Error;
-    if (!(tempRgn = CreateRectRgn( left, top, right, bottom ))) goto Error;
-
-    retval = CombineRgn( newRgn, *hrgn, tempRgn, exclude ? RGN_DIFF : RGN_AND);
-    if (retval == ERROR) goto Error;
-
-    newObj = (RGNOBJ *) GDI_GetObjPtr( newRgn, REGION_MAGIC );
-    prevObj = (RGNOBJ *) GDI_GetObjPtr( *hrgn, REGION_MAGIC );
-    if (newObj && prevObj) newObj->header.hNext = prevObj->header.hNext;
+    ret = CombineRgn( newRgn, dc->w.hClipRgn ? dc->w.hClipRgn : dc->w.hVisRgn,
+                      tempRgn, exclude ? RGN_DIFF : RGN_AND);
     DeleteObject( tempRgn );
-    if (*hrgn) DeleteObject( *hrgn );
-    *hrgn = newRgn;    
-    CLIPPING_UpdateGCRegion( dc );
-    return retval;
 
- Error:
-    if (tempRgn) DeleteObject( tempRgn );
-    if (newRgn) DeleteObject( newRgn );
-    if (prevRgn)
+    if (ret != ERROR)
     {
-	DeleteObject( prevRgn );
-	*hrgn = 0;
+        if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
+        dc->w.hClipRgn = newRgn;    
+        CLIPPING_UpdateGCRegion( dc );
     }
-    return ERROR;
+    else DeleteObject( newRgn );
+    return ret;
 }
 
 
@@ -237,8 +202,7 @@
 
     dprintf_clipping(stddeb, "ExcludeClipRect: %d %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectRect( dc, &dc->w.hClipRgn, left, top,
-				   right, bottom, 1 );
+    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, TRUE );
 }
 
 
@@ -259,23 +223,55 @@
 
     dprintf_clipping(stddeb, "IntersectClipRect: %d %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectRect( dc, &dc->w.hClipRgn, left, top,
-				   right, bottom, 0 );
+    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, FALSE );
+}
+
+
+/***********************************************************************
+ *           CLIPPING_IntersectVisRect
+ *
+ * Helper function for {Intersect,Exclude}VisRect
+ */
+static int CLIPPING_IntersectVisRect( DC * dc, short left, short top,
+                                      short right, short bottom, BOOL exclude )
+{
+    HRGN tempRgn, newRgn;
+    int ret;
+
+    if (!(newRgn = CreateRectRgn( 0, 0, 0, 0 ))) return ERROR;
+    if (!(tempRgn = CreateRectRgn( left, top, right, bottom )))
+    {
+        DeleteObject( newRgn );
+        return ERROR;
+    }
+    ret = CombineRgn( newRgn, dc->w.hVisRgn, tempRgn,
+                      exclude ? RGN_DIFF : RGN_AND);
+    DeleteObject( tempRgn );
+
+    if (ret != ERROR)
+    {
+        RGNOBJ *newObj  = (RGNOBJ*)GDI_GetObjPtr( newRgn, REGION_MAGIC);
+        RGNOBJ *prevObj = (RGNOBJ*)GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC);
+        if (newObj && prevObj) newObj->header.hNext = prevObj->header.hNext;
+        DeleteObject( dc->w.hVisRgn );
+        dc->w.hVisRgn = newRgn;    
+        CLIPPING_UpdateGCRegion( dc );
+    }
+    else DeleteObject( newRgn );
+    return ret;
 }
 
 
 /***********************************************************************
  *           ExcludeVisRect    (GDI.73)
  */
-int ExcludeVisRect( HDC hdc, short left, short top,
-		    short right, short bottom )
+int ExcludeVisRect( HDC hdc, short left, short top, short right, short bottom )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
     dprintf_clipping(stddeb, "ExcludeVisRect: %d %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectRect( dc, &dc->w.hVisRgn, left, top,
-				   right, bottom, 1 );
+    return CLIPPING_IntersectVisRect( dc, left, top, right, bottom, TRUE );
 }
 
 
@@ -283,14 +279,13 @@
  *           IntersectVisRect    (GDI.98)
  */
 int IntersectVisRect( HDC hdc, short left, short top,
-		      short right, short bottom )
+                      short right, short bottom )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
     dprintf_clipping(stddeb, "IntersectVisRect: %d %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectRect( dc, &dc->w.hVisRgn, left, top,
-				   right, bottom, 0 );
+    return CLIPPING_IntersectVisRect( dc, left, top, right, bottom, FALSE );
 }
 
 
@@ -334,15 +329,7 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
     dprintf_clipping(stddeb, "GetClipBox: %d %p\n", hdc, rect );
-
-    if (dc->w.hGCClipRgn) return GetRgnBox( dc->w.hGCClipRgn, rect );
-    else
-    {
-	rect->top = rect->left = 0;
-	rect->right = dc->w.DCSizeX;
-	rect->bottom = dc->w.DCSizeY;
-	return SIMPLEREGION;
-    }
+    return GetRgnBox( dc->w.hGCClipRgn, rect );
 }
 
 
@@ -356,7 +343,11 @@
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return 0;
     dprintf_clipping(stddeb, "SaveVisRgn: %d\n", hdc );
-    if (!dc->w.hVisRgn) return 0;
+    if (!dc->w.hVisRgn)
+    {
+        fprintf( stderr, "SaveVisRgn: hVisRgn is zero. Please report this.\n" );
+        exit(1);
+    }
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
 	return 0;
     if (!(copy = CreateRectRgn( 0, 0, 0, 0 ))) return 0;
@@ -377,9 +368,8 @@
     HRGN saved;
     RGNOBJ *obj, *savedObj;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
-    if (!dc) return ERROR;    
+    if (!dc || !dc->w.hVisRgn) return ERROR;    
     dprintf_clipping(stddeb, "RestoreVisRgn: %d\n", hdc );
-    if (!dc->w.hVisRgn) return ERROR;
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
 	return ERROR;
     if (!(saved = obj->header.hNext)) return ERROR;
diff --git a/objects/dc.c b/objects/dc.c
index 5365efb..a38906c 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -21,7 +21,7 @@
 
 extern const WIN_DC_INFO DCVAL_defaultValues;
 
-extern void CLIPPING_SetDeviceClipping( DC * dc );     /* objects/clipping.c */
+extern void CLIPPING_UpdateGCRegion( DC * dc );     /* objects/clipping.c */
 extern WORD COLOR_ToPhysical( DC *dc, COLORREF color );/* objects/color.c */
 extern void COLOR_SetMapping( DC *dc, HANDLE, WORD );  /* objects/color.c */
 
@@ -110,7 +110,7 @@
     SelectObject( hdc, dc->w.hFont );
     XSetGraphicsExposures( display, dc->u.x.gc, False );
     XSetSubwindowMode( display, dc->u.x.gc, IncludeInferiors );
-    CLIPPING_SetDeviceClipping( dc );
+    CLIPPING_UpdateGCRegion( dc );
 }
 
 
@@ -242,17 +242,14 @@
     newdc->saveLevel = 0;
     newdc->w.flags |= DC_SAVED;
 
+    newdc->w.hGCClipRgn = 0;
+    newdc->w.hVisRgn = CreateRectRgn( 0, 0, 0, 0 );
+    CombineRgn( newdc->w.hVisRgn, dc->w.hVisRgn, 0, RGN_COPY );	
     if (dc->w.hClipRgn)
     {
 	newdc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
 	CombineRgn( newdc->w.hClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
     }
-    if (dc->w.hVisRgn)
-    {
-	newdc->w.hVisRgn = CreateRectRgn( 0, 0, 0, 0 );
-	CombineRgn( newdc->w.hVisRgn, dc->w.hVisRgn, 0, RGN_COPY );	
-    }
-    newdc->w.hGCClipRgn = 0;
     COLOR_SetMapping( newdc, dc->u.x.pal.hMapping, dc->u.x.pal.mappingSize );
     return handle;
 }
@@ -264,26 +261,31 @@
 void SetDCState( HDC hdc, HDC hdcs )
 {
     DC * dc, * dcs;
-    
+    HRGN hVisRgn, hClipRgn, hGCClipRgn;
+
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
     if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return;
     if (!dcs->w.flags & DC_SAVED) return;
     dprintf_dc(stddeb, "SetDCState: %d %d\n", hdc, hdcs );
-    if (dc->w.hClipRgn)	DeleteObject( dc->w.hClipRgn );
-    if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
-    if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
 
+      /* Save the regions before overwriting everything */
+    hVisRgn    = dc->w.hVisRgn;
+    hClipRgn   = dc->w.hClipRgn;
+    hGCClipRgn = dc->w.hGCClipRgn;
     memcpy( &dc->w, &dcs->w, sizeof(dc->w) );
     memcpy( &dc->u.x.pen, &dcs->u.x.pen, sizeof(dc->u.x.pen) );
-    dc->w.hClipRgn = dc->w.hVisRgn = dc->w.hGCClipRgn = 0;
     dc->w.flags &= ~DC_SAVED;
 
+      /* Restore the regions */
+    dc->w.hVisRgn    = hVisRgn;
+    dc->w.hClipRgn   = hClipRgn;
+    dc->w.hGCClipRgn = hGCClipRgn;
+    CombineRgn( dc->w.hVisRgn, dcs->w.hVisRgn, 0, RGN_COPY );
+    SelectClipRgn( hdc, dcs->w.hClipRgn );
+
     SelectObject( hdc, dcs->w.hBrush );
     SelectObject( hdc, dcs->w.hFont );
     COLOR_SetMapping( dc, dcs->u.x.pal.hMapping, dcs->u.x.pal.mappingSize );
-
-    SelectClipRgn( hdc, dcs->w.hClipRgn );
-    SelectVisRgn( hdc, dcs->w.hVisRgn );
 }
 
 
@@ -374,8 +376,13 @@
     dc->w.flags        = 0;
     dc->w.devCaps      = displayDevCaps;
     dc->w.bitsPerPixel = displayDevCaps->bitsPixel;
-    dc->w.DCSizeX      = displayDevCaps->horzRes;
-    dc->w.DCSizeY      = displayDevCaps->vertRes;
+    dc->w.hVisRgn      = CreateRectRgn( 0, 0, displayDevCaps->horzRes,
+                                        displayDevCaps->vertRes );
+    if (!dc->w.hVisRgn)
+    {
+        GDI_HEAP_FREE( handle );
+        return 0;
+    }
 
     DC_InitDC( handle );
 
@@ -426,9 +433,15 @@
     dc->w.flags        = DC_MEMORY;
     dc->w.bitsPerPixel = 1;
     dc->w.devCaps      = displayDevCaps;
-    dc->w.DCSizeX      = 1;
-    dc->w.DCSizeY      = 1;
     dc->w.hBitmap      = hbitmap;
+    dc->w.hVisRgn      = CreateRectRgn( 0, 0, 1, 1 );
+
+    if (!dc->w.hVisRgn)
+    {
+        DeleteObject( hbitmap );
+        GDI_HEAP_FREE( handle );
+        return 0;
+    }
 
     DC_InitDC( handle );
 
diff --git a/objects/dcvalues.c b/objects/dcvalues.c
index c1fafaf..2def05b 100644
--- a/objects/dcvalues.c
+++ b/objects/dcvalues.c
@@ -45,8 +45,6 @@
     MM_TEXT,                /* MapMode */
     0,                      /* DCOrgX */
     0,                      /* DCOrgY */
-    0,                      /* DCSizeX */
-    0,                      /* DCSizeY */
     0,                      /* CursPosX */
     0,                      /* CursPosY */
     0,                      /* WndOrgX */
diff --git a/objects/font.c b/objects/font.c
index 1a28d6c..111984d 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -48,6 +48,47 @@
 #define CI_GET_DEFAULT_INFO(fs,cs) \
   CI_GET_CHAR_INFO(fs, fs->default_char, NULL, cs)
 
+struct FontStructure {
+	char *window;
+	char *x11;
+} FontNames[32];
+int FontSize;
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
+ *           Font_Init
+ */
+
+void Font_Init( void )
+{
+  char  temp[1024];
+  LPSTR ptr;
+  int i;
+
+  if( GetPrivateProfileString("fonts", NULL, "*", temp, sizeof(temp), WINE_INI) > 2 ) {
+    for( ptr = temp, i = 1; strlen(ptr) != 0; ptr += strlen(ptr) + 1, i++ )
+      if( strcmp( ptr, "default" ) )
+	FontNames[i].window = strdup( ptr );
+    FontSize = i;
+
+    for( i = 1; i < FontSize; i++ ) {
+      GetPrivateProfileString("fonts", FontNames[i].window, "*", temp, sizeof(temp), WINE_INI);
+      FontNames[i].x11 = strdup( temp );
+    }
+    GetPrivateProfileString("fonts", "default", "*", temp, sizeof(temp), WINE_INI);
+    if( *temp == '*' )
+      FontNames[0].x11 = strdup( temp );
+
+  } else {
+    FontNames[0].window = NULL; FontNames[0].x11 = "bitstream-courier";
+    FontNames[1].window = "ms sans serif"; FontNames[1].x11 = "*-helvetica";
+    FontNames[2].window = "ms serif"; FontNames[2].x11 = "*-times";
+    FontNames[3].window = "fixedsys"; FontNames[3].x11 = "*-fixed";
+    FontNames[4].window = "arial"; FontNames[4].x11 = "*-helvetica";
+    FontNames[5].window = "helv"; FontNames[5].x11 = "*-helvetica";
+    FontNames[6].window = "roman"; FontNames[6].x11 = "*-times";
+    FontSize = 7;
+  }
+}
 
 /***********************************************************************
  *           FONT_TranslateName
@@ -57,26 +98,14 @@
  */
 static const char *FONT_TranslateName( char *winFaceName )
 {
-    int i;
-    static const char *mappings[] =
-    {
-        /*Windows name*/  /*X11 name*/
-        "system",         "helvetica",
-        "ms sans serif",  "helvetica",
-        "ms serif",       "times",
-        "fixedsys",       "fixed",
-        "arial",          "helvetica",
-        "helv",           "helvetica",
-        "roman",          "times"
-    };
+  int i;
 
-    for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); i += 2)
-        if (!strcmp( winFaceName, mappings[i] ))
-        {
-            dprintf_font(stddeb, "---- Mapped %s to %s\n", winFaceName, mappings[i+1] );
-            return mappings[i+1];
-        }
-    return winFaceName;
+  for (i = 1; i < FontSize; i ++)
+    if( !strcmp( winFaceName, FontNames[i].window ) ) {
+      dprintf_font(stddeb, "---- Mapped %s to %s\n", winFaceName, FontNames[i].x11 );
+      return FontNames[i].x11;
+    }
+  return FontNames[0].x11;
 }
 
 
@@ -100,25 +129,37 @@
     width = font->lfWidth * 10;
     spacing = (font->lfPitchAndFamily & FIXED_PITCH) ? 'm' :
 	      (font->lfPitchAndFamily & VARIABLE_PITCH) ? 'p' : '*';
-    charset = (font->lfCharSet == ANSI_CHARSET) ? "iso8859-1" : "*";
+    charset = (font->lfCharSet == ANSI_CHARSET) ? "iso8859-1" : "*-*";
     if (*font->lfFaceName) family = FONT_TranslateName( font->lfFaceName );
     else switch(font->lfPitchAndFamily & 0xf0)
     {
-      case FF_ROMAN:      family = "times"; break;
-      case FF_SWISS:      family = "helvetica"; break;
-      case FF_MODERN:     family = "courier"; break;
-      case FF_SCRIPT:     family = "*"; break;
-      case FF_DECORATIVE: family = "*"; break;
-      default:            family = "*"; break;
+    case FF_ROMAN:
+      family = FONT_TranslateName( "roman" );
+      break;
+    case FF_SWISS:
+      family = FONT_TranslateName( "swiss" );
+      break;
+    case FF_MODERN:
+      family = FONT_TranslateName( "modern" );
+      break;
+    case FF_SCRIPT:
+      family = FONT_TranslateName( "script" );
+      break;
+    case FF_DECORATIVE:
+      family = FONT_TranslateName( "decorative" );
+      break;
+    default:
+      family = FontNames[0].x11;
+      break;
     }
     
 	while (TRUE) {
 	    /* Width==0 seems not to be a valid wildcard on SGI's, using * instead */
 	    if ( width == 0 )
-	      sprintf( pattern, "-*-%s-%s-%c-normal-*-*-%d-*-*-%c-*-%s",
+	      sprintf( pattern, "-%s-%s-%c-normal-*-*-%d-*-*-%c-*-%s",
 		      family, weight, slant, height, spacing, charset);
 	    else
-	      sprintf( pattern, "-*-%s-%s-%c-normal-*-*-%d-*-*-%c-%d-%s",
+	      sprintf( pattern, "-%s-%s-%c-normal-*-*-%d-*-*-%c-%d-%s",
 		      family, weight, slant, height, spacing, width, charset);
 	    dprintf_font(stddeb, "FONT_MatchFont: '%s'\n", pattern );
 	    names = XListFonts( display, pattern, 1, &count );
@@ -525,9 +566,9 @@
     slant = 'r';
     spacing = '*';
     charset = "*";
-    family = "*";
+    family = "*-*";
     dprintf_font(stddeb,"InitFontsList !\n");
-    sprintf( pattern, "-*-%s-%s-%c-normal-*-*-*-*-*-%c-*-%s",
+    sprintf( pattern, "-%s-%s-%c-normal-*-*-*-*-*-%c-*-%s",
 	      family, weight, slant, spacing, charset);
     names = XListFonts( display, pattern, MAX_FONTS, &count );
     dprintf_font(stddeb,"InitFontsList // count=%d \n", count);
diff --git a/objects/metafile.c b/objects/metafile.c
index 83cf4c4..8715bf7 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -897,7 +897,7 @@
 BOOL MF_BitBlt(DC *dcDest, short xDest, short yDest, short width,
 	       short height, HDC hdcSrc, short xSrc, short ySrc, DWORD rop)
 {
-    dprintf_metafile(stdnimp,"MF_BitBlt: not implemented yet\n");
+    fprintf(stdnimp,"MF_BitBlt: not implemented yet\n");
 }
 
 
@@ -908,5 +908,5 @@
 		   short heightDest, HDC hdcSrc, short xSrc, short ySrc, 
 		   short widthSrc, short heightSrc, DWORD rop)
 {
-    dprintf_metafile(stdnimp,"MF_StretchBlt: not implemented yet\n");
+    fprintf(stdnimp,"MF_StretchBlt: not implemented yet\n");
 }
diff --git a/objects/text.c b/objects/text.c
index 95b2eb7..e45973e 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -62,9 +62,9 @@
 	case LF:
 	    if (!(format & DT_SINGLELINE))
 	    {
-		i++;
-		if (str[i] == CR || str[i] == LF)
+		if (str[i] == CR && str[i+1] == LF)
 		    i++;
+		i++;
 		*len = j;
 		return (&str[i]);
 	    }
@@ -188,6 +188,7 @@
     TEXTMETRIC tm;
     int x = rect->left, y = rect->top;
     int width = rect->right - rect->left;
+    int max_width = 0;
 
     dprintf_text(stddeb,"DrawText: '%s', %d , [(%d,%d),(%d,%d)]\n", str, count,
 	   rect->left, rect->top, rect->right, rect->bottom);
@@ -237,8 +238,12 @@
 	    else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
 	}
 	if (!(flags & DT_CALCRECT))
+	{
 	    if (!ExtTextOut( hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
                              rect, line, len, NULL )) return 0;
+	}
+	else if (size.cx > max_width)
+	    max_width = size.cx;
 
 	if (prefix_offset != -1)
 	{
@@ -250,9 +255,9 @@
 	    DeleteObject( hpen );
 	}
 
+	y += lh;
 	if (strPtr)
 	{
-	    y += lh;
 	    if (!(flags & DT_NOCLIP))
 	    {
 		if (y > rect->bottom - lh)
@@ -261,7 +266,11 @@
 	}
     }
     while (strPtr);
-    if (flags & DT_CALCRECT) rect->bottom = y;
+    if (flags & DT_CALCRECT)
+    {
+	rect->right = rect->left + max_width;
+	rect->bottom = y;
+    }
     return 1;
 }