Author: tkreuzer
Date: Sat Aug 13 15:16:31 2011
New Revision: 53204
URL:
http://svn.reactos.org/svn/reactos?rev=53204&view=rev
Log:
[USER32]
Partly sync static.c with wine, reduce diff between ros and wine code. The leak fix is
taken care of. Also go back from Get/SetWindowLongPtr to Get/SetWindowLong for LONG
values. Using the *Ptr version is wrong for LONG values!
Modified:
trunk/reactos/dll/win32/user32/controls/static.c
trunk/reactos/dll/win32/user32/include/user32p.h
Modified: trunk/reactos/dll/win32/user32/controls/static.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/…
==============================================================================
--- trunk/reactos/dll/win32/user32/controls/static.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/controls/static.c [iso-8859-1] Sat Aug 13 15:16:31
2011
@@ -55,15 +55,13 @@
static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
-//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_3dshadow, color_3ddkshadow, color_3dhighlight;
/* offsets for GetWindowLong for static private information */
#define HFONT_GWL_OFFSET 0
#define HICON_GWL_OFFSET (sizeof(HFONT))
-#define UISTATE_GWL_OFFSET (HICON_GWL_OFFSET+sizeof(HICON))
+#define UISTATE_GWL_OFFSET (HICON_GWL_OFFSET+sizeof(HICON)) // ReactOS: keep in sync with
STATIC_UISTATE_GWL_OFFSET
#define STATIC_EXTRA_BYTES (UISTATE_GWL_OFFSET + sizeof(LONG))
typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
@@ -107,40 +105,6 @@
0 /* brush */
};
-/* REACTOS ONLY */
-static __inline void set_ui_state( HWND hwnd, LONG flags )
-{
- SetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET, flags );
-}
-
-static __inline LONG get_ui_state( HWND hwnd )
-{
- return GetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET );
-}
-
-/* Retrieve the UI state for the control */
-static BOOL STATIC_update_uistate(HWND hwnd, BOOL unicode)
-{
- LONG flags, prevflags;
-
- if (unicode)
- flags = DefWindowProcW(hwnd, WM_QUERYUISTATE, 0, 0);
- else
- flags = DefWindowProcA(hwnd, WM_QUERYUISTATE, 0, 0);
-
- prevflags = get_ui_state(hwnd);
-
- if (prevflags != flags)
- {
- set_ui_state(hwnd, flags);
- return TRUE;
- }
-
- return FALSE;
-}
-
-/* END REACTOS ONLY */
-
static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
{
RECT rc;
@@ -172,28 +136,22 @@
/***********************************************************************
* STATIC_SetIcon
*
- * Set the icon for an SS_ICON control. Modified for ReactOS
+ * Set the icon for an SS_ICON control.
*/
static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
{
HICON prevIcon;
- ICONINFO info;
+ SIZE size;
if ((style & SS_TYPEMASK) != SS_ICON) return 0;
- if (hicon && (!GetIconInfo(hicon, &info))) {
- WARN("hicon != 0, but info == 0\n");
+ if (hicon && !get_icon_size( hicon, &size ))
+ {
+ WARN("hicon != 0, but invalid\n");
return 0;
}
prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
if (hicon && !(style & SS_CENTERIMAGE) && !(style &
SS_REALSIZECONTROL))
{
- BITMAP bm;
-
- if (!GetObjectW(info.hbmColor, sizeof(BITMAP), &bm))
- {
- return 0;
- }
-
/* Windows currently doesn't implement SS_RIGHTJUST */
/*
if ((style & SS_RIGHTJUST) != 0)
@@ -205,12 +163,8 @@
}
else */
{
- SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
- SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
- }
-
- DeleteObject(info.hbmMask);
- if (info.hbmColor) DeleteObject(info.hbmColor);
+ SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE |
SWP_NOZORDER );
+ }
}
return prevIcon;
}
@@ -218,7 +172,7 @@
/***********************************************************************
* STATIC_SetBitmap
*
- * Set the bitmap for an SS_BITMAP control. Modified for ReactOS
+ * Set the bitmap for an SS_BITMAP control.
*/
static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
{
@@ -331,13 +285,13 @@
if (hInstance && ((ULONG_PTR)hInstance >> 16))
{
- if ((style & SS_REALSIZEIMAGE) != 0)
- hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
- else
- {
- hicon = LoadIconW( hInstance, name );
- if (!hicon) hicon = LoadCursorW( hInstance, name );
- }
+ if ((style & SS_REALSIZEIMAGE) != 0)
+ hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
+ else
+ {
+ hicon = LoadIconW( hInstance, name );
+ if (!hicon) hicon = LoadCursorW( hInstance, name );
+ }
}
if (!hicon) hicon = LoadIconW( 0, name );
/* Windows doesn't try to load a standard cursor,
@@ -346,7 +300,6 @@
return hicon;
}
-
/***********************************************************************
* STATIC_TryPaintFcn
*
@@ -362,11 +315,11 @@
{
HDC hdc;
HRGN hOrigClipping;
-
+
hdc = GetDC( hwnd );
setup_clipping(hwnd, hdc, &hOrigClipping);
(staticPaintFunc[style])( hwnd, hdc, full_style );
- restore_clipping(hdc, hOrigClipping);
+ restore_clipping(hdc, hOrigClipping);
ReleaseDC( hwnd, hdc );
}
}
@@ -420,11 +373,10 @@
/***********************************************************************
* StaticWndProc_common
*/
-LRESULT WINAPI StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
- LPARAM lParam, BOOL unicode )
+LRESULT WINAPI StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
BOOL unicode ) // ReactOS
{
LRESULT lResult = 0;
- LONG full_style = GetWindowLongPtrW( hwnd, GWL_STYLE );
+ LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
LONG style = full_style & SS_TYPEMASK;
#ifdef __REACTOS__
PWND pWnd;
@@ -436,8 +388,10 @@
{
NtUserSetWindowFNID(hwnd, FNID_STATIC);
}
- }
-#endif
+ }
+#endif
+
+ if (!IsWindow( hwnd )) return 0;
switch (uMsg)
{
@@ -447,7 +401,7 @@
ERR("Unknown style 0x%02lx\n", style );
return -1;
}
- STATIC_update_uistate(hwnd, unicode);
+ STATIC_update_uistate(hwnd, unicode); // ReactOS r30727
STATIC_InitColours();
break;
@@ -470,8 +424,8 @@
DefWindowProcA(hwnd, uMsg, wParam, lParam);
case WM_ERASEBKGND:
- /* do all painting in WM_PAINT like Windows does */
- return 1;
+ /* do all painting in WM_PAINT like Windows does */
+ return 1;
case WM_PRINTCLIENT:
case WM_PAINT:
@@ -510,47 +464,31 @@
case WM_NCCREATE:
{
- LPCSTR textA;
- LPCWSTR textW;
- HINSTANCE hInstance;
+ CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
if (full_style & SS_SUNKEN)
- SetWindowLongPtrW( hwnd, GWL_EXSTYLE,
- GetWindowLongPtrW( hwnd, GWL_EXSTYLE ) |
WS_EX_STATICEDGE );
-
- if(unicode)
- {
- textA = NULL;
- textW = ((LPCREATESTRUCTW)lParam)->lpszName;
- }
- else
- {
- textA = ((LPCREATESTRUCTA)lParam)->lpszName;
- textW = NULL;
-
- }
-
- hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
+ SetWindowLongW( hwnd, GWL_EXSTYLE,
+ GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE
);
switch (style) {
case SS_ICON:
{
HICON hIcon;
- if(unicode )
- hIcon = STATIC_LoadIconW(hInstance, textW, full_style);
+ if (unicode || IS_INTRESOURCE(cs->lpszName))
+ hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName,
full_style);
else
- hIcon = STATIC_LoadIconA(hInstance, textA, full_style);
+ hIcon = STATIC_LoadIconA(cs->hInstance,
(LPCSTR)cs->lpszName, full_style);
STATIC_SetIcon(hwnd, hIcon, full_style);
}
break;
case SS_BITMAP:
- if ((ULONG_PTR)hInstance >> 16)
+ if ((ULONG_PTR)cs->hInstance >> 16)
{
HBITMAP hBitmap;
- if(unicode)
- hBitmap = LoadBitmapW(hInstance, textW);
+ if (unicode || IS_INTRESOURCE(cs->lpszName))
+ hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
else
- hBitmap = LoadBitmapA(hInstance, textA);
+ hBitmap = LoadBitmapA(cs->hInstance,
(LPCSTR)cs->lpszName);
STATIC_SetBitmap(hwnd, hBitmap, full_style);
}
break;
@@ -619,16 +557,16 @@
case STM_SETIMAGE:
switch(wParam) {
case IMAGE_BITMAP:
- if (style != SS_BITMAP) return 0;
+ if (style != SS_BITMAP) return 0; // ReactOS r43158
lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
break;
case IMAGE_ENHMETAFILE:
- if (style != SS_ENHMETAFILE) return 0;
+ if (style != SS_ENHMETAFILE) return 0; // ReactOS r43158
lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
break;
case IMAGE_ICON:
case IMAGE_CURSOR:
- if (style != SS_ICON) return 0;
+ if (style != SS_ICON) return 0; // ReactOS r43158
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
break;
default:
@@ -643,6 +581,7 @@
STATIC_TryPaintFcn( hwnd, full_style );
break;
+#ifdef __REACTOS__
case WM_UPDATEUISTATE:
if (unicode)
DefWindowProcW(hwnd, uMsg, wParam, lParam);
@@ -654,6 +593,7 @@
RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW |
RDW_ALLCHILDREN );
}
break;
+#endif
default:
return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
@@ -745,7 +685,7 @@
if (style & SS_NOPREFIX)
wFormat |= DT_NOPREFIX;
- else if (get_ui_state(hwnd) & UISF_HIDEACCEL)
+ else if (GetWindowLongW(hwnd, UISTATE_GWL_OFFSET) & UISF_HIDEACCEL) // ReactOS
r30727
wFormat |= DT_HIDEPREFIX;
if ((style & SS_TYPEMASK) != SS_SIMPLE)
@@ -781,9 +721,9 @@
while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
{
- buf_size *= 2;
- if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
- goto no_TextOut;
+ buf_size *= 2;
+ if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR)
)))
+ goto no_TextOut;
}
if (!len) goto no_TextOut;
@@ -850,6 +790,7 @@
}
DeleteObject( hBrush );
}
+
static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
{
@@ -969,4 +910,3 @@
break;
}
}
-
Modified: trunk/reactos/dll/win32/user32/include/user32p.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/include/u…
==============================================================================
--- trunk/reactos/dll/win32/user32/include/user32p.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/include/user32p.h [iso-8859-1] Sat Aug 13 15:16:31
2011
@@ -214,4 +214,28 @@
#define __EXCEPT_PAGE_FAULT else
#define __ENDTRY
+#define STATIC_UISTATE_GWL_OFFSET (sizeof(HFONT)+sizeof(HICON))// see UISTATE_GWL_OFFSET
in static.c
+
+/* Retrieve the UI state for the control */
+static __inline BOOL STATIC_update_uistate(HWND hwnd, BOOL unicode)
+{
+ LONG flags, prevflags;
+
+ if (unicode)
+ flags = DefWindowProcW(hwnd, WM_QUERYUISTATE, 0, 0);
+ else
+ flags = DefWindowProcA(hwnd, WM_QUERYUISTATE, 0, 0);
+
+ prevflags = GetWindowLongW(hwnd, STATIC_UISTATE_GWL_OFFSET);
+
+ if (prevflags != flags)
+ {
+ SetWindowLongW(hwnd, STATIC_UISTATE_GWL_OFFSET, flags);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/* EOF */