Robert Shearman <rob@codeweavers.com>
- Fix colours used for SS_*RECT, SS_*FRAME.
- Implement SS_CENTERIMAGE for static control.
Modified: trunk/reactos/lib/user32/controls/static.c

Modified: trunk/reactos/lib/user32/controls/static.c
--- trunk/reactos/lib/user32/controls/static.c	2005-01-04 00:10:50 UTC (rev 12772)
+++ trunk/reactos/lib/user32/controls/static.c	2005-01-04 01:49:08 UTC (rev 12773)
@@ -34,7 +34,7 @@
 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
 
-static COLORREF color_windowframe, color_background, color_window;
+static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
 
 /* offsets for GetWindowLong for static private information */
 #define HFONT_GWL_OFFSET    0
@@ -104,7 +104,7 @@
 
     if ((style & SS_TYPEMASK) != SS_ICON) return 0;
     prevIcon = (HICON)SetWindowLongA( hwnd, HICON_GWL_OFFSET, (LONG)hicon );
-    if (hicon)
+    if (hicon && !(style & SS_CENTERIMAGE))
     {
         ICONINFO info;
         BITMAP bm;
@@ -118,7 +118,7 @@
             return 0;
         }
         SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
-                        SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
+                      SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
     }
     return prevIcon;
 #else
@@ -131,7 +131,7 @@
     	return 0;
     }
     prevIcon = (HICON)SetWindowLongA( hwnd, HICON_GWL_OFFSET, (LONG)hicon );
-    if (hicon)
+    if (hicon && !(style & SS_CENTERIMAGE))
     {
         SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
@@ -153,14 +153,14 @@
     if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
     if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
 #ifdef __REACTOS__
-  OutputDebugStringA("huh? hBitmap!=0, but not bitmap\n");
+	OutputDebugStringA("huh? hBitmap!=0, but not bitmap\n");
 #else
 	ERR("huh? hBitmap!=0, but not bitmap\n");
 #endif
     	return 0;
     }
     hOldBitmap = (HBITMAP)SetWindowLongA( hwnd, HICON_GWL_OFFSET, (LONG)hBitmap );
-    if (hBitmap)
+    if (hBitmap && !(style & SS_CENTERIMAGE))
     {
         BITMAP bm;
         GetObjectW(hBitmap, sizeof(bm), &bm);
@@ -244,6 +244,13 @@
     }
 }
 
+static VOID STATIC_InitColours()
+{
+    color_3ddkshadow  = GetSysColor(COLOR_3DDKSHADOW);
+    color_3dshadow    = GetSysColor(COLOR_3DSHADOW);
+    color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
+}
+
 /***********************************************************************
  *           StaticWndProc_common
  */
@@ -266,10 +273,7 @@
 #endif
             return -1;
         }
-        /* initialise colours */
-        color_windowframe  = GetSysColor(COLOR_WINDOWFRAME);
-        color_background   = GetSysColor(COLOR_BACKGROUND);
-        color_window       = GetSysColor(COLOR_WINDOW);
+        STATIC_InitColours();
         break;
 
     case WM_NCDESTROY:
@@ -302,9 +306,7 @@
         break;
 
     case WM_SYSCOLORCHANGE:
-        color_windowframe  = GetSysColor(COLOR_WINDOWFRAME);
-        color_background   = GetSysColor(COLOR_BACKGROUND);
-        color_window       = GetSysColor(COLOR_WINDOW);
+        STATIC_InitColours();
         InvalidateRect(hwnd, NULL, TRUE);
         break;
 
@@ -328,7 +330,7 @@
 	    else
 		hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
             /* FIXME : should we also return the previous hIcon here ??? */
-            STATIC_SetIcon(hwnd, hIcon, style);
+            STATIC_SetIcon(hwnd, hIcon, full_style);
 	    break;
 	}
         case SS_BITMAP:
@@ -338,7 +340,7 @@
 		hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
 	    else
 		hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
-            STATIC_SetBitmap(hwnd, hBitmap, style);
+            STATIC_SetBitmap(hwnd, hBitmap, full_style);
 	    break;
 	}
 	case SS_LEFT:
@@ -414,10 +416,10 @@
     case STM_SETIMAGE:
         switch(wParam) {
 	case IMAGE_BITMAP:
-	    lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, style );
+	    lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
 	    break;
 	case IMAGE_ICON:
-	    lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, style );
+	    lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
 	    break;
 	default:
 #ifndef __REACTOS__
@@ -432,7 +434,7 @@
     case STM_SETICON16:
 #endif
     case STM_SETICON:
-        lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, style );
+        lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
         InvalidateRect( hwnd, NULL, TRUE );
         break;
 
@@ -519,6 +521,8 @@
 
     if (style & SS_NOPREFIX)
 	wFormat |= DT_NOPREFIX;
+    if (style & SS_CENTERIMAGE)
+	wFormat |= DT_VCENTER;
 
     if ((hFont = (HFONT)GetWindowLongA( hwnd, HFONT_GWL_OFFSET ))) SelectObject( hdc, hFont );
 
@@ -550,27 +554,27 @@
     switch (style & SS_TYPEMASK)
     {
     case SS_BLACKRECT:
-	hBrush = CreateSolidBrush(color_windowframe);
+	hBrush = CreateSolidBrush(color_3ddkshadow);
         FillRect( hdc, &rc, hBrush );
 	break;
     case SS_GRAYRECT:
-	hBrush = CreateSolidBrush(color_background);
+	hBrush = CreateSolidBrush(color_3dshadow);
         FillRect( hdc, &rc, hBrush );
 	break;
     case SS_WHITERECT:
-	hBrush = CreateSolidBrush(color_window);
+	hBrush = CreateSolidBrush(color_3dhighlight);
         FillRect( hdc, &rc, hBrush );
 	break;
     case SS_BLACKFRAME:
-	hBrush = CreateSolidBrush(color_windowframe);
+	hBrush = CreateSolidBrush(color_3ddkshadow);
         FrameRect( hdc, &rc, hBrush );
 	break;
     case SS_GRAYFRAME:
-	hBrush = CreateSolidBrush(color_background);
+	hBrush = CreateSolidBrush(color_3dshadow);
         FrameRect( hdc, &rc, hBrush );
 	break;
     case SS_WHITEFRAME:
-	hBrush = CreateSolidBrush(color_window);
+	hBrush = CreateSolidBrush(color_3dhighlight);
         FrameRect( hdc, &rc, hBrush );
 	break;
     default:
@@ -585,13 +589,38 @@
     RECT rc;
     HBRUSH hbrush;
     HICON hIcon;
+    INT x, y;
 
     GetClientRect( hwnd, &rc );
     hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
 				   (WPARAM)hdc, (LPARAM)hwnd );
     FillRect( hdc, &rc, hbrush );
-    if ((hIcon = (HICON)GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
-        DrawIcon( hdc, rc.left, rc.top, hIcon );
+    hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
+    if (style & SS_CENTERIMAGE)
+    {
+#ifndef __REACTOS__
+        CURSORICONINFO *info = hIcon ? (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)) : NULL;
+        x = (rc.right - rc.left)/2 - (info ? info->nWidth/2 : 0);
+        y = (rc.bottom - rc.top)/2 - (info ? info->nHeight/2 : 0);
+#else
+        ICONINFO info;
+        BITMAP bm;
+
+        if (!GetIconInfo(hIcon, &info))
+            return;
+        if (!GetObjectW(info.hbmColor, sizeof(BITMAP), &bm))
+            return;
+        x = (rc.right - rc.left)/2 - bm.bmWidth/2;
+        y = (rc.bottom - rc.top)/2 - bm.bmHeight/2;
+#endif
+    }
+    else
+    {
+        x = rc.left;
+        y = rc.top;
+    }
+    if (hIcon)
+        DrawIcon( hdc, x, y, hIcon );
 }
 
 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
@@ -606,12 +635,25 @@
     if ((hBitmap = (HBITMAP)GetWindowLongA( hwnd, HICON_GWL_OFFSET )))
     {
         BITMAP bm;
+        INT x, y;
 
         if(GetObjectType(hBitmap) != OBJ_BITMAP) return;
         if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
 	GetObjectW(hBitmap, sizeof(bm), &bm);
 	oldbitmap = SelectObject(hMemDC, hBitmap);
-	BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
+        if (style & SS_CENTERIMAGE)
+        {
+            RECT rcClient;
+            GetClientRect(hwnd, &rcClient);
+            x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
+            y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
+        }
+        else
+        {
+            x = 0;
+            y = 0;
+        }
+        BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
 	       SRCCOPY);
 	SelectObject(hMemDC, oldbitmap);
 	DeleteDC(hMemDC);