Make WIN_SetStyle more thread-safe by specifying the bits to change

instead of the new value.
oldstable
Alexandre Julliard 2005-01-21 10:32:13 +00:00
parent 49a6c097b3
commit f936428601
8 changed files with 45 additions and 93 deletions

View File

@ -418,9 +418,9 @@ BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
&newWindowRect, &newClientRect, winpos->flags, wvrFlags ); &newWindowRect, &newClientRect, winpos->flags, wvrFlags );
if( winpos->flags & SWP_SHOWWINDOW ) if( winpos->flags & SWP_SHOWWINDOW )
WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle | WS_VISIBLE ); WIN_SetStyle( winpos->hwnd, WS_VISIBLE, 0 );
else if( winpos->flags & SWP_HIDEWINDOW ) else if( winpos->flags & SWP_HIDEWINDOW )
WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle & ~WS_VISIBLE ); WIN_SetStyle( winpos->hwnd, 0, WS_VISIBLE );
/* ------------------------------------------------------------------------ FINAL */ /* ------------------------------------------------------------------------ FINAL */

View File

@ -1793,10 +1793,9 @@ BOOL WINAPI GetScrollRange(HWND hwnd, INT nBar, LPINT lpMin, LPINT lpMax)
* *
* Back-end for ShowScrollBar(). Returns FALSE if no action was taken. * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
*/ */
BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV )
BOOL fShowH, BOOL fShowV )
{ {
LONG style = GetWindowLongW( hwnd, GWL_STYLE ); ULONG old_style, set_bits = 0, clear_bits = 0;
TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV ); TRACE("hwnd=%p bar=%d horz=%d, vert=%d\n", hwnd, nBar, fShowH, fShowV );
@ -1808,45 +1807,24 @@ BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar,
case SB_BOTH: case SB_BOTH:
case SB_HORZ: case SB_HORZ:
if (fShowH) if (fShowH) set_bits |= WS_HSCROLL;
{ else clear_bits |= WS_HSCROLL;
fShowH = !(style & WS_HSCROLL); if( nBar == SB_HORZ ) break;
style |= WS_HSCROLL; /* fall through */
}
else /* hide it */
{
fShowH = (style & WS_HSCROLL);
style &= ~WS_HSCROLL;
}
if( nBar == SB_HORZ ) {
fShowV = FALSE;
break;
}
/* fall through */
case SB_VERT: case SB_VERT:
if (fShowV) if (fShowV) set_bits |= WS_VSCROLL;
{ else clear_bits |= WS_VSCROLL;
fShowV = !(style & WS_VSCROLL);
style |= WS_VSCROLL;
}
else /* hide it */
{
fShowV = (style & WS_VSCROLL);
style &= ~WS_VSCROLL;
}
if ( nBar == SB_VERT )
fShowH = FALSE;
break; break;
default: default:
return FALSE; /* Nothing to do! */ return FALSE; /* Nothing to do! */
} }
if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */ old_style = WIN_SetStyle( hwnd, set_bits, clear_bits );
if ((old_style & clear_bits) != 0 || (old_style & set_bits) != set_bits)
{ {
WIN_SetStyle( hwnd, style ); /* frame has been changed, let the window redraw itself */
SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
| SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
return TRUE; return TRUE;
} }

View File

@ -738,5 +738,5 @@
@ cdecl WIN_ListParents(long) @ cdecl WIN_ListParents(long)
@ cdecl WIN_ReleaseWndPtr(ptr) @ cdecl WIN_ReleaseWndPtr(ptr)
@ cdecl WIN_SetExStyle(long long) @ cdecl WIN_SetExStyle(long long)
@ cdecl WIN_SetStyle(long long) @ cdecl WIN_SetStyle(long long long)
@ cdecl WIN_UnlinkWindow(long) @ cdecl WIN_UnlinkWindow(long)

View File

@ -1155,7 +1155,7 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
RECT newPos; RECT newPos;
UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE; UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
WIN_SetStyle( hwnd, style & ~(WS_MAXIMIZE | WS_MINIMIZE) ); WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
WINPOS_MinMaximize( hwnd, swFlag, &newPos ); WINPOS_MinMaximize( hwnd, swFlag, &newPos );
swFlag = ((style & WS_CHILD) || GetActiveWindow()) swFlag = ((style & WS_CHILD) || GetActiveWindow())
? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED

View File

@ -995,7 +995,7 @@ UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX; if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
else wndPtr->flags &= ~WIN_RESTORE_MAX; else wndPtr->flags &= ~WIN_RESTORE_MAX;
WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE ); WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
X11DRV_set_iconic_state( hwnd ); X11DRV_set_iconic_state( hwnd );
@ -1009,7 +1009,7 @@ UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
case SW_MAXIMIZE: case SW_MAXIMIZE:
WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL ); WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE ); old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
if (old_style & WS_MINIMIZE) if (old_style & WS_MINIMIZE)
{ {
WINPOS_ShowIconTitle( hwnd, FALSE ); WINPOS_ShowIconTitle( hwnd, FALSE );
@ -1019,7 +1019,7 @@ UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
break; break;
case SW_RESTORE: case SW_RESTORE:
old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) ); old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
if (old_style & WS_MINIMIZE) if (old_style & WS_MINIMIZE)
{ {
WINPOS_ShowIconTitle( hwnd, FALSE ); WINPOS_ShowIconTitle( hwnd, FALSE );
@ -1029,7 +1029,7 @@ UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
{ {
/* Restore to maximized position */ /* Restore to maximized position */
WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL); WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE ); WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y ); SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
break; break;
} }
@ -1198,7 +1198,7 @@ void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
unsigned int width, height, border, depth; unsigned int width, height, border, depth;
Window root, top; Window root, top;
RECT rect; RECT rect;
LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE; LONG style = WS_VISIBLE;
/* FIXME: hack */ /* FIXME: hack */
wine_tsx11_lock(); wine_tsx11_lock();
@ -1215,7 +1215,7 @@ void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
DCE_InvalidateDCE( hwnd, &win->rectWindow ); DCE_InvalidateDCE( hwnd, &win->rectWindow );
if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE; if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
WIN_SetStyle( hwnd, style ); WIN_SetStyle( hwnd, style, WS_MINIMIZE );
WIN_ReleasePtr( win ); WIN_ReleasePtr( win );
SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 ); SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
@ -1244,7 +1244,7 @@ void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
else else
win->flags &= ~WIN_RESTORE_MAX; win->flags &= ~WIN_RESTORE_MAX;
WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE ); WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
WIN_ReleasePtr( win ); WIN_ReleasePtr( win );
EndMenu(); EndMenu();

View File

@ -87,7 +87,7 @@ extern HWND WIN_IsCurrentThread( HWND hwnd );
extern void WIN_LinkWindow( HWND hwnd, HWND parent, HWND hwndInsertAfter ); extern void WIN_LinkWindow( HWND hwnd, HWND parent, HWND hwndInsertAfter );
extern void WIN_UnlinkWindow( HWND hwnd ); extern void WIN_UnlinkWindow( HWND hwnd );
extern HWND WIN_SetOwner( HWND hwnd, HWND owner ); extern HWND WIN_SetOwner( HWND hwnd, HWND owner );
extern LONG WIN_SetStyle( HWND hwnd, LONG style ); extern ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits );
extern LONG WIN_SetExStyle( HWND hwnd, LONG style ); extern LONG WIN_SetExStyle( HWND hwnd, LONG style );
extern BOOL WIN_GetRectangles( HWND hwnd, RECT *rectWindow, RECT *rectClient ); extern BOOL WIN_GetRectangles( HWND hwnd, RECT *rectWindow, RECT *rectClient );
extern LRESULT WIN_DestroyWindow( HWND hwnd ); extern LRESULT WIN_DestroyWindow( HWND hwnd );

View File

@ -184,34 +184,6 @@ HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
} }
/***********************************************************************
* DEFWND_SetRedraw
*/
static void DEFWND_SetRedraw( HWND hwnd, WPARAM wParam )
{
WND *wndPtr = WIN_FindWndPtr( hwnd );
BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
TRACE("%p %i\n", hwnd, (wParam!=0) );
if( wParam )
{
if( !bVisible )
{
WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_VISIBLE );
}
}
else if( bVisible )
{
if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
RedrawWindow( hwnd, NULL, 0, wParam );
WIN_SetStyle( hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
}
WIN_ReleaseWndPtr( wndPtr );
}
/*********************************************************************** /***********************************************************************
* DEFWND_Print * DEFWND_Print
* *
@ -463,7 +435,12 @@ static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa
return 0; return 0;
case WM_SETREDRAW: case WM_SETREDRAW:
DEFWND_SetRedraw( hwnd, wParam ); if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
else
{
RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
WIN_SetStyle( hwnd, 0, WS_VISIBLE );
}
return 0; return 0;
case WM_CLOSE: case WM_CLOSE:

View File

@ -462,40 +462,42 @@ HWND WIN_SetOwner( HWND hwnd, HWND owner )
* *
* Change the style of a window. * Change the style of a window.
*/ */
LONG WIN_SetStyle( HWND hwnd, LONG style ) ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits )
{ {
BOOL ok; BOOL ok;
LONG ret = 0; ULONG new_style, old_style = 0;
WND *win = WIN_GetPtr( hwnd ); WND *win = WIN_GetPtr( hwnd );
if (!win) return 0; if (!win) return 0;
if (win == WND_OTHER_PROCESS) if (win == WND_OTHER_PROCESS)
{ {
if (IsWindow(hwnd)) if (IsWindow(hwnd))
ERR( "cannot set style %lx on other process window %p\n", style, hwnd ); ERR( "cannot set style %lx/%lx on other process window %p\n",
set_bits, clear_bits, hwnd );
return 0; return 0;
} }
if (style == win->dwStyle) new_style = (win->dwStyle | set_bits) & ~clear_bits;
if (new_style == win->dwStyle)
{ {
WIN_ReleasePtr( win ); WIN_ReleasePtr( win );
return style; return new_style;
} }
SERVER_START_REQ( set_window_info ) SERVER_START_REQ( set_window_info )
{ {
req->handle = hwnd; req->handle = hwnd;
req->flags = SET_WIN_STYLE; req->flags = SET_WIN_STYLE;
req->style = style; req->style = new_style;
req->extra_offset = -1; req->extra_offset = -1;
if ((ok = !wine_server_call( req ))) if ((ok = !wine_server_call( req )))
{ {
ret = reply->old_style; old_style = reply->old_style;
win->dwStyle = style; win->dwStyle = new_style;
} }
} }
SERVER_END_REQ; SERVER_END_REQ;
WIN_ReleasePtr( win ); WIN_ReleasePtr( win );
if (ok && USER_Driver.pSetWindowStyle) USER_Driver.pSetWindowStyle( hwnd, ret ); if (ok && USER_Driver.pSetWindowStyle) USER_Driver.pSetWindowStyle( hwnd, old_style );
return ret; return old_style;
} }
@ -1685,9 +1687,7 @@ HWND WINAPI GetDesktopWindow(void)
*/ */
BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable ) BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
{ {
WND *wndPtr;
BOOL retvalue; BOOL retvalue;
LONG style;
HWND full_handle; HWND full_handle;
if (is_broadcast(hwnd)) if (is_broadcast(hwnd))
@ -1703,14 +1703,11 @@ BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
TRACE("( %p, %d )\n", hwnd, enable); TRACE("( %p, %d )\n", hwnd, enable);
if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE; retvalue = !IsWindowEnabled( hwnd );
style = wndPtr->dwStyle;
retvalue = ((style & WS_DISABLED) != 0);
WIN_ReleasePtr( wndPtr );
if (enable && retvalue) if (enable && retvalue)
{ {
WIN_SetStyle( hwnd, style & ~WS_DISABLED ); WIN_SetStyle( hwnd, 0, WS_DISABLED );
SendMessageA( hwnd, WM_ENABLE, TRUE, 0 ); SendMessageA( hwnd, WM_ENABLE, TRUE, 0 );
} }
else if (!enable && !retvalue) else if (!enable && !retvalue)
@ -1719,7 +1716,7 @@ BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
SendMessageA( hwnd, WM_CANCELMODE, 0, 0); SendMessageA( hwnd, WM_CANCELMODE, 0, 0);
WIN_SetStyle( hwnd, style | WS_DISABLED ); WIN_SetStyle( hwnd, WS_DISABLED, 0 );
if (hwnd == GetFocus()) if (hwnd == GetFocus())
SetFocus( 0 ); /* A disabled window can't have the focus */ SetFocus( 0 ); /* A disabled window can't have the focus */