Fix definition of LookupPrivilegeNameW and declare it.
[wine/multimedia.git] / dlls / ttydrv / wnd.c
blob71395e50b17b5ce78247cbc9828c0090b5c712bc
1 /*
2 * TTY window driver
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
21 #include "config.h"
23 #include "ttydrv.h"
24 #include "win.h"
25 #include "winpos.h"
26 #include "wownt32.h"
27 #include "wine/wingdi16.h"
28 #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 )
44 BOOL ret;
45 HWND hwndLinkAfter;
46 CBT_CREATEWNDA cbtc;
47 WND *wndPtr = WIN_GetPtr( hwnd );
49 TRACE("(%p)\n", hwnd);
51 if (!wndPtr->parent) /* desktop window */
53 wndPtr->pDriverData = root_window;
54 WIN_ReleasePtr( wndPtr );
55 return TRUE;
58 #ifdef WINE_CURSES
59 /* Only create top-level windows */
60 if (!(wndPtr->dwStyle & WS_CHILD))
62 WINDOW *window;
63 const INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
65 int x = wndPtr->rectWindow.left;
66 int y = wndPtr->rectWindow.top;
67 int cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
68 int cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
70 window = subwin( root_window, cy/cellHeight, cx/cellWidth,
71 y/cellHeight, x/cellWidth);
72 werase(window);
73 wrefresh(window);
74 wndPtr->pDriverData = window;
76 #else /* defined(WINE_CURSES) */
77 FIXME("(%p): stub\n", hwnd);
78 #endif /* defined(WINE_CURSES) */
79 WIN_ReleasePtr( wndPtr );
81 /* Call the WH_CBT hook */
83 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
85 cbtc.lpcs = cs;
86 cbtc.hwndInsertAfter = hwndLinkAfter;
87 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
89 TRACE("CBT-hook returned !0\n");
90 return FALSE;
93 if (unicode)
95 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
96 if (ret) ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
98 else
100 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
101 if (ret) ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
103 return ret;
106 /***********************************************************************
107 * DestroyWindow (TTYDRV.@)
109 BOOL TTYDRV_DestroyWindow( HWND hwnd )
111 #ifdef WINE_CURSES
112 WND *wndPtr = WIN_GetPtr( hwnd );
113 WINDOW *window = wndPtr->pDriverData;
115 TRACE("(%p)\n", hwnd);
117 if (window && window != root_window) delwin(window);
118 wndPtr->pDriverData = NULL;
119 WIN_ReleasePtr( wndPtr );
120 #else /* defined(WINE_CURSES) */
121 FIXME("(%p): stub\n", hwnd);
122 #endif /* defined(WINE_CURSES) */
123 return TRUE;
127 /***********************************************************************
128 * DCE_GetVisRect
130 * Calculate the visible rectangle of a window (i.e. the client or
131 * window area clipped by the client area of all ancestors) in the
132 * corresponding coordinates. Return FALSE if the visible region is empty.
134 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
136 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
138 if (wndPtr->dwStyle & WS_VISIBLE)
140 INT xoffset = lprect->left;
141 INT yoffset = lprect->top;
143 while ((wndPtr = WIN_FindWndPtr( GetAncestor(wndPtr->hwndSelf,GA_PARENT) )))
145 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
147 WIN_ReleaseWndPtr(wndPtr);
148 goto fail;
151 xoffset += wndPtr->rectClient.left;
152 yoffset += wndPtr->rectClient.top;
153 OffsetRect( lprect, wndPtr->rectClient.left,
154 wndPtr->rectClient.top );
156 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
157 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
158 (lprect->left >= wndPtr->rectClient.right) ||
159 (lprect->right <= wndPtr->rectClient.left) ||
160 (lprect->top >= wndPtr->rectClient.bottom) ||
161 (lprect->bottom <= wndPtr->rectClient.top) )
163 WIN_ReleaseWndPtr(wndPtr);
164 goto fail;
167 lprect->left = max( lprect->left, wndPtr->rectClient.left );
168 lprect->right = min( lprect->right, wndPtr->rectClient.right );
169 lprect->top = max( lprect->top, wndPtr->rectClient.top );
170 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
172 WIN_ReleaseWndPtr(wndPtr);
174 OffsetRect( lprect, -xoffset, -yoffset );
175 return TRUE;
178 fail:
179 SetRectEmpty( lprect );
180 return FALSE;
184 /***********************************************************************
185 * DCE_AddClipRects
187 * Go through the linked list of windows from pWndStart to pWndEnd,
188 * adding to the clip region the intersection of the target rectangle
189 * with an offset window rectangle.
191 static void DCE_AddClipRects( HWND parent, HWND end, HRGN hrgnClip, LPRECT lpRect, int x, int y )
193 RECT rect;
194 WND *pWnd;
195 int i;
196 HWND *list = WIN_ListChildren( parent );
197 HRGN hrgn = 0;
199 if (!list) return;
200 for (i = 0; list[i]; i++)
202 if (list[i] == end) break;
203 if (!(pWnd = WIN_FindWndPtr( list[i] ))) continue;
204 if (pWnd->dwStyle & WS_VISIBLE)
206 rect.left = pWnd->rectWindow.left + x;
207 rect.top = pWnd->rectWindow.top + y;
208 rect.right = pWnd->rectWindow.right + x;
209 rect.bottom = pWnd->rectWindow.bottom + y;
210 if( IntersectRect( &rect, &rect, lpRect ))
212 if (!hrgn) hrgn = CreateRectRgnIndirect( &rect );
213 else SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
214 CombineRgn( hrgnClip, hrgnClip, hrgn, RGN_OR );
217 WIN_ReleaseWndPtr( pWnd );
219 if (hrgn) DeleteObject( hrgn );
220 HeapFree( GetProcessHeap(), 0, list );
224 /***********************************************************************
225 * DCE_GetVisRgn
227 * Return the visible region of a window, i.e. the client or window area
228 * clipped by the client area of all ancestors, and then optionally
229 * by siblings and children.
231 static HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
233 HRGN hrgnVis = 0;
234 RECT rect;
235 WND *wndPtr = WIN_FindWndPtr( hwnd );
236 WND *childWnd = WIN_FindWndPtr( hwndChild );
238 /* Get visible rectangle and create a region with it. */
240 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
242 if((hrgnVis = CreateRectRgnIndirect( &rect )))
244 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
245 INT xoffset, yoffset;
247 if( hrgnClip )
249 /* Compute obscured region for the visible rectangle by
250 * clipping children, siblings, and ancestors. Note that
251 * DCE_GetVisRect() returns a rectangle either in client
252 * or in window coordinates (for DCX_WINDOW request). */
254 if (flags & DCX_CLIPCHILDREN)
256 if( flags & DCX_WINDOW )
258 /* adjust offsets since child window rectangles are
259 * in client coordinates */
261 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
262 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
264 else
265 xoffset = yoffset = 0;
267 DCE_AddClipRects( wndPtr->hwndSelf, 0, hrgnClip, &rect, xoffset, yoffset );
270 /* We may need to clip children of child window, if a window with PARENTDC
271 * class style and CLIPCHILDREN window style (like in Free Agent 16
272 * preference dialogs) gets here, we take the region for the parent window
273 * but apparently still need to clip the children of the child window... */
275 if( (cflags & DCX_CLIPCHILDREN) && childWnd)
277 if( flags & DCX_WINDOW )
279 /* adjust offsets since child window rectangles are
280 * in client coordinates */
282 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
283 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
285 else
286 xoffset = yoffset = 0;
288 /* client coordinates of child window */
289 xoffset += childWnd->rectClient.left;
290 yoffset += childWnd->rectClient.top;
292 DCE_AddClipRects( childWnd->hwndSelf, 0, hrgnClip,
293 &rect, xoffset, yoffset );
296 /* sibling window rectangles are in client
297 * coordinates of the parent window */
299 if (flags & DCX_WINDOW)
301 xoffset = -wndPtr->rectWindow.left;
302 yoffset = -wndPtr->rectWindow.top;
304 else
306 xoffset = -wndPtr->rectClient.left;
307 yoffset = -wndPtr->rectClient.top;
310 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
311 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
312 hrgnClip, &rect, xoffset, yoffset );
314 /* Clip siblings of all ancestors that have the
315 * WS_CLIPSIBLINGS style
318 while (wndPtr->parent)
320 WND *ptr = WIN_FindWndPtr( wndPtr->parent );
321 WIN_ReleaseWndPtr( wndPtr );
322 wndPtr = ptr;
323 xoffset -= wndPtr->rectClient.left;
324 yoffset -= wndPtr->rectClient.top;
325 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
327 DCE_AddClipRects( wndPtr->parent, wndPtr->hwndSelf,
328 hrgnClip, &rect, xoffset, yoffset );
332 /* Now once we've got a jumbo clip region we have
333 * to substract it from the visible rectangle.
335 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
336 DeleteObject( hrgnClip );
338 else
340 DeleteObject( hrgnVis );
341 hrgnVis = 0;
345 else
346 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
347 WIN_ReleaseWndPtr(wndPtr);
348 WIN_ReleaseWndPtr(childWnd);
349 return hrgnVis;
353 /***********************************************************************
354 * GetDC (TTYDRV.@)
356 * Set the drawable, origin and dimensions for the DC associated to
357 * a given window.
359 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
361 WND *wndPtr = WIN_FindWndPtr(hwnd);
362 HRGN hrgnVisible = 0;
363 POINT org;
365 if (!wndPtr) return FALSE;
367 if(flags & DCX_WINDOW)
369 org.x = wndPtr->rectWindow.left;
370 org.y = wndPtr->rectWindow.top;
372 else
374 org.x = wndPtr->rectClient.left;
375 org.y = wndPtr->rectClient.top;
378 SetDCOrg16( HDC_16(hdc), org.x, org.y );
380 if (SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN ) || /* DC was dirty */
381 ( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ))
383 if (flags & DCX_PARENTCLIP)
385 WND *parentPtr = WIN_FindWndPtr( wndPtr->parent );
387 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
389 DWORD dcxFlags;
391 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
392 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
393 else
394 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
396 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
397 wndPtr->hwndSelf, flags );
398 if( flags & DCX_WINDOW )
399 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
400 -wndPtr->rectWindow.top );
401 else
402 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
403 -wndPtr->rectClient.top );
405 else
406 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
407 WIN_ReleaseWndPtr(parentPtr);
409 else
411 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
412 OffsetRgn( hrgnVisible, org.x, org.y );
415 /* apply additional region operation (if any) */
416 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
417 CombineRgn( hrgnVisible, hrgnVisible, hrgn,
418 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
420 SelectVisRgn16( HDC_16(hdc), HRGN_16(hrgnVisible) );
423 if (hrgnVisible) DeleteObject( hrgnVisible );
425 WIN_ReleaseWndPtr( wndPtr );
426 return TRUE;
430 /***********************************************************************
431 * SetWindowPos (TTYDRV.@)
433 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
435 WND *wndPtr;
436 RECT newWindowRect, newClientRect;
437 BOOL retvalue;
438 HWND hwndActive = GetForegroundWindow();
440 TRACE( "hwnd %p, swp (%i,%i)-(%i,%i) flags %08x\n",
441 winpos->hwnd, winpos->x, winpos->y,
442 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
444 /* ------------------------------------------------------------------------ CHECKS */
446 /* Check window handle */
448 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
449 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
451 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
452 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
453 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
455 /* Fix redundant flags */
457 if(wndPtr->dwStyle & WS_VISIBLE)
458 winpos->flags &= ~SWP_SHOWWINDOW;
459 else
461 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
462 winpos->flags &= ~SWP_HIDEWINDOW;
465 if ( winpos->cx < 0 ) winpos->cx = 0;
466 if ( winpos->cy < 0 ) winpos->cy = 0;
468 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
469 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
470 winpos->flags |= SWP_NOSIZE; /* Already the right size */
472 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
473 winpos->flags |= SWP_NOMOVE; /* Already the right position */
475 if (winpos->hwnd == hwndActive)
476 winpos->flags |= SWP_NOACTIVATE; /* Already active */
477 else if ( (wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD )
479 if(!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
481 winpos->flags &= ~SWP_NOZORDER;
482 winpos->hwndInsertAfter = HWND_TOP;
483 goto Pos;
487 /* Check hwndInsertAfter */
489 /* FIXME: TOPMOST not supported yet */
490 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
491 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
493 /* hwndInsertAfter must be a sibling of the window */
494 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
496 WND* wnd = WIN_FindWndPtr(winpos->hwndInsertAfter);
498 if( wnd ) {
499 if( wnd->parent != wndPtr->parent )
501 retvalue = FALSE;
502 WIN_ReleaseWndPtr(wnd);
503 goto END;
505 /* don't need to change the Zorder of hwnd if it's already inserted
506 * after hwndInsertAfter or when inserting hwnd after itself.
508 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
509 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
510 winpos->flags |= SWP_NOZORDER;
512 WIN_ReleaseWndPtr(wnd);
515 Pos: /* ------------------------------------------------------------------------ MAIN part */
517 /* Send WM_WINDOWPOSCHANGING message */
519 if (!(winpos->flags & SWP_NOSENDCHANGING))
520 SendMessageA( wndPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos );
522 /* Calculate new position and size */
524 newWindowRect = wndPtr->rectWindow;
525 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
526 : wndPtr->rectClient;
528 if (!(winpos->flags & SWP_NOSIZE))
530 newWindowRect.right = newWindowRect.left + winpos->cx;
531 newWindowRect.bottom = newWindowRect.top + winpos->cy;
533 if (!(winpos->flags & SWP_NOMOVE))
535 newWindowRect.left = winpos->x;
536 newWindowRect.top = winpos->y;
537 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
538 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
540 OffsetRect( &newClientRect, winpos->x - wndPtr->rectWindow.left,
541 winpos->y - wndPtr->rectWindow.top );
544 if( winpos->hwndInsertAfter == HWND_TOP )
546 if (GetWindow( wndPtr->hwndSelf, GW_HWNDFIRST ) == wndPtr->hwndSelf)
547 winpos->flags |= SWP_NOZORDER;
549 else
550 if( winpos->hwndInsertAfter == HWND_BOTTOM )
552 if (!GetWindow( wndPtr->hwndSelf, GW_HWNDNEXT ))
553 winpos->flags |= SWP_NOZORDER;
555 else
556 if( !(winpos->flags & SWP_NOZORDER) )
557 if( GetWindow(winpos->hwndInsertAfter, GW_HWNDNEXT) == wndPtr->hwndSelf )
558 winpos->flags |= SWP_NOZORDER;
560 /* Common operations */
562 /* Send WM_NCCALCSIZE message to get new client area */
563 if( (winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
565 NCCALCSIZE_PARAMS params;
566 WINDOWPOS winposCopy;
568 params.rgrc[0] = newWindowRect;
569 params.rgrc[1] = wndPtr->rectWindow;
570 params.rgrc[2] = wndPtr->rectClient;
571 params.lppos = &winposCopy;
572 winposCopy = *winpos;
574 SendMessageW( winpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
576 TRACE( "%ld,%ld-%ld,%ld\n", params.rgrc[0].left, params.rgrc[0].top,
577 params.rgrc[0].right, params.rgrc[0].bottom );
579 /* If the application send back garbage, ignore it */
580 if (params.rgrc[0].left <= params.rgrc[0].right &&
581 params.rgrc[0].top <= params.rgrc[0].bottom)
582 newClientRect = params.rgrc[0];
584 /* FIXME: WVR_ALIGNxxx */
586 if( newClientRect.left != wndPtr->rectClient.left ||
587 newClientRect.top != wndPtr->rectClient.top )
588 winpos->flags &= ~SWP_NOCLIENTMOVE;
590 if( (newClientRect.right - newClientRect.left !=
591 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
592 (newClientRect.bottom - newClientRect.top !=
593 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
594 winpos->flags &= ~SWP_NOCLIENTSIZE;
597 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
599 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
600 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
603 /* FIXME: actually do something with WVR_VALIDRECTS */
605 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
607 if( winpos->flags & SWP_SHOWWINDOW )
608 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle | WS_VISIBLE );
609 else if( winpos->flags & SWP_HIDEWINDOW )
610 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
612 /* ------------------------------------------------------------------------ FINAL */
614 /* repaint invalidated region (if any)
616 * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
617 * and force update after ChangeActiveWindow() to avoid painting frames twice.
620 if( !(winpos->flags & SWP_NOREDRAW) )
622 RedrawWindow( wndPtr->parent, NULL, 0,
623 RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN );
624 if (wndPtr->parent == GetDesktopWindow())
625 RedrawWindow( wndPtr->parent, NULL, 0,
626 RDW_ERASENOW | RDW_NOCHILDREN );
629 if (!(winpos->flags & SWP_NOACTIVATE)) SetActiveWindow( winpos->hwnd );
631 /* And last, send the WM_WINDOWPOSCHANGED message */
633 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
635 if ((((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
636 !(winpos->flags & SWP_NOSENDCHANGING)) )
637 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
639 retvalue = TRUE;
640 END:
641 WIN_ReleaseWndPtr(wndPtr);
642 return retvalue;
646 /***********************************************************************
647 * WINPOS_MinMaximize (internal)
649 *Lifted from x11 driver
651 static UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
653 UINT swpFlags = 0;
654 WINDOWPLACEMENT wpl;
656 TRACE("%p %u\n", hwnd, cmd );
657 FIXME("(%p): stub\n", hwnd);
659 wpl.length = sizeof(wpl);
660 GetWindowPlacement( hwnd, &wpl );
662 /* If I glark this right, yields an immutable window*/
663 swpFlags = SWP_NOSIZE | SWP_NOMOVE;
665 /*cmd handling goes here. see dlls/x1drv/winpos.c*/
667 return swpFlags;
670 /***********************************************************************
671 * ShowWindow (TTYDRV.@)
673 *Lifted from x11 driver
674 *Sets the specified windows' show state.
676 BOOL TTYDRV_ShowWindow( HWND hwnd, INT cmd )
678 WND* wndPtr = WIN_FindWndPtr( hwnd );
679 BOOL wasVisible, showFlag;
680 RECT newPos = {0, 0, 0, 0};
681 UINT swp = 0;
683 if (!wndPtr) return FALSE;
684 hwnd = wndPtr->hwndSelf; /* make it a full handle */
686 TRACE("hwnd=%p, cmd=%d\n", hwnd, cmd);
688 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
690 switch(cmd)
692 case SW_HIDE:
693 if (!wasVisible) goto END;
694 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
695 SWP_NOACTIVATE | SWP_NOZORDER;
696 break;
698 case SW_SHOWMINNOACTIVE:
699 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
700 /* fall through */
701 case SW_SHOWMINIMIZED:
702 swp |= SWP_SHOWWINDOW;
703 /* fall through */
704 case SW_MINIMIZE:
705 swp |= SWP_FRAMECHANGED;
706 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
707 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
708 else swp |= SWP_NOSIZE | SWP_NOMOVE;
709 break;
711 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
712 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
713 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
714 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
715 else swp |= SWP_NOSIZE | SWP_NOMOVE;
716 break;
718 case SW_SHOWNA:
719 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
720 /* fall through */
721 case SW_SHOW:
722 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
725 * ShowWindow has a little peculiar behavior that if the
726 * window is already the topmost window, it will not
727 * activate it.
729 if (GetTopWindow(NULL)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
730 swp |= SWP_NOACTIVATE;
732 break;
734 case SW_SHOWNOACTIVATE:
735 swp |= SWP_NOZORDER;
736 if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
737 /* fall through */
738 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
739 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
740 case SW_RESTORE:
741 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
743 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
744 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
745 else swp |= SWP_NOSIZE | SWP_NOMOVE;
746 break;
749 showFlag = (cmd != SW_HIDE);
750 if (showFlag != wasVisible)
752 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
753 if (!IsWindow( hwnd )) goto END;
756 /* We can't activate a child window */
757 if ((wndPtr->dwStyle & WS_CHILD) &&
758 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
759 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
761 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
762 newPos.right, newPos.bottom, LOWORD(swp) );
763 if (cmd == SW_HIDE)
765 /* FIXME: This will cause the window to be activated irrespective
766 * of whether it is owned by the same thread. Has to be done
767 * asynchronously.
770 if (hwnd == GetActiveWindow())
771 WINPOS_ActivateOtherWindow(hwnd);
773 /* Revert focus to parent */
774 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
775 SetFocus( GetParent(hwnd) );
777 if (!IsWindow( hwnd )) goto END;
778 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
780 if (wndPtr->flags & WIN_NEED_SIZE)
782 /* should happen only in CreateWindowEx() */
783 int wParam = SIZE_RESTORED;
785 wndPtr->flags &= ~WIN_NEED_SIZE;
786 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
787 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
788 SendMessageA( hwnd, WM_SIZE, wParam,
789 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
790 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
791 SendMessageA( hwnd, WM_MOVE, 0,
792 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
795 END:
796 WIN_ReleaseWndPtr(wndPtr);
797 return wasVisible;