From cbfbf2a582186e6a6f5265a6599f25477ccc1490 Mon Sep 17 00:00:00 2001
From: Bill Medland <medbi01@accpac.com>
Date: Fri, 20 Jul 2001 18:36:49 +0000
Subject: [PATCH] Corrections to the Win95 and later frame drawing code.

---
 windows/nonclient.c | 137 ++++++++++++++++++++++++++++----------------
 1 file changed, 88 insertions(+), 49 deletions(-)

diff --git a/windows/nonclient.c b/windows/nonclient.c
index 709111c1160..287c6fb9153 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -66,6 +66,10 @@ static const BYTE lpGrayMask[] = { 0xAA, 0xA0,
     (((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,14 +150,28 @@ static void NC_AdjustRect( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
 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)
     {
@@ -200,9 +218,6 @@ NC_AdjustRectInner95 (LPRECT rect, DWORD style, DWORD exStyle)
     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 +1176,11 @@ static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame,
  *   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 +1206,63 @@ static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame,
 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_CXDLGFRAME);
+	height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYDLGFRAME);
+
+        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_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
-	height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
+        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 );
     }
-
-    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 );
 }
 
 
@@ -1329,7 +1371,10 @@ static void  NC_DrawCaption95(
     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 +1602,15 @@ static void  NC_DoNCPaint95(
 
     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;
@@ -1602,9 +1644,6 @@ static void  NC_DoNCPaint95(
     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 */
 
     if (wndPtr->dwStyle & WS_VSCROLL)
-- 
GitLab