4 * Copyright 1998,1999 Patrik Stridvall
14 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(ttydrv);
19 #define SWP_AGG_NOGEOMETRYCHANGE \
20 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
21 #define SWP_AGG_NOPOSCHANGE \
22 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
23 #define SWP_AGG_STATUSFLAGS \
24 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
26 /**********************************************************************
27 * CreateWindow (TTYDRV.@)
29 BOOL TTYDRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
35 WND *wndPtr = WIN_FindWndPtr( hwnd );
37 INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
39 TRACE("(%x)\n", hwnd);
41 /* Only create top-level windows */
42 if (!(wndPtr->dwStyle & WS_CHILD))
44 if (!wndPtr->parent) /* desktop */
48 int x = wndPtr->rectWindow.left;
49 int y = wndPtr->rectWindow.top;
50 int cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
51 int cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
53 window = subwin( root_window, cy/cellHeight, cx/cellWidth,
54 y/cellHeight, x/cellWidth);
58 wndPtr->pDriverData = window;
60 WIN_ReleaseWndPtr( wndPtr );
61 #else /* defined(WINE_CURSES) */
62 FIXME("(%x): stub\n", hwnd);
63 #endif /* defined(WINE_CURSES) */
65 /* Call the WH_CBT hook */
67 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
68 ? HWND_BOTTOM : HWND_TOP;
70 if (HOOK_IsHooked( WH_CBT ))
76 cbtc.hwndInsertAfter = hwndLinkAfter;
77 lret = (unicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND,
78 (WPARAM)hwnd, (LPARAM)&cbtc)
79 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND,
80 (WPARAM)hwnd, (LPARAM)&cbtc);
83 TRACE("CBT-hook returned !0\n");
90 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
91 if (ret) ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
95 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
96 if (ret) ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
101 /***********************************************************************
102 * DestroyWindow (TTYDRV.@)
104 BOOL TTYDRV_DestroyWindow( HWND hwnd )
107 WND *wndPtr = WIN_FindWndPtr( hwnd );
108 WINDOW *window = wndPtr->pDriverData;
110 TRACE("(%x)\n", hwnd);
112 if (window && window != root_window) delwin(window);
113 wndPtr->pDriverData = NULL;
114 WIN_ReleaseWndPtr( wndPtr );
115 #else /* defined(WINE_CURSES) */
116 FIXME("(%x): stub\n", hwnd);
117 #endif /* defined(WINE_CURSES) */
122 /***********************************************************************
125 * Change region from DC-origin relative coordinates to screen coords.
128 static void DCE_OffsetVisRgn( HDC hDC, HRGN hVisRgn )
131 if (!(dc = DC_GetDCPtr( hDC ))) return;
133 OffsetRgn( hVisRgn, dc->DCOrgX, dc->DCOrgY );
135 GDI_ReleaseObj( hDC );
139 /***********************************************************************
142 * Calculate the visible rectangle of a window (i.e. the client or
143 * window area clipped by the client area of all ancestors) in the
144 * corresponding coordinates. Return FALSE if the visible region is empty.
146 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
148 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
150 if (wndPtr->dwStyle & WS_VISIBLE)
152 INT xoffset = lprect->left;
153 INT yoffset = lprect->top;
155 while ((wndPtr = WIN_FindWndPtr( GetAncestor(wndPtr->hwndSelf,GA_PARENT) )))
157 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
159 WIN_ReleaseWndPtr(wndPtr);
163 xoffset += wndPtr->rectClient.left;
164 yoffset += wndPtr->rectClient.top;
165 OffsetRect( lprect, wndPtr->rectClient.left,
166 wndPtr->rectClient.top );
168 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
169 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
170 (lprect->left >= wndPtr->rectClient.right) ||
171 (lprect->right <= wndPtr->rectClient.left) ||
172 (lprect->top >= wndPtr->rectClient.bottom) ||
173 (lprect->bottom <= wndPtr->rectClient.top) )
175 WIN_ReleaseWndPtr(wndPtr);
179 lprect->left = max( lprect->left, wndPtr->rectClient.left );
180 lprect->right = min( lprect->right, wndPtr->rectClient.right );
181 lprect->top = max( lprect->top, wndPtr->rectClient.top );
182 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
184 WIN_ReleaseWndPtr(wndPtr);
186 OffsetRect( lprect, -xoffset, -yoffset );
191 SetRectEmpty( lprect );
196 /***********************************************************************
199 * Go through the linked list of windows from pWndStart to pWndEnd,
200 * adding to the clip region the intersection of the target rectangle
201 * with an offset window rectangle.
203 static void DCE_AddClipRects( HWND parent, HWND end, HRGN hrgnClip, LPRECT lpRect, int x, int y )
208 HWND *list = WIN_ListChildren( parent );
211 for (i = 0; list[i]; i++)
213 if (list[i] == end) break;
214 if (!(pWnd = WIN_FindWndPtr( list[i] ))) continue;
215 if (pWnd->dwStyle & WS_VISIBLE)
217 rect.left = pWnd->rectWindow.left + x;
218 rect.top = pWnd->rectWindow.top + y;
219 rect.right = pWnd->rectWindow.right + x;
220 rect.bottom = pWnd->rectWindow.bottom + y;
221 if( IntersectRect( &rect, &rect, lpRect ))
223 if(!REGION_UnionRectWithRgn( hrgnClip, &rect ))
225 WIN_ReleaseWndPtr( pWnd );
230 WIN_ReleaseWndPtr( pWnd );
232 HeapFree( GetProcessHeap(), 0, list );
236 /***********************************************************************
239 * Return the visible region of a window, i.e. the client or window area
240 * clipped by the client area of all ancestors, and then optionally
241 * by siblings and children.
243 static HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
247 WND *wndPtr = WIN_FindWndPtr( hwnd );
248 WND *childWnd = WIN_FindWndPtr( hwndChild );
250 /* Get visible rectangle and create a region with it. */
252 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
254 if((hrgnVis = CreateRectRgnIndirect( &rect )))
256 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
257 INT xoffset, yoffset;
261 /* Compute obscured region for the visible rectangle by
262 * clipping children, siblings, and ancestors. Note that
263 * DCE_GetVisRect() returns a rectangle either in client
264 * or in window coordinates (for DCX_WINDOW request). */
266 if (flags & DCX_CLIPCHILDREN)
268 if( flags & DCX_WINDOW )
270 /* adjust offsets since child window rectangles are
271 * in client coordinates */
273 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
274 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
277 xoffset = yoffset = 0;
279 DCE_AddClipRects( wndPtr->hwndSelf, 0, hrgnClip, &rect, xoffset, yoffset );
282 /* We may need to clip children of child window, if a window with PARENTDC
283 * class style and CLIPCHILDREN window style (like in Free Agent 16
284 * preference dialogs) gets here, we take the region for the parent window
285 * but apparently still need to clip the children of the child window... */
287 if( (cflags & DCX_CLIPCHILDREN) && childWnd)
289 if( flags & DCX_WINDOW )
291 /* adjust offsets since child window rectangles are
292 * in client coordinates */
294 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
295 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
298 xoffset = yoffset = 0;
300 /* client coordinates of child window */
301 xoffset += childWnd->rectClient.left;
302 yoffset += childWnd->rectClient.top;
304 DCE_AddClipRects( childWnd->hwndSelf, 0, hrgnClip,
305 &rect, xoffset, yoffset );
308 /* sibling window rectangles are in client
309 * coordinates of the parent window */
311 if (flags & DCX_WINDOW)
313 xoffset = -wndPtr->rectWindow.left;
314 yoffset = -wndPtr->rectWindow.top;
318 xoffset = -wndPtr->rectClient.left;
319 yoffset = -wndPtr->rectClient.top;
322 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
323 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
324 hrgnClip, &rect, xoffset, yoffset );
326 /* Clip siblings of all ancestors that have the
327 * WS_CLIPSIBLINGS style
330 while (wndPtr->parent)
332 WND *ptr = WIN_FindWndPtr( wndPtr->parent );
333 WIN_ReleaseWndPtr( wndPtr );
335 xoffset -= wndPtr->rectClient.left;
336 yoffset -= wndPtr->rectClient.top;
337 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
339 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
340 hrgnClip, &rect, xoffset, yoffset );
344 /* Now once we've got a jumbo clip region we have
345 * to substract it from the visible rectangle.
347 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
348 DeleteObject( hrgnClip );
352 DeleteObject( hrgnVis );
358 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
359 WIN_ReleaseWndPtr(wndPtr);
360 WIN_ReleaseWndPtr(childWnd);
365 /***********************************************************************
368 * Set the drawable, origin and dimensions for the DC associated to
371 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
373 WND *wndPtr = WIN_FindWndPtr(hwnd);
376 HRGN hrgnVisible = 0;
378 if (!wndPtr) return FALSE;
380 if (!(dc = DC_GetDCPtr( hdc )))
382 WIN_ReleaseWndPtr( wndPtr );
386 if(flags & DCX_WINDOW)
388 dc->DCOrgX = wndPtr->rectWindow.left;
389 dc->DCOrgY = wndPtr->rectWindow.top;
393 dc->DCOrgX = wndPtr->rectClient.left;
394 dc->DCOrgY = wndPtr->rectClient.top;
396 updateVisRgn = (dc->flags & DC_DIRTY) != 0;
397 GDI_ReleaseObj( hdc );
401 if (flags & DCX_PARENTCLIP)
403 WND *parentPtr = WIN_FindWndPtr( wndPtr->parent );
405 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
409 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
410 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
412 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
414 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
415 wndPtr->hwndSelf, flags );
416 if( flags & DCX_WINDOW )
417 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
418 -wndPtr->rectWindow.top );
420 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
421 -wndPtr->rectClient.top );
422 DCE_OffsetVisRgn( hdc, hrgnVisible );
425 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
426 WIN_ReleaseWndPtr(parentPtr);
430 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
431 DCE_OffsetVisRgn( hdc, hrgnVisible );
433 SelectVisRgn16( hdc, hrgnVisible );
436 /* apply additional region operation (if any) */
438 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
440 if( !hrgnVisible ) hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
442 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgn);
445 CombineRgn( hrgnVisible, hrgn, 0, RGN_COPY );
446 DCE_OffsetVisRgn( hdc, hrgnVisible );
447 CombineRgn( hrgnVisible, InquireVisRgn16( hdc ), hrgnVisible,
448 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
449 SelectVisRgn16( hdc, hrgnVisible );
452 if (hrgnVisible) DeleteObject( hrgnVisible );
454 WIN_ReleaseWndPtr( wndPtr );
459 /***********************************************************************
460 * SetWindowPos (TTYDRV.@)
462 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
465 RECT newWindowRect, newClientRect;
467 HWND hwndActive = GetForegroundWindow();
469 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
470 winpos->hwnd, winpos->x, winpos->y,
471 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
473 /* ------------------------------------------------------------------------ CHECKS */
475 /* Check window handle */
477 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
478 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
480 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
481 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
482 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
484 /* Fix redundant flags */
486 if(wndPtr->dwStyle & WS_VISIBLE)
487 winpos->flags &= ~SWP_SHOWWINDOW;
490 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
491 winpos->flags &= ~SWP_HIDEWINDOW;
494 if ( winpos->cx < 0 ) winpos->cx = 0;
495 if ( winpos->cy < 0 ) winpos->cy = 0;
497 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
498 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
499 winpos->flags |= SWP_NOSIZE; /* Already the right size */
501 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
502 winpos->flags |= SWP_NOMOVE; /* Already the right position */
504 if (winpos->hwnd == hwndActive)
505 winpos->flags |= SWP_NOACTIVATE; /* Already active */
506 else if ( (wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD )
508 if(!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
510 winpos->flags &= ~SWP_NOZORDER;
511 winpos->hwndInsertAfter = HWND_TOP;
516 /* Check hwndInsertAfter */
518 /* FIXME: TOPMOST not supported yet */
519 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
520 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
522 /* hwndInsertAfter must be a sibling of the window */
523 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
525 WND* wnd = WIN_FindWndPtr(winpos->hwndInsertAfter);
528 if( wnd->parent != wndPtr->parent )
531 WIN_ReleaseWndPtr(wnd);
534 /* don't need to change the Zorder of hwnd if it's already inserted
535 * after hwndInsertAfter or when inserting hwnd after itself.
537 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
538 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
539 winpos->flags |= SWP_NOZORDER;
541 WIN_ReleaseWndPtr(wnd);
544 Pos: /* ------------------------------------------------------------------------ MAIN part */
546 /* Send WM_WINDOWPOSCHANGING message */
548 if (!(winpos->flags & SWP_NOSENDCHANGING))
549 SendMessageA( wndPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos );
551 /* Calculate new position and size */
553 newWindowRect = wndPtr->rectWindow;
554 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
555 : wndPtr->rectClient;
557 if (!(winpos->flags & SWP_NOSIZE))
559 newWindowRect.right = newWindowRect.left + winpos->cx;
560 newWindowRect.bottom = newWindowRect.top + winpos->cy;
562 if (!(winpos->flags & SWP_NOMOVE))
564 newWindowRect.left = winpos->x;
565 newWindowRect.top = winpos->y;
566 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
567 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
569 OffsetRect( &newClientRect, winpos->x - wndPtr->rectWindow.left,
570 winpos->y - wndPtr->rectWindow.top );
573 if( winpos->hwndInsertAfter == HWND_TOP )
575 if (GetWindow( wndPtr->hwndSelf, GW_HWNDFIRST ) == wndPtr->hwndSelf)
576 winpos->flags |= SWP_NOZORDER;
579 if( winpos->hwndInsertAfter == HWND_BOTTOM )
581 if (!GetWindow( wndPtr->hwndSelf, GW_HWNDNEXT ))
582 winpos->flags |= SWP_NOZORDER;
585 if( !(winpos->flags & SWP_NOZORDER) )
586 if( GetWindow(winpos->hwndInsertAfter, GW_HWNDNEXT) == wndPtr->hwndSelf )
587 winpos->flags |= SWP_NOZORDER;
589 /* Common operations */
591 /* Send WM_NCCALCSIZE message to get new client area */
592 if( (winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
594 NCCALCSIZE_PARAMS params;
595 WINDOWPOS winposCopy;
597 params.rgrc[0] = newWindowRect;
598 params.rgrc[1] = wndPtr->rectWindow;
599 params.rgrc[2] = wndPtr->rectClient;
600 params.lppos = &winposCopy;
601 winposCopy = *winpos;
603 SendMessageW( winpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
605 TRACE( "%d,%d-%d,%d\n", params.rgrc[0].left, params.rgrc[0].top,
606 params.rgrc[0].right, params.rgrc[0].bottom );
608 /* If the application send back garbage, ignore it */
609 if (params.rgrc[0].left <= params.rgrc[0].right &&
610 params.rgrc[0].top <= params.rgrc[0].bottom)
611 newClientRect = params.rgrc[0];
613 /* FIXME: WVR_ALIGNxxx */
615 if( newClientRect.left != wndPtr->rectClient.left ||
616 newClientRect.top != wndPtr->rectClient.top )
617 winpos->flags &= ~SWP_NOCLIENTMOVE;
619 if( (newClientRect.right - newClientRect.left !=
620 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
621 (newClientRect.bottom - newClientRect.top !=
622 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
623 winpos->flags &= ~SWP_NOCLIENTSIZE;
626 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
628 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
629 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
632 /* FIXME: actually do something with WVR_VALIDRECTS */
634 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
636 if( winpos->flags & SWP_SHOWWINDOW )
637 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle | WS_VISIBLE );
638 else if( winpos->flags & SWP_HIDEWINDOW )
639 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
641 /* ------------------------------------------------------------------------ FINAL */
643 /* repaint invalidated region (if any)
645 * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
646 * and force update after ChangeActiveWindow() to avoid painting frames twice.
649 if( !(winpos->flags & SWP_NOREDRAW) )
651 RedrawWindow( wndPtr->parent, NULL, 0,
652 RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN );
653 if (wndPtr->parent == GetDesktopWindow())
654 RedrawWindow( wndPtr->parent, NULL, 0,
655 RDW_ERASENOW | RDW_NOCHILDREN );
658 if (!(winpos->flags & SWP_NOACTIVATE)) SetActiveWindow( winpos->hwnd );
660 /* And last, send the WM_WINDOWPOSCHANGED message */
662 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
664 if ((((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
665 !(winpos->flags & SWP_NOSENDCHANGING)) )
666 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
670 WIN_ReleaseWndPtr(wndPtr);
675 /***********************************************************************
676 * WINPOS_MinMaximize (internal)
678 *Lifted from x11 driver
680 static UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
686 TRACE("0x%04x %u\n", hwnd, cmd );
687 FIXME("(%x): stub\n", hwnd);
689 wpl.length = sizeof(wpl);
690 GetWindowPlacement( hwnd, &wpl );
692 /* If I glark this right, yields an immutable window*/
693 swpFlags = SWP_NOSIZE | SWP_NOMOVE;
695 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
697 /*cmd handling goes here. see dlls/x1drv/winpos.c*/
699 WIN_ReleaseWndPtr( wndPtr );
703 /***********************************************************************
704 * ShowWindow (TTYDRV.@)
706 *Lifted from x11 driver
707 *Sets the specified windows' show state.
709 BOOL TTYDRV_ShowWindow( HWND hwnd, INT cmd )
711 WND* wndPtr = WIN_FindWndPtr( hwnd );
712 BOOL wasVisible, showFlag;
713 RECT newPos = {0, 0, 0, 0};
716 if (!wndPtr) return FALSE;
717 hwnd = wndPtr->hwndSelf; /* make it a full handle */
719 TRACE("hwnd=%04x, cmd=%d\n", hwnd, cmd);
721 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
726 if (!wasVisible) goto END;;
727 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
728 SWP_NOACTIVATE | SWP_NOZORDER;
731 case SW_SHOWMINNOACTIVE:
732 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
734 case SW_SHOWMINIMIZED:
735 swp |= SWP_SHOWWINDOW;
738 swp |= SWP_FRAMECHANGED;
739 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
740 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
741 else swp |= SWP_NOSIZE | SWP_NOMOVE;
744 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
745 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
746 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
747 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
748 else swp |= SWP_NOSIZE | SWP_NOMOVE;
752 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
755 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
758 * ShowWindow has a little peculiar behavior that if the
759 * window is already the topmost window, it will not
762 if (GetTopWindow((HWND)0)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
763 swp |= SWP_NOACTIVATE;
767 case SW_SHOWNOACTIVATE:
769 if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
771 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
772 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
774 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
776 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
777 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
778 else swp |= SWP_NOSIZE | SWP_NOMOVE;
782 showFlag = (cmd != SW_HIDE);
783 if (showFlag != wasVisible)
785 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
786 if (!IsWindow( hwnd )) goto END;
789 /* We can't activate a child window */
790 if ((wndPtr->dwStyle & WS_CHILD) &&
791 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
792 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
794 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
795 newPos.right, newPos.bottom, LOWORD(swp) );
798 /* FIXME: This will cause the window to be activated irrespective
799 * of whether it is owned by the same thread. Has to be done
803 if (hwnd == GetActiveWindow())
804 WINPOS_ActivateOtherWindow(hwnd);
806 /* Revert focus to parent */
807 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
808 SetFocus( GetParent(hwnd) );
810 if (!IsWindow( hwnd )) goto END;
811 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
813 if (wndPtr->flags & WIN_NEED_SIZE)
815 /* should happen only in CreateWindowEx() */
816 int wParam = SIZE_RESTORED;
818 wndPtr->flags &= ~WIN_NEED_SIZE;
819 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
820 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
821 SendMessageA( hwnd, WM_SIZE, wParam,
822 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
823 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
824 SendMessageA( hwnd, WM_MOVE, 0,
825 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
829 WIN_ReleaseWndPtr(wndPtr);