Win95 frame drawing code

Medland, Bill Bill.Medland at accpac.com
Fri Jul 6 17:44:01 CDT 2001


 <<diff.txt>> 
-------------- next part --------------
Bill Medland (medbi01 at accpac.com)
Corrections to the Win95 and later frame drawing code.  These corrections have
been tested against a Win95 computer by creating 50x70 pixel windows in a
variety of styles (all WS_CHILD | WS_VISIBLE).  All combinations of the 
following have been tested:
    WS_BORDER, WS_DLGFRAME, WS_THICKFRAME,
    WS_DLGMODALFRAME, WS_EX_STATICEDGE, WS_EXCLIENTEDGE, WS_WINDOWEDGE

Index: wine/windows/nonclient.c
===================================================================
RCS file: /home/wine/wine/windows/nonclient.c,v
retrieving revision 1.78
diff -u -r1.78 nonclient.c
--- wine/windows/nonclient.c	2001/06/14 19:24:02	1.78
+++ wine/windows/nonclient.c	2001/07/06 22:12:49
@@ -66,6 +66,10 @@
     (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
      ((exStyle) & WS_EX_DLGMODALFRAME))
 
+#define HAS_STATICOUTERFRAME(style,exStyle) \
+    (((exStyle) & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) == \
+     WS_EX_STATICEDGE)
+
 #define HAS_ANYFRAME(style,exStyle) \
     (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
      ((exStyle) & WS_EX_DLGMODALFRAME) || \
@@ -146,15 +150,29 @@
 static void
 NC_AdjustRectOuter95 (LPRECT rect, DWORD style, BOOL menu, DWORD exStyle)
 {
+    int adjust;
     if(style & WS_ICONIC) return;
 
-    if (HAS_THICKFRAME( style, exStyle ))
-        InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
-    else if (HAS_DLGFRAME( style, exStyle ))
-        InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
-    else if (HAS_THINFRAME( style ))
-        InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
+    if ((exStyle & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) == 
+        WS_EX_STATICEDGE)
+    {
+        adjust = 1; /* for the outer frame always present */
+    }
+    else
+    {
+        adjust = 0;
+        if ((exStyle & WS_EX_DLGMODALFRAME) ||
+            (style & (WS_THICKFRAME|WS_DLGFRAME))) adjust = 2; /* outer */
+    }
+    if (style & WS_THICKFRAME)
+        adjust +=  ( GetSystemMetrics (SM_CXFRAME)
+                   - GetSystemMetrics (SM_CXDLGFRAME)); /* The resize border */
+    if ((style & (WS_BORDER|WS_DLGFRAME)) || 
+        (exStyle & WS_EX_DLGMODALFRAME))
+        adjust++; /* The other border */
 
+    InflateRect (rect, adjust, adjust);
+
     if ((style & WS_CAPTION) == WS_CAPTION)
     {
         if (exStyle & WS_EX_TOOLWINDOW)
@@ -200,11 +218,9 @@
     if (exStyle & WS_EX_CLIENTEDGE)
         InflateRect(rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
 
-    if (exStyle & WS_EX_STATICEDGE)
-        InflateRect(rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
-
     if (style & WS_VSCROLL) rect->right  += GetSystemMetrics(SM_CXVSCROLL);
     if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
+
 }
 
 
@@ -1161,11 +1177,11 @@
  *   void  NC_DrawFrame95(
  *      HDC  hdc,
  *      RECT  *rect,
- *      BOOL  dlgFrame,
- *      BOOL  active )
+ *      BOOL  active,
+ *      DWORD style,
+ *      DWORD exStyle )
  *
  *   Draw a window frame inside the given rectangle, and update the rectangle.
- *   The correct pen for the frame must be selected in the DC.
  *
  *   Bugs
  *        Many.  First, just what IS a frame in Win95?  Note that the 3D look
@@ -1191,36 +1207,63 @@
 static void  NC_DrawFrame95(
     HDC  hdc,
     RECT  *rect,
-    BOOL  dlgFrame,
-    BOOL  active )
+    BOOL  active,
+    DWORD style,
+    DWORD exStyle)
 {
     INT width, height;
 
-    if (dlgFrame)
+    /* Firstly the "thick" frame */
+    if (style & WS_THICKFRAME)
     {
-	width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
-	height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
-    }
-    else
-    {
-	width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
-	height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
-    }
-
-    SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
-		COLOR_INACTIVEBORDER) );
+	width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME);
+	height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYDLGFRAME);
 
-    /* Draw frame */
-    PatBlt( hdc, rect->left, rect->top,
-              rect->right - rect->left, height, PATCOPY );
-    PatBlt( hdc, rect->left, rect->top,
-              width, rect->bottom - rect->top, PATCOPY );
-    PatBlt( hdc, rect->left, rect->bottom - 1,
-              rect->right - rect->left, -height, PATCOPY );
-    PatBlt( hdc, rect->right - 1, rect->top,
-              -width, rect->bottom - rect->top, PATCOPY );
+        SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
+		      COLOR_INACTIVEBORDER) );
+        /* Draw frame */
+        PatBlt( hdc, rect->left, rect->top,
+                  rect->right - rect->left, height, PATCOPY );
+        PatBlt( hdc, rect->left, rect->top,
+                  width, rect->bottom - rect->top, PATCOPY );
+        PatBlt( hdc, rect->left, rect->bottom - 1,
+                  rect->right - rect->left, -height, PATCOPY );
+        PatBlt( hdc, rect->right - 1, rect->top,
+                  -width, rect->bottom - rect->top, PATCOPY );
+
+        InflateRect( rect, -width, -height );
+    }
+
+    /* Now the other bit of the frame */
+    if ((style & (WS_BORDER|WS_DLGFRAME)) ||
+        (exStyle & WS_EX_DLGMODALFRAME))
+    {
+        width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
+        height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
+        /* This should give a value of 1 that should also work for a border */
+
+        SelectObject( hdc, GetSysColorBrush(
+                      (exStyle & (WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE)) ?
+                          COLOR_3DFACE :
+                      (exStyle & WS_EX_STATICEDGE) ?
+                          COLOR_WINDOWFRAME :
+                      (style & (WS_DLGFRAME|WS_THICKFRAME)) ?
+                          COLOR_3DFACE :
+                      /* else */
+                          COLOR_WINDOWFRAME));
+
+        /* Draw frame */
+        PatBlt( hdc, rect->left, rect->top,
+                  rect->right - rect->left, height, PATCOPY );
+        PatBlt( hdc, rect->left, rect->top,
+                  width, rect->bottom - rect->top, PATCOPY );
+        PatBlt( hdc, rect->left, rect->bottom - 1,
+                  rect->right - rect->left, -height, PATCOPY );
+        PatBlt( hdc, rect->right - 1, rect->top,
+                  -width, rect->bottom - rect->top, PATCOPY );
 
-    InflateRect( rect, -width, -height );
+        InflateRect( rect, -width, -height );
+    }
 }
 
 
@@ -1329,7 +1372,10 @@
     HPEN  hPrevPen;
     HMENU hSysMenu;
 
-    hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) );
+    hPrevPen = SelectObject( hdc, GetSysColorPen(
+                     ((exStyle & (WS_EX_STATICEDGE|WS_EX_CLIENTEDGE|
+                                 WS_EX_DLGMODALFRAME)) == WS_EX_STATICEDGE) ?
+                      COLOR_WINDOWFRAME : COLOR_3DFACE) );
     MoveToEx( hdc, r.left, r.bottom - 1, NULL );
     LineTo( hdc, r.right, r.bottom - 1 );
     SelectObject( hdc, hPrevPen );
@@ -1557,18 +1603,15 @@
 
     SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
 
-    if (HAS_BIGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle)) {
-        DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
+    if (HAS_STATICOUTERFRAME(wndPtr->dwStyle, wndPtr->dwExStyle)) {
+        DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
     }
-    if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
-        NC_DrawFrame95(hdc, &rect, FALSE, active );
-    else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
-        NC_DrawFrame95( hdc, &rect, TRUE, active );
-    else if (HAS_THINFRAME( wndPtr->dwStyle )) {
-        SelectObject( hdc, GetStockObject(NULL_BRUSH) );
-        Rectangle( hdc, 0, 0, rect.right, rect.bottom );
+    else if (HAS_BIGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle)) {
+        DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
     }
 
+    NC_DrawFrame95(hdc, &rect, active, wndPtr->dwStyle, wndPtr->dwExStyle );
+
     if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
     {
         RECT  r = rect;
@@ -1601,9 +1644,6 @@
 
     if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE)
 	DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
-
-    if (wndPtr->dwExStyle & WS_EX_STATICEDGE)
-	DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
 
     /* Draw the scroll-bars */
 


More information about the wine-patches mailing list