2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
8 #include "sysmetrics.h"
16 #include "stackframe.h"
19 #include "nonclient.h"
21 /* #define DEBUG_WIN */
24 #define SWP_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
26 /* ----- external functions ----- */
28 extern void FOCUS_SwitchFocus( HWND , HWND );
29 extern HRGN DCE_GetVisRgn( HWND, WORD );
30 extern HWND CARET_GetHwnd();
31 extern BOOL DCE_InvalidateDCE(WND*, RECT16* );
33 /* ----- internal variables ----- */
35 static HWND hwndActive = 0; /* Currently active window */
36 static HWND hwndPrevActive = 0; /* Previously active window */
38 /***********************************************************************
41 * Find a suitable place for an iconic window.
42 * The new position is stored into wndPtr->ptIconPos.
44 void WINPOS_FindIconPos( HWND hwnd )
47 short x, y, xspacing, yspacing;
48 WND * wndPtr = WIN_FindWndPtr( hwnd );
50 if (!wndPtr || !wndPtr->parent) return;
51 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
52 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
53 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
54 (wndPtr->ptIconPos.y >= rectParent.top) &&
55 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
56 return; /* The icon already has a suitable position */
58 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
59 y = rectParent.bottom;
62 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
64 /* Check if another icon already occupies this spot */
65 WND *childPtr = wndPtr->parent->child;
68 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
70 if ((childPtr->rectWindow.left < x + xspacing) &&
71 (childPtr->rectWindow.right >= x) &&
72 (childPtr->rectWindow.top <= y) &&
73 (childPtr->rectWindow.bottom > y - yspacing))
74 break; /* There's a window in there */
76 childPtr = childPtr->next;
80 /* No window was found, so it's OK for us */
81 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
82 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
91 /***********************************************************************
92 * ArrangeIconicWindows (USER.170)
94 UINT ArrangeIconicWindows( HWND parent )
98 INT x, y, xspacing, yspacing;
100 GetClientRect16( parent, &rectParent );
102 y = rectParent.bottom;
103 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
104 hwndChild = GetWindow( parent, GW_CHILD );
107 if (IsIconic( hwndChild ))
109 SetWindowPos( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
110 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
111 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
112 if (x <= rectParent.right - xspacing) x += xspacing;
119 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
125 /***********************************************************************
126 * GetWindowRect16 (USER.32)
128 void GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
130 WND * wndPtr = WIN_FindWndPtr( hwnd );
133 *rect = wndPtr->rectWindow;
134 if (wndPtr->dwStyle & WS_CHILD)
135 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
139 /***********************************************************************
140 * GetWindowRect32 (USER.32)
142 void GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
144 WND * wndPtr = WIN_FindWndPtr( hwnd );
147 CONV_RECT16TO32( &wndPtr->rectWindow, rect );
148 if (wndPtr->dwStyle & WS_CHILD)
149 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
153 /***********************************************************************
154 * GetClientRect16 (USER.33)
156 void GetClientRect16( HWND16 hwnd, LPRECT16 rect )
158 WND * wndPtr = WIN_FindWndPtr( hwnd );
160 rect->left = rect->top = rect->right = rect->bottom = 0;
163 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
164 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
169 /***********************************************************************
170 * GetClientRect32 (USER32.219)
172 void GetClientRect32( HWND32 hwnd, LPRECT32 rect )
174 WND * wndPtr = WIN_FindWndPtr( hwnd );
176 rect->left = rect->top = rect->right = rect->bottom = 0;
179 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
180 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
185 /*******************************************************************
186 * ClientToScreen16 (USER.28)
188 BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
190 MapWindowPoints16( hwnd, 0, lppnt, 1 );
195 /*******************************************************************
196 * ClientToScreen32 (USER32.51)
198 BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
200 MapWindowPoints32( hwnd, 0, lppnt, 1 );
205 /*******************************************************************
206 * ScreenToClient16 (USER.29)
208 void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
210 MapWindowPoints16( 0, hwnd, lppnt, 1 );
214 /*******************************************************************
215 * ScreenToClient32 (USER32.446)
217 void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
219 MapWindowPoints32( 0, hwnd, lppnt, 1 );
223 /***********************************************************************
224 * WINPOS_WindowFromPoint
226 * Find the window and hittest for a given point.
228 INT16 WINPOS_WindowFromPoint( POINT16 pt, WND **ppWnd )
231 INT16 hittest = HTERROR;
237 wndPtr = WIN_GetDesktop()->child;
242 /* If point is in window, and window is visible, and it */
243 /* is enabled (or it's a top-level window), then explore */
244 /* its children. Otherwise, go to the next window. */
246 if ((wndPtr->dwStyle & WS_VISIBLE) &&
247 (!(wndPtr->dwStyle & WS_DISABLED) ||
248 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
249 (x >= wndPtr->rectWindow.left) &&
250 (x < wndPtr->rectWindow.right) &&
251 (y >= wndPtr->rectWindow.top) &&
252 (y < wndPtr->rectWindow.bottom))
254 *ppWnd = wndPtr; /* Got a suitable window */
256 /* If window is minimized or disabled, return at once */
257 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
258 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
260 /* If point is not in client area, ignore the children */
261 if ((x < wndPtr->rectClient.left) ||
262 (x >= wndPtr->rectClient.right) ||
263 (y < wndPtr->rectClient.top) ||
264 (y >= wndPtr->rectClient.bottom)) break;
266 x -= wndPtr->rectClient.left;
267 y -= wndPtr->rectClient.top;
268 wndPtr = wndPtr->child;
270 else wndPtr = wndPtr->next;
273 /* If nothing found, return the desktop window */
276 *ppWnd = WIN_GetDesktop();
280 /* Send the WM_NCHITTEST message (only if to the same task) */
281 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
282 hittest = (INT)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
283 MAKELONG( pt.x, pt.y ) );
284 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
286 /* If no children found in last search, make point relative to parent*/
289 x += (*ppWnd)->rectClient.left;
290 y += (*ppWnd)->rectClient.top;
293 /* Restart the search from the next sibling */
294 wndPtr = (*ppWnd)->next;
295 *ppWnd = (*ppWnd)->parent;
300 /*******************************************************************
301 * WindowFromPoint16 (USER.30)
303 HWND16 WindowFromPoint16( POINT16 pt )
306 WINPOS_WindowFromPoint( pt, &pWnd );
307 return pWnd->hwndSelf;
311 /*******************************************************************
312 * WindowFromPoint32 (USER32.581)
314 HWND32 WindowFromPoint32( POINT32 pt )
318 CONV_POINT32TO16( &pt, &pt16 );
319 WINPOS_WindowFromPoint( pt16, &pWnd );
320 return (HWND32)pWnd->hwndSelf;
324 /*******************************************************************
325 * ChildWindowFromPoint16 (USER.191)
327 HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
329 /* pt is in the client coordinates */
331 WND* wnd = WIN_FindWndPtr(hwndParent);
336 /* get client rect fast */
337 rect.top = rect.left = 0;
338 rect.right = wnd->rectClient.right - wnd->rectClient.left;
339 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
341 if (!PtInRect16( &rect, pt )) return 0;
346 if (PtInRect16( &wnd->rectWindow, pt )) return wnd->hwndSelf;
353 /*******************************************************************
354 * ChildWindowFromPoint32 (USER32.)
356 HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
359 CONV_POINT32TO16( &pt, &pt16 );
360 return (HWND32)ChildWindowFromPoint16( hwndParent, pt16 );
364 /*******************************************************************
365 * WINPOS_GetWinOffset
367 * Calculate the offset between the origin of the two windows. Used
368 * to implement MapWindowPoints.
370 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
375 offset->x = offset->y = 0;
376 if (hwndFrom == hwndTo ) return;
378 /* Translate source window origin to screen coords */
381 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
383 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
386 while (wndPtr->parent)
388 offset->x += wndPtr->rectClient.left;
389 offset->y += wndPtr->rectClient.top;
390 wndPtr = wndPtr->parent;
394 /* Translate origin to destination window coords */
397 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
399 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
402 while (wndPtr->parent)
404 offset->x -= wndPtr->rectClient.left;
405 offset->y -= wndPtr->rectClient.top;
406 wndPtr = wndPtr->parent;
412 /*******************************************************************
413 * MapWindowPoints16 (USER.258)
415 void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
416 LPPOINT16 lppt, UINT16 count )
420 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
430 /*******************************************************************
431 * MapWindowPoints32 (USER32.385)
433 void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
434 LPPOINT32 lppt, UINT32 count )
438 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
448 /***********************************************************************
451 BOOL IsIconic(HWND hWnd)
453 WND * wndPtr = WIN_FindWndPtr(hWnd);
454 if (wndPtr == NULL) return FALSE;
455 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
459 /***********************************************************************
460 * IsZoomed (USER.272)
462 BOOL IsZoomed(HWND hWnd)
464 WND * wndPtr = WIN_FindWndPtr(hWnd);
465 if (wndPtr == NULL) return FALSE;
466 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
470 /*******************************************************************
471 * GetActiveWindow (USER.60)
473 HWND GetActiveWindow()
479 /*******************************************************************
480 * SetActiveWindow (USER.59)
482 HWND SetActiveWindow( HWND hwnd )
484 HWND prev = hwndActive;
485 WND *wndPtr = WIN_FindWndPtr( hwnd );
487 if (!wndPtr || (wndPtr->dwStyle & WS_DISABLED) ||
488 !(wndPtr->dwStyle & WS_VISIBLE)) return 0;
490 WINPOS_SetActiveWindow( hwnd, 0, 0 );
495 /***********************************************************************
496 * BringWindowToTop (USER.45)
498 BOOL BringWindowToTop( HWND hwnd )
500 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
504 /***********************************************************************
505 * MoveWindow (USER.56)
507 BOOL MoveWindow( HWND hwnd, short x, short y, short cx, short cy, BOOL repaint)
509 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
510 if (!repaint) flags |= SWP_NOREDRAW;
511 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
512 hwnd, x, y, cx, cy, repaint );
513 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
517 /***********************************************************************
518 * ShowWindow (USER.42)
520 BOOL ShowWindow( HWND hwnd, int cmd )
522 WND * wndPtr = WIN_FindWndPtr( hwnd );
526 short x = 0, y = 0, cx = 0, cy = 0;
528 if (!wndPtr) return FALSE;
530 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
532 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
537 if (!wasVisible) return FALSE;
538 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
539 SWP_NOACTIVATE | SWP_NOZORDER;
542 case SW_SHOWMINNOACTIVE:
543 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
545 case SW_SHOWMINIMIZED:
546 swpflags |= SWP_SHOWWINDOW;
549 swpflags |= SWP_FRAMECHANGED;
550 if (!(wndPtr->dwStyle & WS_MINIMIZE))
552 if (wndPtr->dwStyle & WS_MAXIMIZE)
554 wndPtr->flags |= WIN_RESTORE_MAX;
555 wndPtr->dwStyle &= ~WS_MAXIMIZE;
559 wndPtr->flags &= ~WIN_RESTORE_MAX;
560 wndPtr->rectNormal = wndPtr->rectWindow;
562 wndPtr->dwStyle |= WS_MINIMIZE;
563 WINPOS_FindIconPos( hwnd );
564 x = wndPtr->ptIconPos.x;
565 y = wndPtr->ptIconPos.y;
566 cx = SYSMETRICS_CXICON;
567 cy = SYSMETRICS_CYICON;
569 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
572 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
573 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
574 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
576 /* Store the current position and find the maximized size */
577 if (!(wndPtr->dwStyle & WS_MINIMIZE))
578 wndPtr->rectNormal = wndPtr->rectWindow;
580 NC_GetMinMaxInfo( hwnd, &maxSize,
581 &wndPtr->ptMaxPos, NULL, NULL );
582 x = wndPtr->ptMaxPos.x;
583 y = wndPtr->ptMaxPos.y;
585 if( wndPtr->dwStyle & WS_MINIMIZE )
586 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L ) )
588 swpflags |= SWP_NOSIZE;
594 wndPtr->dwStyle &= ~WS_MINIMIZE;
595 wndPtr->dwStyle |= WS_MAXIMIZE;
597 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
601 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
604 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
607 case SW_SHOWNOACTIVATE:
608 swpflags |= SWP_NOZORDER;
609 if (GetActiveWindow()) swpflags |= SWP_NOACTIVATE;
611 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
612 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
614 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
616 if (wndPtr->dwStyle & WS_MINIMIZE)
618 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L) )
620 swpflags |= SWP_NOSIZE;
623 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
624 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
625 wndPtr->dwStyle &= ~WS_MINIMIZE;
626 if (wndPtr->flags & WIN_RESTORE_MAX)
628 /* Restore to maximized position */
629 NC_GetMinMaxInfo( hwnd, &maxSize, &wndPtr->ptMaxPos,
631 x = wndPtr->ptMaxPos.x;
632 y = wndPtr->ptMaxPos.y;
635 wndPtr->dwStyle |= WS_MAXIMIZE;
637 else /* Restore to normal position */
639 x = wndPtr->rectNormal.left;
640 y = wndPtr->rectNormal.top;
641 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
642 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
645 else if (wndPtr->dwStyle & WS_MAXIMIZE)
647 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
648 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
649 wndPtr->dwStyle &= ~WS_MAXIMIZE;
650 x = wndPtr->rectNormal.left;
651 y = wndPtr->rectNormal.top;
652 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
653 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
655 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
659 SendMessage16( hwnd, WM_SHOWWINDOW, (cmd != SW_HIDE), 0 );
660 SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
662 if (wndPtr->flags & WIN_NEED_SIZE)
664 int wParam = SIZE_RESTORED;
666 wndPtr->flags &= ~WIN_NEED_SIZE;
667 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
668 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
669 SendMessage16( hwnd, WM_SIZE, wParam,
670 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
671 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
672 SendMessage16( hwnd, WM_MOVE, 0,
673 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
676 if (hwnd == GetFocus())
678 SetFocus( (wndPtr->dwStyle & WS_CHILD)? wndPtr->parent->hwndSelf: 0 );
679 if (hwnd == CARET_GetHwnd()) DestroyCaret();
686 /***********************************************************************
687 * GetInternalWindowPos16 (USER.460)
689 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
691 WINDOWPLACEMENT16 wndpl;
692 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
693 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
694 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
695 return wndpl.showCmd;
699 /***********************************************************************
700 * GetInternalWindowPos32 (USER32.244)
702 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
704 WINDOWPLACEMENT32 wndpl;
705 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
706 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
707 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
708 return wndpl.showCmd;
712 /***********************************************************************
713 * SetInternalWindowPos16 (USER.461)
715 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
716 LPRECT16 rect, LPPOINT16 pt )
718 WINDOWPLACEMENT16 wndpl;
719 WND *wndPtr = WIN_FindWndPtr( hwnd );
721 wndpl.length = sizeof(wndpl);
722 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
723 wndpl.showCmd = showCmd;
724 if (pt) wndpl.ptMinPosition = *pt;
725 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
726 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
727 SetWindowPlacement16( hwnd, &wndpl );
731 /***********************************************************************
732 * SetInternalWindowPos32 (USER32.482)
734 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
735 LPRECT32 rect, LPPOINT32 pt )
737 WINDOWPLACEMENT32 wndpl;
738 WND *wndPtr = WIN_FindWndPtr( hwnd );
740 wndpl.length = sizeof(wndpl);
741 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
742 wndpl.showCmd = showCmd;
743 if (pt) wndpl.ptMinPosition = *pt;
744 if (rect) wndpl.rcNormalPosition = *rect;
745 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
746 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
747 SetWindowPlacement32( hwnd, &wndpl );
751 /***********************************************************************
752 * GetWindowPlacement16 (USER.370)
754 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
756 WND *wndPtr = WIN_FindWndPtr( hwnd );
757 if (!wndPtr) return FALSE;
759 wndpl->length = sizeof(*wndpl);
761 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
762 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
763 wndpl->ptMinPosition = wndPtr->ptIconPos;
764 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
765 wndpl->rcNormalPosition = wndPtr->rectNormal;
770 /***********************************************************************
771 * GetWindowPlacement32 (USER32.306)
773 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
775 WND *wndPtr = WIN_FindWndPtr( hwnd );
776 if (!wndPtr) return FALSE;
778 wndpl->length = sizeof(*wndpl);
780 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
781 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
782 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
783 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
784 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
789 /***********************************************************************
790 * SetWindowPlacement16 (USER.371)
792 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
794 WND *wndPtr = WIN_FindWndPtr( hwnd );
795 if (!wndPtr) return FALSE;
797 if (wndpl->flags & WPF_SETMINPOSITION)
798 wndPtr->ptIconPos = wndpl->ptMinPosition;
799 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
800 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
801 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
802 wndPtr->rectNormal = wndpl->rcNormalPosition;
803 ShowWindow( hwnd, wndpl->showCmd );
808 /***********************************************************************
809 * SetWindowPlacement32 (USER32.518)
811 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
813 WND *wndPtr = WIN_FindWndPtr( hwnd );
814 if (!wndPtr) return FALSE;
816 if (wndpl->flags & WPF_SETMINPOSITION)
817 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
818 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
819 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
820 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
821 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
822 ShowWindow( hwnd, wndpl->showCmd );
827 /*******************************************************************
828 * WINPOS_SetActiveWindow
830 * back-end to SetActiveWindow
832 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus )
834 WND *wndPtr = WIN_FindWndPtr(hWnd);
835 WND *wndTemp = WIN_FindWndPtr(hwndActive);
836 CBTACTIVATESTRUCT16 *cbtStruct;
839 /* FIXME: When proper support for cooperative multitasking is in place
840 * hActiveQ will be global
845 /* paranoid checks */
846 if( !hWnd || hWnd == GetDesktopWindow() || hWnd == hwndActive )
849 if( GetTaskQueue(0) != wndPtr->hmemTaskQ )
853 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
855 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
857 /* call CBT hook chain */
858 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
861 cbtStruct->fMouse = fMouse;
862 cbtStruct->hWndActive = hwndActive;
863 wRet = HOOK_CallHooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd,
864 (LPARAM)SEGPTR_GET(cbtStruct) );
865 SEGPTR_FREE(cbtStruct);
866 if (wRet) return wRet;
869 /* set prev active wnd to current active wnd and send notification */
870 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
872 if (!SendMessage16( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
874 if (GetSysModalWindow() != hWnd) return 0;
875 /* disregard refusal if hWnd is sysmodal */
878 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
879 MAKEWPARAM( WA_INACTIVE, wIconized ),
882 /* check if something happened during message processing */
883 if( hwndPrevActive != hwndActive ) return 0;
889 /* send palette messages */
890 if( SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L) )
891 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
893 /* if prev wnd is minimized redraw icon title
896 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
898 if(wndTemp->dwStyle & WS_MINIMIZE)
899 RedrawIconTitle(hwndPrevActive);
903 /* managed windows will get ConfigureNotify event */
904 if (!(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
906 /* check Z-order and bring hWnd to the top */
907 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
908 if (wndTemp->dwStyle & WS_VISIBLE) break;
910 if( wndTemp != wndPtr )
911 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
912 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
915 if( !IsWindow(hWnd) ) return 0;
919 wndTemp = WIN_FindWndPtr( hwndPrevActive );
920 if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
923 /* send WM_ACTIVATEAPP if necessary */
924 if (hActiveQ != wndPtr->hmemTaskQ)
928 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
930 for (ppWnd = list; *ppWnd; ppWnd++)
932 /* Make sure that the window still exists */
933 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
934 if ((*ppWnd)->hmemTaskQ != hActiveQ) continue;
935 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
936 0, QUEUE_GetQueueTask(wndPtr->hmemTaskQ) );
938 HeapFree( SystemHeap, 0, list );
941 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
943 for (ppWnd = list; *ppWnd; ppWnd++)
945 /* Make sure that the window still exists */
946 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
947 if ((*ppWnd)->hmemTaskQ != wndPtr->hmemTaskQ) continue;
948 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
949 1, QUEUE_GetQueueTask( hActiveQ ) );
951 HeapFree( SystemHeap, 0, list );
953 if (!IsWindow(hWnd)) return 0;
956 /* walk up to the first unowned window */
958 while (wndTemp->owner) wndTemp = wndTemp->owner;
959 /* and set last active owned popup */
960 wndTemp->hwndLastActive = hWnd;
962 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
963 SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
965 SendMessage32A( hWnd, WM_ACTIVATE,
966 MAKEWPARAM( (fMouse)?WA_CLICKACTIVE:WA_ACTIVE, wIconized),
967 (LPARAM)hwndPrevActive );
969 SendMessage16( hWnd, WM_ACTIVATE, (fMouse)? WA_CLICKACTIVE : WA_ACTIVE,
970 MAKELONG(hwndPrevActive,wIconized));
973 if( !IsWindow(hWnd) ) return 0;
975 /* change focus if possible */
976 if( fChangeFocus && GetFocus() )
977 if( WIN_GetTopParent(GetFocus()) != hwndActive )
978 FOCUS_SwitchFocus( GetFocus(),
979 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
981 /* if active wnd is minimized redraw icon title
984 wndPtr = WIN_FindWndPtr(hwndActive);
985 if(wndPtr->dwStyle & WS_MINIMIZE)
986 RedrawIconTitle(hwndActive);
989 return (hWnd == hwndActive);
993 /*******************************************************************
994 * WINPOS_ChangeActiveWindow
997 BOOL WINPOS_ChangeActiveWindow( HWND hWnd, BOOL mouseMsg )
999 WND *wndPtr = WIN_FindWndPtr(hWnd);
1001 if( !wndPtr ) return FALSE;
1003 /* child windows get WM_CHILDACTIVATE message */
1004 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1005 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1007 /* owned popups imply owner activation - not sure */
1008 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1009 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1011 if (!(wndPtr = wndPtr->owner)) return FALSE;
1012 hWnd = wndPtr->hwndSelf;
1015 if( hWnd == hwndActive ) return FALSE;
1017 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1020 /* switch desktop queue to current active */
1021 if( wndPtr->parent == WIN_GetDesktop())
1022 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1028 /***********************************************************************
1029 * WINPOS_SendNCCalcSize
1031 * Send a WM_NCCALCSIZE message to a window.
1032 * All parameters are read-only except newClientRect.
1033 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1034 * when calcValidRect is TRUE.
1036 LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect,
1037 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1038 RECT16 *oldClientRect, SEGPTR winpos,
1039 RECT16 *newClientRect )
1041 NCCALCSIZE_PARAMS16 *params;
1044 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1045 params->rgrc[0] = *newWindowRect;
1048 params->rgrc[1] = *oldWindowRect;
1049 params->rgrc[2] = *oldClientRect;
1050 params->lppos = winpos;
1052 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1053 (LPARAM)SEGPTR_GET( params ) );
1054 dprintf_win(stddeb, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
1055 (int)params->rgrc[0].top, (int)params->rgrc[0].left,
1056 (int)params->rgrc[0].bottom, (int)params->rgrc[0].right);
1057 *newClientRect = params->rgrc[0];
1058 SEGPTR_FREE(params);
1063 /***********************************************************************
1064 * WINPOS_HandleWindowPosChanging16
1066 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1068 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1071 if (winpos->flags & SWP_NOSIZE) return 0;
1072 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1073 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1075 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1076 winpos->cx = MIN( winpos->cx, maxSize.x );
1077 winpos->cy = MIN( winpos->cy, maxSize.y );
1083 /***********************************************************************
1084 * WINPOS_HandleWindowPosChanging32
1086 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1088 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1091 if (winpos->flags & SWP_NOSIZE) return 0;
1092 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1093 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1095 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1096 winpos->cx = MIN( winpos->cx, maxSize.x );
1097 winpos->cy = MIN( winpos->cy, maxSize.y );
1103 /***********************************************************************
1104 * WINPOS_MoveWindowZOrder
1106 * Move a window in Z order, invalidating everything that needs it.
1107 * Only necessary for windows without associated X window.
1109 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
1112 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1114 /* We have two possible cases:
1115 * - The window is moving up: we have to invalidate all areas
1116 * of the window that were covered by other windows
1117 * - The window is moving down: we have to invalidate areas
1118 * of other windows covered by this one.
1121 if (hwndAfter == HWND_TOP)
1125 else if (hwndAfter == HWND_BOTTOM)
1127 if (!wndPtr->next) return; /* Already at the bottom */
1132 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1133 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1135 /* Determine which window we encounter first in Z-order */
1136 pWndCur = wndPtr->parent->child;
1137 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1138 pWndCur = pWndCur->next;
1139 movingUp = (pWndCur == pWndAfter);
1144 WND *pWndPrevAfter = wndPtr->next;
1145 WIN_UnlinkWindow( hwnd );
1146 WIN_LinkWindow( hwnd, hwndAfter );
1147 pWndCur = wndPtr->next;
1148 while (pWndCur != pWndPrevAfter)
1150 RECT16 rect = pWndCur->rectWindow;
1151 OffsetRect16( &rect, -wndPtr->rectClient.left,
1152 -wndPtr->rectClient.top );
1153 RedrawWindow16( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1154 RDW_FRAME | RDW_ERASE );
1155 pWndCur = pWndCur->next;
1158 else /* Moving down */
1160 pWndCur = wndPtr->next;
1161 WIN_UnlinkWindow( hwnd );
1162 WIN_LinkWindow( hwnd, hwndAfter );
1163 while (pWndCur != wndPtr)
1165 RECT16 rect = wndPtr->rectWindow;
1166 OffsetRect16( &rect, -pWndCur->rectClient.left,
1167 -pWndCur->rectClient.top );
1168 RedrawWindow16( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1169 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
1170 pWndCur = pWndCur->next;
1175 /***********************************************************************
1176 * WINPOS_ReorderOwnedPopups
1178 * fix Z order taking into account owned popups -
1179 * basically we need to maintain them above owner window
1181 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
1183 WND* w = WIN_GetDesktop();
1187 /* if we are dealing with owned popup...
1189 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner && hwndInsertAfter != HWND_TOP )
1191 BOOL bFound = FALSE;
1192 HWND hwndLocalPrev = HWND_TOP;
1193 HWND hwndNewAfter = 0;
1197 if( !bFound && hwndInsertAfter == hwndLocalPrev )
1198 hwndInsertAfter = HWND_TOP;
1200 if( w->dwStyle & WS_POPUP && w->owner == wndPtr->owner )
1204 if( hwndInsertAfter == HWND_TOP )
1206 hwndInsertAfter = hwndLocalPrev;
1209 hwndNewAfter = hwndLocalPrev;
1212 if( w == wndPtr->owner )
1214 /* basically HWND_BOTTOM */
1215 hwndInsertAfter = hwndLocalPrev;
1218 hwndInsertAfter = hwndNewAfter;
1223 hwndLocalPrev = w->hwndSelf;
1229 /* or overlapped top-level window...
1231 if( !(wndPtr->dwStyle & WS_CHILD) )
1234 if( w == wndPtr ) break;
1236 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1238 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1239 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1240 hwndInsertAfter = w->hwndSelf;
1245 return hwndInsertAfter;
1248 /***********************************************************************
1249 * WINPOS_SizeMoveClean
1251 * Make window look nice without excessive repainting
1255 * visible regions are in window coordinates
1256 * update regions are in window client coordinates
1257 * client and window rectangles are in parent client coordinates
1259 static void WINPOS_SizeMoveClean(WND* Wnd, HRGN oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, BOOL bNoCopy )
1261 HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf, DCX_WINDOW | DCX_CLIPSIBLINGS );
1262 HRGN dirtyRgn = CreateRectRgn(0,0,0,0);
1265 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1266 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1267 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1268 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1269 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1270 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1272 CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY);
1276 HRGN hRgn = CreateRectRgn( lpOldClientRect->left - lpOldWndRect->left, lpOldClientRect->top - lpOldWndRect->top,
1277 lpOldClientRect->right - lpOldWndRect->left, lpOldClientRect->bottom - lpOldWndRect->top);
1278 CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1279 CombineRgn( newVisRgn, newVisRgn, hRgn, RGN_AND );
1283 /* map regions to the parent client area */
1285 OffsetRgn(dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top);
1286 OffsetRgn(oldVisRgn, lpOldWndRect->left, lpOldWndRect->top);
1288 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1290 other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1292 /* map visible region to the Wnd client area */
1294 OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1295 Wnd->rectWindow.top - Wnd->rectClient.top );
1297 /* substract previously invalidated region from the Wnd visible region */
1299 my = (Wnd->hrgnUpdate > 1)? CombineRgn( newVisRgn, newVisRgn, Wnd->hrgnUpdate, RGN_DIFF)
1302 if( bNoCopy ) /* invalidate Wnd visible region */
1304 if (my != NULLREGION) RedrawWindow32( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1305 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1307 else /* bitblt old client area */
1315 updateRgn = CreateRectRgn( 0,0, Wnd->rectClient.right - Wnd->rectClient.left,
1316 Wnd->rectClient.bottom - Wnd->rectClient.top );
1318 /* clip visible region with client rect */
1320 my = CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1322 /* substract result from client rect to get region that won't be copied */
1324 update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1326 /* Blt valid bits using parent window DC */
1328 if( my != NULLREGION )
1330 int xfrom = lpOldClientRect->left;
1331 int yfrom = lpOldClientRect->top;
1332 int xto = Wnd->rectClient.left;
1333 int yto = Wnd->rectClient.top;
1335 /* check if we can skip copying */
1337 if( xfrom != xto || yfrom != yto )
1339 /* compute clipping region in parent client coordinates */
1341 OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top);
1342 CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1344 hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS);
1346 BitBlt(hDC, xto, yto, lpOldClientRect->right - lpOldClientRect->left,
1347 lpOldClientRect->bottom - lpOldClientRect->top,
1348 hDC, xfrom, yfrom, SRCCOPY );
1350 ReleaseDC( Wnd->parent->hwndSelf, hDC);
1354 if( update != NULLREGION )
1355 RedrawWindow32( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1356 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1357 DeleteObject( updateRgn );
1360 /* erase uncovered areas */
1362 if( other != NULLREGION )
1363 RedrawWindow32( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1364 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1366 DeleteObject(dirtyRgn);
1367 DeleteObject(newVisRgn);
1370 /***********************************************************************
1371 * WINPOS_SetXWindowPos
1373 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1375 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1377 XWindowChanges winChanges;
1379 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1381 if (!(winpos->flags & SWP_NOSIZE))
1383 winChanges.width = winpos->cx;
1384 winChanges.height = winpos->cy;
1385 changeMask |= CWWidth | CWHeight;
1387 if (!(winpos->flags & SWP_NOMOVE))
1389 winChanges.x = winpos->x;
1390 winChanges.y = winpos->y;
1391 changeMask |= CWX | CWY;
1393 if (!(winpos->flags & SWP_NOZORDER))
1395 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1396 else winChanges.stack_mode = Below;
1397 if ((winpos->hwndInsertAfter != HWND_TOP) &&
1398 (winpos->hwndInsertAfter != HWND_BOTTOM))
1400 WND * insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1401 winChanges.sibling = insertPtr->window;
1402 changeMask |= CWSibling;
1404 changeMask |= CWStackMode;
1407 XConfigureWindow( display, wndPtr->window, changeMask, &winChanges );
1411 /***********************************************************************
1412 * SetWindowPos (USER.232)
1414 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1415 INT cx, INT cy, WORD flags )
1419 RECT16 newWindowRect, newClientRect;
1423 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, flags %08x\n", hwnd, flags);
1425 /* Check window handle */
1427 if (hwnd == GetDesktopWindow()) return FALSE;
1428 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1430 /* Check for windows that may not be resized
1431 FIXME: this should be done only for Windows 3.0 programs */
1432 if (flags ==(SWP_SHOWWINDOW) || flags ==(SWP_HIDEWINDOW ) )
1433 flags |= SWP_NOSIZE | SWP_NOMOVE;
1435 /* Check dimensions */
1437 if (cx <= 0) cx = 1;
1438 if (cy <= 0) cy = 1;
1442 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1443 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1444 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1445 flags |= SWP_NOSIZE; /* Already the right size */
1446 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1447 flags |= SWP_NOMOVE; /* Already the right position */
1449 /* Check hwndInsertAfter */
1451 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1453 /* Ignore TOPMOST flags when activating a window */
1454 /* _and_ moving it in Z order. */
1455 if ((hwndInsertAfter == HWND_TOPMOST) ||
1456 (hwndInsertAfter == HWND_NOTOPMOST))
1457 hwndInsertAfter = HWND_TOP;
1459 /* TOPMOST not supported yet */
1460 if ((hwndInsertAfter == HWND_TOPMOST) ||
1461 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1463 /* hwndInsertAfter must be a sibling of the window */
1464 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1466 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1467 if( wnd->parent != wndPtr->parent ) return FALSE;
1468 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1471 if (hwndInsertAfter == HWND_TOP)
1472 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1473 else /* HWND_BOTTOM */
1474 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1476 /* Fill the WINDOWPOS structure */
1479 winpos.hwndInsertAfter = hwndInsertAfter;
1484 winpos.flags = flags;
1486 /* Send WM_WINDOWPOSCHANGING message */
1488 if (!(flags & SWP_NOSENDCHANGING))
1489 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1491 /* Calculate new position and size */
1493 newWindowRect = wndPtr->rectWindow;
1494 newClientRect = wndPtr->rectClient;
1496 if (!(winpos.flags & SWP_NOSIZE))
1498 newWindowRect.right = newWindowRect.left + winpos.cx;
1499 newWindowRect.bottom = newWindowRect.top + winpos.cy;
1501 if (!(winpos.flags & SWP_NOMOVE))
1503 newWindowRect.left = winpos.x;
1504 newWindowRect.top = winpos.y;
1505 newWindowRect.right += winpos.x - wndPtr->rectWindow.left;
1506 newWindowRect.bottom += winpos.y - wndPtr->rectWindow.top;
1508 OffsetRect16( &newClientRect, winpos.x - wndPtr->rectWindow.left,
1509 winpos.y - wndPtr->rectWindow.top );
1512 winpos.flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1514 /* Reposition window in Z order */
1516 if (!(winpos.flags & SWP_NOZORDER))
1518 /* reorder owned popups if hwnd is top-level window
1520 if( wndPtr->parent == WIN_GetDesktop() )
1521 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1526 WIN_UnlinkWindow( winpos.hwnd );
1527 WIN_LinkWindow( winpos.hwnd, hwndInsertAfter );
1529 else WINPOS_MoveWindowZOrder( winpos.hwnd, hwndInsertAfter );
1532 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1533 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1534 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1537 /* Send WM_NCCALCSIZE message to get new client area */
1538 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1540 result = WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
1541 &wndPtr->rectWindow, &wndPtr->rectClient,
1542 MAKE_SEGPTR(&winpos), &newClientRect );
1544 /* FIXME: WVR_ALIGNxxx */
1546 if( newClientRect.left != wndPtr->rectClient.left ||
1547 newClientRect.top != wndPtr->rectClient.top )
1548 winpos.flags &= ~SWP_NOCLIENTMOVE;
1550 if( (newClientRect.right - newClientRect.left !=
1551 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1552 (newClientRect.bottom - newClientRect.top !=
1553 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1554 winpos.flags &= ~SWP_NOCLIENTSIZE;
1557 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1558 newClientRect.top != wndPtr->rectClient.top) )
1559 winpos.flags &= ~SWP_NOCLIENTMOVE;
1561 /* Update active DCEs */
1563 if( !(flags & SWP_NOZORDER) || (flags & SWP_HIDEWINDOW) || (flags & SWP_SHOWWINDOW)
1564 || (memcmp(&newWindowRect,&wndPtr->rectWindow,sizeof(RECT16))
1565 && wndPtr->dwStyle & WS_VISIBLE ) )
1569 UnionRect16(&rect,&newWindowRect,&wndPtr->rectWindow);
1570 DCE_InvalidateDCE(wndPtr->parent, &rect);
1573 /* Perform the moving and resizing */
1577 RECT16 oldWindowRect = wndPtr->rectWindow;
1578 RECT16 oldClientRect = wndPtr->rectClient;
1580 HWND bogusInsertAfter = winpos.hwndInsertAfter;
1582 winpos.hwndInsertAfter = hwndInsertAfter;
1583 WINPOS_SetXWindowPos( &winpos );
1585 wndPtr->rectWindow = newWindowRect;
1586 wndPtr->rectClient = newClientRect;
1587 winpos.hwndInsertAfter = bogusInsertAfter;
1589 /* FIXME: should do something like WINPOS_SizeMoveClean */
1591 if( (oldClientRect.left - oldWindowRect.left !=
1592 newClientRect.left - newWindowRect.left) ||
1593 (oldClientRect.top - oldWindowRect.top !=
1594 newClientRect.top - newWindowRect.top) )
1596 RedrawWindow32( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
1597 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
1599 if( winpos.flags & SWP_FRAMECHANGED )
1604 if( oldClientRect.right > newClientRect.right )
1606 rect.left = newClientRect.right; rect.top = newClientRect.top;
1607 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1609 RedrawWindow32( wndPtr->hwndSelf, &rect, 0,
1610 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN );
1612 if( oldClientRect.bottom > newClientRect.bottom )
1614 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1615 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1616 rect.bottom = oldClientRect.bottom;
1618 RedrawWindow32( wndPtr->hwndSelf, &rect, 0,
1619 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN );
1621 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1626 RECT16 oldWindowRect = wndPtr->rectWindow;
1627 RECT16 oldClientRect = wndPtr->rectClient;
1629 wndPtr->rectWindow = newWindowRect;
1630 wndPtr->rectClient = newClientRect;
1632 if( !(flags & SWP_NOREDRAW) )
1634 BOOL bNoCopy = (flags & SWP_NOCOPYBITS) ||
1635 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS);
1637 if( (winpos.flags & SWP_NOPOSCHANGE) != SWP_NOPOSCHANGE )
1638 /* optimize cleanup by BitBlt'ing where possible */
1640 WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect, &oldClientRect, bNoCopy);
1642 if( winpos.flags & SWP_FRAMECHANGED )
1643 RedrawWindow32( winpos.hwnd, NULL, 0, RDW_NOCHILDREN | RDW_FRAME );
1646 DeleteObject(visRgn);
1649 if (flags & SWP_SHOWWINDOW)
1651 wndPtr->dwStyle |= WS_VISIBLE;
1654 XMapWindow( display, wndPtr->window );
1658 if (!(flags & SWP_NOREDRAW))
1659 RedrawWindow32( winpos.hwnd, NULL, 0,
1660 RDW_INVALIDATE | RDW_ALLCHILDREN |
1661 RDW_FRAME | RDW_ERASE );
1664 else if (flags & SWP_HIDEWINDOW)
1666 wndPtr->dwStyle &= ~WS_VISIBLE;
1669 XUnmapWindow( display, wndPtr->window );
1673 if (!(flags & SWP_NOREDRAW))
1674 RedrawWindow16( wndPtr->parent->hwndSelf, &wndPtr->rectWindow, 0,
1675 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1678 if ((winpos.hwnd == GetFocus()) || IsChild(winpos.hwnd, GetFocus()))
1679 SetFocus( GetParent(winpos.hwnd) ); /* Revert focus to parent */
1681 if (winpos.hwnd == hwndActive)
1683 /* Activate previously active window if possible */
1684 HWND newActive = hwndPrevActive;
1685 if (!IsWindow(newActive) || (newActive == winpos.hwnd))
1687 newActive = GetTopWindow( GetDesktopWindow() );
1688 if (newActive == winpos.hwnd)
1689 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1691 WINPOS_ChangeActiveWindow( newActive, FALSE );
1695 /* Activate the window */
1697 if (!(flags & SWP_NOACTIVATE))
1698 WINPOS_ChangeActiveWindow( winpos.hwnd, FALSE );
1700 /* Repaint the window */
1702 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
1704 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1706 if (!(flags & SWP_DEFERERASE))
1707 RedrawWindow32( wndPtr->parent->hwndSelf, NULL, 0,
1708 RDW_ALLCHILDREN | RDW_ERASENOW );
1710 /* And last, send the WM_WINDOWPOSCHANGED message */
1712 if (!(winpos.flags & SWP_NOSENDCHANGING))
1713 SendMessage16( winpos.hwnd, WM_WINDOWPOSCHANGED,
1714 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1720 /***********************************************************************
1721 * BeginDeferWindowPos (USER.259)
1723 HDWP16 BeginDeferWindowPos( INT count )
1728 if (count <= 0) return 0;
1729 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS16) );
1730 if (!handle) return 0;
1731 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1732 pDWP->actualCount = 0;
1733 pDWP->suggestedCount = count;
1735 pDWP->wMagic = DWP_MAGIC;
1736 pDWP->hwndParent = 0;
1741 /***********************************************************************
1742 * DeferWindowPos (USER.260)
1744 HDWP16 DeferWindowPos( HDWP16 hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
1745 INT cx, INT cy, UINT flags )
1749 HDWP16 newhdwp = hdwp;
1752 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1753 if (!pDWP) return 0;
1754 if (hwnd == GetDesktopWindow()) return 0;
1756 /* All the windows of a DeferWindowPos() must have the same parent */
1758 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
1759 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1760 else if (parent != pDWP->hwndParent)
1762 USER_HEAP_FREE( hdwp );
1766 for (i = 0; i < pDWP->actualCount; i++)
1768 if (pDWP->winPos[i].hwnd == hwnd)
1770 /* Merge with the other changes */
1771 if (!(flags & SWP_NOZORDER))
1773 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1775 if (!(flags & SWP_NOMOVE))
1777 pDWP->winPos[i].x = x;
1778 pDWP->winPos[i].y = y;
1780 if (!(flags & SWP_NOSIZE))
1782 pDWP->winPos[i].cx = cx;
1783 pDWP->winPos[i].cy = cy;
1785 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
1786 SWP_NOZORDER | SWP_NOREDRAW |
1787 SWP_NOACTIVATE | SWP_NOCOPYBITS |
1789 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1794 if (pDWP->actualCount >= pDWP->suggestedCount)
1796 newhdwp = USER_HEAP_REALLOC( hdwp,
1797 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS16) );
1798 if (!newhdwp) return 0;
1799 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1800 pDWP->suggestedCount++;
1802 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1803 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1804 pDWP->winPos[pDWP->actualCount].x = x;
1805 pDWP->winPos[pDWP->actualCount].y = y;
1806 pDWP->winPos[pDWP->actualCount].cx = cx;
1807 pDWP->winPos[pDWP->actualCount].cy = cy;
1808 pDWP->winPos[pDWP->actualCount].flags = flags;
1809 pDWP->actualCount++;
1814 /***********************************************************************
1815 * EndDeferWindowPos (USER.261)
1817 BOOL EndDeferWindowPos( HDWP16 hdwp )
1820 WINDOWPOS16 *winpos;
1824 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1825 if (!pDWP) return FALSE;
1826 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1828 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1829 winpos->x, winpos->y, winpos->cx, winpos->cy,
1830 winpos->flags ))) break;
1832 USER_HEAP_FREE( hdwp );
1837 /***********************************************************************
1838 * TileChildWindows (USER.199)
1840 void TileChildWindows( HWND parent, WORD action )
1842 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
1845 /***********************************************************************
1846 * CascageChildWindows (USER.198)
1848 void CascadeChildWindows( HWND parent, WORD action )
1850 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);