2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWinpos
);
12 /* GLOBALS *******************************************************************/
14 #define MINMAX_NOSWP (0x00010000)
16 #define SWP_EX_NOCOPY 0x0001
17 #define SWP_EX_PAINTSELF 0x0002
19 #define SWP_AGG_NOGEOMETRYCHANGE \
20 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
21 #define SWP_AGG_NOPOSCHANGE \
22 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
23 #define SWP_AGG_STATUSFLAGS \
24 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
26 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
27 #define PLACE_MIN 0x0001
28 #define PLACE_MAX 0x0002
29 #define PLACE_RECT 0x0004
31 VOID FASTCALL
IntLinkWindow(PWND Wnd
,PWND WndInsertAfter
);
33 /* FUNCTIONS *****************************************************************/
36 IntGetClientOrigin(PWND Window OPTIONAL
, LPPOINT Point
)
38 Window
= Window
? Window
: UserGetDesktopWindow();
41 Point
->x
= Point
->y
= 0;
44 Point
->x
= Window
->rcClient
.left
;
45 Point
->y
= Window
->rcClient
.top
;
52 * Returns client window rectangle relative to the upper-left corner of client area.
54 * \note Does not check the validity of the parameters
57 IntGetClientRect(PWND Wnd
, RECTL
*Rect
)
61 if (Wnd
->style
& WS_MINIMIZED
)
63 Rect
->left
= Rect
->top
= 0;
64 Rect
->right
= UserGetSystemMetrics(SM_CXMINIMIZED
);
65 Rect
->bottom
= UserGetSystemMetrics(SM_CYMINIMIZED
);
68 if ( Wnd
!= UserGetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
70 *Rect
= Wnd
->rcClient
;
71 RECTL_vOffsetRect(Rect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
75 Rect
->left
= Rect
->top
= 0;
76 Rect
->right
= Wnd
->rcClient
.right
;
77 Rect
->bottom
= Wnd
->rcClient
.bottom
;
78 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
79 Rect->right = UserGetSystemMetrics(SM_CXSCREEN);
80 Rect->bottom = UserGetSystemMetrics(SM_CYSCREEN);
86 IntMapWindowPoints(PWND FromWnd
, PWND ToWnd
, LPPOINT lpPoints
, UINT cPoints
)
88 BOOL mirror_from
, mirror_to
;
93 /* Note: Desktop Top and Left is always 0! */
94 Delta
.x
= Delta
.y
= 0;
95 mirror_from
= mirror_to
= FALSE
;
97 if (FromWnd
&& FromWnd
!= UserGetDesktopWindow()) // FromWnd->fnid != FNID_DESKTOP)
99 if (FromWnd
->ExStyle
& WS_EX_LAYOUTRTL
)
103 Delta
.x
= -FromWnd
->rcClient
.right
;
106 Delta
.x
= FromWnd
->rcClient
.left
;
107 Delta
.y
= FromWnd
->rcClient
.top
;
110 if (ToWnd
&& ToWnd
!= UserGetDesktopWindow()) // ToWnd->fnid != FNID_DESKTOP)
112 if (ToWnd
->ExStyle
& WS_EX_LAYOUTRTL
)
116 Delta
.x
+= Change
* ToWnd
->rcClient
.right
;
119 Delta
.x
-= Change
* ToWnd
->rcClient
.left
;
120 Delta
.y
-= ToWnd
->rcClient
.top
;
123 for (i
= 0; i
!= cPoints
; i
++)
125 lpPoints
[i
].x
+= Delta
.x
;
126 lpPoints
[i
].x
*= Change
;
127 lpPoints
[i
].y
+= Delta
.y
;
130 if ((mirror_from
|| mirror_to
) && cPoints
== 2) /* special case for rectangle */
132 int tmp
= min(lpPoints
[0].x
, lpPoints
[1].x
);
133 lpPoints
[1].x
= max(lpPoints
[0].x
, lpPoints
[1].x
);
137 return MAKELONG(LOWORD(Delta
.x
), LOWORD(Delta
.y
));
141 IntClientToScreen(PWND Wnd
, LPPOINT lpPoint
)
143 if (Wnd
&& Wnd
->fnid
!= FNID_DESKTOP
)
145 if (Wnd
->ExStyle
& WS_EX_LAYOUTRTL
)
146 lpPoint
->x
= Wnd
->rcClient
.right
- lpPoint
->x
;
148 lpPoint
->x
+= Wnd
->rcClient
.left
;
149 lpPoint
->y
+= Wnd
->rcClient
.top
;
155 IntScreenToClient(PWND Wnd
, LPPOINT lpPoint
)
157 if (Wnd
&& Wnd
->fnid
!= FNID_DESKTOP
)
159 if (Wnd
->ExStyle
& WS_EX_LAYOUTRTL
)
160 lpPoint
->x
= Wnd
->rcClient
.right
- lpPoint
->x
;
162 lpPoint
->x
-= Wnd
->rcClient
.left
;
163 lpPoint
->y
-= Wnd
->rcClient
.top
;
168 BOOL FASTCALL
IsChildVisible(PWND pWnd
)
172 if ( (pWnd
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
||
173 !(pWnd
= pWnd
->spwndParent
) )
176 while (pWnd
->style
& WS_VISIBLE
);
180 PWND FASTCALL
IntGetLastTopMostWindow(VOID
)
183 PDESKTOP rpdesk
= gptiCurrent
->rpdesk
;
186 (pWnd
= rpdesk
->pDeskInfo
->spwnd
->spwndChild
) &&
187 pWnd
->ExStyle
& WS_EX_TOPMOST
)
191 if (!pWnd
->spwndNext
) break;
192 if (!(pWnd
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)) break;
193 pWnd
= pWnd
->spwndNext
;
201 // This helps with bug 6751 forcing modal dialog active when another app is minimized or closed.
203 BOOL FASTCALL
ActivateOtherWindowMin(PWND Wnd
)
205 BOOL ActivePrev
, FindTopWnd
;
206 PWND pWndTopMost
, pWndChild
, pWndSetActive
, pWndTemp
, pWndDesk
;
207 USER_REFERENCE_ENTRY Ref
;
208 PTHREADINFO pti
= gptiCurrent
;
211 ActivePrev
= (pti
->MessageQueue
->spwndActivePrev
!= NULL
);
214 if ((pWndTopMost
= IntGetLastTopMostWindow()))
215 pWndChild
= pWndTopMost
->spwndNext
;
217 pWndChild
= Wnd
->spwndParent
->spwndChild
;
222 pWndSetActive
= pti
->MessageQueue
->spwndActivePrev
;
224 pWndSetActive
= pWndChild
;
230 if ( VerifyWnd(pWndSetActive
) &&
231 !(pWndSetActive
->ExStyle
& WS_EX_NOACTIVATE
) &&
232 (pWndSetActive
->style
& (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
&&
233 (!(pWndSetActive
->style
& WS_ICONIC
) /* FIXME MinMax pos? */ ) )
235 if (!(pWndSetActive
->ExStyle
& WS_EX_TOOLWINDOW
) )
237 UserRefObjectCo(pWndSetActive
, &Ref
);
238 //ERR("ActivateOtherWindowMin Set FG 1\n");
239 co_IntSetForegroundWindow(pWndSetActive
);
240 UserDerefObjectCo(pWndSetActive
);
241 //ERR("AOWM 2 Exit Good\n");
244 if (!pWndTemp
) pWndTemp
= pWndSetActive
;
249 pWndSetActive
= pWndChild
;
252 pWndSetActive
= pWndSetActive
->spwndNext
;
255 if ( !FindTopWnd
) break;
260 pWndChild
= pWndChild
->spwndParent
->spwndChild
;
264 if (!(pWndDesk
= IntGetThreadDesktopWindow(pti
)))
269 pWndChild
= pWndDesk
->spwndChild
;
272 if ((pWndSetActive
= pWndTemp
))
274 UserRefObjectCo(pWndSetActive
, &Ref
);
275 //ERR("ActivateOtherWindowMin Set FG 2\n");
276 co_IntSetForegroundWindow(pWndSetActive
);
277 UserDerefObjectCo(pWndSetActive
);
278 //ERR("AOWM 3 Exit Good\n");
281 //ERR("AOWM 4 Bad\n");
285 /*******************************************************************
286 * can_activate_window
288 * Check if we can activate the specified window.
291 BOOL FASTCALL
can_activate_window( PWND Wnd OPTIONAL
)
295 if (!Wnd
) return FALSE
;
298 if (!(style
& WS_VISIBLE
)) return FALSE
;
299 if (style
& WS_MINIMIZE
) return FALSE
;
300 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
302 /* FIXME: This window could be disable because the child that closed
304 //return !(style & WS_DISABLED);
308 /*******************************************************************
309 * WinPosActivateOtherWindow
311 * Activates window other than pWnd.
314 co_WinPosActivateOtherWindow(PWND Wnd
)
317 USER_REFERENCE_ENTRY Ref
;
321 if (IntIsDesktopWindow(Wnd
))
323 IntSetFocusMessageQueue(NULL
);
327 /* If this is popup window, try to activate the owner first. */
328 if ((Wnd
->style
& WS_POPUP
) && (WndTo
= Wnd
->spwndOwner
))
330 WndTo
= UserGetAncestor( WndTo
, GA_ROOT
);
331 if (can_activate_window(WndTo
)) goto done
;
334 /* Pick a next top-level window. */
335 /* FIXME: Search for non-tooltip windows first. */
339 if (!(WndTo
= WndTo
->spwndNext
)) break;
340 if (can_activate_window( WndTo
)) break;
345 if (WndTo
) UserRefObjectCo(WndTo
, &Ref
);
347 if (!gpqForeground
|| Wnd
== gpqForeground
->spwndActive
)
349 /* ReactOS can pass WndTo = NULL to co_IntSetForegroundWindow and returns FALSE. */
350 //ERR("WinPosActivateOtherWindow Set FG 0x%p\n",WndTo);
351 if (co_IntSetForegroundWindow(WndTo
))
353 if (WndTo
) UserDerefObjectCo(WndTo
);
357 //ERR("WinPosActivateOtherWindow Set Active 0x%p\n",WndTo);
358 if (!co_IntSetActiveWindow(WndTo
,FALSE
,TRUE
,FALSE
)) /* Ok for WndTo to be NULL here */
360 co_IntSetActiveWindow(NULL
,FALSE
,TRUE
,FALSE
);
362 if (WndTo
) UserDerefObjectCo(WndTo
);
367 co_WinPosArrangeIconicWindows(PWND parent
)
370 INT i
, x
, y
, xspacing
, yspacing
, sx
, sy
;
371 HWND
*List
= IntWinListChildren(parent
);
373 ASSERT_REFS_CO(parent
);
375 /* Check if we found any children */
381 IntGetClientRect( parent
, &rectParent
);
382 // FIXME: Support gspv.mm.iArrange.
384 y
= rectParent
.bottom
;
386 xspacing
= (UserGetSystemMetrics(SM_CXMINSPACING
)/2)+UserGetSystemMetrics(SM_CXBORDER
);
387 yspacing
= (UserGetSystemMetrics(SM_CYMINSPACING
)/2)+UserGetSystemMetrics(SM_CYBORDER
);
389 //ERR("X:%d Y:%d XS:%d YS:%d\n",x,y,xspacing,yspacing);
391 for(i
= 0; List
[i
]; i
++)
395 if (!(Child
= ValidateHwndNoErr(List
[i
])))
398 if((Child
->style
& WS_MINIMIZE
) != 0 )
400 USER_REFERENCE_ENTRY Ref
;
401 UserRefObjectCo(Child
, &Ref
);
403 sx
= x
+ UserGetSystemMetrics(SM_CXBORDER
);
404 sy
= y
- yspacing
- UserGetSystemMetrics(SM_CYBORDER
);
406 co_WinPosSetWindowPos( Child
, 0, sx
, sy
, 0, 0,
407 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
409 Child
->InternalPos
.IconPos
.x
= sx
;
410 Child
->InternalPos
.IconPos
.y
= sy
;
411 Child
->InternalPos
.flags
|= WPF_MININIT
;
412 Child
->InternalPos
.flags
&= ~WPF_SETMINPOSITION
;
414 UserDerefObjectCo(Child
);
416 if (x
<= (rectParent
.right
- UserGetSystemMetrics(SM_CXMINSPACING
)))
423 //ERR("X:%d Y:%d\n",x,y);
426 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
431 WinPosFindIconPos(PWND Window
, POINT
*Pos
)
434 PWND pwndChild
, pwndParent
;
435 int x
, y
, xspacing
, yspacing
;
437 pwndParent
= Window
->spwndParent
;
438 if (pwndParent
== UserGetDesktopWindow())
440 //ERR("Parent is Desktop, Min off screen!\n");
441 /* ReactOS doesn't support iconic minimize to desktop */
442 Pos
->x
= Pos
->y
= -32000;
443 Window
->InternalPos
.flags
|= WPF_MININIT
;
444 Window
->InternalPos
.IconPos
.x
= Pos
->x
;
445 Window
->InternalPos
.IconPos
.y
= Pos
->y
;
449 IntGetClientRect( pwndParent
, &rectParent
);
450 // FIXME: Support gspv.mm.iArrange.
452 y
= rectParent
.bottom
;
454 xspacing
= (UserGetSystemMetrics(SM_CXMINSPACING
)/2)+UserGetSystemMetrics(SM_CXBORDER
);
455 yspacing
= (UserGetSystemMetrics(SM_CYMINSPACING
)/2)+UserGetSystemMetrics(SM_CYBORDER
);
457 //ERR("X:%d Y:%d XS:%d YS:%d\n",Pos->x,Pos->y,xspacing,yspacing);
459 // Set to default position when minimized.
460 Pos
->x
= x
+ UserGetSystemMetrics(SM_CXBORDER
);
461 Pos
->y
= y
- yspacing
- UserGetSystemMetrics(SM_CYBORDER
);
463 for (pwndChild
= pwndParent
->spwndChild
; pwndChild
; pwndChild
= pwndChild
->spwndNext
)
465 if (pwndChild
== Window
) continue;
467 if (pwndChild
->style
& WS_VISIBLE
)
472 //ERR("Pos Child X %d Y %d!\n", pwndChild->InternalPos.IconPos.x, pwndChild->InternalPos.IconPos.y);
473 if ( pwndChild
->InternalPos
.IconPos
.x
== Pos
->x
&&
474 pwndChild
->InternalPos
.IconPos
.y
== Pos
->y
)
476 if (x
<= rectParent
.right
- UserGetSystemMetrics(SM_CXMINSPACING
))
483 Pos
->x
= x
+ UserGetSystemMetrics(SM_CXBORDER
);
484 Pos
->y
= y
- yspacing
- UserGetSystemMetrics(SM_CYBORDER
);
487 Window
->InternalPos
.IconPos
.x
= Pos
->x
;
488 Window
->InternalPos
.IconPos
.y
= Pos
->y
;
489 Window
->InternalPos
.flags
|= WPF_MININIT
;
490 //ERR("Position is set! X:%d Y:%d\n",Pos->x,Pos->y);
495 WinPosInitInternalPos(PWND Wnd
, RECTL
*RestoreRect
)
498 RECTL Rect
= *RestoreRect
;
500 if (Wnd
->spwndParent
!= UserGetDesktopWindow())
502 RECTL_vOffsetRect(&Rect
,
503 -Wnd
->spwndParent
->rcClient
.left
,
504 -Wnd
->spwndParent
->rcClient
.top
);
510 if (!Wnd
->InternalPosInitialized
)
512 // FIXME: Use check point Atom..
513 Wnd
->InternalPos
.flags
= 0;
514 Wnd
->InternalPos
.MaxPos
.x
= Wnd
->InternalPos
.MaxPos
.y
= -1;
515 Wnd
->InternalPos
.IconPos
.x
= Wnd
->InternalPos
.IconPos
.y
= -1;
516 Wnd
->InternalPos
.NormalRect
= Rect
;
517 Wnd
->InternalPosInitialized
= TRUE
;
520 if (Wnd
->style
& WS_MINIMIZE
)
522 Wnd
->InternalPos
.IconPos
= Size
;
523 Wnd
->InternalPos
.flags
|= WPF_MININIT
;
525 else if (Wnd
->style
& WS_MAXIMIZE
)
527 Wnd
->InternalPos
.flags
|= WPF_MAXINIT
;
529 if ( Wnd
->spwndParent
== Wnd
->head
.rpdesk
->pDeskInfo
->spwnd
)
531 if (Wnd
->state
& WNDS_MAXIMIZESTOMONITOR
)
533 Wnd
->InternalPos
.flags
&= ~WPF_MAXINIT
;
534 Wnd
->InternalPos
.MaxPos
.x
= Wnd
->InternalPos
.MaxPos
.y
= -1;
539 PMONITOR pmonitor
= UserMonitorFromRect(&Rect
, MONITOR_DEFAULTTOPRIMARY
);
540 // FIXME: support DPI aware, rcWorkDPI/Real etc..
541 WorkArea
= pmonitor
->rcMonitor
;
543 if (Wnd
->style
& WS_MAXIMIZEBOX
)
544 { // Support (Wnd->state & WNDS_HASCAPTION) || pmonitor->cFullScreen too.
545 if ((Wnd
->style
& WS_CAPTION
) == WS_CAPTION
|| !(Wnd
->style
& (WS_CHILD
| WS_POPUP
)))
547 WorkArea
= pmonitor
->rcWork
;
552 Wnd
->InternalPos
.MaxPos
.x
= Rect
.left
- WorkArea
.left
;
553 Wnd
->InternalPos
.MaxPos
.y
= Rect
.top
- WorkArea
.top
;
555 /*ERR("WinPosIP 2 X %d = R.l %d - W.l %d | Y %d = R.t %d - W.t %d\n",
556 Wnd->InternalPos.MaxPos.x,
557 Rect.left, WorkArea.left,
558 Wnd->InternalPos.MaxPos.y,
559 Rect.top, WorkArea.top);*/
563 Wnd
->InternalPos
.MaxPos
= Size
;
567 Wnd
->InternalPos
.NormalRect
= Rect
;
573 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
575 if (!Wnd
) return FALSE
;
577 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
584 WinPosInitInternalPos(Wnd
, &Wnd
->rcWindow
);
586 lpwndpl
->showCmd
= SW_HIDE
;
588 if ( Wnd
->style
& WS_MINIMIZE
)
589 lpwndpl
->showCmd
= SW_SHOWMINIMIZED
;
591 lpwndpl
->showCmd
= ( Wnd
->style
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
593 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
595 if (Wnd
->InternalPos
.flags
& WPF_MININIT
) // Return if it was set!
597 lpwndpl
->ptMinPosition
.x
= Wnd
->InternalPos
.IconPos
.x
;
598 lpwndpl
->ptMinPosition
.y
= Wnd
->InternalPos
.IconPos
.y
;
601 lpwndpl
->ptMinPosition
.x
= lpwndpl
->ptMinPosition
.y
= -1;
603 if ( Wnd
->InternalPos
.flags
& WPF_MAXINIT
&& // Return if set and not maximized to monitor!
604 !(Wnd
->state
& WNDS_MAXIMIZESTOMONITOR
))
606 lpwndpl
->ptMaxPosition
.x
= Wnd
->InternalPos
.MaxPos
.x
;
607 lpwndpl
->ptMaxPosition
.y
= Wnd
->InternalPos
.MaxPos
.y
;
610 lpwndpl
->ptMaxPosition
.x
= lpwndpl
->ptMaxPosition
.y
= -1;
612 if ( Wnd
->spwndParent
== Wnd
->head
.rpdesk
->pDeskInfo
->spwnd
&&
613 !(Wnd
->ExStyle
& WS_EX_TOOLWINDOW
))
615 PMONITOR pmonitor
= UserMonitorFromRect(&lpwndpl
->rcNormalPosition
, MONITOR_DEFAULTTOPRIMARY
);
617 // FIXME: support DPI aware, rcWorkDPI/Real etc..
618 if (Wnd
->InternalPos
.flags
& WPF_MININIT
)
620 lpwndpl
->ptMinPosition
.x
-= (pmonitor
->rcWork
.left
- pmonitor
->rcMonitor
.left
);
621 lpwndpl
->ptMinPosition
.y
-= (pmonitor
->rcWork
.top
- pmonitor
->rcMonitor
.top
);
623 RECTL_vOffsetRect(&lpwndpl
->rcNormalPosition
,
624 pmonitor
->rcMonitor
.left
- pmonitor
->rcWork
.left
,
625 pmonitor
->rcMonitor
.top
- pmonitor
->rcWork
.top
);
628 if ( Wnd
->InternalPos
.flags
& WPF_RESTORETOMAXIMIZED
|| Wnd
->style
& WS_MAXIMIZE
)
629 lpwndpl
->flags
|= WPF_RESTORETOMAXIMIZED
;
631 if ( ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) && Wnd
->InternalPos
.flags
& WPF_SETMINPOSITION
)
632 lpwndpl
->flags
|= WPF_SETMINPOSITION
;
637 /* make sure the specified rect is visible on screen */
638 static void make_rect_onscreen( RECT
*rect
)
640 PMONITOR pmonitor
= UserMonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
); // Wine uses this.
642 // FIXME: support DPI aware, rcWorkDPI/Real etc..
643 if (!pmonitor
) return;
644 /* FIXME: map coordinates from rcWork to rcMonitor */
645 if (rect
->right
<= pmonitor
->rcWork
.left
)
647 rect
->right
+= pmonitor
->rcWork
.left
- rect
->left
;
648 rect
->left
= pmonitor
->rcWork
.left
;
650 else if (rect
->left
>= pmonitor
->rcWork
.right
)
652 rect
->left
+= pmonitor
->rcWork
.right
- rect
->right
;
653 rect
->right
= pmonitor
->rcWork
.right
;
655 if (rect
->bottom
<= pmonitor
->rcWork
.top
)
657 rect
->bottom
+= pmonitor
->rcWork
.top
- rect
->top
;
658 rect
->top
= pmonitor
->rcWork
.top
;
660 else if (rect
->top
>= pmonitor
->rcWork
.bottom
)
662 rect
->top
+= pmonitor
->rcWork
.bottom
- rect
->bottom
;
663 rect
->bottom
= pmonitor
->rcWork
.bottom
;
667 /* make sure the specified point is visible on screen */
668 static void make_point_onscreen( POINT
*pt
)
672 RECTL_vSetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
673 make_rect_onscreen( &rect
);
679 IntSetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*wpl
, UINT Flags
)
684 if ( Flags
& PLACE_MIN
) make_point_onscreen( &wpl
->ptMinPosition
);
685 if ( Flags
& PLACE_MAX
) make_point_onscreen( &wpl
->ptMaxPosition
);
686 if ( Flags
& PLACE_RECT
) make_rect_onscreen( &wpl
->rcNormalPosition
);
688 if (!Wnd
|| Wnd
== Wnd
->head
.rpdesk
->pDeskInfo
->spwnd
) return FALSE
;
690 if ( Flags
& PLACE_MIN
) Wnd
->InternalPos
.IconPos
= wpl
->ptMinPosition
;
691 if ( Flags
& PLACE_MAX
) Wnd
->InternalPos
.MaxPos
= wpl
->ptMaxPosition
;
692 if ( Flags
& PLACE_RECT
) Wnd
->InternalPos
.NormalRect
= wpl
->rcNormalPosition
;
694 SWP_Flags
= SWP_NOZORDER
| SWP_NOACTIVATE
| ((wpl
->flags
& WPF_ASYNCWINDOWPLACEMENT
) ? SWP_ASYNCWINDOWPOS
: 0);
696 if (Wnd
->style
& WS_MINIMIZE
)
698 if (Flags
& PLACE_MIN
|| Wnd
->InternalPos
.flags
& WPF_SETMINPOSITION
)
700 co_WinPosSetWindowPos(Wnd
, HWND_TOP
,
701 wpl
->ptMinPosition
.x
, wpl
->ptMinPosition
.y
, 0, 0,
702 SWP_NOSIZE
| SWP_Flags
);
703 Wnd
->InternalPos
.flags
|= WPF_MININIT
;
706 else if (Wnd
->style
& WS_MAXIMIZE
)
708 if (Flags
& PLACE_MAX
)
710 co_WinPosSetWindowPos(Wnd
, HWND_TOP
,
711 wpl
->ptMaxPosition
.x
, wpl
->ptMaxPosition
.y
, 0, 0,
712 SWP_NOSIZE
| SWP_Flags
);
713 Wnd
->InternalPos
.flags
|= WPF_MAXINIT
;
716 else if (Flags
& PLACE_RECT
)
718 co_WinPosSetWindowPos(Wnd
, HWND_TOP
,
719 wpl
->rcNormalPosition
.left
, wpl
->rcNormalPosition
.top
,
720 wpl
->rcNormalPosition
.right
- wpl
->rcNormalPosition
.left
,
721 wpl
->rcNormalPosition
.bottom
- wpl
->rcNormalPosition
.top
,
725 sAsync
= (Wnd
->head
.pti
->MessageQueue
!= gptiCurrent
->MessageQueue
&& wpl
->flags
& WPF_ASYNCWINDOWPLACEMENT
);
728 co_IntSendMessageNoWait( UserHMGetHandle(Wnd
), WM_ASYNC_SHOWWINDOW
, wpl
->showCmd
, 0 );
730 co_WinPosShowWindow(Wnd
, wpl
->showCmd
);
732 if ( Wnd
->style
& WS_MINIMIZE
&& !sAsync
)
734 if ( wpl
->flags
& WPF_SETMINPOSITION
)
735 Wnd
->InternalPos
.flags
|= WPF_SETMINPOSITION
;
737 if ( wpl
->flags
& WPF_RESTORETOMAXIMIZED
)
738 Wnd
->InternalPos
.flags
|= WPF_RESTORETOMAXIMIZED
;
744 co_WinPosMinMaximize(PWND Wnd
, UINT ShowFlag
, RECT
* NewPos
)
753 wpl
.length
= sizeof(wpl
);
754 IntGetWindowPlacement( Wnd
, &wpl
);
756 if (co_HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)Wnd
->head
.h
, ShowFlag
))
758 ERR("WinPosMinMaximize WH_CBT Call Hook return!\n");
759 return SWP_NOSIZE
| SWP_NOMOVE
;
761 if (Wnd
->style
& WS_MINIMIZE
)
765 case SW_SHOWMINNOACTIVE
:
766 case SW_SHOWMINIMIZED
:
767 case SW_FORCEMINIMIZE
:
769 return SWP_NOSIZE
| SWP_NOMOVE
;
771 if (!co_IntSendMessageNoWait(Wnd
->head
.h
, WM_QUERYOPEN
, 0, 0))
773 return(SWP_NOSIZE
| SWP_NOMOVE
);
775 SwpFlags
|= SWP_NOCOPYBITS
;
779 case SW_SHOWMINNOACTIVE
:
780 case SW_SHOWMINIMIZED
:
781 case SW_FORCEMINIMIZE
:
784 //ERR("MinMaximize Minimize\n");
785 if (Wnd
->style
& WS_MAXIMIZE
)
787 Wnd
->InternalPos
.flags
|= WPF_RESTORETOMAXIMIZED
;
791 Wnd
->InternalPos
.flags
&= ~WPF_RESTORETOMAXIMIZED
;
794 old_style
= IntSetStyle( Wnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
796 co_UserRedrawWindow(Wnd
, NULL
, 0, RDW_VALIDATE
| RDW_NOERASE
|
797 RDW_NOINTERNALPAINT
);
799 if (!(Wnd
->InternalPos
.flags
& WPF_SETMINPOSITION
))
800 Wnd
->InternalPos
.flags
&= ~WPF_MININIT
;
802 WinPosFindIconPos(Wnd
, &wpl
.ptMinPosition
);
804 if (!(old_style
& WS_MINIMIZE
)) SwpFlags
|= SWP_STATECHANGED
;
806 /*ERR("Minimize: %d,%d %dx%d\n",
807 wpl.ptMinPosition.x, wpl.ptMinPosition.y, UserGetSystemMetrics(SM_CXMINIMIZED),
808 UserGetSystemMetrics(SM_CYMINIMIZED));
810 RECTL_vSetRect(NewPos
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
811 // wpl.ptMinPosition.x + UserGetSystemMetrics(SM_CXMINIMIZED),
812 // wpl.ptMinPosition.y + UserGetSystemMetrics(SM_CYMINIMIZED));
813 UserGetSystemMetrics(SM_CXMINIMIZED
),
814 UserGetSystemMetrics(SM_CYMINIMIZED
));
815 SwpFlags
|= SWP_NOCOPYBITS
;
821 //ERR("MinMaximize Maximize\n");
822 if ((Wnd
->style
& WS_MAXIMIZE
) && (Wnd
->style
& WS_VISIBLE
))
824 SwpFlags
= SWP_NOSIZE
| SWP_NOMOVE
;
827 co_WinPosGetMinMaxInfo(Wnd
, &Size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
829 /*ERR("Maximize: %d,%d %dx%d\n",
830 wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, Size.x, Size.y);
832 old_style
= IntSetStyle( Wnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
834 if (!(old_style
& WS_MAXIMIZE
)) SwpFlags
|= SWP_STATECHANGED
;
835 RECTL_vSetRect(NewPos
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
836 // wpl.ptMaxPosition.x + Size.x, wpl.ptMaxPosition.y + Size.y);
841 case SW_SHOWNOACTIVATE
:
842 Wnd
->InternalPos
.flags
&= ~WPF_RESTORETOMAXIMIZED
;
846 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
848 //ERR("MinMaximize Restore\n");
849 old_style
= IntSetStyle( Wnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
850 if (old_style
& WS_MINIMIZE
)
852 if (Wnd
->InternalPos
.flags
& WPF_RESTORETOMAXIMIZED
)
854 co_WinPosGetMinMaxInfo(Wnd
, &Size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
855 IntSetStyle( Wnd
, WS_MAXIMIZE
, 0 );
856 SwpFlags
|= SWP_STATECHANGED
;
857 /*ERR("Restore to Max: %d,%d %dx%d\n",
858 wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, Size.x, Size.y);
860 RECTL_vSetRect(NewPos
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
861 // wpl.ptMaxPosition.x + Size.x, wpl.ptMaxPosition.y + Size.y);
867 *NewPos
= wpl
.rcNormalPosition
;
868 /*ERR("Restore Max: %d,%d %dx%d\n",
869 NewPos->left, NewPos->top, NewPos->right - NewPos->left, NewPos->bottom - NewPos->top);
871 NewPos
->right
-= NewPos
->left
;
872 NewPos
->bottom
-= NewPos
->top
;
878 if (!(old_style
& WS_MAXIMIZE
))
882 SwpFlags
|= SWP_STATECHANGED
;
883 Wnd
->InternalPos
.flags
&= ~WPF_RESTORETOMAXIMIZED
;
884 *NewPos
= wpl
.rcNormalPosition
;
885 /*ERR("Restore Min: %d,%d %dx%d\n",
886 NewPos->left, NewPos->top, NewPos->right - NewPos->left, NewPos->bottom - NewPos->top);
888 NewPos
->right
-= NewPos
->left
;
889 NewPos
->bottom
-= NewPos
->top
;
898 UserHasWindowEdge(DWORD Style
, DWORD ExStyle
)
900 if (Style
& WS_MINIMIZE
)
902 if (ExStyle
& WS_EX_DLGMODALFRAME
)
904 if (ExStyle
& WS_EX_STATICEDGE
)
906 if (Style
& WS_THICKFRAME
)
909 if (Style
== WS_DLGFRAME
|| Style
== WS_CAPTION
)
915 IntGetWindowBorderMeasures(PWND Wnd
, UINT
*cx
, UINT
*cy
)
917 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
919 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
920 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
924 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
926 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
927 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
929 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
931 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
932 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
942 UserGetWindowBorders(DWORD Style
, DWORD ExStyle
, SIZE
*Size
, BOOL WithClient
)
946 if (UserHasWindowEdge(Style
, ExStyle
))
948 else if (ExStyle
& WS_EX_STATICEDGE
)
950 if ((ExStyle
& WS_EX_CLIENTEDGE
) && WithClient
)
952 if (Style
& WS_CAPTION
|| ExStyle
& WS_EX_DLGMODALFRAME
)
954 Size
->cx
= Size
->cy
= Border
;
955 if ((Style
& WS_THICKFRAME
) && !(Style
& WS_MINIMIZE
))
957 Size
->cx
+= UserGetSystemMetrics(SM_CXFRAME
) - UserGetSystemMetrics(SM_CXDLGFRAME
);
958 Size
->cy
+= UserGetSystemMetrics(SM_CYFRAME
) - UserGetSystemMetrics(SM_CYDLGFRAME
);
960 Size
->cx
*= UserGetSystemMetrics(SM_CXBORDER
);
961 Size
->cy
*= UserGetSystemMetrics(SM_CYBORDER
);
965 UserAdjustWindowRectEx(LPRECT lpRect
,
974 lpRect
->top
-= UserGetSystemMetrics(SM_CYMENU
);
976 if ((dwStyle
& WS_CAPTION
) == WS_CAPTION
)
978 if (dwExStyle
& WS_EX_TOOLWINDOW
)
979 lpRect
->top
-= UserGetSystemMetrics(SM_CYSMCAPTION
);
981 lpRect
->top
-= UserGetSystemMetrics(SM_CYCAPTION
);
983 UserGetWindowBorders(dwStyle
, dwExStyle
, &BorderSize
, TRUE
);
993 co_WinPosGetMinMaxInfo(PWND Window
, POINT
* MaxSize
, POINT
* MaxPos
,
994 POINT
* MinTrack
, POINT
* MaxTrack
)
999 LONG style
= Window
->style
;
1001 LONG exstyle
= Window
->ExStyle
;
1004 ASSERT_REFS_CO(Window
);
1006 /* Compute default values */
1008 rc
= Window
->rcWindow
;
1009 MinMax
.ptReserved
.x
= rc
.left
;
1010 MinMax
.ptReserved
.y
= rc
.top
;
1012 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1013 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1015 adjustedStyle
= style
;
1017 if(Window
->spwndParent
)
1018 IntGetClientRect(Window
->spwndParent
, &rc
);
1019 UserAdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && Window
->IDMenu
), exstyle
);
1024 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
1025 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
1026 if (style
& (WS_DLGFRAME
| WS_BORDER
))
1028 MinMax
.ptMinTrackSize
.x
= UserGetSystemMetrics(SM_CXMINTRACK
);
1029 MinMax
.ptMinTrackSize
.y
= UserGetSystemMetrics(SM_CYMINTRACK
);
1033 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
1034 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
1036 MinMax
.ptMaxTrackSize
.x
= UserGetSystemMetrics(SM_CXMAXTRACK
);
1037 MinMax
.ptMaxTrackSize
.y
= UserGetSystemMetrics(SM_CYMAXTRACK
);
1038 MinMax
.ptMaxPosition
.x
= -xinc
;
1039 MinMax
.ptMaxPosition
.y
= -yinc
;
1041 if (!EMPTYPOINT(Window
->InternalPos
.MaxPos
)) MinMax
.ptMaxPosition
= Window
->InternalPos
.MaxPos
;
1043 co_IntSendMessage(Window
->head
.h
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
1045 /* if the app didn't change the values, adapt them for the current monitor */
1046 if ((monitor
= UserGetPrimaryMonitor()))
1050 rc_work
= monitor
->rcMonitor
;
1052 if (style
& WS_MAXIMIZEBOX
)
1054 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
1055 rc_work
= monitor
->rcWork
;
1058 if (MinMax
.ptMaxSize
.x
== UserGetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
1059 MinMax
.ptMaxSize
.y
== UserGetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
1061 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
1062 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
1064 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
1066 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
1067 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
1069 if (MinMax
.ptMaxSize
.x
>= (monitor
->rcMonitor
.right
- monitor
->rcMonitor
.left
) &&
1070 MinMax
.ptMaxSize
.y
>= (monitor
->rcMonitor
.bottom
- monitor
->rcMonitor
.top
) )
1071 Window
->state
|= WNDS_MAXIMIZESTOMONITOR
;
1073 Window
->state
&= ~WNDS_MAXIMIZESTOMONITOR
;
1077 MinMax
.ptMaxTrackSize
.x
= max(MinMax
.ptMaxTrackSize
.x
,
1078 MinMax
.ptMinTrackSize
.x
);
1079 MinMax
.ptMaxTrackSize
.y
= max(MinMax
.ptMaxTrackSize
.y
,
1080 MinMax
.ptMinTrackSize
.y
);
1083 *MaxSize
= MinMax
.ptMaxSize
;
1085 *MaxPos
= MinMax
.ptMaxPosition
;
1087 *MinTrack
= MinMax
.ptMinTrackSize
;
1089 *MaxTrack
= MinMax
.ptMaxTrackSize
;
1091 return 0; // FIXME: What does it return?
1096 FixClientRect(PRECTL ClientRect
, PRECTL WindowRect
)
1098 if (ClientRect
->left
< WindowRect
->left
)
1100 ClientRect
->left
= WindowRect
->left
;
1102 else if (WindowRect
->right
< ClientRect
->left
)
1104 ClientRect
->left
= WindowRect
->right
;
1106 if (ClientRect
->right
< WindowRect
->left
)
1108 ClientRect
->right
= WindowRect
->left
;
1110 else if (WindowRect
->right
< ClientRect
->right
)
1112 ClientRect
->right
= WindowRect
->right
;
1114 if (ClientRect
->top
< WindowRect
->top
)
1116 ClientRect
->top
= WindowRect
->top
;
1118 else if (WindowRect
->bottom
< ClientRect
->top
)
1120 ClientRect
->top
= WindowRect
->bottom
;
1122 if (ClientRect
->bottom
< WindowRect
->top
)
1124 ClientRect
->bottom
= WindowRect
->top
;
1126 else if (WindowRect
->bottom
< ClientRect
->bottom
)
1128 ClientRect
->bottom
= WindowRect
->bottom
;
1131 /***********************************************************************
1134 * Compute the valid rects from the old and new client rect and WVR_* flags.
1135 * Helper for WM_NCCALCSIZE handling.
1139 get_valid_rects( RECTL
*old_client
, RECTL
*new_client
, UINT flags
, RECTL
*valid
)
1143 if (flags
& WVR_REDRAW
)
1145 RECTL_vSetEmptyRect( &valid
[0] );
1146 RECTL_vSetEmptyRect( &valid
[1] );
1150 if (flags
& WVR_VALIDRECTS
)
1152 if (!RECTL_bIntersectRect( &valid
[0], &valid
[0], new_client
) ||
1153 !RECTL_bIntersectRect( &valid
[1], &valid
[1], old_client
))
1155 RECTL_vSetEmptyRect( &valid
[0] );
1156 RECTL_vSetEmptyRect( &valid
[1] );
1159 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1163 valid
[0] = *new_client
;
1164 valid
[1] = *old_client
;
1167 /* make sure the rectangles have the same size */
1168 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1169 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1171 if (flags
& WVR_ALIGNBOTTOM
)
1173 valid
[0].top
= valid
[0].bottom
- cy
;
1174 valid
[1].top
= valid
[1].bottom
- cy
;
1178 valid
[0].bottom
= valid
[0].top
+ cy
;
1179 valid
[1].bottom
= valid
[1].top
+ cy
;
1181 if (flags
& WVR_ALIGNRIGHT
)
1183 valid
[0].left
= valid
[0].right
- cx
;
1184 valid
[1].left
= valid
[1].right
- cx
;
1188 valid
[0].right
= valid
[0].left
+ cx
;
1189 valid
[1].right
= valid
[1].left
+ cx
;
1195 co_WinPosDoNCCALCSize(PWND Window
, PWINDOWPOS WinPos
, RECTL
* WindowRect
, RECTL
* ClientRect
, RECTL
* validRects
)
1200 ASSERT_REFS_CO(Window
);
1202 /* Send WM_NCCALCSIZE message to get new client area */
1203 if ((WinPos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1205 NCCALCSIZE_PARAMS params
;
1206 WINDOWPOS winposCopy
;
1208 params
.rgrc
[0] = *WindowRect
; // new coordinates of a window that has been moved or resized
1209 params
.rgrc
[1] = Window
->rcWindow
; // window before it was moved or resized
1210 params
.rgrc
[2] = Window
->rcClient
; // client area before the window was moved or resized
1212 Parent
= Window
->spwndParent
;
1213 if (0 != (Window
->style
& WS_CHILD
) && Parent
)
1215 RECTL_vOffsetRect(&(params
.rgrc
[0]), - Parent
->rcClient
.left
,
1216 - Parent
->rcClient
.top
);
1217 RECTL_vOffsetRect(&(params
.rgrc
[1]), - Parent
->rcClient
.left
,
1218 - Parent
->rcClient
.top
);
1219 RECTL_vOffsetRect(&(params
.rgrc
[2]), - Parent
->rcClient
.left
,
1220 - Parent
->rcClient
.top
);
1223 params
.lppos
= &winposCopy
;
1224 winposCopy
= *WinPos
;
1226 wvrFlags
= co_IntSendMessage(Window
->head
.h
, WM_NCCALCSIZE
, TRUE
, (LPARAM
) ¶ms
);
1228 /* If the application send back garbage, ignore it */
1229 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
1230 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
1232 *ClientRect
= params
.rgrc
[0]; // First rectangle contains the coordinates of the new client rectangle resulting from the move or resize
1233 if ((Window
->style
& WS_CHILD
) && Parent
)
1235 RECTL_vOffsetRect(ClientRect
, Parent
->rcClient
.left
,
1236 Parent
->rcClient
.top
);
1238 FixClientRect(ClientRect
, WindowRect
);
1241 if (ClientRect
->left
!= Window
->rcClient
.left
||
1242 ClientRect
->top
!= Window
->rcClient
.top
)
1244 WinPos
->flags
&= ~SWP_NOCLIENTMOVE
;
1247 if (ClientRect
->right
- ClientRect
->left
!=
1248 Window
->rcClient
.right
- Window
->rcClient
.left
)
1250 WinPos
->flags
&= ~SWP_NOCLIENTSIZE
;
1253 wvrFlags
&= ~WVR_HREDRAW
;
1255 if (ClientRect
->bottom
- ClientRect
->top
!=
1256 Window
->rcClient
.bottom
- Window
->rcClient
.top
)
1258 WinPos
->flags
&= ~SWP_NOCLIENTSIZE
;
1261 wvrFlags
&= ~WVR_VREDRAW
;
1263 validRects
[0] = params
.rgrc
[1]; // second rectangle contains the valid destination rectangle
1264 validRects
[1] = params
.rgrc
[2]; // third rectangle contains the valid source rectangle
1268 if (!(WinPos
->flags
& SWP_NOMOVE
) &&
1269 (ClientRect
->left
!= Window
->rcClient
.left
||
1270 ClientRect
->top
!= Window
->rcClient
.top
))
1272 WinPos
->flags
&= ~SWP_NOCLIENTMOVE
;
1276 if (WinPos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1278 RECTL_vSetEmptyRect( &validRects
[0] );
1279 RECTL_vSetEmptyRect( &validRects
[1] );
1281 else get_valid_rects( &Window
->rcClient
, ClientRect
, wvrFlags
, validRects
);
1288 co_WinPosDoWinPosChanging(PWND Window
,
1293 ASSERT_REFS_CO(Window
);
1295 /* Send WM_WINDOWPOSCHANGING message */
1297 if (!(WinPos
->flags
& SWP_NOSENDCHANGING
))
1299 co_IntSendMessageNoWait(Window
->head
.h
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
) WinPos
);
1302 /* Calculate new position and size */
1304 *WindowRect
= Window
->rcWindow
;
1305 *ClientRect
= (Window
->style
& WS_MINIMIZE
) ? Window
->rcWindow
: Window
->rcClient
;
1307 if (!(WinPos
->flags
& SWP_NOSIZE
))
1309 if (Window
->style
& WS_MINIMIZE
)
1311 WindowRect
->right
= WindowRect
->left
+ UserGetSystemMetrics(SM_CXICON
);
1312 WindowRect
->bottom
= WindowRect
->top
+ UserGetSystemMetrics(SM_CYICON
);
1316 WindowRect
->right
= WindowRect
->left
+ WinPos
->cx
;
1317 WindowRect
->bottom
= WindowRect
->top
+ WinPos
->cy
;
1321 if (!(WinPos
->flags
& SWP_NOMOVE
))
1323 WindowRect
->left
= WinPos
->x
;
1324 WindowRect
->top
= WinPos
->y
;
1325 WindowRect
->right
+= WinPos
->x
- Window
->rcWindow
.left
;
1326 WindowRect
->bottom
+= WinPos
->y
- Window
->rcWindow
.top
;
1327 RECTL_vOffsetRect(ClientRect
,
1328 WinPos
->x
- Window
->rcWindow
.left
,
1329 WinPos
->y
- Window
->rcWindow
.top
);
1333 *WindowRect
= Window
->rcWindow
;
1334 *ClientRect
= Window
->rcClient
;
1336 if (!(WinPos
->flags
& SWP_NOSIZE
))
1338 WindowRect
->right
= WindowRect
->left
+ WinPos
->cx
;
1339 WindowRect
->bottom
= WindowRect
->top
+ WinPos
->cy
;
1342 if (!(WinPos
->flags
& SWP_NOMOVE
))
1348 //ERR("Not SWP_NOMOVE\n");
1349 Parent
= Window
->spwndParent
;
1350 if (((Window
->style
& WS_CHILD
) != 0) &&
1352 Parent
!= Window
->head
.rpdesk
->pDeskInfo
->spwnd
)
1354 //ERR("Not SWP_NOMOVE 1 Parent client offset X %d Y %d\n",X,Y);
1355 X
+= Parent
->rcClient
.left
;
1356 Y
+= Parent
->rcClient
.top
;
1357 //ERR("Not SWP_NOMOVE 2 Parent client offset X %d Y %d\n",X,Y);
1360 WindowRect
->left
= X
;
1361 WindowRect
->top
= Y
;
1362 WindowRect
->right
+= X
- Window
->rcWindow
.left
;
1363 WindowRect
->bottom
+= Y
- Window
->rcWindow
.top
;
1365 RECTL_vOffsetRect(ClientRect
, X
- Window
->rcWindow
.left
,
1366 Y
- Window
->rcWindow
.top
);
1369 WinPos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1371 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1372 WinPos
->hwnd
, WinPos
->hwndInsertAfter
, WinPos
->x
, WinPos
->y
,
1373 WinPos
->cx
, WinPos
->cy
, WinPos
->flags
);
1379 * Fix Z order taking into account owned popups -
1380 * basically we need to maintain them above the window that owns them
1382 * FIXME: hide/show owned popups when owner visibility changes.
1384 * ReactOS: See bug CORE-6129 and CORE-6554.
1388 // Pass all the win:test_children/popup_zorder tests except "move hwnd_F and its popups down" which is if'ed out.
1389 // Side effect, breaks more of the DeferWindowPos api tests, but wine breaks more!!!!
1392 WinPosDoOwnedPopups(PWND Window
, HWND hWndInsertAfter
)
1397 PWND DesktopWindow
, ChildObject
;
1400 TRACE("(%p) hInsertAfter = %p\n", Window
, hWndInsertAfter
);
1402 Owner
= Window
->spwndOwner
? Window
->spwndOwner
->head
.h
: NULL
;
1403 Style
= Window
->style
;
1405 if (Style
& WS_CHILD
)
1407 TRACE("Window is child\n");
1408 return hWndInsertAfter
;
1413 /* Make sure this popup stays above the owner */
1415 if (hWndInsertAfter
!= HWND_TOPMOST
)
1417 DesktopWindow
= UserGetDesktopWindow();
1418 List
= IntWinListChildren(DesktopWindow
);
1422 for (i
= 0; List
[i
]; i
++)
1424 BOOL topmost
= FALSE
;
1426 ChildObject
= ValidateHwndNoErr(List
[i
]);
1429 topmost
= (ChildObject
->ExStyle
& WS_EX_TOPMOST
) != 0;
1432 if (List
[i
] == Owner
)
1434 if (i
> 0) hWndInsertAfter
= List
[i
-1];
1435 else hWndInsertAfter
= topmost
? HWND_TOPMOST
: HWND_TOP
;
1439 if (hWndInsertAfter
== HWND_TOP
|| hWndInsertAfter
== HWND_NOTOPMOST
)
1441 if (!topmost
) break;
1443 else if (List
[i
] == hWndInsertAfter
) break;
1447 return hWndInsertAfter
;
1451 if (hWndInsertAfter
== HWND_BOTTOM
)
1453 ERR("Window is HWND_BOTTOM\n");
1454 if (List
) ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1460 DesktopWindow
= UserGetDesktopWindow();
1461 List
= IntWinListChildren(DesktopWindow
);
1468 if (hWndInsertAfter
== HWND_TOP
|| hWndInsertAfter
== HWND_NOTOPMOST
)
1470 if (hWndInsertAfter
== HWND_NOTOPMOST
|| !(Window
->ExStyle
& WS_EX_TOPMOST
))
1472 TRACE("skip all the topmost windows\n");
1473 /* skip all the topmost windows */
1475 (ChildObject
= ValidateHwndNoErr(List
[i
])) &&
1476 (ChildObject
->ExStyle
& WS_EX_TOPMOST
)) i
++;
1479 else if (hWndInsertAfter
!= HWND_TOPMOST
)
1481 /* skip windows that are already placed correctly */
1482 for (i
= 0; List
[i
]; i
++)
1484 if (List
[i
] == hWndInsertAfter
) break;
1485 if (List
[i
] == UserHMGetHandle(Window
))
1487 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1488 goto done
; /* nothing to do if window is moving backwards in z-order */
1493 for (; List
[i
]; i
++)
1496 USER_REFERENCE_ENTRY Ref
;
1498 if (List
[i
] == UserHMGetHandle(Window
))
1501 if (!(Wnd
= ValidateHwndNoErr(List
[i
])))
1504 Owner
= Wnd
->spwndOwner
? Wnd
->spwndOwner
->head
.h
: NULL
;
1506 if (Owner
!= UserHMGetHandle(Window
)) continue;
1508 UserRefObjectCo(Wnd
, &Ref
);
1509 TRACE( "moving %p owned by %p after %p\n", List
[i
], UserHMGetHandle(Window
), hWndInsertAfter
);
1510 co_WinPosSetWindowPos(Wnd
, hWndInsertAfter
, 0, 0, 0, 0,
1511 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1513 UserDerefObjectCo(Wnd
);
1514 hWndInsertAfter
= List
[i
];
1516 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1519 return hWndInsertAfter
;
1523 /***********************************************************************
1524 * WinPosInternalMoveWindow
1526 * Update WindowRect and ClientRect of Window and all of its children
1527 * We keep both WindowRect and ClientRect in screen coordinates internally
1531 WinPosInternalMoveWindow(PWND Window
, INT MoveX
, INT MoveY
)
1535 ASSERT(Window
!= Window
->spwndChild
);
1537 Window
->rcWindow
.left
+= MoveX
;
1538 Window
->rcWindow
.right
+= MoveX
;
1539 Window
->rcWindow
.top
+= MoveY
;
1540 Window
->rcWindow
.bottom
+= MoveY
;
1542 Window
->rcClient
.left
+= MoveX
;
1543 Window
->rcClient
.right
+= MoveX
;
1544 Window
->rcClient
.top
+= MoveY
;
1545 Window
->rcClient
.bottom
+= MoveY
;
1547 for(Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1549 WinPosInternalMoveWindow(Child
, MoveX
, MoveY
);
1554 * WinPosFixupSWPFlags
1556 * Fix redundant flags and values in the WINDOWPOS structure.
1560 WinPosFixupFlags(WINDOWPOS
*WinPos
, PWND Wnd
)
1565 /* Finally make sure that all coordinates are valid */
1566 if (WinPos
->x
< -32768) WinPos
->x
= -32768;
1567 else if (WinPos
->x
> 32767) WinPos
->x
= 32767;
1568 if (WinPos
->y
< -32768) WinPos
->y
= -32768;
1569 else if (WinPos
->y
> 32767) WinPos
->y
= 32767;
1571 WinPos
->cx
= max(WinPos
->cx
, 0);
1572 WinPos
->cy
= max(WinPos
->cy
, 0);
1574 Parent
= UserGetAncestor( Wnd
, GA_PARENT
);
1575 if (!IntIsWindowVisible( Parent
)) WinPos
->flags
|= SWP_NOREDRAW
;
1577 if (Wnd
->style
& WS_VISIBLE
) WinPos
->flags
&= ~SWP_SHOWWINDOW
;
1580 WinPos
->flags
&= ~SWP_HIDEWINDOW
;
1581 if (!(WinPos
->flags
& SWP_SHOWWINDOW
)) WinPos
->flags
|= SWP_NOREDRAW
;
1584 /* Check for right size */
1585 if (Wnd
->rcWindow
.right
- Wnd
->rcWindow
.left
== WinPos
->cx
&&
1586 Wnd
->rcWindow
.bottom
- Wnd
->rcWindow
.top
== WinPos
->cy
)
1588 WinPos
->flags
|= SWP_NOSIZE
;
1593 IntClientToScreen( Parent
, &pt
);
1594 //ERR("WPFU C2S wpx %d wpy %d ptx %d pty %d\n",WinPos->x,WinPos->y,pt.x,pt.y);
1595 /* Check for right position */
1596 if (Wnd
->rcWindow
.left
== pt
.x
&& Wnd
->rcWindow
.top
== pt
.y
)
1598 //ERR("In right pos\n");
1599 WinPos
->flags
|= SWP_NOMOVE
;
1602 if (WinPos
->hwnd
== UserGetForegroundWindow())
1604 WinPos
->flags
|= SWP_NOACTIVATE
; /* Already active */
1607 if ((Wnd
->style
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1609 /* Bring to the top when activating */
1610 if (!(WinPos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) &&
1611 (WinPos
->flags
& SWP_NOZORDER
||
1612 (WinPos
->hwndInsertAfter
!= HWND_TOPMOST
&& WinPos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1614 WinPos
->flags
&= ~SWP_NOZORDER
;
1615 WinPos
->hwndInsertAfter
= (0 != (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOPMOST
: HWND_TOP
);
1619 /* Check hwndInsertAfter */
1620 if (!(WinPos
->flags
& SWP_NOZORDER
))
1622 /* Fix sign extension */
1623 if (WinPos
->hwndInsertAfter
== (HWND
)0xffff)
1625 WinPos
->hwndInsertAfter
= HWND_TOPMOST
;
1627 else if (WinPos
->hwndInsertAfter
== (HWND
)0xfffe)
1629 WinPos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1632 if (WinPos
->hwndInsertAfter
== HWND_TOP
)
1634 /* Keep it topmost when it's already topmost */
1635 if ((Wnd
->ExStyle
& WS_EX_TOPMOST
) != 0)
1636 WinPos
->hwndInsertAfter
= HWND_TOPMOST
;
1638 if (IntGetWindow(WinPos
->hwnd
, GW_HWNDFIRST
) == WinPos
->hwnd
)
1639 WinPos
->flags
|= SWP_NOZORDER
;
1641 else if (WinPos
->hwndInsertAfter
== HWND_BOTTOM
)
1643 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) && IntGetWindow(WinPos
->hwnd
, GW_HWNDLAST
) == WinPos
->hwnd
)
1644 WinPos
->flags
|= SWP_NOZORDER
;
1646 else if (WinPos
->hwndInsertAfter
== HWND_TOPMOST
)
1648 if ((Wnd
->ExStyle
& WS_EX_TOPMOST
) && IntGetWindow(WinPos
->hwnd
, GW_HWNDFIRST
) == WinPos
->hwnd
)
1649 WinPos
->flags
|= SWP_NOZORDER
;
1651 else if (WinPos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1653 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
))
1654 WinPos
->flags
|= SWP_NOZORDER
;
1656 else /* hwndInsertAfter must be a sibling of the window */
1660 InsAfterWnd
= ValidateHwndNoErr(WinPos
->hwndInsertAfter
);
1666 if (InsAfterWnd
->spwndParent
!= Wnd
->spwndParent
)
1668 /* Note from wine User32 Win test_SetWindowPos:
1669 "Returns TRUE also for windows that are not siblings"
1670 "Does not seem to do anything even without passing flags, still returns TRUE"
1671 "Same thing the other way around."
1672 ".. and with these windows."
1679 * We don't need to change the Z order of hwnd if it's already
1680 * inserted after hwndInsertAfter or when inserting hwnd after
1683 if ((WinPos
->hwnd
== WinPos
->hwndInsertAfter
) ||
1684 ((InsAfterWnd
->spwndNext
) && (WinPos
->hwnd
== InsAfterWnd
->spwndNext
->head
.h
)))
1686 WinPos
->flags
|= SWP_NOZORDER
;
1695 /* x and y are always screen relative */
1697 co_WinPosSetWindowPos(
1699 HWND WndInsertAfter
,
1708 RECTL NewWindowRect
;
1709 RECTL NewClientRect
;
1710 RECTL valid_rects
[2];
1712 HRGN VisBefore
= NULL
;
1713 HRGN VisAfter
= NULL
;
1714 HRGN DirtyRgn
= NULL
;
1715 HRGN ExposedRgn
= NULL
;
1716 HRGN CopyRgn
= NULL
;
1718 RECTL OldWindowRect
, OldClientRect
;
1723 BOOL bPointerInWindow
;
1725 ASSERT_REFS_CO(Window
);
1727 /* FIXME: Get current active window from active queue. Why? since r2915. */
1729 bPointerInWindow
= IntPtInWindow(Window
, gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
1731 WinPos
.hwnd
= Window
->head
.h
;
1732 WinPos
.hwndInsertAfter
= WndInsertAfter
;
1737 WinPos
.flags
= flags
;
1739 if ( flags
& SWP_ASYNCWINDOWPOS
)
1742 PWINDOWPOS ppos
= ExAllocatePoolWithTag(PagedPool
, sizeof(WINDOWPOS
), USERTAG_SWP
);
1745 WinPos
.flags
&= ~SWP_ASYNCWINDOWPOS
; // Clear flag.
1747 /* Yes it's a pointer inside Win32k! */
1748 lRes
= co_IntSendMessageNoWait( WinPos
.hwnd
, WM_ASYNC_SETWINDOWPOS
, 0, (LPARAM
)ppos
);
1749 /* We handle this the same way as Event Hooks and Hooks. */
1752 ExFreePoolWithTag(ppos
, USERTAG_SWP
);
1760 co_WinPosDoWinPosChanging(Window
, &WinPos
, &NewWindowRect
, &NewClientRect
);
1762 /* Does the window still exist? */
1763 if (!IntIsWindow(WinPos
.hwnd
))
1765 TRACE("WinPosSetWindowPos: Invalid handle 0x%p!\n",WinPos
.hwnd
);
1766 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1770 /* Fix up the flags. */
1771 if (!WinPosFixupFlags(&WinPos
, Window
))
1777 Ancestor
= UserGetAncestor(Window
, GA_PARENT
);
1778 if ( (WinPos
.flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
&&
1779 Ancestor
&& Ancestor
->head
.h
== IntGetDesktopWindow() )
1781 WinPos
.hwndInsertAfter
= WinPosDoOwnedPopups(Window
, WinPos
.hwndInsertAfter
);
1784 if (!(WinPos
.flags
& SWP_NOREDRAW
))
1786 /* Compute the visible region before the window position is changed */
1787 if (!(WinPos
.flags
& SWP_SHOWWINDOW
) &&
1788 (WinPos
.flags
& (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1789 SWP_HIDEWINDOW
| SWP_FRAMECHANGED
)) !=
1790 (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
))
1792 VisBefore
= VIS_ComputeVisibleRegion(Window
, FALSE
, FALSE
,
1793 (Window
->style
& WS_CLIPSIBLINGS
) ? TRUE
: FALSE
);
1796 if ( VisBefore
!= NULL
&&
1797 (VisRgn
= (PROSRGNDATA
)RGNOBJAPI_Lock(VisBefore
, NULL
)) &&
1798 REGION_Complexity(VisRgn
) == NULLREGION
)
1800 RGNOBJAPI_Unlock(VisRgn
);
1801 GreDeleteObject(VisBefore
);
1806 RGNOBJAPI_Unlock(VisRgn
);
1807 NtGdiOffsetRgn(VisBefore
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
1812 WvrFlags
= co_WinPosDoNCCALCSize(Window
, &WinPos
, &NewWindowRect
, &NewClientRect
, valid_rects
);
1814 // ERR("co_WinPosDoNCCALCSize returned 0x%x\n valid dest: %d %d %d %d\n valid src : %d %d %d %d\n", WvrFlags,
1815 // valid_rects[0].left,valid_rects[0].top,valid_rects[0].right,valid_rects[0].bottom,
1816 // valid_rects[1].left,valid_rects[1].top,valid_rects[1].right,valid_rects[1].bottom);
1818 /* Validate link windows. (also take into account shell window in hwndShellWindow) */
1819 if (!(WinPos
.flags
& SWP_NOZORDER
) && WinPos
.hwnd
!= UserGetShellWindow())
1821 IntLinkHwnd(Window
, WinPos
.hwndInsertAfter
);
1824 OldWindowRect
= Window
->rcWindow
;
1825 OldClientRect
= Window
->rcClient
;
1826 //ERR("SetWindowPos OldWindowRect: %d %d %d %d\n", OldWindowRect.left,OldWindowRect.top,OldWindowRect.right,OldWindowRect.bottom);
1827 //ERR("SetWindowPos OldClientRect: %d %d %d %d\n", OldClientRect.left,OldClientRect.top,OldClientRect.right,OldClientRect.bottom);
1829 if (NewClientRect
.left
!= OldClientRect
.left
||
1830 NewClientRect
.top
!= OldClientRect
.top
)
1832 WinPosInternalMoveWindow(Window
,
1833 NewClientRect
.left
- OldClientRect
.left
,
1834 NewClientRect
.top
- OldClientRect
.top
);
1837 Window
->rcWindow
= NewWindowRect
;
1838 Window
->rcClient
= NewClientRect
;
1840 //ERR("SetWindowPos NewWindowRect: %d %d %d %d\n", NewWindowRect.left,NewWindowRect.top,NewWindowRect.right,NewWindowRect.bottom);
1841 //ERR("SetWindowPos NewClientRect: %d %d %d %d\n", NewClientRect.left,NewClientRect.top,NewClientRect.right,NewClientRect.bottom);
1843 /* erase parent when hiding or resizing child */
1844 if (WinPos
.flags
& SWP_HIDEWINDOW
)
1846 /* Clear the update region */
1847 co_UserRedrawWindow( Window
,
1850 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
| RDW_NOINTERNALPAINT
| RDW_ALLCHILDREN
);
1852 if (Window
->spwndParent
== UserGetDesktopWindow())
1853 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
)Window
->head
.h
, 0);
1855 Window
->style
&= ~WS_VISIBLE
; //IntSetStyle( Window, 0, WS_VISIBLE );
1856 Window
->head
.pti
->cVisWindows
--;
1857 IntNotifyWinEvent(EVENT_OBJECT_HIDE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1859 else if (WinPos
.flags
& SWP_SHOWWINDOW
)
1861 if (Window
->spwndParent
== UserGetDesktopWindow())
1862 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)Window
->head
.h
, 0);
1864 Window
->style
|= WS_VISIBLE
; //IntSetStyle( Window, WS_VISIBLE, 0 );
1865 Window
->head
.pti
->cVisWindows
++;
1866 IntNotifyWinEvent(EVENT_OBJECT_SHOW
, Window
, OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1869 if (Window
->hrgnUpdate
!= NULL
&& Window
->hrgnUpdate
!= HRGN_WINDOW
)
1871 NtGdiOffsetRgn(Window
->hrgnUpdate
,
1872 NewWindowRect
.left
- OldWindowRect
.left
,
1873 NewWindowRect
.top
- OldWindowRect
.top
);
1876 DceResetActiveDCEs(Window
); // For WS_VISIBLE changes.
1878 if (!(WinPos
.flags
& SWP_NOREDRAW
))
1880 /* Determine the new visible region */
1881 VisAfter
= VIS_ComputeVisibleRegion(Window
, FALSE
, FALSE
,
1882 (Window
->style
& WS_CLIPSIBLINGS
) ? TRUE
: FALSE
);
1885 if ( VisAfter
!= NULL
&&
1886 (VisRgn
= (PROSRGNDATA
)RGNOBJAPI_Lock(VisAfter
, NULL
)) &&
1887 REGION_Complexity(VisRgn
) == NULLREGION
)
1889 RGNOBJAPI_Unlock(VisRgn
);
1890 GreDeleteObject(VisAfter
);
1895 RGNOBJAPI_Unlock(VisRgn
);
1896 NtGdiOffsetRgn(VisAfter
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
1900 * Determine which pixels can be copied from the old window position
1901 * to the new. Those pixels must be visible in both the old and new
1902 * position. Also, check the class style to see if the windows of this
1903 * class need to be completely repainted on (horizontal/vertical) size
1906 if ( VisBefore
!= NULL
&&
1908 !(WinPos
.flags
& SWP_NOCOPYBITS
) &&
1909 ((WinPos
.flags
& SWP_NOSIZE
) || !(WvrFlags
& WVR_REDRAW
)) &&
1910 !(Window
->ExStyle
& WS_EX_TRANSPARENT
) )
1912 CopyRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
1913 RgnType
= NtGdiCombineRgn(CopyRgn
, VisAfter
, VisBefore
, RGN_AND
);
1916 * If this is (also) a window resize, the whole nonclient area
1917 * needs to be repainted. So we limit the copy to the client area,
1918 * 'cause there is no use in copying it (would possibly cause
1919 * "flashing" too). However, if the copy region is already empty,
1920 * we don't have to crop (can't take anything away from an empty
1923 if (!(WinPos
.flags
& SWP_NOSIZE
) &&
1925 RgnType
!= NULLREGION
)
1927 PROSRGNDATA pCopyRgn
;
1928 RECTL ORect
= OldClientRect
;
1929 RECTL NRect
= NewClientRect
;
1930 RECTL_vOffsetRect(&ORect
, - OldWindowRect
.left
, - OldWindowRect
.top
);
1931 RECTL_vOffsetRect(&NRect
, - NewWindowRect
.left
, - NewWindowRect
.top
);
1932 RECTL_bIntersectRect(&CopyRect
, &ORect
, &NRect
);
1933 pCopyRgn
= RGNOBJAPI_Lock(CopyRgn
, NULL
);
1934 REGION_CropAndOffsetRegion(pCopyRgn
, pCopyRgn
, &CopyRect
, NULL
);
1935 RGNOBJAPI_Unlock(pCopyRgn
);
1938 /* No use in copying bits which are in the update region. */
1939 if (Window
->hrgnUpdate
!= NULL
)
1941 NtGdiOffsetRgn(CopyRgn
, NewWindowRect
.left
, NewWindowRect
.top
);
1942 NtGdiCombineRgn(CopyRgn
, CopyRgn
, Window
->hrgnUpdate
, RGN_DIFF
);
1943 NtGdiOffsetRgn(CopyRgn
, -NewWindowRect
.left
, -NewWindowRect
.top
);
1947 * Now, get the bounding box of the copy region. If it's empty
1948 * there's nothing to copy. Also, it's no use copying bits onto
1951 if ( (VisRgn
= (PROSRGNDATA
)RGNOBJAPI_Lock(CopyRgn
, NULL
)) &&
1952 REGION_GetRgnBox(VisRgn
, &CopyRect
) == NULLREGION
)
1954 /* Nothing to copy, clean up */
1955 RGNOBJAPI_Unlock(VisRgn
);
1956 GreDeleteObject(CopyRgn
);
1959 else if (OldWindowRect
.left
!= NewWindowRect
.left
||
1960 OldWindowRect
.top
!= NewWindowRect
.top
)
1964 RGNOBJAPI_Unlock(VisRgn
);
1968 * Small trick here: there is no function to bitblt a region. So
1969 * we set the region as the clipping region, take the bounding box
1970 * of the region and bitblt that. Since nothing outside the clipping
1971 * region is copied, this has the effect of bitblt'ing the region.
1973 * Since NtUserGetDCEx takes ownership of the clip region, we need
1974 * to create a copy of CopyRgn and pass that. We need CopyRgn later
1976 NtGdiOffsetRgn(CopyRgn
, NewWindowRect
.left
, NewWindowRect
.top
);
1977 Dc
= UserGetDCEx( Window
,
1979 DCX_WINDOW
|DCX_CACHE
|DCX_INTERSECTRGN
|DCX_CLIPSIBLINGS
|DCX_KEEPCLIPRGN
);
1981 CopyRect
.left
, CopyRect
.top
,
1982 CopyRect
.right
- CopyRect
.left
,
1983 CopyRect
.bottom
- CopyRect
.top
,
1985 CopyRect
.left
+ (OldWindowRect
.left
- NewWindowRect
.left
),
1986 CopyRect
.top
+ (OldWindowRect
.top
- NewWindowRect
.top
),
1991 UserReleaseDC(Window
, Dc
, FALSE
);
1992 IntValidateParent(Window
, CopyRgn
, FALSE
);
1993 NtGdiOffsetRgn(CopyRgn
, -NewWindowRect
.left
, -NewWindowRect
.top
);
1997 RGNOBJAPI_Unlock(VisRgn
);
2005 /* We need to redraw what wasn't visible before */
2006 if (VisAfter
!= NULL
)
2008 DirtyRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
2009 if (CopyRgn
!= NULL
)
2011 RgnType
= NtGdiCombineRgn(DirtyRgn
, VisAfter
, CopyRgn
, RGN_DIFF
);
2015 RgnType
= NtGdiCombineRgn(DirtyRgn
, VisAfter
, 0, RGN_COPY
);
2017 if (RgnType
!= ERROR
&& RgnType
!= NULLREGION
)
2020 NtGdiOffsetRgn(DirtyRgn, Window->rcWindow.left, Window->rcWindow.top);
2021 IntInvalidateWindows( Window,
2023 RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
2025 GreDeleteObject(DirtyRgn);
2028 PWND Parent
= Window
->spwndParent
;
2030 NtGdiOffsetRgn( DirtyRgn
,
2031 Window
->rcWindow
.left
,
2032 Window
->rcWindow
.top
);
2033 if ( (Window
->style
& WS_CHILD
) &&
2035 !(Parent
->style
& WS_CLIPCHILDREN
))
2037 IntInvalidateWindows( Parent
,
2039 RDW_ERASE
| RDW_INVALIDATE
);
2040 co_IntPaintWindows(Parent
, RDW_ERASENOW
, FALSE
);
2044 IntInvalidateWindows( Window
,
2046 RDW_ERASE
| RDW_FRAME
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
2049 GreDeleteObject(DirtyRgn
);
2052 if (CopyRgn
!= NULL
)
2054 GreDeleteObject(CopyRgn
);
2057 /* Expose what was covered before but not covered anymore */
2058 if (VisBefore
!= NULL
)
2060 ExposedRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
2061 RgnType
= NtGdiCombineRgn(ExposedRgn
, VisBefore
, NULL
, RGN_COPY
);
2062 NtGdiOffsetRgn( ExposedRgn
,
2063 OldWindowRect
.left
- NewWindowRect
.left
,
2064 OldWindowRect
.top
- NewWindowRect
.top
);
2066 if (VisAfter
!= NULL
)
2067 RgnType
= NtGdiCombineRgn(ExposedRgn
, ExposedRgn
, VisAfter
, RGN_DIFF
);
2069 if (RgnType
!= ERROR
&& RgnType
!= NULLREGION
)
2071 co_VIS_WindowLayoutChanged(Window
, ExposedRgn
);
2073 GreDeleteObject(ExposedRgn
);
2074 GreDeleteObject(VisBefore
);
2077 if (VisAfter
!= NULL
)
2079 GreDeleteObject(VisAfter
);
2083 if (!(WinPos
.flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2085 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2087 co_IntSendMessageNoWait(WinPos
.hwnd
, WM_CHILDACTIVATE
, 0, 0);
2091 //ERR("SetWindowPos Set FG Window!\n");
2092 if (Window
->state
& WNDS_BEINGACTIVATED
) // Inside SAW?
2093 co_IntSetActiveWindow(Window
, FALSE
, TRUE
, FALSE
); // Fixes Api AttachThreadInput tests.
2095 co_IntSetForegroundWindow(Window
); // Fixes SW_HIDE issues. Wine win test_SetActiveWindow & test_SetForegroundWindow.
2099 /* And last, send the WM_WINDOWPOSCHANGED message */
2101 TRACE("\tstatus flags = %04x\n", WinPos
.flags
& SWP_AGG_STATUSFLAGS
);
2103 if ((WinPos
.flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
)
2105 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2106 and always contains final window position.
2108 WinPos
.x
= NewWindowRect
.left
;
2109 WinPos
.y
= NewWindowRect
.top
;
2110 WinPos
.cx
= NewWindowRect
.right
- NewWindowRect
.left
;
2111 WinPos
.cy
= NewWindowRect
.bottom
- NewWindowRect
.top
;
2112 co_IntSendMessageNoWait(WinPos
.hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
) &WinPos
);
2115 if ( WinPos
.flags
& SWP_FRAMECHANGED
|| WinPos
.flags
& SWP_STATECHANGED
||
2116 !(WinPos
.flags
& SWP_NOCLIENTSIZE
) || !(WinPos
.flags
& SWP_NOCLIENTMOVE
) )
2118 PWND pWnd
= ValidateHwndNoErr(WinPos
.hwnd
);
2120 IntNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
2123 if(bPointerInWindow
!= IntPtInWindow(Window
, gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
))
2125 /* Generate mouse move message */
2127 msg
.message
= WM_MOUSEMOVE
;
2128 msg
.wParam
= UserGetMouseButtonsState();
2129 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2130 msg
.pt
= gpsi
->ptCursor
;
2131 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2138 co_WinPosGetNonClientSize(PWND Window
, RECT
* WindowRect
, RECT
* ClientRect
)
2142 ASSERT_REFS_CO(Window
);
2144 *ClientRect
= *WindowRect
;
2145 Result
= co_IntSendMessageNoWait(Window
->head
.h
, WM_NCCALCSIZE
, FALSE
, (LPARAM
) ClientRect
);
2147 FixClientRect(ClientRect
, WindowRect
);
2153 co_WinPosSendSizeMove(PWND Wnd
)
2157 WPARAM wParam
= SIZE_RESTORED
;
2159 IntGetClientRect(Wnd
, &Rect
);
2160 lParam
= MAKELONG(Rect
.right
-Rect
.left
, Rect
.bottom
-Rect
.top
);
2162 Wnd
->state
&= ~WNDS_SENDSIZEMOVEMSGS
;
2164 if (Wnd
->style
& WS_MAXIMIZE
)
2166 wParam
= SIZE_MAXIMIZED
;
2168 else if (Wnd
->style
& WS_MINIMIZE
)
2170 wParam
= SIZE_MINIMIZED
;
2174 co_IntSendMessageNoWait(UserHMGetHandle(Wnd
), WM_SIZE
, wParam
, lParam
);
2176 if (Wnd
->spwndParent
== UserGetDesktopWindow()) // Wnd->spwndParent->fnid == FNID_DESKTOP )
2177 lParam
= MAKELONG(Wnd
->rcClient
.left
, Wnd
->rcClient
.top
);
2179 lParam
= MAKELONG(Wnd
->rcClient
.left
-Wnd
->spwndParent
->rcClient
.left
, Wnd
->rcClient
.top
-Wnd
->spwndParent
->rcClient
.top
);
2181 co_IntSendMessageNoWait(UserHMGetHandle(Wnd
), WM_MOVE
, 0, lParam
);
2183 IntEngWindowChanged(Wnd
, WOC_RGN_CLIENT
);
2187 co_WinPosShowWindow(PWND Wnd
, INT Cmd
)
2190 UINT Swp
= 0, EventMsg
= 0;
2191 RECTL NewPos
= {0, 0, 0, 0};
2197 //ERR("co_WinPosShowWindow START\n");
2198 BOOL ShowOwned
= FALSE
;
2199 ASSERT_REFS_CO(Wnd
);
2201 pti
= PsGetCurrentThreadWin32Thread();
2202 WasVisible
= (Wnd
->style
& WS_VISIBLE
) != 0;
2211 //ERR("co_WinPosShowWindow Exit Bad\n");
2214 Swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
2215 if (Wnd
!= pti
->MessageQueue
->spwndActive
)
2216 Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2220 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
2221 case SW_SHOWMINNOACTIVE
:
2222 Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2224 case SW_SHOWMINIMIZED
:
2225 Swp
|= SWP_SHOWWINDOW
;
2229 Swp
|= SWP_NOACTIVATE
;
2230 if (!(style
& WS_MINIMIZE
))
2232 IntShowOwnedPopups(Wnd
, FALSE
);
2234 // Fix wine Win test_SetFocus todo #1 & #2,
2235 if (Cmd
== SW_SHOWMINIMIZED
)
2237 //ERR("co_WinPosShowWindow Set focus 1\n");
2238 if ((style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2239 co_UserSetFocus(Wnd
->spwndParent
);
2244 Swp
|= co_WinPosMinMaximize(Wnd
, Cmd
, &NewPos
) |
2247 EventMsg
= EVENT_SYSTEM_MINIMIZESTART
;
2253 Swp
|= SWP_FRAMECHANGED
;
2257 //ERR("co_WinPosShowWindow Exit Good\n");
2260 Swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
2265 case SW_SHOWMAXIMIZED
:
2267 Swp
|= SWP_SHOWWINDOW
;
2268 if (!(style
& WS_MAXIMIZE
))
2272 Swp
|= co_WinPosMinMaximize(Wnd
, SW_MAXIMIZE
, &NewPos
) |
2275 EventMsg
= EVENT_SYSTEM_MINIMIZEEND
;
2281 Swp
|= SWP_FRAMECHANGED
;
2285 //ERR("co_WinPosShowWindow Exit Good 1\n");
2288 Swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
2294 Swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
2295 if (style
& WS_CHILD
&& !(Wnd
->ExStyle
& WS_EX_MDICHILD
)) Swp
|= SWP_NOZORDER
;
2298 if (WasVisible
) return(TRUE
); // Nothing to do!
2299 Swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
2300 /* Don't activate the topmost window. */
2301 if (style
& WS_CHILD
&& !(Wnd
->ExStyle
& WS_EX_MDICHILD
)) Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2304 case SW_SHOWNOACTIVATE
:
2305 Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2308 case SW_SHOWDEFAULT
:
2310 if (!WasVisible
) Swp
|= SWP_SHOWWINDOW
;
2311 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2313 Swp
|= co_WinPosMinMaximize(Wnd
, Cmd
, &NewPos
) |
2316 if (style
& WS_MINIMIZE
) EventMsg
= EVENT_SYSTEM_MINIMIZEEND
;
2322 Swp
|= SWP_FRAMECHANGED
;
2326 //ERR("co_WinPosShowWindow Exit Good 3\n");
2329 Swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
2331 if ( style
& WS_CHILD
&&
2332 !(Wnd
->ExStyle
& WS_EX_MDICHILD
) &&
2333 !(Swp
& SWP_STATECHANGED
))
2334 Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2338 //ERR("co_WinPosShowWindow Exit Good 4\n");
2342 ShowFlag
= (Cmd
!= SW_HIDE
);
2344 if ((ShowFlag
!= WasVisible
|| Cmd
== SW_SHOWNA
) && Cmd
!= SW_SHOWMAXIMIZED
&& !(Swp
& SWP_STATECHANGED
))
2346 co_IntSendMessageNoWait(Wnd
->head
.h
, WM_SHOWWINDOW
, ShowFlag
, 0);
2347 if (!(Wnd
->state2
& WNDS2_WIN31COMPAT
))
2348 co_IntSendMessageNoWait(Wnd
->head
.h
, WM_SETVISIBLE
, ShowFlag
, 0);
2349 if (!VerifyWnd(Wnd
)) return WasVisible
;
2352 /* We can't activate a child window */
2353 if ((Wnd
->style
& WS_CHILD
) &&
2354 !(Wnd
->ExStyle
& WS_EX_MDICHILD
) &&
2357 //ERR("SWP Child No active and ZOrder\n");
2358 Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2361 #if 0 // Explorer issues with common controls. Someone does not know how CS_SAVEBITS works.
2362 if ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
&&
2363 Wnd
->pcls
->style
& CS_SAVEBITS
&&
2364 ((Cmd
== SW_SHOW
) || (Cmd
== SW_NORMAL
)))
2366 ERR("WinPosShowWindow Set active\n");
2367 UserSetActiveWindow(Wnd
);
2368 Swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
2372 if (IsChildVisible(Wnd
) || Swp
& SWP_STATECHANGED
)
2374 TRACE("Child is Vis %s or State changed %s. ShowFlag %s\n",
2375 (IsChildVisible(Wnd
) ? "TRUE" : "FALSE"), (Swp
& SWP_STATECHANGED
? "TRUE" : "FALSE"),
2376 (ShowFlag
? "TRUE" : "FALSE"));
2377 co_WinPosSetWindowPos( Wnd
,
2378 0 != (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOPMOST
: HWND_TOP
,
2381 NewPos
.right
, //NewPos.right - NewPos.left,
2382 NewPos
.bottom
, //NewPos.bottom - NewPos.top,
2387 TRACE("Parent Vis?\n");
2388 /* if parent is not visible simply toggle WS_VISIBLE and return */
2389 if (ShowFlag
) IntSetStyle( Wnd
, WS_VISIBLE
, 0 );
2390 else IntSetStyle( Wnd
, 0, WS_VISIBLE
);
2393 if ( EventMsg
) IntNotifyWinEvent(EventMsg
, Wnd
, OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
2395 if ( ShowOwned
) IntShowOwnedPopups(Wnd
, TRUE
);
2397 if ((Cmd
== SW_HIDE
) || (Cmd
== SW_MINIMIZE
))
2399 if ( Wnd
== pti
->MessageQueue
->spwndActive
&& pti
->MessageQueue
== IntGetFocusMessageQueue() )
2401 if ( Wnd
->spwndParent
== UserGetDesktopWindow())
2403 if(!ActivateOtherWindowMin(Wnd
))
2404 co_WinPosActivateOtherWindow(Wnd
);
2407 co_WinPosActivateOtherWindow(Wnd
);
2410 /* Revert focus to parent */
2411 if (Wnd
== pti
->MessageQueue
->spwndFocus
)
2413 Parent
= Wnd
->spwndParent
;
2414 if (Wnd
->spwndParent
== UserGetDesktopWindow()) Parent
= 0;
2415 co_UserSetFocus(Parent
);
2419 /* FIXME: Check for window destruction. */
2421 if ((Wnd
->state
& WNDS_SENDSIZEMOVEMSGS
) &&
2422 !(Wnd
->state2
& WNDS2_INDESTROY
))
2424 co_WinPosSendSizeMove(Wnd
);
2427 /* if previous state was minimized Windows sets focus to the window */
2428 if (style
& WS_MINIMIZE
)
2430 co_UserSetFocus(Wnd
);
2431 // Fix wine Win test_SetFocus todo #3,
2432 if (!(style
& WS_CHILD
)) co_IntSendMessageNoWait(UserHMGetHandle(Wnd
), WM_ACTIVATE
, WA_ACTIVE
, 0);
2434 //ERR("co_WinPosShowWindow EXIT\n");
2440 co_WinPosSearchChildren(
2450 if (!(ScopeWin
->style
& WS_VISIBLE
))
2455 if (!Ignore
&& (ScopeWin
->style
& WS_DISABLED
))
2460 if (!IntPtInWindow(ScopeWin
, Point
->x
, Point
->y
))
2465 UserReferenceObject(ScopeWin
);
2467 if ( RECTL_bPointInRect(&ScopeWin
->rcClient
, Point
->x
, Point
->y
) )
2469 List
= IntWinListChildren(ScopeWin
);
2472 for (phWnd
= List
; *phWnd
; ++phWnd
)
2474 if (!(pwndChild
= ValidateHwndNoErr(*phWnd
)))
2479 pwndChild
= co_WinPosSearchChildren(pwndChild
, Point
, HitTest
, Ignore
);
2481 if(pwndChild
!= NULL
)
2483 /* We found a window. Don't send any more WM_NCHITTEST messages */
2484 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2485 UserDereferenceObject(ScopeWin
);
2489 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2493 if (ScopeWin
->head
.pti
== PsGetCurrentThreadWin32Thread())
2495 *HitTest
= (USHORT
)co_IntSendMessage(ScopeWin
->head
.h
, WM_NCHITTEST
, 0,
2496 MAKELONG(Point
->x
, Point
->y
));
2497 if ((*HitTest
) == (USHORT
)HTTRANSPARENT
)
2499 UserDereferenceObject(ScopeWin
);
2504 *HitTest
= HTCLIENT
;
2510 co_WinPosWindowFromPoint(PWND ScopeWin
, POINT
*WinPoint
, USHORT
* HitTest
, BOOL Ignore
)
2513 POINT Point
= *WinPoint
;
2514 USER_REFERENCE_ENTRY Ref
;
2516 if( ScopeWin
== NULL
)
2518 ScopeWin
= UserGetDesktopWindow();
2519 if(ScopeWin
== NULL
)
2523 *HitTest
= HTNOWHERE
;
2525 ASSERT_REFS_CO(ScopeWin
);
2526 UserRefObjectCo(ScopeWin
, &Ref
);
2528 Window
= co_WinPosSearchChildren(ScopeWin
, &Point
, HitTest
, Ignore
);
2530 UserDerefObjectCo(ScopeWin
);
2532 ASSERT_REFS_CO(Window
);
2533 ASSERT_REFS_CO(ScopeWin
);
2539 IntRealChildWindowFromPoint(PWND Parent
, LONG x
, LONG y
)
2543 PWND pwndHit
= NULL
;
2548 if (Parent
!= UserGetDesktopWindow())
2550 Pt
.x
+= Parent
->rcClient
.left
;
2551 Pt
.y
+= Parent
->rcClient
.top
;
2554 if (!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
)) return NULL
;
2556 if ((List
= IntWinListChildren(Parent
)))
2558 for (phWnd
= List
; *phWnd
; phWnd
++)
2561 if ((Child
= ValidateHwndNoErr(*phWnd
)))
2563 if ( Child
->style
& WS_VISIBLE
&& IntPtInWindow(Child
, Pt
.x
, Pt
.y
) )
2565 if ( Child
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_BUTTON
] ||
2566 (Child
->style
& BS_TYPEMASK
) != BS_GROUPBOX
)
2568 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2575 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2577 return pwndHit
? pwndHit
: Parent
;
2581 IntChildWindowFromPointEx(PWND Parent
, LONG x
, LONG y
, UINT uiFlags
)
2585 PWND pwndHit
= NULL
;
2590 if (Parent
!= UserGetDesktopWindow())
2592 if (Parent
->ExStyle
& WS_EX_LAYOUTRTL
)
2593 Pt
.x
= Parent
->rcClient
.right
- Pt
.x
;
2595 Pt
.x
+= Parent
->rcClient
.left
;
2596 Pt
.y
+= Parent
->rcClient
.top
;
2599 if (!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
)) return NULL
;
2601 if ((List
= IntWinListChildren(Parent
)))
2603 for (phWnd
= List
; *phWnd
; phWnd
++)
2606 if ((Child
= ValidateHwndNoErr(*phWnd
)))
2608 if (uiFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
2610 if (!(Child
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
)) continue;
2611 if ((Child
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
)) continue;
2614 if (uiFlags
& CWP_SKIPTRANSPARENT
)
2616 if (Child
->ExStyle
& WS_EX_TRANSPARENT
) continue;
2619 if (IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
2626 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2628 return pwndHit
? pwndHit
: Parent
;
2633 IntDeferWindowPos( HDWP hdwp
,
2644 HDWP retvalue
= hdwp
;
2646 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2647 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2649 if (flags
& ~(SWP_NOSIZE
| SWP_NOMOVE
|
2650 SWP_NOZORDER
| SWP_NOREDRAW
|
2651 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2652 SWP_NOOWNERZORDER
|SWP_SHOWWINDOW
|
2653 SWP_HIDEWINDOW
| SWP_FRAMECHANGED
))
2655 EngSetLastError(ERROR_INVALID_PARAMETER
);
2659 if (!(pDWP
= (PSMWP
)UserGetObject(gHandleTable
, hdwp
, TYPE_SETWINDOWPOS
)))
2661 EngSetLastError(ERROR_INVALID_DWP_HANDLE
);
2665 for (i
= 0; i
< pDWP
->ccvr
; i
++)
2667 if (pDWP
->acvr
[i
].pos
.hwnd
== hwnd
)
2669 /* Merge with the other changes */
2670 if (!(flags
& SWP_NOZORDER
))
2672 pDWP
->acvr
[i
].pos
.hwndInsertAfter
= hwndAfter
;
2674 if (!(flags
& SWP_NOMOVE
))
2676 pDWP
->acvr
[i
].pos
.x
= x
;
2677 pDWP
->acvr
[i
].pos
.y
= y
;
2679 if (!(flags
& SWP_NOSIZE
))
2681 pDWP
->acvr
[i
].pos
.cx
= cx
;
2682 pDWP
->acvr
[i
].pos
.cy
= cy
;
2684 pDWP
->acvr
[i
].pos
.flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2685 SWP_NOZORDER
| SWP_NOREDRAW
|
2686 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2688 pDWP
->acvr
[i
].pos
.flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2693 if (pDWP
->ccvr
>= pDWP
->ccvrAlloc
)
2695 PCVR newpos
= ExAllocatePoolWithTag(PagedPool
, pDWP
->ccvrAlloc
* 2 * sizeof(CVR
), USERTAG_SWP
);
2701 RtlZeroMemory(newpos
, pDWP
->ccvrAlloc
* 2 * sizeof(CVR
));
2702 RtlCopyMemory(newpos
, pDWP
->acvr
, pDWP
->ccvrAlloc
* sizeof(CVR
));
2703 ExFreePoolWithTag(pDWP
->acvr
, USERTAG_SWP
);
2704 pDWP
->ccvrAlloc
*= 2;
2705 pDWP
->acvr
= newpos
;
2707 pDWP
->acvr
[pDWP
->ccvr
].pos
.hwnd
= hwnd
;
2708 pDWP
->acvr
[pDWP
->ccvr
].pos
.hwndInsertAfter
= hwndAfter
;
2709 pDWP
->acvr
[pDWP
->ccvr
].pos
.x
= x
;
2710 pDWP
->acvr
[pDWP
->ccvr
].pos
.y
= y
;
2711 pDWP
->acvr
[pDWP
->ccvr
].pos
.cx
= cx
;
2712 pDWP
->acvr
[pDWP
->ccvr
].pos
.cy
= cy
;
2713 pDWP
->acvr
[pDWP
->ccvr
].pos
.flags
= flags
;
2714 pDWP
->acvr
[pDWP
->ccvr
].hrgnClip
= NULL
;
2715 pDWP
->acvr
[pDWP
->ccvr
].hrgnInterMonitor
= NULL
;
2721 BOOL FASTCALL
IntEndDeferWindowPosEx( HDWP hdwp
, BOOL sAsync
)
2728 TRACE("%p\n", hdwp
);
2730 if (!(pDWP
= (PSMWP
)UserGetObject(gHandleTable
, hdwp
, TYPE_SETWINDOWPOS
)))
2732 EngSetLastError(ERROR_INVALID_DWP_HANDLE
);
2736 for (i
= 0, winpos
= pDWP
->acvr
; res
&& i
< pDWP
->ccvr
; i
++, winpos
++)
2739 USER_REFERENCE_ENTRY Ref
;
2741 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2742 winpos
->pos
.hwnd
, winpos
->pos
.hwndInsertAfter
, winpos
->pos
.x
, winpos
->pos
.y
,
2743 winpos
->pos
.cx
, winpos
->pos
.cy
, winpos
->pos
.flags
);
2745 pwnd
= ValidateHwndNoErr(winpos
->pos
.hwnd
);
2749 UserRefObjectCo(pwnd
, &Ref
);
2754 PWINDOWPOS ppos
= ExAllocatePoolWithTag(PagedPool
, sizeof(WINDOWPOS
), USERTAG_SWP
);
2757 *ppos
= winpos
->pos
;
2758 /* Yes it's a pointer inside Win32k! */
2759 lRes
= co_IntSendMessageNoWait( winpos
->pos
.hwnd
, WM_ASYNC_SETWINDOWPOS
, 0, (LPARAM
)ppos
);
2760 /* We handle this the same way as Event Hooks and Hooks. */
2763 ExFreePoolWithTag(ppos
, USERTAG_SWP
);
2768 res
= co_WinPosSetWindowPos( pwnd
,
2769 winpos
->pos
.hwndInsertAfter
,
2776 // Hack to pass tests.... Must have some work to do so clear the error.
2777 if (res
&& (winpos
->pos
.flags
& (SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
)) == SWP_NOZORDER
)
2778 EngSetLastError(ERROR_SUCCESS
);
2780 UserDerefObjectCo(pwnd
);
2782 ExFreePoolWithTag(pDWP
->acvr
, USERTAG_SWP
);
2783 UserDereferenceObject(pDWP
);
2784 UserDeleteObject(hdwp
, TYPE_SETWINDOWPOS
);
2792 NtUserChildWindowFromPointEx(HWND hwndParent
,
2798 TRACE("Enter NtUserChildWindowFromPointEx\n");
2799 UserEnterExclusive();
2800 if ((pwndParent
= UserGetWindowObject(hwndParent
)))
2802 pwndParent
= IntChildWindowFromPointEx(pwndParent
, x
, y
, uiFlags
);
2805 TRACE("Leave NtUserChildWindowFromPointEx\n");
2806 return pwndParent
? UserHMGetHandle(pwndParent
) : NULL
;
2813 NtUserEndDeferWindowPosEx(HDWP WinPosInfo
,
2817 TRACE("Enter NtUserEndDeferWindowPosEx\n");
2818 UserEnterExclusive();
2819 Ret
= IntEndDeferWindowPosEx(WinPosInfo
, (BOOL
)Unknown1
);
2820 TRACE("Leave NtUserEndDeferWindowPosEx, ret=%i\n", Ret
);
2829 NtUserDeferWindowPos(HDWP WinPosInfo
,
2831 HWND WndInsertAfter
,
2840 UINT Tmp
= ~(SWP_ASYNCWINDOWPOS
|SWP_DEFERERASE
|SWP_NOSENDCHANGING
|SWP_NOREPOSITION
|
2841 SWP_NOCOPYBITS
|SWP_HIDEWINDOW
|SWP_SHOWWINDOW
|SWP_FRAMECHANGED
|
2842 SWP_NOACTIVATE
|SWP_NOREDRAW
|SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
);
2844 TRACE("Enter NtUserDeferWindowPos\n");
2845 UserEnterExclusive();
2849 EngSetLastError(ERROR_INVALID_FLAGS
);
2853 pWnd
= UserGetWindowObject(Wnd
);
2854 if ( !pWnd
|| // FIXME:
2855 pWnd
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
2856 pWnd
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
2861 if ( WndInsertAfter
&&
2862 WndInsertAfter
!= HWND_BOTTOM
&&
2863 WndInsertAfter
!= HWND_TOPMOST
&&
2864 WndInsertAfter
!= HWND_NOTOPMOST
)
2866 pWndIA
= UserGetWindowObject(WndInsertAfter
);
2868 pWndIA
== UserGetDesktopWindow() ||
2869 pWndIA
== UserGetMessageWindow() )
2875 Ret
= IntDeferWindowPos(WinPosInfo
, Wnd
, WndInsertAfter
, x
, y
, cx
, cy
, Flags
);
2878 TRACE("Leave NtUserDeferWindowPos, ret=%p\n", Ret
);
2887 NtUserGetInternalWindowPos( HWND hWnd
,
2894 WINDOWPLACEMENT wndpl
;
2898 if (!(Window
= UserGetWindowObject(hWnd
)))
2908 ProbeForWrite(rectWnd
,
2914 ProbeForWrite(ptIcon
,
2920 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2922 SetLastNtError(_SEH2_GetExceptionCode());
2927 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
2929 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
2935 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
2939 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
2943 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2945 SetLastNtError(_SEH2_GetExceptionCode());
2950 if (!Hit
) Ret
= wndpl
.showCmd
;
2961 NtUserGetWindowPlacement(HWND hWnd
,
2962 WINDOWPLACEMENT
*lpwndpl
)
2965 WINDOWPLACEMENT Safepl
;
2967 DECLARE_RETURN(BOOL
);
2969 TRACE("Enter NtUserGetWindowPlacement\n");
2972 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2977 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
2978 if(!NT_SUCCESS(Status
))
2980 SetLastNtError(Status
);
2983 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
2988 IntGetWindowPlacement(Wnd
, &Safepl
);
2990 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
2991 if(!NT_SUCCESS(Status
))
2993 SetLastNtError(Status
);
3000 TRACE("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3009 UINT cmd
, // Wine SW_ commands
3014 TRACE("Enter NtUserMinMaximize\n");
3015 UserEnterExclusive();
3017 pWnd
= UserGetWindowObject(hWnd
);
3018 if ( !pWnd
|| // FIXME:
3019 pWnd
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3020 pWnd
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3025 if ( cmd
> SW_MAX
|| pWnd
->state2
& WNDS2_INDESTROY
)
3027 EngSetLastError(ERROR_INVALID_PARAMETER
);
3031 cmd
|= Hide
? SW_HIDE
: 0;
3033 co_WinPosShowWindow(pWnd
, cmd
);
3036 TRACE("Leave NtUserMinMaximize\n");
3038 return 0; // Always NULL?
3053 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3054 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3055 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3062 NtUserRealChildWindowFromPoint(HWND Parent
,
3067 TRACE("Enter NtUserRealChildWindowFromPoint\n");
3069 if ((pwndParent
= UserGetWindowObject(Parent
)))
3071 pwndParent
= IntRealChildWindowFromPoint(pwndParent
, x
, y
);
3074 TRACE("Leave NtUserRealChildWindowFromPoint\n");
3075 return pwndParent
? UserHMGetHandle(pwndParent
) : NULL
;
3084 HWND hWndInsertAfter
,
3091 DECLARE_RETURN(BOOL
);
3092 PWND Window
, pWndIA
;
3094 USER_REFERENCE_ENTRY Ref
;
3096 TRACE("Enter NtUserSetWindowPos\n");
3097 UserEnterExclusive();
3099 if (!(Window
= UserGetWindowObject(hWnd
)) || // FIXME:
3100 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3101 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3103 ERR("NtUserSetWindowPos bad window handle!\n");
3107 if ( hWndInsertAfter
&&
3108 hWndInsertAfter
!= HWND_BOTTOM
&&
3109 hWndInsertAfter
!= HWND_TOPMOST
&&
3110 hWndInsertAfter
!= HWND_NOTOPMOST
)
3112 if (!(pWndIA
= UserGetWindowObject(hWndInsertAfter
)) ||
3113 pWndIA
== UserGetDesktopWindow() ||
3114 pWndIA
== UserGetMessageWindow() )
3116 ERR("NtUserSetWindowPos bad insert window handle!\n");
3121 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
3122 if (!(uFlags
& SWP_NOMOVE
))
3124 if (X
< -32768) X
= -32768;
3125 else if (X
> 32767) X
= 32767;
3126 if (Y
< -32768) Y
= -32768;
3127 else if (Y
> 32767) Y
= 32767;
3129 if (!(uFlags
& SWP_NOSIZE
))
3132 else if (cx
> 32767) cx
= 32767;
3134 else if (cy
> 32767) cy
= 32767;
3137 UserRefObjectCo(Window
, &Ref
);
3138 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3139 UserDerefObjectCo(Window
);
3144 TRACE("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
3160 INT flags
= (SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOSIZE
|SWP_NOMOVE
);
3161 BOOLEAN Ret
= FALSE
;
3162 DECLARE_RETURN(INT
);
3164 TRACE("Enter NtUserSetWindowRgn\n");
3165 UserEnterExclusive();
3167 if (!(Window
= UserGetWindowObject(hWnd
)) || // FIXME:
3168 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3169 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3174 if (hRgn
) // The region will be deleted in user32.
3176 if (GreIsHandleValid(hRgn
))
3178 hrgnCopy
= IntSysCreateRectRgn(0, 0, 0, 0);
3179 /* The coordinates of a window's window region are relative to the
3180 upper-left corner of the window, not the client area of the window. */
3181 NtGdiCombineRgn( hrgnCopy
, hRgn
, 0, RGN_COPY
);
3191 if (Window
->hrgnClip
)
3193 /* Delete no longer needed region handle */
3194 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
3195 GreDeleteObject(Window
->hrgnClip
);
3200 /* Set public ownership */
3201 IntGdiSetRegionOwner(hrgnCopy
, GDI_OBJ_HMGR_PUBLIC
);
3203 Window
->hrgnClip
= hrgnCopy
;
3205 Ret
= co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, bRedraw
? flags
: (flags
|SWP_NOREDRAW
) );
3210 TRACE("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
3219 NtUserSetInternalWindowPos(
3225 WINDOWPLACEMENT wndpl
;
3230 DECLARE_RETURN(BOOL
);
3231 USER_REFERENCE_ENTRY Ref
;
3233 TRACE("Enter NtUserSetWindowPlacement\n");
3234 UserEnterExclusive();
3236 if (!(Wnd
= UserGetWindowObject(hwnd
)) || // FIXME:
3237 Wnd
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3238 Wnd
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3247 ProbeForRead(lppt
, sizeof(POINT
), 1);
3248 RtlCopyMemory(&pt
, lppt
, sizeof(POINT
));
3252 ProbeForRead(lprect
, sizeof(RECT
), 1);
3253 RtlCopyMemory(&rect
, lprect
, sizeof(RECT
));
3256 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3258 SetLastNtError(_SEH2_GetExceptionCode());
3259 _SEH2_YIELD(RETURN( FALSE
));
3263 wndpl
.length
= sizeof(wndpl
);
3264 wndpl
.showCmd
= showCmd
;
3265 wndpl
.flags
= flags
= 0;
3270 wndpl
.flags
|= WPF_SETMINPOSITION
;
3271 wndpl
.ptMinPosition
= pt
;
3275 flags
|= PLACE_RECT
;
3276 wndpl
.rcNormalPosition
= rect
;
3279 UserRefObjectCo(Wnd
, &Ref
);
3280 IntSetWindowPlacement(Wnd
, &wndpl
, flags
);
3281 UserDerefObjectCo(Wnd
);
3285 TRACE("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
3294 NtUserSetWindowPlacement(HWND hWnd
,
3295 WINDOWPLACEMENT
*lpwndpl
)
3298 WINDOWPLACEMENT Safepl
;
3300 DECLARE_RETURN(BOOL
);
3301 USER_REFERENCE_ENTRY Ref
;
3303 TRACE("Enter NtUserSetWindowPlacement\n");
3304 UserEnterExclusive();
3306 if (!(Wnd
= UserGetWindowObject(hWnd
)) || // FIXME:
3307 Wnd
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3308 Wnd
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3315 ProbeForRead(lpwndpl
, sizeof(WINDOWPLACEMENT
), 1);
3316 RtlCopyMemory(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3318 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3320 SetLastNtError(_SEH2_GetExceptionCode());
3321 _SEH2_YIELD(RETURN( FALSE
));
3325 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3330 Flags
= PLACE_MAX
| PLACE_RECT
;
3331 if (Safepl
.flags
& WPF_SETMINPOSITION
) Flags
|= PLACE_MIN
;
3332 UserRefObjectCo(Wnd
, &Ref
);
3333 IntSetWindowPlacement(Wnd
, &Safepl
, Flags
);
3334 UserDerefObjectCo(Wnd
);
3338 TRACE("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
3347 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
3351 DECLARE_RETURN(BOOL
);
3352 USER_REFERENCE_ENTRY Ref
;
3354 TRACE("Enter NtUserShowWindowAsync\n");
3355 UserEnterExclusive();
3357 if (!(Window
= UserGetWindowObject(hWnd
)) || // FIXME:
3358 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3359 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3364 if ( nCmdShow
> SW_MAX
)
3366 EngSetLastError(ERROR_INVALID_PARAMETER
);
3370 UserRefObjectCo(Window
, &Ref
);
3371 ret
= co_IntSendMessageNoWait( hWnd
, WM_ASYNC_SHOWWINDOW
, nCmdShow
, 0 );
3372 UserDerefObjectCo(Window
);
3373 if (-1 == (int) ret
|| !ret
) ret
= FALSE
;
3378 TRACE("Leave NtUserShowWindowAsync, ret=%i\n",_ret_
);
3387 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
3391 DECLARE_RETURN(BOOL
);
3392 USER_REFERENCE_ENTRY Ref
;
3394 TRACE("Enter NtUserShowWindow\n");
3395 UserEnterExclusive();
3397 if (!(Window
= UserGetWindowObject(hWnd
)) || // FIXME:
3398 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
3399 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
3404 if ( nCmdShow
> SW_MAX
|| Window
->state2
& WNDS2_INDESTROY
)
3406 EngSetLastError(ERROR_INVALID_PARAMETER
);
3410 UserRefObjectCo(Window
, &Ref
);
3411 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
3412 UserDerefObjectCo(Window
);
3417 TRACE("Leave NtUserShowWindow, ret=%i\n",_ret_
);
3427 NtUserWindowFromPoint(LONG X
, LONG Y
)
3431 PWND DesktopWindow
= NULL
, Window
= NULL
;
3433 DECLARE_RETURN(HWND
);
3434 USER_REFERENCE_ENTRY Ref
;
3436 TRACE("Enter NtUserWindowFromPoint\n");
3437 UserEnterExclusive();
3439 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
3446 // Hmm... Threads live on desktops thus we have a reference on the desktop and indirectly the desktop window.
3447 // It is possible this referencing is useless, though it should not hurt...
3448 UserRefObjectCo(DesktopWindow
, &Ref
);
3450 //pti = PsGetCurrentThreadWin32Thread();
3451 Window
= co_WinPosWindowFromPoint(DesktopWindow
, &pt
, &hittest
, FALSE
);
3455 Ret
= UserHMGetHandle(Window
);
3464 if (Window
) UserDereferenceObject(Window
);
3465 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
3467 TRACE("Leave NtUserWindowFromPoint, ret=%p\n", _ret_
);