4 * Copyright 1998,1999 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/wingdi16.h"
29 #include "wine/server.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
34 #define SWP_AGG_NOGEOMETRYCHANGE \
35 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
36 #define SWP_AGG_NOPOSCHANGE \
37 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
38 #define SWP_AGG_STATUSFLAGS \
39 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
41 /***********************************************************************
42 * get_server_visible_region
44 static HRGN get_server_visible_region( HWND hwnd, UINT flags )
53 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 ))) return 0;
54 SERVER_START_REQ( get_visible_region )
58 wine_server_set_reply( req, data->Buffer, size );
59 if (!(status = wine_server_call( req )))
61 size_t reply_size = wine_server_reply_size( reply );
62 data->rdh.dwSize = sizeof(data->rdh);
63 data->rdh.iType = RDH_RECTANGLES;
64 data->rdh.nCount = reply_size / sizeof(RECT);
65 data->rdh.nRgnSize = reply_size;
66 ret = ExtCreateRegion( NULL, size, data );
68 else size = reply->total_size;
71 HeapFree( GetProcessHeap(), 0, data );
72 } while (status == STATUS_BUFFER_OVERFLOW);
74 if (status) SetLastError( RtlNtStatusToDosError(status) );
79 /***********************************************************************
82 * Set a window position and Z order.
84 static BOOL set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
85 const RECT *rectClient, UINT swp_flags )
87 WND *win = WIN_GetPtr( hwnd );
90 if (!win) return FALSE;
91 if (win == WND_OTHER_PROCESS)
93 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
96 SERVER_START_REQ( set_window_pos )
99 req->previous = insert_after;
100 req->flags = swp_flags;
101 req->window.left = rectWindow->left;
102 req->window.top = rectWindow->top;
103 req->window.right = rectWindow->right;
104 req->window.bottom = rectWindow->bottom;
105 req->client.left = rectClient->left;
106 req->client.top = rectClient->top;
107 req->client.right = rectClient->right;
108 req->client.bottom = rectClient->bottom;
109 ret = !wine_server_call( req );
114 win->rectWindow = *rectWindow;
115 win->rectClient = *rectClient;
117 TRACE( "win %p window (%ld,%ld)-(%ld,%ld) client (%ld,%ld)-(%ld,%ld)\n", hwnd,
118 rectWindow->left, rectWindow->top, rectWindow->right, rectWindow->bottom,
119 rectClient->left, rectClient->top, rectClient->right, rectClient->bottom );
121 WIN_ReleasePtr( win );
126 /**********************************************************************
127 * CreateWindow (TTYDRV.@)
129 BOOL TTYDRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
133 HWND parent, hwndLinkAfter;
136 TRACE("(%p)\n", hwnd);
138 /* initialize the dimensions before sending WM_GETMINMAXINFO */
139 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
140 set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER );
142 parent = GetAncestor( hwnd, GA_PARENT );
143 if (!parent) /* desktop window */
145 SetPropA( hwnd, "__wine_ttydrv_window", root_window );
150 /* Only create top-level windows */
151 if (parent == GetDesktopWindow())
154 const INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
156 window = subwin( root_window, cs->cy/cellHeight, cs->cx/cellWidth,
157 cs->y/cellHeight, cs->x/cellWidth);
160 SetPropA( hwnd, "__wine_ttydrv_window", window );
162 #else /* defined(WINE_CURSES) */
163 FIXME("(%p): stub\n", hwnd);
164 #endif /* defined(WINE_CURSES) */
166 /* Call the WH_CBT hook */
168 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
171 cbtc.hwndInsertAfter = hwndLinkAfter;
172 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
174 TRACE("CBT-hook returned !0\n");
180 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
181 if (ret) ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
185 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
186 if (ret) ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
188 if (ret) NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0);
192 /***********************************************************************
193 * DestroyWindow (TTYDRV.@)
195 BOOL TTYDRV_DestroyWindow( HWND hwnd )
198 WINDOW *window = GetPropA( hwnd, "__wine_ttydrv_window" );
200 TRACE("(%p)\n", hwnd);
202 if (window && window != root_window) delwin(window);
203 #else /* defined(WINE_CURSES) */
204 FIXME("(%p): stub\n", hwnd);
205 #endif /* defined(WINE_CURSES) */
210 /***********************************************************************
213 * Set the drawable, origin and dimensions for the DC associated to
216 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
218 struct ttydrv_escape_set_drawable escape;
220 if(flags & DCX_WINDOW)
223 GetWindowRect( hwnd, &rect );
224 escape.org.x = rect.left;
225 escape.org.y = rect.top;
229 escape.org.x = escape.org.y = 0;
230 MapWindowPoints( hwnd, 0, &escape.org, 1 );
233 escape.code = TTYDRV_SET_DRAWABLE;
234 ExtEscape( hdc, TTYDRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
236 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
237 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
239 /* need to recompute the visible region */
240 HRGN visRgn = get_server_visible_region( hwnd, flags );
242 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
243 CombineRgn( visRgn, visRgn, hrgn, (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
245 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
246 DeleteObject( visRgn );
252 /* fix redundant flags and values in the WINDOWPOS structure */
253 static BOOL fixup_flags( WINDOWPOS *winpos )
256 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
259 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
261 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
264 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
266 /* Finally make sure that all coordinates are valid */
267 if (winpos->x < -32768) winpos->x = -32768;
268 else if (winpos->x > 32767) winpos->x = 32767;
269 if (winpos->y < -32768) winpos->y = -32768;
270 else if (winpos->y > 32767) winpos->y = 32767;
272 if (winpos->cx < 0) winpos->cx = 0;
273 else if (winpos->cx > 32767) winpos->cx = 32767;
274 if (winpos->cy < 0) winpos->cy = 0;
275 else if (winpos->cy > 32767) winpos->cy = 32767;
277 parent = GetAncestor( winpos->hwnd, GA_PARENT );
278 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
280 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
283 winpos->flags &= ~SWP_HIDEWINDOW;
284 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
287 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
288 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
289 winpos->flags |= SWP_NOSIZE; /* Already the right size */
291 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
292 winpos->flags |= SWP_NOMOVE; /* Already the right position */
294 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
296 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
298 winpos->flags &= ~SWP_NOZORDER;
299 winpos->hwndInsertAfter = HWND_TOP;
303 /* Check hwndInsertAfter */
304 if (winpos->flags & SWP_NOZORDER) goto done;
306 /* fix sign extension */
307 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
308 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
310 /* FIXME: TOPMOST not supported yet */
311 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
312 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
314 /* hwndInsertAfter must be a sibling of the window */
315 if (winpos->hwndInsertAfter == HWND_TOP)
317 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
318 winpos->flags |= SWP_NOZORDER;
320 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
322 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
323 winpos->flags |= SWP_NOZORDER;
327 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
330 /* don't need to change the Zorder of hwnd if it's already inserted
331 * after hwndInsertAfter or when inserting hwnd after itself.
333 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
334 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
335 winpos->flags |= SWP_NOZORDER;
339 WIN_ReleasePtr( wndPtr );
344 /***********************************************************************
347 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect )
352 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
354 /* Send WM_NCCALCSIZE message to get new client area */
355 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
357 NCCALCSIZE_PARAMS params;
358 WINDOWPOS winposCopy;
360 params.rgrc[0] = *pNewWindowRect;
361 params.rgrc[1] = wndPtr->rectWindow;
362 params.rgrc[2] = wndPtr->rectClient;
363 params.lppos = &winposCopy;
364 winposCopy = *pWinpos;
365 WIN_ReleasePtr( wndPtr );
367 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
369 *pNewClientRect = params.rgrc[0];
371 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
373 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
374 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
375 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
377 if( pNewClientRect->left != wndPtr->rectClient.left ||
378 pNewClientRect->top != wndPtr->rectClient.top )
379 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
381 if( (pNewClientRect->right - pNewClientRect->left !=
382 wndPtr->rectClient.right - wndPtr->rectClient.left))
383 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
385 wvrFlags &= ~WVR_HREDRAW;
387 if (pNewClientRect->bottom - pNewClientRect->top !=
388 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
389 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
391 wvrFlags &= ~WVR_VREDRAW;
395 if (!(pWinpos->flags & SWP_NOMOVE) &&
396 (pNewClientRect->left != wndPtr->rectClient.left ||
397 pNewClientRect->top != wndPtr->rectClient.top))
398 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
401 WIN_ReleasePtr( wndPtr );
406 /***********************************************************************
409 * fix Z order taking into account owned popups -
410 * basically we need to maintain them above the window that owns them
412 * FIXME: hide/show owned popups when owner visibility changes.
414 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
417 HWND owner = GetWindow( hwnd, GW_OWNER );
418 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
420 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
422 if ((style & WS_POPUP) && owner)
424 /* make sure this popup stays above the owner */
426 HWND hwndLocalPrev = HWND_TOP;
428 if( hwndInsertAfter != HWND_TOP )
430 if ((list = WIN_ListChildren( GetDesktopWindow() )))
433 for (i = 0; list[i]; i++)
435 if (list[i] == owner) break;
436 if (list[i] != hwnd) hwndLocalPrev = list[i];
437 if (hwndLocalPrev == hwndInsertAfter) break;
439 hwndInsertAfter = hwndLocalPrev;
443 else if (style & WS_CHILD) return hwndInsertAfter;
445 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
449 for (i = 0; list[i]; i++)
451 if (list[i] == hwnd) break;
452 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
453 GetWindow( list[i], GW_OWNER ) == hwnd)
455 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
456 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
457 SWP_NOSENDCHANGING | SWP_DEFERERASE );
458 hwndInsertAfter = list[i];
461 HeapFree( GetProcessHeap(), 0, list );
464 return hwndInsertAfter;
468 /***********************************************************************
469 * SWP_DoWinPosChanging
471 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
475 /* Send WM_WINDOWPOSCHANGING message */
477 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
478 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
480 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
482 /* Calculate new position and size */
484 *pNewWindowRect = wndPtr->rectWindow;
485 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
486 : wndPtr->rectClient;
488 if (!(pWinpos->flags & SWP_NOSIZE))
490 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
491 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
493 if (!(pWinpos->flags & SWP_NOMOVE))
495 pNewWindowRect->left = pWinpos->x;
496 pNewWindowRect->top = pWinpos->y;
497 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
498 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
500 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
501 pWinpos->y - wndPtr->rectWindow.top );
503 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
505 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
506 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
507 pWinpos->cx, pWinpos->cy, pWinpos->flags );
508 TRACE( "current %s style %08lx new %s\n",
509 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
510 wine_dbgstr_rect( pNewWindowRect ));
512 WIN_ReleasePtr( wndPtr );
517 /***********************************************************************
518 * SetWindowPos (TTYDRV.@)
520 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
522 RECT newWindowRect, newClientRect;
525 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
526 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
527 winpos->cx, winpos->cy, winpos->flags);
529 orig_flags = winpos->flags;
530 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
532 /* Check window handle */
533 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
535 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
536 if (!(winpos->flags & SWP_NOMOVE))
538 if (winpos->x < -32768) winpos->x = -32768;
539 else if (winpos->x > 32767) winpos->x = 32767;
540 if (winpos->y < -32768) winpos->y = -32768;
541 else if (winpos->y > 32767) winpos->y = 32767;
543 if (!(winpos->flags & SWP_NOSIZE))
545 if (winpos->cx < 0) winpos->cx = 0;
546 else if (winpos->cx > 32767) winpos->cx = 32767;
547 if (winpos->cy < 0) winpos->cy = 0;
548 else if (winpos->cy > 32767) winpos->cy = 32767;
551 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
553 /* Fix redundant flags */
554 if (!fixup_flags( winpos )) return FALSE;
556 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
558 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
559 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
562 /* Common operations */
564 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
566 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
567 &newWindowRect, &newClientRect, orig_flags ))
570 if( winpos->flags & SWP_HIDEWINDOW )
571 HideCaret(winpos->hwnd);
572 else if (winpos->flags & SWP_SHOWWINDOW)
573 ShowCaret(winpos->hwnd);
575 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
577 /* child windows get WM_CHILDACTIVATE message */
578 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
579 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
581 SetForegroundWindow( winpos->hwnd );
584 /* And last, send the WM_WINDOWPOSCHANGED message */
586 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
588 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
590 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
591 and always contains final window position.
593 winpos->x = newWindowRect.left;
594 winpos->y = newWindowRect.top;
595 winpos->cx = newWindowRect.right - newWindowRect.left;
596 winpos->cy = newWindowRect.bottom - newWindowRect.top;
597 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
604 /***********************************************************************
605 * WINPOS_MinMaximize (internal)
607 *Lifted from x11 driver
609 static UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
614 TRACE("%p %u\n", hwnd, cmd );
615 FIXME("(%p): stub\n", hwnd);
617 wpl.length = sizeof(wpl);
618 GetWindowPlacement( hwnd, &wpl );
620 /* If I glark this right, yields an immutable window*/
621 swpFlags = SWP_NOSIZE | SWP_NOMOVE;
623 /*cmd handling goes here. see dlls/x1drv/winpos.c*/
628 /***********************************************************************
629 * ShowWindow (TTYDRV.@)
631 *Lifted from x11 driver
632 *Sets the specified windows' show state.
634 BOOL TTYDRV_ShowWindow( HWND hwnd, INT cmd )
637 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
638 BOOL wasVisible = (style & WS_VISIBLE) != 0;
639 BOOL showFlag = TRUE;
640 RECT newPos = {0, 0, 0, 0};
644 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
649 if (!wasVisible) return FALSE;
651 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER;
654 case SW_SHOWMINNOACTIVE:
655 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
657 case SW_SHOWMINIMIZED:
658 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
659 swp |= SWP_SHOWWINDOW;
662 swp |= SWP_FRAMECHANGED;
663 if( !(style & WS_MINIMIZE) )
664 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
665 else swp |= SWP_NOSIZE | SWP_NOMOVE;
668 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
669 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
670 if( !(style & WS_MAXIMIZE) )
671 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
672 else swp |= SWP_NOSIZE | SWP_NOMOVE;
676 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
677 if (style & WS_CHILD) swp |= SWP_NOZORDER;
680 if (wasVisible) return TRUE;
681 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
685 swp |= SWP_FRAMECHANGED;
687 case SW_SHOWNOACTIVATE:
688 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
690 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
691 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
692 swp |= SWP_SHOWWINDOW;
694 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
695 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
696 else swp |= SWP_NOSIZE | SWP_NOMOVE;
700 if (showFlag != wasVisible || cmd == SW_SHOWNA)
702 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
703 if (!IsWindow( hwnd )) return wasVisible;
706 /* ShowWindow won't activate a not being maximized child window */
707 if ((style & WS_CHILD) && cmd != SW_MAXIMIZE)
708 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
710 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
711 newPos.right, newPos.bottom, LOWORD(swp) );
716 /* FIXME: This will cause the window to be activated irrespective
717 * of whether it is owned by the same thread. Has to be done
721 if (hwnd == GetActiveWindow())
722 WINPOS_ActivateOtherWindow(hwnd);
724 /* Revert focus to parent */
726 if (hwnd == hFocus || IsChild(hwnd, hFocus))
728 HWND parent = GetAncestor(hwnd, GA_PARENT);
729 if (parent == GetDesktopWindow()) parent = 0;
734 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
736 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
738 if (wndPtr->flags & WIN_NEED_SIZE)
740 /* should happen only in CreateWindowEx() */
741 int wParam = SIZE_RESTORED;
742 RECT client = wndPtr->rectClient;
744 wndPtr->flags &= ~WIN_NEED_SIZE;
745 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
746 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
747 WIN_ReleasePtr( wndPtr );
749 SendMessageW( hwnd, WM_SIZE, wParam,
750 MAKELONG( client.right - client.left, client.bottom - client.top ));
751 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
753 else WIN_ReleasePtr( wndPtr );