WinWorkstation.st
changeset 2601 d97601d0098e
parent 2599 9c0749ee47ed
child 2602 2d8af0930e87
--- a/WinWorkstation.st	Wed Apr 28 15:51:51 1999 +0200
+++ b/WinWorkstation.st	Wed Apr 28 19:24:44 1999 +0200
@@ -146,13 +146,15 @@
 
 #define _GCDATA(o)           ((struct gcData *)(__MKCP(o)))
 
-#define __rootDC             (HDC)(__MKCP(__INST(rootDC)))
-
-#if 0
-# define ISCONNECTED         (__INST(rootDC) != nil)
-#else
-# define ISCONNECTED         1
-#endif
+#ifdef LATER
+  /* for multi-WIN display support, we need this as an instance var (as below)
+   * however, there are many more places, where a single static datum is
+   * used currently - therefore dont care for this - at least now.
+   */
+# define __rootDC             (HDC)(__MKCP(__INST(rootDC)))
+#endif
+
+#define ISCONNECTED         1
 
 struct gcData {
     HWND        hWnd;
@@ -419,11 +421,14 @@
 static UINT nextMultiClickTime;
 static int destroyWin;
 static int __modifiers;
-static HDC tmpDC;
+static HDC __tmpDC;
 static int __isWinNT;
 static int __logPixelSY;
 static struct gcData *lastGcData = 0;
 static int            lastGcOwnerThreadID = 0;
+#ifndef __rootDC
+ static HDC __rootDC;
+#endif
 
 /*
  * does not work, yet
@@ -648,6 +653,9 @@
 	      return BlackPixel;
 	}
     }
+#ifdef ALWAYSTRUECOLOR
+    return (color & 0xffffff);
+#else
     if (__depth < 15) {
 	return 0;
     } else {
@@ -662,6 +670,7 @@
 	}
 	return (color & 0xffffff);
     }
+#endif
 }
 
 static int
@@ -669,6 +678,13 @@
 {
     int ir,ig,ib,id;
 
+#ifdef ALWAYSTRUECOLOR
+    ir = (r >> 8) & 0xff;
+    ig = (g >> 8) & 0xff;
+    ib = (b >> 8) & 0xff;
+
+    id = RGB( ir, ig, ib);
+#else
     if (__depth < 15) {
 	id = 0;
     } else {
@@ -686,6 +702,7 @@
 	    id = RGB( ir, ig, ib);
 	}
     }
+#endif
     return id;
 }
 
@@ -828,7 +845,7 @@
 		gcData->_hDC = GetDCEx(gcData->hWnd,0,DCX_PARENTCLIP);
 	}
     } else if (gcData->hBitmap) {
-	gcData->_hDC = CreateCompatibleDC(tmpDC);
+	gcData->_hDC = CreateCompatibleDC(__tmpDC);
 	gcData->save_hBitmap = SelectObject(gcData->_hDC,gcData->hBitmap);
     }
     if (gcData->_hDC) {
@@ -1838,9 +1855,9 @@
 			    enqEvent(ENQ_AT_END, EnterWindowMask,hWnd, __WM_MOUSEENTER, 0, x, y, 0, modifiers);
 			currentPointerView = hWnd;
 		    }
-		    CPRINTF(("MouseMove %x\n",currentPointerView));
+		    DDPRINTF(("MouseMove %x\n", currentPointerView));
 		} else {
-		    CPRINTF(("MouseMove Capture %x\n",currentPointerView));
+		    CPRINTF(("MouseMove Capture %x\n", currentPointerView));
 		}
 		if (    (GetWindow_eventMask(currentPointerView) & PointerMotionMask)
 		     || (modifiers & (Button1Mask|Button2Mask|Button3Mask))
@@ -1958,6 +1975,7 @@
 		    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();
@@ -3739,61 +3757,6 @@
 
 !WinWorkstation class methodsFor:'queries'!
 
-getSystemMetrics:aSymbol
-    "get a system metrics value"
-
-%{  /* xxLIMITEDSTACK (WIN95 only) */
-    int info = 0;
-    int isBool = 0;
-    int arg;
-
-    if ((aSymbol == @symbol(swapButton))
-    || (aSymbol == @symbol(SM_SWAPBUTTON))) {
-	arg = SM_SWAPBUTTON;
-	isBool = 1;
-    } else if (aSymbol == @symbol(mouseButtons)) {
-	arg = SM_CMOUSEBUTTONS;
-    } else if ((aSymbol == @symbol(iconWidth)) || (aSymbol == @symbol(SM_CXICON))) {
-	arg = SM_CXICON;
-    } else if ((aSymbol == @symbol(iconHeight)) || (aSymbol == @symbol(SM_CYICON))) {
-	arg = SM_CYICON;
-    } else if ((aSymbol == @symbol(cursorWidth)) || (aSymbol == @symbol(SM_CXCURSOR))) {
-	arg = SM_CXCURSOR;
-    } else if ((aSymbol == @symbol(cursorHeight)) || (aSymbol == @symbol(SM_CYCURSOR))) {
-	arg = SM_CYCURSOR;
-    } else if ((aSymbol == @symbol(captionHeight)) || (aSymbol == @symbol(SM_CYCAPTION))) {
-	arg = SM_CYCAPTION;
-    } else if ((aSymbol == @symbol(resizeFrameWidth)) || (aSymbol == @symbol(SM_CXFRAME))) {
-	arg = SM_CXFRAME;
-    } else if ((aSymbol == @symbol(resizeFrameHeight)) || (aSymbol == @symbol(SM_CYFRAME))) {
-	arg = SM_CYFRAME;
-    } else if ((aSymbol == @symbol(borderFrameWidth)) || (aSymbol == @symbol(SM_CXBORDER))) {
-	arg = SM_CXBORDER;
-    } else if ((aSymbol == @symbol(borderFrameHeight)) || (aSymbol == @symbol(SM_CYBORDER))) {
-	arg = SM_CYBORDER;
-    } else if ((aSymbol == @symbol(fullScreenWindowWidth)) || (aSymbol == @symbol(SM_CXFULLSCREEN))) {
-	arg = SM_CXFULLSCREEN;
-    } else if ((aSymbol == @symbol(fullScreenWindowHeight)) || (aSymbol == @symbol(SM_CYFULLSCREEN))) {
-	arg = SM_CYFULLSCREEN;
-    } else if ((aSymbol == @symbol(vScrollbarWidth)) || (aSymbol == @symbol(SM_CXVSCROLL))) {
-	arg = SM_CXVSCROLL;
-    } else if ((aSymbol == @symbol(hScrollbarHeight)) || (aSymbol == @symbol(SM_CYHSCROLL))) {
-	arg = SM_CYHSCROLL;
-    } else if ((aSymbol == @symbol(vThumbHeight)) || (aSymbol == @symbol(SM_CYVTHUMB))) {
-	arg = SM_CYVTHUMB;
-    } else if ((aSymbol == @symbol(hThumbWidth)) || (aSymbol == @symbol(SM_CXHTHUMB))) {
-	arg = SM_CXHTHUMB;
-    } else {
-	RETURN (nil);
-    }
-    info = GetSystemMetrics(arg);
-    if (isBool) {
-	RETURN (info ? true : false);
-    }
-    RETURN (__MKSMALLINT(info));
-%}
-!
-
 platformName
     "ST-80 compatibility.
      Return a string describing the display systems platform."
@@ -3925,6 +3888,65 @@
     "
 !
 
+getSystemMetrics:aNumberOrSymbol
+    "get a system metrics value; the argument is a #define-like symbol
+     as described in the windows API;
+     However, to allow for future values to be retrieved, also allow an integer
+     which must be the define-value."
+
+%{  /* NOCONTEXT */
+    int info = 0;
+    int isBool = 0;
+    int arg;
+
+    if (__isSmallInteger(aNumberOrSymbol)) {
+	arg = __intVal(aNumberOrSymbol);
+    } else if ((aNumberOrSymbol == @symbol(swapButton)) || (aNumberOrSymbol == @symbol(SM_SWAPBUTTON))) {
+	arg = SM_SWAPBUTTON;
+	isBool = 1;
+    } else if ((aNumberOrSymbol == @symbol(mouseButtons)) || (aNumberOrSymbol == @symbol(SM_CMOUSEBUTTONS))) {
+	arg = SM_CMOUSEBUTTONS;
+    } else if ((aNumberOrSymbol == @symbol(iconWidth)) || (aNumberOrSymbol == @symbol(SM_CXICON))) {
+	arg = SM_CXICON;
+    } else if ((aNumberOrSymbol == @symbol(iconHeight)) || (aNumberOrSymbol == @symbol(SM_CYICON))) {
+	arg = SM_CYICON;
+    } else if ((aNumberOrSymbol == @symbol(cursorWidth)) || (aNumberOrSymbol == @symbol(SM_CXCURSOR))) {
+	arg = SM_CXCURSOR;
+    } else if ((aNumberOrSymbol == @symbol(cursorHeight)) || (aNumberOrSymbol == @symbol(SM_CYCURSOR))) {
+	arg = SM_CYCURSOR;
+    } else if ((aNumberOrSymbol == @symbol(captionHeight)) || (aNumberOrSymbol == @symbol(SM_CYCAPTION))) {
+	arg = SM_CYCAPTION;
+    } else if ((aNumberOrSymbol == @symbol(resizeFrameWidth)) || (aNumberOrSymbol == @symbol(SM_CXFRAME))) {
+	arg = SM_CXFRAME;
+    } else if ((aNumberOrSymbol == @symbol(resizeFrameHeight)) || (aNumberOrSymbol == @symbol(SM_CYFRAME))) {
+	arg = SM_CYFRAME;
+    } else if ((aNumberOrSymbol == @symbol(borderFrameWidth)) || (aNumberOrSymbol == @symbol(SM_CXBORDER))) {
+	arg = SM_CXBORDER;
+    } else if ((aNumberOrSymbol == @symbol(borderFrameHeight)) || (aNumberOrSymbol == @symbol(SM_CYBORDER))) {
+	arg = SM_CYBORDER;
+    } else if ((aNumberOrSymbol == @symbol(fullScreenWindowWidth)) || (aNumberOrSymbol == @symbol(SM_CXFULLSCREEN))) {
+	arg = SM_CXFULLSCREEN;
+    } else if ((aNumberOrSymbol == @symbol(fullScreenWindowHeight)) || (aNumberOrSymbol == @symbol(SM_CYFULLSCREEN))) {
+	arg = SM_CYFULLSCREEN;
+    } else if ((aNumberOrSymbol == @symbol(vScrollbarWidth)) || (aNumberOrSymbol == @symbol(SM_CXVSCROLL))) {
+	arg = SM_CXVSCROLL;
+    } else if ((aNumberOrSymbol == @symbol(hScrollbarHeight)) || (aNumberOrSymbol == @symbol(SM_CYHSCROLL))) {
+	arg = SM_CYHSCROLL;
+    } else if ((aNumberOrSymbol == @symbol(vThumbHeight)) || (aNumberOrSymbol == @symbol(SM_CYVTHUMB))) {
+	arg = SM_CYVTHUMB;
+    } else if ((aNumberOrSymbol == @symbol(hThumbWidth)) || (aNumberOrSymbol == @symbol(SM_CXHTHUMB))) {
+	arg = SM_CXHTHUMB;
+    } else {
+	RETURN (nil);
+    }
+    info = GetSystemMetrics(arg);
+    if (isBool) {
+	RETURN (info ? true : false);
+    }
+    RETURN (__MKSMALLINT(info));
+%}
+!
+
 primGetSystemColor:aKey
 %{  /* xxLIMITEDSTACK (WIN95 only) */
     int p;
@@ -4150,7 +4172,7 @@
     "return the height in pixels of any caption (title-bar) in
      standard topWindows."
 
-    ^ self class getSystemMetrics:#captionHeight
+    ^ self getSystemMetrics:#captionHeight
 !
 
 iconSizes
@@ -4158,8 +4180,8 @@
 
     |d w h|
 
-    w := self class getSystemMetrics:#iconWidth.
-    h := self class getSystemMetrics:#iconHeight.
+    w := self getSystemMetrics:#iconWidth.
+    h := self getSystemMetrics:#iconHeight.
 
     d := IdentityDictionary new.
     d at:#minWidth put:w.
@@ -4251,9 +4273,9 @@
      Normally, the same as extent, but may be smaller, in
      case some menu space is taken up by the window manager (windows)"
 
-    ^ (self class getSystemMetrics:#fullScreenWindowWidth)
+    ^ (self getSystemMetrics:#fullScreenWindowWidth)
       @
-      (self class getSystemMetrics:#fullScreenWindowHeight)
+      (self getSystemMetrics:#fullScreenWindowHeight)
 
     "
      Display usableExtent
@@ -4265,6 +4287,7 @@
 addMenuItemWithLabel:aString toWindowID:aWindowId
     "not yet finished"
 %{
+#ifdef NOT_YET_IMPLEMENTED
     if (__isExternalAddress(aWindowId)) {
 	HWND hWin = _HWNDVal(aWindowId);
 	HMENU hMenu;
@@ -4274,6 +4297,7 @@
         
 	}
     }
+#endif
 %}
 !
 
@@ -4321,31 +4345,27 @@
 
 %{  /* xxLIMITEDSTACK (WIN95 only) */
     HANDLE newBitmapHandle;
+
     /*printf("CreateBitmap Color\n");*/
-    if (__bothSmallInteger(w, h) && __isSmallInteger(d) && ISCONNECTED)
-    {
-	if (__intVal(d) == 1)
-	{
-	  newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL);
-	}
-	else
-	{
+    if (__bothSmallInteger(w, h) && __isSmallInteger(d) && ISCONNECTED) {
+	if (__intVal(d) == 1) {
+	    newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL);
+	} else {
 #if 0
-	  if (__intVal(d) != __depth)
-	  {
-	    printf("invalite depth\n");
-	    RETURN (nil);
-	  } 
-#endif
-	  newBitmapHandle = CreateCompatibleBitmap(__rootDC,__intVal(w), __intVal(h) );
-	}
-	if (newBitmapHandle)
-	{
+	    if (__intVal(d) != __depth) {
+		printf("invalid depth\n");
+		RETURN (nil);
+	    } 
+#endif
+	    newBitmapHandle = CreateCompatibleBitmap(__rootDC,__intVal(w), __intVal(h) );
+	}
+
+	if (newBitmapHandle) {
 #ifdef COUNT_BMP_RESOURCES
 	    __cnt_bitmap++;
-	   RES_BMP_PRINTF(("CreatePixmap %x %d\n",newBitmapHandle,__cnt_bitmap));
-#endif
-	  RETURN ( __MKOBJ(newBitmapHandle));
+	    RES_BMP_PRINTF(("CreatePixmap %x %d\n",newBitmapHandle,__cnt_bitmap));
+#endif
+	    RETURN ( __MKOBJ(newBitmapHandle));
 	}
 	DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle));
     }
@@ -5377,8 +5397,9 @@
     |padding bpl bplPadded srcOffs dstOffs
      src mask srcPadded maskPadded cW cH nB nR cursor |
 
-    cW := self class getSystemMetrics:#cursorWidth.
-    cH := self class getSystemMetrics:#cursorHeight.
+    cW := self getSystemMetrics:#cursorWidth.
+    cH := self getSystemMetrics:#cursorHeight.
+
     "/ ('cursorWidth ',cW printString,'cursorHeight ',cH printString) infoPrintCR.
     src := sourceBytes.
     mask := maskBytes.
@@ -6510,13 +6531,7 @@
 	w = __intVal(width);
 	h = __intVal(height);
 
-	/*DPRINTF(("fillRect %d/%d -> %d/%d\n", __intVal(x), __intVal(y), w, h));*/
-
-	/*
-	 * need this check here: some servers simply dump core with bad args
-	 */
-	if ((w >= 0) && (h >= 0))
-	{
+	if ((w >= 0) && (h >= 0)) {
 	    struct gcData *gcData = _GCDATA(aGCId);
 	    HDC hDC;
 	    HBRUSH hBrush;
@@ -6535,7 +6550,7 @@
 		rct.right = rct.left + w + 1;
 		rct.bottom = rct.top + h + 1;
 
-		DPRINTF(("fillRectangle:%d.%d -> %d.%d\n",rct.left,rct.top,rct.right,rct.bottom));
+		DDPRINTF(("fillRectangle:%d.%d -> %d.%d\n",rct.left,rct.top,rct.right,rct.bottom));
 		hSaveBrush = SelectObject(hDC, hBrush);
 		hSavePen = SelectObject(hDC, GetStockObject(NULL_PEN));
 
@@ -6766,22 +6781,30 @@
 
 activate:aBoolean view:aView
     "some view was activated/deactivated.
-     This is only used with systems, which use a concept of an active
-     view which gets keyboard focus (as opposed to X, where the pointer view
-     gets the focus normally)"
+     For compatibility we send a focus-event to that topView"
 
     aBoolean ifFalse:[
-        activeView := nil.
-        self focusOutView:aView.
+	activeView := nil.
+	self focusOutView:aView.
     ] ifTrue:[
-        activeView := aView.
-        self focusInView:aView.
+	activeView := aView.
+	self focusInView:aView.
     ].
 
     "Created: / 28.4.1999 / 14:51:51 / cg"
     "Modified: / 28.4.1999 / 15:07:09 / cg"
 !
 
+displayChange
+    "the display metrics/settings have changed.
+     This is a speciality of windows.
+     TODO: Tell the viewStyle to update itself,
+	   and tell all views to reinit their style.
+     For now,this is ignored, except for updating my metrics."
+
+    self initializeVariableScreenProperties.
+!
+
 fontChange
     "the system fonts (users preferences) have changed.
      This is a speciality of windows.
@@ -7544,6 +7567,11 @@
 		(*fontChg.ilc_func)(self, @symbol(fontChange), nil, &fontChg);
 		break;
 
+	   case WM_DISPLAYCHANGE:
+		DPRINTF((">>> WM_DISPLAYCHANGE\n"));
+		(*fontChg.ilc_func)(self, @symbol(displayChange), nil, &fontChg);
+		break;
+
 	   case WM_QUERYENDSESSION:
 		DPRINTF((">>> WM_QUERYENDSESSION\n"));
 		(*qEndSess.ilc_func)(self, @symbol(queryEndSession), nil, &qEndSess);
@@ -8326,9 +8354,8 @@
 
 primEnumFontTypesInto:typeFaceList
 %{      /* xxLIMITEDSTACK (WIN95) */
-	if (tmpDC)
-	{
-	    if ( EnumFontFamilies( tmpDC, NULL, EnumFPTypeFaceProc, (DWORD)&(typeFaceList))) {
+	if (__tmpDC) {
+	    if ( EnumFontFamilies( __tmpDC, NULL, EnumFPTypeFaceProc, (DWORD)&(typeFaceList))) {
 		DPRINTF(("EnumFonts successful\n"));
 	    }
 	}
@@ -8339,10 +8366,9 @@
 %{      /* xxLIMITEDSTACK (WIN95) */
 	char *cp;
 
-	if (__isString(typeFace))
-	{
-	    if (tmpDC) {
-		if (EnumFontFamilies(tmpDC, __stringVal(typeFace), EnumFontsProc, (DWORD)&(fontList))) {
+	if (__isString(typeFace)) {
+	    if (__tmpDC) {
+		if (EnumFontFamilies(__tmpDC, __stringVal(typeFace), EnumFontsProc, (DWORD)&(fontList))) {
 		    DPRINTF(("EnumFonts Successful\n"));
 		}
 	    }
@@ -8355,8 +8381,7 @@
 
 %{  /* xxLIMITEDSTACK (WIN95 only) */
 
-    if (__isExternalAddress(fontId))
-    {
+    if (__isExternalAddress(fontId)) {
 	SIZE size;
 	int avgWidth;
 	HGDIOBJ hFont;
@@ -8367,11 +8392,11 @@
 	/*
 	 * temporarily set this font in the root context
 	 */
-	prevFont = SelectObject(tmpDC, hFont);
-	GetTextMetrics(tmpDC, &tmet);
-	GetTextExtentPoint32(tmpDC,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst"
+	prevFont = SelectObject(__tmpDC, hFont);
+	GetTextMetrics(__tmpDC, &tmet);
+	GetTextExtentPoint32(__tmpDC,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst"
 	 "uvwxyz",52,&size);
-	SelectObject(tmpDC, prevFont);
+	SelectObject(__tmpDC, prevFont);
 	avgWidth = (size.cx/26+1)/2;
 
 	__ArrayInstPtr(data)->a_element[0] = __MKSMALLINT(tmet.tmAscent);
@@ -8438,71 +8463,69 @@
     OBJ cls;
     int nInstBytes;
 
-	if (__bothSmallInteger(index1, index2)
-	 && __isExternalAddress(aFontId)
-	 && __isNonNilObject(aString)) {
-	    HGDIOBJ hFont,prevFont;
-	    SIZE tsize;
-
-	    hFont = _HGDIOBJVal(aFontId);
-
-	    i1 = __intVal(index1) - 1;
-	    cls = __qClass(aString);
-
-	    if (i1 >= 0) {
-		i2 = __intVal(index2) - 1;
-		if (i2 < i1) {
-		    RETURN ( __MKSMALLINT( 0 ) );
+    if (__bothSmallInteger(index1, index2)
+     && __isExternalAddress(aFontId)
+     && __isNonNilObject(aString)) {
+	HGDIOBJ hFont,prevFont;
+	SIZE tsize;
+
+	hFont = _HGDIOBJVal(aFontId);
+
+	i1 = __intVal(index1) - 1;
+	cls = __qClass(aString);
+
+	if (i1 >= 0) {
+	    i2 = __intVal(index2) - 1;
+	    if (i2 < i1) {
+		RETURN ( __MKSMALLINT( 0 ) );
+	    }
+
+	    cp = (char *) _stringVal(aString);
+	    l = i2 - i1 + 1;
+
+	    if ((cls == @global(String)) || (cls == @global(Symbol))) {
+		n = _stringSize(aString);
+		if (i2 < n) {
+		    cp += i1;
+
+		    prevFont = SelectObject(__tmpDC, hFont);
+		    GetTextExtentPoint32(__tmpDC, cp, l, &tsize);
+#ifdef SUPERDEBUG
+		    if (__debug__) {
+		      char buf[80];
+
+		      GetTextFace(__tmpDC,80,buf);
+		      printf("font1 %x %s >%s< l=%d dx=%d\n",hFont,buf,cp,l,tsize.cx);
+		    }
+#endif
+		    SelectObject(__tmpDC, prevFont);
+		    RETURN ( __MKSMALLINT(tsize.cx) );
 		}
-
-		cp = (char *) _stringVal(aString);
-		l = i2 - i1 + 1;
-
-		if ((cls == @global(String)) || (cls == @global(Symbol))) {
-		    n = _stringSize(aString);
-		    if (i2 < n)
-		    {
-			cp += i1;
-
-			prevFont = SelectObject(tmpDC, hFont);
-			GetTextExtentPoint32(tmpDC, cp, l, &tsize);
-#ifdef xxDEBUG
-			if (__debug__)
-			{
-			  char buf[80];
-			  GetTextFace(tmpDC,80,buf);
-			  printf("font1 %x %s >%s< l=%d dx=%d\n",hFont,buf,cp,l,tsize.cx);
-			}
-#endif
-			SelectObject(tmpDC, prevFont);
-			RETURN ( __MKSMALLINT(tsize.cx) );
+	    }
+
+	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	    cp += nInstBytes;
+
+	    if (__isBytes(aString)) {
+		n = __byteArraySize(aString) - nInstBytes;
+		if (i2 < n) {
+		    cp += i1;
+
+		    prevFont = SelectObject(__tmpDC, hFont);
+		    GetTextExtentPoint32(__tmpDC, cp, l, &tsize);
+#ifdef SUPERDEBUG
+		    if (__debug__) {
+		      char buf[80];
+
+		      GetTextFace(__tmpDC,80,buf);
+		      printf("font1 %x %s >%s< l=%d dx=%d\n",hFont,buf,cp,l,tsize.cx);
 		    }
+#endif
+		    SelectObject(__tmpDC, prevFont);
+		    RETURN ( __MKSMALLINT(tsize.cx) );
 		}
-
-		nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		cp += nInstBytes;
-
-		if (__isBytes(aString)) {
-		    n = __byteArraySize(aString) - nInstBytes;
-		    if (i2 < n)
-		    {
-			cp += i1;
-
-			prevFont = SelectObject(tmpDC, hFont);
-			GetTextExtentPoint32(tmpDC, cp, l, &tsize);
-#ifdef xxDEBUG
-			if (__debug__)
-			{
-			  char buf[80];
-			  GetTextFace(tmpDC,80,buf);
-			  printf("font1 %x %s >%s< l=%d dx=%d\n",hFont,buf,cp,l,tsize.cx);
-			}
-#endif
-			SelectObject(tmpDC, prevFont);
-			RETURN ( __MKSMALLINT(tsize.cx) );
-		    }
-		}
-	    }
+	    }
+	}
     }
 #undef NLOCALBUFFER
 %}.
@@ -8630,7 +8653,7 @@
 #endif
 	}
 
-	DPRINTF(("setBackground: %x\n", bgColor));
+	DDPRINTF(("setBackground: %x\n", bgColor));
 	RETURN (self);
     }
 %}
@@ -9086,7 +9109,7 @@
     focusMode := #activeWindow.
 
     buttonTranslation := ButtonTranslation.
-    multiClickTimeDelta := MultiClickTimeDelta.
+"/    multiClickTimeDelta := MultiClickTimeDelta.  "/ ignored - defined by preference-panel
 
     self initializeModifierMappings
 !
@@ -9149,15 +9172,14 @@
     int scr;
     int maxRGBDepth;
     int rgbRedMask, rgbGreenMask, rgbBlueMask;
-    int nvi, i, val, capabilities,__planes,__numcolors,__numpens,__ras;
+    int nvi, i;
     char *type, *nm;
     int dummy;
     int mask, shift, nBits;
-    RECT rect;
     HDC _rootDC;
     OBJ id;
-    if (firstInstance)
-    {
+
+    if (firstInstance) {
 	OSVERSIONINFO osvi;
 	WNDCLASS wc;
 	firstInstance = 0;
@@ -9289,12 +9311,10 @@
 			    hCreateEvent,   /* handle of mutex */
 			    5000L);         /* time-out interval */
 	    if (dwWaitResult != WAIT_OBJECT_0) {
-		fprintf(stderr, "WinWorkstation: oops timeout waiting for eventThread to start\n");
-	    }
-	}
-    }
-    multiClickTime = GetDoubleClickTime();
-    DPRINTF(("multiClickTime = %d\n",multiClickTime));
+		fprintf(stderr, "WinWorkstation [error]: oops timeout waiting for eventThread to start\n");
+	    }
+	}
+    }
 
 #if 0
     __rootDesk = OpenDesktop ("Desktop0", 0, FALSE, GENERIC_ALL);
@@ -9312,103 +9332,135 @@
     __UNPROTECT__(self);
     __INST(rootWin) = id; __STORE(self, id);
 
-    _rootDC = CreateDC("DISPLAY", NULL, NULL, NULL);
-
-    tmpDC = CreateCompatibleDC(_rootDC);
+    _rootDC = __rootDC = CreateDC("DISPLAY", NULL, NULL, NULL);
+
+    __tmpDC = CreateCompatibleDC(_rootDC);
 
     __PROTECT__(self);
     id = __MKOBJ(_rootDC);
     __UNPROTECT__(self);
     __INST(rootDC) = id; __STORE(self, id);
+%}.
+    self initializeVariableScreenProperties.
+!
+
+initializeVariableScreenProperties
+    "fetch properties which can be changed via the user settings.
+     Invoked initially and as a result of the displayChange event."
+
+%{
+    int nvi, i, val, capabilities, planes, numcolors, numpens, realDepth;
+    RECT rect;
+
+    multiClickTime = GetDoubleClickTime();
+    DPRINTF(("multiClickTime = %d\n",multiClickTime));
+    __INST(multiClickTimeDelta) = __MKSMALLINT(multiClickTime);
 
     GetWindowRect(__rootWin, &rect);
-    __INST(width) = __MKSMALLINT(rect.right-rect.left);
-    __INST(height) = __MKSMALLINT(rect.bottom-rect.top);
+    __INST(width) = __MKSMALLINT(rect.right - rect.left);
+    __INST(height) = __MKSMALLINT(rect.bottom - rect.top);
     DPRINTF(("screen is %d/%d\n", __intVal(__INST(width)), __intVal(__INST(height))));
 
-    __planes = GetDeviceCaps(_rootDC, PLANES);
-
-#ifndef ALWAYSTRUECOLOR
-    __depth = GetDeviceCaps(_rootDC, BITSPIXEL);
+    realDepth = GetDeviceCaps(__rootDC, BITSPIXEL);
+
+#ifdef ALWAYSTRUECOLOR
+    __depth = 24;  /* its a hack */
+#else
+    __depth = realDepth;
     if (__depth == 15)
 	__depth = 16;
-#else
-    __depth = 24;  /* its a hack */
 #endif
 
 #if 0
-    __numcolors = GetDeviceCaps(_rootDC, NUMCOLORS);
-    __numpens = GetDeviceCaps(_rootDC, NUMPENS);
-    DPRINTF(("screen has %d planes\n",__planes));
-    DPRINTF(("numcolors is %d\n",__numcolors));
-    DPRINTF(("numpens is %d\n",__numpens));
-#endif
-
-    __ras = GetDeviceCaps(_rootDC, RASTERCAPS);
-
-#if 0
-    printf("device support:\n");
-    if (__ras & RC_BANDING)
-	printf(" RC_BANDING");
-
-    if (__ras & RC_BITBLT)
-	printf(" RC_BITBLT");
-
-    if (__ras & RC_BITMAP64)
-	printf(" RC_BITMAP64");
-
-    if (__ras & RC_DI_BITMAP)
-	printf(" RC_DI_BITMAP");
-
-    if (__ras & RC_DIBTODEV)
-	printf(" RC_DIBTODEV");
-
-    if (__ras & RC_FLOODFILL)
-	printf(" RC_FLOODFILL");
-
-    if (__ras & RC_PALETTE)
-	printf(" RC_PALETTE");
-
-    if (__ras & RC_SCALING)
-	printf(" RC_SCALING");
-
-    if (__ras & RC_STRETCHBLT)
-	printf(" RC_STRETCHBLT");
-
-    if (__ras & RC_STRETCHDIB)
-	printf(" RC_STRETCHDIB");
-    printf("\n");
-    printf("cursor size %d %d\n",GetSystemMetrics(SM_CXCURSOR),GetSystemMetrics(SM_CYCURSOR));
-
+    numcolors = GetDeviceCaps(__rootDC, NUMCOLORS);
+    numpens = GetDeviceCaps(__rootDC, NUMPENS);
+    planes = GetDeviceCaps(__rootDC, PLANES);
+
+    DPRINTF(("screen has %d planes\n", planes));
+    DPRINTF(("numcolors is %d\n", numcolors));
+    DPRINTF(("numpens is %d\n", numpens));
 #endif
 
     __INST(depth) = __MKSMALLINT(__depth);
     __INST(ncells) = __MKSMALLINT(1<<__depth);
 
-
-    val = GetDeviceCaps(_rootDC, HORZSIZE);
+    val = GetDeviceCaps(__rootDC, HORZSIZE);
     DPRINTF(("HORSIZE=%d\n",val));
     __INST(widthMM) = __MKSMALLINT(val);
-    val = GetDeviceCaps(_rootDC, VERTSIZE);
+    val = GetDeviceCaps(__rootDC, VERTSIZE);
     DPRINTF(("VERTSIZE=%d\n",val));
     __INST(heightMM) = __MKSMALLINT(val);
 
-
-    __logPixelSY = GetDeviceCaps(_rootDC, LOGPIXELSY);
-    capabilities = GetDeviceCaps(_rootDC, RASTERCAPS);
+    __logPixelSY = GetDeviceCaps(__rootDC, LOGPIXELSY);
+    capabilities = GetDeviceCaps(__rootDC, RASTERCAPS);
+
+#ifdef LATER
+    printf("device support:\n");
+    if (capabilities & RC_BANDING)
+	printf(" RC_BANDING");
+
+    if (capabilities & RC_BITBLT)
+	printf(" RC_BITBLT");
+
+    if (capabilities & RC_BITMAP64)
+	printf(" RC_BITMAP64");
+
+    if (capabilities & RC_DI_BITMAP)
+	printf(" RC_DI_BITMAP");
+
+    if (capabilities & RC_DIBTODEV)
+	printf(" RC_DIBTODEV");
+
+    if (capabilities & RC_FLOODFILL)
+	printf(" RC_FLOODFILL");
+
+    if (capabilities & RC_PALETTE)
+	printf(" RC_PALETTE");
+
+    if (capabilities & RC_SCALING)
+	printf(" RC_SCALING");
+
+    if (capabilities & RC_STRETCHBLT)
+	printf(" RC_STRETCHBLT");
+
+    if (capabilities & RC_STRETCHDIB)
+	printf(" RC_STRETCHDIB");
+
+    printf("\n");
+    printf("cursor size %d %d\n", GetSystemMetrics(SM_CXCURSOR), GetSystemMetrics(SM_CYCURSOR));
+#endif
 
     __INST(whitepixel) = __MKSMALLINT(WhitePixel);
     __INST(blackpixel) = __MKSMALLINT(BlackPixel);
 
-#ifndef ALWAYSTRUECOLOR
-    if (! (capabilities & RC_PALETTE))
-#endif
-    {
+    __INST(monitorType) = @symbol(unknown);
+
+#ifdef ALWAYSTRUECOLOR
+    __INST(hasColors) = true;
+    __INST(hasGreyscales) = true;
+    __INST(visualType) = @symbol(TrueColor);
+    __INST(redShift) = __MKSMALLINT(0);
+    __INST(greenShift) = __MKSMALLINT(8);
+    __INST(blueShift) = __MKSMALLINT(16);
+    switch (realDepth) {
+	case 15:
+	case 16:
+	    __INST(bitsPerRGB) = __MKSMALLINT(5);
+	    break;
+	default:
+	    __INST(bitsPerRGB) = __MKSMALLINT(8);
+    }
+    __INST(bitsRed) = __INST(bitsGreen) = __INST(bitsBlue) = __MKSMALLINT(8);
+    __INST(redMask) = __MKSMALLINT(0xFF);
+    __INST(greenMask) = __MKSMALLINT(0xFF00);
+    __INST(blueMask) = __MKSMALLINT(0xFF0000);
+#else
+    if (! (capabilities & RC_PALETTE)) {
 	DPRINTF(("no palette\n"));
 	if (__depth == 1) {
-	    __INST(visualType) = @symbol(GrayScale);
 	    __INST(hasColors) = false;
 	    __INST(hasGreyscales) = false;
+	    __INST(visualType) = @symbol(GrayScale);
 	    __INST(monitorType) = @symbol(monochrome);
 	} else {
 	    __INST(hasColors) = true;
@@ -9435,11 +9487,8 @@
 	      __INST(blueMask) = __MKSMALLINT(0xFF0000);
 	    }
 	}
-    }
-
-#ifndef ALWAYSTRUECOLOR
-    else {
-	val = GetDeviceCaps(_rootDC, SIZEPALETTE); /* First two entries are black and white. */
+    } else {
+	val = GetDeviceCaps(__rootDC, SIZEPALETTE); /* First two entries are black and white. */
 	// printf("SizeofPalette %d\n",val);
 	__INST(ncells) = __MKSMALLINT(val);
 	__INST(blackpixel) = __MKSMALLINT(0);
@@ -9457,9 +9506,8 @@
 	__INST(greenMask) = __MKSMALLINT(0xc); 
 	__INST(blueMask) = __MKSMALLINT(0x30);
     }
-#endif
-    __INST(monitorType) = @symbol(unknown);
-%}.
+#endif /* ! ALWAYSTRUECOLOR */
+%}
 !
 
 initializeSpecialFlags
@@ -9905,21 +9953,25 @@
 
 	    bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 	    bitmap.bmiHeader.biPlanes = 1;
+#ifdef ALWAYSTRUECOLOR
+	    bitmap.bmiHeader.biCompression = BI_RGB;
+#else
 	    if (__depth == 24) {
 		bitmap.bmiHeader.biCompression = BI_RGB;
 	    } else if (__depth == 16) {
-#if 0
+# if 0
 		bitmap.bmiHeader.biCompression = BI_BITFIELDS;
 		bitmap.b = 0x001f;
 		bitmap.g = 0x07e0;
 		bitmap.r = 0xf800;
-#else
+# else
 		bitmap.b = 0;
 		bitmap.g = 0;
 		bitmap.r = 0;
 		bitmap.bmiHeader.biCompression = BI_RGB;
-#endif
-	    }
+# endif
+	    }
+#endif /* ALWAYSTRUECOLOR */
 	    bitmap.bmiHeader.biSizeImage = 0;
 	    bitmap.bmiHeader.biXPelsPerMeter = 0;
 	    bitmap.bmiHeader.biYPelsPerMeter = 0;
@@ -10062,23 +10114,27 @@
 	    }
 	    bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 	    bitmap.bmiHeader.biPlanes = 1;
-	    if (__depth == 24)
-	    {
+#ifdef ALWAYSTRUECOLOR
+	    bitmap.bmiHeader.biCompression = BI_RGB;
+#else
+	    if (__depth == 24) {
 		/*bitmap.bmiHeader.biCompression = BI_BITFIELDS;
 		bitmap.r = 0xff0000;
 		bitmap.g = 0x00ff00;
 		bitmap.b = 0x0000ff;*/
 		bitmap.bmiHeader.biCompression = BI_RGB;
-	    }
-	    else if (__depth == 16)
-	    {
+	    } else if (__depth == 16) {
 		/*bitmap.bmiHeader.biCompression = BI_RGB;
 		bitmap.bmiHeader.biCompression = BI_BITFIELDS;
 		bitmap.b = 0x001f;
 		bitmap.g = 0x07e0;
 		bitmap.r = 0xf800;*/
 		bitmap.bmiHeader.biCompression = BI_RGB;
-	    }
+	    } else {
+		DPRINTF(("primGetBitsFromPixmap: unsupported depth\n"));
+		got fail;
+	    }
+#endif /* ALWAYSTRUECOLOR */
 	    bitmap.bmiHeader.biSizeImage = 0;
 	    bitmap.bmiHeader.biXPelsPerMeter = 0;
 	    bitmap.bmiHeader.biYPelsPerMeter = 0;
@@ -10096,8 +10152,7 @@
 	    }
 	    DPRINTF(("bitmap info:%d %d %d %d\n",bitmap.bmiHeader.biWidth,bitmap.bmiHeader.biHeight,bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biSizeImage));
 	    numBytes = bitmap.bmiHeader.biSizeImage;
-	    if( numBytes != 0 )
-	    {
+	    if ( numBytes != 0 ) {
 		if (numBytes > __byteArraySize(imageBits)) {
 		    /* imageBits too small */
 		    DPRINTF(("provided byteArray too small\n"));
@@ -10114,9 +10169,7 @@
 		    DPRINTF(("zero bits returned\n"));
 		    goto fail;
 		}
-	    }
-	    else
-	    {
+	    } else {
 		DPRINTF(("unacceptable bitmap\n"));
 		goto fail;
 	    }
@@ -10884,6 +10937,6 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.97 1999-04-28 13:23:12 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.98 1999-04-28 17:24:44 cg Exp $'
 ! !
 WinWorkstation initialize!