*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Wed, 19 Aug 1998 16:21:21 +0200
changeset 2253 864c30e95b4b
parent 2252 53bad848ffa8
child 2254 705357007714
*** empty log message ***
WinWorkstat.st
WinWorkstation.st
--- a/WinWorkstat.st	Tue Aug 18 15:14:42 1998 +0200
+++ b/WinWorkstat.st	Wed Aug 19 16:21:21 1998 +0200
@@ -324,9 +324,9 @@
 #ifdef DEBUG
 # define PRINTF(x)              { printf x;}
 # define CPRINTF(x)              { if (__debug__) printf x;}
-# define RESPRINTF(x)           { if (__debug__) printf x;}
-# define RES1PRINTF(x)          { if (__debug__) printf x;}
-# define RES_BMP_PRINTF(x)      { if (__debug__) printf x;}
+# define RESPRINTF(x)           /*{ if (__debug__) printf x;}*/
+# define RES1PRINTF(x)          /*{ if (__debug__) printf x;}*/
+# define RES_BMP_PRINTF(x)      /*{ if (__debug__) printf x;}*/
 # define TH_DPRINTF(x)          /*{ if (__debug__) printf x;}*/
 # define POSTPRINTF(x)          { if (__debug__) printf x;}
 # define DPRINTF(x)             { if (__debug__) printf x;}
@@ -552,7 +552,7 @@
 
 !WinWorkstation primitiveFunctions!
 %{
-#ifdef WIN32THREADS
+#ifdef xxWIN32THREADS
 extern void __suspendAktThread();
 extern void __resumeAktThread();
 #endif
@@ -877,9 +877,10 @@
 	  }
 	  eventQueueTail = ev;
       } else {
-	SetEvent(hInputEvent);
 
 	unlockEvent();
+	SetEvent(hInputEvent);
+        printf("winthread wait\n");
 	if (repeatCount++ < 10)
 	{
 	  Sleep(20);
@@ -888,16 +889,17 @@
 	     goto again;
 	  }
 	}
+        printf("winthread throw away\n");
 	/* throw away sorry */
 	return;
       }
 
 
-      SetEvent(hInputEvent);
 
       unlockEvent();
+      SetEvent(hInputEvent);
       /*SetThreadPriority(_masterThread,THREAD_PRIORITY_HIGHEST);*/
-      Sleep(0);
+      //Sleep(0);
     }
 }
 
@@ -1094,17 +1096,21 @@
 	      {
 		if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN)
 		{
+#if 0
 #ifdef WIN32THREADS
 		  __suspendAktThread();
 #else
 		  SuspendThread(_masterThread);
 #endif
+#endif
 		  n = (char*)malloc(200);
+#if 0
 #ifdef WIN32THREADS
 		  __resumeAktThread();
 #else
 		  ResumeThread(_masterThread);
 #endif
+#endif
 		  GetClassName(hWnd,n,200);
 		}
 #ifdef COUNT_RESOURCES
@@ -1190,7 +1196,7 @@
 			       rct.right-rct.left,
 			       rct.bottom-rct.top);
 	    return 0;
-
+            break;
 	case WM_ERASEBKGND:
 	    EVENT_PRINTF(("WM_ERASEBKGND\n"));
 	    if (isNative) {
@@ -1200,6 +1206,7 @@
 	    *pDefault = 0;
 	    if ((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0)
 	    {
+#if 0
 		int state;
 		HDC dc = (HDC)wParam;
 		/*HBRUSH br = GetWindow_bgBrush(hWnd);*/
@@ -1226,6 +1233,7 @@
 		ResumeThread(_masterThread);
 #endif
 		DelObject(br);
+#endif
 	    }
 	    return 1;
 	    break;
@@ -1235,19 +1243,17 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    if ((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0)
+	    if (((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0) && (__rootWinSpezial != hWnd))
 	    {
-	      if (GetUpdateRect(hWnd, &upd, TRUE))
-	      //if (GetUpdateRect(hWnd, &upd, FALSE))
+	      //if (GetUpdateRect(hWnd, &upd, TRUE))
+	      if (GetUpdateRect(hWnd, &upd, FALSE))
 	      {
-		  if ((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0)
-		  {
-		    if (GetWindow_eventMask(hWnd) & ExposureMask)
-		      enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
-		  }
+                  if (GetWindow_eventMask(hWnd) & ExposureMask)
+                    enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
 	      }
 	    }
-	    /**pDefault = 0;*/
+            else
+	      pDefault = 0;
 	    return 0;
 	    break;
 
@@ -1271,14 +1277,15 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    *pDefault = 0;
-	    return 0;
+            break;
+	    //*pDefault = 0;
+	    //return 0;
 
 	case WM_MOUSEACTIVATE :
 	    EVENT_PRINTF2(("WM_MOUSEACTIVATE h=%x\n", hWnd));
 	    *pDefault = 0;
-	    if (GetActiveWindow() &&
-		((GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) == 0)
+	    if ((__rootWinSpezial == hWnd) || (GetActiveWindow() && (LOWORD(lParam) == HTCLIENT))
+		/*((GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) == 0) */
 	       )
 	       return MA_NOACTIVATE;
 	    else
@@ -1286,11 +1293,22 @@
 	      return MA_ACTIVATE;
 	    }
 	    break;
+        case WM_NCHITTEST:
+	    EVENT_PRINTF(("WM_NCHITTEST\n"));
+            if (hWnd == __rootWinSpezial)
+            {
+	      *pDefault = 0;
+              return HTCLIENT;
+            }
+	    break;
+	case WM_NCACTIVATE:
+	    EVENT_PRINTF(("WM_NCACTIVATE\n"));
+	    break;
 	case WM_ACTIVATE:
 	    CPRINTF(("WM_ACTIVATE %s h=%x\n",
 			    LOWORD(wParam) ? "active" : "inactive",
 			    hWnd));
-
+#if 0
 	    enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
 	    switch (LOWORD(wParam)) {
 		case WA_INACTIVE:
@@ -1345,7 +1363,8 @@
 	    }
 	    *pDefault = 0;
 	    return 0;
-
+#endif
+            break;
 	case WM_SYSCHAR:
 	    EVENT_PRINTF2(("WM_SYSCHAR h=%x %x\n", hWnd, wParam));
 	    goto commonChar;
@@ -1609,13 +1628,13 @@
 		  }
 	      }
 	    }
+#endif
 	    if (isNative) {
 		*pDefault = 1;
 		return 0;
 	    }
 	    *pDefault = 0;
-#endif
-	    break;                                                                                                                                                                                      
+	    break;
 	case WM_STYLECHANGING:
 	    EVENT_PRINTF(("WM_STYLECHANGING\n"));
 	    break;
@@ -1636,10 +1655,6 @@
 	    EVENT_PRINTF(("WM_NCCREATE %x\n", message));
 	    break;
 
-	case WM_NCHITTEST:
-	    EVENT_PRINTF3(("WM_NCHITTEST %x\n", message));
-	    break;
-
 	case WM_NCMOUSEMOVE:
 	    {
 		short x, y;
@@ -1758,9 +1773,6 @@
 	case WM_PALETTECHANGED:
 	    EVENT_PRINTF(("WM_PALETTECHANGED\n"));
 	    break;
-	case WM_NCACTIVATE:
-	    EVENT_PRINTF(("WM_NCACTIVATE\n"));
-	    break;
 	case WM_ACTIVATEAPP:
 	    EVENT_PRINTF2(("WM_ACTIVATEAPP %s\n", wParam ? "active" : "inactive"));
 	    break;
@@ -1813,6 +1825,7 @@
     }
     return 0;
 }
+#if 0
 static
 winEventProcessingRoot(hWnd, message, wParam, lParam, pDefault)
     HWND hWnd;                /* window handle                   */
@@ -1827,11 +1840,12 @@
     RECT upd;
     int modifiers;
     int x, y, w, h;
+    int isNative = 0;
     PAINTSTRUCT ps;
 
-
-/*    printf("winEvent hWin=0x%x message=0x%x wP=0x%x lP=0x%x\n",
-			hWnd, message, wParam, lParam);
+/*
+    EVENT_PRINTF(("winEvent hWin=0x%x message=0x%x wP=0x%x lP=0x%x\n",
+			hWnd, message, wParam, lParam));
 */
 
 
@@ -1844,11 +1858,73 @@
 	      CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
 	      SETLOCALWINDOWINFOPTR(hWnd,lpcs->lpCreateParams);
 	      if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams)
-		DPRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
+		PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
 	      *pDefault = 0;
+#ifdef COUNT_RESOURCES
+	      __cnt_createWindows++;
+	   RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
+#endif
 	      DPRINTF(("WM_CREATE\n"));
 	    }
 	    break;
+	case WM_CLOSE:
+	    DPRINTF(("WM_CLOSE\n"));
+	    if (!destroyWin)
+	      enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
+	    else
+	    {
+	      destroyWin = 0;
+	      if (!DestroyWindow(hWnd))
+	      {
+		DPRINTF(("DestroyWindow ERROR\n"));
+	      }
+
+	    }
+	    *pDefault = 0;
+	    return 0;
+	    break;
+	case WM_DESTROY:
+	    {
+	      char *n = 0;
+	      DPRINTF(("WM_DESTROY\n"));
+	      if (GETLOCALWINDOWINFOPTR(hWnd))
+	      {
+		if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN)
+		{
+#if 0
+#ifdef WIN32THREADS
+		  __suspendAktThread();
+#else
+		  SuspendThread(_masterThread);
+#endif
+#endif
+		  n = (char*)malloc(200);
+#if 0
+#ifdef WIN32THREADS
+		  __resumeAktThread();
+#else
+		  ResumeThread(_masterThread);
+#endif
+#endif
+		  GetClassName(hWnd,n,200);
+		}
+#ifdef COUNT_RESOURCES
+	      __cnt_createWindows--;
+	   RESPRINTF(("DestroyWindows %d\n",__cnt_createWindows));
+#endif
+	      /* free all resources */
+		/*if (GetWindow_bgBrush(hWnd))
+		  DelObject(GetWindow_bgBrush(hWnd));*/
+		free(GETLOCALWINDOWINFOPTR(hWnd));
+		SETLOCALWINDOWINFOPTR(hWnd,0);
+	      }
+
+
+	      enqEvent(0,hWnd, message, wParam, (int)n, 0, 0, 0);
+	      *pDefault = 0;
+	      return 0;
+	    }
+	    break;
 	case WM_SETCURSOR:
 	    {
 		HCURSOR curs;
@@ -1878,22 +1954,76 @@
 	case WM_CHAR:
 	    EVENT_PRINTF2(("WM_CHAR h=%x %x\n", hWnd, wParam));
 	commonChar:
+	    if (isNative) {
+		*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, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	      if (GetWindow_eventMask(currentPointerView) & KeyReleaseMask)
+		enqEvent(KeyReleaseMask,currentPointerView, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	    }
+	    else
+	    {
+	      if (GetWindow_eventMask(hWnd) & KeyPressMask)
+		enqEvent(KeyPressMask,hWnd, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	      if (GetWindow_eventMask(hWnd) & KeyReleaseMask)
+		enqEvent(KeyReleaseMask,hWnd, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	    }
 	    *pDefault = 0;
 	    return 0;
 
+	case WM_KEYUP:
+	    EVENT_PRINTF2(("WM_KEYUP h=%x %x\n", hWnd, wParam));
+	    goto commonKeyUp;
+
 	case WM_SYSKEYUP:
 	    EVENT_PRINTF2(("WM_SYSKEYUP %x\n, wParam"));
-	    goto commonKey;
+	commonKeyUp:
+	    if (isNative) {
+		*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);
+	    }
+	    *pDefault = 0;
+	    return 0;
 
 	case WM_SYSKEYDOWN:
 	    EVENT_PRINTF2(("WM_SYSKEYDOWN %x\n, wParam"));
 	    goto commonKey;
 
-	case WM_KEYUP:
-	    EVENT_PRINTF2(("WM_KEYUP h=%x %x\n", hWnd, wParam));
-	    goto commonKey;
-
 	case WM_KEYDOWN:
 	    EVENT_PRINTF2(("WM_KEYDOWN h=%x %x\n", hWnd, wParam));
 
@@ -1901,49 +2031,143 @@
 	    if (wParam == VK_ESCAPE) {
 		ReleaseCapture();
 		currentCapture = CAPTURE_NONE;
-		ShowWindow(hWnd,SW_HIDE);
-		CPRINTF(("rootReleaseCapture <ESC>\n"));
+		CPRINTF(("ReleaseCapture <ESC>\n"));
 	    }
 
 	commonKey:
+	    if (isNative) {
+		*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);
+	    }
 	    *pDefault = 0;
 	    return 0;
-	case WM_LBUTTONDOWN:
-	case WM_MBUTTONDOWN:
-	case WM_RBUTTONDOWN:
-	    goto commonButton;
+
+	case WM_MOUSEMOVE:
+	    EVENT_PRINTF3(("WM_MOUSEMOVE h=%x\n", hWnd));
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
+
+	    {
+		short x, y;
+
+		x = (int)(short)LOWORD(lParam);
+		y = (int)(short)HIWORD(lParam);
+
+		modifiers = getModifiers();
+
+		if (currentCapture == CAPTURE_NONE)
+		{
+		  if (hWnd != currentPointerView) {
+		      if (currentPointerView) {
+			  if (GetWindow_eventMask(hWnd) & 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))
+		   )
+		     enqEvent(PointerMotionMask,currentPointerView, message, wParam, x, y, 0, modifiers);
+	    }
+	    *pDefault = 0;
+	    return 0;
 
 	case WM_LBUTTONUP:
 	case WM_MBUTTONUP:
 	case WM_RBUTTONUP:
-	    ReleaseCapture();
-	    SetWindowPos(hWnd, HWND_BOTTOM , 0, 0, 0, 0, SWP_NOSENDCHANGING|SWP_NOOWNERZORDER|SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
-	    ShowWindow(hWnd,SW_HIDE);
-	    currentCapture = CAPTURE_NONE;
-	    CPRINTF(("rootReleaseCapture <BUTTONUP>\n"));
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
+
+	    if (currentCapture == CAPTURE_IMPLICIT) {
+		currentCapture = CAPTURE_NONE;
+		ReleaseCapture();
+		CPRINTF(("ReleaseCapture <BUTTONUP>\n"));
+	    }
+	    modifiers = getModifiers();
+	    EVENT_PRINTF3(("WM_BUTTONUP h=%x pos=%d/%d\n",
+			   hWnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)));
+
+
+	    if (GetWindow_eventMask(hWnd) & ButtonReleaseMask)
+	      enqEvent(ButtonReleaseMask,hWnd, message, wParam, (int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),
+					      wParam,modifiers);
+	    *pDefault = 0;
+	    break;
+
+	case WM_LBUTTONDOWN:
+	case WM_MBUTTONDOWN:
+	case WM_RBUTTONDOWN:
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
+
+	    if (currentCapture == CAPTURE_NONE)
+	    {
+		currentCapture = CAPTURE_IMPLICIT;
+		//SetFocus(hWnd);
+		SetCapture(hWnd);
+		CPRINTF(("SetCapture <BUTTONDOWN>%x\n",hWnd));
+	    }
 	    goto commonButton;
-
 	case WM_LBUTTONDBLCLK:
 	case WM_MBUTTONDBLCLK:
 	case WM_RBUTTONDBLCLK:
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
 	commonButton:
 	    modifiers = getModifiers();
-	    EVENT_PRINTF3(("WM_BUTTONUP/DOWN h=%x pos=%d/%d\n",
-			   hWnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)));
-
+	    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);
 	    *pDefault = 0;
 	    break;
-	default:
-	    EVENT_PRINTF(("msg = %x\n", message));
-	    break;
     }
     return 0;
 }
+#endif
 LONG APIENTRY
 MainWndProc(HWND hWnd,UINT message,UINT wParam,LONG lParam);
-LONG APIENTRY
-MainWndProcRoot(HWND hWnd,UINT message,UINT wParam,LONG lParam);
+//LONG APIENTRY MainWndProcRoot(HWND hWnd,UINT message,UINT wParam,LONG lParam);
 
 void _USERENTRY dispatchThread(void *arg)
 {
@@ -1968,12 +2192,14 @@
       memset(li,0,sizeof(*_thread_local));
     }
 
-    __rootWinSpezial = CreateWindowEx( WS_EX_TRANSPARENT,app_nameroot,app_nameroot,0,
+    __rootWinSpezial = CreateWindowEx( WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT,app_nameroot,app_nameroot,
+                                       WS_POPUP|WS_DISABLED,
 				0,0,
 				rect.right-rect.left,rect.bottom-rect.top,
 				0,0,(HANDLE) __getHInstance(),li);
 
     /*printf("__rootWinSpezial %x\n",__rootWinSpezial);*/
+    //ShowWindow(__rootWinSpezial,SW_SHOWNOACTIVATE);
     SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
     SetEvent(hCreateEvent);
 
@@ -1991,7 +2217,7 @@
 	}
 	else if (msg.message == WM_THREADSETFOCUS)
 	{
-#ifdef WIN32THREADS
+#ifdef xxWIN32THREADS
 	  if (msg.lParam)
 	  {
 	    if (AttachThreadInput(_dispatchThreadId,msg.lParam,TRUE) == FALSE)
@@ -1999,7 +2225,8 @@
 	  }
 #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;
 	}
@@ -2023,6 +2250,12 @@
 	  }
 	  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"));
@@ -2109,7 +2342,7 @@
     }
     return retVal;
 }
-
+#if 0
 LONG APIENTRY
 MainWndProcRoot(HWND hWnd,UINT message,UINT wParam,LONG lParam)
 {
@@ -2120,7 +2353,7 @@
     retVal = winEventProcessingRoot(hWnd, message, wParam, lParam, &wantDefault);
     return TRUE;
 }
-
+#endif
 int CALLBACK
 EnumFPTypeFaceProc( lplf, lptm, dwType, lpData )
 	LOGFONT*        lplf;
@@ -5446,7 +5679,7 @@
 		if (i2 < n) 
 		{
 		    cp += i1;
-		    DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x hWnd=%x\n", cp, pX, pY,l,hDC,_HWNDVal(aDrawableId)));
+		    DDPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x hWnd=%x\n", cp, pX, pY,l,hDC,_HWNDVal(aDrawableId)));
 		    if (opaque == true) {
 			SetBkMode(hDC, OPAQUE);
 		    } else {
@@ -5475,7 +5708,7 @@
 		if (i2 < n) 
 		{
 		    cp += i1;
-		    DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
+		    DDPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
 		    if (opaque == true) {
 			SetBkMode(hDC, OPAQUE);
 		    } else {
@@ -6299,7 +6532,6 @@
 			 theView);
 		break;
 	    case WM_PAINT:
-#if 0
 		{
 		  RECT rec;
 		  HDC dc = (HDC)GetDC(ev->ev_hWnd);
@@ -6310,14 +6542,13 @@
 		    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);
+		    //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;
 		y = ev->ev_y;
 		w = ev->ev_w;
@@ -6992,7 +7223,8 @@
 handleExposeOnlyFor:aView
     "from now on, handle expose events only"
 
-    dispatchingExpose := aView id
+    "/ dispatchingExpose := aView id
+    'handleExposeOnlyFor: not yet implemented' printCR.
 !
 
 mappingChanged:what event:eB
@@ -7695,7 +7927,7 @@
 
 			prevFont = SelectObject(tmpDC, hFont);
 			GetTextExtentPoint32(tmpDC, cp, l, &tsize);
-#ifdef DEBUG
+#ifdef xxDEBUG
 			if (__debug__)
 			{
 			  char buf[80];
@@ -7719,7 +7951,7 @@
 
 			prevFont = SelectObject(tmpDC, hFont);
 			GetTextExtentPoint32(tmpDC, cp, l, &tsize);
-#ifdef DEBUG
+#ifdef xxDEBUG
 			if (__debug__)
 			{
 			  char buf[80];
@@ -7774,7 +8006,10 @@
 	  {
 	     hWnd = __rootWinSpezial;
 	     ShowWindow(hWnd,SW_SHOWNOACTIVATE);
-	     SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSENDCHANGING|SWP_NOOWNERZORDER|SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
+             //EnableWindow(hWnd,TRUE);
+	     SetWindowPos(hWnd, HWND_TOP,
+              0, 0, 0, 0,SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOCOPYBITS
+              |SWP_NOACTIVATE |SWP_NOMOVE|SWP_NOSIZE);
 	     CPRINTF(("setRootCapture %x\n",hWnd));
 	  }
 #endif
@@ -8345,7 +8580,7 @@
 	}
 
 	wc.style = 0;
-	wc.lpfnWndProc = (WNDPROC) MainWndProcRoot;
+	wc.lpfnWndProc = (WNDPROC) MainWndProc;// Root;
 	wc.cbClsExtra = 0;
 	wc.cbWndExtra = N_WINDOW_PRIVATE;
 	wc.hInstance = (HANDLE) __getHInstance();
@@ -8773,7 +9008,23 @@
     |s |
 
 %{
-    s = __MKSMALLINT(__modifiers);
+    int modifiers = 0;
+    int b1m = Button1Mask;
+    int b3m = Button3Mask;
+    if (GetSystemMetrics(SM_SWAPBUTTON))
+    {
+      b3m = Button1Mask;
+      b1m = Button3Mask;
+    }
+
+    if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
+	modifiers |= b1m;
+    if (GetAsyncKeyState(VK_MBUTTON) & 0x8000)
+	modifiers |= Button2Mask;
+    if (GetAsyncKeyState(VK_RBUTTON) & 0x8000)
+	modifiers |= b3m;
+
+    s = __MKSMALLINT(modifiers);
 %}.
     ^ s
 
@@ -9420,7 +9671,7 @@
 	    SetWindowPos(win, (HWND)0,
 			 rec.left, rec.top,
 			 rec.right - rec.left, rec.bottom - rec.top,
-			 SWP_NOACTIVATE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	    if (aBoolean == true)
 	    {
 	      ShowWindow(win, SW_SHOWMINIMIZED);
@@ -9429,8 +9680,8 @@
 	    else
 	    {
 	      enqEvent(0,win, WM_SHOWWINDOW, TRUE, 0, 0, 0, 0);
-	      ShowWindow(win, SW_RESTORE);
-	      /*ShowWindow(win, SW_SHOW);*/
+	      //ShowWindow(win, SW_RESTORE);
+	      ShowWindow(win, SW_SHOWNOACTIVATE);
 	    }
 	}
 	RETURN ( self );
@@ -9450,7 +9701,7 @@
 	    CPRINTF(("mapWindow %x\n",win));
 	    ShowWindow(win, SW_SHOWNOACTIVATE);
 	    //ShowWindow(win, SW_SHOW);
-	    //SetWindowPos(_thread_newWinHandle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW|/*SWP_NOACTIVATE|*/SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
+	    SetWindowPos(win, HWND_TOP, 0, 0, 0, 0, SWP_NOSENDCHANGING|/*SWP_SHOWWINDOW|*/SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE/*|SWP_NOZORDER|SWP_NOOWNERZORDER */	);
 	    //enqEvent(0,win, WM_SHOWWINDOW, TRUE, 0, 0, 0, 0);
 	}
 	RETURN ( self );
@@ -9468,7 +9719,7 @@
 
 	if (win) {
 	    CPRINTF(("activateWindow %x\n",win));
-            ShowWindowAsync(win, SW_SHOW | SW_SHOWNORMAL);
+	    ShowWindowAsync(win, SW_SHOW | SW_SHOWNORMAL);
 	    //ShowWindow(win, SW_SHOW);
 	    //SetWindowPos(_thread_newWinHandle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW|/*SWP_NOACTIVATE|*/SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
 	    //enqEvent(0,win, WM_SHOWWINDOW, TRUE, 0, 0, 0, 0);
@@ -9502,7 +9753,7 @@
 	    SetWindowPos(win, (HWND)0,
 			 rec.left, rec.top,
 			 rec.right - rec.left, rec.bottom - rec.top,
-			 SWP_NOACTIVATE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	}
 	RETURN ( self );
     }
@@ -9532,7 +9783,7 @@
 	    SetWindowPos(win, (HWND)0,
 			 rec.left, rec.top,
 			 0, 0,
-			 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	}
 	RETURN ( self );
     }
@@ -9628,7 +9879,7 @@
 
 	if (hWnd) {
 	    CPRINTF(("raiseWindow %x\n",hWnd));
-	    SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER  |SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
+	    SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, /*SWP_NOOWNERZORDER  |*/SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
 	}
 	RETURN ( self );
     }
@@ -9657,7 +9908,7 @@
 	    SetWindowPos(hWnd, (HWND)0,
 			 0, 0,
 			 rec.right - rec.left, rec.bottom - rec.top,
-			 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	}
 	RETURN ( self );
     }
@@ -9849,8 +10100,9 @@
 	HWND win = _HWNDVal(aWindowId);
 
 	if (win) {
+	    CPRINTF(("unmapWindow %x\n",win));
 	    ShowWindow(win, SW_HIDE);
-	    CPRINTF(("unmapWindow %x\n",win));
+	    CPRINTF(("unmapWindow1 %x\n",win));
 	    //enqEvent(win, WM_SHOWWINDOW, FALSE, 0, 0, 0, 0);
 	}
 	RETURN ( self );
@@ -9861,6 +10113,6 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/WinWorkstat.st,v 1.43 1998-08-17 09:55:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/WinWorkstat.st,v 1.44 1998-08-19 14:21:21 cg Exp $'
 ! !
 WinWorkstation initialize!
--- a/WinWorkstation.st	Tue Aug 18 15:14:42 1998 +0200
+++ b/WinWorkstation.st	Wed Aug 19 16:21:21 1998 +0200
@@ -324,9 +324,9 @@
 #ifdef DEBUG
 # define PRINTF(x)              { printf x;}
 # define CPRINTF(x)              { if (__debug__) printf x;}
-# define RESPRINTF(x)           { if (__debug__) printf x;}
-# define RES1PRINTF(x)          { if (__debug__) printf x;}
-# define RES_BMP_PRINTF(x)      { if (__debug__) printf x;}
+# define RESPRINTF(x)           /*{ if (__debug__) printf x;}*/
+# define RES1PRINTF(x)          /*{ if (__debug__) printf x;}*/
+# define RES_BMP_PRINTF(x)      /*{ if (__debug__) printf x;}*/
 # define TH_DPRINTF(x)          /*{ if (__debug__) printf x;}*/
 # define POSTPRINTF(x)          { if (__debug__) printf x;}
 # define DPRINTF(x)             { if (__debug__) printf x;}
@@ -552,7 +552,7 @@
 
 !WinWorkstation primitiveFunctions!
 %{
-#ifdef WIN32THREADS
+#ifdef xxWIN32THREADS
 extern void __suspendAktThread();
 extern void __resumeAktThread();
 #endif
@@ -877,9 +877,10 @@
 	  }
 	  eventQueueTail = ev;
       } else {
-	SetEvent(hInputEvent);
 
 	unlockEvent();
+	SetEvent(hInputEvent);
+        printf("winthread wait\n");
 	if (repeatCount++ < 10)
 	{
 	  Sleep(20);
@@ -888,16 +889,17 @@
 	     goto again;
 	  }
 	}
+        printf("winthread throw away\n");
 	/* throw away sorry */
 	return;
       }
 
 
-      SetEvent(hInputEvent);
 
       unlockEvent();
+      SetEvent(hInputEvent);
       /*SetThreadPriority(_masterThread,THREAD_PRIORITY_HIGHEST);*/
-      Sleep(0);
+      //Sleep(0);
     }
 }
 
@@ -1094,17 +1096,21 @@
 	      {
 		if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN)
 		{
+#if 0
 #ifdef WIN32THREADS
 		  __suspendAktThread();
 #else
 		  SuspendThread(_masterThread);
 #endif
+#endif
 		  n = (char*)malloc(200);
+#if 0
 #ifdef WIN32THREADS
 		  __resumeAktThread();
 #else
 		  ResumeThread(_masterThread);
 #endif
+#endif
 		  GetClassName(hWnd,n,200);
 		}
 #ifdef COUNT_RESOURCES
@@ -1190,7 +1196,7 @@
 			       rct.right-rct.left,
 			       rct.bottom-rct.top);
 	    return 0;
-
+            break;
 	case WM_ERASEBKGND:
 	    EVENT_PRINTF(("WM_ERASEBKGND\n"));
 	    if (isNative) {
@@ -1200,6 +1206,7 @@
 	    *pDefault = 0;
 	    if ((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0)
 	    {
+#if 0
 		int state;
 		HDC dc = (HDC)wParam;
 		/*HBRUSH br = GetWindow_bgBrush(hWnd);*/
@@ -1226,6 +1233,7 @@
 		ResumeThread(_masterThread);
 #endif
 		DelObject(br);
+#endif
 	    }
 	    return 1;
 	    break;
@@ -1235,19 +1243,17 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    if ((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0)
+	    if (((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0) && (__rootWinSpezial != hWnd))
 	    {
-	      if (GetUpdateRect(hWnd, &upd, TRUE))
-	      //if (GetUpdateRect(hWnd, &upd, FALSE))
+	      //if (GetUpdateRect(hWnd, &upd, TRUE))
+	      if (GetUpdateRect(hWnd, &upd, FALSE))
 	      {
-		  if ((GetWindow_Flag(hWnd) & LI_INPUTWIN) == 0)
-		  {
-		    if (GetWindow_eventMask(hWnd) & ExposureMask)
-		      enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
-		  }
+                  if (GetWindow_eventMask(hWnd) & ExposureMask)
+                    enqEvent(ExposureMask,hWnd, message, wParam, upd.left, upd.top, upd.right, upd.bottom);
 	      }
 	    }
-	    /**pDefault = 0;*/
+            else
+	      pDefault = 0;
 	    return 0;
 	    break;
 
@@ -1271,14 +1277,15 @@
 		*pDefault = 1;
 		return 0;
 	    }
-	    *pDefault = 0;
-	    return 0;
+            break;
+	    //*pDefault = 0;
+	    //return 0;
 
 	case WM_MOUSEACTIVATE :
 	    EVENT_PRINTF2(("WM_MOUSEACTIVATE h=%x\n", hWnd));
 	    *pDefault = 0;
-	    if (GetActiveWindow() &&
-		((GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) == 0)
+	    if ((__rootWinSpezial == hWnd) || (GetActiveWindow() && (LOWORD(lParam) == HTCLIENT))
+		/*((GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN) == 0) */
 	       )
 	       return MA_NOACTIVATE;
 	    else
@@ -1286,11 +1293,22 @@
 	      return MA_ACTIVATE;
 	    }
 	    break;
+        case WM_NCHITTEST:
+	    EVENT_PRINTF(("WM_NCHITTEST\n"));
+            if (hWnd == __rootWinSpezial)
+            {
+	      *pDefault = 0;
+              return HTCLIENT;
+            }
+	    break;
+	case WM_NCACTIVATE:
+	    EVENT_PRINTF(("WM_NCACTIVATE\n"));
+	    break;
 	case WM_ACTIVATE:
 	    CPRINTF(("WM_ACTIVATE %s h=%x\n",
 			    LOWORD(wParam) ? "active" : "inactive",
 			    hWnd));
-
+#if 0
 	    enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
 	    switch (LOWORD(wParam)) {
 		case WA_INACTIVE:
@@ -1345,7 +1363,8 @@
 	    }
 	    *pDefault = 0;
 	    return 0;
-
+#endif
+            break;
 	case WM_SYSCHAR:
 	    EVENT_PRINTF2(("WM_SYSCHAR h=%x %x\n", hWnd, wParam));
 	    goto commonChar;
@@ -1609,13 +1628,13 @@
 		  }
 	      }
 	    }
+#endif
 	    if (isNative) {
 		*pDefault = 1;
 		return 0;
 	    }
 	    *pDefault = 0;
-#endif
-	    break;                                                                                                                                                                                      
+	    break;
 	case WM_STYLECHANGING:
 	    EVENT_PRINTF(("WM_STYLECHANGING\n"));
 	    break;
@@ -1636,10 +1655,6 @@
 	    EVENT_PRINTF(("WM_NCCREATE %x\n", message));
 	    break;
 
-	case WM_NCHITTEST:
-	    EVENT_PRINTF3(("WM_NCHITTEST %x\n", message));
-	    break;
-
 	case WM_NCMOUSEMOVE:
 	    {
 		short x, y;
@@ -1758,9 +1773,6 @@
 	case WM_PALETTECHANGED:
 	    EVENT_PRINTF(("WM_PALETTECHANGED\n"));
 	    break;
-	case WM_NCACTIVATE:
-	    EVENT_PRINTF(("WM_NCACTIVATE\n"));
-	    break;
 	case WM_ACTIVATEAPP:
 	    EVENT_PRINTF2(("WM_ACTIVATEAPP %s\n", wParam ? "active" : "inactive"));
 	    break;
@@ -1813,6 +1825,7 @@
     }
     return 0;
 }
+#if 0
 static
 winEventProcessingRoot(hWnd, message, wParam, lParam, pDefault)
     HWND hWnd;                /* window handle                   */
@@ -1827,11 +1840,12 @@
     RECT upd;
     int modifiers;
     int x, y, w, h;
+    int isNative = 0;
     PAINTSTRUCT ps;
 
-
-/*    printf("winEvent hWin=0x%x message=0x%x wP=0x%x lP=0x%x\n",
-			hWnd, message, wParam, lParam);
+/*
+    EVENT_PRINTF(("winEvent hWin=0x%x message=0x%x wP=0x%x lP=0x%x\n",
+			hWnd, message, wParam, lParam));
 */
 
 
@@ -1844,11 +1858,73 @@
 	      CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
 	      SETLOCALWINDOWINFOPTR(hWnd,lpcs->lpCreateParams);
 	      if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams)
-		DPRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
+		PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
 	      *pDefault = 0;
+#ifdef COUNT_RESOURCES
+	      __cnt_createWindows++;
+	   RESPRINTF(("CreateWindows %d\n",__cnt_createWindows));
+#endif
 	      DPRINTF(("WM_CREATE\n"));
 	    }
 	    break;
+	case WM_CLOSE:
+	    DPRINTF(("WM_CLOSE\n"));
+	    if (!destroyWin)
+	      enqEvent(0,hWnd, message, wParam, 0, 0, 0, 0);
+	    else
+	    {
+	      destroyWin = 0;
+	      if (!DestroyWindow(hWnd))
+	      {
+		DPRINTF(("DestroyWindow ERROR\n"));
+	      }
+
+	    }
+	    *pDefault = 0;
+	    return 0;
+	    break;
+	case WM_DESTROY:
+	    {
+	      char *n = 0;
+	      DPRINTF(("WM_DESTROY\n"));
+	      if (GETLOCALWINDOWINFOPTR(hWnd))
+	      {
+		if (GETLOCALWINDOWINFOPTR(hWnd)->flag & LI_TOPWIN)
+		{
+#if 0
+#ifdef WIN32THREADS
+		  __suspendAktThread();
+#else
+		  SuspendThread(_masterThread);
+#endif
+#endif
+		  n = (char*)malloc(200);
+#if 0
+#ifdef WIN32THREADS
+		  __resumeAktThread();
+#else
+		  ResumeThread(_masterThread);
+#endif
+#endif
+		  GetClassName(hWnd,n,200);
+		}
+#ifdef COUNT_RESOURCES
+	      __cnt_createWindows--;
+	   RESPRINTF(("DestroyWindows %d\n",__cnt_createWindows));
+#endif
+	      /* free all resources */
+		/*if (GetWindow_bgBrush(hWnd))
+		  DelObject(GetWindow_bgBrush(hWnd));*/
+		free(GETLOCALWINDOWINFOPTR(hWnd));
+		SETLOCALWINDOWINFOPTR(hWnd,0);
+	      }
+
+
+	      enqEvent(0,hWnd, message, wParam, (int)n, 0, 0, 0);
+	      *pDefault = 0;
+	      return 0;
+	    }
+	    break;
 	case WM_SETCURSOR:
 	    {
 		HCURSOR curs;
@@ -1878,22 +1954,76 @@
 	case WM_CHAR:
 	    EVENT_PRINTF2(("WM_CHAR h=%x %x\n", hWnd, wParam));
 	commonChar:
+	    if (isNative) {
+		*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, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	      if (GetWindow_eventMask(currentPointerView) & KeyReleaseMask)
+		enqEvent(KeyReleaseMask,currentPointerView, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	    }
+	    else
+	    {
+	      if (GetWindow_eventMask(hWnd) & KeyPressMask)
+		enqEvent(KeyPressMask,hWnd, WM_KEYDOWN, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	      if (GetWindow_eventMask(hWnd) & KeyReleaseMask)
+		enqEvent(KeyReleaseMask,hWnd, WM_KEYUP, wParam, x, y, lParam, modifiers | TRANSLATED_KEY);
+	    }
 	    *pDefault = 0;
 	    return 0;
 
+	case WM_KEYUP:
+	    EVENT_PRINTF2(("WM_KEYUP h=%x %x\n", hWnd, wParam));
+	    goto commonKeyUp;
+
 	case WM_SYSKEYUP:
 	    EVENT_PRINTF2(("WM_SYSKEYUP %x\n, wParam"));
-	    goto commonKey;
+	commonKeyUp:
+	    if (isNative) {
+		*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);
+	    }
+	    *pDefault = 0;
+	    return 0;
 
 	case WM_SYSKEYDOWN:
 	    EVENT_PRINTF2(("WM_SYSKEYDOWN %x\n, wParam"));
 	    goto commonKey;
 
-	case WM_KEYUP:
-	    EVENT_PRINTF2(("WM_KEYUP h=%x %x\n", hWnd, wParam));
-	    goto commonKey;
-
 	case WM_KEYDOWN:
 	    EVENT_PRINTF2(("WM_KEYDOWN h=%x %x\n", hWnd, wParam));
 
@@ -1901,49 +2031,143 @@
 	    if (wParam == VK_ESCAPE) {
 		ReleaseCapture();
 		currentCapture = CAPTURE_NONE;
-		ShowWindow(hWnd,SW_HIDE);
-		CPRINTF(("rootReleaseCapture <ESC>\n"));
+		CPRINTF(("ReleaseCapture <ESC>\n"));
 	    }
 
 	commonKey:
+	    if (isNative) {
+		*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);
+	    }
 	    *pDefault = 0;
 	    return 0;
-	case WM_LBUTTONDOWN:
-	case WM_MBUTTONDOWN:
-	case WM_RBUTTONDOWN:
-	    goto commonButton;
+
+	case WM_MOUSEMOVE:
+	    EVENT_PRINTF3(("WM_MOUSEMOVE h=%x\n", hWnd));
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
+
+	    {
+		short x, y;
+
+		x = (int)(short)LOWORD(lParam);
+		y = (int)(short)HIWORD(lParam);
+
+		modifiers = getModifiers();
+
+		if (currentCapture == CAPTURE_NONE)
+		{
+		  if (hWnd != currentPointerView) {
+		      if (currentPointerView) {
+			  if (GetWindow_eventMask(hWnd) & 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))
+		   )
+		     enqEvent(PointerMotionMask,currentPointerView, message, wParam, x, y, 0, modifiers);
+	    }
+	    *pDefault = 0;
+	    return 0;
 
 	case WM_LBUTTONUP:
 	case WM_MBUTTONUP:
 	case WM_RBUTTONUP:
-	    ReleaseCapture();
-	    SetWindowPos(hWnd, HWND_BOTTOM , 0, 0, 0, 0, SWP_NOSENDCHANGING|SWP_NOOWNERZORDER|SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
-	    ShowWindow(hWnd,SW_HIDE);
-	    currentCapture = CAPTURE_NONE;
-	    CPRINTF(("rootReleaseCapture <BUTTONUP>\n"));
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
+
+	    if (currentCapture == CAPTURE_IMPLICIT) {
+		currentCapture = CAPTURE_NONE;
+		ReleaseCapture();
+		CPRINTF(("ReleaseCapture <BUTTONUP>\n"));
+	    }
+	    modifiers = getModifiers();
+	    EVENT_PRINTF3(("WM_BUTTONUP h=%x pos=%d/%d\n",
+			   hWnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)));
+
+
+	    if (GetWindow_eventMask(hWnd) & ButtonReleaseMask)
+	      enqEvent(ButtonReleaseMask,hWnd, message, wParam, (int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),
+					      wParam,modifiers);
+	    *pDefault = 0;
+	    break;
+
+	case WM_LBUTTONDOWN:
+	case WM_MBUTTONDOWN:
+	case WM_RBUTTONDOWN:
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
+
+	    if (currentCapture == CAPTURE_NONE)
+	    {
+		currentCapture = CAPTURE_IMPLICIT;
+		//SetFocus(hWnd);
+		SetCapture(hWnd);
+		CPRINTF(("SetCapture <BUTTONDOWN>%x\n",hWnd));
+	    }
 	    goto commonButton;
-
 	case WM_LBUTTONDBLCLK:
 	case WM_MBUTTONDBLCLK:
 	case WM_RBUTTONDBLCLK:
+	    if (isNative) {
+		*pDefault = 1;
+		return 0;
+	    }
 	commonButton:
 	    modifiers = getModifiers();
-	    EVENT_PRINTF3(("WM_BUTTONUP/DOWN h=%x pos=%d/%d\n",
-			   hWnd, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam)));
-
+	    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);
 	    *pDefault = 0;
 	    break;
-	default:
-	    EVENT_PRINTF(("msg = %x\n", message));
-	    break;
     }
     return 0;
 }
+#endif
 LONG APIENTRY
 MainWndProc(HWND hWnd,UINT message,UINT wParam,LONG lParam);
-LONG APIENTRY
-MainWndProcRoot(HWND hWnd,UINT message,UINT wParam,LONG lParam);
+//LONG APIENTRY MainWndProcRoot(HWND hWnd,UINT message,UINT wParam,LONG lParam);
 
 void _USERENTRY dispatchThread(void *arg)
 {
@@ -1968,12 +2192,14 @@
       memset(li,0,sizeof(*_thread_local));
     }
 
-    __rootWinSpezial = CreateWindowEx( WS_EX_TRANSPARENT,app_nameroot,app_nameroot,0,
+    __rootWinSpezial = CreateWindowEx( WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT,app_nameroot,app_nameroot,
+                                       WS_POPUP|WS_DISABLED,
 				0,0,
 				rect.right-rect.left,rect.bottom-rect.top,
 				0,0,(HANDLE) __getHInstance(),li);
 
     /*printf("__rootWinSpezial %x\n",__rootWinSpezial);*/
+    //ShowWindow(__rootWinSpezial,SW_SHOWNOACTIVATE);
     SetWindowPos(__rootWinSpezial, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
     SetEvent(hCreateEvent);
 
@@ -1991,7 +2217,7 @@
 	}
 	else if (msg.message == WM_THREADSETFOCUS)
 	{
-#ifdef WIN32THREADS
+#ifdef xxWIN32THREADS
 	  if (msg.lParam)
 	  {
 	    if (AttachThreadInput(_dispatchThreadId,msg.lParam,TRUE) == FALSE)
@@ -1999,7 +2225,8 @@
 	  }
 #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;
 	}
@@ -2023,6 +2250,12 @@
 	  }
 	  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"));
@@ -2109,7 +2342,7 @@
     }
     return retVal;
 }
-
+#if 0
 LONG APIENTRY
 MainWndProcRoot(HWND hWnd,UINT message,UINT wParam,LONG lParam)
 {
@@ -2120,7 +2353,7 @@
     retVal = winEventProcessingRoot(hWnd, message, wParam, lParam, &wantDefault);
     return TRUE;
 }
-
+#endif
 int CALLBACK
 EnumFPTypeFaceProc( lplf, lptm, dwType, lpData )
 	LOGFONT*        lplf;
@@ -5446,7 +5679,7 @@
 		if (i2 < n) 
 		{
 		    cp += i1;
-		    DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x hWnd=%x\n", cp, pX, pY,l,hDC,_HWNDVal(aDrawableId)));
+		    DDPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x hWnd=%x\n", cp, pX, pY,l,hDC,_HWNDVal(aDrawableId)));
 		    if (opaque == true) {
 			SetBkMode(hDC, OPAQUE);
 		    } else {
@@ -5475,7 +5708,7 @@
 		if (i2 < n) 
 		{
 		    cp += i1;
-		    DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
+		    DDPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
 		    if (opaque == true) {
 			SetBkMode(hDC, OPAQUE);
 		    } else {
@@ -6299,7 +6532,6 @@
 			 theView);
 		break;
 	    case WM_PAINT:
-#if 0
 		{
 		  RECT rec;
 		  HDC dc = (HDC)GetDC(ev->ev_hWnd);
@@ -6310,14 +6542,13 @@
 		    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);
+		    //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;
 		y = ev->ev_y;
 		w = ev->ev_w;
@@ -6992,7 +7223,8 @@
 handleExposeOnlyFor:aView
     "from now on, handle expose events only"
 
-    dispatchingExpose := aView id
+    "/ dispatchingExpose := aView id
+    'handleExposeOnlyFor: not yet implemented' printCR.
 !
 
 mappingChanged:what event:eB
@@ -7695,7 +7927,7 @@
 
 			prevFont = SelectObject(tmpDC, hFont);
 			GetTextExtentPoint32(tmpDC, cp, l, &tsize);
-#ifdef DEBUG
+#ifdef xxDEBUG
 			if (__debug__)
 			{
 			  char buf[80];
@@ -7719,7 +7951,7 @@
 
 			prevFont = SelectObject(tmpDC, hFont);
 			GetTextExtentPoint32(tmpDC, cp, l, &tsize);
-#ifdef DEBUG
+#ifdef xxDEBUG
 			if (__debug__)
 			{
 			  char buf[80];
@@ -7774,7 +8006,10 @@
 	  {
 	     hWnd = __rootWinSpezial;
 	     ShowWindow(hWnd,SW_SHOWNOACTIVATE);
-	     SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSENDCHANGING|SWP_NOOWNERZORDER|SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
+             //EnableWindow(hWnd,TRUE);
+	     SetWindowPos(hWnd, HWND_TOP,
+              0, 0, 0, 0,SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOCOPYBITS
+              |SWP_NOACTIVATE |SWP_NOMOVE|SWP_NOSIZE);
 	     CPRINTF(("setRootCapture %x\n",hWnd));
 	  }
 #endif
@@ -8345,7 +8580,7 @@
 	}
 
 	wc.style = 0;
-	wc.lpfnWndProc = (WNDPROC) MainWndProcRoot;
+	wc.lpfnWndProc = (WNDPROC) MainWndProc;// Root;
 	wc.cbClsExtra = 0;
 	wc.cbWndExtra = N_WINDOW_PRIVATE;
 	wc.hInstance = (HANDLE) __getHInstance();
@@ -8773,7 +9008,23 @@
     |s |
 
 %{
-    s = __MKSMALLINT(__modifiers);
+    int modifiers = 0;
+    int b1m = Button1Mask;
+    int b3m = Button3Mask;
+    if (GetSystemMetrics(SM_SWAPBUTTON))
+    {
+      b3m = Button1Mask;
+      b1m = Button3Mask;
+    }
+
+    if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
+	modifiers |= b1m;
+    if (GetAsyncKeyState(VK_MBUTTON) & 0x8000)
+	modifiers |= Button2Mask;
+    if (GetAsyncKeyState(VK_RBUTTON) & 0x8000)
+	modifiers |= b3m;
+
+    s = __MKSMALLINT(modifiers);
 %}.
     ^ s
 
@@ -9420,7 +9671,7 @@
 	    SetWindowPos(win, (HWND)0,
 			 rec.left, rec.top,
 			 rec.right - rec.left, rec.bottom - rec.top,
-			 SWP_NOACTIVATE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	    if (aBoolean == true)
 	    {
 	      ShowWindow(win, SW_SHOWMINIMIZED);
@@ -9429,8 +9680,8 @@
 	    else
 	    {
 	      enqEvent(0,win, WM_SHOWWINDOW, TRUE, 0, 0, 0, 0);
-	      ShowWindow(win, SW_RESTORE);
-	      /*ShowWindow(win, SW_SHOW);*/
+	      //ShowWindow(win, SW_RESTORE);
+	      ShowWindow(win, SW_SHOWNOACTIVATE);
 	    }
 	}
 	RETURN ( self );
@@ -9450,7 +9701,7 @@
 	    CPRINTF(("mapWindow %x\n",win));
 	    ShowWindow(win, SW_SHOWNOACTIVATE);
 	    //ShowWindow(win, SW_SHOW);
-	    //SetWindowPos(_thread_newWinHandle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW|/*SWP_NOACTIVATE|*/SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
+	    SetWindowPos(win, HWND_TOP, 0, 0, 0, 0, SWP_NOSENDCHANGING|/*SWP_SHOWWINDOW|*/SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE/*|SWP_NOZORDER|SWP_NOOWNERZORDER */	);
 	    //enqEvent(0,win, WM_SHOWWINDOW, TRUE, 0, 0, 0, 0);
 	}
 	RETURN ( self );
@@ -9468,7 +9719,7 @@
 
 	if (win) {
 	    CPRINTF(("activateWindow %x\n",win));
-            ShowWindowAsync(win, SW_SHOW | SW_SHOWNORMAL);
+	    ShowWindowAsync(win, SW_SHOW | SW_SHOWNORMAL);
 	    //ShowWindow(win, SW_SHOW);
 	    //SetWindowPos(_thread_newWinHandle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW|/*SWP_NOACTIVATE|*/SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
 	    //enqEvent(0,win, WM_SHOWWINDOW, TRUE, 0, 0, 0, 0);
@@ -9502,7 +9753,7 @@
 	    SetWindowPos(win, (HWND)0,
 			 rec.left, rec.top,
 			 rec.right - rec.left, rec.bottom - rec.top,
-			 SWP_NOACTIVATE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	}
 	RETURN ( self );
     }
@@ -9532,7 +9783,7 @@
 	    SetWindowPos(win, (HWND)0,
 			 rec.left, rec.top,
 			 0, 0,
-			 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	}
 	RETURN ( self );
     }
@@ -9628,7 +9879,7 @@
 
 	if (hWnd) {
 	    CPRINTF(("raiseWindow %x\n",hWnd));
-	    SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER  |SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
+	    SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, /*SWP_NOOWNERZORDER  |*/SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOMOVE|SWP_NOSIZE);
 	}
 	RETURN ( self );
     }
@@ -9657,7 +9908,7 @@
 	    SetWindowPos(hWnd, (HWND)0,
 			 0, 0,
 			 rec.right - rec.left, rec.bottom - rec.top,
-			 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
+			 SWP_NOSENDCHANGING|SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER|SWP_NOOWNERZORDER);
 	}
 	RETURN ( self );
     }
@@ -9849,8 +10100,9 @@
 	HWND win = _HWNDVal(aWindowId);
 
 	if (win) {
+	    CPRINTF(("unmapWindow %x\n",win));
 	    ShowWindow(win, SW_HIDE);
-	    CPRINTF(("unmapWindow %x\n",win));
+	    CPRINTF(("unmapWindow1 %x\n",win));
 	    //enqEvent(win, WM_SHOWWINDOW, FALSE, 0, 0, 0, 0);
 	}
 	RETURN ( self );
@@ -9861,6 +10113,6 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.43 1998-08-17 09:55:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.44 1998-08-19 14:21:21 cg Exp $'
 ! !
 WinWorkstation initialize!