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_FindWndPtr( 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_ReleaseWndPtr( 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_FindWndPtr( 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_ReleaseWndPtr( 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
);
372 HRGN hrgnVisible
= 0;
375 if (!wndPtr
) return FALSE
;
377 if(flags
& DCX_WINDOW
)
379 org
.x
= wndPtr
->rectWindow
.left
;
380 org
.y
= wndPtr
->rectWindow
.top
;
384 org
.x
= wndPtr
->rectClient
.left
;
385 org
.y
= wndPtr
->rectClient
.top
;
388 if (!(dc
= DC_GetDCPtr( hdc
)))
390 WIN_ReleaseWndPtr( wndPtr
);
395 updateVisRgn
= (dc
->flags
& DC_DIRTY
) != 0;
396 GDI_ReleaseObj( hdc
);
400 if (flags
& DCX_PARENTCLIP
)
402 WND
*parentPtr
= WIN_FindWndPtr( wndPtr
->parent
);
404 if( wndPtr
->dwStyle
& WS_VISIBLE
&& !(parentPtr
->dwStyle
& WS_MINIMIZE
) )
408 if( parentPtr
->dwStyle
& WS_CLIPSIBLINGS
)
409 dcxFlags
= DCX_CLIPSIBLINGS
| (flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
411 dcxFlags
= flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
413 hrgnVisible
= DCE_GetVisRgn( parentPtr
->hwndSelf
, dcxFlags
,
414 wndPtr
->hwndSelf
, flags
);
415 if( flags
& DCX_WINDOW
)
416 OffsetRgn( hrgnVisible
, -wndPtr
->rectWindow
.left
,
417 -wndPtr
->rectWindow
.top
);
419 OffsetRgn( hrgnVisible
, -wndPtr
->rectClient
.left
,
420 -wndPtr
->rectClient
.top
);
421 OffsetRgn( hrgnVisible
, org
.x
, org
.y
);
424 hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
425 WIN_ReleaseWndPtr(parentPtr
);
429 hrgnVisible
= DCE_GetVisRgn( hwnd
, flags
, 0, 0 );
430 OffsetRgn( hrgnVisible
, org
.x
, org
.y
);
432 SelectVisRgn16( hdc
, hrgnVisible
);
435 /* apply additional region operation (if any) */
437 if( flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) )
439 if( !hrgnVisible
) hrgnVisible
= CreateRectRgn( 0, 0, 0, 0 );
441 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgn
);
444 CombineRgn( hrgnVisible
, hrgn
, 0, RGN_COPY
);
445 OffsetRgn( hrgnVisible
, org
.x
, org
.y
);
446 CombineRgn( hrgnVisible
, InquireVisRgn16( hdc
), hrgnVisible
,
447 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
448 SelectVisRgn16( hdc
, hrgnVisible
);
451 if (hrgnVisible
) DeleteObject( hrgnVisible
);
453 WIN_ReleaseWndPtr( wndPtr
);
458 /***********************************************************************
459 * SetWindowPos (TTYDRV.@)
461 BOOL
TTYDRV_SetWindowPos( WINDOWPOS
*winpos
)
464 RECT newWindowRect
, newClientRect
;
466 HWND hwndActive
= GetForegroundWindow();
468 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
469 winpos
->hwnd
, winpos
->x
, winpos
->y
,
470 winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
, winpos
->flags
);
472 /* ------------------------------------------------------------------------ CHECKS */
474 /* Check window handle */
476 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
477 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
479 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
480 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
481 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
, (unsigned)wndPtr
->dwStyle
);
483 /* Fix redundant flags */
485 if(wndPtr
->dwStyle
& WS_VISIBLE
)
486 winpos
->flags
&= ~SWP_SHOWWINDOW
;
489 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
490 winpos
->flags
&= ~SWP_HIDEWINDOW
;
493 if ( winpos
->cx
< 0 ) winpos
->cx
= 0;
494 if ( winpos
->cy
< 0 ) winpos
->cy
= 0;
496 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
497 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
498 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
500 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
501 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
503 if (winpos
->hwnd
== hwndActive
)
504 winpos
->flags
|= SWP_NOACTIVATE
; /* Already active */
505 else if ( (wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
507 if(!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
509 winpos
->flags
&= ~SWP_NOZORDER
;
510 winpos
->hwndInsertAfter
= HWND_TOP
;
515 /* Check hwndInsertAfter */
517 /* FIXME: TOPMOST not supported yet */
518 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
519 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
521 /* hwndInsertAfter must be a sibling of the window */
522 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) && (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
524 WND
* wnd
= WIN_FindWndPtr(winpos
->hwndInsertAfter
);
527 if( wnd
->parent
!= wndPtr
->parent
)
530 WIN_ReleaseWndPtr(wnd
);
533 /* don't need to change the Zorder of hwnd if it's already inserted
534 * after hwndInsertAfter or when inserting hwnd after itself.
536 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
537 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
538 winpos
->flags
|= SWP_NOZORDER
;
540 WIN_ReleaseWndPtr(wnd
);
543 Pos
: /* ------------------------------------------------------------------------ MAIN part */
545 /* Send WM_WINDOWPOSCHANGING message */
547 if (!(winpos
->flags
& SWP_NOSENDCHANGING
))
548 SendMessageA( wndPtr
->hwndSelf
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)winpos
);
550 /* Calculate new position and size */
552 newWindowRect
= wndPtr
->rectWindow
;
553 newClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
554 : wndPtr
->rectClient
;
556 if (!(winpos
->flags
& SWP_NOSIZE
))
558 newWindowRect
.right
= newWindowRect
.left
+ winpos
->cx
;
559 newWindowRect
.bottom
= newWindowRect
.top
+ winpos
->cy
;
561 if (!(winpos
->flags
& SWP_NOMOVE
))
563 newWindowRect
.left
= winpos
->x
;
564 newWindowRect
.top
= winpos
->y
;
565 newWindowRect
.right
+= winpos
->x
- wndPtr
->rectWindow
.left
;
566 newWindowRect
.bottom
+= winpos
->y
- wndPtr
->rectWindow
.top
;
568 OffsetRect( &newClientRect
, winpos
->x
- wndPtr
->rectWindow
.left
,
569 winpos
->y
- wndPtr
->rectWindow
.top
);
572 if( winpos
->hwndInsertAfter
== HWND_TOP
)
574 if (GetWindow( wndPtr
->hwndSelf
, GW_HWNDFIRST
) == wndPtr
->hwndSelf
)
575 winpos
->flags
|= SWP_NOZORDER
;
578 if( winpos
->hwndInsertAfter
== HWND_BOTTOM
)
580 if (!GetWindow( wndPtr
->hwndSelf
, GW_HWNDNEXT
))
581 winpos
->flags
|= SWP_NOZORDER
;
584 if( !(winpos
->flags
& SWP_NOZORDER
) )
585 if( GetWindow(winpos
->hwndInsertAfter
, GW_HWNDNEXT
) == wndPtr
->hwndSelf
)
586 winpos
->flags
|= SWP_NOZORDER
;
588 /* Common operations */
590 /* Send WM_NCCALCSIZE message to get new client area */
591 if( (winpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
593 NCCALCSIZE_PARAMS params
;
594 WINDOWPOS winposCopy
;
596 params
.rgrc
[0] = newWindowRect
;
597 params
.rgrc
[1] = wndPtr
->rectWindow
;
598 params
.rgrc
[2] = wndPtr
->rectClient
;
599 params
.lppos
= &winposCopy
;
600 winposCopy
= *winpos
;
602 SendMessageW( winpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
604 TRACE( "%d,%d-%d,%d\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
605 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
607 /* If the application send back garbage, ignore it */
608 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
609 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
610 newClientRect
= params
.rgrc
[0];
612 /* FIXME: WVR_ALIGNxxx */
614 if( newClientRect
.left
!= wndPtr
->rectClient
.left
||
615 newClientRect
.top
!= wndPtr
->rectClient
.top
)
616 winpos
->flags
&= ~SWP_NOCLIENTMOVE
;
618 if( (newClientRect
.right
- newClientRect
.left
!=
619 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
620 (newClientRect
.bottom
- newClientRect
.top
!=
621 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
622 winpos
->flags
&= ~SWP_NOCLIENTSIZE
;
625 if(!(winpos
->flags
& SWP_NOZORDER
) && winpos
->hwnd
!= winpos
->hwndInsertAfter
)
627 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
628 if (parent
) WIN_LinkWindow( winpos
->hwnd
, parent
, winpos
->hwndInsertAfter
);
631 /* FIXME: actually do something with WVR_VALIDRECTS */
633 WIN_SetRectangles( winpos
->hwnd
, &newWindowRect
, &newClientRect
);
635 if( winpos
->flags
& SWP_SHOWWINDOW
)
636 WIN_SetStyle( winpos
->hwnd
, wndPtr
->dwStyle
| WS_VISIBLE
);
637 else if( winpos
->flags
& SWP_HIDEWINDOW
)
638 WIN_SetStyle( winpos
->hwnd
, wndPtr
->dwStyle
& ~WS_VISIBLE
);
640 /* ------------------------------------------------------------------------ FINAL */
642 /* repaint invalidated region (if any)
644 * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
645 * and force update after ChangeActiveWindow() to avoid painting frames twice.
648 if( !(winpos
->flags
& SWP_NOREDRAW
) )
650 RedrawWindow( wndPtr
->parent
, NULL
, 0,
651 RDW_ERASE
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
652 if (wndPtr
->parent
== GetDesktopWindow())
653 RedrawWindow( wndPtr
->parent
, NULL
, 0,
654 RDW_ERASENOW
| RDW_NOCHILDREN
);
657 if (!(winpos
->flags
& SWP_NOACTIVATE
)) SetActiveWindow( winpos
->hwnd
);
659 /* And last, send the WM_WINDOWPOSCHANGED message */
661 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
663 if ((((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
) &&
664 !(winpos
->flags
& SWP_NOSENDCHANGING
)) )
665 SendMessageA( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
669 WIN_ReleaseWndPtr(wndPtr
);
674 /***********************************************************************
675 * WINPOS_MinMaximize (internal)
677 *Lifted from x11 driver
679 static UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
685 TRACE("0x%04x %u\n", hwnd
, cmd
);
686 FIXME("(%x): stub\n", hwnd
);
688 wpl
.length
= sizeof(wpl
);
689 GetWindowPlacement( hwnd
, &wpl
);
691 /* If I glark this right, yields an immutable window*/
692 swpFlags
= SWP_NOSIZE
| SWP_NOMOVE
;
694 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
696 /*cmd handling goes here. see dlls/x1drv/winpos.c*/
698 WIN_ReleaseWndPtr( wndPtr
);
702 /***********************************************************************
703 * ShowWindow (TTYDRV.@)
705 *Lifted from x11 driver
706 *Sets the specified windows' show state.
708 BOOL
TTYDRV_ShowWindow( HWND hwnd
, INT cmd
)
710 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
711 BOOL wasVisible
, showFlag
;
712 RECT newPos
= {0, 0, 0, 0};
715 if (!wndPtr
) return FALSE
;
716 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
718 TRACE("hwnd=%04x, cmd=%d\n", hwnd
, cmd
);
720 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
725 if (!wasVisible
) goto END
;
726 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
727 SWP_NOACTIVATE
| SWP_NOZORDER
;
730 case SW_SHOWMINNOACTIVE
:
731 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
733 case SW_SHOWMINIMIZED
:
734 swp
|= SWP_SHOWWINDOW
;
737 swp
|= SWP_FRAMECHANGED
;
738 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
739 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
740 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
743 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
744 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
745 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
746 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
747 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
751 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
754 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
757 * ShowWindow has a little peculiar behavior that if the
758 * window is already the topmost window, it will not
761 if (GetTopWindow((HWND
)0)==hwnd
&& (wasVisible
|| GetActiveWindow() == hwnd
))
762 swp
|= SWP_NOACTIVATE
;
766 case SW_SHOWNOACTIVATE
:
768 if (GetActiveWindow()) swp
|= SWP_NOACTIVATE
;
770 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
771 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
773 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
775 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
776 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
777 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
781 showFlag
= (cmd
!= SW_HIDE
);
782 if (showFlag
!= wasVisible
)
784 SendMessageA( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
785 if (!IsWindow( hwnd
)) goto END
;
788 /* We can't activate a child window */
789 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
790 !(wndPtr
->dwExStyle
& WS_EX_MDICHILD
))
791 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
793 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
794 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
797 /* FIXME: This will cause the window to be activated irrespective
798 * of whether it is owned by the same thread. Has to be done
802 if (hwnd
== GetActiveWindow())
803 WINPOS_ActivateOtherWindow(hwnd
);
805 /* Revert focus to parent */
806 if (hwnd
== GetFocus() || IsChild(hwnd
, GetFocus()))
807 SetFocus( GetParent(hwnd
) );
809 if (!IsWindow( hwnd
)) goto END
;
810 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
812 if (wndPtr
->flags
& WIN_NEED_SIZE
)
814 /* should happen only in CreateWindowEx() */
815 int wParam
= SIZE_RESTORED
;
817 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
818 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
819 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
820 SendMessageA( hwnd
, WM_SIZE
, wParam
,
821 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
822 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
823 SendMessageA( hwnd
, WM_MOVE
, 0,
824 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
828 WIN_ReleaseWndPtr(wndPtr
);