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