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
27 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
32 #define SWP_AGG_NOGEOMETRYCHANGE \
33 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
34 #define SWP_AGG_NOPOSCHANGE \
35 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
36 #define SWP_AGG_STATUSFLAGS \
37 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
39 /**********************************************************************
40 * CreateWindow (TTYDRV.@)
42 BOOL TTYDRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
48 WND *wndPtr = WIN_GetPtr( hwnd );
50 INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
52 TRACE("(%x)\n", hwnd);
54 /* Only create top-level windows */
55 if (!(wndPtr->dwStyle & WS_CHILD))
57 if (!wndPtr->parent) /* desktop */
61 int x = wndPtr->rectWindow.left;
62 int y = wndPtr->rectWindow.top;
63 int cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
64 int cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
66 window = subwin( root_window, cy/cellHeight, cx/cellWidth,
67 y/cellHeight, x/cellWidth);
71 wndPtr->pDriverData = window;
73 WIN_ReleasePtr( wndPtr );
74 #else /* defined(WINE_CURSES) */
75 FIXME("(%x): stub\n", hwnd);
76 #endif /* defined(WINE_CURSES) */
78 /* Call the WH_CBT hook */
80 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
81 ? HWND_BOTTOM : HWND_TOP;
83 if (HOOK_IsHooked( WH_CBT ))
89 cbtc.hwndInsertAfter = hwndLinkAfter;
90 lret = (unicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND,
91 (WPARAM)hwnd, (LPARAM)&cbtc)
92 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND,
93 (WPARAM)hwnd, (LPARAM)&cbtc);
96 TRACE("CBT-hook returned !0\n");
103 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
104 if (ret) ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
108 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
109 if (ret) ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
114 /***********************************************************************
115 * DestroyWindow (TTYDRV.@)
117 BOOL TTYDRV_DestroyWindow( HWND hwnd )
120 WND *wndPtr = WIN_GetPtr( hwnd );
121 WINDOW *window = wndPtr->pDriverData;
123 TRACE("(%x)\n", hwnd);
125 if (window && window != root_window) delwin(window);
126 wndPtr->pDriverData = NULL;
127 WIN_ReleasePtr( wndPtr );
128 #else /* defined(WINE_CURSES) */
129 FIXME("(%x): stub\n", hwnd);
130 #endif /* defined(WINE_CURSES) */
135 /***********************************************************************
138 * Calculate the visible rectangle of a window (i.e. the client or
139 * window area clipped by the client area of all ancestors) in the
140 * corresponding coordinates. Return FALSE if the visible region is empty.
142 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
144 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
146 if (wndPtr->dwStyle & WS_VISIBLE)
148 INT xoffset = lprect->left;
149 INT yoffset = lprect->top;
151 while ((wndPtr = WIN_FindWndPtr( GetAncestor(wndPtr->hwndSelf,GA_PARENT) )))
153 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
155 WIN_ReleaseWndPtr(wndPtr);
159 xoffset += wndPtr->rectClient.left;
160 yoffset += wndPtr->rectClient.top;
161 OffsetRect( lprect, wndPtr->rectClient.left,
162 wndPtr->rectClient.top );
164 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
165 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
166 (lprect->left >= wndPtr->rectClient.right) ||
167 (lprect->right <= wndPtr->rectClient.left) ||
168 (lprect->top >= wndPtr->rectClient.bottom) ||
169 (lprect->bottom <= wndPtr->rectClient.top) )
171 WIN_ReleaseWndPtr(wndPtr);
175 lprect->left = max( lprect->left, wndPtr->rectClient.left );
176 lprect->right = min( lprect->right, wndPtr->rectClient.right );
177 lprect->top = max( lprect->top, wndPtr->rectClient.top );
178 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
180 WIN_ReleaseWndPtr(wndPtr);
182 OffsetRect( lprect, -xoffset, -yoffset );
187 SetRectEmpty( lprect );
192 /***********************************************************************
195 * Go through the linked list of windows from pWndStart to pWndEnd,
196 * adding to the clip region the intersection of the target rectangle
197 * with an offset window rectangle.
199 static void DCE_AddClipRects( HWND parent, HWND end, HRGN hrgnClip, LPRECT lpRect, int x, int y )
204 HWND *list = WIN_ListChildren( parent );
208 for (i = 0; list[i]; i++)
210 if (list[i] == end) break;
211 if (!(pWnd = WIN_FindWndPtr( list[i] ))) continue;
212 if (pWnd->dwStyle & WS_VISIBLE)
214 rect.left = pWnd->rectWindow.left + x;
215 rect.top = pWnd->rectWindow.top + y;
216 rect.right = pWnd->rectWindow.right + x;
217 rect.bottom = pWnd->rectWindow.bottom + y;
218 if( IntersectRect( &rect, &rect, lpRect ))
220 if (!hrgn) hrgn = CreateRectRgnIndirect( &rect );
221 else SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
222 CombineRgn( hrgnClip, hrgnClip, hrgn, RGN_OR );
225 WIN_ReleaseWndPtr( pWnd );
227 if (hrgn) DeleteObject( hrgn );
228 HeapFree( GetProcessHeap(), 0, list );
232 /***********************************************************************
235 * Return the visible region of a window, i.e. the client or window area
236 * clipped by the client area of all ancestors, and then optionally
237 * by siblings and children.
239 static HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
243 WND *wndPtr = WIN_FindWndPtr( hwnd );
244 WND *childWnd = WIN_FindWndPtr( hwndChild );
246 /* Get visible rectangle and create a region with it. */
248 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
250 if((hrgnVis = CreateRectRgnIndirect( &rect )))
252 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
253 INT xoffset, yoffset;
257 /* Compute obscured region for the visible rectangle by
258 * clipping children, siblings, and ancestors. Note that
259 * DCE_GetVisRect() returns a rectangle either in client
260 * or in window coordinates (for DCX_WINDOW request). */
262 if (flags & DCX_CLIPCHILDREN)
264 if( flags & DCX_WINDOW )
266 /* adjust offsets since child window rectangles are
267 * in client coordinates */
269 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
270 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
273 xoffset = yoffset = 0;
275 DCE_AddClipRects( wndPtr->hwndSelf, 0, hrgnClip, &rect, xoffset, yoffset );
278 /* We may need to clip children of child window, if a window with PARENTDC
279 * class style and CLIPCHILDREN window style (like in Free Agent 16
280 * preference dialogs) gets here, we take the region for the parent window
281 * but apparently still need to clip the children of the child window... */
283 if( (cflags & DCX_CLIPCHILDREN) && childWnd)
285 if( flags & DCX_WINDOW )
287 /* adjust offsets since child window rectangles are
288 * in client coordinates */
290 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
291 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
294 xoffset = yoffset = 0;
296 /* client coordinates of child window */
297 xoffset += childWnd->rectClient.left;
298 yoffset += childWnd->rectClient.top;
300 DCE_AddClipRects( childWnd->hwndSelf, 0, hrgnClip,
301 &rect, xoffset, yoffset );
304 /* sibling window rectangles are in client
305 * coordinates of the parent window */
307 if (flags & DCX_WINDOW)
309 xoffset = -wndPtr->rectWindow.left;
310 yoffset = -wndPtr->rectWindow.top;
314 xoffset = -wndPtr->rectClient.left;
315 yoffset = -wndPtr->rectClient.top;
318 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
319 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
320 hrgnClip, &rect, xoffset, yoffset );
322 /* Clip siblings of all ancestors that have the
323 * WS_CLIPSIBLINGS style
326 while (wndPtr->parent)
328 WND *ptr = WIN_FindWndPtr( wndPtr->parent );
329 WIN_ReleaseWndPtr( wndPtr );
331 xoffset -= wndPtr->rectClient.left;
332 yoffset -= wndPtr->rectClient.top;
333 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
335 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
336 hrgnClip, &rect, xoffset, yoffset );
340 /* Now once we've got a jumbo clip region we have
341 * to substract it from the visible rectangle.
343 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
344 DeleteObject( hrgnClip );
348 DeleteObject( hrgnVis );
354 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
355 WIN_ReleaseWndPtr(wndPtr);
356 WIN_ReleaseWndPtr(childWnd);
361 /***********************************************************************
364 * Set the drawable, origin and dimensions for the DC associated to
367 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
369 WND *wndPtr = WIN_FindWndPtr(hwnd);
370 HRGN hrgnVisible = 0;
373 if (!wndPtr) return FALSE;
375 if(flags & DCX_WINDOW)
377 org.x = wndPtr->rectWindow.left;
378 org.y = wndPtr->rectWindow.top;
382 org.x = wndPtr->rectClient.left;
383 org.y = wndPtr->rectClient.top;
386 SetDCOrg16( hdc, org.x, org.y );
388 if (SetHookFlags16( hdc, DCHF_VALIDATEVISRGN )) /* DC was dirty */
390 if (flags & DCX_PARENTCLIP)
392 WND *parentPtr = WIN_FindWndPtr( wndPtr->parent );
394 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
398 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
399 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
401 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
403 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
404 wndPtr->hwndSelf, flags );
405 if( flags & DCX_WINDOW )
406 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
407 -wndPtr->rectWindow.top );
409 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
410 -wndPtr->rectClient.top );
413 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
414 WIN_ReleaseWndPtr(parentPtr);
418 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
419 OffsetRgn( hrgnVisible, org.x, org.y );
421 SelectVisRgn16( hdc, hrgnVisible );
424 /* apply additional region operation (if any) */
426 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
428 if( !hrgnVisible ) hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
430 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgn);
433 CombineRgn( hrgnVisible, hrgn, 0, RGN_COPY );
434 OffsetRgn( hrgnVisible, org.x, org.y );
435 CombineRgn( hrgnVisible, InquireVisRgn16( hdc ), hrgnVisible,
436 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
437 SelectVisRgn16( hdc, hrgnVisible );
440 if (hrgnVisible) DeleteObject( hrgnVisible );
442 WIN_ReleaseWndPtr( wndPtr );
447 /***********************************************************************
448 * SetWindowPos (TTYDRV.@)
450 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
453 RECT newWindowRect, newClientRect;
455 HWND hwndActive = GetForegroundWindow();
457 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
458 winpos->hwnd, winpos->x, winpos->y,
459 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
461 /* ------------------------------------------------------------------------ CHECKS */
463 /* Check window handle */
465 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
466 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
468 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
469 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
470 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
472 /* Fix redundant flags */
474 if(wndPtr->dwStyle & WS_VISIBLE)
475 winpos->flags &= ~SWP_SHOWWINDOW;
478 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
479 winpos->flags &= ~SWP_HIDEWINDOW;
482 if ( winpos->cx < 0 ) winpos->cx = 0;
483 if ( winpos->cy < 0 ) winpos->cy = 0;
485 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
486 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
487 winpos->flags |= SWP_NOSIZE; /* Already the right size */
489 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
490 winpos->flags |= SWP_NOMOVE; /* Already the right position */
492 if (winpos->hwnd == hwndActive)
493 winpos->flags |= SWP_NOACTIVATE; /* Already active */
494 else if ( (wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD )
496 if(!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
498 winpos->flags &= ~SWP_NOZORDER;
499 winpos->hwndInsertAfter = HWND_TOP;
504 /* Check hwndInsertAfter */
506 /* FIXME: TOPMOST not supported yet */
507 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
508 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
510 /* hwndInsertAfter must be a sibling of the window */
511 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
513 WND* wnd = WIN_FindWndPtr(winpos->hwndInsertAfter);
516 if( wnd->parent != wndPtr->parent )
519 WIN_ReleaseWndPtr(wnd);
522 /* don't need to change the Zorder of hwnd if it's already inserted
523 * after hwndInsertAfter or when inserting hwnd after itself.
525 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
526 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
527 winpos->flags |= SWP_NOZORDER;
529 WIN_ReleaseWndPtr(wnd);
532 Pos: /* ------------------------------------------------------------------------ MAIN part */
534 /* Send WM_WINDOWPOSCHANGING message */
536 if (!(winpos->flags & SWP_NOSENDCHANGING))
537 SendMessageA( wndPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos );
539 /* Calculate new position and size */
541 newWindowRect = wndPtr->rectWindow;
542 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
543 : wndPtr->rectClient;
545 if (!(winpos->flags & SWP_NOSIZE))
547 newWindowRect.right = newWindowRect.left + winpos->cx;
548 newWindowRect.bottom = newWindowRect.top + winpos->cy;
550 if (!(winpos->flags & SWP_NOMOVE))
552 newWindowRect.left = winpos->x;
553 newWindowRect.top = winpos->y;
554 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
555 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
557 OffsetRect( &newClientRect, winpos->x - wndPtr->rectWindow.left,
558 winpos->y - wndPtr->rectWindow.top );
561 if( winpos->hwndInsertAfter == HWND_TOP )
563 if (GetWindow( wndPtr->hwndSelf, GW_HWNDFIRST ) == wndPtr->hwndSelf)
564 winpos->flags |= SWP_NOZORDER;
567 if( winpos->hwndInsertAfter == HWND_BOTTOM )
569 if (!GetWindow( wndPtr->hwndSelf, GW_HWNDNEXT ))
570 winpos->flags |= SWP_NOZORDER;
573 if( !(winpos->flags & SWP_NOZORDER) )
574 if( GetWindow(winpos->hwndInsertAfter, GW_HWNDNEXT) == wndPtr->hwndSelf )
575 winpos->flags |= SWP_NOZORDER;
577 /* Common operations */
579 /* Send WM_NCCALCSIZE message to get new client area */
580 if( (winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
582 NCCALCSIZE_PARAMS params;
583 WINDOWPOS winposCopy;
585 params.rgrc[0] = newWindowRect;
586 params.rgrc[1] = wndPtr->rectWindow;
587 params.rgrc[2] = wndPtr->rectClient;
588 params.lppos = &winposCopy;
589 winposCopy = *winpos;
591 SendMessageW( winpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
593 TRACE( "%d,%d-%d,%d\n", params.rgrc[0].left, params.rgrc[0].top,
594 params.rgrc[0].right, params.rgrc[0].bottom );
596 /* If the application send back garbage, ignore it */
597 if (params.rgrc[0].left <= params.rgrc[0].right &&
598 params.rgrc[0].top <= params.rgrc[0].bottom)
599 newClientRect = params.rgrc[0];
601 /* FIXME: WVR_ALIGNxxx */
603 if( newClientRect.left != wndPtr->rectClient.left ||
604 newClientRect.top != wndPtr->rectClient.top )
605 winpos->flags &= ~SWP_NOCLIENTMOVE;
607 if( (newClientRect.right - newClientRect.left !=
608 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
609 (newClientRect.bottom - newClientRect.top !=
610 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
611 winpos->flags &= ~SWP_NOCLIENTSIZE;
614 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
616 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
617 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
620 /* FIXME: actually do something with WVR_VALIDRECTS */
622 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
624 if( winpos->flags & SWP_SHOWWINDOW )
625 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle | WS_VISIBLE );
626 else if( winpos->flags & SWP_HIDEWINDOW )
627 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
629 /* ------------------------------------------------------------------------ FINAL */
631 /* repaint invalidated region (if any)
633 * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
634 * and force update after ChangeActiveWindow() to avoid painting frames twice.
637 if( !(winpos->flags & SWP_NOREDRAW) )
639 RedrawWindow( wndPtr->parent, NULL, 0,
640 RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN );
641 if (wndPtr->parent == GetDesktopWindow())
642 RedrawWindow( wndPtr->parent, NULL, 0,
643 RDW_ERASENOW | RDW_NOCHILDREN );
646 if (!(winpos->flags & SWP_NOACTIVATE)) SetActiveWindow( winpos->hwnd );
648 /* And last, send the WM_WINDOWPOSCHANGED message */
650 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
652 if ((((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
653 !(winpos->flags & SWP_NOSENDCHANGING)) )
654 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
658 WIN_ReleaseWndPtr(wndPtr);
663 /***********************************************************************
664 * WINPOS_MinMaximize (internal)
666 *Lifted from x11 driver
668 static UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
673 TRACE("0x%04x %u\n", hwnd, cmd );
674 FIXME("(%x): stub\n", hwnd);
676 wpl.length = sizeof(wpl);
677 GetWindowPlacement( hwnd, &wpl );
679 /* If I glark this right, yields an immutable window*/
680 swpFlags = SWP_NOSIZE | SWP_NOMOVE;
682 /*cmd handling goes here. see dlls/x1drv/winpos.c*/
687 /***********************************************************************
688 * ShowWindow (TTYDRV.@)
690 *Lifted from x11 driver
691 *Sets the specified windows' show state.
693 BOOL TTYDRV_ShowWindow( HWND hwnd, INT cmd )
695 WND* wndPtr = WIN_FindWndPtr( hwnd );
696 BOOL wasVisible, showFlag;
697 RECT newPos = {0, 0, 0, 0};
700 if (!wndPtr) return FALSE;
701 hwnd = wndPtr->hwndSelf; /* make it a full handle */
703 TRACE("hwnd=%04x, cmd=%d\n", hwnd, cmd);
705 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
710 if (!wasVisible) goto END;
711 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
712 SWP_NOACTIVATE | SWP_NOZORDER;
715 case SW_SHOWMINNOACTIVE:
716 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
718 case SW_SHOWMINIMIZED:
719 swp |= SWP_SHOWWINDOW;
722 swp |= SWP_FRAMECHANGED;
723 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
724 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
725 else swp |= SWP_NOSIZE | SWP_NOMOVE;
728 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
729 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
730 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
731 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
732 else swp |= SWP_NOSIZE | SWP_NOMOVE;
736 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
739 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
742 * ShowWindow has a little peculiar behavior that if the
743 * window is already the topmost window, it will not
746 if (GetTopWindow((HWND)0)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
747 swp |= SWP_NOACTIVATE;
751 case SW_SHOWNOACTIVATE:
753 if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
755 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
756 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
758 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
760 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
761 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
762 else swp |= SWP_NOSIZE | SWP_NOMOVE;
766 showFlag = (cmd != SW_HIDE);
767 if (showFlag != wasVisible)
769 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
770 if (!IsWindow( hwnd )) goto END;
773 /* We can't activate a child window */
774 if ((wndPtr->dwStyle & WS_CHILD) &&
775 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
776 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
778 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
779 newPos.right, newPos.bottom, LOWORD(swp) );
782 /* FIXME: This will cause the window to be activated irrespective
783 * of whether it is owned by the same thread. Has to be done
787 if (hwnd == GetActiveWindow())
788 WINPOS_ActivateOtherWindow(hwnd);
790 /* Revert focus to parent */
791 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
792 SetFocus( GetParent(hwnd) );
794 if (!IsWindow( hwnd )) goto END;
795 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
797 if (wndPtr->flags & WIN_NEED_SIZE)
799 /* should happen only in CreateWindowEx() */
800 int wParam = SIZE_RESTORED;
802 wndPtr->flags &= ~WIN_NEED_SIZE;
803 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
804 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
805 SendMessageA( hwnd, WM_SIZE, wParam,
806 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
807 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
808 SendMessageA( hwnd, WM_MOVE, 0,
809 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
813 WIN_ReleaseWndPtr(wndPtr);