Release 970112
[wine/multimedia.git] / windows / winpos.c
blob40516f303d45dc8fd43915613f63966d4cd1cd21
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
6 */
8 #include <X11/Xlib.h>
9 #include <X11/Xutil.h>
10 #include <X11/Xatom.h>
11 #include "sysmetrics.h"
12 #include "heap.h"
13 #include "module.h"
14 #include "user.h"
15 #include "win.h"
16 #include "hook.h"
17 #include "message.h"
18 #include "queue.h"
19 #include "options.h"
20 #include "winpos.h"
21 #include "dce.h"
22 #include "nonclient.h"
23 #include "stddebug.h"
24 /* #define DEBUG_WIN */
25 #include "debug.h"
27 #define SWP_AGG_NOGEOMETRYCHANGE \
28 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
29 #define SWP_AGG_NOPOSCHANGE \
30 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
31 #define SWP_AGG_STATUSFLAGS \
32 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
34 #define SMC_NOCOPY 0x0001
35 #define SMC_NOPARENTERASE 0x0002
36 #define SMC_DRAWFRAME 0x0004
37 #define SMC_SETXPOS 0x0008
39 /* ----- external functions ----- */
41 extern void FOCUS_SwitchFocus( HWND , HWND );
42 extern HRGN32 DCE_GetVisRgn( HWND, WORD );
43 extern HWND CARET_GetHwnd();
44 extern BOOL DCE_InvalidateDCE(WND*, RECT16* );
46 /* ----- internal variables ----- */
48 static HWND hwndActive = 0; /* Currently active window */
49 static HWND hwndPrevActive = 0; /* Previously active window */
51 extern MESSAGEQUEUE* pActiveQueue;
53 /***********************************************************************
54 * WINPOS_CheckActive
56 void WINPOS_CheckActive( HWND32 hwnd )
58 if( hwnd == hwndPrevActive ) hwndPrevActive = 0;
59 if( hwnd == hwndActive )
61 hwndActive = 0;
62 dprintf_win(stddeb,"\tattempt to activate destroyed window!\n");
66 /***********************************************************************
67 * WINPOS_FindIconPos
69 * Find a suitable place for an iconic window.
70 * The new position is stored into wndPtr->ptIconPos.
72 void WINPOS_FindIconPos( HWND32 hwnd )
74 RECT16 rectParent;
75 short x, y, xspacing, yspacing;
76 WND * wndPtr = WIN_FindWndPtr( hwnd );
78 if (!wndPtr || !wndPtr->parent) return;
79 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
80 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
81 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
82 (wndPtr->ptIconPos.y >= rectParent.top) &&
83 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
84 return; /* The icon already has a suitable position */
86 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
87 y = rectParent.bottom;
88 for (;;)
90 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
92 /* Check if another icon already occupies this spot */
93 WND *childPtr = wndPtr->parent->child;
94 while (childPtr)
96 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
98 if ((childPtr->rectWindow.left < x + xspacing) &&
99 (childPtr->rectWindow.right >= x) &&
100 (childPtr->rectWindow.top <= y) &&
101 (childPtr->rectWindow.bottom > y - yspacing))
102 break; /* There's a window in there */
104 childPtr = childPtr->next;
106 if (!childPtr)
108 /* No window was found, so it's OK for us */
109 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
110 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
111 return;
114 y -= yspacing;
119 /***********************************************************************
120 * ArrangeIconicWindows (USER.170)
122 UINT ArrangeIconicWindows( HWND parent )
124 RECT16 rectParent;
125 HWND hwndChild;
126 INT x, y, xspacing, yspacing;
128 GetClientRect16( parent, &rectParent );
129 x = rectParent.left;
130 y = rectParent.bottom;
131 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
132 hwndChild = GetWindow( parent, GW_CHILD );
133 while (hwndChild)
135 if (IsIconic( hwndChild ))
137 SetWindowPos( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
138 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
139 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
140 if (x <= rectParent.right - xspacing) x += xspacing;
141 else
143 x = rectParent.left;
144 y -= yspacing;
147 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
149 return yspacing;
153 /***********************************************************************
154 * GetWindowRect16 (USER.32)
156 void GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
158 WND * wndPtr = WIN_FindWndPtr( hwnd );
159 if (!wndPtr) return;
161 *rect = wndPtr->rectWindow;
162 if (wndPtr->dwStyle & WS_CHILD)
163 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
167 /***********************************************************************
168 * GetWindowRect32 (USER.32)
170 void GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
172 WND * wndPtr = WIN_FindWndPtr( hwnd );
173 if (!wndPtr) return;
175 CONV_RECT16TO32( &wndPtr->rectWindow, rect );
176 if (wndPtr->dwStyle & WS_CHILD)
177 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
181 /***********************************************************************
182 * GetClientRect16 (USER.33)
184 void GetClientRect16( HWND16 hwnd, LPRECT16 rect )
186 WND * wndPtr = WIN_FindWndPtr( hwnd );
188 rect->left = rect->top = rect->right = rect->bottom = 0;
189 if (wndPtr)
191 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
192 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
197 /***********************************************************************
198 * GetClientRect32 (USER32.219)
200 void GetClientRect32( HWND32 hwnd, LPRECT32 rect )
202 WND * wndPtr = WIN_FindWndPtr( hwnd );
204 rect->left = rect->top = rect->right = rect->bottom = 0;
205 if (wndPtr)
207 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
208 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
213 /*******************************************************************
214 * ClientToScreen16 (USER.28)
216 BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
218 MapWindowPoints16( hwnd, 0, lppnt, 1 );
219 return TRUE;
223 /*******************************************************************
224 * ClientToScreen32 (USER32.51)
226 BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
228 MapWindowPoints32( hwnd, 0, lppnt, 1 );
229 return TRUE;
233 /*******************************************************************
234 * ScreenToClient16 (USER.29)
236 void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
238 MapWindowPoints16( 0, hwnd, lppnt, 1 );
242 /*******************************************************************
243 * ScreenToClient32 (USER32.446)
245 void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
247 MapWindowPoints32( 0, hwnd, lppnt, 1 );
251 /***********************************************************************
252 * WINPOS_WindowFromPoint
254 * Find the window and hittest for a given point.
256 INT16 WINPOS_WindowFromPoint( WND* wndScope, POINT16 pt, WND **ppWnd )
258 WND *wndPtr;
259 INT16 hittest = HTERROR;
260 INT16 x, y;
262 *ppWnd = NULL;
263 x = pt.x;
264 y = pt.y;
265 wndPtr = wndScope->child;
266 for (;;)
268 while (wndPtr)
270 /* If point is in window, and window is visible, and it */
271 /* is enabled (or it's a top-level window), then explore */
272 /* its children. Otherwise, go to the next window. */
274 if ((wndPtr->dwStyle & WS_VISIBLE) &&
275 (!(wndPtr->dwStyle & WS_DISABLED) ||
276 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
277 (x >= wndPtr->rectWindow.left) &&
278 (x < wndPtr->rectWindow.right) &&
279 (y >= wndPtr->rectWindow.top) &&
280 (y < wndPtr->rectWindow.bottom))
282 *ppWnd = wndPtr; /* Got a suitable window */
284 /* If window is minimized or disabled, return at once */
285 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
286 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
288 /* If point is not in client area, ignore the children */
289 if ((x < wndPtr->rectClient.left) ||
290 (x >= wndPtr->rectClient.right) ||
291 (y < wndPtr->rectClient.top) ||
292 (y >= wndPtr->rectClient.bottom)) break;
294 x -= wndPtr->rectClient.left;
295 y -= wndPtr->rectClient.top;
296 wndPtr = wndPtr->child;
298 else wndPtr = wndPtr->next;
301 /* If nothing found, return the scope window */
302 if (!*ppWnd)
304 *ppWnd = wndScope;
305 if( pt.x >= (wndScope->rectClient.left - wndScope->rectWindow.left) &&
306 pt.x >= (wndScope->rectClient.top - wndScope->rectWindow.top ) &&
307 pt.x <= (wndScope->rectClient.right - wndScope->rectWindow.left) &&
308 pt.x <= (wndScope->rectClient.bottom - wndScope->rectWindow.top ) )
309 return HTCLIENT;
310 if( pt.x < 0 || pt.y < 0 ||
311 pt.x > (wndScope->rectWindow.right - wndScope->rectWindow.left) ||
312 pt.y > (wndScope->rectWindow.bottom - wndScope->rectWindow.top ) )
313 return HTNOWHERE;
314 return HTCAPTION; /* doesn't matter in this case */
317 /* Send the WM_NCHITTEST message (only if to the same task) */
318 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
319 hittest = (INT)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
320 MAKELONG( pt.x, pt.y ) );
321 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
323 /* If no children found in last search, make point relative to parent*/
324 if (!wndPtr)
326 x += (*ppWnd)->rectClient.left;
327 y += (*ppWnd)->rectClient.top;
330 /* Restart the search from the next sibling */
331 wndPtr = (*ppWnd)->next;
332 *ppWnd = (*ppWnd)->parent;
337 /*******************************************************************
338 * WindowFromPoint16 (USER.30)
340 HWND16 WindowFromPoint16( POINT16 pt )
342 WND *pWnd;
343 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt, &pWnd );
344 return pWnd->hwndSelf;
348 /*******************************************************************
349 * WindowFromPoint32 (USER32.581)
351 HWND32 WindowFromPoint32( POINT32 pt )
353 WND *pWnd;
354 POINT16 pt16;
355 CONV_POINT32TO16( &pt, &pt16 );
356 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt16, &pWnd );
357 return (HWND32)pWnd->hwndSelf;
361 /*******************************************************************
362 * ChildWindowFromPoint16 (USER.191)
364 HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
366 /* pt is in the client coordinates */
368 WND* wnd = WIN_FindWndPtr(hwndParent);
369 RECT16 rect;
371 if( !wnd ) return 0;
373 /* get client rect fast */
374 rect.top = rect.left = 0;
375 rect.right = wnd->rectClient.right - wnd->rectClient.left;
376 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
378 if (!PtInRect16( &rect, pt )) return 0;
380 wnd = wnd->child;
381 while ( wnd )
383 if (PtInRect16( &wnd->rectWindow, pt )) return wnd->hwndSelf;
384 wnd = wnd->next;
386 return hwndParent;
390 /*******************************************************************
391 * ChildWindowFromPoint32 (USER32.)
393 HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
395 POINT16 pt16;
396 CONV_POINT32TO16( &pt, &pt16 );
397 return (HWND32)ChildWindowFromPoint16( hwndParent, pt16 );
401 /*******************************************************************
402 * WINPOS_GetWinOffset
404 * Calculate the offset between the origin of the two windows. Used
405 * to implement MapWindowPoints.
407 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
408 POINT32 *offset )
410 WND * wndPtr;
412 offset->x = offset->y = 0;
413 if (hwndFrom == hwndTo ) return;
415 /* Translate source window origin to screen coords */
416 if (hwndFrom)
418 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
420 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
421 return;
423 while (wndPtr->parent)
425 offset->x += wndPtr->rectClient.left;
426 offset->y += wndPtr->rectClient.top;
427 wndPtr = wndPtr->parent;
431 /* Translate origin to destination window coords */
432 if (hwndTo)
434 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
436 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
437 return;
439 while (wndPtr->parent)
441 offset->x -= wndPtr->rectClient.left;
442 offset->y -= wndPtr->rectClient.top;
443 wndPtr = wndPtr->parent;
449 /*******************************************************************
450 * MapWindowPoints16 (USER.258)
452 void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
453 LPPOINT16 lppt, UINT16 count )
455 POINT32 offset;
457 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
458 while (count--)
460 lppt->x += offset.x;
461 lppt->y += offset.y;
462 lppt++;
467 /*******************************************************************
468 * MapWindowPoints32 (USER32.385)
470 void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
471 LPPOINT32 lppt, UINT32 count )
473 POINT32 offset;
475 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
476 while (count--)
478 lppt->x += offset.x;
479 lppt->y += offset.y;
480 lppt++;
485 /***********************************************************************
486 * IsIconic (USER.31)
488 BOOL IsIconic(HWND hWnd)
490 WND * wndPtr = WIN_FindWndPtr(hWnd);
491 if (wndPtr == NULL) return FALSE;
492 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
496 /***********************************************************************
497 * IsZoomed (USER.272)
499 BOOL IsZoomed(HWND hWnd)
501 WND * wndPtr = WIN_FindWndPtr(hWnd);
502 if (wndPtr == NULL) return FALSE;
503 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
507 /*******************************************************************
508 * GetActiveWindow (USER.60)
510 HWND GetActiveWindow(void)
512 return hwndActive;
516 /*******************************************************************
517 * WINPOS_IsGoodEnough
519 static BOOL32 WINPOS_IsGoodEnough(WND* pWnd)
521 return (pWnd) ? ((!(pWnd->dwStyle & WS_DISABLED) &&
522 pWnd->dwStyle & WS_VISIBLE ) ? TRUE : FALSE) : FALSE;
526 /*******************************************************************
527 * SetActiveWindow (USER.59)
529 HWND SetActiveWindow( HWND hwnd )
531 HWND prev = hwndActive;
532 WND *wndPtr = WIN_FindWndPtr( hwnd );
534 if ( !WINPOS_IsGoodEnough(wndPtr) ) return 0;
536 WINPOS_SetActiveWindow( hwnd, 0, 0 );
537 return prev;
541 /***********************************************************************
542 * BringWindowToTop (USER.45)
544 BOOL BringWindowToTop( HWND hwnd )
546 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
550 /***********************************************************************
551 * MoveWindow (USER.56)
553 BOOL MoveWindow( HWND hwnd, short x, short y, short cx, short cy, BOOL repaint)
555 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
556 if (!repaint) flags |= SWP_NOREDRAW;
557 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
558 hwnd, x, y, cx, cy, repaint );
559 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
563 /***********************************************************************
564 * ShowWindow (USER.42)
566 BOOL ShowWindow( HWND hwnd, int cmd )
568 WND * wndPtr = WIN_FindWndPtr( hwnd );
569 BOOL32 wasVisible, showFlag;
570 POINT16 maxSize;
571 int swpflags = 0;
572 short x = 0, y = 0, cx = 0, cy = 0;
574 if (!wndPtr) return FALSE;
576 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
578 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
580 switch(cmd)
582 case SW_HIDE:
583 if (!wasVisible) return FALSE;
584 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
585 SWP_NOACTIVATE | SWP_NOZORDER;
586 break;
588 case SW_SHOWMINNOACTIVE:
589 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
590 /* fall through */
591 case SW_SHOWMINIMIZED:
592 swpflags |= SWP_SHOWWINDOW;
593 /* fall through */
594 case SW_MINIMIZE:
595 swpflags |= SWP_FRAMECHANGED;
596 if (!(wndPtr->dwStyle & WS_MINIMIZE))
598 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
599 return 0;
601 if (wndPtr->dwStyle & WS_MAXIMIZE)
603 wndPtr->flags |= WIN_RESTORE_MAX;
604 wndPtr->dwStyle &= ~WS_MAXIMIZE;
606 else
608 wndPtr->flags &= ~WIN_RESTORE_MAX;
609 wndPtr->rectNormal = wndPtr->rectWindow;
611 wndPtr->dwStyle |= WS_MINIMIZE;
612 WINPOS_FindIconPos( hwnd );
613 x = wndPtr->ptIconPos.x;
614 y = wndPtr->ptIconPos.y;
615 cx = SYSMETRICS_CXICON;
616 cy = SYSMETRICS_CYICON;
617 swpflags |= SWP_NOCOPYBITS;
619 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
620 break;
622 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
623 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
624 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
626 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
627 return 0;
629 /* Store the current position and find the maximized size */
630 if (!(wndPtr->dwStyle & WS_MINIMIZE))
631 wndPtr->rectNormal = wndPtr->rectWindow;
633 NC_GetMinMaxInfo( wndPtr, &maxSize,
634 &wndPtr->ptMaxPos, NULL, NULL );
635 x = wndPtr->ptMaxPos.x;
636 y = wndPtr->ptMaxPos.y;
638 if( wndPtr->dwStyle & WS_MINIMIZE )
639 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L ) )
641 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
642 break;
644 else swpflags |= SWP_NOCOPYBITS;
646 cx = maxSize.x;
647 cy = maxSize.y;
648 wndPtr->dwStyle &= ~WS_MINIMIZE;
649 wndPtr->dwStyle |= WS_MAXIMIZE;
651 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
652 break;
654 case SW_SHOWNA:
655 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
656 /* fall through */
657 case SW_SHOW:
658 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
659 break;
661 case SW_SHOWNOACTIVATE:
662 swpflags |= SWP_NOZORDER;
663 if (GetActiveWindow()) swpflags |= SWP_NOACTIVATE;
664 /* fall through */
665 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
666 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
667 case SW_RESTORE:
668 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
670 if (wndPtr->dwStyle & WS_MINIMIZE)
672 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
673 return 0;
675 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L) )
677 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
678 break;
680 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
681 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
682 wndPtr->dwStyle &= ~WS_MINIMIZE;
683 if (wndPtr->flags & WIN_RESTORE_MAX)
685 /* Restore to maximized position */
686 NC_GetMinMaxInfo( wndPtr, &maxSize, &wndPtr->ptMaxPos,
687 NULL, NULL );
688 x = wndPtr->ptMaxPos.x;
689 y = wndPtr->ptMaxPos.y;
690 cx = maxSize.x;
691 cy = maxSize.y;
692 wndPtr->dwStyle |= WS_MAXIMIZE;
694 else /* Restore to normal position */
696 x = wndPtr->rectNormal.left;
697 y = wndPtr->rectNormal.top;
698 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
699 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
701 swpflags |= SWP_NOCOPYBITS;
703 else if (wndPtr->dwStyle & WS_MAXIMIZE)
705 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
706 return 0;
708 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
709 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
710 wndPtr->dwStyle &= ~WS_MAXIMIZE;
711 x = wndPtr->rectNormal.left;
712 y = wndPtr->rectNormal.top;
713 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
714 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
716 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
717 break;
720 showFlag = (cmd != SW_HIDE);
721 if (showFlag != wasVisible)
723 SendMessage16( hwnd, WM_SHOWWINDOW, showFlag, 0 );
724 if (!IsWindow( hwnd )) return wasVisible;
727 if ((wndPtr->dwStyle & WS_CHILD) &&
728 !IsWindowVisible( wndPtr->parent->hwndSelf ) &&
729 (swpflags & SWP_NOSIZE) && (swpflags & SWP_NOMOVE))
731 /* Don't call SetWindowPos() on invisible child windows */
732 if (cmd == SW_HIDE) wndPtr->dwStyle &= ~WS_VISIBLE;
733 else wndPtr->dwStyle |= WS_VISIBLE;
735 else
737 /* We can't activate a child window */
738 if (wndPtr->dwStyle & WS_CHILD)
739 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
740 SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
741 if (!IsWindow( hwnd )) return wasVisible;
744 if (wndPtr->flags & WIN_NEED_SIZE)
746 /* should happen only in CreateWindowEx() */
747 int wParam = SIZE_RESTORED;
749 wndPtr->flags &= ~WIN_NEED_SIZE;
750 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
751 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
752 SendMessage16( hwnd, WM_SIZE, wParam,
753 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
754 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
755 SendMessage16( hwnd, WM_MOVE, 0,
756 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
759 return wasVisible;
763 /***********************************************************************
764 * GetInternalWindowPos16 (USER.460)
766 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
768 WINDOWPLACEMENT16 wndpl;
769 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
770 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
771 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
772 return wndpl.showCmd;
776 /***********************************************************************
777 * GetInternalWindowPos32 (USER32.244)
779 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
781 WINDOWPLACEMENT32 wndpl;
782 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
783 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
784 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
785 return wndpl.showCmd;
789 /***********************************************************************
790 * SetInternalWindowPos16 (USER.461)
792 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
793 LPRECT16 rect, LPPOINT16 pt )
795 WINDOWPLACEMENT16 wndpl;
796 WND *wndPtr = WIN_FindWndPtr( hwnd );
798 wndpl.length = sizeof(wndpl);
799 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
800 wndpl.showCmd = showCmd;
801 if (pt) wndpl.ptMinPosition = *pt;
802 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
803 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
804 SetWindowPlacement16( hwnd, &wndpl );
808 /***********************************************************************
809 * SetInternalWindowPos32 (USER32.482)
811 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
812 LPRECT32 rect, LPPOINT32 pt )
814 WINDOWPLACEMENT32 wndpl;
815 WND *wndPtr = WIN_FindWndPtr( hwnd );
817 wndpl.length = sizeof(wndpl);
818 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
819 wndpl.showCmd = showCmd;
820 if (pt) wndpl.ptMinPosition = *pt;
821 if (rect) wndpl.rcNormalPosition = *rect;
822 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
823 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
824 SetWindowPlacement32( hwnd, &wndpl );
828 /***********************************************************************
829 * GetWindowPlacement16 (USER.370)
831 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
833 WND *wndPtr = WIN_FindWndPtr( hwnd );
834 if (!wndPtr) return FALSE;
836 wndpl->length = sizeof(*wndpl);
837 wndpl->flags = 0;
838 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
839 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
840 wndpl->ptMinPosition = wndPtr->ptIconPos;
841 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
842 wndpl->rcNormalPosition = wndPtr->rectNormal;
843 return TRUE;
847 /***********************************************************************
848 * GetWindowPlacement32 (USER32.306)
850 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
852 WND *wndPtr = WIN_FindWndPtr( hwnd );
853 if (!wndPtr) return FALSE;
855 wndpl->length = sizeof(*wndpl);
856 wndpl->flags = 0;
857 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
858 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
859 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
860 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
861 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
862 return TRUE;
866 /***********************************************************************
867 * SetWindowPlacement16 (USER.371)
869 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
871 WND *wndPtr = WIN_FindWndPtr( hwnd );
872 if (!wndPtr) return FALSE;
874 if (wndpl->flags & WPF_SETMINPOSITION)
875 wndPtr->ptIconPos = wndpl->ptMinPosition;
876 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
877 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
878 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
879 wndPtr->rectNormal = wndpl->rcNormalPosition;
880 ShowWindow( hwnd, wndpl->showCmd );
881 return TRUE;
885 /***********************************************************************
886 * SetWindowPlacement32 (USER32.518)
888 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
890 WND *wndPtr = WIN_FindWndPtr( hwnd );
891 if (!wndPtr) return FALSE;
893 if (wndpl->flags & WPF_SETMINPOSITION)
894 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
895 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
896 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
897 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
898 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
899 ShowWindow( hwnd, wndpl->showCmd );
900 return TRUE;
904 /***********************************************************************
905 * WINPOS_ForceXWindowRaise
907 * Raise a window on top of the X stacking order, while preserving
908 * the correct Windows Z order.
910 static void WINPOS_ForceXWindowRaise( WND* pWnd )
912 XWindowChanges winChanges;
913 WND *wndPrev;
915 /* Raise all windows up to pWnd according to their Z order.
916 * (it would be easier with sibling-related Below but it doesn't
917 * work very well with SGI mwm for instance)
919 winChanges.stack_mode = Above;
920 while (pWnd)
922 if (pWnd->window) XReconfigureWMWindow( display, pWnd->window, 0,
923 CWStackMode, &winChanges );
924 wndPrev = WIN_GetDesktop()->child;
925 if (wndPrev == pWnd) break;
926 while (wndPrev && (wndPrev->next != pWnd)) wndPrev = wndPrev->next;
927 pWnd = wndPrev;
932 /*******************************************************************
933 * WINPOS_SetActiveWindow
935 * back-end to SetActiveWindow
937 BOOL32 WINPOS_SetActiveWindow( HWND32 hWnd, BOOL32 fMouse, BOOL32 fChangeFocus)
939 WND *wndPtr = WIN_FindWndPtr(hWnd);
940 WND *wndTemp = WIN_FindWndPtr(hwndActive);
941 CBTACTIVATESTRUCT16 *cbtStruct;
942 WORD wIconized=0;
943 HQUEUE16 hOldActiveQueue = (pActiveQueue)?pActiveQueue->self:0;
944 HQUEUE16 hNewActiveQueue;
946 /* paranoid checks */
947 if( hWnd == GetDesktopWindow32() || hWnd == hwndActive )
948 return 0;
950 /* if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
951 return 0;
954 if( wndTemp )
955 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
956 else
957 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
959 /* call CBT hook chain */
960 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
962 LRESULT wRet;
963 cbtStruct->fMouse = fMouse;
964 cbtStruct->hWndActive = hwndActive;
965 wRet = HOOK_CallHooks16( WH_CBT, HCBT_ACTIVATE, (WPARAM16)hWnd,
966 (LPARAM)SEGPTR_GET(cbtStruct) );
967 SEGPTR_FREE(cbtStruct);
968 if (wRet) return wRet;
971 /* set prev active wnd to current active wnd and send notification */
972 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
974 if (!SendMessage16( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
976 if (GetSysModalWindow16() != hWnd) return 0;
977 /* disregard refusal if hWnd is sysmodal */
980 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
981 MAKEWPARAM( WA_INACTIVE, wIconized ),
982 (LPARAM)hWnd );
984 /* check if something happened during message processing */
985 if( hwndPrevActive != hwndActive ) return 0;
988 /* set active wnd */
989 hwndActive = hWnd;
991 /* send palette messages */
992 if (hWnd && SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
993 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM16)hWnd, 0L );
995 /* if prev wnd is minimized redraw icon title
996 if( hwndPrevActive )
998 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
999 if(wndTemp)
1000 if(wndTemp->dwStyle & WS_MINIMIZE)
1001 RedrawIconTitle(hwndPrevActive);
1005 /* managed windows will get ConfigureNotify event */
1006 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
1008 /* check Z-order and bring hWnd to the top */
1009 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
1010 if (wndTemp->dwStyle & WS_VISIBLE) break;
1012 if( wndTemp != wndPtr )
1013 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
1014 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1015 if( !IsWindow(hWnd) ) return 0;
1018 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
1020 /* send WM_ACTIVATEAPP if necessary */
1021 if (hOldActiveQueue != hNewActiveQueue)
1023 WND **list, **ppWnd;
1025 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
1027 for (ppWnd = list; *ppWnd; ppWnd++)
1029 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
1031 if ((*ppWnd)->hmemTaskQ == hOldActiveQueue)
1032 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
1033 0, QUEUE_GetQueueTask(hNewActiveQueue) );
1035 HeapFree( SystemHeap, 0, list );
1038 pActiveQueue = (hNewActiveQueue)
1039 ? (MESSAGEQUEUE*) GlobalLock16(hNewActiveQueue) : NULL;
1041 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
1043 for (ppWnd = list; *ppWnd; ppWnd++)
1045 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
1047 if ((*ppWnd)->hmemTaskQ == hNewActiveQueue)
1048 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
1049 1, QUEUE_GetQueueTask( hOldActiveQueue ) );
1051 HeapFree( SystemHeap, 0, list );
1053 if (!IsWindow(hWnd)) return 0;
1056 if (hWnd)
1058 /* walk up to the first unowned window */
1059 wndTemp = wndPtr;
1060 while (wndTemp->owner) wndTemp = wndTemp->owner;
1061 /* and set last active owned popup */
1062 wndTemp->hwndLastActive = hWnd;
1064 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1065 SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
1066 SendMessage32A( hWnd, WM_ACTIVATE,
1067 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1068 (LPARAM)hwndPrevActive );
1070 if( !IsWindow(hWnd) ) return 0;
1073 /* change focus if possible */
1074 if( fChangeFocus && GetFocus32() )
1075 if( WIN_GetTopParent(GetFocus32()) != hwndActive )
1076 FOCUS_SwitchFocus( GetFocus32(),
1077 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
1079 if( !hwndPrevActive && wndPtr &&
1080 wndPtr->window && !(wndPtr->flags & WIN_MANAGED) )
1081 WINPOS_ForceXWindowRaise(wndPtr);
1083 /* if active wnd is minimized redraw icon title
1084 if( hwndActive )
1086 wndPtr = WIN_FindWndPtr(hwndActive);
1087 if(wndPtr->dwStyle & WS_MINIMIZE)
1088 RedrawIconTitle(hwndActive);
1091 return (hWnd == hwndActive);
1094 /*******************************************************************
1095 * WINPOS_ActivateOtherWindow
1097 * DestroyWindow() helper. pWnd must be a top-level window.
1099 BOOL32 WINPOS_ActivateOtherWindow(WND* pWnd)
1101 BOOL32 bRet = 0;
1102 WND* pWndTo = NULL;
1104 if( pWnd->hwndSelf == hwndPrevActive )
1105 hwndPrevActive = 0;
1107 if( hwndActive != pWnd->hwndSelf &&
1108 ( hwndActive || QUEUE_IsDoomedQueue(pWnd->hmemTaskQ)) )
1109 return 0;
1111 if( pWnd->dwStyle & WS_POPUP &&
1112 WINPOS_IsGoodEnough( pWnd->owner ) ) pWndTo = pWnd->owner;
1113 else
1115 WND* pWndPtr = pWnd;
1117 pWndTo = WIN_FindWndPtr(hwndPrevActive);
1119 while( !WINPOS_IsGoodEnough(pWndTo) )
1121 /* by now owned windows should've been taken care of */
1123 pWndTo = pWndPtr->next;
1124 pWndPtr = pWndTo;
1125 if( !pWndTo ) return 0;
1129 bRet = WINPOS_SetActiveWindow( pWndTo->hwndSelf, FALSE, TRUE );
1131 /* switch desktop queue to current active */
1132 if( pWndTo->parent == WIN_GetDesktop())
1133 WIN_GetDesktop()->hmemTaskQ = pWndTo->hmemTaskQ;
1135 hwndPrevActive = 0;
1136 return bRet;
1139 /*******************************************************************
1140 * WINPOS_ChangeActiveWindow
1143 BOOL32 WINPOS_ChangeActiveWindow( HWND32 hWnd, BOOL32 mouseMsg )
1145 WND *wndPtr = WIN_FindWndPtr(hWnd);
1147 if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE );
1149 if( !wndPtr ) return FALSE;
1151 /* child windows get WM_CHILDACTIVATE message */
1152 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1153 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1155 /* owned popups imply owner activation - not sure */
1156 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1157 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1159 if (!(wndPtr = wndPtr->owner)) return FALSE;
1160 hWnd = wndPtr->hwndSelf;
1163 if( hWnd == hwndActive ) return FALSE;
1165 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1166 return FALSE;
1168 /* switch desktop queue to current active */
1169 if( wndPtr->parent == WIN_GetDesktop())
1170 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1172 return TRUE;
1176 /***********************************************************************
1177 * WINPOS_SendNCCalcSize
1179 * Send a WM_NCCALCSIZE message to a window.
1180 * All parameters are read-only except newClientRect.
1181 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1182 * when calcValidRect is TRUE.
1184 LONG WINPOS_SendNCCalcSize( HWND32 hwnd, BOOL32 calcValidRect,
1185 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1186 RECT16 *oldClientRect, SEGPTR winpos,
1187 RECT16 *newClientRect )
1189 NCCALCSIZE_PARAMS16 *params;
1190 LONG result;
1192 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1193 params->rgrc[0] = *newWindowRect;
1194 if (calcValidRect)
1196 params->rgrc[1] = *oldWindowRect;
1197 params->rgrc[2] = *oldClientRect;
1198 params->lppos = winpos;
1200 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1201 (LPARAM)SEGPTR_GET( params ) );
1202 dprintf_win( stddeb, "WINPOS_SendNCCalcSize: %d,%d-%d,%d\n",
1203 params->rgrc[0].left, params->rgrc[0].top,
1204 params->rgrc[0].right, params->rgrc[0].bottom );
1205 *newClientRect = params->rgrc[0];
1206 SEGPTR_FREE(params);
1207 return result;
1211 /***********************************************************************
1212 * WINPOS_HandleWindowPosChanging16
1214 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1216 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1218 POINT16 maxSize;
1219 if (winpos->flags & SWP_NOSIZE) return 0;
1220 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1221 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1223 NC_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL );
1224 winpos->cx = MIN( winpos->cx, maxSize.x );
1225 winpos->cy = MIN( winpos->cy, maxSize.y );
1227 return 0;
1231 /***********************************************************************
1232 * WINPOS_HandleWindowPosChanging32
1234 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1236 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1238 POINT16 maxSize;
1239 if (winpos->flags & SWP_NOSIZE) return 0;
1240 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1241 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1243 NC_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL );
1244 winpos->cx = MIN( winpos->cx, maxSize.x );
1245 winpos->cy = MIN( winpos->cy, maxSize.y );
1247 return 0;
1251 /***********************************************************************
1252 * WINPOS_MoveWindowZOrder
1254 * Move a window in Z order, invalidating everything that needs it.
1255 * Only necessary for windows without associated X window.
1257 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
1259 BOOL movingUp;
1260 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1262 /* We have two possible cases:
1263 * - The window is moving up: we have to invalidate all areas
1264 * of the window that were covered by other windows
1265 * - The window is moving down: we have to invalidate areas
1266 * of other windows covered by this one.
1269 if (hwndAfter == HWND_TOP)
1271 movingUp = TRUE;
1273 else if (hwndAfter == HWND_BOTTOM)
1275 if (!wndPtr->next) return; /* Already at the bottom */
1276 movingUp = FALSE;
1278 else
1280 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1281 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1283 /* Determine which window we encounter first in Z-order */
1284 pWndCur = wndPtr->parent->child;
1285 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1286 pWndCur = pWndCur->next;
1287 movingUp = (pWndCur == pWndAfter);
1290 if (movingUp)
1292 WND *pWndPrevAfter = wndPtr->next;
1293 WIN_UnlinkWindow( hwnd );
1294 WIN_LinkWindow( hwnd, hwndAfter );
1295 pWndCur = wndPtr->next;
1296 while (pWndCur != pWndPrevAfter)
1298 RECT32 rect = { pWndCur->rectWindow.left,
1299 pWndCur->rectWindow.top,
1300 pWndCur->rectWindow.right,
1301 pWndCur->rectWindow.bottom };
1302 OffsetRect32( &rect, -wndPtr->rectClient.left,
1303 -wndPtr->rectClient.top );
1304 PAINT_RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1305 RDW_FRAME | RDW_ERASE, 0 );
1306 pWndCur = pWndCur->next;
1309 else /* Moving down */
1311 pWndCur = wndPtr->next;
1312 WIN_UnlinkWindow( hwnd );
1313 WIN_LinkWindow( hwnd, hwndAfter );
1314 while (pWndCur != wndPtr)
1316 RECT32 rect = { pWndCur->rectWindow.left,
1317 pWndCur->rectWindow.top,
1318 pWndCur->rectWindow.right,
1319 pWndCur->rectWindow.bottom };
1320 OffsetRect32( &rect, -pWndCur->rectClient.left,
1321 -pWndCur->rectClient.top );
1322 PAINT_RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1323 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1324 pWndCur = pWndCur->next;
1329 /***********************************************************************
1330 * WINPOS_ReorderOwnedPopups
1332 * fix Z order taking into account owned popups -
1333 * basically we need to maintain them above owner window
1335 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
1337 WND* w = WIN_GetDesktop()->child;
1339 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner )
1341 /* implement "local z-order" between the top and owner window */
1343 HWND hwndLocalPrev = HWND_TOP;
1345 if( hwndInsertAfter != HWND_TOP )
1347 while( w != wndPtr->owner )
1349 if (w != wndPtr) hwndLocalPrev = w->hwndSelf;
1350 if( hwndLocalPrev == hwndInsertAfter ) break;
1351 w = w->next;
1353 hwndInsertAfter = hwndLocalPrev;
1357 else if( wndPtr->dwStyle & WS_CHILD ) return hwndInsertAfter;
1359 w = WIN_GetDesktop()->child;
1360 while( w )
1362 if( w == wndPtr ) break;
1364 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1366 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1367 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1368 hwndInsertAfter = w->hwndSelf;
1370 w = w->next;
1373 return hwndInsertAfter;
1376 /***********************************************************************
1377 * WINPOS_SizeMoveClean
1379 * Make window look nice without excessive repainting
1381 * the pain:
1383 * visible regions are in window coordinates
1384 * update regions are in window client coordinates
1385 * client and window rectangles are in parent client coordinates
1387 static UINT WINPOS_SizeMoveClean(WND* Wnd, HRGN32 oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, UINT uFlags )
1389 HRGN32 newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf,DCX_WINDOW | DCX_CLIPSIBLINGS);
1390 HRGN32 dirtyRgn = CreateRectRgn32(0,0,0,0);
1391 int other, my;
1393 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1394 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1395 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1396 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1397 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1398 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1400 if( (lpOldWndRect->right - lpOldWndRect->left) != (Wnd->rectWindow.right - Wnd->rectWindow.left) ||
1401 (lpOldWndRect->bottom - lpOldWndRect->top) != (Wnd->rectWindow.bottom - Wnd->rectWindow.top) )
1402 uFlags |= SMC_DRAWFRAME;
1404 CombineRgn32( dirtyRgn, newVisRgn, 0, RGN_COPY);
1406 if( !(uFlags & SMC_NOCOPY) )
1407 CombineRgn32( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1409 /* map regions to the parent client area */
1411 OffsetRgn32( dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top );
1412 OffsetRgn32( oldVisRgn, lpOldWndRect->left, lpOldWndRect->top );
1414 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1416 other = CombineRgn32(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1418 /* map visible region to the Wnd client area */
1420 OffsetRgn32( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1421 Wnd->rectWindow.top - Wnd->rectClient.top );
1423 /* substract previously invalidated region from the Wnd visible region */
1425 my = (Wnd->hrgnUpdate > 1) ? CombineRgn32( newVisRgn, newVisRgn,
1426 Wnd->hrgnUpdate, RGN_DIFF)
1427 : COMPLEXREGION;
1429 if( uFlags & SMC_NOCOPY ) /* invalidate Wnd visible region */
1431 if (my != NULLREGION)
1432 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1433 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1434 else if(uFlags & SMC_DRAWFRAME)
1435 Wnd->flags |= WIN_NEEDS_NCPAINT;
1437 else /* bitblt old client area */
1439 HDC32 hDC;
1440 int update;
1441 HRGN32 updateRgn;
1442 int xfrom,yfrom,xto,yto,width,height;
1444 if( uFlags & SMC_DRAWFRAME )
1446 /* copy only client area, frame will be redrawn anyway */
1448 xfrom = lpOldClientRect->left; yfrom = lpOldClientRect->top;
1449 xto = Wnd->rectClient.left; yto = Wnd->rectClient.top;
1450 width = lpOldClientRect->right - xfrom; height = lpOldClientRect->bottom - yfrom;
1451 updateRgn = CreateRectRgn32( 0, 0, width, height );
1452 CombineRgn32( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1453 SetRectRgn( updateRgn, 0, 0, Wnd->rectClient.right - xto, Wnd->rectClient.bottom - yto );
1455 else
1457 xfrom = lpOldWndRect->left; yfrom = lpOldWndRect->top;
1458 xto = Wnd->rectWindow.left; yto = Wnd->rectWindow.top;
1459 width = lpOldWndRect->right - xfrom; height = lpOldWndRect->bottom - yfrom;
1460 updateRgn = CreateRectRgn32( xto - Wnd->rectClient.left,
1461 yto - Wnd->rectClient.top,
1462 Wnd->rectWindow.right - Wnd->rectClient.left,
1463 Wnd->rectWindow.bottom - Wnd->rectClient.top );
1466 CombineRgn32( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1468 /* substract new visRgn from target rect to get a region that won't be copied */
1470 update = CombineRgn32( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1472 /* Blt valid bits using parent window DC */
1474 if( my != NULLREGION && (xfrom != xto || yfrom != yto) )
1477 /* compute clipping region in parent client coordinates */
1479 OffsetRgn32( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top );
1480 CombineRgn32( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1482 hDC = GetDCEx32( Wnd->parent->hwndSelf, oldVisRgn,
1483 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
1484 DCX_CACHE | DCX_CLIPSIBLINGS);
1486 BitBlt32( hDC, xto, yto, width, height, hDC, xfrom, yfrom, SRCCOPY );
1487 ReleaseDC32( Wnd->parent->hwndSelf, hDC);
1490 if( update != NULLREGION )
1491 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1492 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1493 else if( uFlags & SMC_DRAWFRAME ) Wnd->flags |= WIN_NEEDS_NCPAINT;
1494 DeleteObject32( updateRgn );
1497 /* erase uncovered areas */
1499 if( !(uFlags & SMC_NOPARENTERASE) && (other != NULLREGION ) )
1500 PAINT_RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1501 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1502 DeleteObject32(dirtyRgn);
1503 DeleteObject32(newVisRgn);
1504 return uFlags;
1508 /***********************************************************************
1509 * WINPOS_FindDeskTopXWindow
1511 * Find the actual X window which needs be restacked.
1512 * Used by WINPOS_SetXWindowPos().
1514 static Window WINPOS_FindDeskTopXWindow( WND *wndPtr )
1516 if (!(wndPtr->flags & WIN_MANAGED))
1517 return wndPtr->window;
1518 else
1520 Window window, root, parent, *children;
1521 int nchildren;
1522 window = wndPtr->window;
1523 for (;;)
1525 XQueryTree( display, window, &root, &parent,
1526 &children, &nchildren );
1527 XFree( children );
1528 if (parent == root)
1529 return window;
1530 window = parent;
1535 /***********************************************************************
1536 * WINPOS_SetXWindowPos
1538 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1540 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1542 XWindowChanges winChanges;
1543 int changeMask = 0;
1544 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1546 if (!(winpos->flags & SWP_NOSIZE))
1548 winChanges.width = winpos->cx;
1549 winChanges.height = winpos->cy;
1550 changeMask |= CWWidth | CWHeight;
1552 /* Tweak dialog window size hints */
1554 if ((wndPtr->flags & WIN_MANAGED) &&
1555 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1557 XSizeHints *size_hints = XAllocSizeHints();
1559 if (size_hints)
1561 long supplied_return;
1563 XGetWMSizeHints( display, wndPtr->window, size_hints,
1564 &supplied_return, XA_WM_NORMAL_HINTS);
1565 size_hints->min_width = size_hints->max_width = winpos->cx;
1566 size_hints->min_height = size_hints->max_height = winpos->cy;
1567 XSetWMSizeHints( display, wndPtr->window, size_hints,
1568 XA_WM_NORMAL_HINTS );
1569 XFree(size_hints);
1573 if (!(winpos->flags & SWP_NOMOVE))
1575 winChanges.x = winpos->x;
1576 winChanges.y = winpos->y;
1577 changeMask |= CWX | CWY;
1579 if (!(winpos->flags & SWP_NOZORDER))
1581 winChanges.stack_mode = Below;
1582 changeMask |= CWStackMode;
1584 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1585 else if (winpos->hwndInsertAfter != HWND_BOTTOM)
1587 WND* insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1588 Window stack[2];
1590 stack[0] = WINPOS_FindDeskTopXWindow( insertPtr );
1591 stack[1] = WINPOS_FindDeskTopXWindow( wndPtr );
1593 /* for stupid window managers (i.e. all of them) */
1595 XRestackWindows(display, stack, 2);
1596 changeMask &= ~CWStackMode;
1599 if (!changeMask) return;
1601 XReconfigureWMWindow( display, wndPtr->window, 0, changeMask, &winChanges );
1605 /***********************************************************************
1606 * SetWindowPos (USER.232)
1608 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1609 INT cx, INT cy, WORD flags )
1611 WINDOWPOS16 *winpos;
1612 WND * wndPtr;
1613 RECT16 newWindowRect, newClientRect, oldWindowRect;
1614 HRGN32 visRgn = 0;
1615 HWND tempInsertAfter= 0;
1616 int result = 0;
1617 UINT uFlags = 0;
1619 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
1620 hwnd, x, y, x+cx, y+cy, flags);
1621 /* Check window handle */
1623 if (hwnd == GetDesktopWindow32()) return FALSE;
1624 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1626 if (wndPtr->dwStyle & WS_VISIBLE) flags &= ~SWP_SHOWWINDOW;
1627 else
1629 uFlags |= SMC_NOPARENTERASE;
1630 flags &= ~SWP_HIDEWINDOW;
1631 if (!(flags & SWP_SHOWWINDOW)) flags |= SWP_NOREDRAW;
1634 /* Check for windows that may not be resized
1635 FIXME: this should be done only for Windows 3.0 programs
1636 if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
1637 flags |= SWP_NOSIZE | SWP_NOMOVE;
1639 /* Check dimensions */
1641 if (cx <= 0) cx = 1;
1642 if (cy <= 0) cy = 1;
1644 /* Check flags */
1646 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1647 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1648 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1649 flags |= SWP_NOSIZE; /* Already the right size */
1650 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1651 flags |= SWP_NOMOVE; /* Already the right position */
1653 /* Check hwndInsertAfter */
1655 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1657 /* Ignore TOPMOST flags when activating a window */
1658 /* _and_ moving it in Z order. */
1659 if ((hwndInsertAfter == HWND_TOPMOST) ||
1660 (hwndInsertAfter == HWND_NOTOPMOST))
1661 hwndInsertAfter = HWND_TOP;
1663 /* TOPMOST not supported yet */
1664 if ((hwndInsertAfter == HWND_TOPMOST) ||
1665 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1667 /* hwndInsertAfter must be a sibling of the window */
1668 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1670 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1671 if( wnd->parent != wndPtr->parent ) return FALSE;
1672 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1674 else if (!(wndPtr->window))
1675 /* FIXME: the following optimization is no good for "X-ed" windows */
1676 if (hwndInsertAfter == HWND_TOP)
1677 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1678 else /* HWND_BOTTOM */
1679 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1681 /* Fill the WINDOWPOS structure */
1683 if (!(winpos = SEGPTR_NEW(WINDOWPOS16))) return FALSE;
1684 winpos->hwnd = hwnd;
1685 winpos->hwndInsertAfter = hwndInsertAfter;
1686 winpos->x = x;
1687 winpos->y = y;
1688 winpos->cx = cx;
1689 winpos->cy = cy;
1690 winpos->flags = flags;
1692 /* Send WM_WINDOWPOSCHANGING message */
1694 if (!(flags & SWP_NOSENDCHANGING))
1695 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0,
1696 (LPARAM)SEGPTR_GET(winpos) );
1698 /* Calculate new position and size */
1700 newWindowRect = wndPtr->rectWindow;
1701 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1702 : wndPtr->rectClient;
1704 if (!(winpos->flags & SWP_NOSIZE))
1706 newWindowRect.right = newWindowRect.left + winpos->cx;
1707 newWindowRect.bottom = newWindowRect.top + winpos->cy;
1709 if (!(winpos->flags & SWP_NOMOVE))
1711 newWindowRect.left = winpos->x;
1712 newWindowRect.top = winpos->y;
1713 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
1714 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
1716 OffsetRect16( &newClientRect, winpos->x - wndPtr->rectWindow.left,
1717 winpos->y - wndPtr->rectWindow.top );
1720 winpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1722 /* Reposition window in Z order */
1724 if (!(winpos->flags & SWP_NOZORDER))
1726 /* reorder owned popups if hwnd is top-level window
1728 if( wndPtr->parent == WIN_GetDesktop() )
1729 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1730 wndPtr, flags );
1732 if (wndPtr->window)
1734 WIN_UnlinkWindow( winpos->hwnd );
1735 WIN_LinkWindow( winpos->hwnd, hwndInsertAfter );
1737 else WINPOS_MoveWindowZOrder( winpos->hwnd, hwndInsertAfter );
1740 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1741 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1742 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1745 /* Send WM_NCCALCSIZE message to get new client area */
1746 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1748 result = WINPOS_SendNCCalcSize( winpos->hwnd, TRUE, &newWindowRect,
1749 &wndPtr->rectWindow, &wndPtr->rectClient,
1750 SEGPTR_GET(winpos), &newClientRect );
1752 /* FIXME: WVR_ALIGNxxx */
1754 if( newClientRect.left != wndPtr->rectClient.left ||
1755 newClientRect.top != wndPtr->rectClient.top )
1756 winpos->flags &= ~SWP_NOCLIENTMOVE;
1758 if( (newClientRect.right - newClientRect.left !=
1759 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1760 (newClientRect.bottom - newClientRect.top !=
1761 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1762 winpos->flags &= ~SWP_NOCLIENTSIZE;
1764 else
1765 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1766 newClientRect.top != wndPtr->rectClient.top) )
1767 winpos->flags &= ~SWP_NOCLIENTMOVE;
1769 /* Update active DCEs */
1771 if( !(flags & SWP_NOZORDER) || (flags & SWP_HIDEWINDOW) || (flags & SWP_SHOWWINDOW)
1772 || (memcmp(&newWindowRect,&wndPtr->rectWindow,sizeof(RECT16))
1773 && wndPtr->dwStyle & WS_VISIBLE ) )
1775 RECT16 rect;
1777 UnionRect16(&rect,&newWindowRect,&wndPtr->rectWindow);
1778 DCE_InvalidateDCE(wndPtr->parent, &rect);
1781 /* change geometry */
1783 oldWindowRect = wndPtr->rectWindow;
1785 if (wndPtr->window)
1787 RECT16 oldClientRect = wndPtr->rectClient;
1789 tempInsertAfter = winpos->hwndInsertAfter;
1791 winpos->hwndInsertAfter = hwndInsertAfter;
1793 /* postpone geometry change */
1795 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1797 WINPOS_SetXWindowPos( winpos );
1798 winpos->hwndInsertAfter = tempInsertAfter;
1800 else uFlags |= SMC_SETXPOS;
1802 wndPtr->rectWindow = newWindowRect;
1803 wndPtr->rectClient = newClientRect;
1805 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1806 if( (oldClientRect.left - oldWindowRect.left !=
1807 newClientRect.left - newWindowRect.left) ||
1808 (oldClientRect.top - oldWindowRect.top !=
1809 newClientRect.top - newWindowRect.top) || winpos->flags & SWP_NOCOPYBITS )
1811 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
1812 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1813 else
1814 if( winpos->flags & SWP_FRAMECHANGED )
1816 WORD wErase = 0;
1817 RECT32 rect;
1819 if( oldClientRect.right > newClientRect.right )
1821 rect.left = newClientRect.right; rect.top = newClientRect.top;
1822 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1823 wErase = 1;
1824 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1825 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1827 if( oldClientRect.bottom > newClientRect.bottom )
1829 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1830 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1831 rect.bottom = oldClientRect.bottom;
1832 wErase = 1;
1833 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1834 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1836 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1839 else
1841 RECT16 oldClientRect = wndPtr->rectClient;
1843 wndPtr->rectWindow = newWindowRect;
1844 wndPtr->rectClient = newClientRect;
1846 if( oldClientRect.bottom - oldClientRect.top ==
1847 newClientRect.bottom - newClientRect.top ) result &= ~WVR_VREDRAW;
1849 if( oldClientRect.right - oldClientRect.left ==
1850 newClientRect.right - newClientRect.left ) result &= ~WVR_HREDRAW;
1852 if( !(flags & (SWP_NOREDRAW | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
1854 uFlags |= ((winpos->flags & SWP_NOCOPYBITS) ||
1855 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS)) ? SMC_NOCOPY : 0;
1856 uFlags |= (winpos->flags & SWP_FRAMECHANGED) ? SMC_DRAWFRAME : 0;
1858 if( (winpos->flags & SWP_AGG_NOGEOMETRYCHANGE) != SWP_AGG_NOGEOMETRYCHANGE )
1859 uFlags = WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect,
1860 &oldClientRect, uFlags);
1861 else
1863 /* adjust frame and do not erase parent */
1865 if( winpos->flags & SWP_FRAMECHANGED ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1866 if( winpos->flags & SWP_NOZORDER ) uFlags |= SMC_NOPARENTERASE;
1869 DeleteObject32(visRgn);
1872 if (flags & SWP_SHOWWINDOW)
1874 wndPtr->dwStyle |= WS_VISIBLE;
1875 if (wndPtr->window)
1877 if( uFlags & SMC_SETXPOS )
1879 WINPOS_SetXWindowPos( winpos );
1880 winpos->hwndInsertAfter = tempInsertAfter;
1882 XMapWindow( display, wndPtr->window );
1884 else
1886 if (!(flags & SWP_NOREDRAW))
1887 PAINT_RedrawWindow( winpos->hwnd, NULL, 0,
1888 RDW_INVALIDATE | RDW_ALLCHILDREN |
1889 RDW_FRAME | RDW_ERASENOW | RDW_ERASE, 0 );
1892 else if (flags & SWP_HIDEWINDOW)
1894 wndPtr->dwStyle &= ~WS_VISIBLE;
1895 if (wndPtr->window)
1897 XUnmapWindow( display, wndPtr->window );
1898 if( uFlags & SMC_SETXPOS )
1900 WINPOS_SetXWindowPos( winpos );
1901 winpos->hwndInsertAfter = tempInsertAfter;
1904 else
1906 if (!(flags & SWP_NOREDRAW))
1908 RECT32 rect = { oldWindowRect.left, oldWindowRect.top,
1909 oldWindowRect.right, oldWindowRect.bottom };
1910 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, &rect, 0,
1911 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE | RDW_ERASENOW, 0);
1913 uFlags |= SMC_NOPARENTERASE;
1916 if ((winpos->hwnd == GetFocus32()) ||
1917 IsChild( winpos->hwnd, GetFocus32()))
1919 /* Revert focus to parent */
1920 SetFocus32( GetParent32(winpos->hwnd) );
1922 if (hwnd == CARET_GetHwnd()) DestroyCaret();
1924 if (winpos->hwnd == hwndActive)
1926 /* Activate previously active window if possible */
1927 HWND newActive = hwndPrevActive;
1928 if (!IsWindow(newActive) || (newActive == winpos->hwnd))
1930 newActive = GetTopWindow( GetDesktopWindow32() );
1931 if (newActive == winpos->hwnd)
1932 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1934 WINPOS_ChangeActiveWindow( newActive, FALSE );
1938 /* Activate the window */
1940 if (!(flags & SWP_NOACTIVATE))
1941 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
1943 /* Repaint the window */
1945 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
1947 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1949 if (!(flags & SWP_DEFERERASE) && !(uFlags & SMC_NOPARENTERASE) )
1951 RECT32 rect;
1952 CONV_RECT16TO32( &oldWindowRect, &rect );
1953 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, (wndPtr->flags & WIN_SAVEUNDER_OVERRIDE)
1954 ? &rect : NULL, 0, RDW_ALLCHILDREN | RDW_ERASENOW |
1955 ((wndPtr->flags & WIN_SAVEUNDER_OVERRIDE) ? RDW_INVALIDATE : 0), 0 );
1956 wndPtr->flags &= ~WIN_SAVEUNDER_OVERRIDE;
1958 else if( wndPtr->parent == WIN_GetDesktop() && wndPtr->parent->flags & WIN_NEEDS_ERASEBKGND )
1959 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_NOCHILDREN | RDW_ERASENOW, 0 );
1961 /* And last, send the WM_WINDOWPOSCHANGED message */
1963 dprintf_win(stddeb,"\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1965 if ( ((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
1966 !(winpos->flags & SWP_NOSENDCHANGING))
1967 SendMessage16( winpos->hwnd, WM_WINDOWPOSCHANGED,
1968 0, (LPARAM)SEGPTR_GET(winpos) );
1970 SEGPTR_FREE(winpos);
1971 return TRUE;
1975 /***********************************************************************
1976 * BeginDeferWindowPos (USER.259)
1978 HDWP16 BeginDeferWindowPos( INT count )
1980 HDWP16 handle;
1981 DWP *pDWP;
1983 if (count <= 0) return 0;
1984 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS16) );
1985 if (!handle) return 0;
1986 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1987 pDWP->actualCount = 0;
1988 pDWP->suggestedCount = count;
1989 pDWP->valid = TRUE;
1990 pDWP->wMagic = DWP_MAGIC;
1991 pDWP->hwndParent = 0;
1992 return handle;
1996 /***********************************************************************
1997 * DeferWindowPos (USER.260)
1999 HDWP16 DeferWindowPos( HDWP16 hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
2000 INT cx, INT cy, UINT flags )
2002 DWP *pDWP;
2003 int i;
2004 HDWP16 newhdwp = hdwp;
2005 HWND parent;
2007 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2008 if (!pDWP) return 0;
2009 if (hwnd == GetDesktopWindow32()) return 0;
2011 /* All the windows of a DeferWindowPos() must have the same parent */
2013 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
2014 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
2015 else if (parent != pDWP->hwndParent)
2017 USER_HEAP_FREE( hdwp );
2018 return 0;
2021 for (i = 0; i < pDWP->actualCount; i++)
2023 if (pDWP->winPos[i].hwnd == hwnd)
2025 /* Merge with the other changes */
2026 if (!(flags & SWP_NOZORDER))
2028 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
2030 if (!(flags & SWP_NOMOVE))
2032 pDWP->winPos[i].x = x;
2033 pDWP->winPos[i].y = y;
2035 if (!(flags & SWP_NOSIZE))
2037 pDWP->winPos[i].cx = cx;
2038 pDWP->winPos[i].cy = cy;
2040 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
2041 SWP_NOZORDER | SWP_NOREDRAW |
2042 SWP_NOACTIVATE | SWP_NOCOPYBITS |
2043 SWP_NOOWNERZORDER);
2044 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2045 SWP_FRAMECHANGED);
2046 return hdwp;
2049 if (pDWP->actualCount >= pDWP->suggestedCount)
2051 newhdwp = USER_HEAP_REALLOC( hdwp,
2052 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS16) );
2053 if (!newhdwp) return 0;
2054 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2055 pDWP->suggestedCount++;
2057 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2058 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2059 pDWP->winPos[pDWP->actualCount].x = x;
2060 pDWP->winPos[pDWP->actualCount].y = y;
2061 pDWP->winPos[pDWP->actualCount].cx = cx;
2062 pDWP->winPos[pDWP->actualCount].cy = cy;
2063 pDWP->winPos[pDWP->actualCount].flags = flags;
2064 pDWP->actualCount++;
2065 return newhdwp;
2069 /***********************************************************************
2070 * EndDeferWindowPos (USER.261)
2072 BOOL EndDeferWindowPos( HDWP16 hdwp )
2074 DWP *pDWP;
2075 WINDOWPOS16 *winpos;
2076 BOOL res = TRUE;
2077 int i;
2079 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2080 if (!pDWP) return FALSE;
2081 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2083 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
2084 winpos->x, winpos->y, winpos->cx, winpos->cy,
2085 winpos->flags ))) break;
2087 USER_HEAP_FREE( hdwp );
2088 return res;
2092 /***********************************************************************
2093 * TileChildWindows (USER.199)
2095 void TileChildWindows( HWND parent, WORD action )
2097 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
2100 /***********************************************************************
2101 * CascageChildWindows (USER.198)
2103 void CascadeChildWindows( HWND parent, WORD action )
2105 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);