user32: Static controls should have a clipping region set while sending the WM_CTLCOLORSTATIC.
This commit is contained in:
parent
c9a0da51a5
commit
613cfc2870
|
@ -111,6 +111,33 @@ const struct builtin_class_descr STATIC_builtin_class =
|
|||
0 /* brush */
|
||||
};
|
||||
|
||||
static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
|
||||
{
|
||||
RECT rc;
|
||||
HRGN hrgn;
|
||||
|
||||
/* Native control has always a clipping region set (this may be because
|
||||
* builtin controls uses CS_PARENTDC) and an application depends on it
|
||||
*/
|
||||
hrgn = CreateRectRgn(0, 0, 1, 1);
|
||||
if (GetClipRgn(hdc, hrgn) != 1)
|
||||
{
|
||||
DeleteObject(hrgn);
|
||||
*orig = NULL;
|
||||
} else
|
||||
*orig = hrgn;
|
||||
|
||||
GetClientRect(hwnd, &rc);
|
||||
DPtoLP(hdc, (POINT *)&rc, 2);
|
||||
IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
|
||||
}
|
||||
|
||||
static void restore_clipping(HDC hdc, HRGN hrgn)
|
||||
{
|
||||
SelectClipRgn(hdc, hrgn);
|
||||
if (hrgn != NULL)
|
||||
DeleteObject(hrgn);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* STATIC_SetIcon
|
||||
|
@ -315,8 +342,12 @@ static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
|
|||
if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
|
||||
{
|
||||
HDC hdc;
|
||||
HRGN hOrigClipping;
|
||||
|
||||
hdc = GetDC( hwnd );
|
||||
setup_clipping(hwnd, hdc, &hOrigClipping);
|
||||
(staticPaintFunc[style])( hwnd, hdc, full_style );
|
||||
restore_clipping(hdc, hOrigClipping);
|
||||
ReleaseDC( hwnd, hdc );
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +444,12 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||
PAINTSTRUCT ps;
|
||||
HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
|
||||
if (staticPaintFunc[style])
|
||||
{
|
||||
HRGN hOrigClipping;
|
||||
setup_clipping(hwnd, hdc, &hOrigClipping);
|
||||
(staticPaintFunc[style])( hwnd, hdc, full_style );
|
||||
restore_clipping(hdc, hOrigClipping);
|
||||
}
|
||||
if (!wParam) EndPaint(hwnd, &ps);
|
||||
}
|
||||
break;
|
||||
|
@ -721,6 +757,7 @@ static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
|
|||
|
||||
GetClientRect( hwnd, &rc);
|
||||
|
||||
/* FIXME: send WM_CTLCOLORSTATIC */
|
||||
switch (style & SS_TYPEMASK)
|
||||
{
|
||||
case SS_BLACKRECT:
|
||||
|
@ -865,6 +902,7 @@ static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
|
|||
{
|
||||
RECT rc;
|
||||
|
||||
/* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
|
||||
GetClientRect( hwnd, &rc );
|
||||
switch (style & SS_TYPEMASK)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ CTESTS = \
|
|||
monitor.c \
|
||||
msg.c \
|
||||
resource.c \
|
||||
static.c \
|
||||
sysparams.c \
|
||||
text.c \
|
||||
win.c \
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
/* Unit test suite for static controls.
|
||||
*
|
||||
* Copyright 2007 Google (Mikolaj Zalewski)
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define STRICT
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
#define TODO_COUNT 1
|
||||
|
||||
#define CTRL_ID 1995
|
||||
|
||||
static HWND hMainWnd;
|
||||
|
||||
#define expect_eq(expr, value, type, fmt) { type val = expr; ok(val == (value), #expr " expected " #fmt " got " #fmt "\n", (value), val); }
|
||||
#define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
|
||||
r.bottom == _bottom && r.right == _right, "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", \
|
||||
r.left, r.top, r.right, r.bottom, _left, _top, _right, _bottom);
|
||||
|
||||
int g_nReceivedColorStatic = 0;
|
||||
|
||||
static HWND build_static(DWORD style)
|
||||
{
|
||||
return CreateWindow("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case WM_CTLCOLORSTATIC:
|
||||
{
|
||||
HDC hdc = (HDC)wparam;
|
||||
HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
|
||||
ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
|
||||
DeleteObject(hrgn);
|
||||
g_nReceivedColorStatic++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd, msg, wparam, lparam);
|
||||
}
|
||||
|
||||
void test_updates(int style, int flags)
|
||||
{
|
||||
RECT r1 = {20, 20, 30, 30};
|
||||
HWND hStatic = build_static(style);
|
||||
int exp;
|
||||
|
||||
trace("Testing style 0x%x\n", style);
|
||||
g_nReceivedColorStatic = 0;
|
||||
/* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
|
||||
InvalidateRect(hMainWnd, NULL, FALSE);
|
||||
UpdateWindow(hMainWnd);
|
||||
InvalidateRect(hMainWnd, &r1, FALSE);
|
||||
UpdateWindow(hMainWnd);
|
||||
InvalidateRect(hStatic, &r1, FALSE);
|
||||
UpdateWindow(hStatic);
|
||||
InvalidateRect(hStatic, NULL, FALSE);
|
||||
UpdateWindow(hStatic);
|
||||
|
||||
|
||||
if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
|
||||
exp = 4;
|
||||
else
|
||||
exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
|
||||
|
||||
if (flags & TODO_COUNT)
|
||||
todo_wine { expect_eq(g_nReceivedColorStatic, exp, int, "%d"); }
|
||||
else
|
||||
expect_eq(g_nReceivedColorStatic, exp, int, "%d");
|
||||
DestroyWindow(hStatic);
|
||||
}
|
||||
|
||||
START_TEST(static)
|
||||
{
|
||||
static char szClassName[] = "testclass";
|
||||
WNDCLASSEX wndclass;
|
||||
|
||||
wndclass.cbSize = sizeof(wndclass);
|
||||
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wndclass.lpfnWndProc = WndProc;
|
||||
wndclass.cbClsExtra = 0;
|
||||
wndclass.cbWndExtra = 0;
|
||||
wndclass.hInstance = GetModuleHandle(NULL);
|
||||
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
|
||||
wndclass.lpszClassName = szClassName;
|
||||
wndclass.lpszMenuName = NULL;
|
||||
RegisterClassEx(&wndclass);
|
||||
|
||||
hMainWnd = CreateWindow(szClassName, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, GetModuleHandle(NULL), NULL);
|
||||
ShowWindow(hMainWnd, SW_SHOW);
|
||||
UpdateWindow(hMainWnd);
|
||||
|
||||
test_updates(0, 0);
|
||||
test_updates(SS_SIMPLE, 0);
|
||||
test_updates(SS_ICON, 0);
|
||||
test_updates(SS_BITMAP, 0);
|
||||
test_updates(SS_BLACKRECT, TODO_COUNT);
|
||||
test_updates(SS_WHITERECT, TODO_COUNT);
|
||||
test_updates(SS_ETCHEDHORZ, TODO_COUNT);
|
||||
test_updates(SS_ETCHEDVERT, TODO_COUNT);
|
||||
|
||||
DestroyWindow(hMainWnd);
|
||||
}
|
Loading…
Reference in New Issue