preparations for DC, PEN & BRUSH caching (does not work yet);
authorClaus Gittinger <cg@exept.de>
Mon, 28 Sep 1998 11:25:02 +0200
changeset 2369 72986787c2b0
parent 2368 a7bd567cd899
child 2370 5f45f0d30fba
preparations for DC, PEN & BRUSH caching (does not work yet); fixed lineWidth when drawing points;
WinWorkstat.st
WinWorkstation.st
--- a/WinWorkstat.st	Fri Sep 25 20:25:25 1998 +0200
+++ b/WinWorkstat.st	Mon Sep 28 11:25:02 1998 +0200
@@ -30,31 +30,31 @@
 #define WIN32THREADS
 /*#define DEBUGMASK*/
 
-# undef INT
-# define INT WIN_INT
-# undef Array
-# define Array WIN_Array
-# undef Number
-# define Number WIN_Number
-# undef Method
-# define Method WIN_Method
-# undef Point
-# define Point WIN_Point
-# undef Rectangle
-/*# define Rectangle WIN_Rectangle*/
-# undef True
-# define True WIN_True
-# undef False
-# define False WIN_False
-# undef Block
-# define Block WIN_Block
-# undef Context
-# define Context WIN_Context
-
-# undef xxCONTEXT
-# define xxCONTEXT        WIN_CONTEXT
-# undef _xxCONTEXT
-# define _xxCONTEXT       _WIN_CONTEXT
+#undef INT
+#define INT WIN_INT
+#undef Array
+#define Array WIN_Array
+#undef Number
+#define Number WIN_Number
+#undef Method
+#define Method WIN_Method
+#undef Point
+#define Point WIN_Point
+#undef Rectangle
+/* #define Rectangle WIN_Rectangle*/
+#undef True
+#define True WIN_True
+#undef False
+#define False WIN_False
+#undef Block
+#define Block WIN_Block
+#undef Context
+#define Context WIN_Context
+
+#undef xxCONTEXT
+#define xxCONTEXT        WIN_CONTEXT
+#undef _xxCONTEXT
+#define _xxCONTEXT       _WIN_CONTEXT
 
 
 #include <stdio.h>
@@ -101,32 +101,33 @@
 
 #include <process.h>
 
-#   ifdef __DEF_Array
-#    undef Array
-#    define Array __DEF_Array
-#   endif
-#   ifdef __DEF_Number
-#    undef Number
-#    define Number __DEF_Number
-#   endif
-#   ifdef __DEF_Method
-#    undef Method
-#    define Method __DEF_Method
-#   endif
-#   ifdef __DEF_Point
-#    undef Point
-#    define Point __DEF_Point
-#   endif
-#   ifdef __DEF_Block
-#    undef Block
-#    define Block __DEF_Block
-#   endif
-#   ifdef __DEF_Context
-#    undef Context
-#    define Context __DEF_Context
-#   endif
-#   undef INT
-#   define INT int
+#ifdef __DEF_Array
+# undef Array
+# define Array __DEF_Array
+#endif
+#ifdef __DEF_Number
+# undef Number
+# define Number __DEF_Number
+#endif
+#ifdef __DEF_Method
+# undef Method
+# define Method __DEF_Method
+#endif
+#ifdef __DEF_Point
+# undef Point
+# define Point __DEF_Point
+#endif
+#ifdef __DEF_Block
+# undef Block
+# define Block __DEF_Block
+#endif
+#ifdef __DEF_Context
+# undef Context
+# define Context __DEF_Context
+#endif
+#undef INT
+
+#define INT int
 
 /*
  * some defines - tired of typing ...
@@ -154,22 +155,22 @@
     int         clipY;
     int         clipW;
     int         clipH;
-    int         clipByChild;
+    short       clipByChild;
+    short       bitmapColorBitCount;
     HDC         _hDC;
     HBITMAP     hMask;
     int         maskOrgX;
     int         maskOrgY;
-    int         bitmapColorBitCount;
-    int         lineWidth;
-    int         lineStyle;
-    int         joinStyle;
-    int         capStyle;
-    int         fontAscent;
+    short       lineWidth;
+    short       fontAscent;
+    int         lStyle;   /* is lineStyle | joinStyle | capStyle */
     int         rop2;
     int         bitbltrop2;
     COLORREF    fgColor;
     COLORREF    bgColor;
     HFONT       hFont;
+    HPEN        hPen;
+    HBRUSH      hBrush;
 };
 
 /*
@@ -248,13 +249,13 @@
 #define MappingNotify           34
 #define LASTEvent               35      /* must be bigger than any event # */
 
-/*# define Button1MotionMask      1
-# define Button2MotionMask      2
-# define Button3MotionMask      4
-
-# define Button1Mask            Button1MotionMask
-# define Button2Mask            Button2MotionMask
-# define Button3Mask            Button3MotionMask*/
+/*#define Button1MotionMask      1
+#define Button2MotionMask       2
+#define Button3MotionMask       4
+
+#define Button1Mask             Button1MotionMask
+#define Button2Mask             Button2MotionMask
+#define Button3Mask             Button3MotionMask*/
 
 /* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
    state in various key-, mouse-, and button-related events. */
@@ -284,11 +285,11 @@
 /* button masks.  Used in same manner as Key masks above. Not to be confused
    with button names below. */
 
-# define Button1Mask            Button1MotionMask
-# define Button2Mask            Button2MotionMask
-# define Button3Mask            Button3MotionMask
-# define Button4Mask            Button4MotionMask
-# define Button5Mask            Button5MotionMask
+#define Button1Mask            Button1MotionMask
+#define Button2Mask            Button2MotionMask
+#define Button3Mask            Button3MotionMask
+#define Button4Mask            Button4MotionMask
+#define Button5Mask            Button5MotionMask
 
 #define AnyModifier             (1<<15)  /* used in GrabButton, GrabKey */
 
@@ -307,11 +308,11 @@
 #define CAPTURE_IMPLICIT 7
 #define CAPTURE_EXPLICIT 8
 
-/*# define ControlMask            8
-# define ShiftMask              16*/
-# define LeftAltMask            Mod1Mask
-# define RightAltMask           Mod2Mask
-# define TRANSLATED_KEY         Mod5Mask
+/*#define ControlMask            8
+#define ShiftMask              16*/
+#define LeftAltMask            Mod1Mask
+#define RightAltMask           Mod2Mask
+#define TRANSLATED_KEY         Mod5Mask
 
 #define WIN32PADDING 32
 /*
@@ -325,8 +326,8 @@
 static int AltMask = RightAltMask;
 static int MetaMask = LeftAltMask;
 
-# define WhitePixel     RGB(0xFF, 0xFF, 0xFF)
-# define BlackPixel     RGB(0, 0, 0)
+#define WhitePixel     RGB(0xFF, 0xFF, 0xFF)
+#define BlackPixel     RGB(0, 0, 0)
 
 /*#undef DEBUG*/
 #ifdef DEBUG
@@ -364,12 +365,12 @@
 	__win32_fprintf __x__;           \
     }
 
-# define BR_SOLID       0
-# define BR_PATTERN     1
-
-# define LINE_SOLID     0
-# define LINE_DASH      1
-# define LINE_DDASH     2
+#define BR_SOLID       0
+#define BR_PATTERN     1
+
+#define LINE_SOLID     0
+#define LINE_DASH      1
+#define LINE_DDASH     2
 
 #ifdef KEEP_STD_CURSORS
 # define _C_ARROW       1
@@ -411,7 +412,12 @@
 static HDC tmpDC;
 static int __isWinNT;
 static int __logPixelSY;
-static struct gcData *lastGcData;
+static struct gcData *lastGcData = 0;
+static int            lastGcOwnerThreadID = 0;
+
+#define xxCACHE_LAST_DC
+#define xxCACHE_LAST_PEN
+#define xxCACHE_LAST_BRUSH
 
 #define WM_THREADCREATEWINDOW   WM_USER + 0x101
 #define WM_THREADDESTROYWINDOW  WM_USER + 0x102
@@ -420,9 +426,10 @@
 #define WM_THREADSETCURSOR      WM_USER + 0x105
 
 #define THREADINPUTEVENTNAME "InputEvents"
-#define THREADEVENTNAME "CreateEvents"
-#define THREADMUTEXNAME "MutexToProtectEvents"
-#define isInputEvent() ((int)eventQueueHead)
+#define THREADEVENTNAME      "CreateEvents"
+#define THREADMUTEXNAME      "MutexToProtectEvents"
+
+#define hasEventQueued() ((int)eventQueueHead)
 
 typedef int (*intf)(int);
 
@@ -431,8 +438,8 @@
  */
 #define LI_TOPWIN       0x0001
 #define LI_INPUTWIN     0x0002
-typedef struct
-{
+
+typedef struct {
 	HCURSOR hCursor;
 	int bgBrush;
 	int flag;
@@ -517,6 +524,12 @@
 #define BITBLT_AND              SRCAND
 #define BITBLT_OR               SRCPAINT
 
+/*
+ * need threadSafe printf versions
+ */
+#define printf  __win32_printf
+#define fprintf __win32_fprintf
+#define fflush  __win32_fflush
 
 %}
 ! !
@@ -535,7 +548,7 @@
 static HDESK __rootDesk;
 #endif
 
-static int buttonClickWindowsLike = 1;
+static int activateOnClick = 1;
 
 static int currentCapture = CAPTURE_NONE;
 static int lastNCMouseX, lastNCMouseY;
@@ -680,7 +693,7 @@
 {
     int r = DeleteObject(o);
     if (r == 0)
-	__win32_fprintf(stderr, "WinWorkstation: ERROR in DelObjectect\n");
+	fprintf(stderr, "WinWorkstation: ERROR in DelObjectect\n");
     return r;
 }
 
@@ -693,14 +706,15 @@
     }
     memset(gcData, 0, sizeof(struct gcData));
     gcData->fgColor = 0xffffff;
+    /* gcData->bgColor = 0; - not needed - memset does it */
     gcData->clipping = FALSE;
     gcData->clipByChild = TRUE;
     gcData->bitbltrop2 = BITBLT_COPY;
     gcData->lineWidth = 1;
-    gcData->lineStyle = PS_SOLID;
-    gcData->joinStyle = PS_JOIN_MITER;
-    gcData->capStyle = PS_ENDCAP_FLAT;
+    gcData->lStyle = PS_SOLID | PS_JOIN_MITER | PS_ENDCAP_FLAT;
     /* gcData->brushOrgX = gcData->brushOrgY = 0; - not needed - memset does it */
+    /* gcData->hPen = 0; - not needed - memset does it */
+    /* gcData->hBrush = 0; - not needed - memset does it */
     return gcData;
 }
 
@@ -709,30 +723,78 @@
 {
 }
 
+#ifdef CACHE_LAST_DC
+# define FLUSH_CACHED_DC(__gcData__) \
+    if (lastGcData == __gcData__) {  \
+	_releaseDC(lastGcData);      \
+    }
+#else
+# define FLUSH_CACHED_DC(x)     /* */
+#endif
+
+#ifdef CACHE_LAST_PEN
+# define FLUSH_CACHED_PEN(__gcData__) \
+    if (__gcData__->hPen) {           \
+	DelObject(gcData->hPen);      \
+	gcData->hPen = 0;             \
+    }
+#else
+# define FLUSH_CACHED_PEN(x)    /* */
+#endif
+
+#ifdef CACHE_LAST_BRUSH
+# define FLUSH_CACHED_BRUSH(__gcData__) \
+    if (__gcData__->hBrush) {           \
+	DelObject(gcData->hBrush);      \
+	gcData->hBrush = 0;             \
+    }
+#else
+# define FLUSH_CACHED_BRUSH(x)    /* */
+#endif
+
 static void
 _releaseDC(struct gcData *gcData)
 {
     if (gcData->hWnd) {
 	if (gcData->_hDC) {
-	    ReleaseDC(gcData->hWnd,gcData->_hDC);
+	    ReleaseDC(gcData->hWnd, gcData->_hDC);
 	}
     } else if (gcData->hBitmap) {
-	SelectObject(gcData->_hDC,gcData->savehBitmap);
+	SelectObject(gcData->_hDC, gcData->savehBitmap);
 	DeleteDC(gcData->_hDC);
     }
+
+#ifdef CACHE_LAST_PEN
+    if (gcData->hPen) {
+	DelObject(gcData->hPen);
+	gcData->hPen = 0;
+    }
+#endif
+#ifdef CACHE_LAST_BRUSH
+    if (gcData->hBrush) {
+	DelObject(gcData->hBrush);
+	gcData->hBrush = 0;
+    }
+#endif
+#ifdef CACHE_LAST_DC
+    if (lastGcData == gcData) {
+	lastGcData = 0;
+    }
+#endif
     gcData->_hDC = 0;
 }
 
 static HDC
 _getDC(struct gcData *gcData)
 {
-#if 0
+#ifdef CACHE_LAST_DC
     if (lastGcData) {
-	if (lastGcData == gcData) {
+	if ((lastGcData == gcData) 
+	 && (lastGcOwnerThreadID == GetCurrentThreadId())) {
 	    //printf(".");
 	    return gcData->_hDC;
 	}
-	__releaseDC(lastGcData);
+	_releaseDC(lastGcData);
     }
 #endif
 
@@ -771,7 +833,10 @@
 	    }
 	}
     }
+#ifdef CACHE_LAST_DC
     lastGcData = gcData;
+    lastGcOwnerThreadID == GetCurrentThreadId();
+#endif
     return gcData->_hDC;
 }
 
@@ -780,6 +845,11 @@
 {
     HBRUSH hBrush = 0;
 
+#ifdef CACHE_LAST_BRUSH
+    if (gcData->hBrush) {
+	return gcData->hBrush;
+    }
+#endif
     if (gcData->hMask) {
 	hBrush = CreatePatternBrush(gcData->hMask);
 	SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);       
@@ -788,95 +858,101 @@
 	hBrush = CreateSolidBrush(gcData->fgColor);
 	RESPRINTF(("CreateSolidBrush %x\n",gcData->fgColor));
     }
+#ifdef CACHE_LAST_BRUSH
+    gcData->hBrush = hBrush;
+#endif
     return hBrush;
 }
 
 static HPEN
-GcDataGetPen(HDC hDC,struct gcData *gcData)
+GcDataGetPen(HDC hDC, struct gcData *gcData)
 {
     HPEN hPen = 0;
     LOGBRUSH Brush;
 
-    if (__isWinNT)
-    {
-      if (gcData->hMask)
-      {
-	  Brush.lbStyle = BS_PATTERN;
-	  Brush.lbHatch = (DWORD)gcData->hMask;
-	  Brush.lbColor = gcData->fgColor;
-	  hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
-			    gcData->lineWidth,
-			    &Brush,
-			    0,0);
-	  SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
-	  RESPRINTF(("ExtCreatePen %d %d %x %x\n",gcData->lineStyle,
-						gcData->lineWidth,
-						gcData->fgColor,gcData->hMask));
-      }
-      else
-      {
-	  Brush.lbStyle = BS_SOLID;
-	  Brush.lbHatch = 0;
-	  Brush.lbColor = gcData->fgColor;
-	  hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
-			    gcData->lineWidth,
-			    &Brush,
-			    0,0);
-	  RESPRINTF(("ExtCreatePen1 %d %d %x %x\n",gcData->lineStyle,
-
-						gcData->lineWidth,
-						gcData->fgColor,gcData->hMask));
-      }
-    }
-    else
-    {
-      if (gcData->lineStyle == PS_SOLID)
-      {
-	if (gcData->hMask)
-	{
+#ifdef CACHE_LAST_PEN
+    if (gcData->hPen) {
+	return gcData->hPen;
+    }
+#endif
+    if (__isWinNT) {
+	/*
+	 * NT supports masked drawing with any lineStyle
+	 */
+	if (gcData->hMask) {
 	    Brush.lbStyle = BS_PATTERN;
 	    Brush.lbHatch = (DWORD)gcData->hMask;
 	    Brush.lbColor = gcData->fgColor;
-	    hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
-			      gcData->lineWidth,
-			      &Brush,
-			      0,0);
-	    SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
-	    RESPRINTF(("ExtCreatePen %d %d %x %x\n",gcData->lineStyle,
-						  gcData->lineWidth,
-						  gcData->fgColor,gcData->hMask));
-	}
-	else
-	{
+	} else {
 	    Brush.lbStyle = BS_SOLID;
 	    Brush.lbHatch = 0;
 	    Brush.lbColor = gcData->fgColor;
-	    hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
+	}
+
+	hPen = ExtCreatePen(PS_GEOMETRIC | gcData->lStyle,
+			  gcData->lineWidth,
+			  &Brush,
+			  0, 0);
+	RESPRINTF(("ExtCreatePen1 %x %d %x %x\n",
+			gcData->lStyle,
+			gcData->lineWidth,
+			gcData->fgColor, gcData->hMask));
+
+	if (gcData->hMask) {
+	    SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
+	}
+    } else {
+	/*
+	 * W95 only supports masked drawing with SOLID lines
+	 */
+	if ((gcData->lStyle & PS_STYLE_MASK) == PS_SOLID) {
+	    if (gcData->hMask) {
+		Brush.lbStyle = BS_PATTERN;
+		Brush.lbHatch = (DWORD)gcData->hMask;
+		Brush.lbColor = gcData->fgColor;
+	    } else {
+		Brush.lbStyle = BS_SOLID;
+		Brush.lbHatch = 0;
+		Brush.lbColor = gcData->fgColor;
+	    }
+
+	    hPen = ExtCreatePen(PS_GEOMETRIC | gcData->lStyle,
 			      gcData->lineWidth,
 			      &Brush,
-			      0,0);
-	    RESPRINTF(("ExtCreatePen1 %d %d %x %x\n",gcData->lineStyle,
-						  gcData->lineWidth,
-						  gcData->fgColor,gcData->hMask));
-	}
-      }
-    }
-    if (! hPen) {
-	if (gcData->lineStyle == PS_SOLID)
-	    hPen = CreatePen(gcData->lineStyle,
-			     gcData->lineWidth,
-			     gcData->fgColor);
-	else
-	    hPen = CreatePen(gcData->lineStyle,
-			     0,
-			     gcData->fgColor);
-
-	RESPRINTF(("CreatePen %d %d %x\n",gcData->lineStyle,
-					  gcData->lineWidth,
-					  gcData->fgColor));
-	//SetTextColor(gcData->_hDC, gcData->fgColor);
-	SetBkMode(gcData->_hDC, TRANSPARENT);
-    }
+			      0, 0);
+	    RESPRINTF(("ExtCreatePen1 %x %d %x %x\n",
+			    gcData->lStyle,
+			    gcData->lineWidth,
+			    gcData->fgColor, gcData->hMask));
+	    if (gcData->hMask) {
+		SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
+	    }
+	} else {
+	    /*
+	     * dashes only supported with lineWidth 0
+	     */
+	    if ((gcData->lStyle & PS_STYLE_MASK) == PS_SOLID) {
+		hPen = CreatePen((gcData->lStyle & PS_STYLE_MASK),
+				 gcData->lineWidth,
+				 gcData->fgColor);
+	    } else {
+		hPen = CreatePen((gcData->lStyle & PS_STYLE_MASK),
+				 0,
+				 gcData->fgColor);
+	    }
+	    RESPRINTF(("CreatePen %x %d %x\n",
+				(gcData->lStyle & PS_STYLE_MASK),
+				gcData->lineWidth,
+				gcData->fgColor));
+	    //SetTextColor(gcData->_hDC, gcData->fgColor);
+	    SetBkMode(gcData->_hDC, TRANSPARENT);
+	}
+    }
+
+#ifdef CACHE_LAST_PEN
+    gcData->hPen = hPen;
+#endif
+
     return hPen;
 }
 
@@ -936,7 +1012,7 @@
     bulk = (struct queuedEvent *) malloc(EV_CHUNK_SZ);
     if (bulk == 0)
     {
-	__win32_fprintf(stderr, "WinWorkstation: no memory for dispatchqueue\n");
+	fprintf(stderr, "WinWorkstation: no memory for dispatchqueue\n");
 	return 0;
     }
     for (i=1; i<EV_CHUNK_CNT; i++) {
@@ -991,7 +1067,7 @@
 	     goto again;
 	  }
 	}
-	__win32_fprintf(stderr, "WinWorkstation: event throw away\n");
+	fprintf(stderr, "WinWorkstation: event throw away\n");
 	/* throw away sorry */
 	return;
       }
@@ -1009,104 +1085,87 @@
 {
   struct queuedEvent *ev = 0;
 
-  if (mask != ~0)
-  {
-    PRINTF(("deqEvent mask:%x\n",mask));
+  if (mask != ~0) {
+      PRINTF(("deqEvent mask:%x\n",mask));
   }
-  if (hWnd)
-  {
-    PRINTF(("deqEvent hWnd:%x\n",hWnd));
+  if (hWnd) {
+      PRINTF(("deqEvent hWnd:%x\n",hWnd));
   }
-  if (lockEvent())
-  {
-
-    while (TRUE)
-    {
-      TH_DPRINTF(("TDEQ\n"));
-      ev = eventQueueHead;
-      if (ev)
-      {
-	eventQueueHead = ev->ev_next;
-	if (! eventQueueHead)
-	{
-	    eventQueueTail = (struct queuedEvent *)0;
-	}
-	if (eventempfcount != ev->count)
-	{
-	  printf("eventcount error %d <-> %d\n",eventempfcount,ev->count);
-	}
-	eventempfcount++;
-	if (ev->ev_message == WM_DESTROY)
-	{
-	    if (ev->ev_arg2)
-	    {
-	      free((char*)ev->ev_arg2);
-	    }
-#ifdef TOPWINDOWCLASS
-	    if (ev->ev_arg1)
-	    {
-	      if (UnregisterClass((char*)ev->ev_arg1,(HANDLE) __getHInstance()))
-	      {
-		/*printf("UnregisterClass %s ok.\n",(char*)ev->ev_arg1);*/
-		free((char*)ev->ev_arg1);
-		ev->ev_arg1 = 0;
+  if (lockEvent()) {
+      while (TRUE) {
+	  TH_DPRINTF(("TDEQ\n"));
+	  ev = eventQueueHead;
+	  if (ev) {
+	      eventQueueHead = ev->ev_next;
+	      if (! eventQueueHead) {
+		  eventQueueTail = (struct queuedEvent *)0;
+	      }
+	      if (eventempfcount != ev->count) {
+		  printf("eventcount error %d <-> %d\n",eventempfcount,ev->count);
 	      }
-	      else
-	      {
-		/* noch einmal in die queue */
-		if (ev->ev_arg2++ < 100)
-		{
-		  ev->ev_next = (struct queuedEvent *)0;
-		  ev->count = eventsendcount++;
-
-		  if (eventQueueTail) {
-		      eventQueueTail->ev_next = ev;
-		  } else {
-		      eventQueueHead = ev;
-		  }
-		  eventQueueTail = ev;
-		  if (ev->ev_arg2 > 98)
-		  {
-		    __win32_fprintf(stderr, "WinWorkstation: UnregisterClass %s failed. Wait 1 sec.\n",(char*)ev->ev_arg1);
-		    unlockEvent();
-		    sleep(1);
-		    lockEvent();
-		  }
-		  else
-		  {
-		    unlockEvent();
-		    sleep(0);
-		    lockEvent();
+	      eventempfcount++;
+	      if (ev->ev_message == WM_DESTROY) {
+		  if (ev->ev_arg2) {
+		      free((char*)ev->ev_arg2);
+		      ev->ev_arg2 = 0;
 		  }
-		  continue;
-		}
-		else /* fail evtl. später ändern und in st verzögert aufrufen */
-		{
-		  __win32_fprintf(stderr, "WinWorkstation: UnregisterClass %s failed.\n",(char*)ev->ev_arg1);
-		  free((char*)ev->ev_arg1);
-		  ev->ev_arg1 = 0;
-		}
+#ifdef TOPWINDOWCLASS
+		  if (ev->ev_arg1) {
+		      if (UnregisterClass((char*)ev->ev_arg1,(HANDLE) __getHInstance())) {
+			  /*printf("UnregisterClass %s ok.\n",(char*)ev->ev_arg1);*/
+			  free((char*)ev->ev_arg1);
+			  ev->ev_arg1 = 0;
+		      } else {
+			  /* noch einmal in die queue */
+			  if (ev->ev_arg2++ < 100) {
+			      ev->ev_next = (struct queuedEvent *)0;
+			      ev->count = eventsendcount++;
+
+			      if (eventQueueTail) {
+				  eventQueueTail->ev_next = ev;
+			      } else {
+				  eventQueueHead = ev;
+			      }
+			      eventQueueTail = ev;
+			      if (ev->ev_arg2 > 98) {
+				  fprintf(stderr, "WinWorkstation: UnregisterClass %s failed. Wait 1 sec.\n",(char*)ev->ev_arg1);
+				  unlockEvent();
+				  sleep(1);
+				  lockEvent();
+			      } else {
+				  unlockEvent();
+				  sleep(0);
+				  lockEvent();
+			      }
+			      continue;
+			  } else {
+			      /* fail evtl. später ändern und in st verzögert aufrufen */
+			      fprintf(stderr, "WinWorkstation: UnregisterClass %s failed.\n",(char*)ev->ev_arg1);
+			      free((char*)ev->ev_arg1);
+			      ev->ev_arg1 = 0;
+			  }
+		      }
+		  }
+#endif
 	      }
-	    }
-#endif
-	}
-	break;
-
+	      break;
+	  } else
+	      break;
       }
-      else
-	break;
-    }
-    if (ev)
-    {
-      *ret_ev = *ev;
-      ev->ev_next = eventFreeList;
-      eventFreeList = ev;
-    }
-
-    unlockEvent();
+      if (ev) {
+	  *ret_ev = *ev;
+	  ev->ev_next = eventFreeList;
+	  eventFreeList = ev;
+      }
+
+      unlockEvent();
   }
-    /*if (!ev)
-      SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);*/
+
+#if 0
+  if (!ev)
+      SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);
+#endif
+
   return (ev != 0);
 }
 
@@ -1168,31 +1227,29 @@
     switch (message) {
 	case WM_CREATE:
 	    {
-	      CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
-	      SETLOCALWINDOWINFOPTR(hWnd,lpcs->lpCreateParams);
-	      if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams) {
-		  PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
-	      }
-	      *pDefault = 0;
+		CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
+		SETLOCALWINDOWINFOPTR(hWnd,lpcs->lpCreateParams);
+		if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams) {
+		    PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
+		}
+		*pDefault = 0;
 #ifdef COUNT_RESOURCES
-	      __cnt_createWindows++;
-	      RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
+		__cnt_createWindows++;
+		RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
 #endif
-	      DPRINTF(("WM_CREATE\n"));
+		DPRINTF(("WM_CREATE\n"));
 	    }
 	    break;
 
 	case WM_CLOSE:
 	    DPRINTF(("WM_CLOSE\n"));
 	    if (!destroyWin) {
-	      enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
+		enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
 	    } else {
-	      destroyWin = 0;
-	      if (!DestroyWindow(hWnd))
-	      {
-		DPRINTF(("DestroyWindow ERROR\n"));
-	      }
-
+		destroyWin = 0;
+		if (!DestroyWindow(hWnd)) {
+		    DPRINTF(("DestroyWindow ERROR\n"));
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1205,17 +1262,16 @@
 	      DPRINTF(("WM_DESTROY\n"));
 	      l = (char *)GETLOCALWINDOWINFOPTR(hWnd);
 #ifdef TOPWINDOWCLASS
-	      if (l)
-	      {
-		if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN)
-		{
-		  n = (char*)malloc(200);
-		  GetClassName(hWnd,n,200);
-		}
-	      /* free all resources */
-		/*if (GetWindow_bgBrush(hWnd))
-		  DelObject(GetWindow_bgBrush(hWnd));*/
-		//free(GETLOCALWINDOWINFOPTR(hWnd));
+	      if (l) {
+		  if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) {
+		      n = (char*)malloc(200);
+		      GetClassName(hWnd,n,200);
+		  }
+		  /* free all resources */
+		  /*if (GetWindow_bgBrush(hWnd))
+		   *    DelObject(GetWindow_bgBrush(hWnd));
+		   */
+		  //free(GETLOCALWINDOWINFOPTR(hWnd));
 	      }
 #endif
 	      SETLOCALWINDOWINFOPTR(hWnd,0);
@@ -1278,43 +1334,37 @@
 		    *pDefault = 0;
 		    return 1;
 		}
-
 	    }
 	    return 0;
 
 	case WM_WINDOWPOSCHANGED:
-	    if (currentCapture == CAPTURE_NONE)
-	    {
-	      POINT p;
-	      HWND hWndChild,hWndTemp;
-
-	      p.x = evRootX;
-	      p.y = evRootY;
-	      ScreenToClient(hWnd, &p);
-	      hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-	      do
-	      {
-		hWndTemp = hWndChild;
-		hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
-	      } while ((hWndChild) && (hWndChild != hWndTemp));
-	      if (hWndChild /*&& (hWndChild != hWnd)*/)
-	      {
-		  modifiers = getModifiers();
-		  if (hWndChild != currentPointerView)
-		  {
-		      if (currentPointerView)
-		      {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		      if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
-			enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
-		      //SetFocus(hWndChild);
-		      //printf("WM_WINDOWPOSCHANGED h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);
-		      currentPointerView = hWndChild;
-		  }
-	      }
+	    if (currentCapture == CAPTURE_NONE) {
+		POINT p;
+		HWND hWndChild,hWndTemp;
+
+		p.x = evRootX;
+		p.y = evRootY;
+		ScreenToClient(hWnd, &p);
+		hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
+		do {
+		    hWndTemp = hWndChild;
+		    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
+		} while ((hWndChild) && (hWndChild != hWndTemp));
+		if (hWndChild /*&& (hWndChild != hWnd)*/) {
+		    modifiers = getModifiers();
+		    if (hWndChild != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+				enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+			if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
+			    enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
+			//SetFocus(hWndChild);
+			//printf("WM_WINDOWPOSCHANGED h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);
+			currentPointerView = hWndChild;
+		    }
+		}
 	    }
 
 	    /*
@@ -1355,29 +1405,26 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    if (((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0) && (__rootWinSpezial != hWnd))
-	    {
-	      if (GetUpdateRect(hWnd, &upd, FALSE))
-	      {
-		  if (GetWindow_eventMask(hWnd) & ExposureMask) {
+	    if (((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0) && (__rootWinSpezial != hWnd)) {
+		if (GetUpdateRect(hWnd, &upd, FALSE)) {
+		    if (GetWindow_eventMask(hWnd) & ExposureMask) {
 #ifndef LATE_PAINT
-		    HDC dc = (HDC)GetDC(hWnd);
-		    HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(hWnd),0));
-
-		    if (br) {
-			// printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
-			SelectClipRgn(dc,0);
-			FillRect(dc, &upd, br);
-			DelObject(br);
+			HDC dc = (HDC)GetDC(hWnd);
+			HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(hWnd),0));
+
+			if (br) {
+			    // printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
+			    SelectClipRgn(dc,0);
+			    FillRect(dc, &upd, br);
+			    DelObject(br);
+			}
+			ReleaseDC(hWnd,dc);
+#endif
+			enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
 		    }
-		    ReleaseDC(hWnd,dc);
-#endif
-		    enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
-		  }
-	      }
-	    }
-	    else
-	      pDefault = 0;
+		}
+	    } else
+		pDefault = 0;
 	    return 0;
 	    break;
 
@@ -1415,26 +1462,23 @@
 
 	case WM_MOUSEACTIVATE :
 	    EVENT_PRINTF2(("WM_MOUSEACTIVATE h=%x\n", hWnd));
-	    if (!buttonClickWindowsLike)
-	    {
+	    if (!activateOnClick) {
 		*pDefault = 0;
-		if ((__rootWinSpezial == hWnd) || (GetActiveWindow() && (LOWORD(lParam) == HTCLIENT))
+		if ((__rootWinSpezial == hWnd) || (GetActiveWindow() && (LOWORD(lParam) == HTCLIENT)) 
 		    /*((GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) == 0) */
-		   )
-		   return MA_NOACTIVATE;
-		else
-		{
-		  return MA_ACTIVATE;
+		   ) {
+		     return MA_NOACTIVATE;
+		} else {
+		    return MA_ACTIVATE;
 		}
 	    }
 	    break;
 
 	case WM_NCHITTEST:
 	    EVENT_PRINTF(("WM_NCHITTEST\n"));
-	    if (hWnd == __rootWinSpezial)
-	    {
-	      *pDefault = 0;
-	      return HTCLIENT;
+	    if (hWnd == __rootWinSpezial) {
+		*pDefault = 0;
+		return HTCLIENT;
 	    }
 	    break;
 
@@ -1446,17 +1490,17 @@
 	    CPRINTF(("WM_ACTIVATE %s h=%x\n",
 			    LOWORD(wParam) ? "active" : "inactive",
 			    hWnd));
-	    //if (!buttonClickWindowsLike)
+	    //if (!activateOnClick)
 	    {
 		switch (LOWORD(wParam)) {
 		    case WA_INACTIVE:
 			EVENT_PRINTF2(("WM_ACTIVATE inactive h=%x\n", hWnd));
 			break;
+
 		    case WA_ACTIVE:
 			EVENT_PRINTF2(("WM_ACTIVATE active h=%x\n", hWnd));
 #if 0
-			if (currentCapture == CAPTURE_NONE)
-			{
+			if (currentCapture == CAPTURE_NONE) {
 			  POINT p;
 			  HWND hWndChild,hWndTemp;
 
@@ -1464,22 +1508,16 @@
 			  p.y = evRootY;
 			  ScreenToClient(hWnd, &p);
 			  hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-			  do
-			  {
+			  do {
 			    hWndTemp = hWndChild;
 			    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
 			  } while ((hWndChild) && (hWndChild != hWndTemp));
+
 			  /*printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
-			  if (hWndChild /*&& (hWndChild != hWnd)*/)
-
-
-
-			  {
+			  if (hWndChild /*&& (hWndChild != hWnd)*/) {
 			      modifiers = getModifiers();
-			      if (hWndChild != currentPointerView)
-			      {
-				  if (currentPointerView)
-				  {
+			      if (hWndChild != currentPointerView) {
+				  if (currentPointerView) {
 				      if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
 					enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
 				      currentPointerView = 0;
@@ -1489,17 +1527,15 @@
 				  //SetFocus(hWndChild);
 				  currentPointerView = hWndChild;
 			      }
-
-
-
-
 			  }
 			}
 #endif
 			break;
+
 		    case WA_CLICKACTIVE:
 			EVENT_PRINTF2(("WM_ACTIVATE clkactive h=%x\n", hWnd));
 			break;
+
 		    default:
 			EVENT_PRINTF2(("WM_ACTIVATE ? h=%x\n", hWnd));
 			break;
@@ -1524,30 +1560,32 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    modifiers = getModifiers();
 	    {
-		POINT p;
-
-		p.x = evRootX;
-		p.y = evRootY;
-		ScreenToClient(hWnd, &p);
-		x = p.x;
-		y = p.y;
-	    }
-	    if (currentPointerView) {
-	      int evMask = GetWindow_eventMask(currentPointerView);
-
-	      if (evMask & KeyPressMask)
-		enqEvent(KeyPressMask,currentPointerView, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
-	      if (evMask & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,currentPointerView, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
-	    } else {
-	      int evMask = GetWindow_eventMask(hWnd);
-
-	      if (evMask & KeyPressMask)
-		enqEvent(KeyPressMask,hWnd, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
-	      if (evMask & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,hWnd, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+		HWND destWindow;
+		int evMask;
+
+		destWindow = currentPointerView;
+		if (destWindow == 0) {
+		    destWindow = hWnd;
+		}
+
+		evMask = GetWindow_eventMask(destWindow);
+		if (evMask & (KeyPressMask | KeyReleaseMask)) {
+		    POINT p;
+
+		    modifiers = getModifiers();
+
+		    p.x = evRootX;
+		    p.y = evRootY;
+		    ScreenToClient(destWindow, &p);
+		    x = p.x;
+		    y = p.y;
+
+		    if (evMask & KeyPressMask)
+			enqEvent(KeyPressMask, destWindow, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+		    if (evMask & KeyReleaseMask)
+			enqEvent(KeyReleaseMask, destWindow, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1563,23 +1601,26 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    modifiers = getModifiers();
 	    {
-		POINT p;
-
-		p.x = evRootX;
-		p.y = evRootY;
-		ScreenToClient(hWnd, &p);
-		x = p.x;
-		y = p.y;
-	    }
-
-	    if (currentPointerView) {
-	      if (GetWindow_eventMask(currentPointerView) & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,currentPointerView, message, wParam, x, y, lParam, modifiers);
-	    } else {
-	      if (GetWindow_eventMask(hWnd) & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,hWnd, message, wParam, x, y, lParam, modifiers);
+		HWND destWindow;
+
+		destWindow = currentPointerView;
+		if (destWindow == 0) {
+		    destWindow = hWnd;
+		}
+
+		if (GetWindow_eventMask(destWindow) & KeyReleaseMask) {
+		    POINT p;
+
+		    p.x = evRootX;
+		    p.y = evRootY;
+		    ScreenToClient(destWindow, &p);
+		    x = p.x;
+		    y = p.y;
+
+		    modifiers = getModifiers();
+		    enqEvent(KeyReleaseMask, destWindow, message, wParam, x, y, lParam, modifiers);
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1603,22 +1644,27 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    modifiers = getModifiers();
+
 	    {
-		POINT p;
-
-		p.x = evRootX;
-		p.y = evRootY;
-		ScreenToClient(hWnd, &p);
-		x = p.x;
-		y = p.y;
-	    }
-	    if (currentPointerView) {
-	      if (GetWindow_eventMask(currentPointerView) & KeyPressMask)
-		enqEvent(KeyPressMask,currentPointerView, message, wParam, x, y, lParam, modifiers);
-	    } else {
-	      if (GetWindow_eventMask(hWnd) & KeyPressMask)
-		enqEvent(KeyPressMask,hWnd, message, wParam, x, y, lParam, modifiers);
+		HWND destWindow;
+
+		destWindow = currentPointerView;
+		if (destWindow == 0) {
+		    destWindow = hWnd;
+		}
+
+		if (GetWindow_eventMask(destWindow) & KeyPressMask) {
+		    POINT p;
+
+		    p.x = evRootX;
+		    p.y = evRootY;
+		    ScreenToClient(destWindow, &p);
+		    x = p.x;
+		    y = p.y;
+
+		    modifiers = getModifiers();
+		    enqEvent(KeyPressMask, destWindow, message, wParam, x, y, lParam, modifiers);
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1638,23 +1684,20 @@
 
 		modifiers = getModifiers();
 
-		if (currentCapture == CAPTURE_NONE)
-		{
-		  if (hWnd != currentPointerView) {
-		      if (currentPointerView) {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		      if (GetWindow_eventMask(hWnd) & EnterWindowMask)
-			enqEvent(EnterWindowMask,hWnd, __WM_MOUSEENTER, 0, x, y, 0, modifiers);
-		      currentPointerView = hWnd;
-		  }
-		  CPRINTF(("MouseMove %x\n",currentPointerView));
-		}
-		else
-		{
-		  CPRINTF(("MouseMove Capture %x\n",currentPointerView));
+		if (currentCapture == CAPTURE_NONE) {
+		    if (hWnd != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+				enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+			if (GetWindow_eventMask(hWnd) & EnterWindowMask)
+			    enqEvent(EnterWindowMask,hWnd, __WM_MOUSEENTER, 0, x, y, 0, modifiers);
+			currentPointerView = hWnd;
+		    }
+		    CPRINTF(("MouseMove %x\n",currentPointerView));
+		} else {
+		    CPRINTF(("MouseMove Capture %x\n",currentPointerView));
 		}
 		if (    (GetWindow_eventMask(currentPointerView) & PointerMotionMask)
 		     || (modifiers & (Button1Mask|Button2Mask|Button3Mask))
@@ -1689,8 +1732,9 @@
 
 
 	    if (GetWindow_eventMask(hWnd) & ButtonReleaseMask)
-	      enqEvent(ButtonReleaseMask,hWnd, message, wParam, (int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),
-					      wParam,modifiers);
+		enqEvent(ButtonReleaseMask, hWnd, 
+			 message, wParam, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam),
+			 wParam, modifiers);
 	    *pDefault = 0;
 	    break;
 
@@ -1708,8 +1752,7 @@
 		return 0;
 	    }
 
-	    if (currentCapture == CAPTURE_NONE)
-	    {
+	    if (currentCapture == CAPTURE_NONE) {
 		currentCapture = curButton /*CAPTURE_IMPLICIT*/;
 		//SetFocus(hWnd);
 		SetCapture(hWnd);
@@ -1729,10 +1772,10 @@
 	    EVENT_PRINTF3(("WM_BUTTONDOWN h=%x pos=%d/%d\n",
 			   hWnd, LOWORD(lParam), HIWORD(lParam)));
 
-
 	    if (GetWindow_eventMask(hWnd) & ButtonPressMask)
-	      enqEvent(ButtonPressMask,hWnd, message, wParam, (int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),
-					      wParam,modifiers);
+		enqEvent(ButtonPressMask, hWnd, 
+			 message, wParam, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam),
+			 wParam, modifiers);
 	    *pDefault = 0;
 	    break;
 
@@ -1761,36 +1804,32 @@
 #if 0
 	    //enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
 	    {
-	      POINT p;
-	      HWND hWndChild,hWndTemp;
-
-	      p.x = evRootX;
-	      p.y = evRootY;
-	      ScreenToClient(hWnd, &p);
-	      hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-	      do
-	      {
-		hWndTemp = hWndChild;
-		hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
-	      } while ((hWndChild) && (hWndChild != hWndTemp));
-	      /*printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
-	      if (hWndChild /*&& (hWndChild != hWnd)*/)
-	      {
-		  modifiers = getModifiers();
-		  if (hWndChild != currentPointerView)
-		  {
-		      if (currentPointerView)
-		      {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		      if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
-			enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
-		      //SetFocus(hWndChild);
-		      currentPointerView = hWndChild;
-		  }
-	      }
+		POINT p;
+		HWND hWndChild,hWndTemp;
+
+		p.x = evRootX;
+		p.y = evRootY;
+		ScreenToClient(hWnd, &p);
+		hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
+		do {
+		    hWndTemp = hWndChild;
+		    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
+		} while ((hWndChild) && (hWndChild != hWndTemp));
+		/*printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
+		if (hWndChild /*&& (hWndChild != hWnd)*/) {
+		    modifiers = getModifiers();
+		    if (hWndChild != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+			      enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+			if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
+			    enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
+			//SetFocus(hWndChild);
+			currentPointerView = hWndChild;
+		    }
+		}
 	    }
 
 	    if (isNative) {
@@ -1833,15 +1872,14 @@
 
 		modifiers = getModifiers();
 
-		if (currentCapture == CAPTURE_NONE)
-		{
-		  if (hWnd != currentPointerView) {
-		      if (currentPointerView) {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		  }
+		if (currentCapture == CAPTURE_NONE) {
+		    if (hWnd != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+			      enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+		    }
 		}
 	    }
 	    *pDefault = 0;
@@ -2061,6 +2099,7 @@
     RECT rect;
     MSG msg;
     localWindowInfo *li;
+
     _dispatchThreadId = GetCurrentThreadId();
     TH_DPRINTF(("TS %d\n", th_calls++));
     PeekMessage(&msg,NULL,0,0,PM_NOREMOVE);   /* must be */
@@ -2074,9 +2113,8 @@
     GetWindowRect(GetDesktopWindow(), &rect);
     /* allocate localMemory for Window */
     li = (localWindowInfo*)malloc(sizeof(localWindowInfo));
-    if (li)
-    {
-      memset(li,0,sizeof(*_thread_local));
+    if (li) {
+	memset(li,0,sizeof(*_thread_local));
     }
 
     __rootWinSpezial = CreateWindowEx( WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT,app_nameroot,app_nameroot,
@@ -2090,159 +2128,151 @@
     SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
     SetEvent(hCreateEvent);
 
-    while (bdispatchThreadState)
-    {
+    while (bdispatchThreadState) {
 	HANDLE dummy;
 	TH_DPRINTF(("TG %d\n", th_calls++));
-	if (currentPointerView && (currentCapture == CAPTURE_NONE))
-	{
-	  while (PeekMessage(&msg,0,0,0,PM_NOREMOVE) == 0)
-	  {
-	    if (MsgWaitForMultipleObjects(0,&dummy,FALSE,200,QS_ALLINPUT) == WAIT_TIMEOUT)
-	    {
-	      POINT point;
-	      if (GetCursorPos(&point))
-	      {
-		HWND hWnd = WindowFromPoint(point);
-		if (hWnd)
-		{
-		  if (GetWindowThreadProcessId(hWnd,0) != GetCurrentThreadId())
-		  {
-		    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-		      enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
-		    currentPointerView = 0;
-		    break;
-		  }
+
+	if (currentPointerView && (currentCapture == CAPTURE_NONE)) {
+	    while (PeekMessage(&msg,0,0,0,PM_NOREMOVE) == 0) {
+		/*
+		 * wait for an event; timeout after 200 millis
+		 */
+		if (MsgWaitForMultipleObjects(0,&dummy,FALSE,200,QS_ALLINPUT) == WAIT_TIMEOUT) {
+		    /*
+		     * timeout - see where mouse pointer is
+		     * for synthetic leave events.
+		     */
+		    POINT point;
+		    if (GetCursorPos(&point)) {
+			HWND hWnd = WindowFromPoint(point);
+			if (hWnd) {
+			    if (GetWindowThreadProcessId(hWnd,0) != GetCurrentThreadId()) {
+				if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+				    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
+				currentPointerView = 0;
+				break;
+			    }
+			}
+		    }
 		}
-	      }
-	    }
-	  }
-	}
+	    }
+	}
+
 	GetMessage(&msg, NULL, 0, 0);
 	TH_DPRINTF(("TD %d\n", th_calls++));
 	destroyWin = 0;
-	if (msg.message == WM_THREADDESTROYWINDOW)
-	{
-	  destroyWin = TRUE;
-	  msg.message = WM_CLOSE;
-	  CPRINTF(("thread WM_THREADDESTROYWINDOW %x\n",msg.hwnd));
-	}
-	else if (msg.message == WM_THREADSETFOCUS)
-	{
+
+	switch (msg.message) {
+	    case WM_THREADDESTROYWINDOW:
+		destroyWin = TRUE;
+		msg.message = WM_CLOSE;
+		CPRINTF(("thread WM_THREADDESTROYWINDOW %x\n",msg.hwnd));
+		break;
+
+	    case WM_THREADSETFOCUS:
 #ifdef xxWIN32THREADS
-	  if (msg.lParam)
-	  {
-	    if (AttachThreadInput(_dispatchThreadId,msg.lParam,TRUE) == FALSE)
-	      PRINTF(("SetFocus AttachThreadInput error %d\n",GetLastError()));
-	  }
+		if (msg.lParam) {
+		    if (AttachThreadInput(_dispatchThreadId,msg.lParam,TRUE) == FALSE)
+			PRINTF(("SetFocus AttachThreadInput error %d\n",GetLastError()));
+		}
 #endif
-	  CPRINTF(("threadSetfocus %x\n",msg.wParam));
-	  //SetForegroundWindow((HWND)msg.wParam);
-	  //SetWindowPos((HWND)msg.wParam, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER  |SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
-	  SetFocus((HWND)msg.wParam);
-	  continue;
-	}
-	else if (msg.message == WM_THREADSETCURSOR)
-	{
-	  if (msg.lParam)
-	  {
-	    POINT p;
-
-	    GetCursorPos(&p);
-	    if (WindowFromPoint(p) == msg.hwnd)
-	    {
-	      CPRINTF(("threadSetCursor %x\n",msg.lParam));
-	      SetCursor((HCURSOR)msg.lParam);
-	    }
-	  }
-	  continue;
-	}
-	else if (msg.message == WM_THREADSETCAPTURE)
-	{
-	  if (msg.wParam)
-	  {
-	    if (currentPointerView)
-	    {
-		if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-		  enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
-	    }
-	    currentPointerView = msg.wParam;
-	    currentCapture = CAPTURE_EXPLICIT;
-	    CPRINTF(("threadSetCapture %x\n",msg.wParam));
-	    SetCapture(currentPointerView);
-	  }
-	  else
-	  {
-	    if (currentPointerView  == __rootWinSpezial)
-	    {
-	      //ShowWindow(__rootWinSpezial, SW_HIDE);
-	      SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0,SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOCOPYBITS
-			     |SWP_HIDEWINDOW| SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE/*| SWP_NOZORDER|SWP_NOOWNERZORDER*/);
-	    }
-	    currentPointerView = 0;
-	    currentCapture = CAPTURE_NONE;
-	    CPRINTF(("threadReleaseCapture\n"));
-	    ReleaseCapture();
-	  }
-	  if (msg.lParam)
-	  {
-	      CPRINTF(("threadSetCursor %x\n",msg.lParam));
-	      SetCursor((HCURSOR)msg.lParam);
-	  }
-	  continue;
-	}
-	else if (msg.message == WM_THREADCREATEWINDOW)
-	{
-	  TH_DPRINTF(("C %d\n", th_calls));
-	  if (_thread_winStyleBits & WS_POPUP)
-	  {
-	    //_thread_parentHandle = GetActiveWindow();
-	  }
-	  _thread_newWinHandle = CreateWindowEx(
-				      _thread_winStyleBitsEx,
-				      _thread_className,
-				      _thread_windowName,
-				      _thread_winStyleBits,
-				      _thread_x, _thread_y,
-				      _thread_dx,_thread_dy,
-				      _thread_parentHandle,
-				      NULL,           /* menu */
-				      (HANDLE) __getHInstance(),
-				      _thread_local);
-	  SetEvent(hCreateEvent);
-	  continue;
-	}
-	/* TranslateMessage(&msg); */ /* Translates virtual key codes */
-	if (   (msg.message == WM_KEYDOWN)
-	    || (msg.message == WM_KEYUP)
-	    || (msg.message == WM_SYSKEYDOWN)
-	    || (msg.message == WM_SYSKEYUP)
-	   )
-	{
+		CPRINTF(("threadSetfocus %x\n",msg.wParam));
+		//SetForegroundWindow((HWND)msg.wParam);
+		//SetWindowPos((HWND)msg.wParam, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER  |SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
+		SetFocus((HWND)msg.wParam);
+		continue;
+
+	    case WM_THREADSETCURSOR:
+		if (msg.lParam) {
+		    POINT p;
+
+		    GetCursorPos(&p);
+		    if (WindowFromPoint(p) == msg.hwnd) {
+			CPRINTF(("threadSetCursor %x\n",msg.lParam));
+			SetCursor((HCURSOR)msg.lParam);
+		    }
+		}
+		continue;
+
+	    case WM_THREADSETCAPTURE:
+		if (msg.wParam) {
+		    if (currentPointerView) {
+			if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
+		    }
+		    currentPointerView = msg.wParam;
+		    currentCapture = CAPTURE_EXPLICIT;
+		    CPRINTF(("threadSetCapture %x\n",msg.wParam));
+		    SetCapture(currentPointerView);
+		} else {
+		    if (currentPointerView  == __rootWinSpezial) {
+			//ShowWindow(__rootWinSpezial, SW_HIDE);
+			SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0,SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOCOPYBITS
+				       |SWP_HIDEWINDOW| SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE/*| SWP_NOZORDER|SWP_NOOWNERZORDER*/);
+		    }
+		    currentPointerView = 0;
+		    currentCapture = CAPTURE_NONE;
+		    CPRINTF(("threadReleaseCapture\n"));
+		    ReleaseCapture();
+		}
+		if (msg.lParam) {
+		    CPRINTF(("threadSetCursor %x\n",msg.lParam));
+		    SetCursor((HCURSOR)msg.lParam);
+		}
+		continue;
+
+	    case WM_THREADCREATEWINDOW:
+		TH_DPRINTF(("C %d\n", th_calls));
+		if (_thread_winStyleBits & WS_POPUP) {
+		    //_thread_parentHandle = GetActiveWindow();
+		}
+		_thread_newWinHandle = CreateWindowEx(
+					    _thread_winStyleBitsEx,
+					    _thread_className,
+					    _thread_windowName,
+					    _thread_winStyleBits,
+					    _thread_x, _thread_y,
+					    _thread_dx,_thread_dy,
+					    _thread_parentHandle,
+					    NULL,           /* menu */
+					    (HANDLE) __getHInstance(),
+					    _thread_local);
+		SetEvent(hCreateEvent);
+		continue;
+
+	    case WM_KEYDOWN:
+	    case WM_KEYUP:
+	    case WM_SYSKEYDOWN:
+	    case WM_SYSKEYUP:
 #ifdef xxDEBUG
-	   if ((msg.wParam == 0x11) && (msg.message == WM_KEYDOWN))/* CTRL-C */
-	   {
-	     if (c_count++ > 3)  /* for debugging */
-		exit(1);
-	   }
+		if ((msg.wParam == 0x11) && (msg.message == WM_KEYDOWN)) {
+		    /* CTRL-C */
+		    if (c_count++ > 3)  /* for debugging */
+		       exit(1);
+		}
 #endif
-	    DPRINTF(("keymsg %x\n",msg.wParam));
-	    if (
-		   ((msg.wParam >= '0') && (msg.wParam <= 'Z'))
-		|| ((msg.wParam >= VK_MULTIPLY) && (msg.wParam <= VK_DIVIDE))
-		|| (msg.wParam == 0x20)
-		|| (msg.wParam == 0x14)
-		/*|| (msg.wParam == 0x10)*/
-		|| (msg.wParam >= 0xB0)
-	       )
-	    {
-		/*
-		 * translate to a WM_CHAR message
-		 */
-		if (TranslateMessage(&msg))
-		    continue;
-	    }
-	}
+		DPRINTF(("keymsg %x\n",msg.wParam));
+		if (
+		       ((msg.wParam >= '0') && (msg.wParam <= 'Z'))
+		    || ((msg.wParam >= VK_MULTIPLY) && (msg.wParam <= VK_DIVIDE))
+		    || (msg.wParam == 0x20)
+		    || (msg.wParam == 0x14)
+		    /*|| (msg.wParam == 0x10)*/
+		    || (msg.wParam >= 0xB0)
+		   )
+		{
+		    /*
+		     * translate to a WM_CHAR message
+		     */
+		    if (TranslateMessage(&msg))
+			continue;
+		}
+		break;
+	}
+
+	/*
+	 * common ...
+	 */
 	evRootX = msg.pt.x;
 	evRootY = msg.pt.y;
 	lastMSGTime = msg.time;
@@ -2325,11 +2355,11 @@
 	    __UNPROTECT__(*refToList);
 
 	    if ( dwType & TRUETYPE_FONTTYPE )
-	      __ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(0);
-	    else
-	      //__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(MulDiv(__logPixelSY,lplf->lfHeight, 72));
-	      __ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(lplf->lfHeight);
-
+		__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(0);
+	    else {
+		//__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(MulDiv(__logPixelSY,lplf->lfHeight, 72));
+		__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(lplf->lfHeight);
+	    }
 	    __ArrayInstPtr(newArray)->a_element[1] = __MKSMALLINT(lplf->lfWidth);
 	    __ArrayInstPtr(newArray)->a_element[2] = __MKSMALLINT(lplf->lfEscapement);
 	    __ArrayInstPtr(newArray)->a_element[3] = __MKSMALLINT(lplf->lfOrientation);
@@ -2497,7 +2527,8 @@
     See more documentation in my superclass, DeviceWorkstation.
 
     [author:]
-	Claus Gittinger
+	Claus Gittinger (initial port)
+	Manfred Dierolf (many, many changes & fixes, multithreading etc.)
 "
 ! !
 
@@ -2548,7 +2579,7 @@
 initializeStandardColorNames
     "{ Pragma: +optSpace }"
 
-    "setup standard color names"
+    "setup standard color names (X-color names)"
 
     StandardColorValues := Dictionary new.
     #(
@@ -3462,8 +3493,6 @@
     "
      WinWorkstation initializeStandardColorNames
     "
-
-
 !
 
 nativeWindows:aBoolean
@@ -4223,22 +4252,22 @@
 	struct gcData *gcData = _GCDATA(aGCId);
 
 #ifdef COUNT_RESOURCES
-	__cnt_gcData--;
-       RESPRINTF(("DestroyGcData %d\n",__cnt_gcData));
+	 __cnt_gcData--;
+	RESPRINTF(("DestroyGcData %d\n",__cnt_gcData));
 #endif
-       if (gcData->hBitmap) 
-       {
 #ifdef COUNT_BMP_RESOURCES
+	if (gcData->hBitmap) {
 	    __cnt_bmpdc--;
 	    RES_BMP_PRINTF(("free BmpDC %d\n",__cnt_bmpdc));
+	}
 #endif
-       }
-       if (lastGcData == gcData)
-       {
-	 _releaseDC(lastGcData);
-	 lastGcData = 0;
-       }
-       free(gcData);
+
+#ifdef CACHE_LAST_DC
+	if (lastGcData == gcData) {
+	    _releaseDC(lastGcData);
+	}
+#endif
+	free(gcData);
     }
 %}
 !
@@ -4249,14 +4278,12 @@
     if (__isExternalAddress(aDrawableId) && ISCONNECTED) {
 	HANDLE bitmapHandle = _HANDLEVal(aDrawableId);
 
-	if (bitmapHandle)
-	{
+	if (bitmapHandle) {
 #ifdef COUNT_BMP_RESOURCES
 	    __cnt_bitmap--;
 	    RES_BMP_PRINTF(("DestroyPixmap %x %d\n",bitmapHandle,__cnt_bitmap));
 #endif
-	    if( DelObject(bitmapHandle) )
-	    {
+	    if( DelObject(bitmapHandle) ) {
 		DPRINTF(("Bitmap deleted!\n"));
 	    }
 	}
@@ -4311,12 +4338,9 @@
 	__cnt_bmpdc++;
 	RES_BMP_PRINTF(("CreateBmpDC %d\n",__cnt_bmpdc));
 #endif
-	if (GetObject(hBitmap,sizeof(bitmap),&bitmap))
-	{
+	if (GetObject(hBitmap,sizeof(bitmap),&bitmap)) {
 	    DPRINTF(("bitmap info:%d\n",bitmap.bmBitsPixel));
-	}
-	else
-	{
+	} else {
 	    DPRINTF(("noinfo returned\n"));
 	}
 	gcData->hBitmap = hBitmap;
@@ -4359,73 +4383,57 @@
 	padding = bytesPerRowWN - bytesPerRowST;
 	nBytes = b_height * bytesPerRowWN;
 
-	if (nBytes < sizeof(fastBits))
-	{
+	if (nBytes < sizeof(fastBits)) {
 	    cp = b_bits = fastBits;
-	}
-	else
-	{
+	} else {
 	    cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
 	}
-	if (cp)
-	{
-	  if (__qClass(anArray) == @global(Array))
-	  {
-	      index = 1;
-	      op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
-	      for (row = b_height; row; row--)
-	      {
-		  for (col = bytesPerRowST; col; col--)
-		  {
-		      num = *op++;
-		      if (! __isSmallInteger(num))
-			goto fail;
-		      *cp++ = __intVal(num);
-		  }
-		  cp += padding;
-	      }
-	  }
-	  else if (__qClass(anArray) == @global(ByteArray))
-	  {
-	      pBits = __ByteArrayInstPtr(anArray)->ba_element;
-	      for (row = b_height; row; row--)
-	      {
-		  for (col = bytesPerRowST; col; col--)
-		  {
-		      *cp++ = ( *pBits++ /*^ 0xFF*/ );
-		  }
-		  cp += padding;
-	      }
-	  }
-	  else
-	  {
-	      goto fail;
-	  }
-	  DPRINTF(("create bitmap ...\n"));
-
-	  newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
-
-	  if( newBitmapHandle )
-	  {
+	if (cp) {
+	    if (__qClass(anArray) == @global(Array)) {
+		index = 1;
+		op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
+		for (row = b_height; row; row--) {
+		    for (col = bytesPerRowST; col; col--) {
+			num = *op++;
+			if (! __isSmallInteger(num))
+			    goto fail;
+			*cp++ = __intVal(num);
+		    }
+		    cp += padding;
+		}
+	    } else if (__qClass(anArray) == @global(ByteArray)) {
+		pBits = __ByteArrayInstPtr(anArray)->ba_element;
+		for (row = b_height; row; row--) {
+		    for (col = bytesPerRowST; col; col--) {
+			*cp++ = ( *pBits++ /*^ 0xFF*/ );
+		    }
+		    cp += padding;
+		}
+	    } else {
+		goto fail;
+	    }
+	    DPRINTF(("create bitmap ...\n"));
+
+	    newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
+
+	    if( newBitmapHandle ) {
 #ifdef COUNT_BMP_RESOURCES
-	    __cnt_bitmap++;
-	    RES_BMP_PRINTF(("CreateBitmap %x %d\n",newBitmapHandle,__cnt_bitmap));
+		__cnt_bitmap++;
+		RES_BMP_PRINTF(("CreateBitmap %x %d\n",newBitmapHandle,__cnt_bitmap));
 #endif
-	    DPRINTF(("returning bitmap ...\n"));
-	    if (allocatedBits)
-	    {
-	      free(allocatedBits);
-	    }
-	    RETURN ( __MKOBJ(newBitmapHandle));
-	  }
-      }
+		DPRINTF(("returning bitmap ...\n"));
+		if (allocatedBits) {
+		    free(allocatedBits);
+		}
+		RETURN ( __MKOBJ(newBitmapHandle));
+	    }
+	}
     }
 fail: ;
     PRINTF(("create bitmap FAILED!!!\n"));
-    if (allocatedBits)
-    {
-      PRINTF(("freeing up bitmap bits ...\n"));
-      free(allocatedBits);
+    if (allocatedBits) {
+	PRINTF(("freeing up bitmap bits ...\n"));
+	free(allocatedBits);
     }
     DPRINTF(("returning nil ...\n"));
     RETURN ( nil );
@@ -5036,9 +5044,12 @@
 !
 
 setColor:index scaledRed:sred scaledGreen:sgreen scaledBlue:sblue
-
- 'setColor:index scaledRed:sred scaledGreen:sgreen scaledBlue:sblue' printCR.
-^ self.
+    "change a palette index.
+     This is not yet supported in the Windows Device 
+     - we assume and depend upon transparent 24bit trueColor mode."
+
+     'WinWorkstation [info]: #setColor:scaledRed:scaledGreen:scaledBlue: ignored' infoPrintCR.
+     ^ self.
 
     "Created: 30.1.1998 / 09:27:48 / md"
     "Modified: 30.1.1998 / 09:30:22 / md"
@@ -5064,6 +5075,7 @@
 	#crossHair              "/ IDC_CROSS
 	#fourWay                "/ IDC_SIZEALL
 	#upRightHand            "/ IDC_ARROW
+	#noDrop                 "/ IDC_NO
        )
 !
 
@@ -5125,6 +5137,7 @@
 	mask := maskPadded.
 
     ].
+
     src invert.
     1 to:src size do:[:index |
 	src byteAt:index put:((src byteAt:index) bitAnd:(mask byteAt:index)).
@@ -5135,8 +5148,8 @@
 	maskBits:mask
 	hotX:hx hotY:hy
 	width:cW height:cH.
-    cursor notNil ifTrue:[  ^ cursor ].
-    self halt.
+    cursor notNil ifTrue:[^ cursor ].
+    'WinWorkstation [warning]: could not create bitmap cursor' infoPrintCR.
 !
 
 cursorBitmapPadding
@@ -5291,6 +5304,9 @@
     if (shape == @symbol(execute)) {
 	RETURN ( __MKSMALLINT( (INT)IDC_APPSTARTING));
     }
+    if (shape == @symbol(noDrop)) {
+	RETURN ( __MKSMALLINT( (INT)IDC_NO));
+    }
 
     if (shape == @symbol(IDC_UPARROW)) {
 	RETURN ( __MKSMALLINT( (INT)IDC_UPARROW));
@@ -5334,86 +5350,79 @@
     HDC srcDC = (HDC)0;
     HDC dstDC = (HDC)0;
 
-    if (__isExternalAddress(srcGCId))
-    {
+    if (__isExternalAddress(srcGCId)) {
 	srcGcData = _GCDATA(srcGCId);
-    }
-    else
-    {
+    } else {
 	goto fail;
     }
     if (__isExternalAddress(dstGCId)) {
 	dstGcData = _GCDATA(dstGCId);
-    }
-    else
-    {
+    } else {
 	goto fail;
     }
 
     if (__bothSmallInteger(w, h)
      && __bothSmallInteger(srcX, srcY)
-     && __bothSmallInteger(dstX, dstY))
-    {
+     && __bothSmallInteger(dstX, dstY)) {
 	int fun = BITBLT_COPY;
-	if (srcGcData && dstGcData)
-	{
-	  fun = dstGcData->bitbltrop2;
+
+	if (srcGcData && dstGcData) {
+	    fun = dstGcData->bitbltrop2;
 #if 0
-	  switch (fun)
-	  {
-	    case BITBLT_COPY:
-	      printf("BITBLT_COPY\n");
-	      break;
-	    case BITBLT_COPYINVERTED:
-	      printf("BITBLT_COPYINVERTED\n");
-	      break;
-	    case BITBLT_XOR:
-	      printf("BITBLT_XOR\n");
-	      break;
-	    case BITBLT_AND:
-	      printf("BITBLT_AND\n");
-	      break;
-	    case BITBLT_OR:
-	      printf("BITBLT_OR\n");
-	      break;
-	  }
+	    switch (fun) {
+	      case BITBLT_COPY:
+		printf("BITBLT_COPY\n");
+		break;
+	      case BITBLT_COPYINVERTED:
+		printf("BITBLT_COPYINVERTED\n");
+		break;
+	      case BITBLT_XOR:
+		printf("BITBLT_XOR\n");
+		break;
+	      case BITBLT_AND:
+		printf("BITBLT_AND\n");
+		break;
+	      case BITBLT_OR:
+		printf("BITBLT_OR\n");
+		break;
+	    }
 #endif
-	  if (srcGcData->hWnd && ((srcGcData->hWnd == dstGcData->hWnd) && (fun == BITBLT_COPY)))
-	  {
-	    RECT rec,uprec;
-	    rec.left = __intVal(srcX);
-	    rec.top = __intVal(srcY);
-	    rec.right = rec.left + __intVal(w);
-	    rec.bottom = rec.top + __intVal(h);
-	    DPRINTF(("dst and src is HWND %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
-	    ScrollWindow(srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0);
-	    UpdateWindow(srcGcData->hWnd);
-	    if (GetWindow_eventMask(srcGcData->hWnd) & ExposureMask)
-	      enqEvent(ExposureMask,srcGcData->hWnd, __WM_NOGEXPOSE, 0, 0, 0, 0, 0);
-	    RETURN ( self );
-
-	  }
-	  if (srcGcData->hWnd)
-	  {
-	      /*printf("src is HWND %x\n",srcGcData->hWnd);*/
-	  }
-	  fun = dstGcData->bitbltrop2;
-	  if ((srcGcData == dstGcData) && (fun == BITBLT_COPY))
-	  {
-	    RECT rec,uprec;
-	    rec.left = __intVal(srcX);
-	    rec.top = __intVal(srcY);
-	    rec.right = rec.left + __intVal(w);
-	    rec.bottom = rec.top + __intVal(h);
-	    srcDC = _getDC(srcGcData);
-	    DPRINTF(("dst and src is DC %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
-	    ScrollDC(srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0,0,&uprec);
-	    _releaseDC(srcGcData);
-	    RETURN ( self );
-
-	  }
-	  else
-	  {
+	    if (srcGcData->hWnd 
+	     && ((srcGcData->hWnd == dstGcData->hWnd)
+	     && (fun == BITBLT_COPY))) {
+		RECT rec,uprec;
+
+		rec.left = __intVal(srcX);
+		rec.top = __intVal(srcY);
+		rec.right = rec.left + __intVal(w);
+		rec.bottom = rec.top + __intVal(h);
+		DPRINTF(("dst and src is HWND %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
+		ScrollWindow(srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0);
+		UpdateWindow(srcGcData->hWnd);
+		if (GetWindow_eventMask(srcGcData->hWnd) & ExposureMask)
+		    enqEvent(ExposureMask,srcGcData->hWnd, __WM_NOGEXPOSE, 0, 0, 0, 0, 0);
+		RETURN ( self );
+	    }
+
+	    if (srcGcData->hWnd) {
+		/*printf("src is HWND %x\n",srcGcData->hWnd);*/
+	    }
+	    fun = dstGcData->bitbltrop2;
+	    if ((srcGcData == dstGcData)
+	     && (fun == BITBLT_COPY)) {
+		RECT rec,uprec;
+
+		rec.left = __intVal(srcX);
+		rec.top = __intVal(srcY);
+		rec.right = rec.left + __intVal(w);
+		rec.bottom = rec.top + __intVal(h);
+		srcDC = _getDC(srcGcData);
+		DPRINTF(("dst and src is DC %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
+		ScrollDC(srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0,0,&uprec);
+		_releaseDC(srcGcData);
+		RETURN ( self );
+	    }
+
 	    srcDC = _getDC(srcGcData);
 	    dstDC = _getDC(dstGcData);
 	    DDPRINTF(("bitblt src f:%x b:%x",GetTextColor(srcDC),GetBkColor(srcDC)));
@@ -5425,22 +5434,20 @@
 		 __intVal(srcX), __intVal(srcY),
 		 fun)
 	       == 0
-	      )
-	      {
-		 __win32_fprintf(stderr, "WinWorkstation: ERROR in BitBlt\n");
-	      }
-	  }
-	  _releaseDC(dstGcData);
-	  _releaseDC(srcGcData);
-	  RETURN ( self );
+	      ) {
+		fprintf(stderr, "WinWorkstation [info]: ERROR in BitBlt\n");
+	    }
+
+	    _releaseDC(dstGcData);
+	    _releaseDC(srcGcData);
+	    RETURN ( self );
 	}
     }
 
  fail: ;
 %}.
- self primitiveFailed.
- ^ nil
-
+    self primitiveFailed.
+    ^ nil
 !
 
 copyPlaneFromId:sourceId x:srcX y:srcY gc:srcDCId to:destId x:dstX y:dstY gc:dstDCId
@@ -5500,22 +5507,20 @@
 
 	hDC = _getDC(gcData);
 
-	if (!(hPen = GcDataGetPen(hDC,gcData))) {
+	if (!(hPen = GcDataGetPen(hDC, gcData))) {
 	    DPRINTF(("displayArc: no pen\n"));
 	}
 	else
 	{
 	    double xB, yB, xE, yE, xR, yR;
 	    HPEN hSavePen = SelectObject(hDC, hPen);
+
 	    xR = w / 2;
 	    yR = h / 2;
-	    if (angle2 - angle1 >= 360)
-	    {
+	    if (angle2 - angle1 >= 360) {
 		xB = xE = __x + xR + 0.5;
 		yB = yE = __y /*+ yR + 0.5*/;
-	    }
-	    else
-	    {
+	    } else {
 		double sin(), cos();
 		if (angle1 <= 180)
 		  angle1 = 180 - angle1;
@@ -5540,7 +5545,7 @@
 		(int)xE, (int)yE);
 
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
+	    DelObject(hPen); gcData->hPen = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -5562,6 +5567,7 @@
 	int __x1 = __intVal(x1), __y1 = __intVal(y1);
 	HPEN hPen;
 	HDC hDC = _getDC(gcData);
+
 /*      DPRINTF(("displayLine: %d/%d -> %d/%d in %x\n",
 		    __intVal(x0), __intVal(y0),
 		    __x1, __y1,_HWNDVal(aDrawableId)));
@@ -5578,9 +5584,13 @@
 	     */
 	    LineTo(hDC, __x1+1, __y1);
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
-	}
+#ifndef CACHE_LAST_PEN
+	    DelObject(hPen); gcData->hPen = 0;
+#endif
+	}
+#ifndef CACHE_LAST_DC
 	_releaseDC(gcData);
+#endif
 	RETURN ( self );
     }
 %}
@@ -5598,8 +5608,20 @@
 	POINT p;
 	HPEN hPen;
 	int __x = __intVal(px), __y = __intVal(py);
+	int savedLStyle = gcData->lStyle;
+	int savedLWidth = gcData->lineWidth;
+
+	/*
+	 * a point is a point - no matter what lineWidth we have set before
+	 */
+	gcData->lStyle = PS_SOLID;
+	gcData->lineWidth = 0;
+
 	hDC = _getDC(gcData);
 
+	gcData->lStyle = savedLStyle;
+	gcData->lineWidth = savedLWidth;
+
 	if (!(hPen = GcDataGetPen(hDC,gcData))) {
 	    DPRINTF(("displayPoint: no pen\n"));
 	} else {
@@ -5610,7 +5632,7 @@
 	     */
 	    LineTo(hDC, __x+1, __y);
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
+	    DelObject(hPen); gcData->hPen = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -5623,12 +5645,11 @@
      which define the polygon.
      If any coordinate is not integer, an error is triggered."
 
-    |numberOfPoints |
-
-    numberOfPoints := aPolygon size.
     self
-	primDisplayPolygon:aPolygon n:numberOfPoints
-	in:aDrawableId with:aGCId
+	primDisplayPolygon:aPolygon 
+	n:(aPolygon size)
+	in:aDrawableId 
+	with:aGCId
 !
 
 displayRectangleX:x y:y width:width height:height in:aDrawableId with:aGCId
@@ -5653,20 +5674,21 @@
 	DPRINTF(("displayRectangle: %d/%d -> %d/%d\n",
 			xL, yT, w, h));
 	/*
-	 * need this check here: some servers simply dump core with bad args
+	 * need this check here: some X-servers simply dump core with bad args
 	 */
 	if ((w >= 0) && (h >= 0)) {
 	    if (!(hPen = GcDataGetPen(hDC,gcData))) {
 		DPRINTF(("displayRect: no pen\n"));
 	    } else {
 		HPEN hSavePen = SelectObject(hDC, hPen);
+
 		MoveToEx(hDC, xL, yT, NULL);
 		LineTo(hDC, xL+w-1, yT);
 		LineTo(hDC, xL+w-1, yT+h-1);
 		LineTo(hDC, xL, yT+h-1);
 		LineTo(hDC, xL, yT);
 		SelectObject(hDC,hSavePen);
-		DelObject(hPen);
+		DelObject(hPen); gcData->hPen = 0;
 	    }
 	}
 	_releaseDC(gcData);
@@ -5900,7 +5922,7 @@
 	} else {
 	  HBRUSH hSaveBrush = SelectObject(hDC, hBrush);
 	  HPEN hPen = 0;
-	  HPEN hSavePen;
+	  HPEN hSavePen = 0;
 
 	  if (__isWinNT) {
 	      if (!(hPen = GcDataGetPen(hDC,gcData))) {
@@ -5950,12 +5972,12 @@
 
 	      if (hPen) {
 		  SelectObject(hDC,hSavePen);
-		  DelObject(hPen);
+		  DelObject(hPen); gcData->hPen = 0;
 	      }
 	  }
 failpen:
 	  SelectObject(hDC,hSaveBrush);
-	  DelObject(hBrush);
+	  DelObject(hBrush); gcData->hBrush = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -6004,13 +6026,11 @@
 
 	    hDC = _getDC(gcData);
 	    hBrush = GcDataGetBrush(hDC,gcData);
-	    if (! hBrush)
-	    {
+	    if (! hBrush) {
 		PRINTF(("fillRectangle: no brush\n"));
-	    }
-	    else
-	    {
+	    } else {
 	      HBRUSH hSaveBrush = SelectObject(hDC, hBrush);
+
 	      rct.left = __intVal(x);
 	      rct.top = __intVal(y);
 	      rct.right = rct.left + w + 1;
@@ -6020,7 +6040,7 @@
 	      SelectObject(hDC, GetStockObject(NULL_PEN));
 	      Rectangle(hDC,rct.left,rct.top,rct.right,rct.bottom);
 	      SelectObject(hDC,hSaveBrush);
-	      DelObject(hBrush);
+	      DelObject(hBrush); gcData->hBrush = 0;
 	    }
 	    _releaseDC(gcData);
 	}
@@ -6039,7 +6059,7 @@
      && __isExternalAddress(aDrawableId)
      && __isSmallInteger(numberOfPoints)) {
 	struct gcData *gcData = _GCDATA(aGCId);
-	HDC hDC = _getDC(gcData);
+	HDC hDC = 0;
 	POINT p;
 	HPEN hPen;
 
@@ -6050,16 +6070,17 @@
 	    if (! __isPoint(point)) goto fail;
 	    px = _point_X(point);
 	    py = _point_Y(point);
-	    if (! __bothSmallInteger(px, py))
-	    {
-		_releaseDC(gcData);
+	    if (! __bothSmallInteger(px, py)) {
 		goto fail;
 	    }
 	}
+
+	hDC = _getDC(gcData);
 	if (!(hPen = GcDataGetPen(hDC,gcData))) {
 	    DPRINTF(("displayPolygon: no pen\n"));
 	} else {
 	    HPEN hSavePen = SelectObject(hDC, hPen);
+
 	    for (i=0; i<num; i++) {
 		point = __AT_(aPolygon, __MKSMALLINT(i+1));
 		px = _point_X(point);
@@ -6081,7 +6102,7 @@
 		}
 	    }
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
+	    DelObject(hPen); gcData->hPen = 0;
 	}
 
 	_releaseDC(gcData);
@@ -6231,8 +6252,9 @@
       PRINTF(("freeing up temp bitmap bits ...\n"));
       free(allocatedBits);
     }
-    if (gcData && hDC)
+    if (gcData && hDC) {
 	_releaseDC(gcData);
+    }
 %}
 .
     ^ false
@@ -6293,7 +6315,7 @@
 	    EndPath(hDC);
 	    FillPath(hDC);
 	    SelectObject(hDC,hSaveBrush);
-	    DelObject(hBrush);
+	    DelObject(hBrush); gcData->hBrush = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -6321,9 +6343,10 @@
     "system is about to be shut down.
      This is a speciality of windows.
      TODO: Tell all views to close themself.
-     For now,this is ignored."
-
-    'WinWorkstation [info]: queryEndSession ignored for now.' infoPrintCR
+     For now, this is ignored."
+
+    'WinWorkstation [info]: queryEndSession ignored for now.' infoPrintCR.
+    ^ true
 !
 
 systemColorChange:aWindow
@@ -6350,12 +6373,10 @@
 
 !WinWorkstation methodsFor:'event handling'!
 
-configEventProcessedFor:aWindowId
+XXconfigEventProcessedFor:aWindowId
 %{
-    if (__isExternalAddress(aWindowId))
-    {
-      HWND hWnd = _HWNDVal(aWindowId);
-
+    if (__isExternalAddress(aWindowId)) {
+	HWND hWnd = _HWNDVal(aWindowId);
     }
 %}
 !
@@ -6442,13 +6463,12 @@
     if (__isByteArray(eB)) {
 	ev = (struct queuedEvent *)(__ByteArrayInstPtr(eB)->ba_element);
     } else {
-	__win32_fprintf(stderr, "WinWorkstation: no eventBuffer\n");
+	fprintf(stderr, "WinWorkstation [error]: no eventBuffer\n");
 	RETURN (false);
     }
-    if (ev)
-    {
-      _ev_buf = *ev;
-      ev = &_ev_buf;
+    if (ev) {
+	_ev_buf = *ev;
+	ev = &_ev_buf;
     }
     hWnd = ev->ev_hWnd;
     if (!(hWnd /*&& IsWindow(hWnd)*/)) {
@@ -6520,15 +6540,16 @@
 		  char buf[MAXPATH];
 		  HDROP hDrop = (HDROP)ev->ev_wParam;
 		  int count = DragQueryFile(hDrop,0xffffffff,0,0);
+
 		  PRINTF((">>> WM_DROPFILES %d Files\n",count));
-		  for (i = 0;i < count;i++)
-		  {
-		    DragQueryFile(hDrop,i,buf,sizeof(buf));
-		    PRINTF(("Filename:%s\n",buf));
+		  for (i = 0;i < count;i++) {
+		      DragQueryFile(hDrop,i,buf,sizeof(buf));
+		      PRINTF(("Filename:%s\n",buf));
 		  }
 		  DragFinish(hDrop);
 		}
 		break;
+
 	    case WM_SHOWWINDOW:
 		if (ev->ev_wParam == TRUE) {
 		    DPRINTF((">>> WM_SHOWWINDOW -> mappedView:\n"));
@@ -6638,21 +6659,20 @@
 	    case WM_PAINT:
 #ifdef LATE_PAINT
 		{
-		  RECT rec;
-		  HDC dc = (HDC)GetDC(ev->ev_hWnd);
-		  HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(ev->ev_hWnd),0));
-		  if (br)
-		  {
-		    rec.left = ev->ev_x;
-		    rec.top = ev->ev_y;
-		    rec.right = ev->ev_w;
-		    rec.bottom = ev->ev_h;
-		    // printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
-		    SelectClipRgn(dc,0);
-		    FillRect(dc, &rec, br);
-		    DelObject(br);
-		  }
-		  ReleaseDC(ev->ev_hWnd,dc);
+		    RECT rec;
+		    HDC dc = (HDC)GetDC(ev->ev_hWnd);
+		    HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(ev->ev_hWnd),0));
+		    if (br) {
+			rec.left = ev->ev_x;
+			rec.top = ev->ev_y;
+			rec.right = ev->ev_w;
+			rec.bottom = ev->ev_h;
+			// printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
+			SelectClipRgn(dc,0);
+			FillRect(dc, &rec, br);
+			DelObject(br);
+		    }
+		    ReleaseDC(ev->ev_hWnd,dc);
 		}
 #endif
 		x = ev->ev_x;
@@ -6729,32 +6749,23 @@
 		__INST(shiftDown) = (modifiers & ShiftMask) ? true : false;
 		__INST(ctrlDown) = (modifiers & ControlMask) ? true : false;
 
-		if (isDoubleClick)
-		{
+		if (isDoubleClick) {
 		    multiClickState = 1;
 		    nextMultiClickTime = lastMSGTime + multiClickTime;
 		    ipS = &bmp;
 		    symS = @symbol(buttonMultiPress:x:y:view:);
-		}
-		else
-		{
-		    if (isDown)
-		    {
-			if (multiClickState && (lastMSGTime < nextMultiClickTime))
-			{
-			  nextMultiClickTime = lastMSGTime + multiClickTime;
-			  ipS = &bmp;
-			  symS = @symbol(buttonMultiPress:x:y:view:);
+		} else {
+		    if (isDown) {
+			if (multiClickState && (lastMSGTime < nextMultiClickTime)) {
+			    nextMultiClickTime = lastMSGTime + multiClickTime;
+			    ipS = &bmp;
+			    symS = @symbol(buttonMultiPress:x:y:view:);
+			} else {
+			    multiClickState = 0;
+			    ipS = &bp;
+			    symS = @symbol(buttonPress:x:y:view:);
 			}
-			else
-			{
-			  multiClickState = 0;
-			  ipS = &bp;
-			  symS = @symbol(buttonPress:x:y:view:);
-			}
-		    }
-		    else
-		    {
+		    } else {
 			ipS = &br;
 			symS = @symbol(buttonRelease:x:y:view:);
 		    }
@@ -7190,18 +7201,17 @@
 eventPendingWithSync:doSync
     "return true, if any event is pending.
      The doSync argument is ignored here - in windows, all drawing is synchronous."
+
     doSync notNil ifTrue:[self flush].
+
 %{  /* xxLIMITEDSTACK (WIN95 only) */
-    MSG msg;
-
-    if (__INST(inRecursiveDispatch) == true) {
-	RETURN (false);
-    }
-
-    if (isInputEvent()) {
-	RETURN (true);
+    if (__INST(inRecursiveDispatch) != true) {
+	if (hasEventQueued()) {
+	    RETURN (true);
+	}
     }
 %}.
+    ^ false
 !
 
 eventQueued
@@ -7221,13 +7231,13 @@
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 
     DDPRINTF(("peek q - "));
-    if (isInputEvent()) {
+    if (hasEventQueued()) {
 	DDPRINTF(("true\n"));
 	RETURN (true);
     }
     DDPRINTF(("false\n"));
-    RETURN ( false );
-%}
+%}.
+    ^ false
 !
 
 eventsPending:anEventMask for:aWindowIdOrNil withSync:doSync
@@ -7245,6 +7255,7 @@
     "return true, if any expose event is pending for a specific view,
      or any view (if the arg is nil).
      This is an X specific interface - not used on windows (scrolling is synchronous)"
+
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 %}.
     ^ false
@@ -7262,33 +7273,27 @@
     OBJ eB;
     struct queuedEvent *ev;
     struct queuedEvent *qev;
+
     eB = __INST(eventBuffer);
-    if (__isByteArray(eB)) {
-	ev = (struct queuedEvent *)(__ByteArrayInstPtr(eB)->ba_element);
-    } else {
-	__win32_fprintf(stderr, "WinWorkstation: no eventBuffer\n");
-	RETURN (false);
-    }
-    ev->ev_message = 0;
-
-    if (__isSmallInteger(eventMask)) {
-	evMask = __intVal(eventMask);
+    if (! __isByteArray(eB)) {
+	fprintf(stderr, "WinWorkstation [error]: no eventBuffer\n");
+	/* RETURN (false); */
     } else {
-	evMask = ~0;
-    }
-
-    if (__isExternalAddress(aViewIdOrNil))
-    {
-	if (deqEvent(ev,_HWNDVal(aViewIdOrNil),evMask))
-	{
-	  RETURN ( true );
-	}
-    }
-    else
-    {
-	if (deqEvent(ev,0,evMask))
-	{
-	  RETURN ( true );
+	ev = (struct queuedEvent *)(__ByteArrayInstPtr(eB)->ba_element);
+	ev->ev_message = 0;
+
+	if (__isSmallInteger(eventMask)) {
+	    evMask = __intVal(eventMask);
+	} else {
+	    evMask = ~0;
+	}
+	if (__isExternalAddress(aViewIdOrNil)) {
+	    wWanted = _HWNDVal(aViewIdOrNil);
+	} else{
+	    wWanted = 0;
+	}
+	if (deqEvent(ev, wWanted, evMask)) {
+	    RETURN ( true );
 	}
     }
 %}.
@@ -8141,6 +8146,7 @@
      {
 	struct gcData *gcData = _GCDATA(aGCId);
 	gcData->clipping = FALSE;
+	FLUSH_CACHED_DC(gcData);
 	RETURN (self);
     }
 %}
@@ -8157,11 +8163,13 @@
 	struct gcData *gcData = _GCDATA(aGCId);
 	COLORREF bgColor;
 
-	//hDC = _getDC(gcData);
 	bgColor = (COLORREF)st2RGB(__intVal(bgColorIndex),gcData);
 	if (bgColor != gcData->bgColor) {
 	    gcData->bgColor = bgColor;
-	    // SetBkColor(hDC, bgColor);
+	    // if (lastGcData == gcData) {
+	    //     SetBkColor(gcData->_hDC, bgColor);
+	    // }
+	    FLUSH_CACHED_DC(gcData);
 	}
 
 	DPRINTF(("setBackground: %x\n", bgColor));
@@ -8184,6 +8192,7 @@
 	else
 	    gcData->hMask = 0;
 
+	FLUSH_CACHED_DC(gcData);
 	DPRINTF(("masks set to %x\n",gcData->hMask));
 	RETURN (self);
     }
@@ -8195,26 +8204,17 @@
 
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 
-
-    if (ISCONNECTED && __isExternalAddress(aGCId))
-    {
+    if (ISCONNECTED && __isExternalAddress(aGCId)) {
 	struct gcData *gcData = _GCDATA(aGCId);
-	if (gcData && gcData->hWnd)
-	{
-	    if( aBool == true )
-	    {
+
+	if (gcData && gcData->hWnd) {
+	    if ( aBool == true ) {
 		/* set clip by child */
-		if (gcData->hWnd)
-		{
-		  gcData->clipByChild = TRUE;
-		}
-
+		gcData->clipByChild = TRUE;
 	    } else {
-		if (gcData->hWnd)
-		{
-		  gcData->clipByChild = FALSE;
-		}
-	    }
+		gcData->clipByChild = FALSE;
+	    }
+	    FLUSH_CACHED_DC(gcData);
 	} else {
 	    DPRINTF(("clipping by child failed - invalid win\n" ));
 	}
@@ -8247,6 +8247,7 @@
 	gcData->clipY = __intVal(clipY); 
 	gcData->clipW = __intVal(clipWidth); 
 	gcData->clipH = __intVal(clipHeight); 
+	FLUSH_CACHED_DC(gcData);
 	RETURN (self);
     }
 %}
@@ -8293,6 +8294,7 @@
 #endif
 	SelectObject(hDC, hFont);
 	_releaseDC(gcData);
+	FLUSH_CACHED_DC(gcData);
 	RETURN ( self );
     }
 %}
@@ -8308,6 +8310,11 @@
 
 	gcData->fgColor = (COLORREF)st2RGB(__intVal(fgColorIndex),gcData);
 	gcData->bgColor = (COLORREF)st2RGB(__intVal(bgColorIndex),gcData);
+	// if (lastGcData == gcData) {
+	//     SetTextColor(gcData->_hDC, fgColor);
+	//     SetBkColor(gcData->_hDC, bgColor);
+	// }
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x background: %x\n", gcData->fgColor, gcData->bgColor));
 	RETURN (self);
     }
@@ -8329,6 +8336,7 @@
 	    gcData->hMask = _HBITMAPVAL(aBitmapId);
 	else
 	    gcData->hMask = 0;
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x background: %x mask: %x\n", gcData->fgColor, gcData->bgColor,gcData->hMask));
 	RETURN (self);
     }
@@ -8351,6 +8359,7 @@
 	    gcData->hMask = _HBITMAPVAL(aBitmapId);
 	else
 	    gcData->hMask = 0;
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x background: %x mask: %x linewidth: %d\n", gcData->fgColor, gcData->bgColor,gcData->hMask,gcData->lineWidth));
 	RETURN (self);
     }
@@ -8368,6 +8377,7 @@
 	struct gcData *gcData = _GCDATA(aGCId);
 
 	gcData->fgColor = (COLORREF)st2RGB(__intVal(fgColorIndex),gcData);
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x\n", gcData->fgColor));
 	RETURN (self);
     }
@@ -8435,10 +8445,11 @@
 	    gcData->rop2 = R2_COPYPEN;
 	    gcData->bitbltrop2 = BITBLT_COPY;
 	}
+	FLUSH_CACHED_DC(gcData);
 	RETURN (self);
     }
     else
-	__win32_fprintf(stderr, "WinWorkstation: Rasterfunction no GC\n");
+	INFOPRINT((stderr, "WinWorkstation [warning]: Rasterfunction no GC\n"));
 %}
 !
 
@@ -8457,38 +8468,47 @@
     if (__isExternalAddress(aGCId)
      && __isSmallInteger(aNumber)) {
 	struct gcData *gcData = _GCDATA(aGCId);
+	int style;
 
 	gcData->lineWidth = __intVal(aNumber);
 	if (lineStyle == @symbol(solid)) {
-	    gcData->lineStyle = PS_SOLID;
+	    style = PS_SOLID;
 	} else if (lineStyle == @symbol(dashed)) {
-	    gcData->lineStyle = PS_DASH;
+	    style= PS_DASH;
 	} else if (lineStyle == @symbol(dotted)) {
-	    gcData->lineStyle = PS_DOT;
+	    style= PS_DOT;
 	} else if (lineStyle == @symbol(dashDot)) {
-	    gcData->lineStyle = PS_DASHDOT;
+	    style= PS_DASHDOT;
 	} else if (lineStyle == @symbol(dashDotDot)) {
-	    gcData->lineStyle = PS_DASHDOTDOT;
+	    style= PS_DASHDOTDOT;
 	} else
-	    gcData->lineStyle = PS_SOLID;
+	    style= PS_SOLID;
+	gcData->lStyle &= ~PS_STYLE_MASK;
+	gcData->lStyle |= style;
+
 
 	if (capStyle == @symbol(round)) {
-	    gcData->capStyle = PS_ENDCAP_ROUND;
+	    style = PS_ENDCAP_ROUND;
 	} else if (capStyle == @symbol(square)) {
-	    gcData->capStyle = PS_ENDCAP_SQUARE;
+	    style = PS_ENDCAP_SQUARE;
 	} else if (capStyle == @symbol(flat)) {
-	    gcData->capStyle = PS_ENDCAP_FLAT;
+	    style = PS_ENDCAP_FLAT;
 	} else
-	    gcData->capStyle = PS_ENDCAP_FLAT;
-
+	    style = PS_ENDCAP_FLAT;
+	gcData->lStyle &= ~PS_ENDCAP_MASK;
+	gcData->lStyle |= style;
+        
 	if (joinStyle == @symbol(bevel)) {
-	    gcData->joinStyle = PS_JOIN_BEVEL;
+	    style = PS_JOIN_BEVEL;
 	} else if (joinStyle == @symbol(miter)) {
-	    gcData->joinStyle = PS_JOIN_MITER;
+	    style = PS_JOIN_MITER;
 	} else if (joinStyle == @symbol(round)) {
-	    gcData->joinStyle = PS_JOIN_ROUND;
+	    style = PS_JOIN_ROUND;
 	} else
-	    gcData->joinStyle = PS_JOIN_MITER;
+	    style = PS_JOIN_MITER;
+	gcData->lStyle &= ~PS_JOIN_MASK;
+	gcData->lStyle |= style;
+	FLUSH_CACHED_DC(gcData);
 
 	RETURN (self);
     }
@@ -8506,6 +8526,7 @@
 
 	    gcData->maskOrgX = __intVal(orgX);
 	    gcData->maskOrgY = __intVal(orgY);;
+	    FLUSH_CACHED_DC(gcData);
 	    RETURN (self);
 	}
     }
@@ -8524,6 +8545,7 @@
 	else
 	    gcData->hMask = 0;
 
+	FLUSH_CACHED_DC(gcData);
 	DPRINTF(("PixmapMasks set to %x\n",gcData->hMask));
 	RETURN (self);
     }
@@ -8533,7 +8555,7 @@
 !WinWorkstation methodsFor:'initialize / release'!
 
 close
-    "close down the connection to the X-server"
+    "close down the connection to the display"
 
 !
 
@@ -9394,12 +9416,12 @@
 		 == 0
 		)
 	    {
-		__win32_fprintf(stderr, "WinWorkstation: in primGetBitsFrom: BitBlt\n");
+		INFOPRINT((stderr, "WinWorkstation [warning]: in primGetBitsFrom: BitBlt\n"));
 	    }
 	    ReleaseDC(hWnd,wDC);
 	    if (GetDIBits(bDC,hBitmap,0,height,0,(struct tagBITMAPINFO *)&bitmap,DIB_RGB_COLORS) == 0)
 	    {
-		__win32_fprintf(stderr, "WinWorkstation: noinfo returned in primGetBits\n");
+		INFOPRINT((stderr, "WinWorkstation [warning]: noinfo returned in primGetBits\n"));
 		goto fail;
 	    }
 	    DPRINTF(("bitmap info:%d %d %d %d\n",bitmap.bmiHeader.biWidth,bitmap.bmiHeader.biHeight,bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biSizeImage));
@@ -9410,7 +9432,7 @@
 
 		if (numBytes > __byteArraySize(imageBits)) {
 		    /* imageBits too small */
-		    __win32_fprintf(stderr, "WinWorkstation [warning]: primGetBits - provided byteArray too small\n");
+		    INFOPRINT((stderr, "WinWorkstation [warning]: primGetBits - provided byteArray too small\n"));
 		    goto fail;
 		}
 		DPRINTF(("numBytes %d\n",numBytes));
@@ -9418,7 +9440,7 @@
 		bitmap.bmiHeader.biHeight = -height;
 		if (GetDIBits(bDC,hBitmap,0,height,__ByteArrayInstPtr(imageBits)->ba_element,(struct tagBITMAPINFO *)&bitmap,DIB_RGB_COLORS) == 0)
 		{
-		    __win32_fprintf(stderr, "WinWorkstation: zero bits returned in primGetBits\n");
+		    INFOPRINT((stderr, "WinWorkstation [warning]: zero bits returned in primGetBits\n"));
 		    goto fail;
 		}
 
@@ -9429,11 +9451,11 @@
 		      cp[2] = b;
 		}
 	    } else {
-		__win32_fprintf(stderr, "WinWorkstation: unacceptable bitmap in primGetBits\n");
+		INFOPRINT((stderr, "WinWorkstation [warning]: unacceptable bitmap in primGetBits\n"));
 		goto fail;
 	    }
 	} else {
-	    __win32_fprintf(stderr, "WinWorkstation: unacceptable bitmap in primGetBits\n");
+	    INFOPRINT((stderr, "WinWorkstation [warning]: unacceptable bitmap in primGetBits\n"));
 	    goto fail;
 	}
 
@@ -9659,23 +9681,21 @@
     OBJ s;
 
     hClip = OpenClipboard(NULL);
-    if (hClip)
-    {
-      hData = GetClipboardData(CF_TEXT);
-      CloseClipboard();
-      printf("WinWorkstation: clipBoard data is <%s>\n", (char *)hData);
-      s = __MKSTRING( (char *)hData );
-      RETURN(s);
+    if (hClip) {
+	hData = GetClipboardData(CF_TEXT);
+	CloseClipboard();
+	INFOPRINT((stderr, "WinWorkstation [info]: clipBoard data is <%s>\n", (char *)hData));
+	s = __MKSTRING( (char *)hData );
+	RETURN(s);
     }
     RETURN(nil);
 %}
 !
 
 getSelectionFor:drawableId
-    'getSelectionFor: not yet implemented' errorPrintCR.
+    'WinWorkstation [warning]:getSelectionFor: not yet implemented' errorPrintCR.
+
     ^ nil
-
-
 ! !
 
 !WinWorkstation methodsFor:'style defaults'!
@@ -10326,6 +10346,6 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/WinWorkstat.st,v 1.71 1998-09-25 18:25:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/WinWorkstat.st,v 1.72 1998-09-28 09:25:02 cg Exp $'
 ! !
 WinWorkstation initialize!
--- a/WinWorkstation.st	Fri Sep 25 20:25:25 1998 +0200
+++ b/WinWorkstation.st	Mon Sep 28 11:25:02 1998 +0200
@@ -30,31 +30,31 @@
 #define WIN32THREADS
 /*#define DEBUGMASK*/
 
-# undef INT
-# define INT WIN_INT
-# undef Array
-# define Array WIN_Array
-# undef Number
-# define Number WIN_Number
-# undef Method
-# define Method WIN_Method
-# undef Point
-# define Point WIN_Point
-# undef Rectangle
-/*# define Rectangle WIN_Rectangle*/
-# undef True
-# define True WIN_True
-# undef False
-# define False WIN_False
-# undef Block
-# define Block WIN_Block
-# undef Context
-# define Context WIN_Context
-
-# undef xxCONTEXT
-# define xxCONTEXT        WIN_CONTEXT
-# undef _xxCONTEXT
-# define _xxCONTEXT       _WIN_CONTEXT
+#undef INT
+#define INT WIN_INT
+#undef Array
+#define Array WIN_Array
+#undef Number
+#define Number WIN_Number
+#undef Method
+#define Method WIN_Method
+#undef Point
+#define Point WIN_Point
+#undef Rectangle
+/* #define Rectangle WIN_Rectangle*/
+#undef True
+#define True WIN_True
+#undef False
+#define False WIN_False
+#undef Block
+#define Block WIN_Block
+#undef Context
+#define Context WIN_Context
+
+#undef xxCONTEXT
+#define xxCONTEXT        WIN_CONTEXT
+#undef _xxCONTEXT
+#define _xxCONTEXT       _WIN_CONTEXT
 
 
 #include <stdio.h>
@@ -101,32 +101,33 @@
 
 #include <process.h>
 
-#   ifdef __DEF_Array
-#    undef Array
-#    define Array __DEF_Array
-#   endif
-#   ifdef __DEF_Number
-#    undef Number
-#    define Number __DEF_Number
-#   endif
-#   ifdef __DEF_Method
-#    undef Method
-#    define Method __DEF_Method
-#   endif
-#   ifdef __DEF_Point
-#    undef Point
-#    define Point __DEF_Point
-#   endif
-#   ifdef __DEF_Block
-#    undef Block
-#    define Block __DEF_Block
-#   endif
-#   ifdef __DEF_Context
-#    undef Context
-#    define Context __DEF_Context
-#   endif
-#   undef INT
-#   define INT int
+#ifdef __DEF_Array
+# undef Array
+# define Array __DEF_Array
+#endif
+#ifdef __DEF_Number
+# undef Number
+# define Number __DEF_Number
+#endif
+#ifdef __DEF_Method
+# undef Method
+# define Method __DEF_Method
+#endif
+#ifdef __DEF_Point
+# undef Point
+# define Point __DEF_Point
+#endif
+#ifdef __DEF_Block
+# undef Block
+# define Block __DEF_Block
+#endif
+#ifdef __DEF_Context
+# undef Context
+# define Context __DEF_Context
+#endif
+#undef INT
+
+#define INT int
 
 /*
  * some defines - tired of typing ...
@@ -154,22 +155,22 @@
     int         clipY;
     int         clipW;
     int         clipH;
-    int         clipByChild;
+    short       clipByChild;
+    short       bitmapColorBitCount;
     HDC         _hDC;
     HBITMAP     hMask;
     int         maskOrgX;
     int         maskOrgY;
-    int         bitmapColorBitCount;
-    int         lineWidth;
-    int         lineStyle;
-    int         joinStyle;
-    int         capStyle;
-    int         fontAscent;
+    short       lineWidth;
+    short       fontAscent;
+    int         lStyle;   /* is lineStyle | joinStyle | capStyle */
     int         rop2;
     int         bitbltrop2;
     COLORREF    fgColor;
     COLORREF    bgColor;
     HFONT       hFont;
+    HPEN        hPen;
+    HBRUSH      hBrush;
 };
 
 /*
@@ -248,13 +249,13 @@
 #define MappingNotify           34
 #define LASTEvent               35      /* must be bigger than any event # */
 
-/*# define Button1MotionMask      1
-# define Button2MotionMask      2
-# define Button3MotionMask      4
-
-# define Button1Mask            Button1MotionMask
-# define Button2Mask            Button2MotionMask
-# define Button3Mask            Button3MotionMask*/
+/*#define Button1MotionMask      1
+#define Button2MotionMask       2
+#define Button3MotionMask       4
+
+#define Button1Mask             Button1MotionMask
+#define Button2Mask             Button2MotionMask
+#define Button3Mask             Button3MotionMask*/
 
 /* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
    state in various key-, mouse-, and button-related events. */
@@ -284,11 +285,11 @@
 /* button masks.  Used in same manner as Key masks above. Not to be confused
    with button names below. */
 
-# define Button1Mask            Button1MotionMask
-# define Button2Mask            Button2MotionMask
-# define Button3Mask            Button3MotionMask
-# define Button4Mask            Button4MotionMask
-# define Button5Mask            Button5MotionMask
+#define Button1Mask            Button1MotionMask
+#define Button2Mask            Button2MotionMask
+#define Button3Mask            Button3MotionMask
+#define Button4Mask            Button4MotionMask
+#define Button5Mask            Button5MotionMask
 
 #define AnyModifier             (1<<15)  /* used in GrabButton, GrabKey */
 
@@ -307,11 +308,11 @@
 #define CAPTURE_IMPLICIT 7
 #define CAPTURE_EXPLICIT 8
 
-/*# define ControlMask            8
-# define ShiftMask              16*/
-# define LeftAltMask            Mod1Mask
-# define RightAltMask           Mod2Mask
-# define TRANSLATED_KEY         Mod5Mask
+/*#define ControlMask            8
+#define ShiftMask              16*/
+#define LeftAltMask            Mod1Mask
+#define RightAltMask           Mod2Mask
+#define TRANSLATED_KEY         Mod5Mask
 
 #define WIN32PADDING 32
 /*
@@ -325,8 +326,8 @@
 static int AltMask = RightAltMask;
 static int MetaMask = LeftAltMask;
 
-# define WhitePixel     RGB(0xFF, 0xFF, 0xFF)
-# define BlackPixel     RGB(0, 0, 0)
+#define WhitePixel     RGB(0xFF, 0xFF, 0xFF)
+#define BlackPixel     RGB(0, 0, 0)
 
 /*#undef DEBUG*/
 #ifdef DEBUG
@@ -364,12 +365,12 @@
 	__win32_fprintf __x__;           \
     }
 
-# define BR_SOLID       0
-# define BR_PATTERN     1
-
-# define LINE_SOLID     0
-# define LINE_DASH      1
-# define LINE_DDASH     2
+#define BR_SOLID       0
+#define BR_PATTERN     1
+
+#define LINE_SOLID     0
+#define LINE_DASH      1
+#define LINE_DDASH     2
 
 #ifdef KEEP_STD_CURSORS
 # define _C_ARROW       1
@@ -411,7 +412,12 @@
 static HDC tmpDC;
 static int __isWinNT;
 static int __logPixelSY;
-static struct gcData *lastGcData;
+static struct gcData *lastGcData = 0;
+static int            lastGcOwnerThreadID = 0;
+
+#define xxCACHE_LAST_DC
+#define xxCACHE_LAST_PEN
+#define xxCACHE_LAST_BRUSH
 
 #define WM_THREADCREATEWINDOW   WM_USER + 0x101
 #define WM_THREADDESTROYWINDOW  WM_USER + 0x102
@@ -420,9 +426,10 @@
 #define WM_THREADSETCURSOR      WM_USER + 0x105
 
 #define THREADINPUTEVENTNAME "InputEvents"
-#define THREADEVENTNAME "CreateEvents"
-#define THREADMUTEXNAME "MutexToProtectEvents"
-#define isInputEvent() ((int)eventQueueHead)
+#define THREADEVENTNAME      "CreateEvents"
+#define THREADMUTEXNAME      "MutexToProtectEvents"
+
+#define hasEventQueued() ((int)eventQueueHead)
 
 typedef int (*intf)(int);
 
@@ -431,8 +438,8 @@
  */
 #define LI_TOPWIN       0x0001
 #define LI_INPUTWIN     0x0002
-typedef struct
-{
+
+typedef struct {
 	HCURSOR hCursor;
 	int bgBrush;
 	int flag;
@@ -517,6 +524,12 @@
 #define BITBLT_AND              SRCAND
 #define BITBLT_OR               SRCPAINT
 
+/*
+ * need threadSafe printf versions
+ */
+#define printf  __win32_printf
+#define fprintf __win32_fprintf
+#define fflush  __win32_fflush
 
 %}
 ! !
@@ -535,7 +548,7 @@
 static HDESK __rootDesk;
 #endif
 
-static int buttonClickWindowsLike = 1;
+static int activateOnClick = 1;
 
 static int currentCapture = CAPTURE_NONE;
 static int lastNCMouseX, lastNCMouseY;
@@ -680,7 +693,7 @@
 {
     int r = DeleteObject(o);
     if (r == 0)
-	__win32_fprintf(stderr, "WinWorkstation: ERROR in DelObjectect\n");
+	fprintf(stderr, "WinWorkstation: ERROR in DelObjectect\n");
     return r;
 }
 
@@ -693,14 +706,15 @@
     }
     memset(gcData, 0, sizeof(struct gcData));
     gcData->fgColor = 0xffffff;
+    /* gcData->bgColor = 0; - not needed - memset does it */
     gcData->clipping = FALSE;
     gcData->clipByChild = TRUE;
     gcData->bitbltrop2 = BITBLT_COPY;
     gcData->lineWidth = 1;
-    gcData->lineStyle = PS_SOLID;
-    gcData->joinStyle = PS_JOIN_MITER;
-    gcData->capStyle = PS_ENDCAP_FLAT;
+    gcData->lStyle = PS_SOLID | PS_JOIN_MITER | PS_ENDCAP_FLAT;
     /* gcData->brushOrgX = gcData->brushOrgY = 0; - not needed - memset does it */
+    /* gcData->hPen = 0; - not needed - memset does it */
+    /* gcData->hBrush = 0; - not needed - memset does it */
     return gcData;
 }
 
@@ -709,30 +723,78 @@
 {
 }
 
+#ifdef CACHE_LAST_DC
+# define FLUSH_CACHED_DC(__gcData__) \
+    if (lastGcData == __gcData__) {  \
+	_releaseDC(lastGcData);      \
+    }
+#else
+# define FLUSH_CACHED_DC(x)     /* */
+#endif
+
+#ifdef CACHE_LAST_PEN
+# define FLUSH_CACHED_PEN(__gcData__) \
+    if (__gcData__->hPen) {           \
+	DelObject(gcData->hPen);      \
+	gcData->hPen = 0;             \
+    }
+#else
+# define FLUSH_CACHED_PEN(x)    /* */
+#endif
+
+#ifdef CACHE_LAST_BRUSH
+# define FLUSH_CACHED_BRUSH(__gcData__) \
+    if (__gcData__->hBrush) {           \
+	DelObject(gcData->hBrush);      \
+	gcData->hBrush = 0;             \
+    }
+#else
+# define FLUSH_CACHED_BRUSH(x)    /* */
+#endif
+
 static void
 _releaseDC(struct gcData *gcData)
 {
     if (gcData->hWnd) {
 	if (gcData->_hDC) {
-	    ReleaseDC(gcData->hWnd,gcData->_hDC);
+	    ReleaseDC(gcData->hWnd, gcData->_hDC);
 	}
     } else if (gcData->hBitmap) {
-	SelectObject(gcData->_hDC,gcData->savehBitmap);
+	SelectObject(gcData->_hDC, gcData->savehBitmap);
 	DeleteDC(gcData->_hDC);
     }
+
+#ifdef CACHE_LAST_PEN
+    if (gcData->hPen) {
+	DelObject(gcData->hPen);
+	gcData->hPen = 0;
+    }
+#endif
+#ifdef CACHE_LAST_BRUSH
+    if (gcData->hBrush) {
+	DelObject(gcData->hBrush);
+	gcData->hBrush = 0;
+    }
+#endif
+#ifdef CACHE_LAST_DC
+    if (lastGcData == gcData) {
+	lastGcData = 0;
+    }
+#endif
     gcData->_hDC = 0;
 }
 
 static HDC
 _getDC(struct gcData *gcData)
 {
-#if 0
+#ifdef CACHE_LAST_DC
     if (lastGcData) {
-	if (lastGcData == gcData) {
+	if ((lastGcData == gcData) 
+	 && (lastGcOwnerThreadID == GetCurrentThreadId())) {
 	    //printf(".");
 	    return gcData->_hDC;
 	}
-	__releaseDC(lastGcData);
+	_releaseDC(lastGcData);
     }
 #endif
 
@@ -771,7 +833,10 @@
 	    }
 	}
     }
+#ifdef CACHE_LAST_DC
     lastGcData = gcData;
+    lastGcOwnerThreadID == GetCurrentThreadId();
+#endif
     return gcData->_hDC;
 }
 
@@ -780,6 +845,11 @@
 {
     HBRUSH hBrush = 0;
 
+#ifdef CACHE_LAST_BRUSH
+    if (gcData->hBrush) {
+	return gcData->hBrush;
+    }
+#endif
     if (gcData->hMask) {
 	hBrush = CreatePatternBrush(gcData->hMask);
 	SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);       
@@ -788,95 +858,101 @@
 	hBrush = CreateSolidBrush(gcData->fgColor);
 	RESPRINTF(("CreateSolidBrush %x\n",gcData->fgColor));
     }
+#ifdef CACHE_LAST_BRUSH
+    gcData->hBrush = hBrush;
+#endif
     return hBrush;
 }
 
 static HPEN
-GcDataGetPen(HDC hDC,struct gcData *gcData)
+GcDataGetPen(HDC hDC, struct gcData *gcData)
 {
     HPEN hPen = 0;
     LOGBRUSH Brush;
 
-    if (__isWinNT)
-    {
-      if (gcData->hMask)
-      {
-	  Brush.lbStyle = BS_PATTERN;
-	  Brush.lbHatch = (DWORD)gcData->hMask;
-	  Brush.lbColor = gcData->fgColor;
-	  hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
-			    gcData->lineWidth,
-			    &Brush,
-			    0,0);
-	  SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
-	  RESPRINTF(("ExtCreatePen %d %d %x %x\n",gcData->lineStyle,
-						gcData->lineWidth,
-						gcData->fgColor,gcData->hMask));
-      }
-      else
-      {
-	  Brush.lbStyle = BS_SOLID;
-	  Brush.lbHatch = 0;
-	  Brush.lbColor = gcData->fgColor;
-	  hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
-			    gcData->lineWidth,
-			    &Brush,
-			    0,0);
-	  RESPRINTF(("ExtCreatePen1 %d %d %x %x\n",gcData->lineStyle,
-
-						gcData->lineWidth,
-						gcData->fgColor,gcData->hMask));
-      }
-    }
-    else
-    {
-      if (gcData->lineStyle == PS_SOLID)
-      {
-	if (gcData->hMask)
-	{
+#ifdef CACHE_LAST_PEN
+    if (gcData->hPen) {
+	return gcData->hPen;
+    }
+#endif
+    if (__isWinNT) {
+	/*
+	 * NT supports masked drawing with any lineStyle
+	 */
+	if (gcData->hMask) {
 	    Brush.lbStyle = BS_PATTERN;
 	    Brush.lbHatch = (DWORD)gcData->hMask;
 	    Brush.lbColor = gcData->fgColor;
-	    hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
-			      gcData->lineWidth,
-			      &Brush,
-			      0,0);
-	    SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
-	    RESPRINTF(("ExtCreatePen %d %d %x %x\n",gcData->lineStyle,
-						  gcData->lineWidth,
-						  gcData->fgColor,gcData->hMask));
-	}
-	else
-	{
+	} else {
 	    Brush.lbStyle = BS_SOLID;
 	    Brush.lbHatch = 0;
 	    Brush.lbColor = gcData->fgColor;
-	    hPen = ExtCreatePen(PS_GEOMETRIC | gcData->capStyle | gcData->joinStyle | gcData->lineStyle,
+	}
+
+	hPen = ExtCreatePen(PS_GEOMETRIC | gcData->lStyle,
+			  gcData->lineWidth,
+			  &Brush,
+			  0, 0);
+	RESPRINTF(("ExtCreatePen1 %x %d %x %x\n",
+			gcData->lStyle,
+			gcData->lineWidth,
+			gcData->fgColor, gcData->hMask));
+
+	if (gcData->hMask) {
+	    SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
+	}
+    } else {
+	/*
+	 * W95 only supports masked drawing with SOLID lines
+	 */
+	if ((gcData->lStyle & PS_STYLE_MASK) == PS_SOLID) {
+	    if (gcData->hMask) {
+		Brush.lbStyle = BS_PATTERN;
+		Brush.lbHatch = (DWORD)gcData->hMask;
+		Brush.lbColor = gcData->fgColor;
+	    } else {
+		Brush.lbStyle = BS_SOLID;
+		Brush.lbHatch = 0;
+		Brush.lbColor = gcData->fgColor;
+	    }
+
+	    hPen = ExtCreatePen(PS_GEOMETRIC | gcData->lStyle,
 			      gcData->lineWidth,
 			      &Brush,
-			      0,0);
-	    RESPRINTF(("ExtCreatePen1 %d %d %x %x\n",gcData->lineStyle,
-						  gcData->lineWidth,
-						  gcData->fgColor,gcData->hMask));
-	}
-      }
-    }
-    if (! hPen) {
-	if (gcData->lineStyle == PS_SOLID)
-	    hPen = CreatePen(gcData->lineStyle,
-			     gcData->lineWidth,
-			     gcData->fgColor);
-	else
-	    hPen = CreatePen(gcData->lineStyle,
-			     0,
-			     gcData->fgColor);
-
-	RESPRINTF(("CreatePen %d %d %x\n",gcData->lineStyle,
-					  gcData->lineWidth,
-					  gcData->fgColor));
-	//SetTextColor(gcData->_hDC, gcData->fgColor);
-	SetBkMode(gcData->_hDC, TRANSPARENT);
-    }
+			      0, 0);
+	    RESPRINTF(("ExtCreatePen1 %x %d %x %x\n",
+			    gcData->lStyle,
+			    gcData->lineWidth,
+			    gcData->fgColor, gcData->hMask));
+	    if (gcData->hMask) {
+		SetBrushOrgEx(hDC, gcData->maskOrgX, gcData->maskOrgY, 0);
+	    }
+	} else {
+	    /*
+	     * dashes only supported with lineWidth 0
+	     */
+	    if ((gcData->lStyle & PS_STYLE_MASK) == PS_SOLID) {
+		hPen = CreatePen((gcData->lStyle & PS_STYLE_MASK),
+				 gcData->lineWidth,
+				 gcData->fgColor);
+	    } else {
+		hPen = CreatePen((gcData->lStyle & PS_STYLE_MASK),
+				 0,
+				 gcData->fgColor);
+	    }
+	    RESPRINTF(("CreatePen %x %d %x\n",
+				(gcData->lStyle & PS_STYLE_MASK),
+				gcData->lineWidth,
+				gcData->fgColor));
+	    //SetTextColor(gcData->_hDC, gcData->fgColor);
+	    SetBkMode(gcData->_hDC, TRANSPARENT);
+	}
+    }
+
+#ifdef CACHE_LAST_PEN
+    gcData->hPen = hPen;
+#endif
+
     return hPen;
 }
 
@@ -936,7 +1012,7 @@
     bulk = (struct queuedEvent *) malloc(EV_CHUNK_SZ);
     if (bulk == 0)
     {
-	__win32_fprintf(stderr, "WinWorkstation: no memory for dispatchqueue\n");
+	fprintf(stderr, "WinWorkstation: no memory for dispatchqueue\n");
 	return 0;
     }
     for (i=1; i<EV_CHUNK_CNT; i++) {
@@ -991,7 +1067,7 @@
 	     goto again;
 	  }
 	}
-	__win32_fprintf(stderr, "WinWorkstation: event throw away\n");
+	fprintf(stderr, "WinWorkstation: event throw away\n");
 	/* throw away sorry */
 	return;
       }
@@ -1009,104 +1085,87 @@
 {
   struct queuedEvent *ev = 0;
 
-  if (mask != ~0)
-  {
-    PRINTF(("deqEvent mask:%x\n",mask));
+  if (mask != ~0) {
+      PRINTF(("deqEvent mask:%x\n",mask));
   }
-  if (hWnd)
-  {
-    PRINTF(("deqEvent hWnd:%x\n",hWnd));
+  if (hWnd) {
+      PRINTF(("deqEvent hWnd:%x\n",hWnd));
   }
-  if (lockEvent())
-  {
-
-    while (TRUE)
-    {
-      TH_DPRINTF(("TDEQ\n"));
-      ev = eventQueueHead;
-      if (ev)
-      {
-	eventQueueHead = ev->ev_next;
-	if (! eventQueueHead)
-	{
-	    eventQueueTail = (struct queuedEvent *)0;
-	}
-	if (eventempfcount != ev->count)
-	{
-	  printf("eventcount error %d <-> %d\n",eventempfcount,ev->count);
-	}
-	eventempfcount++;
-	if (ev->ev_message == WM_DESTROY)
-	{
-	    if (ev->ev_arg2)
-	    {
-	      free((char*)ev->ev_arg2);
-	    }
-#ifdef TOPWINDOWCLASS
-	    if (ev->ev_arg1)
-	    {
-	      if (UnregisterClass((char*)ev->ev_arg1,(HANDLE) __getHInstance()))
-	      {
-		/*printf("UnregisterClass %s ok.\n",(char*)ev->ev_arg1);*/
-		free((char*)ev->ev_arg1);
-		ev->ev_arg1 = 0;
+  if (lockEvent()) {
+      while (TRUE) {
+	  TH_DPRINTF(("TDEQ\n"));
+	  ev = eventQueueHead;
+	  if (ev) {
+	      eventQueueHead = ev->ev_next;
+	      if (! eventQueueHead) {
+		  eventQueueTail = (struct queuedEvent *)0;
+	      }
+	      if (eventempfcount != ev->count) {
+		  printf("eventcount error %d <-> %d\n",eventempfcount,ev->count);
 	      }
-	      else
-	      {
-		/* noch einmal in die queue */
-		if (ev->ev_arg2++ < 100)
-		{
-		  ev->ev_next = (struct queuedEvent *)0;
-		  ev->count = eventsendcount++;
-
-		  if (eventQueueTail) {
-		      eventQueueTail->ev_next = ev;
-		  } else {
-		      eventQueueHead = ev;
-		  }
-		  eventQueueTail = ev;
-		  if (ev->ev_arg2 > 98)
-		  {
-		    __win32_fprintf(stderr, "WinWorkstation: UnregisterClass %s failed. Wait 1 sec.\n",(char*)ev->ev_arg1);
-		    unlockEvent();
-		    sleep(1);
-		    lockEvent();
-		  }
-		  else
-		  {
-		    unlockEvent();
-		    sleep(0);
-		    lockEvent();
+	      eventempfcount++;
+	      if (ev->ev_message == WM_DESTROY) {
+		  if (ev->ev_arg2) {
+		      free((char*)ev->ev_arg2);
+		      ev->ev_arg2 = 0;
 		  }
-		  continue;
-		}
-		else /* fail evtl. später ändern und in st verzögert aufrufen */
-		{
-		  __win32_fprintf(stderr, "WinWorkstation: UnregisterClass %s failed.\n",(char*)ev->ev_arg1);
-		  free((char*)ev->ev_arg1);
-		  ev->ev_arg1 = 0;
-		}
+#ifdef TOPWINDOWCLASS
+		  if (ev->ev_arg1) {
+		      if (UnregisterClass((char*)ev->ev_arg1,(HANDLE) __getHInstance())) {
+			  /*printf("UnregisterClass %s ok.\n",(char*)ev->ev_arg1);*/
+			  free((char*)ev->ev_arg1);
+			  ev->ev_arg1 = 0;
+		      } else {
+			  /* noch einmal in die queue */
+			  if (ev->ev_arg2++ < 100) {
+			      ev->ev_next = (struct queuedEvent *)0;
+			      ev->count = eventsendcount++;
+
+			      if (eventQueueTail) {
+				  eventQueueTail->ev_next = ev;
+			      } else {
+				  eventQueueHead = ev;
+			      }
+			      eventQueueTail = ev;
+			      if (ev->ev_arg2 > 98) {
+				  fprintf(stderr, "WinWorkstation: UnregisterClass %s failed. Wait 1 sec.\n",(char*)ev->ev_arg1);
+				  unlockEvent();
+				  sleep(1);
+				  lockEvent();
+			      } else {
+				  unlockEvent();
+				  sleep(0);
+				  lockEvent();
+			      }
+			      continue;
+			  } else {
+			      /* fail evtl. später ändern und in st verzögert aufrufen */
+			      fprintf(stderr, "WinWorkstation: UnregisterClass %s failed.\n",(char*)ev->ev_arg1);
+			      free((char*)ev->ev_arg1);
+			      ev->ev_arg1 = 0;
+			  }
+		      }
+		  }
+#endif
 	      }
-	    }
-#endif
-	}
-	break;
-
+	      break;
+	  } else
+	      break;
       }
-      else
-	break;
-    }
-    if (ev)
-    {
-      *ret_ev = *ev;
-      ev->ev_next = eventFreeList;
-      eventFreeList = ev;
-    }
-
-    unlockEvent();
+      if (ev) {
+	  *ret_ev = *ev;
+	  ev->ev_next = eventFreeList;
+	  eventFreeList = ev;
+      }
+
+      unlockEvent();
   }
-    /*if (!ev)
-      SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);*/
+
+#if 0
+  if (!ev)
+      SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);
+#endif
+
   return (ev != 0);
 }
 
@@ -1168,31 +1227,29 @@
     switch (message) {
 	case WM_CREATE:
 	    {
-	      CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
-	      SETLOCALWINDOWINFOPTR(hWnd,lpcs->lpCreateParams);
-	      if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams) {
-		  PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
-	      }
-	      *pDefault = 0;
+		CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
+		SETLOCALWINDOWINFOPTR(hWnd,lpcs->lpCreateParams);
+		if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams) {
+		    PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
+		}
+		*pDefault = 0;
 #ifdef COUNT_RESOURCES
-	      __cnt_createWindows++;
-	      RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
+		__cnt_createWindows++;
+		RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
 #endif
-	      DPRINTF(("WM_CREATE\n"));
+		DPRINTF(("WM_CREATE\n"));
 	    }
 	    break;
 
 	case WM_CLOSE:
 	    DPRINTF(("WM_CLOSE\n"));
 	    if (!destroyWin) {
-	      enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
+		enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
 	    } else {
-	      destroyWin = 0;
-	      if (!DestroyWindow(hWnd))
-	      {
-		DPRINTF(("DestroyWindow ERROR\n"));
-	      }
-
+		destroyWin = 0;
+		if (!DestroyWindow(hWnd)) {
+		    DPRINTF(("DestroyWindow ERROR\n"));
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1205,17 +1262,16 @@
 	      DPRINTF(("WM_DESTROY\n"));
 	      l = (char *)GETLOCALWINDOWINFOPTR(hWnd);
 #ifdef TOPWINDOWCLASS
-	      if (l)
-	      {
-		if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN)
-		{
-		  n = (char*)malloc(200);
-		  GetClassName(hWnd,n,200);
-		}
-	      /* free all resources */
-		/*if (GetWindow_bgBrush(hWnd))
-		  DelObject(GetWindow_bgBrush(hWnd));*/
-		//free(GETLOCALWINDOWINFOPTR(hWnd));
+	      if (l) {
+		  if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) {
+		      n = (char*)malloc(200);
+		      GetClassName(hWnd,n,200);
+		  }
+		  /* free all resources */
+		  /*if (GetWindow_bgBrush(hWnd))
+		   *    DelObject(GetWindow_bgBrush(hWnd));
+		   */
+		  //free(GETLOCALWINDOWINFOPTR(hWnd));
 	      }
 #endif
 	      SETLOCALWINDOWINFOPTR(hWnd,0);
@@ -1278,43 +1334,37 @@
 		    *pDefault = 0;
 		    return 1;
 		}
-
 	    }
 	    return 0;
 
 	case WM_WINDOWPOSCHANGED:
-	    if (currentCapture == CAPTURE_NONE)
-	    {
-	      POINT p;
-	      HWND hWndChild,hWndTemp;
-
-	      p.x = evRootX;
-	      p.y = evRootY;
-	      ScreenToClient(hWnd, &p);
-	      hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-	      do
-	      {
-		hWndTemp = hWndChild;
-		hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
-	      } while ((hWndChild) && (hWndChild != hWndTemp));
-	      if (hWndChild /*&& (hWndChild != hWnd)*/)
-	      {
-		  modifiers = getModifiers();
-		  if (hWndChild != currentPointerView)
-		  {
-		      if (currentPointerView)
-		      {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		      if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
-			enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
-		      //SetFocus(hWndChild);
-		      //printf("WM_WINDOWPOSCHANGED h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);
-		      currentPointerView = hWndChild;
-		  }
-	      }
+	    if (currentCapture == CAPTURE_NONE) {
+		POINT p;
+		HWND hWndChild,hWndTemp;
+
+		p.x = evRootX;
+		p.y = evRootY;
+		ScreenToClient(hWnd, &p);
+		hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
+		do {
+		    hWndTemp = hWndChild;
+		    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
+		} while ((hWndChild) && (hWndChild != hWndTemp));
+		if (hWndChild /*&& (hWndChild != hWnd)*/) {
+		    modifiers = getModifiers();
+		    if (hWndChild != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+				enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+			if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
+			    enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
+			//SetFocus(hWndChild);
+			//printf("WM_WINDOWPOSCHANGED h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);
+			currentPointerView = hWndChild;
+		    }
+		}
 	    }
 
 	    /*
@@ -1355,29 +1405,26 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    if (((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0) && (__rootWinSpezial != hWnd))
-	    {
-	      if (GetUpdateRect(hWnd, &upd, FALSE))
-	      {
-		  if (GetWindow_eventMask(hWnd) & ExposureMask) {
+	    if (((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0) && (__rootWinSpezial != hWnd)) {
+		if (GetUpdateRect(hWnd, &upd, FALSE)) {
+		    if (GetWindow_eventMask(hWnd) & ExposureMask) {
 #ifndef LATE_PAINT
-		    HDC dc = (HDC)GetDC(hWnd);
-		    HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(hWnd),0));
-
-		    if (br) {
-			// printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
-			SelectClipRgn(dc,0);
-			FillRect(dc, &upd, br);
-			DelObject(br);
+			HDC dc = (HDC)GetDC(hWnd);
+			HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(hWnd),0));
+
+			if (br) {
+			    // printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
+			    SelectClipRgn(dc,0);
+			    FillRect(dc, &upd, br);
+			    DelObject(br);
+			}
+			ReleaseDC(hWnd,dc);
+#endif
+			enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
 		    }
-		    ReleaseDC(hWnd,dc);
-#endif
-		    enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
-		  }
-	      }
-	    }
-	    else
-	      pDefault = 0;
+		}
+	    } else
+		pDefault = 0;
 	    return 0;
 	    break;
 
@@ -1415,26 +1462,23 @@
 
 	case WM_MOUSEACTIVATE :
 	    EVENT_PRINTF2(("WM_MOUSEACTIVATE h=%x\n", hWnd));
-	    if (!buttonClickWindowsLike)
-	    {
+	    if (!activateOnClick) {
 		*pDefault = 0;
-		if ((__rootWinSpezial == hWnd) || (GetActiveWindow() && (LOWORD(lParam) == HTCLIENT))
+		if ((__rootWinSpezial == hWnd) || (GetActiveWindow() && (LOWORD(lParam) == HTCLIENT)) 
 		    /*((GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) == 0) */
-		   )
-		   return MA_NOACTIVATE;
-		else
-		{
-		  return MA_ACTIVATE;
+		   ) {
+		     return MA_NOACTIVATE;
+		} else {
+		    return MA_ACTIVATE;
 		}
 	    }
 	    break;
 
 	case WM_NCHITTEST:
 	    EVENT_PRINTF(("WM_NCHITTEST\n"));
-	    if (hWnd == __rootWinSpezial)
-	    {
-	      *pDefault = 0;
-	      return HTCLIENT;
+	    if (hWnd == __rootWinSpezial) {
+		*pDefault = 0;
+		return HTCLIENT;
 	    }
 	    break;
 
@@ -1446,17 +1490,17 @@
 	    CPRINTF(("WM_ACTIVATE %s h=%x\n",
 			    LOWORD(wParam) ? "active" : "inactive",
 			    hWnd));
-	    //if (!buttonClickWindowsLike)
+	    //if (!activateOnClick)
 	    {
 		switch (LOWORD(wParam)) {
 		    case WA_INACTIVE:
 			EVENT_PRINTF2(("WM_ACTIVATE inactive h=%x\n", hWnd));
 			break;
+
 		    case WA_ACTIVE:
 			EVENT_PRINTF2(("WM_ACTIVATE active h=%x\n", hWnd));
 #if 0
-			if (currentCapture == CAPTURE_NONE)
-			{
+			if (currentCapture == CAPTURE_NONE) {
 			  POINT p;
 			  HWND hWndChild,hWndTemp;
 
@@ -1464,22 +1508,16 @@
 			  p.y = evRootY;
 			  ScreenToClient(hWnd, &p);
 			  hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-			  do
-			  {
+			  do {
 			    hWndTemp = hWndChild;
 			    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
 			  } while ((hWndChild) && (hWndChild != hWndTemp));
+
 			  /*printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
-			  if (hWndChild /*&& (hWndChild != hWnd)*/)
-
-
-
-			  {
+			  if (hWndChild /*&& (hWndChild != hWnd)*/) {
 			      modifiers = getModifiers();
-			      if (hWndChild != currentPointerView)
-			      {
-				  if (currentPointerView)
-				  {
+			      if (hWndChild != currentPointerView) {
+				  if (currentPointerView) {
 				      if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
 					enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
 				      currentPointerView = 0;
@@ -1489,17 +1527,15 @@
 				  //SetFocus(hWndChild);
 				  currentPointerView = hWndChild;
 			      }
-
-
-
-
 			  }
 			}
 #endif
 			break;
+
 		    case WA_CLICKACTIVE:
 			EVENT_PRINTF2(("WM_ACTIVATE clkactive h=%x\n", hWnd));
 			break;
+
 		    default:
 			EVENT_PRINTF2(("WM_ACTIVATE ? h=%x\n", hWnd));
 			break;
@@ -1524,30 +1560,32 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    modifiers = getModifiers();
 	    {
-		POINT p;
-
-		p.x = evRootX;
-		p.y = evRootY;
-		ScreenToClient(hWnd, &p);
-		x = p.x;
-		y = p.y;
-	    }
-	    if (currentPointerView) {
-	      int evMask = GetWindow_eventMask(currentPointerView);
-
-	      if (evMask & KeyPressMask)
-		enqEvent(KeyPressMask,currentPointerView, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
-	      if (evMask & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,currentPointerView, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
-	    } else {
-	      int evMask = GetWindow_eventMask(hWnd);
-
-	      if (evMask & KeyPressMask)
-		enqEvent(KeyPressMask,hWnd, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
-	      if (evMask & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,hWnd, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+		HWND destWindow;
+		int evMask;
+
+		destWindow = currentPointerView;
+		if (destWindow == 0) {
+		    destWindow = hWnd;
+		}
+
+		evMask = GetWindow_eventMask(destWindow);
+		if (evMask & (KeyPressMask | KeyReleaseMask)) {
+		    POINT p;
+
+		    modifiers = getModifiers();
+
+		    p.x = evRootX;
+		    p.y = evRootY;
+		    ScreenToClient(destWindow, &p);
+		    x = p.x;
+		    y = p.y;
+
+		    if (evMask & KeyPressMask)
+			enqEvent(KeyPressMask, destWindow, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+		    if (evMask & KeyReleaseMask)
+			enqEvent(KeyReleaseMask, destWindow, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1563,23 +1601,26 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    modifiers = getModifiers();
 	    {
-		POINT p;
-
-		p.x = evRootX;
-		p.y = evRootY;
-		ScreenToClient(hWnd, &p);
-		x = p.x;
-		y = p.y;
-	    }
-
-	    if (currentPointerView) {
-	      if (GetWindow_eventMask(currentPointerView) & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,currentPointerView, message, wParam, x, y, lParam, modifiers);
-	    } else {
-	      if (GetWindow_eventMask(hWnd) & KeyReleaseMask)
-		enqEvent(KeyReleaseMask,hWnd, message, wParam, x, y, lParam, modifiers);
+		HWND destWindow;
+
+		destWindow = currentPointerView;
+		if (destWindow == 0) {
+		    destWindow = hWnd;
+		}
+
+		if (GetWindow_eventMask(destWindow) & KeyReleaseMask) {
+		    POINT p;
+
+		    p.x = evRootX;
+		    p.y = evRootY;
+		    ScreenToClient(destWindow, &p);
+		    x = p.x;
+		    y = p.y;
+
+		    modifiers = getModifiers();
+		    enqEvent(KeyReleaseMask, destWindow, message, wParam, x, y, lParam, modifiers);
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1603,22 +1644,27 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    modifiers = getModifiers();
+
 	    {
-		POINT p;
-
-		p.x = evRootX;
-		p.y = evRootY;
-		ScreenToClient(hWnd, &p);
-		x = p.x;
-		y = p.y;
-	    }
-	    if (currentPointerView) {
-	      if (GetWindow_eventMask(currentPointerView) & KeyPressMask)
-		enqEvent(KeyPressMask,currentPointerView, message, wParam, x, y, lParam, modifiers);
-	    } else {
-	      if (GetWindow_eventMask(hWnd) & KeyPressMask)
-		enqEvent(KeyPressMask,hWnd, message, wParam, x, y, lParam, modifiers);
+		HWND destWindow;
+
+		destWindow = currentPointerView;
+		if (destWindow == 0) {
+		    destWindow = hWnd;
+		}
+
+		if (GetWindow_eventMask(destWindow) & KeyPressMask) {
+		    POINT p;
+
+		    p.x = evRootX;
+		    p.y = evRootY;
+		    ScreenToClient(destWindow, &p);
+		    x = p.x;
+		    y = p.y;
+
+		    modifiers = getModifiers();
+		    enqEvent(KeyPressMask, destWindow, message, wParam, x, y, lParam, modifiers);
+		}
 	    }
 	    *pDefault = 0;
 	    return 0;
@@ -1638,23 +1684,20 @@
 
 		modifiers = getModifiers();
 
-		if (currentCapture == CAPTURE_NONE)
-		{
-		  if (hWnd != currentPointerView) {
-		      if (currentPointerView) {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		      if (GetWindow_eventMask(hWnd) & EnterWindowMask)
-			enqEvent(EnterWindowMask,hWnd, __WM_MOUSEENTER, 0, x, y, 0, modifiers);
-		      currentPointerView = hWnd;
-		  }
-		  CPRINTF(("MouseMove %x\n",currentPointerView));
-		}
-		else
-		{
-		  CPRINTF(("MouseMove Capture %x\n",currentPointerView));
+		if (currentCapture == CAPTURE_NONE) {
+		    if (hWnd != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+				enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+			if (GetWindow_eventMask(hWnd) & EnterWindowMask)
+			    enqEvent(EnterWindowMask,hWnd, __WM_MOUSEENTER, 0, x, y, 0, modifiers);
+			currentPointerView = hWnd;
+		    }
+		    CPRINTF(("MouseMove %x\n",currentPointerView));
+		} else {
+		    CPRINTF(("MouseMove Capture %x\n",currentPointerView));
 		}
 		if (    (GetWindow_eventMask(currentPointerView) & PointerMotionMask)
 		     || (modifiers & (Button1Mask|Button2Mask|Button3Mask))
@@ -1689,8 +1732,9 @@
 
 
 	    if (GetWindow_eventMask(hWnd) & ButtonReleaseMask)
-	      enqEvent(ButtonReleaseMask,hWnd, message, wParam, (int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),
-					      wParam,modifiers);
+		enqEvent(ButtonReleaseMask, hWnd, 
+			 message, wParam, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam),
+			 wParam, modifiers);
 	    *pDefault = 0;
 	    break;
 
@@ -1708,8 +1752,7 @@
 		return 0;
 	    }
 
-	    if (currentCapture == CAPTURE_NONE)
-	    {
+	    if (currentCapture == CAPTURE_NONE) {
 		currentCapture = curButton /*CAPTURE_IMPLICIT*/;
 		//SetFocus(hWnd);
 		SetCapture(hWnd);
@@ -1729,10 +1772,10 @@
 	    EVENT_PRINTF3(("WM_BUTTONDOWN h=%x pos=%d/%d\n",
 			   hWnd, LOWORD(lParam), HIWORD(lParam)));
 
-
 	    if (GetWindow_eventMask(hWnd) & ButtonPressMask)
-	      enqEvent(ButtonPressMask,hWnd, message, wParam, (int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),
-					      wParam,modifiers);
+		enqEvent(ButtonPressMask, hWnd, 
+			 message, wParam, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam),
+			 wParam, modifiers);
 	    *pDefault = 0;
 	    break;
 
@@ -1761,36 +1804,32 @@
 #if 0
 	    //enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
 	    {
-	      POINT p;
-	      HWND hWndChild,hWndTemp;
-
-	      p.x = evRootX;
-	      p.y = evRootY;
-	      ScreenToClient(hWnd, &p);
-	      hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
-	      do
-	      {
-		hWndTemp = hWndChild;
-		hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
-	      } while ((hWndChild) && (hWndChild != hWndTemp));
-	      /*printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
-	      if (hWndChild /*&& (hWndChild != hWnd)*/)
-	      {
-		  modifiers = getModifiers();
-		  if (hWndChild != currentPointerView)
-		  {
-		      if (currentPointerView)
-		      {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		      if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
-			enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
-		      //SetFocus(hWndChild);
-		      currentPointerView = hWndChild;
-		  }
-	      }
+		POINT p;
+		HWND hWndChild,hWndTemp;
+
+		p.x = evRootX;
+		p.y = evRootY;
+		ScreenToClient(hWnd, &p);
+		hWndChild = hWnd; //hWndChild = ChildWindowFromPoint(hWnd,p);
+		do {
+		    hWndTemp = hWndChild;
+		    hWndChild = ChildWindowFromPointEx(hWndTemp,p,CWP_SKIPINVISIBLE|CWP_SKIPDISABLED|CWP_SKIPTRANSPARENT);
+		} while ((hWndChild) && (hWndChild != hWndTemp));
+		/*printf("WM_ACTIVATE active h=%x p=%d.%d in %x\n", hWnd,p.x,p.y,hWndChild);*/
+		if (hWndChild /*&& (hWndChild != hWnd)*/) {
+		    modifiers = getModifiers();
+		    if (hWndChild != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+			      enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+			if (GetWindow_eventMask(hWndChild) & EnterWindowMask)
+			    enqEvent(EnterWindowMask,hWndChild, __WM_MOUSEENTER, 0, evRootX, evRootY, 0, modifiers);
+			//SetFocus(hWndChild);
+			currentPointerView = hWndChild;
+		    }
+		}
 	    }
 
 	    if (isNative) {
@@ -1833,15 +1872,14 @@
 
 		modifiers = getModifiers();
 
-		if (currentCapture == CAPTURE_NONE)
-		{
-		  if (hWnd != currentPointerView) {
-		      if (currentPointerView) {
-			  if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
-			  currentPointerView = 0;
-		      }
-		  }
+		if (currentCapture == CAPTURE_NONE) {
+		    if (hWnd != currentPointerView) {
+			if (currentPointerView) {
+			    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+			      enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, modifiers);
+			    currentPointerView = 0;
+			}
+		    }
 		}
 	    }
 	    *pDefault = 0;
@@ -2061,6 +2099,7 @@
     RECT rect;
     MSG msg;
     localWindowInfo *li;
+
     _dispatchThreadId = GetCurrentThreadId();
     TH_DPRINTF(("TS %d\n", th_calls++));
     PeekMessage(&msg,NULL,0,0,PM_NOREMOVE);   /* must be */
@@ -2074,9 +2113,8 @@
     GetWindowRect(GetDesktopWindow(), &rect);
     /* allocate localMemory for Window */
     li = (localWindowInfo*)malloc(sizeof(localWindowInfo));
-    if (li)
-    {
-      memset(li,0,sizeof(*_thread_local));
+    if (li) {
+	memset(li,0,sizeof(*_thread_local));
     }
 
     __rootWinSpezial = CreateWindowEx( WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT,app_nameroot,app_nameroot,
@@ -2090,159 +2128,151 @@
     SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
     SetEvent(hCreateEvent);
 
-    while (bdispatchThreadState)
-    {
+    while (bdispatchThreadState) {
 	HANDLE dummy;
 	TH_DPRINTF(("TG %d\n", th_calls++));
-	if (currentPointerView && (currentCapture == CAPTURE_NONE))
-	{
-	  while (PeekMessage(&msg,0,0,0,PM_NOREMOVE) == 0)
-	  {
-	    if (MsgWaitForMultipleObjects(0,&dummy,FALSE,200,QS_ALLINPUT) == WAIT_TIMEOUT)
-	    {
-	      POINT point;
-	      if (GetCursorPos(&point))
-	      {
-		HWND hWnd = WindowFromPoint(point);
-		if (hWnd)
-		{
-		  if (GetWindowThreadProcessId(hWnd,0) != GetCurrentThreadId())
-		  {
-		    if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-		      enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
-		    currentPointerView = 0;
-		    break;
-		  }
+
+	if (currentPointerView && (currentCapture == CAPTURE_NONE)) {
+	    while (PeekMessage(&msg,0,0,0,PM_NOREMOVE) == 0) {
+		/*
+		 * wait for an event; timeout after 200 millis
+		 */
+		if (MsgWaitForMultipleObjects(0,&dummy,FALSE,200,QS_ALLINPUT) == WAIT_TIMEOUT) {
+		    /*
+		     * timeout - see where mouse pointer is
+		     * for synthetic leave events.
+		     */
+		    POINT point;
+		    if (GetCursorPos(&point)) {
+			HWND hWnd = WindowFromPoint(point);
+			if (hWnd) {
+			    if (GetWindowThreadProcessId(hWnd,0) != GetCurrentThreadId()) {
+				if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+				    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
+				currentPointerView = 0;
+				break;
+			    }
+			}
+		    }
 		}
-	      }
-	    }
-	  }
-	}
+	    }
+	}
+
 	GetMessage(&msg, NULL, 0, 0);
 	TH_DPRINTF(("TD %d\n", th_calls++));
 	destroyWin = 0;
-	if (msg.message == WM_THREADDESTROYWINDOW)
-	{
-	  destroyWin = TRUE;
-	  msg.message = WM_CLOSE;
-	  CPRINTF(("thread WM_THREADDESTROYWINDOW %x\n",msg.hwnd));
-	}
-	else if (msg.message == WM_THREADSETFOCUS)
-	{
+
+	switch (msg.message) {
+	    case WM_THREADDESTROYWINDOW:
+		destroyWin = TRUE;
+		msg.message = WM_CLOSE;
+		CPRINTF(("thread WM_THREADDESTROYWINDOW %x\n",msg.hwnd));
+		break;
+
+	    case WM_THREADSETFOCUS:
 #ifdef xxWIN32THREADS
-	  if (msg.lParam)
-	  {
-	    if (AttachThreadInput(_dispatchThreadId,msg.lParam,TRUE) == FALSE)
-	      PRINTF(("SetFocus AttachThreadInput error %d\n",GetLastError()));
-	  }
+		if (msg.lParam) {
+		    if (AttachThreadInput(_dispatchThreadId,msg.lParam,TRUE) == FALSE)
+			PRINTF(("SetFocus AttachThreadInput error %d\n",GetLastError()));
+		}
 #endif
-	  CPRINTF(("threadSetfocus %x\n",msg.wParam));
-	  //SetForegroundWindow((HWND)msg.wParam);
-	  //SetWindowPos((HWND)msg.wParam, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER  |SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
-	  SetFocus((HWND)msg.wParam);
-	  continue;
-	}
-	else if (msg.message == WM_THREADSETCURSOR)
-	{
-	  if (msg.lParam)
-	  {
-	    POINT p;
-
-	    GetCursorPos(&p);
-	    if (WindowFromPoint(p) == msg.hwnd)
-	    {
-	      CPRINTF(("threadSetCursor %x\n",msg.lParam));
-	      SetCursor((HCURSOR)msg.lParam);
-	    }
-	  }
-	  continue;
-	}
-	else if (msg.message == WM_THREADSETCAPTURE)
-	{
-	  if (msg.wParam)
-	  {
-	    if (currentPointerView)
-	    {
-		if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
-		  enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
-	    }
-	    currentPointerView = msg.wParam;
-	    currentCapture = CAPTURE_EXPLICIT;
-	    CPRINTF(("threadSetCapture %x\n",msg.wParam));
-	    SetCapture(currentPointerView);
-	  }
-	  else
-	  {
-	    if (currentPointerView  == __rootWinSpezial)
-	    {
-	      //ShowWindow(__rootWinSpezial, SW_HIDE);
-	      SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0,SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOCOPYBITS
-			     |SWP_HIDEWINDOW| SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE/*| SWP_NOZORDER|SWP_NOOWNERZORDER*/);
-	    }
-	    currentPointerView = 0;
-	    currentCapture = CAPTURE_NONE;
-	    CPRINTF(("threadReleaseCapture\n"));
-	    ReleaseCapture();
-	  }
-	  if (msg.lParam)
-	  {
-	      CPRINTF(("threadSetCursor %x\n",msg.lParam));
-	      SetCursor((HCURSOR)msg.lParam);
-	  }
-	  continue;
-	}
-	else if (msg.message == WM_THREADCREATEWINDOW)
-	{
-	  TH_DPRINTF(("C %d\n", th_calls));
-	  if (_thread_winStyleBits & WS_POPUP)
-	  {
-	    //_thread_parentHandle = GetActiveWindow();
-	  }
-	  _thread_newWinHandle = CreateWindowEx(
-				      _thread_winStyleBitsEx,
-				      _thread_className,
-				      _thread_windowName,
-				      _thread_winStyleBits,
-				      _thread_x, _thread_y,
-				      _thread_dx,_thread_dy,
-				      _thread_parentHandle,
-				      NULL,           /* menu */
-				      (HANDLE) __getHInstance(),
-				      _thread_local);
-	  SetEvent(hCreateEvent);
-	  continue;
-	}
-	/* TranslateMessage(&msg); */ /* Translates virtual key codes */
-	if (   (msg.message == WM_KEYDOWN)
-	    || (msg.message == WM_KEYUP)
-	    || (msg.message == WM_SYSKEYDOWN)
-	    || (msg.message == WM_SYSKEYUP)
-	   )
-	{
+		CPRINTF(("threadSetfocus %x\n",msg.wParam));
+		//SetForegroundWindow((HWND)msg.wParam);
+		//SetWindowPos((HWND)msg.wParam, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER  |SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
+		SetFocus((HWND)msg.wParam);
+		continue;
+
+	    case WM_THREADSETCURSOR:
+		if (msg.lParam) {
+		    POINT p;
+
+		    GetCursorPos(&p);
+		    if (WindowFromPoint(p) == msg.hwnd) {
+			CPRINTF(("threadSetCursor %x\n",msg.lParam));
+			SetCursor((HCURSOR)msg.lParam);
+		    }
+		}
+		continue;
+
+	    case WM_THREADSETCAPTURE:
+		if (msg.wParam) {
+		    if (currentPointerView) {
+			if (GetWindow_eventMask(currentPointerView) & LeaveWindowMask)
+			    enqEvent(LeaveWindowMask,currentPointerView, __WM_MOUSELEAVE, 0, -1, -1, 0, getModifiers());
+		    }
+		    currentPointerView = msg.wParam;
+		    currentCapture = CAPTURE_EXPLICIT;
+		    CPRINTF(("threadSetCapture %x\n",msg.wParam));
+		    SetCapture(currentPointerView);
+		} else {
+		    if (currentPointerView  == __rootWinSpezial) {
+			//ShowWindow(__rootWinSpezial, SW_HIDE);
+			SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0,SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOCOPYBITS
+				       |SWP_HIDEWINDOW| SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE/*| SWP_NOZORDER|SWP_NOOWNERZORDER*/);
+		    }
+		    currentPointerView = 0;
+		    currentCapture = CAPTURE_NONE;
+		    CPRINTF(("threadReleaseCapture\n"));
+		    ReleaseCapture();
+		}
+		if (msg.lParam) {
+		    CPRINTF(("threadSetCursor %x\n",msg.lParam));
+		    SetCursor((HCURSOR)msg.lParam);
+		}
+		continue;
+
+	    case WM_THREADCREATEWINDOW:
+		TH_DPRINTF(("C %d\n", th_calls));
+		if (_thread_winStyleBits & WS_POPUP) {
+		    //_thread_parentHandle = GetActiveWindow();
+		}
+		_thread_newWinHandle = CreateWindowEx(
+					    _thread_winStyleBitsEx,
+					    _thread_className,
+					    _thread_windowName,
+					    _thread_winStyleBits,
+					    _thread_x, _thread_y,
+					    _thread_dx,_thread_dy,
+					    _thread_parentHandle,
+					    NULL,           /* menu */
+					    (HANDLE) __getHInstance(),
+					    _thread_local);
+		SetEvent(hCreateEvent);
+		continue;
+
+	    case WM_KEYDOWN:
+	    case WM_KEYUP:
+	    case WM_SYSKEYDOWN:
+	    case WM_SYSKEYUP:
 #ifdef xxDEBUG
-	   if ((msg.wParam == 0x11) && (msg.message == WM_KEYDOWN))/* CTRL-C */
-	   {
-	     if (c_count++ > 3)  /* for debugging */
-		exit(1);
-	   }
+		if ((msg.wParam == 0x11) && (msg.message == WM_KEYDOWN)) {
+		    /* CTRL-C */
+		    if (c_count++ > 3)  /* for debugging */
+		       exit(1);
+		}
 #endif
-	    DPRINTF(("keymsg %x\n",msg.wParam));
-	    if (
-		   ((msg.wParam >= '0') && (msg.wParam <= 'Z'))
-		|| ((msg.wParam >= VK_MULTIPLY) && (msg.wParam <= VK_DIVIDE))
-		|| (msg.wParam == 0x20)
-		|| (msg.wParam == 0x14)
-		/*|| (msg.wParam == 0x10)*/
-		|| (msg.wParam >= 0xB0)
-	       )
-	    {
-		/*
-		 * translate to a WM_CHAR message
-		 */
-		if (TranslateMessage(&msg))
-		    continue;
-	    }
-	}
+		DPRINTF(("keymsg %x\n",msg.wParam));
+		if (
+		       ((msg.wParam >= '0') && (msg.wParam <= 'Z'))
+		    || ((msg.wParam >= VK_MULTIPLY) && (msg.wParam <= VK_DIVIDE))
+		    || (msg.wParam == 0x20)
+		    || (msg.wParam == 0x14)
+		    /*|| (msg.wParam == 0x10)*/
+		    || (msg.wParam >= 0xB0)
+		   )
+		{
+		    /*
+		     * translate to a WM_CHAR message
+		     */
+		    if (TranslateMessage(&msg))
+			continue;
+		}
+		break;
+	}
+
+	/*
+	 * common ...
+	 */
 	evRootX = msg.pt.x;
 	evRootY = msg.pt.y;
 	lastMSGTime = msg.time;
@@ -2325,11 +2355,11 @@
 	    __UNPROTECT__(*refToList);
 
 	    if ( dwType & TRUETYPE_FONTTYPE )
-	      __ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(0);
-	    else
-	      //__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(MulDiv(__logPixelSY,lplf->lfHeight, 72));
-	      __ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(lplf->lfHeight);
-
+		__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(0);
+	    else {
+		//__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(MulDiv(__logPixelSY,lplf->lfHeight, 72));
+		__ArrayInstPtr(newArray)->a_element[0] = __MKSMALLINT(lplf->lfHeight);
+	    }
 	    __ArrayInstPtr(newArray)->a_element[1] = __MKSMALLINT(lplf->lfWidth);
 	    __ArrayInstPtr(newArray)->a_element[2] = __MKSMALLINT(lplf->lfEscapement);
 	    __ArrayInstPtr(newArray)->a_element[3] = __MKSMALLINT(lplf->lfOrientation);
@@ -2497,7 +2527,8 @@
     See more documentation in my superclass, DeviceWorkstation.
 
     [author:]
-	Claus Gittinger
+	Claus Gittinger (initial port)
+	Manfred Dierolf (many, many changes & fixes, multithreading etc.)
 "
 ! !
 
@@ -2548,7 +2579,7 @@
 initializeStandardColorNames
     "{ Pragma: +optSpace }"
 
-    "setup standard color names"
+    "setup standard color names (X-color names)"
 
     StandardColorValues := Dictionary new.
     #(
@@ -3462,8 +3493,6 @@
     "
      WinWorkstation initializeStandardColorNames
     "
-
-
 !
 
 nativeWindows:aBoolean
@@ -4223,22 +4252,22 @@
 	struct gcData *gcData = _GCDATA(aGCId);
 
 #ifdef COUNT_RESOURCES
-	__cnt_gcData--;
-       RESPRINTF(("DestroyGcData %d\n",__cnt_gcData));
+	 __cnt_gcData--;
+	RESPRINTF(("DestroyGcData %d\n",__cnt_gcData));
 #endif
-       if (gcData->hBitmap) 
-       {
 #ifdef COUNT_BMP_RESOURCES
+	if (gcData->hBitmap) {
 	    __cnt_bmpdc--;
 	    RES_BMP_PRINTF(("free BmpDC %d\n",__cnt_bmpdc));
+	}
 #endif
-       }
-       if (lastGcData == gcData)
-       {
-	 _releaseDC(lastGcData);
-	 lastGcData = 0;
-       }
-       free(gcData);
+
+#ifdef CACHE_LAST_DC
+	if (lastGcData == gcData) {
+	    _releaseDC(lastGcData);
+	}
+#endif
+	free(gcData);
     }
 %}
 !
@@ -4249,14 +4278,12 @@
     if (__isExternalAddress(aDrawableId) && ISCONNECTED) {
 	HANDLE bitmapHandle = _HANDLEVal(aDrawableId);
 
-	if (bitmapHandle)
-	{
+	if (bitmapHandle) {
 #ifdef COUNT_BMP_RESOURCES
 	    __cnt_bitmap--;
 	    RES_BMP_PRINTF(("DestroyPixmap %x %d\n",bitmapHandle,__cnt_bitmap));
 #endif
-	    if( DelObject(bitmapHandle) )
-	    {
+	    if( DelObject(bitmapHandle) ) {
 		DPRINTF(("Bitmap deleted!\n"));
 	    }
 	}
@@ -4311,12 +4338,9 @@
 	__cnt_bmpdc++;
 	RES_BMP_PRINTF(("CreateBmpDC %d\n",__cnt_bmpdc));
 #endif
-	if (GetObject(hBitmap,sizeof(bitmap),&bitmap))
-	{
+	if (GetObject(hBitmap,sizeof(bitmap),&bitmap)) {
 	    DPRINTF(("bitmap info:%d\n",bitmap.bmBitsPixel));
-	}
-	else
-	{
+	} else {
 	    DPRINTF(("noinfo returned\n"));
 	}
 	gcData->hBitmap = hBitmap;
@@ -4359,73 +4383,57 @@
 	padding = bytesPerRowWN - bytesPerRowST;
 	nBytes = b_height * bytesPerRowWN;
 
-	if (nBytes < sizeof(fastBits))
-	{
+	if (nBytes < sizeof(fastBits)) {
 	    cp = b_bits = fastBits;
-	}
-	else
-	{
+	} else {
 	    cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
 	}
-	if (cp)
-	{
-	  if (__qClass(anArray) == @global(Array))
-	  {
-	      index = 1;
-	      op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
-	      for (row = b_height; row; row--)
-	      {
-		  for (col = bytesPerRowST; col; col--)
-		  {
-		      num = *op++;
-		      if (! __isSmallInteger(num))
-			goto fail;
-		      *cp++ = __intVal(num);
-		  }
-		  cp += padding;
-	      }
-	  }
-	  else if (__qClass(anArray) == @global(ByteArray))
-	  {
-	      pBits = __ByteArrayInstPtr(anArray)->ba_element;
-	      for (row = b_height; row; row--)
-	      {
-		  for (col = bytesPerRowST; col; col--)
-		  {
-		      *cp++ = ( *pBits++ /*^ 0xFF*/ );
-		  }
-		  cp += padding;
-	      }
-	  }
-	  else
-	  {
-	      goto fail;
-	  }
-	  DPRINTF(("create bitmap ...\n"));
-
-	  newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
-
-	  if( newBitmapHandle )
-	  {
+	if (cp) {
+	    if (__qClass(anArray) == @global(Array)) {
+		index = 1;
+		op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
+		for (row = b_height; row; row--) {
+		    for (col = bytesPerRowST; col; col--) {
+			num = *op++;
+			if (! __isSmallInteger(num))
+			    goto fail;
+			*cp++ = __intVal(num);
+		    }
+		    cp += padding;
+		}
+	    } else if (__qClass(anArray) == @global(ByteArray)) {
+		pBits = __ByteArrayInstPtr(anArray)->ba_element;
+		for (row = b_height; row; row--) {
+		    for (col = bytesPerRowST; col; col--) {
+			*cp++ = ( *pBits++ /*^ 0xFF*/ );
+		    }
+		    cp += padding;
+		}
+	    } else {
+		goto fail;
+	    }
+	    DPRINTF(("create bitmap ...\n"));
+
+	    newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
+
+	    if( newBitmapHandle ) {
 #ifdef COUNT_BMP_RESOURCES
-	    __cnt_bitmap++;
-	    RES_BMP_PRINTF(("CreateBitmap %x %d\n",newBitmapHandle,__cnt_bitmap));
+		__cnt_bitmap++;
+		RES_BMP_PRINTF(("CreateBitmap %x %d\n",newBitmapHandle,__cnt_bitmap));
 #endif
-	    DPRINTF(("returning bitmap ...\n"));
-	    if (allocatedBits)
-	    {
-	      free(allocatedBits);
-	    }
-	    RETURN ( __MKOBJ(newBitmapHandle));
-	  }
-      }
+		DPRINTF(("returning bitmap ...\n"));
+		if (allocatedBits) {
+		    free(allocatedBits);
+		}
+		RETURN ( __MKOBJ(newBitmapHandle));
+	    }
+	}
     }
 fail: ;
     PRINTF(("create bitmap FAILED!!!\n"));
-    if (allocatedBits)
-    {
-      PRINTF(("freeing up bitmap bits ...\n"));
-      free(allocatedBits);
+    if (allocatedBits) {
+	PRINTF(("freeing up bitmap bits ...\n"));
+	free(allocatedBits);
     }
     DPRINTF(("returning nil ...\n"));
     RETURN ( nil );
@@ -5036,9 +5044,12 @@
 !
 
 setColor:index scaledRed:sred scaledGreen:sgreen scaledBlue:sblue
-
- 'setColor:index scaledRed:sred scaledGreen:sgreen scaledBlue:sblue' printCR.
-^ self.
+    "change a palette index.
+     This is not yet supported in the Windows Device 
+     - we assume and depend upon transparent 24bit trueColor mode."
+
+     'WinWorkstation [info]: #setColor:scaledRed:scaledGreen:scaledBlue: ignored' infoPrintCR.
+     ^ self.
 
     "Created: 30.1.1998 / 09:27:48 / md"
     "Modified: 30.1.1998 / 09:30:22 / md"
@@ -5064,6 +5075,7 @@
 	#crossHair              "/ IDC_CROSS
 	#fourWay                "/ IDC_SIZEALL
 	#upRightHand            "/ IDC_ARROW
+	#noDrop                 "/ IDC_NO
        )
 !
 
@@ -5125,6 +5137,7 @@
 	mask := maskPadded.
 
     ].
+
     src invert.
     1 to:src size do:[:index |
 	src byteAt:index put:((src byteAt:index) bitAnd:(mask byteAt:index)).
@@ -5135,8 +5148,8 @@
 	maskBits:mask
 	hotX:hx hotY:hy
 	width:cW height:cH.
-    cursor notNil ifTrue:[  ^ cursor ].
-    self halt.
+    cursor notNil ifTrue:[^ cursor ].
+    'WinWorkstation [warning]: could not create bitmap cursor' infoPrintCR.
 !
 
 cursorBitmapPadding
@@ -5291,6 +5304,9 @@
     if (shape == @symbol(execute)) {
 	RETURN ( __MKSMALLINT( (INT)IDC_APPSTARTING));
     }
+    if (shape == @symbol(noDrop)) {
+	RETURN ( __MKSMALLINT( (INT)IDC_NO));
+    }
 
     if (shape == @symbol(IDC_UPARROW)) {
 	RETURN ( __MKSMALLINT( (INT)IDC_UPARROW));
@@ -5334,86 +5350,79 @@
     HDC srcDC = (HDC)0;
     HDC dstDC = (HDC)0;
 
-    if (__isExternalAddress(srcGCId))
-    {
+    if (__isExternalAddress(srcGCId)) {
 	srcGcData = _GCDATA(srcGCId);
-    }
-    else
-    {
+    } else {
 	goto fail;
     }
     if (__isExternalAddress(dstGCId)) {
 	dstGcData = _GCDATA(dstGCId);
-    }
-    else
-    {
+    } else {
 	goto fail;
     }
 
     if (__bothSmallInteger(w, h)
      && __bothSmallInteger(srcX, srcY)
-     && __bothSmallInteger(dstX, dstY))
-    {
+     && __bothSmallInteger(dstX, dstY)) {
 	int fun = BITBLT_COPY;
-	if (srcGcData && dstGcData)
-	{
-	  fun = dstGcData->bitbltrop2;
+
+	if (srcGcData && dstGcData) {
+	    fun = dstGcData->bitbltrop2;
 #if 0
-	  switch (fun)
-	  {
-	    case BITBLT_COPY:
-	      printf("BITBLT_COPY\n");
-	      break;
-	    case BITBLT_COPYINVERTED:
-	      printf("BITBLT_COPYINVERTED\n");
-	      break;
-	    case BITBLT_XOR:
-	      printf("BITBLT_XOR\n");
-	      break;
-	    case BITBLT_AND:
-	      printf("BITBLT_AND\n");
-	      break;
-	    case BITBLT_OR:
-	      printf("BITBLT_OR\n");
-	      break;
-	  }
+	    switch (fun) {
+	      case BITBLT_COPY:
+		printf("BITBLT_COPY\n");
+		break;
+	      case BITBLT_COPYINVERTED:
+		printf("BITBLT_COPYINVERTED\n");
+		break;
+	      case BITBLT_XOR:
+		printf("BITBLT_XOR\n");
+		break;
+	      case BITBLT_AND:
+		printf("BITBLT_AND\n");
+		break;
+	      case BITBLT_OR:
+		printf("BITBLT_OR\n");
+		break;
+	    }
 #endif
-	  if (srcGcData->hWnd && ((srcGcData->hWnd == dstGcData->hWnd) && (fun == BITBLT_COPY)))
-	  {
-	    RECT rec,uprec;
-	    rec.left = __intVal(srcX);
-	    rec.top = __intVal(srcY);
-	    rec.right = rec.left + __intVal(w);
-	    rec.bottom = rec.top + __intVal(h);
-	    DPRINTF(("dst and src is HWND %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
-	    ScrollWindow(srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0);
-	    UpdateWindow(srcGcData->hWnd);
-	    if (GetWindow_eventMask(srcGcData->hWnd) & ExposureMask)
-	      enqEvent(ExposureMask,srcGcData->hWnd, __WM_NOGEXPOSE, 0, 0, 0, 0, 0);
-	    RETURN ( self );
-
-	  }
-	  if (srcGcData->hWnd)
-	  {
-	      /*printf("src is HWND %x\n",srcGcData->hWnd);*/
-	  }
-	  fun = dstGcData->bitbltrop2;
-	  if ((srcGcData == dstGcData) && (fun == BITBLT_COPY))
-	  {
-	    RECT rec,uprec;
-	    rec.left = __intVal(srcX);
-	    rec.top = __intVal(srcY);
-	    rec.right = rec.left + __intVal(w);
-	    rec.bottom = rec.top + __intVal(h);
-	    srcDC = _getDC(srcGcData);
-	    DPRINTF(("dst and src is DC %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
-	    ScrollDC(srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0,0,&uprec);
-	    _releaseDC(srcGcData);
-	    RETURN ( self );
-
-	  }
-	  else
-	  {
+	    if (srcGcData->hWnd 
+	     && ((srcGcData->hWnd == dstGcData->hWnd)
+	     && (fun == BITBLT_COPY))) {
+		RECT rec,uprec;
+
+		rec.left = __intVal(srcX);
+		rec.top = __intVal(srcY);
+		rec.right = rec.left + __intVal(w);
+		rec.bottom = rec.top + __intVal(h);
+		DPRINTF(("dst and src is HWND %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
+		ScrollWindow(srcGcData->hWnd,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0);
+		UpdateWindow(srcGcData->hWnd);
+		if (GetWindow_eventMask(srcGcData->hWnd) & ExposureMask)
+		    enqEvent(ExposureMask,srcGcData->hWnd, __WM_NOGEXPOSE, 0, 0, 0, 0, 0);
+		RETURN ( self );
+	    }
+
+	    if (srcGcData->hWnd) {
+		/*printf("src is HWND %x\n",srcGcData->hWnd);*/
+	    }
+	    fun = dstGcData->bitbltrop2;
+	    if ((srcGcData == dstGcData)
+	     && (fun == BITBLT_COPY)) {
+		RECT rec,uprec;
+
+		rec.left = __intVal(srcX);
+		rec.top = __intVal(srcY);
+		rec.right = rec.left + __intVal(w);
+		rec.bottom = rec.top + __intVal(h);
+		srcDC = _getDC(srcGcData);
+		DPRINTF(("dst and src is DC %x fun == BITBLT_COPY  --> scrolling %d %d\n",srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY)));
+		ScrollDC(srcDC,__intVal(dstX) - __intVal(srcX),__intVal(dstY) - __intVal(srcY),&rec,0,0,&uprec);
+		_releaseDC(srcGcData);
+		RETURN ( self );
+	    }
+
 	    srcDC = _getDC(srcGcData);
 	    dstDC = _getDC(dstGcData);
 	    DDPRINTF(("bitblt src f:%x b:%x",GetTextColor(srcDC),GetBkColor(srcDC)));
@@ -5425,22 +5434,20 @@
 		 __intVal(srcX), __intVal(srcY),
 		 fun)
 	       == 0
-	      )
-	      {
-		 __win32_fprintf(stderr, "WinWorkstation: ERROR in BitBlt\n");
-	      }
-	  }
-	  _releaseDC(dstGcData);
-	  _releaseDC(srcGcData);
-	  RETURN ( self );
+	      ) {
+		fprintf(stderr, "WinWorkstation [info]: ERROR in BitBlt\n");
+	    }
+
+	    _releaseDC(dstGcData);
+	    _releaseDC(srcGcData);
+	    RETURN ( self );
 	}
     }
 
  fail: ;
 %}.
- self primitiveFailed.
- ^ nil
-
+    self primitiveFailed.
+    ^ nil
 !
 
 copyPlaneFromId:sourceId x:srcX y:srcY gc:srcDCId to:destId x:dstX y:dstY gc:dstDCId
@@ -5500,22 +5507,20 @@
 
 	hDC = _getDC(gcData);
 
-	if (!(hPen = GcDataGetPen(hDC,gcData))) {
+	if (!(hPen = GcDataGetPen(hDC, gcData))) {
 	    DPRINTF(("displayArc: no pen\n"));
 	}
 	else
 	{
 	    double xB, yB, xE, yE, xR, yR;
 	    HPEN hSavePen = SelectObject(hDC, hPen);
+
 	    xR = w / 2;
 	    yR = h / 2;
-	    if (angle2 - angle1 >= 360)
-	    {
+	    if (angle2 - angle1 >= 360) {
 		xB = xE = __x + xR + 0.5;
 		yB = yE = __y /*+ yR + 0.5*/;
-	    }
-	    else
-	    {
+	    } else {
 		double sin(), cos();
 		if (angle1 <= 180)
 		  angle1 = 180 - angle1;
@@ -5540,7 +5545,7 @@
 		(int)xE, (int)yE);
 
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
+	    DelObject(hPen); gcData->hPen = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -5562,6 +5567,7 @@
 	int __x1 = __intVal(x1), __y1 = __intVal(y1);
 	HPEN hPen;
 	HDC hDC = _getDC(gcData);
+
 /*      DPRINTF(("displayLine: %d/%d -> %d/%d in %x\n",
 		    __intVal(x0), __intVal(y0),
 		    __x1, __y1,_HWNDVal(aDrawableId)));
@@ -5578,9 +5584,13 @@
 	     */
 	    LineTo(hDC, __x1+1, __y1);
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
-	}
+#ifndef CACHE_LAST_PEN
+	    DelObject(hPen); gcData->hPen = 0;
+#endif
+	}
+#ifndef CACHE_LAST_DC
 	_releaseDC(gcData);
+#endif
 	RETURN ( self );
     }
 %}
@@ -5598,8 +5608,20 @@
 	POINT p;
 	HPEN hPen;
 	int __x = __intVal(px), __y = __intVal(py);
+	int savedLStyle = gcData->lStyle;
+	int savedLWidth = gcData->lineWidth;
+
+	/*
+	 * a point is a point - no matter what lineWidth we have set before
+	 */
+	gcData->lStyle = PS_SOLID;
+	gcData->lineWidth = 0;
+
 	hDC = _getDC(gcData);
 
+	gcData->lStyle = savedLStyle;
+	gcData->lineWidth = savedLWidth;
+
 	if (!(hPen = GcDataGetPen(hDC,gcData))) {
 	    DPRINTF(("displayPoint: no pen\n"));
 	} else {
@@ -5610,7 +5632,7 @@
 	     */
 	    LineTo(hDC, __x+1, __y);
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
+	    DelObject(hPen); gcData->hPen = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -5623,12 +5645,11 @@
      which define the polygon.
      If any coordinate is not integer, an error is triggered."
 
-    |numberOfPoints |
-
-    numberOfPoints := aPolygon size.
     self
-	primDisplayPolygon:aPolygon n:numberOfPoints
-	in:aDrawableId with:aGCId
+	primDisplayPolygon:aPolygon 
+	n:(aPolygon size)
+	in:aDrawableId 
+	with:aGCId
 !
 
 displayRectangleX:x y:y width:width height:height in:aDrawableId with:aGCId
@@ -5653,20 +5674,21 @@
 	DPRINTF(("displayRectangle: %d/%d -> %d/%d\n",
 			xL, yT, w, h));
 	/*
-	 * need this check here: some servers simply dump core with bad args
+	 * need this check here: some X-servers simply dump core with bad args
 	 */
 	if ((w >= 0) && (h >= 0)) {
 	    if (!(hPen = GcDataGetPen(hDC,gcData))) {
 		DPRINTF(("displayRect: no pen\n"));
 	    } else {
 		HPEN hSavePen = SelectObject(hDC, hPen);
+
 		MoveToEx(hDC, xL, yT, NULL);
 		LineTo(hDC, xL+w-1, yT);
 		LineTo(hDC, xL+w-1, yT+h-1);
 		LineTo(hDC, xL, yT+h-1);
 		LineTo(hDC, xL, yT);
 		SelectObject(hDC,hSavePen);
-		DelObject(hPen);
+		DelObject(hPen); gcData->hPen = 0;
 	    }
 	}
 	_releaseDC(gcData);
@@ -5900,7 +5922,7 @@
 	} else {
 	  HBRUSH hSaveBrush = SelectObject(hDC, hBrush);
 	  HPEN hPen = 0;
-	  HPEN hSavePen;
+	  HPEN hSavePen = 0;
 
 	  if (__isWinNT) {
 	      if (!(hPen = GcDataGetPen(hDC,gcData))) {
@@ -5950,12 +5972,12 @@
 
 	      if (hPen) {
 		  SelectObject(hDC,hSavePen);
-		  DelObject(hPen);
+		  DelObject(hPen); gcData->hPen = 0;
 	      }
 	  }
 failpen:
 	  SelectObject(hDC,hSaveBrush);
-	  DelObject(hBrush);
+	  DelObject(hBrush); gcData->hBrush = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -6004,13 +6026,11 @@
 
 	    hDC = _getDC(gcData);
 	    hBrush = GcDataGetBrush(hDC,gcData);
-	    if (! hBrush)
-	    {
+	    if (! hBrush) {
 		PRINTF(("fillRectangle: no brush\n"));
-	    }
-	    else
-	    {
+	    } else {
 	      HBRUSH hSaveBrush = SelectObject(hDC, hBrush);
+
 	      rct.left = __intVal(x);
 	      rct.top = __intVal(y);
 	      rct.right = rct.left + w + 1;
@@ -6020,7 +6040,7 @@
 	      SelectObject(hDC, GetStockObject(NULL_PEN));
 	      Rectangle(hDC,rct.left,rct.top,rct.right,rct.bottom);
 	      SelectObject(hDC,hSaveBrush);
-	      DelObject(hBrush);
+	      DelObject(hBrush); gcData->hBrush = 0;
 	    }
 	    _releaseDC(gcData);
 	}
@@ -6039,7 +6059,7 @@
      && __isExternalAddress(aDrawableId)
      && __isSmallInteger(numberOfPoints)) {
 	struct gcData *gcData = _GCDATA(aGCId);
-	HDC hDC = _getDC(gcData);
+	HDC hDC = 0;
 	POINT p;
 	HPEN hPen;
 
@@ -6050,16 +6070,17 @@
 	    if (! __isPoint(point)) goto fail;
 	    px = _point_X(point);
 	    py = _point_Y(point);
-	    if (! __bothSmallInteger(px, py))
-	    {
-		_releaseDC(gcData);
+	    if (! __bothSmallInteger(px, py)) {
 		goto fail;
 	    }
 	}
+
+	hDC = _getDC(gcData);
 	if (!(hPen = GcDataGetPen(hDC,gcData))) {
 	    DPRINTF(("displayPolygon: no pen\n"));
 	} else {
 	    HPEN hSavePen = SelectObject(hDC, hPen);
+
 	    for (i=0; i<num; i++) {
 		point = __AT_(aPolygon, __MKSMALLINT(i+1));
 		px = _point_X(point);
@@ -6081,7 +6102,7 @@
 		}
 	    }
 	    SelectObject(hDC,hSavePen);
-	    DelObject(hPen);
+	    DelObject(hPen); gcData->hPen = 0;
 	}
 
 	_releaseDC(gcData);
@@ -6231,8 +6252,9 @@
       PRINTF(("freeing up temp bitmap bits ...\n"));
       free(allocatedBits);
     }
-    if (gcData && hDC)
+    if (gcData && hDC) {
 	_releaseDC(gcData);
+    }
 %}
 .
     ^ false
@@ -6293,7 +6315,7 @@
 	    EndPath(hDC);
 	    FillPath(hDC);
 	    SelectObject(hDC,hSaveBrush);
-	    DelObject(hBrush);
+	    DelObject(hBrush); gcData->hBrush = 0;
 	}
 	_releaseDC(gcData);
 	RETURN ( self );
@@ -6321,9 +6343,10 @@
     "system is about to be shut down.
      This is a speciality of windows.
      TODO: Tell all views to close themself.
-     For now,this is ignored."
-
-    'WinWorkstation [info]: queryEndSession ignored for now.' infoPrintCR
+     For now, this is ignored."
+
+    'WinWorkstation [info]: queryEndSession ignored for now.' infoPrintCR.
+    ^ true
 !
 
 systemColorChange:aWindow
@@ -6350,12 +6373,10 @@
 
 !WinWorkstation methodsFor:'event handling'!
 
-configEventProcessedFor:aWindowId
+XXconfigEventProcessedFor:aWindowId
 %{
-    if (__isExternalAddress(aWindowId))
-    {
-      HWND hWnd = _HWNDVal(aWindowId);
-
+    if (__isExternalAddress(aWindowId)) {
+	HWND hWnd = _HWNDVal(aWindowId);
     }
 %}
 !
@@ -6442,13 +6463,12 @@
     if (__isByteArray(eB)) {
 	ev = (struct queuedEvent *)(__ByteArrayInstPtr(eB)->ba_element);
     } else {
-	__win32_fprintf(stderr, "WinWorkstation: no eventBuffer\n");
+	fprintf(stderr, "WinWorkstation [error]: no eventBuffer\n");
 	RETURN (false);
     }
-    if (ev)
-    {
-      _ev_buf = *ev;
-      ev = &_ev_buf;
+    if (ev) {
+	_ev_buf = *ev;
+	ev = &_ev_buf;
     }
     hWnd = ev->ev_hWnd;
     if (!(hWnd /*&& IsWindow(hWnd)*/)) {
@@ -6520,15 +6540,16 @@
 		  char buf[MAXPATH];
 		  HDROP hDrop = (HDROP)ev->ev_wParam;
 		  int count = DragQueryFile(hDrop,0xffffffff,0,0);
+
 		  PRINTF((">>> WM_DROPFILES %d Files\n",count));
-		  for (i = 0;i < count;i++)
-		  {
-		    DragQueryFile(hDrop,i,buf,sizeof(buf));
-		    PRINTF(("Filename:%s\n",buf));
+		  for (i = 0;i < count;i++) {
+		      DragQueryFile(hDrop,i,buf,sizeof(buf));
+		      PRINTF(("Filename:%s\n",buf));
 		  }
 		  DragFinish(hDrop);
 		}
 		break;
+
 	    case WM_SHOWWINDOW:
 		if (ev->ev_wParam == TRUE) {
 		    DPRINTF((">>> WM_SHOWWINDOW -> mappedView:\n"));
@@ -6638,21 +6659,20 @@
 	    case WM_PAINT:
 #ifdef LATE_PAINT
 		{
-		  RECT rec;
-		  HDC dc = (HDC)GetDC(ev->ev_hWnd);
-		  HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(ev->ev_hWnd),0));
-		  if (br)
-		  {
-		    rec.left = ev->ev_x;
-		    rec.top = ev->ev_y;
-		    rec.right = ev->ev_w;
-		    rec.bottom = ev->ev_h;
-		    // printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
-		    SelectClipRgn(dc,0);
-		    FillRect(dc, &rec, br);
-		    DelObject(br);
-		  }
-		  ReleaseDC(ev->ev_hWnd,dc);
+		    RECT rec;
+		    HDC dc = (HDC)GetDC(ev->ev_hWnd);
+		    HBRUSH br = CreateSolidBrush(st2RGB(GetWindow_bgBrush(ev->ev_hWnd),0));
+		    if (br) {
+			rec.left = ev->ev_x;
+			rec.top = ev->ev_y;
+			rec.right = ev->ev_w;
+			rec.bottom = ev->ev_h;
+			// printf("erase %d %d %d %d\n",rec.left,rec.top,rec.right,rec.bottom);
+			SelectClipRgn(dc,0);
+			FillRect(dc, &rec, br);
+			DelObject(br);
+		    }
+		    ReleaseDC(ev->ev_hWnd,dc);
 		}
 #endif
 		x = ev->ev_x;
@@ -6729,32 +6749,23 @@
 		__INST(shiftDown) = (modifiers & ShiftMask) ? true : false;
 		__INST(ctrlDown) = (modifiers & ControlMask) ? true : false;
 
-		if (isDoubleClick)
-		{
+		if (isDoubleClick) {
 		    multiClickState = 1;
 		    nextMultiClickTime = lastMSGTime + multiClickTime;
 		    ipS = &bmp;
 		    symS = @symbol(buttonMultiPress:x:y:view:);
-		}
-		else
-		{
-		    if (isDown)
-		    {
-			if (multiClickState && (lastMSGTime < nextMultiClickTime))
-			{
-			  nextMultiClickTime = lastMSGTime + multiClickTime;
-			  ipS = &bmp;
-			  symS = @symbol(buttonMultiPress:x:y:view:);
+		} else {
+		    if (isDown) {
+			if (multiClickState && (lastMSGTime < nextMultiClickTime)) {
+			    nextMultiClickTime = lastMSGTime + multiClickTime;
+			    ipS = &bmp;
+			    symS = @symbol(buttonMultiPress:x:y:view:);
+			} else {
+			    multiClickState = 0;
+			    ipS = &bp;
+			    symS = @symbol(buttonPress:x:y:view:);
 			}
-			else
-			{
-			  multiClickState = 0;
-			  ipS = &bp;
-			  symS = @symbol(buttonPress:x:y:view:);
-			}
-		    }
-		    else
-		    {
+		    } else {
 			ipS = &br;
 			symS = @symbol(buttonRelease:x:y:view:);
 		    }
@@ -7190,18 +7201,17 @@
 eventPendingWithSync:doSync
     "return true, if any event is pending.
      The doSync argument is ignored here - in windows, all drawing is synchronous."
+
     doSync notNil ifTrue:[self flush].
+
 %{  /* xxLIMITEDSTACK (WIN95 only) */
-    MSG msg;
-
-    if (__INST(inRecursiveDispatch) == true) {
-	RETURN (false);
-    }
-
-    if (isInputEvent()) {
-	RETURN (true);
+    if (__INST(inRecursiveDispatch) != true) {
+	if (hasEventQueued()) {
+	    RETURN (true);
+	}
     }
 %}.
+    ^ false
 !
 
 eventQueued
@@ -7221,13 +7231,13 @@
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 
     DDPRINTF(("peek q - "));
-    if (isInputEvent()) {
+    if (hasEventQueued()) {
 	DDPRINTF(("true\n"));
 	RETURN (true);
     }
     DDPRINTF(("false\n"));
-    RETURN ( false );
-%}
+%}.
+    ^ false
 !
 
 eventsPending:anEventMask for:aWindowIdOrNil withSync:doSync
@@ -7245,6 +7255,7 @@
     "return true, if any expose event is pending for a specific view,
      or any view (if the arg is nil).
      This is an X specific interface - not used on windows (scrolling is synchronous)"
+
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 %}.
     ^ false
@@ -7262,33 +7273,27 @@
     OBJ eB;
     struct queuedEvent *ev;
     struct queuedEvent *qev;
+
     eB = __INST(eventBuffer);
-    if (__isByteArray(eB)) {
-	ev = (struct queuedEvent *)(__ByteArrayInstPtr(eB)->ba_element);
-    } else {
-	__win32_fprintf(stderr, "WinWorkstation: no eventBuffer\n");
-	RETURN (false);
-    }
-    ev->ev_message = 0;
-
-    if (__isSmallInteger(eventMask)) {
-	evMask = __intVal(eventMask);
+    if (! __isByteArray(eB)) {
+	fprintf(stderr, "WinWorkstation [error]: no eventBuffer\n");
+	/* RETURN (false); */
     } else {
-	evMask = ~0;
-    }
-
-    if (__isExternalAddress(aViewIdOrNil))
-    {
-	if (deqEvent(ev,_HWNDVal(aViewIdOrNil),evMask))
-	{
-	  RETURN ( true );
-	}
-    }
-    else
-    {
-	if (deqEvent(ev,0,evMask))
-	{
-	  RETURN ( true );
+	ev = (struct queuedEvent *)(__ByteArrayInstPtr(eB)->ba_element);
+	ev->ev_message = 0;
+
+	if (__isSmallInteger(eventMask)) {
+	    evMask = __intVal(eventMask);
+	} else {
+	    evMask = ~0;
+	}
+	if (__isExternalAddress(aViewIdOrNil)) {
+	    wWanted = _HWNDVal(aViewIdOrNil);
+	} else{
+	    wWanted = 0;
+	}
+	if (deqEvent(ev, wWanted, evMask)) {
+	    RETURN ( true );
 	}
     }
 %}.
@@ -8141,6 +8146,7 @@
      {
 	struct gcData *gcData = _GCDATA(aGCId);
 	gcData->clipping = FALSE;
+	FLUSH_CACHED_DC(gcData);
 	RETURN (self);
     }
 %}
@@ -8157,11 +8163,13 @@
 	struct gcData *gcData = _GCDATA(aGCId);
 	COLORREF bgColor;
 
-	//hDC = _getDC(gcData);
 	bgColor = (COLORREF)st2RGB(__intVal(bgColorIndex),gcData);
 	if (bgColor != gcData->bgColor) {
 	    gcData->bgColor = bgColor;
-	    // SetBkColor(hDC, bgColor);
+	    // if (lastGcData == gcData) {
+	    //     SetBkColor(gcData->_hDC, bgColor);
+	    // }
+	    FLUSH_CACHED_DC(gcData);
 	}
 
 	DPRINTF(("setBackground: %x\n", bgColor));
@@ -8184,6 +8192,7 @@
 	else
 	    gcData->hMask = 0;
 
+	FLUSH_CACHED_DC(gcData);
 	DPRINTF(("masks set to %x\n",gcData->hMask));
 	RETURN (self);
     }
@@ -8195,26 +8204,17 @@
 
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 
-
-    if (ISCONNECTED && __isExternalAddress(aGCId))
-    {
+    if (ISCONNECTED && __isExternalAddress(aGCId)) {
 	struct gcData *gcData = _GCDATA(aGCId);
-	if (gcData && gcData->hWnd)
-	{
-	    if( aBool == true )
-	    {
+
+	if (gcData && gcData->hWnd) {
+	    if ( aBool == true ) {
 		/* set clip by child */
-		if (gcData->hWnd)
-		{
-		  gcData->clipByChild = TRUE;
-		}
-
+		gcData->clipByChild = TRUE;
 	    } else {
-		if (gcData->hWnd)
-		{
-		  gcData->clipByChild = FALSE;
-		}
-	    }
+		gcData->clipByChild = FALSE;
+	    }
+	    FLUSH_CACHED_DC(gcData);
 	} else {
 	    DPRINTF(("clipping by child failed - invalid win\n" ));
 	}
@@ -8247,6 +8247,7 @@
 	gcData->clipY = __intVal(clipY); 
 	gcData->clipW = __intVal(clipWidth); 
 	gcData->clipH = __intVal(clipHeight); 
+	FLUSH_CACHED_DC(gcData);
 	RETURN (self);
     }
 %}
@@ -8293,6 +8294,7 @@
 #endif
 	SelectObject(hDC, hFont);
 	_releaseDC(gcData);
+	FLUSH_CACHED_DC(gcData);
 	RETURN ( self );
     }
 %}
@@ -8308,6 +8310,11 @@
 
 	gcData->fgColor = (COLORREF)st2RGB(__intVal(fgColorIndex),gcData);
 	gcData->bgColor = (COLORREF)st2RGB(__intVal(bgColorIndex),gcData);
+	// if (lastGcData == gcData) {
+	//     SetTextColor(gcData->_hDC, fgColor);
+	//     SetBkColor(gcData->_hDC, bgColor);
+	// }
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x background: %x\n", gcData->fgColor, gcData->bgColor));
 	RETURN (self);
     }
@@ -8329,6 +8336,7 @@
 	    gcData->hMask = _HBITMAPVAL(aBitmapId);
 	else
 	    gcData->hMask = 0;
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x background: %x mask: %x\n", gcData->fgColor, gcData->bgColor,gcData->hMask));
 	RETURN (self);
     }
@@ -8351,6 +8359,7 @@
 	    gcData->hMask = _HBITMAPVAL(aBitmapId);
 	else
 	    gcData->hMask = 0;
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x background: %x mask: %x linewidth: %d\n", gcData->fgColor, gcData->bgColor,gcData->hMask,gcData->lineWidth));
 	RETURN (self);
     }
@@ -8368,6 +8377,7 @@
 	struct gcData *gcData = _GCDATA(aGCId);
 
 	gcData->fgColor = (COLORREF)st2RGB(__intVal(fgColorIndex),gcData);
+	FLUSH_CACHED_DC(gcData);
 	DDPRINTF(("setForeground: %x\n", gcData->fgColor));
 	RETURN (self);
     }
@@ -8435,10 +8445,11 @@
 	    gcData->rop2 = R2_COPYPEN;
 	    gcData->bitbltrop2 = BITBLT_COPY;
 	}
+	FLUSH_CACHED_DC(gcData);
 	RETURN (self);
     }
     else
-	__win32_fprintf(stderr, "WinWorkstation: Rasterfunction no GC\n");
+	INFOPRINT((stderr, "WinWorkstation [warning]: Rasterfunction no GC\n"));
 %}
 !
 
@@ -8457,38 +8468,47 @@
     if (__isExternalAddress(aGCId)
      && __isSmallInteger(aNumber)) {
 	struct gcData *gcData = _GCDATA(aGCId);
+	int style;
 
 	gcData->lineWidth = __intVal(aNumber);
 	if (lineStyle == @symbol(solid)) {
-	    gcData->lineStyle = PS_SOLID;
+	    style = PS_SOLID;
 	} else if (lineStyle == @symbol(dashed)) {
-	    gcData->lineStyle = PS_DASH;
+	    style= PS_DASH;
 	} else if (lineStyle == @symbol(dotted)) {
-	    gcData->lineStyle = PS_DOT;
+	    style= PS_DOT;
 	} else if (lineStyle == @symbol(dashDot)) {
-	    gcData->lineStyle = PS_DASHDOT;
+	    style= PS_DASHDOT;
 	} else if (lineStyle == @symbol(dashDotDot)) {
-	    gcData->lineStyle = PS_DASHDOTDOT;
+	    style= PS_DASHDOTDOT;
 	} else
-	    gcData->lineStyle = PS_SOLID;
+	    style= PS_SOLID;
+	gcData->lStyle &= ~PS_STYLE_MASK;
+	gcData->lStyle |= style;
+
 
 	if (capStyle == @symbol(round)) {
-	    gcData->capStyle = PS_ENDCAP_ROUND;
+	    style = PS_ENDCAP_ROUND;
 	} else if (capStyle == @symbol(square)) {
-	    gcData->capStyle = PS_ENDCAP_SQUARE;
+	    style = PS_ENDCAP_SQUARE;
 	} else if (capStyle == @symbol(flat)) {
-	    gcData->capStyle = PS_ENDCAP_FLAT;
+	    style = PS_ENDCAP_FLAT;
 	} else
-	    gcData->capStyle = PS_ENDCAP_FLAT;
-
+	    style = PS_ENDCAP_FLAT;
+	gcData->lStyle &= ~PS_ENDCAP_MASK;
+	gcData->lStyle |= style;
+        
 	if (joinStyle == @symbol(bevel)) {
-	    gcData->joinStyle = PS_JOIN_BEVEL;
+	    style = PS_JOIN_BEVEL;
 	} else if (joinStyle == @symbol(miter)) {
-	    gcData->joinStyle = PS_JOIN_MITER;
+	    style = PS_JOIN_MITER;
 	} else if (joinStyle == @symbol(round)) {
-	    gcData->joinStyle = PS_JOIN_ROUND;
+	    style = PS_JOIN_ROUND;
 	} else
-	    gcData->joinStyle = PS_JOIN_MITER;
+	    style = PS_JOIN_MITER;
+	gcData->lStyle &= ~PS_JOIN_MASK;
+	gcData->lStyle |= style;
+	FLUSH_CACHED_DC(gcData);
 
 	RETURN (self);
     }
@@ -8506,6 +8526,7 @@
 
 	    gcData->maskOrgX = __intVal(orgX);
 	    gcData->maskOrgY = __intVal(orgY);;
+	    FLUSH_CACHED_DC(gcData);
 	    RETURN (self);
 	}
     }
@@ -8524,6 +8545,7 @@
 	else
 	    gcData->hMask = 0;
 
+	FLUSH_CACHED_DC(gcData);
 	DPRINTF(("PixmapMasks set to %x\n",gcData->hMask));
 	RETURN (self);
     }
@@ -8533,7 +8555,7 @@
 !WinWorkstation methodsFor:'initialize / release'!
 
 close
-    "close down the connection to the X-server"
+    "close down the connection to the display"
 
 !
 
@@ -9394,12 +9416,12 @@
 		 == 0
 		)
 	    {
-		__win32_fprintf(stderr, "WinWorkstation: in primGetBitsFrom: BitBlt\n");
+		INFOPRINT((stderr, "WinWorkstation [warning]: in primGetBitsFrom: BitBlt\n"));
 	    }
 	    ReleaseDC(hWnd,wDC);
 	    if (GetDIBits(bDC,hBitmap,0,height,0,(struct tagBITMAPINFO *)&bitmap,DIB_RGB_COLORS) == 0)
 	    {
-		__win32_fprintf(stderr, "WinWorkstation: noinfo returned in primGetBits\n");
+		INFOPRINT((stderr, "WinWorkstation [warning]: noinfo returned in primGetBits\n"));
 		goto fail;
 	    }
 	    DPRINTF(("bitmap info:%d %d %d %d\n",bitmap.bmiHeader.biWidth,bitmap.bmiHeader.biHeight,bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biSizeImage));
@@ -9410,7 +9432,7 @@
 
 		if (numBytes > __byteArraySize(imageBits)) {
 		    /* imageBits too small */
-		    __win32_fprintf(stderr, "WinWorkstation [warning]: primGetBits - provided byteArray too small\n");
+		    INFOPRINT((stderr, "WinWorkstation [warning]: primGetBits - provided byteArray too small\n"));
 		    goto fail;
 		}
 		DPRINTF(("numBytes %d\n",numBytes));
@@ -9418,7 +9440,7 @@
 		bitmap.bmiHeader.biHeight = -height;
 		if (GetDIBits(bDC,hBitmap,0,height,__ByteArrayInstPtr(imageBits)->ba_element,(struct tagBITMAPINFO *)&bitmap,DIB_RGB_COLORS) == 0)
 		{
-		    __win32_fprintf(stderr, "WinWorkstation: zero bits returned in primGetBits\n");
+		    INFOPRINT((stderr, "WinWorkstation [warning]: zero bits returned in primGetBits\n"));
 		    goto fail;
 		}
 
@@ -9429,11 +9451,11 @@
 		      cp[2] = b;
 		}
 	    } else {
-		__win32_fprintf(stderr, "WinWorkstation: unacceptable bitmap in primGetBits\n");
+		INFOPRINT((stderr, "WinWorkstation [warning]: unacceptable bitmap in primGetBits\n"));
 		goto fail;
 	    }
 	} else {
-	    __win32_fprintf(stderr, "WinWorkstation: unacceptable bitmap in primGetBits\n");
+	    INFOPRINT((stderr, "WinWorkstation [warning]: unacceptable bitmap in primGetBits\n"));
 	    goto fail;
 	}
 
@@ -9659,23 +9681,21 @@
     OBJ s;
 
     hClip = OpenClipboard(NULL);
-    if (hClip)
-    {
-      hData = GetClipboardData(CF_TEXT);
-      CloseClipboard();
-      printf("WinWorkstation: clipBoard data is <%s>\n", (char *)hData);
-      s = __MKSTRING( (char *)hData );
-      RETURN(s);
+    if (hClip) {
+	hData = GetClipboardData(CF_TEXT);
+	CloseClipboard();
+	INFOPRINT((stderr, "WinWorkstation [info]: clipBoard data is <%s>\n", (char *)hData));
+	s = __MKSTRING( (char *)hData );
+	RETURN(s);
     }
     RETURN(nil);
 %}
 !
 
 getSelectionFor:drawableId
-    'getSelectionFor: not yet implemented' errorPrintCR.
+    'WinWorkstation [warning]:getSelectionFor: not yet implemented' errorPrintCR.
+
     ^ nil
-
-
 ! !
 
 !WinWorkstation methodsFor:'style defaults'!
@@ -10326,6 +10346,6 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.71 1998-09-25 18:25:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.72 1998-09-28 09:25:02 cg Exp $'
 ! !
 WinWorkstation initialize!