Handle CBR_BLOCK in EXECUTE and ADVISE DDE transactions.
[wine] / dlls / ttydrv / wnd.c
1 /*
2  * TTY window driver
3  *
4  * Copyright 1998,1999 Patrik Stridvall
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include "ttydrv.h"
24 #include "ntstatus.h"
25 #include "win.h"
26 #include "winpos.h"
27 #include "wownt32.h"
28 #include "wine/wingdi16.h"
29 #include "wine/server.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
33
34 #define SWP_AGG_NOGEOMETRYCHANGE \
35     (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
36 #define SWP_AGG_NOPOSCHANGE \
37     (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
38 #define SWP_AGG_STATUSFLAGS \
39     (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
40
41 /***********************************************************************
42  *              get_server_visible_region
43  */
44 static HRGN get_server_visible_region( HWND hwnd, HWND top, UINT flags )
45 {
46     RGNDATA *data;
47     NTSTATUS status;
48     HRGN ret = 0;
49     size_t size = 256;
50
51     do
52     {
53         if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 ))) return 0;
54         SERVER_START_REQ( get_visible_region )
55         {
56             req->window  = hwnd;
57             req->top_win = top;
58             req->flags   = flags;
59             wine_server_set_reply( req, data->Buffer, size );
60             if (!(status = wine_server_call( req )))
61             {
62                 size_t reply_size = wine_server_reply_size( reply );
63                 data->rdh.dwSize   = sizeof(data->rdh);
64                 data->rdh.iType    = RDH_RECTANGLES;
65                 data->rdh.nCount   = reply_size / sizeof(RECT);
66                 data->rdh.nRgnSize = reply_size;
67                 ret = ExtCreateRegion( NULL, size, data );
68             }
69             else size = reply->total_size;
70         }
71         SERVER_END_REQ;
72         HeapFree( GetProcessHeap(), 0, data );
73     } while (status == STATUS_BUFFER_OVERFLOW);
74
75     if (status) SetLastError( RtlNtStatusToDosError(status) );
76     return ret;
77 }
78
79
80 /***********************************************************************
81  *           set_window_pos
82  *
83  * Set a window position and Z order.
84  */
85 static void set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
86                             const RECT *rectClient, UINT swp_flags, UINT wvr_flags )
87 {
88     WND *win = WIN_GetPtr( hwnd );
89     BOOL ret;
90
91     if (!win) return;
92     if (win == WND_OTHER_PROCESS)
93     {
94         if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
95         return;
96     }
97     SERVER_START_REQ( set_window_pos )
98     {
99         req->handle        = hwnd;
100         req->top_win       = 0;
101         req->previous      = insert_after;
102         req->flags         = swp_flags;
103         req->redraw_flags  = wvr_flags;
104         req->window.left   = rectWindow->left;
105         req->window.top    = rectWindow->top;
106         req->window.right  = rectWindow->right;
107         req->window.bottom = rectWindow->bottom;
108         req->client.left   = rectClient->left;
109         req->client.top    = rectClient->top;
110         req->client.right  = rectClient->right;
111         req->client.bottom = rectClient->bottom;
112         ret = !wine_server_call( req );
113     }
114     SERVER_END_REQ;
115     if (ret)
116     {
117         win->rectWindow = *rectWindow;
118         win->rectClient = *rectClient;
119
120         TRACE( "win %p window (%ld,%ld)-(%ld,%ld) client (%ld,%ld)-(%ld,%ld)\n", hwnd,
121                rectWindow->left, rectWindow->top, rectWindow->right, rectWindow->bottom,
122                rectClient->left, rectClient->top, rectClient->right, rectClient->bottom );
123     }
124     WIN_ReleasePtr( win );
125 }
126
127
128 /**********************************************************************
129  *              CreateWindow   (TTYDRV.@)
130  */
131 BOOL TTYDRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
132 {
133     BOOL ret;
134     RECT rect;
135     HWND parent, hwndLinkAfter;
136     CBT_CREATEWNDA cbtc;
137
138     TRACE("(%p)\n", hwnd);
139
140     /* initialize the dimensions before sending WM_GETMINMAXINFO */
141     SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
142     set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, 0 );
143
144     parent = GetAncestor( hwnd, GA_PARENT );
145     if (!parent)  /* desktop window */
146     {
147         SetPropA( hwnd, "__wine_ttydrv_window", root_window );
148         return TRUE;
149     }
150
151 #ifdef WINE_CURSES
152     /* Only create top-level windows */
153     if (parent == GetDesktopWindow())
154     {
155         WINDOW *window;
156         const INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
157
158         window = subwin( root_window, cs->cy/cellHeight, cs->cx/cellWidth,
159                          cs->y/cellHeight, cs->x/cellWidth);
160         werase(window);
161         wrefresh(window);
162         SetPropA( hwnd, "__wine_ttydrv_window", window );
163     }
164 #else /* defined(WINE_CURSES) */
165     FIXME("(%p): stub\n", hwnd);
166 #endif /* defined(WINE_CURSES) */
167
168     /* Call the WH_CBT hook */
169
170     hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
171
172     cbtc.lpcs = cs;
173     cbtc.hwndInsertAfter = hwndLinkAfter;
174     if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
175     {
176         TRACE("CBT-hook returned !0\n");
177         return FALSE;
178     }
179
180     if (unicode)
181     {
182         ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
183         if (ret) ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
184     }
185     else
186     {
187         ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
188         if (ret) ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
189     }
190     return ret;
191 }
192
193 /***********************************************************************
194  *              DestroyWindow   (TTYDRV.@)
195  */
196 BOOL TTYDRV_DestroyWindow( HWND hwnd )
197 {
198 #ifdef WINE_CURSES
199     WINDOW *window = GetPropA( hwnd, "__wine_ttydrv_window" );
200
201     TRACE("(%p)\n", hwnd);
202
203     if (window && window != root_window) delwin(window);
204 #else /* defined(WINE_CURSES) */
205     FIXME("(%p): stub\n", hwnd);
206 #endif /* defined(WINE_CURSES) */
207     return TRUE;
208 }
209
210
211 /***********************************************************************
212  *              GetDC   (TTYDRV.@)
213  *
214  * Set the drawable, origin and dimensions for the DC associated to
215  * a given window.
216  */
217 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
218 {
219     struct ttydrv_escape_set_drawable escape;
220
221     if(flags & DCX_WINDOW)
222     {
223         RECT rect;
224         GetWindowRect( hwnd, &rect );
225         escape.org.x = rect.left;
226         escape.org.y = rect.top;
227     }
228     else
229     {
230         escape.org.x = escape.org.y = 0;
231         MapWindowPoints( hwnd, 0, &escape.org, 1 );
232     }
233
234     escape.code = TTYDRV_SET_DRAWABLE;
235     ExtEscape( hdc, TTYDRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
236
237     if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
238         SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN ))  /* DC was dirty */
239     {
240         /* need to recompute the visible region */
241         HRGN visRgn = get_server_visible_region( hwnd, GetDesktopWindow(), flags );
242
243         if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
244             CombineRgn( visRgn, visRgn, hrgn, (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
245
246         SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
247         DeleteObject( visRgn );
248     }
249     return TRUE;
250 }
251
252
253 /***********************************************************************
254  *              SetWindowPos   (TTYDRV.@)
255  */
256 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
257 {
258     WND *wndPtr;
259     RECT newWindowRect, newClientRect;
260     UINT wvrFlags = 0;
261     BOOL retvalue;
262     HWND hwndActive = GetForegroundWindow();
263
264     TRACE( "hwnd %p, swp (%i,%i)-(%i,%i) flags %08x\n",
265            winpos->hwnd, winpos->x, winpos->y,
266            winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
267
268     /* ------------------------------------------------------------------------ CHECKS */
269
270       /* Check window handle */
271
272     if (winpos->hwnd == GetDesktopWindow()) return FALSE;
273     if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
274
275     TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
276           wndPtr->rectWindow.left, wndPtr->rectWindow.top,
277           wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
278
279     /* Fix redundant flags */
280
281     if(wndPtr->dwStyle & WS_VISIBLE)
282         winpos->flags &= ~SWP_SHOWWINDOW;
283     else
284     {
285         if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
286         winpos->flags &= ~SWP_HIDEWINDOW;
287     }
288
289     if ( winpos->cx < 0 ) winpos->cx = 0;
290     if ( winpos->cy < 0 ) winpos->cy = 0;
291
292     if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
293         (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
294         winpos->flags |= SWP_NOSIZE;    /* Already the right size */
295
296     if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
297         winpos->flags |= SWP_NOMOVE;    /* Already the right position */
298
299     if (winpos->hwnd == hwndActive)
300         winpos->flags |= SWP_NOACTIVATE;   /* Already active */
301     else if ( (wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD )
302     {
303         if(!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
304         {
305             winpos->flags &= ~SWP_NOZORDER;
306             winpos->hwndInsertAfter = HWND_TOP;
307             goto Pos;
308         }
309     }
310
311     /* Check hwndInsertAfter */
312
313       /* FIXME: TOPMOST not supported yet */
314     if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
315         (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
316
317     /* hwndInsertAfter must be a sibling of the window */
318     if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
319     {
320         if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent)
321         {
322             retvalue = FALSE;
323             goto END;
324         }
325         /* don't need to change the Zorder of hwnd if it's already inserted
326          * after hwndInsertAfter or when inserting hwnd after itself.
327          */
328         if ((winpos->hwnd == winpos->hwndInsertAfter) ||
329             (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
330             winpos->flags |= SWP_NOZORDER;
331     }
332
333  Pos:  /* ------------------------------------------------------------------------ MAIN part */
334
335       /* Send WM_WINDOWPOSCHANGING message */
336
337     if (!(winpos->flags & SWP_NOSENDCHANGING))
338         SendMessageA( wndPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos );
339
340       /* Calculate new position and size */
341
342     newWindowRect = wndPtr->rectWindow;
343     newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
344                                                     : wndPtr->rectClient;
345
346     if (!(winpos->flags & SWP_NOSIZE))
347     {
348         newWindowRect.right  = newWindowRect.left + winpos->cx;
349         newWindowRect.bottom = newWindowRect.top + winpos->cy;
350     }
351     if (!(winpos->flags & SWP_NOMOVE))
352     {
353         newWindowRect.left    = winpos->x;
354         newWindowRect.top     = winpos->y;
355         newWindowRect.right  += winpos->x - wndPtr->rectWindow.left;
356         newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
357
358         OffsetRect( &newClientRect, winpos->x - wndPtr->rectWindow.left,
359                     winpos->y - wndPtr->rectWindow.top );
360     }
361
362     if( winpos->hwndInsertAfter == HWND_TOP )
363     {
364         if (GetWindow( wndPtr->hwndSelf, GW_HWNDFIRST ) == wndPtr->hwndSelf)
365             winpos->flags |= SWP_NOZORDER;
366     }
367     else
368         if( winpos->hwndInsertAfter == HWND_BOTTOM )
369         {
370             if (!GetWindow( wndPtr->hwndSelf, GW_HWNDNEXT ))
371                 winpos->flags |= SWP_NOZORDER;
372         }
373         else
374             if( !(winpos->flags & SWP_NOZORDER) )
375                 if( GetWindow(winpos->hwndInsertAfter, GW_HWNDNEXT) == wndPtr->hwndSelf )
376                     winpos->flags |= SWP_NOZORDER;
377
378     /* Common operations */
379
380       /* Send WM_NCCALCSIZE message to get new client area */
381     if( (winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
382     {
383         NCCALCSIZE_PARAMS params;
384         WINDOWPOS winposCopy;
385
386         params.rgrc[0] = newWindowRect;
387         params.rgrc[1] = wndPtr->rectWindow;
388         params.rgrc[2] = wndPtr->rectClient;
389         params.lppos = &winposCopy;
390         winposCopy = *winpos;
391
392         wvrFlags = SendMessageW( winpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
393
394         TRACE( "%ld,%ld-%ld,%ld\n", params.rgrc[0].left, params.rgrc[0].top,
395                params.rgrc[0].right, params.rgrc[0].bottom );
396
397         /* If the application send back garbage, ignore it */
398         if (params.rgrc[0].left <= params.rgrc[0].right &&
399             params.rgrc[0].top <= params.rgrc[0].bottom)
400             newClientRect = params.rgrc[0];
401
402          /* FIXME: WVR_ALIGNxxx */
403
404         if( newClientRect.left != wndPtr->rectClient.left ||
405             newClientRect.top != wndPtr->rectClient.top )
406             winpos->flags &= ~SWP_NOCLIENTMOVE;
407
408         if( (newClientRect.right - newClientRect.left !=
409              wndPtr->rectClient.right - wndPtr->rectClient.left) ||
410             (newClientRect.bottom - newClientRect.top !=
411              wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
412             winpos->flags &= ~SWP_NOCLIENTSIZE;
413     }
414
415     /* FIXME: actually do something with WVR_VALIDRECTS */
416
417     set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
418                     &newWindowRect, &newClientRect, winpos->flags, wvrFlags );
419
420     if( winpos->flags & SWP_SHOWWINDOW )
421         WIN_SetStyle( winpos->hwnd, WS_VISIBLE, 0 );
422     else if( winpos->flags & SWP_HIDEWINDOW )
423         WIN_SetStyle( winpos->hwnd, 0, WS_VISIBLE );
424
425     /* ------------------------------------------------------------------------ FINAL */
426
427     /* repaint invalidated region (if any)
428      *
429      * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
430      *        and force update after ChangeActiveWindow() to avoid painting frames twice.
431      */
432
433     if( !(winpos->flags & SWP_NOREDRAW) )
434     {
435         RedrawWindow( wndPtr->parent, NULL, 0,
436                       RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN );
437         if (wndPtr->parent == GetDesktopWindow())
438             RedrawWindow( wndPtr->parent, NULL, 0,
439                           RDW_ERASENOW | RDW_NOCHILDREN );
440     }
441
442     if (!(winpos->flags & SWP_NOACTIVATE)) SetActiveWindow( winpos->hwnd );
443
444       /* And last, send the WM_WINDOWPOSCHANGED message */
445
446     TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
447
448     if ((((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
449           !(winpos->flags & SWP_NOSENDCHANGING)) )
450         SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
451
452     retvalue = TRUE;
453  END:
454     WIN_ReleaseWndPtr(wndPtr);
455     return retvalue;
456 }
457
458
459 /***********************************************************************
460  *              WINPOS_MinMaximize   (internal)
461  *
462  *Lifted from x11 driver
463  */
464 static UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
465 {
466     UINT swpFlags = 0;
467     WINDOWPLACEMENT wpl;
468
469     TRACE("%p %u\n", hwnd, cmd );
470     FIXME("(%p): stub\n", hwnd);
471
472     wpl.length = sizeof(wpl);
473     GetWindowPlacement( hwnd, &wpl );
474
475     /* If I glark this right, yields an immutable window*/
476     swpFlags = SWP_NOSIZE | SWP_NOMOVE;
477
478     /*cmd handling goes here.  see dlls/x1drv/winpos.c*/
479
480     return swpFlags;
481 }
482
483 /***********************************************************************
484  *              ShowWindow   (TTYDRV.@)
485  *
486  *Lifted from x11 driver
487  *Sets the specified windows' show state.
488  */
489 BOOL TTYDRV_ShowWindow( HWND hwnd, INT cmd )
490 {
491     WND*        wndPtr = WIN_FindWndPtr( hwnd );
492     BOOL        wasVisible, showFlag;
493     RECT        newPos = {0, 0, 0, 0};
494     UINT        swp = 0;
495
496     if (!wndPtr) return FALSE;
497     hwnd = wndPtr->hwndSelf;  /* make it a full handle */
498
499     TRACE("hwnd=%p, cmd=%d\n", hwnd, cmd);
500
501     wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
502
503     switch(cmd)
504     {
505         case SW_HIDE:
506             if (!wasVisible) goto END;
507             swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
508                         SWP_NOACTIVATE | SWP_NOZORDER;
509             break;
510
511         case SW_SHOWMINNOACTIVE:
512             swp |= SWP_NOACTIVATE | SWP_NOZORDER;
513             /* fall through */
514         case SW_SHOWMINIMIZED:
515             swp |= SWP_SHOWWINDOW;
516             /* fall through */
517         case SW_MINIMIZE:
518             swp |= SWP_FRAMECHANGED;
519             if( !(wndPtr->dwStyle & WS_MINIMIZE) )
520                  swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
521             else swp |= SWP_NOSIZE | SWP_NOMOVE;
522             break;
523
524         case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
525             swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
526             if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
527                  swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
528             else swp |= SWP_NOSIZE | SWP_NOMOVE;
529             break;
530
531         case SW_SHOWNA:
532             swp |= SWP_NOACTIVATE | SWP_NOZORDER;
533             /* fall through */
534         case SW_SHOW:
535             swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
536
537             /*
538              * ShowWindow has a little peculiar behavior that if the
539              * window is already the topmost window, it will not
540              * activate it.
541              */
542             if (GetTopWindow(NULL)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
543               swp |= SWP_NOACTIVATE;
544
545             break;
546
547         case SW_SHOWNOACTIVATE:
548             swp |= SWP_NOZORDER;
549             if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
550             /* fall through */
551         case SW_SHOWNORMAL:  /* same as SW_NORMAL: */
552         case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
553         case SW_RESTORE:
554             swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
555
556             if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
557                  swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
558             else swp |= SWP_NOSIZE | SWP_NOMOVE;
559             break;
560     }
561
562     showFlag = (cmd != SW_HIDE);
563     if (showFlag != wasVisible)
564     {
565         SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
566         if (!IsWindow( hwnd )) goto END;
567     }
568
569     /* We can't activate a child window */
570     if ((wndPtr->dwStyle & WS_CHILD) &&
571         !(wndPtr->dwExStyle & WS_EX_MDICHILD))
572         swp |= SWP_NOACTIVATE | SWP_NOZORDER;
573
574     SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
575                   newPos.right, newPos.bottom, LOWORD(swp) );
576     if (cmd == SW_HIDE)
577     {
578         /* FIXME: This will cause the window to be activated irrespective
579          * of whether it is owned by the same thread. Has to be done
580          * asynchronously.
581          */
582
583         if (hwnd == GetActiveWindow())
584             WINPOS_ActivateOtherWindow(hwnd);
585
586         /* Revert focus to parent */
587         if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
588             SetFocus( GetParent(hwnd) );
589     }
590     if (!IsWindow( hwnd )) goto END;
591     else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
592
593     if (wndPtr->flags & WIN_NEED_SIZE)
594     {
595         /* should happen only in CreateWindowEx() */
596         int wParam = SIZE_RESTORED;
597
598         wndPtr->flags &= ~WIN_NEED_SIZE;
599         if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
600         else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
601         SendMessageA( hwnd, WM_SIZE, wParam,
602                      MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
603                             wndPtr->rectClient.bottom-wndPtr->rectClient.top));
604         SendMessageA( hwnd, WM_MOVE, 0,
605                    MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
606     }
607
608 END:
609     WIN_ReleaseWndPtr(wndPtr);
610     return wasVisible;
611 }