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/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
33 #define SWP_AGG_NOGEOMETRYCHANGE \
34 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
35 #define SWP_AGG_NOPOSCHANGE \
36 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
37 #define SWP_AGG_STATUSFLAGS \
38 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
40 /**********************************************************************
41 * CreateWindow (TTYDRV.@)
43 BOOL TTYDRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
49 WND *wndPtr = WIN_FindWndPtr( hwnd );
51 INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
53 TRACE("(%x)\n", hwnd);
55 /* Only create top-level windows */
56 if (!(wndPtr->dwStyle & WS_CHILD))
58 if (!wndPtr->parent) /* desktop */
62 int x = wndPtr->rectWindow.left;
63 int y = wndPtr->rectWindow.top;
64 int cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
65 int cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
67 window = subwin( root_window, cy/cellHeight, cx/cellWidth,
68 y/cellHeight, x/cellWidth);
72 wndPtr->pDriverData = window;
74 WIN_ReleaseWndPtr( wndPtr );
75 #else /* defined(WINE_CURSES) */
76 FIXME("(%x): stub\n", hwnd);
77 #endif /* defined(WINE_CURSES) */
79 /* Call the WH_CBT hook */
81 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
82 ? HWND_BOTTOM : HWND_TOP;
84 if (HOOK_IsHooked( WH_CBT ))
90 cbtc.hwndInsertAfter = hwndLinkAfter;
91 lret = (unicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND,
92 (WPARAM)hwnd, (LPARAM)&cbtc)
93 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND,
94 (WPARAM)hwnd, (LPARAM)&cbtc);
97 TRACE("CBT-hook returned !0\n");
104 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
105 if (ret) ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
109 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
110 if (ret) ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
115 /***********************************************************************
116 * DestroyWindow (TTYDRV.@)
118 BOOL TTYDRV_DestroyWindow( HWND hwnd )
121 WND *wndPtr = WIN_FindWndPtr( hwnd );
122 WINDOW *window = wndPtr->pDriverData;
124 TRACE("(%x)\n", hwnd);
126 if (window && window != root_window) delwin(window);
127 wndPtr->pDriverData = NULL;
128 WIN_ReleaseWndPtr( wndPtr );
129 #else /* defined(WINE_CURSES) */
130 FIXME("(%x): stub\n", hwnd);
131 #endif /* defined(WINE_CURSES) */
136 /***********************************************************************
139 * Calculate the visible rectangle of a window (i.e. the client or
140 * window area clipped by the client area of all ancestors) in the
141 * corresponding coordinates. Return FALSE if the visible region is empty.
143 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
145 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
147 if (wndPtr->dwStyle & WS_VISIBLE)
149 INT xoffset = lprect->left;
150 INT yoffset = lprect->top;
152 while ((wndPtr = WIN_FindWndPtr( GetAncestor(wndPtr->hwndSelf,GA_PARENT) )))
154 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
156 WIN_ReleaseWndPtr(wndPtr);
160 xoffset += wndPtr->rectClient.left;
161 yoffset += wndPtr->rectClient.top;
162 OffsetRect( lprect, wndPtr->rectClient.left,
163 wndPtr->rectClient.top );
165 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
166 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
167 (lprect->left >= wndPtr->rectClient.right) ||
168 (lprect->right <= wndPtr->rectClient.left) ||
169 (lprect->top >= wndPtr->rectClient.bottom) ||
170 (lprect->bottom <= wndPtr->rectClient.top) )
172 WIN_ReleaseWndPtr(wndPtr);
176 lprect->left = max( lprect->left, wndPtr->rectClient.left );
177 lprect->right = min( lprect->right, wndPtr->rectClient.right );
178 lprect->top = max( lprect->top, wndPtr->rectClient.top );
179 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
181 WIN_ReleaseWndPtr(wndPtr);
183 OffsetRect( lprect, -xoffset, -yoffset );
188 SetRectEmpty( lprect );
193 /***********************************************************************
196 * Go through the linked list of windows from pWndStart to pWndEnd,
197 * adding to the clip region the intersection of the target rectangle
198 * with an offset window rectangle.
200 static void DCE_AddClipRects( HWND parent, HWND end, HRGN hrgnClip, LPRECT lpRect, int x, int y )
205 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(!REGION_UnionRectWithRgn( hrgnClip, &rect ))
222 WIN_ReleaseWndPtr( pWnd );
227 WIN_ReleaseWndPtr( pWnd );
229 HeapFree( GetProcessHeap(), 0, list );
233 /***********************************************************************
236 * Return the visible region of a window, i.e. the client or window area
237 * clipped by the client area of all ancestors, and then optionally
238 * by siblings and children.
240 static HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
244 WND *wndPtr = WIN_FindWndPtr( hwnd );
245 WND *childWnd = WIN_FindWndPtr( hwndChild );
247 /* Get visible rectangle and create a region with it. */
249 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
251 if((hrgnVis = CreateRectRgnIndirect( &rect )))
253 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
254 INT xoffset, yoffset;
258 /* Compute obscured region for the visible rectangle by
259 * clipping children, siblings, and ancestors. Note that
260 * DCE_GetVisRect() returns a rectangle either in client
261 * or in window coordinates (for DCX_WINDOW request). */
263 if (flags & DCX_CLIPCHILDREN)
265 if( flags & DCX_WINDOW )
267 /* adjust offsets since child window rectangles are
268 * in client coordinates */
270 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
271 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
274 xoffset = yoffset = 0;
276 DCE_AddClipRects( wndPtr->hwndSelf, 0, hrgnClip, &rect, xoffset, yoffset );
279 /* We may need to clip children of child window, if a window with PARENTDC
280 * class style and CLIPCHILDREN window style (like in Free Agent 16
281 * preference dialogs) gets here, we take the region for the parent window
282 * but apparently still need to clip the children of the child window... */
284 if( (cflags & DCX_CLIPCHILDREN) && childWnd)
286 if( flags & DCX_WINDOW )
288 /* adjust offsets since child window rectangles are
289 * in client coordinates */
291 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
292 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
295 xoffset = yoffset = 0;
297 /* client coordinates of child window */
298 xoffset += childWnd->rectClient.left;
299 yoffset += childWnd->rectClient.top;
301 DCE_AddClipRects( childWnd->hwndSelf, 0, hrgnClip,
302 &rect, xoffset, yoffset );
305 /* sibling window rectangles are in client
306 * coordinates of the parent window */
308 if (flags & DCX_WINDOW)
310 xoffset = -wndPtr->rectWindow.left;
311 yoffset = -wndPtr->rectWindow.top;
315 xoffset = -wndPtr->rectClient.left;
316 yoffset = -wndPtr->rectClient.top;
319 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
320 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
321 hrgnClip, &rect, xoffset, yoffset );
323 /* Clip siblings of all ancestors that have the
324 * WS_CLIPSIBLINGS style
327 while (wndPtr->parent)
329 WND *ptr = WIN_FindWndPtr( wndPtr->parent );
330 WIN_ReleaseWndPtr( wndPtr );
332 xoffset -= wndPtr->rectClient.left;
333 yoffset -= wndPtr->rectClient.top;
334 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
336 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
337 hrgnClip, &rect, xoffset, yoffset );
341 /* Now once we've got a jumbo clip region we have
342 * to substract it from the visible rectangle.
344 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
345 DeleteObject( hrgnClip );
349 DeleteObject( hrgnVis );
355 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
356 WIN_ReleaseWndPtr(wndPtr);
357 WIN_ReleaseWndPtr(childWnd);
362 /***********************************************************************
365 * Set the drawable, origin and dimensions for the DC associated to
368 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
370 WND *wndPtr = WIN_FindWndPtr(hwnd);
373 HRGN hrgnVisible = 0;
376 if (!wndPtr) return FALSE;
378 if(flags & DCX_WINDOW)
380 org.x = wndPtr->rectWindow.left;
381 org.y = wndPtr->rectWindow.top;
385 org.x = wndPtr->rectClient.left;
386 org.y = wndPtr->rectClient.top;
389 if (!(dc = DC_GetDCPtr( hdc )))
391 WIN_ReleaseWndPtr( wndPtr );
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 OffsetRgn( hrgnVisible, org.x, org.y );
425 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
426 WIN_ReleaseWndPtr(parentPtr);
430 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
431 OffsetRgn( hrgnVisible, org.x, org.y );
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 OffsetRgn( hrgnVisible, org.x, org.y );
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);