2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
10 #include <X11/Xatom.h>
11 #include "sysmetrics.h"
22 #include "nonclient.h"
24 /* #define DEBUG_WIN */
27 #define SWP_AGG_NOGEOMETRYCHANGE \
28 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
29 #define SWP_AGG_NOPOSCHANGE \
30 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
31 #define SWP_AGG_STATUSFLAGS \
32 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
34 #define SMC_NOCOPY 0x0001
35 #define SMC_NOPARENTERASE 0x0002
36 #define SMC_DRAWFRAME 0x0004
37 #define SMC_SETXPOS 0x0008
39 /* ----- external functions ----- */
41 extern void FOCUS_SwitchFocus( HWND32
, HWND32
);
42 extern HRGN32
DCE_GetVisRgn( HWND32
, WORD
);
43 extern HWND32
CARET_GetHwnd();
44 extern BOOL32
DCE_InvalidateDCE(WND
*, RECT16
* );
46 /* ----- internal variables ----- */
48 static HWND32 hwndActive
= 0; /* Currently active window */
49 static HWND32 hwndPrevActive
= 0; /* Previously active window */
51 extern MESSAGEQUEUE
* pActiveQueue
;
53 /***********************************************************************
56 void WINPOS_CheckActive( HWND32 hwnd
)
58 if( hwnd
== hwndPrevActive
) hwndPrevActive
= 0;
59 if( hwnd
== hwndActive
)
62 dprintf_win(stddeb
,"\tattempt to activate destroyed window!\n");
66 /***********************************************************************
69 * Find a suitable place for an iconic window.
70 * The new position is stored into wndPtr->ptIconPos.
72 void WINPOS_FindIconPos( HWND32 hwnd
)
75 short x
, y
, xspacing
, yspacing
;
76 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
78 if (!wndPtr
|| !wndPtr
->parent
) return;
79 GetClientRect16( wndPtr
->parent
->hwndSelf
, &rectParent
);
80 if ((wndPtr
->ptIconPos
.x
>= rectParent
.left
) &&
81 (wndPtr
->ptIconPos
.x
+ SYSMETRICS_CXICON
< rectParent
.right
) &&
82 (wndPtr
->ptIconPos
.y
>= rectParent
.top
) &&
83 (wndPtr
->ptIconPos
.y
+ SYSMETRICS_CYICON
< rectParent
.bottom
))
84 return; /* The icon already has a suitable position */
86 xspacing
= yspacing
= 70; /* FIXME: This should come from WIN.INI */
87 y
= rectParent
.bottom
;
90 for (x
= rectParent
.left
; x
<=rectParent
.right
-xspacing
; x
+= xspacing
)
92 /* Check if another icon already occupies this spot */
93 WND
*childPtr
= wndPtr
->parent
->child
;
96 if ((childPtr
->dwStyle
& WS_MINIMIZE
) && (childPtr
!= wndPtr
))
98 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
99 (childPtr
->rectWindow
.right
>= x
) &&
100 (childPtr
->rectWindow
.top
<= y
) &&
101 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
102 break; /* There's a window in there */
104 childPtr
= childPtr
->next
;
108 /* No window was found, so it's OK for us */
109 wndPtr
->ptIconPos
.x
= x
+ (xspacing
- SYSMETRICS_CXICON
) / 2;
110 wndPtr
->ptIconPos
.y
= y
- (yspacing
+ SYSMETRICS_CYICON
) / 2;
119 /***********************************************************************
120 * ArrangeIconicWindows (USER32.6)
122 UINT16
ArrangeIconicWindows16( HWND16 parent
) {
123 return ArrangeIconicWindows32(parent
);
125 /***********************************************************************
126 * ArrangeIconicWindows (USER.170)
128 UINT32
ArrangeIconicWindows32( HWND32 parent
)
132 INT32 x
, y
, xspacing
, yspacing
;
134 GetClientRect32( parent
, &rectParent
);
136 y
= rectParent
.bottom
;
137 xspacing
= yspacing
= 70; /* FIXME: This should come from WIN.INI */
138 hwndChild
= GetWindow32( parent
, GW_CHILD
);
141 if (IsIconic32( hwndChild
))
143 SetWindowPos32( hwndChild
, 0, x
+ (xspacing
- SYSMETRICS_CXICON
) / 2,
144 y
- (yspacing
+ SYSMETRICS_CYICON
) / 2, 0, 0,
145 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
);
146 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
153 hwndChild
= GetWindow32( hwndChild
, GW_HWNDNEXT
);
159 /***********************************************************************
160 * SwitchToThisWindow16 (USER.172)
162 void SwitchToThisWindow16( HWND16 hwnd
, BOOL16 restore
)
164 SwitchToThisWindow32( hwnd
, restore
);
168 /***********************************************************************
169 * SwitchToThisWindow32 (USER32.538)
171 void SwitchToThisWindow32( HWND32 hwnd
, BOOL32 restore
)
173 ShowWindow32( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
177 /***********************************************************************
178 * GetWindowRect16 (USER.32)
180 void GetWindowRect16( HWND16 hwnd
, LPRECT16 rect
)
182 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
185 *rect
= wndPtr
->rectWindow
;
186 if (wndPtr
->dwStyle
& WS_CHILD
)
187 MapWindowPoints16( wndPtr
->parent
->hwndSelf
, 0, (POINT16
*)rect
, 2 );
191 /***********************************************************************
192 * GetWindowRect32 (USER.32)
194 void GetWindowRect32( HWND32 hwnd
, LPRECT32 rect
)
196 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
199 CONV_RECT16TO32( &wndPtr
->rectWindow
, rect
);
200 if (wndPtr
->dwStyle
& WS_CHILD
)
201 MapWindowPoints32( wndPtr
->parent
->hwndSelf
, 0, (POINT32
*)rect
, 2 );
205 /***********************************************************************
206 * GetClientRect16 (USER.33)
208 void GetClientRect16( HWND16 hwnd
, LPRECT16 rect
)
210 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
212 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
215 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
216 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
221 /***********************************************************************
222 * GetClientRect32 (USER32.219)
224 void GetClientRect32( HWND32 hwnd
, LPRECT32 rect
)
226 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
228 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
231 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
232 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
237 /*******************************************************************
238 * ClientToScreen16 (USER.28)
240 BOOL16
ClientToScreen16( HWND16 hwnd
, LPPOINT16 lppnt
)
242 MapWindowPoints16( hwnd
, 0, lppnt
, 1 );
247 /*******************************************************************
248 * ClientToScreen32 (USER32.51)
250 BOOL32
ClientToScreen32( HWND32 hwnd
, LPPOINT32 lppnt
)
252 MapWindowPoints32( hwnd
, 0, lppnt
, 1 );
257 /*******************************************************************
258 * ScreenToClient16 (USER.29)
260 void ScreenToClient16( HWND16 hwnd
, LPPOINT16 lppnt
)
262 MapWindowPoints16( 0, hwnd
, lppnt
, 1 );
266 /*******************************************************************
267 * ScreenToClient32 (USER32.446)
269 void ScreenToClient32( HWND32 hwnd
, LPPOINT32 lppnt
)
271 MapWindowPoints32( 0, hwnd
, lppnt
, 1 );
275 /***********************************************************************
276 * WINPOS_WindowFromPoint
278 * Find the window and hittest for a given point.
280 INT16
WINPOS_WindowFromPoint( WND
* wndScope
, POINT16 pt
, WND
**ppWnd
)
283 INT16 hittest
= HTERROR
;
289 wndPtr
= wndScope
->child
;
294 /* If point is in window, and window is visible, and it */
295 /* is enabled (or it's a top-level window), then explore */
296 /* its children. Otherwise, go to the next window. */
298 if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
299 (!(wndPtr
->dwStyle
& WS_DISABLED
) ||
300 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)) &&
301 (x
>= wndPtr
->rectWindow
.left
) &&
302 (x
< wndPtr
->rectWindow
.right
) &&
303 (y
>= wndPtr
->rectWindow
.top
) &&
304 (y
< wndPtr
->rectWindow
.bottom
))
306 *ppWnd
= wndPtr
; /* Got a suitable window */
308 /* If window is minimized or disabled, return at once */
309 if (wndPtr
->dwStyle
& WS_MINIMIZE
) return HTCAPTION
;
310 if (wndPtr
->dwStyle
& WS_DISABLED
) return HTERROR
;
312 /* If point is not in client area, ignore the children */
313 if ((x
< wndPtr
->rectClient
.left
) ||
314 (x
>= wndPtr
->rectClient
.right
) ||
315 (y
< wndPtr
->rectClient
.top
) ||
316 (y
>= wndPtr
->rectClient
.bottom
)) break;
318 x
-= wndPtr
->rectClient
.left
;
319 y
-= wndPtr
->rectClient
.top
;
320 wndPtr
= wndPtr
->child
;
322 else wndPtr
= wndPtr
->next
;
325 /* If nothing found, return the scope window */
329 if( pt
.x
>= (wndScope
->rectClient
.left
- wndScope
->rectWindow
.left
) &&
330 pt
.x
>= (wndScope
->rectClient
.top
- wndScope
->rectWindow
.top
) &&
331 pt
.x
<= (wndScope
->rectClient
.right
- wndScope
->rectWindow
.left
) &&
332 pt
.x
<= (wndScope
->rectClient
.bottom
- wndScope
->rectWindow
.top
) )
334 if( pt
.x
< 0 || pt
.y
< 0 ||
335 pt
.x
> (wndScope
->rectWindow
.right
- wndScope
->rectWindow
.left
) ||
336 pt
.y
> (wndScope
->rectWindow
.bottom
- wndScope
->rectWindow
.top
) )
338 return HTCAPTION
; /* doesn't matter in this case */
341 /* Send the WM_NCHITTEST message (only if to the same task) */
342 if ((*ppWnd
)->hmemTaskQ
!= GetTaskQueue(0)) return HTCLIENT
;
343 hittest
= (INT16
)SendMessage16( (*ppWnd
)->hwndSelf
, WM_NCHITTEST
, 0,
344 MAKELONG( pt
.x
, pt
.y
) );
345 if (hittest
!= HTTRANSPARENT
) return hittest
; /* Found the window */
347 /* If no children found in last search, make point relative to parent*/
350 x
+= (*ppWnd
)->rectClient
.left
;
351 y
+= (*ppWnd
)->rectClient
.top
;
354 /* Restart the search from the next sibling */
355 wndPtr
= (*ppWnd
)->next
;
356 *ppWnd
= (*ppWnd
)->parent
;
361 /*******************************************************************
362 * WindowFromPoint16 (USER.30)
364 HWND16
WindowFromPoint16( POINT16 pt
)
367 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt
, &pWnd
);
368 return pWnd
->hwndSelf
;
372 /*******************************************************************
373 * WindowFromPoint32 (USER32.581)
375 HWND32
WindowFromPoint32( POINT32 pt
)
379 CONV_POINT32TO16( &pt
, &pt16
);
380 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt16
, &pWnd
);
381 return (HWND32
)pWnd
->hwndSelf
;
385 /*******************************************************************
386 * ChildWindowFromPoint16 (USER.191)
388 HWND16
ChildWindowFromPoint16( HWND16 hwndParent
, POINT16 pt
)
390 /* pt is in the client coordinates */
392 WND
* wnd
= WIN_FindWndPtr(hwndParent
);
397 /* get client rect fast */
398 rect
.top
= rect
.left
= 0;
399 rect
.right
= wnd
->rectClient
.right
- wnd
->rectClient
.left
;
400 rect
.bottom
= wnd
->rectClient
.bottom
- wnd
->rectClient
.top
;
402 if (!PtInRect16( &rect
, pt
)) return 0;
407 if (PtInRect16( &wnd
->rectWindow
, pt
)) return wnd
->hwndSelf
;
414 /*******************************************************************
415 * ChildWindowFromPoint32 (USER32.)
417 HWND32
ChildWindowFromPoint32( HWND32 hwndParent
, POINT32 pt
)
420 CONV_POINT32TO16( &pt
, &pt16
);
421 return (HWND32
)ChildWindowFromPoint16( hwndParent
, pt16
);
425 /*******************************************************************
426 * WINPOS_GetWinOffset
428 * Calculate the offset between the origin of the two windows. Used
429 * to implement MapWindowPoints.
431 static void WINPOS_GetWinOffset( HWND32 hwndFrom
, HWND32 hwndTo
,
436 offset
->x
= offset
->y
= 0;
437 if (hwndFrom
== hwndTo
) return;
439 /* Translate source window origin to screen coords */
442 if (!(wndPtr
= WIN_FindWndPtr( hwndFrom
)))
444 fprintf(stderr
,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom
);
447 while (wndPtr
->parent
)
449 offset
->x
+= wndPtr
->rectClient
.left
;
450 offset
->y
+= wndPtr
->rectClient
.top
;
451 wndPtr
= wndPtr
->parent
;
455 /* Translate origin to destination window coords */
458 if (!(wndPtr
= WIN_FindWndPtr( hwndTo
)))
460 fprintf(stderr
,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo
);
463 while (wndPtr
->parent
)
465 offset
->x
-= wndPtr
->rectClient
.left
;
466 offset
->y
-= wndPtr
->rectClient
.top
;
467 wndPtr
= wndPtr
->parent
;
473 /*******************************************************************
474 * MapWindowPoints16 (USER.258)
476 void MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
477 LPPOINT16 lppt
, UINT16 count
)
481 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
491 /*******************************************************************
492 * MapWindowPoints32 (USER32.385)
494 void MapWindowPoints32( HWND32 hwndFrom
, HWND32 hwndTo
,
495 LPPOINT32 lppt
, UINT32 count
)
499 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
509 /***********************************************************************
512 BOOL16
IsIconic16(HWND16 hWnd
)
514 return IsIconic32(hWnd
);
516 /***********************************************************************
517 * IsIconic (USER32.344)
519 BOOL32
IsIconic32(HWND32 hWnd
)
521 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
522 if (wndPtr
== NULL
) return FALSE
;
523 return (wndPtr
->dwStyle
& WS_MINIMIZE
) != 0;
527 /***********************************************************************
528 * IsZoomed (USER.272)
530 BOOL16
IsZoomed16(HWND16 hWnd
)
532 return IsZoomed32(hWnd
);
534 /***********************************************************************
535 * IsZoomed (USER32.351)
537 BOOL32
IsZoomed32(HWND32 hWnd
)
539 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
540 if (wndPtr
== NULL
) return FALSE
;
541 return (wndPtr
->dwStyle
& WS_MAXIMIZE
) != 0;
545 /*******************************************************************
546 * GetActiveWindow (USER.60)
548 HWND16
GetActiveWindow16(void)
550 return GetActiveWindow32();
552 /*******************************************************************
553 * GetActiveWindow (USER32.204)
555 HWND32
GetActiveWindow32(void)
561 /*******************************************************************
562 * WINPOS_IsGoodEnough
564 static BOOL32
WINPOS_IsGoodEnough(WND
* pWnd
)
566 return (pWnd
) ? ((!(pWnd
->dwStyle
& WS_DISABLED
) &&
567 pWnd
->dwStyle
& WS_VISIBLE
) ? TRUE
: FALSE
) : FALSE
;
571 /*******************************************************************
572 * SetActiveWindow (USER.59)
574 HWND16
SetActiveWindow16( HWND16 hwnd
)
576 return SetActiveWindow32(hwnd
);
578 /*******************************************************************
579 * SetActiveWindow (USER.59)
581 HWND32
SetActiveWindow32( HWND32 hwnd
)
583 HWND32 prev
= hwndActive
;
584 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
586 if ( !WINPOS_IsGoodEnough(wndPtr
) ) return 0;
588 WINPOS_SetActiveWindow( hwnd
, 0, 0 );
593 /***********************************************************************
594 * BringWindowToTop (USER.45)
596 BOOL16
BringWindowToTop16( HWND16 hwnd
)
598 return BringWindowToTop32(hwnd
);
600 /***********************************************************************
601 * BringWindowToTop (USER32.10)
603 BOOL32
BringWindowToTop32( HWND32 hwnd
)
605 return SetWindowPos32( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
609 /***********************************************************************
610 * MoveWindow (USER.56)
613 HWND16 hwnd
, INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, BOOL16 repaint
615 return MoveWindow32(hwnd
,x
,y
,cx
,cy
,repaint
);
617 /***********************************************************************
618 * MoveWindow (USER32.398)
621 HWND32 hwnd
, INT32 x
, INT32 y
, INT32 cx
, INT32 cy
, BOOL32 repaint
623 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
624 if (!repaint
) flags
|= SWP_NOREDRAW
;
625 dprintf_win(stddeb
, "MoveWindow: %04x %d,%d %dx%d %d\n",
626 hwnd
, x
, y
, cx
, cy
, repaint
);
627 return SetWindowPos32( hwnd
, 0, x
, y
, cx
, cy
, flags
);
630 /***********************************************************************
631 * ShowWindow (USER.42)
633 BOOL16
ShowWindow16( HWND16 hwnd
, INT16 cmd
)
635 return ShowWindow32(hwnd
,cmd
);
637 /***********************************************************************
638 * ShowWindow (USER.42)
640 BOOL32
ShowWindow32( HWND32 hwnd
, INT32 cmd
)
642 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
643 BOOL32 wasVisible
, showFlag
;
646 short x
= 0, y
= 0, cx
= 0, cy
= 0;
648 if (!wndPtr
) return FALSE
;
650 dprintf_win(stddeb
,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd
, cmd
);
652 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
657 if (!wasVisible
) return FALSE
;
658 swpflags
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
659 SWP_NOACTIVATE
| SWP_NOZORDER
;
662 case SW_SHOWMINNOACTIVE
:
663 swpflags
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
665 case SW_SHOWMINIMIZED
:
666 swpflags
|= SWP_SHOWWINDOW
;
669 swpflags
|= SWP_FRAMECHANGED
;
670 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
672 if( HOOK_CallHooks16( WH_CBT
, HCBT_MINMAX
, hwnd
, cmd
) )
675 if (wndPtr
->dwStyle
& WS_MAXIMIZE
)
677 wndPtr
->flags
|= WIN_RESTORE_MAX
;
678 wndPtr
->dwStyle
&= ~WS_MAXIMIZE
;
682 wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
683 wndPtr
->rectNormal
= wndPtr
->rectWindow
;
685 wndPtr
->dwStyle
|= WS_MINIMIZE
;
686 WINPOS_FindIconPos( hwnd
);
687 x
= wndPtr
->ptIconPos
.x
;
688 y
= wndPtr
->ptIconPos
.y
;
689 cx
= SYSMETRICS_CXICON
;
690 cy
= SYSMETRICS_CYICON
;
691 swpflags
|= SWP_NOCOPYBITS
;
693 else swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
696 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE: */
697 swpflags
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
698 if (!(wndPtr
->dwStyle
& WS_MAXIMIZE
))
700 if( HOOK_CallHooks16( WH_CBT
, HCBT_MINMAX
, hwnd
, cmd
) )
703 /* Store the current position and find the maximized size */
704 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
705 wndPtr
->rectNormal
= wndPtr
->rectWindow
;
707 NC_GetMinMaxInfo( wndPtr
, &maxSize
,
708 &wndPtr
->ptMaxPos
, NULL
, NULL
);
709 x
= wndPtr
->ptMaxPos
.x
;
710 y
= wndPtr
->ptMaxPos
.y
;
712 if( wndPtr
->dwStyle
& WS_MINIMIZE
)
713 if( !SendMessage32A( hwnd
, WM_QUERYOPEN
, 0, 0L ) )
715 swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
718 else swpflags
|= SWP_NOCOPYBITS
;
722 wndPtr
->dwStyle
&= ~WS_MINIMIZE
;
723 wndPtr
->dwStyle
|= WS_MAXIMIZE
;
725 else swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
729 swpflags
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
732 swpflags
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
735 case SW_SHOWNOACTIVATE
:
736 swpflags
|= SWP_NOZORDER
;
737 if (GetActiveWindow32()) swpflags
|= SWP_NOACTIVATE
;
739 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
740 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
742 swpflags
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
744 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
746 if( HOOK_CallHooks16( WH_CBT
, HCBT_MINMAX
, hwnd
, cmd
) )
749 if( !SendMessage16( hwnd
, WM_QUERYOPEN
, 0, 0L) )
751 swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
754 wndPtr
->ptIconPos
.x
= wndPtr
->rectWindow
.left
;
755 wndPtr
->ptIconPos
.y
= wndPtr
->rectWindow
.top
;
756 wndPtr
->dwStyle
&= ~WS_MINIMIZE
;
757 if (wndPtr
->flags
& WIN_RESTORE_MAX
)
759 /* Restore to maximized position */
760 NC_GetMinMaxInfo( wndPtr
, &maxSize
, &wndPtr
->ptMaxPos
,
762 x
= wndPtr
->ptMaxPos
.x
;
763 y
= wndPtr
->ptMaxPos
.y
;
766 wndPtr
->dwStyle
|= WS_MAXIMIZE
;
768 else /* Restore to normal position */
770 x
= wndPtr
->rectNormal
.left
;
771 y
= wndPtr
->rectNormal
.top
;
772 cx
= wndPtr
->rectNormal
.right
- wndPtr
->rectNormal
.left
;
773 cy
= wndPtr
->rectNormal
.bottom
- wndPtr
->rectNormal
.top
;
775 swpflags
|= SWP_NOCOPYBITS
;
777 else if (wndPtr
->dwStyle
& WS_MAXIMIZE
)
779 if( HOOK_CallHooks16( WH_CBT
, HCBT_MINMAX
, hwnd
, cmd
) )
782 wndPtr
->ptMaxPos
.x
= wndPtr
->rectWindow
.left
;
783 wndPtr
->ptMaxPos
.y
= wndPtr
->rectWindow
.top
;
784 wndPtr
->dwStyle
&= ~WS_MAXIMIZE
;
785 x
= wndPtr
->rectNormal
.left
;
786 y
= wndPtr
->rectNormal
.top
;
787 cx
= wndPtr
->rectNormal
.right
- wndPtr
->rectNormal
.left
;
788 cy
= wndPtr
->rectNormal
.bottom
- wndPtr
->rectNormal
.top
;
790 else swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
794 showFlag
= (cmd
!= SW_HIDE
);
795 if (showFlag
!= wasVisible
)
797 SendMessage16( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
798 if (!IsWindow32( hwnd
)) return wasVisible
;
801 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
802 !IsWindowVisible32( wndPtr
->parent
->hwndSelf
) &&
803 (swpflags
& SWP_NOSIZE
) && (swpflags
& SWP_NOMOVE
))
805 /* Don't call SetWindowPos32() on invisible child windows */
806 if (cmd
== SW_HIDE
) wndPtr
->dwStyle
&= ~WS_VISIBLE
;
807 else wndPtr
->dwStyle
|= WS_VISIBLE
;
811 /* We can't activate a child window */
812 if (wndPtr
->dwStyle
& WS_CHILD
)
813 swpflags
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
814 SetWindowPos32( hwnd
, HWND_TOP
, x
, y
, cx
, cy
, swpflags
);
815 if (!IsWindow32( hwnd
)) return wasVisible
;
818 if (wndPtr
->flags
& WIN_NEED_SIZE
)
820 /* should happen only in CreateWindowEx() */
821 int wParam
= SIZE_RESTORED
;
823 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
824 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
825 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
826 SendMessage16( hwnd
, WM_SIZE
, wParam
,
827 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
828 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
829 SendMessage16( hwnd
, WM_MOVE
, 0,
830 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
837 /***********************************************************************
838 * GetInternalWindowPos16 (USER.460)
840 UINT16
GetInternalWindowPos16( HWND16 hwnd
, LPRECT16 rectWnd
, LPPOINT16 ptIcon
)
842 WINDOWPLACEMENT16 wndpl
;
843 if (!GetWindowPlacement16( hwnd
, &wndpl
)) return 0;
844 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
845 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
846 return wndpl
.showCmd
;
850 /***********************************************************************
851 * GetInternalWindowPos32 (USER32.244)
853 UINT32
GetInternalWindowPos32( HWND32 hwnd
, LPRECT32 rectWnd
, LPPOINT32 ptIcon
)
855 WINDOWPLACEMENT32 wndpl
;
856 if (!GetWindowPlacement32( hwnd
, &wndpl
)) return 0;
857 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
858 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
859 return wndpl
.showCmd
;
863 /***********************************************************************
864 * SetInternalWindowPos16 (USER.461)
866 void SetInternalWindowPos16( HWND16 hwnd
, UINT16 showCmd
,
867 LPRECT16 rect
, LPPOINT16 pt
)
869 WINDOWPLACEMENT16 wndpl
;
870 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
872 wndpl
.length
= sizeof(wndpl
);
873 wndpl
.flags
= (pt
!= NULL
) ? WPF_SETMINPOSITION
: 0;
874 wndpl
.showCmd
= showCmd
;
875 if (pt
) wndpl
.ptMinPosition
= *pt
;
876 wndpl
.rcNormalPosition
= (rect
!= NULL
) ? *rect
: wndPtr
->rectNormal
;
877 wndpl
.ptMaxPosition
= wndPtr
->ptMaxPos
;
878 SetWindowPlacement16( hwnd
, &wndpl
);
882 /***********************************************************************
883 * SetInternalWindowPos32 (USER32.482)
885 void SetInternalWindowPos32( HWND32 hwnd
, UINT32 showCmd
,
886 LPRECT32 rect
, LPPOINT32 pt
)
888 WINDOWPLACEMENT32 wndpl
;
889 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
891 wndpl
.length
= sizeof(wndpl
);
892 wndpl
.flags
= (pt
!= NULL
) ? WPF_SETMINPOSITION
: 0;
893 wndpl
.showCmd
= showCmd
;
894 if (pt
) wndpl
.ptMinPosition
= *pt
;
895 if (rect
) wndpl
.rcNormalPosition
= *rect
;
896 else CONV_RECT16TO32( &wndPtr
->rectNormal
, &wndpl
.rcNormalPosition
);
897 CONV_POINT16TO32( &wndPtr
->ptMaxPos
, &wndpl
.ptMaxPosition
);
898 SetWindowPlacement32( hwnd
, &wndpl
);
902 /***********************************************************************
903 * GetWindowPlacement16 (USER.370)
905 BOOL16
GetWindowPlacement16( HWND16 hwnd
, WINDOWPLACEMENT16
*wndpl
)
907 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
908 if (!wndPtr
) return FALSE
;
910 wndpl
->length
= sizeof(*wndpl
);
912 wndpl
->showCmd
= IsZoomed16(hwnd
) ? SW_SHOWMAXIMIZED
:
913 (IsIconic16(hwnd
) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
);
914 wndpl
->ptMinPosition
= wndPtr
->ptIconPos
;
915 wndpl
->ptMaxPosition
= wndPtr
->ptMaxPos
;
916 wndpl
->rcNormalPosition
= wndPtr
->rectNormal
;
921 /***********************************************************************
922 * GetWindowPlacement32 (USER32.306)
924 BOOL32
GetWindowPlacement32( HWND32 hwnd
, WINDOWPLACEMENT32
*wndpl
)
926 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
927 if (!wndPtr
) return FALSE
;
929 wndpl
->length
= sizeof(*wndpl
);
931 wndpl
->showCmd
= IsZoomed32(hwnd
) ? SW_SHOWMAXIMIZED
:
932 (IsIconic32(hwnd
) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
);
933 CONV_POINT16TO32( &wndPtr
->ptIconPos
, &wndpl
->ptMinPosition
);
934 CONV_POINT16TO32( &wndPtr
->ptMaxPos
, &wndpl
->ptMaxPosition
);
935 CONV_RECT16TO32( &wndPtr
->rectNormal
, &wndpl
->rcNormalPosition
);
940 /***********************************************************************
941 * SetWindowPlacement16 (USER.371)
943 BOOL16
SetWindowPlacement16( HWND16 hwnd
, const WINDOWPLACEMENT16
*wndpl
)
945 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
946 if (!wndPtr
) return FALSE
;
948 if (wndpl
->flags
& WPF_SETMINPOSITION
)
949 wndPtr
->ptIconPos
= wndpl
->ptMinPosition
;
950 if ((wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) &&
951 (wndpl
->showCmd
== SW_SHOWMINIMIZED
)) wndPtr
->flags
|= WIN_RESTORE_MAX
;
952 wndPtr
->ptMaxPos
= wndpl
->ptMaxPosition
;
953 wndPtr
->rectNormal
= wndpl
->rcNormalPosition
;
954 ShowWindow16( hwnd
, wndpl
->showCmd
);
959 /***********************************************************************
960 * SetWindowPlacement32 (USER32.518)
962 BOOL32
SetWindowPlacement32( HWND32 hwnd
, const WINDOWPLACEMENT32
*wndpl
)
964 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
965 if (!wndPtr
) return FALSE
;
967 if (wndpl
->flags
& WPF_SETMINPOSITION
)
968 CONV_POINT32TO16( &wndpl
->ptMinPosition
, &wndPtr
->ptIconPos
);
969 if ((wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) &&
970 (wndpl
->showCmd
== SW_SHOWMINIMIZED
)) wndPtr
->flags
|= WIN_RESTORE_MAX
;
971 CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &wndPtr
->ptMaxPos
);
972 CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &wndPtr
->rectNormal
);
973 ShowWindow32( hwnd
, wndpl
->showCmd
);
978 /***********************************************************************
979 * WINPOS_ForceXWindowRaise
981 * Raise a window on top of the X stacking order, while preserving
982 * the correct Windows Z order.
984 static void WINPOS_ForceXWindowRaise( WND
* pWnd
)
986 XWindowChanges winChanges
;
989 /* Raise all windows up to pWnd according to their Z order.
990 * (it would be easier with sibling-related Below but it doesn't
991 * work very well with SGI mwm for instance)
993 winChanges
.stack_mode
= Above
;
996 if (pWnd
->window
) XReconfigureWMWindow( display
, pWnd
->window
, 0,
997 CWStackMode
, &winChanges
);
998 wndPrev
= WIN_GetDesktop()->child
;
999 if (wndPrev
== pWnd
) break;
1000 while (wndPrev
&& (wndPrev
->next
!= pWnd
)) wndPrev
= wndPrev
->next
;
1006 /*******************************************************************
1007 * WINPOS_SetActiveWindow
1009 * back-end to SetActiveWindow
1011 BOOL32
WINPOS_SetActiveWindow( HWND32 hWnd
, BOOL32 fMouse
, BOOL32 fChangeFocus
)
1013 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1014 WND
*wndTemp
= WIN_FindWndPtr(hwndActive
);
1015 CBTACTIVATESTRUCT16
*cbtStruct
;
1017 HQUEUE16 hOldActiveQueue
= (pActiveQueue
)?pActiveQueue
->self
:0;
1018 HQUEUE16 hNewActiveQueue
;
1020 /* paranoid checks */
1021 if( hWnd
== GetDesktopWindow32() || hWnd
== hwndActive
)
1024 /* if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
1029 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1031 dprintf_win(stddeb
,"WINPOS_ActivateWindow: no current active window.\n");
1033 /* call CBT hook chain */
1034 if ((cbtStruct
= SEGPTR_NEW(CBTACTIVATESTRUCT16
)))
1037 cbtStruct
->fMouse
= fMouse
;
1038 cbtStruct
->hWndActive
= hwndActive
;
1039 wRet
= HOOK_CallHooks16( WH_CBT
, HCBT_ACTIVATE
, (WPARAM16
)hWnd
,
1040 (LPARAM
)SEGPTR_GET(cbtStruct
) );
1041 SEGPTR_FREE(cbtStruct
);
1042 if (wRet
) return wRet
;
1045 /* set prev active wnd to current active wnd and send notification */
1046 if ((hwndPrevActive
= hwndActive
) && IsWindow32(hwndPrevActive
))
1048 if (!SendMessage16( hwndPrevActive
, WM_NCACTIVATE
, FALSE
, 0 ))
1050 if (GetSysModalWindow16() != hWnd
) return 0;
1051 /* disregard refusal if hWnd is sysmodal */
1055 SendMessage32A( hwndPrevActive
, WM_ACTIVATE
,
1056 MAKEWPARAM( WA_INACTIVE
, wIconized
),
1059 /* FIXME: must be SendMessage16() because 32A doesn't do
1060 * intertask at this time */
1061 SendMessage16( hwndPrevActive
, WM_ACTIVATE
, WA_INACTIVE
,
1062 MAKELPARAM( (HWND16
)hWnd
, wIconized
) );
1065 /* check if something happened during message processing */
1066 if( hwndPrevActive
!= hwndActive
) return 0;
1069 /* set active wnd */
1072 /* send palette messages */
1073 if (hWnd
&& SendMessage16( hWnd
, WM_QUERYNEWPALETTE
, 0, 0L))
1074 SendMessage16((HWND16
)-1, WM_PALETTEISCHANGING
, (WPARAM16
)hWnd
, 0L );
1076 /* if prev wnd is minimized redraw icon title
1077 if( hwndPrevActive )
1079 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
1081 if(wndTemp->dwStyle & WS_MINIMIZE)
1082 RedrawIconTitle(hwndPrevActive);
1086 /* managed windows will get ConfigureNotify event */
1087 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
) && !(wndPtr
->flags
& WIN_MANAGED
))
1089 /* check Z-order and bring hWnd to the top */
1090 for (wndTemp
= WIN_GetDesktop()->child
; wndTemp
; wndTemp
= wndTemp
->next
)
1091 if (wndTemp
->dwStyle
& WS_VISIBLE
) break;
1093 if( wndTemp
!= wndPtr
)
1094 SetWindowPos32(hWnd
, HWND_TOP
, 0,0,0,0,
1095 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1096 if (!IsWindow32(hWnd
)) return 0;
1099 hNewActiveQueue
= wndPtr
? wndPtr
->hmemTaskQ
: 0;
1101 /* send WM_ACTIVATEAPP if necessary */
1102 if (hOldActiveQueue
!= hNewActiveQueue
)
1104 WND
**list
, **ppWnd
;
1106 if ((list
= WIN_BuildWinArray( WIN_GetDesktop() )))
1108 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1110 if (!IsWindow32( (*ppWnd
)->hwndSelf
)) continue;
1112 if ((*ppWnd
)->hmemTaskQ
== hOldActiveQueue
)
1113 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ACTIVATEAPP
,
1114 0, QUEUE_GetQueueTask(hNewActiveQueue
) );
1116 HeapFree( SystemHeap
, 0, list
);
1119 pActiveQueue
= (hNewActiveQueue
)
1120 ? (MESSAGEQUEUE
*) GlobalLock16(hNewActiveQueue
) : NULL
;
1122 if ((list
= WIN_BuildWinArray( WIN_GetDesktop() )))
1124 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1126 if (!IsWindow32( (*ppWnd
)->hwndSelf
)) continue;
1128 if ((*ppWnd
)->hmemTaskQ
== hNewActiveQueue
)
1129 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ACTIVATEAPP
,
1130 1, QUEUE_GetQueueTask( hOldActiveQueue
) );
1132 HeapFree( SystemHeap
, 0, list
);
1134 if (!IsWindow32(hWnd
)) return 0;
1139 /* walk up to the first unowned window */
1141 while (wndTemp
->owner
) wndTemp
= wndTemp
->owner
;
1142 /* and set last active owned popup */
1143 wndTemp
->hwndLastActive
= hWnd
;
1145 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1146 SendMessage16( hWnd
, WM_NCACTIVATE
, TRUE
, 0 );
1148 SendMessage32A( hWnd
, WM_ACTIVATE
,
1149 MAKEWPARAM( (fMouse
) ? WA_CLICKACTIVE
: WA_ACTIVE
, wIconized
),
1150 (LPARAM
)hwndPrevActive
);
1152 SendMessage16(hWnd
, WM_ACTIVATE
, (fMouse
) ? WA_CLICKACTIVE
: WA_ACTIVE
,
1153 MAKELPARAM( (HWND16
)hwndPrevActive
, wIconized
) );
1156 if( !IsWindow32(hWnd
) ) return 0;
1159 /* change focus if possible */
1160 if( fChangeFocus
&& GetFocus32() )
1161 if( WIN_GetTopParent(GetFocus32()) != hwndActive
)
1162 FOCUS_SwitchFocus( GetFocus32(),
1163 (wndPtr
->dwStyle
& WS_MINIMIZE
)? 0: hwndActive
);
1165 if( !hwndPrevActive
&& wndPtr
&&
1166 wndPtr
->window
&& !(wndPtr
->flags
& WIN_MANAGED
) )
1167 WINPOS_ForceXWindowRaise(wndPtr
);
1169 /* if active wnd is minimized redraw icon title
1172 wndPtr = WIN_FindWndPtr(hwndActive);
1173 if(wndPtr->dwStyle & WS_MINIMIZE)
1174 RedrawIconTitle(hwndActive);
1177 return (hWnd
== hwndActive
);
1180 /*******************************************************************
1181 * WINPOS_ActivateOtherWindow
1183 * DestroyWindow() helper. pWnd must be a top-level window.
1185 BOOL32
WINPOS_ActivateOtherWindow(WND
* pWnd
)
1190 if( pWnd
->hwndSelf
== hwndPrevActive
)
1193 if( hwndActive
!= pWnd
->hwndSelf
&&
1194 ( hwndActive
|| QUEUE_IsDoomedQueue(pWnd
->hmemTaskQ
)) )
1197 if( pWnd
->dwStyle
& WS_POPUP
&&
1198 WINPOS_IsGoodEnough( pWnd
->owner
) ) pWndTo
= pWnd
->owner
;
1201 WND
* pWndPtr
= pWnd
;
1203 pWndTo
= WIN_FindWndPtr(hwndPrevActive
);
1205 while( !WINPOS_IsGoodEnough(pWndTo
) )
1207 /* by now owned windows should've been taken care of */
1209 pWndTo
= pWndPtr
->next
;
1211 if( !pWndTo
) return 0;
1215 bRet
= WINPOS_SetActiveWindow( pWndTo
->hwndSelf
, FALSE
, TRUE
);
1217 /* switch desktop queue to current active */
1218 if( pWndTo
->parent
== WIN_GetDesktop())
1219 WIN_GetDesktop()->hmemTaskQ
= pWndTo
->hmemTaskQ
;
1225 /*******************************************************************
1226 * WINPOS_ChangeActiveWindow
1229 BOOL32
WINPOS_ChangeActiveWindow( HWND32 hWnd
, BOOL32 mouseMsg
)
1231 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1233 if (!hWnd
) return WINPOS_SetActiveWindow( 0, mouseMsg
, TRUE
);
1235 if( !wndPtr
) return FALSE
;
1237 /* child windows get WM_CHILDACTIVATE message */
1238 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1239 return SendMessage16(hWnd
, WM_CHILDACTIVATE
, 0, 0L);
1241 /* owned popups imply owner activation - not sure */
1242 if ((wndPtr
->dwStyle
& WS_POPUP
) && wndPtr
->owner
&&
1243 !(wndPtr
->owner
->dwStyle
& WS_DISABLED
))
1245 if (!(wndPtr
= wndPtr
->owner
)) return FALSE
;
1246 hWnd
= wndPtr
->hwndSelf
;
1249 if( hWnd
== hwndActive
) return FALSE
;
1251 if( !WINPOS_SetActiveWindow(hWnd
,mouseMsg
,TRUE
) )
1254 /* switch desktop queue to current active */
1255 if( wndPtr
->parent
== WIN_GetDesktop())
1256 WIN_GetDesktop()->hmemTaskQ
= wndPtr
->hmemTaskQ
;
1262 /***********************************************************************
1263 * WINPOS_SendNCCalcSize
1265 * Send a WM_NCCALCSIZE message to a window.
1266 * All parameters are read-only except newClientRect.
1267 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1268 * when calcValidRect is TRUE.
1270 LONG
WINPOS_SendNCCalcSize( HWND32 hwnd
, BOOL32 calcValidRect
,
1271 RECT16
*newWindowRect
, RECT16
*oldWindowRect
,
1272 RECT16
*oldClientRect
, SEGPTR winpos
,
1273 RECT16
*newClientRect
)
1275 NCCALCSIZE_PARAMS16
*params
;
1278 if (!(params
= SEGPTR_NEW(NCCALCSIZE_PARAMS16
))) return 0;
1279 params
->rgrc
[0] = *newWindowRect
;
1282 params
->rgrc
[1] = *oldWindowRect
;
1283 params
->rgrc
[2] = *oldClientRect
;
1284 params
->lppos
= winpos
;
1286 result
= SendMessage16( hwnd
, WM_NCCALCSIZE
, calcValidRect
,
1287 (LPARAM
)SEGPTR_GET( params
) );
1288 dprintf_win( stddeb
, "WINPOS_SendNCCalcSize: %d,%d-%d,%d\n",
1289 params
->rgrc
[0].left
, params
->rgrc
[0].top
,
1290 params
->rgrc
[0].right
, params
->rgrc
[0].bottom
);
1291 *newClientRect
= params
->rgrc
[0];
1292 SEGPTR_FREE(params
);
1297 /***********************************************************************
1298 * WINPOS_HandleWindowPosChanging16
1300 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1302 LONG
WINPOS_HandleWindowPosChanging16( WND
*wndPtr
, WINDOWPOS16
*winpos
)
1305 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1306 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
1307 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) == 0))
1309 NC_GetMinMaxInfo( wndPtr
, &maxSize
, NULL
, NULL
, NULL
);
1310 winpos
->cx
= MIN( winpos
->cx
, maxSize
.x
);
1311 winpos
->cy
= MIN( winpos
->cy
, maxSize
.y
);
1317 /***********************************************************************
1318 * WINPOS_HandleWindowPosChanging32
1320 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1322 LONG
WINPOS_HandleWindowPosChanging32( WND
*wndPtr
, WINDOWPOS32
*winpos
)
1325 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1326 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
1327 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) == 0))
1329 NC_GetMinMaxInfo( wndPtr
, &maxSize
, NULL
, NULL
, NULL
);
1330 winpos
->cx
= MIN( winpos
->cx
, maxSize
.x
);
1331 winpos
->cy
= MIN( winpos
->cy
, maxSize
.y
);
1337 /***********************************************************************
1338 * WINPOS_MoveWindowZOrder
1340 * Move a window in Z order, invalidating everything that needs it.
1341 * Only necessary for windows without associated X window.
1343 static void WINPOS_MoveWindowZOrder( HWND32 hwnd
, HWND32 hwndAfter
)
1346 WND
*pWndAfter
, *pWndCur
, *wndPtr
= WIN_FindWndPtr( hwnd
);
1348 /* We have two possible cases:
1349 * - The window is moving up: we have to invalidate all areas
1350 * of the window that were covered by other windows
1351 * - The window is moving down: we have to invalidate areas
1352 * of other windows covered by this one.
1355 if (hwndAfter
== HWND_TOP
)
1359 else if (hwndAfter
== HWND_BOTTOM
)
1361 if (!wndPtr
->next
) return; /* Already at the bottom */
1366 if (!(pWndAfter
= WIN_FindWndPtr( hwndAfter
))) return;
1367 if (wndPtr
->next
== pWndAfter
) return; /* Already placed right */
1369 /* Determine which window we encounter first in Z-order */
1370 pWndCur
= wndPtr
->parent
->child
;
1371 while ((pWndCur
!= wndPtr
) && (pWndCur
!= pWndAfter
))
1372 pWndCur
= pWndCur
->next
;
1373 movingUp
= (pWndCur
== pWndAfter
);
1378 WND
*pWndPrevAfter
= wndPtr
->next
;
1379 WIN_UnlinkWindow( hwnd
);
1380 WIN_LinkWindow( hwnd
, hwndAfter
);
1381 pWndCur
= wndPtr
->next
;
1382 while (pWndCur
!= pWndPrevAfter
)
1384 RECT32 rect
= { pWndCur
->rectWindow
.left
,
1385 pWndCur
->rectWindow
.top
,
1386 pWndCur
->rectWindow
.right
,
1387 pWndCur
->rectWindow
.bottom
};
1388 OffsetRect32( &rect
, -wndPtr
->rectClient
.left
,
1389 -wndPtr
->rectClient
.top
);
1390 PAINT_RedrawWindow( hwnd
, &rect
, 0, RDW_INVALIDATE
| RDW_ALLCHILDREN
|
1391 RDW_FRAME
| RDW_ERASE
, 0 );
1392 pWndCur
= pWndCur
->next
;
1395 else /* Moving down */
1397 pWndCur
= wndPtr
->next
;
1398 WIN_UnlinkWindow( hwnd
);
1399 WIN_LinkWindow( hwnd
, hwndAfter
);
1400 while (pWndCur
!= wndPtr
)
1402 RECT32 rect
= { pWndCur
->rectWindow
.left
,
1403 pWndCur
->rectWindow
.top
,
1404 pWndCur
->rectWindow
.right
,
1405 pWndCur
->rectWindow
.bottom
};
1406 OffsetRect32( &rect
, -pWndCur
->rectClient
.left
,
1407 -pWndCur
->rectClient
.top
);
1408 PAINT_RedrawWindow( pWndCur
->hwndSelf
, &rect
, 0, RDW_INVALIDATE
|
1409 RDW_ALLCHILDREN
| RDW_FRAME
| RDW_ERASE
, 0 );
1410 pWndCur
= pWndCur
->next
;
1415 /***********************************************************************
1416 * WINPOS_ReorderOwnedPopups
1418 * fix Z order taking into account owned popups -
1419 * basically we need to maintain them above owner window
1421 HWND32
WINPOS_ReorderOwnedPopups(HWND32 hwndInsertAfter
,WND
* wndPtr
,WORD flags
)
1423 WND
* w
= WIN_GetDesktop()->child
;
1425 if( wndPtr
->dwStyle
& WS_POPUP
&& wndPtr
->owner
)
1427 /* implement "local z-order" between the top and owner window */
1429 HWND32 hwndLocalPrev
= HWND_TOP
;
1431 if( hwndInsertAfter
!= HWND_TOP
)
1433 while( w
!= wndPtr
->owner
)
1435 if (w
!= wndPtr
) hwndLocalPrev
= w
->hwndSelf
;
1436 if( hwndLocalPrev
== hwndInsertAfter
) break;
1439 hwndInsertAfter
= hwndLocalPrev
;
1443 else if( wndPtr
->dwStyle
& WS_CHILD
) return hwndInsertAfter
;
1445 w
= WIN_GetDesktop()->child
;
1448 if( w
== wndPtr
) break;
1450 if( w
->dwStyle
& WS_POPUP
&& w
->owner
== wndPtr
)
1452 SetWindowPos32(w
->hwndSelf
, hwndInsertAfter
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1453 SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1454 hwndInsertAfter
= w
->hwndSelf
;
1459 return hwndInsertAfter
;
1462 /***********************************************************************
1463 * WINPOS_SizeMoveClean
1465 * Make window look nice without excessive repainting
1469 * visible regions are in window coordinates
1470 * update regions are in window client coordinates
1471 * client and window rectangles are in parent client coordinates
1473 static UINT32
WINPOS_SizeMoveClean(WND
* Wnd
, HRGN32 oldVisRgn
, LPRECT16 lpOldWndRect
, LPRECT16 lpOldClientRect
, UINT32 uFlags
)
1475 HRGN32 newVisRgn
= DCE_GetVisRgn(Wnd
->hwndSelf
,DCX_WINDOW
| DCX_CLIPSIBLINGS
);
1476 HRGN32 dirtyRgn
= CreateRectRgn32(0,0,0,0);
1479 dprintf_win(stddeb
,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1480 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1481 Wnd
->rectWindow
.left
, Wnd
->rectWindow
.top
, Wnd
->rectWindow
.right
, Wnd
->rectWindow
.bottom
,
1482 lpOldWndRect
->left
, lpOldWndRect
->top
, lpOldWndRect
->right
, lpOldWndRect
->bottom
,
1483 Wnd
->rectClient
.left
,Wnd
->rectClient
.top
,Wnd
->rectClient
.right
,Wnd
->rectClient
.bottom
,
1484 lpOldClientRect
->left
,lpOldClientRect
->top
,lpOldClientRect
->right
,lpOldClientRect
->bottom
);
1486 if( (lpOldWndRect
->right
- lpOldWndRect
->left
) != (Wnd
->rectWindow
.right
- Wnd
->rectWindow
.left
) ||
1487 (lpOldWndRect
->bottom
- lpOldWndRect
->top
) != (Wnd
->rectWindow
.bottom
- Wnd
->rectWindow
.top
) )
1488 uFlags
|= SMC_DRAWFRAME
;
1490 CombineRgn32( dirtyRgn
, newVisRgn
, 0, RGN_COPY
);
1492 if( !(uFlags
& SMC_NOCOPY
) )
1493 CombineRgn32( newVisRgn
, newVisRgn
, oldVisRgn
, RGN_AND
);
1495 /* map regions to the parent client area */
1497 OffsetRgn32( dirtyRgn
, Wnd
->rectWindow
.left
, Wnd
->rectWindow
.top
);
1498 OffsetRgn32( oldVisRgn
, lpOldWndRect
->left
, lpOldWndRect
->top
);
1500 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1502 other
= CombineRgn32(dirtyRgn
, oldVisRgn
, dirtyRgn
, RGN_DIFF
);
1504 /* map visible region to the Wnd client area */
1506 OffsetRgn32( newVisRgn
, Wnd
->rectWindow
.left
- Wnd
->rectClient
.left
,
1507 Wnd
->rectWindow
.top
- Wnd
->rectClient
.top
);
1509 /* substract previously invalidated region from the Wnd visible region */
1511 my
= (Wnd
->hrgnUpdate
> 1) ? CombineRgn32( newVisRgn
, newVisRgn
,
1512 Wnd
->hrgnUpdate
, RGN_DIFF
)
1515 if( uFlags
& SMC_NOCOPY
) /* invalidate Wnd visible region */
1517 if (my
!= NULLREGION
)
1518 PAINT_RedrawWindow( Wnd
->hwndSelf
, NULL
, newVisRgn
, RDW_INVALIDATE
|
1519 RDW_FRAME
| RDW_ALLCHILDREN
| RDW_ERASE
, RDW_C_USEHRGN
);
1520 else if(uFlags
& SMC_DRAWFRAME
)
1521 Wnd
->flags
|= WIN_NEEDS_NCPAINT
;
1523 else /* bitblt old client area */
1528 int xfrom
,yfrom
,xto
,yto
,width
,height
;
1530 if( uFlags
& SMC_DRAWFRAME
)
1532 /* copy only client area, frame will be redrawn anyway */
1534 xfrom
= lpOldClientRect
->left
; yfrom
= lpOldClientRect
->top
;
1535 xto
= Wnd
->rectClient
.left
; yto
= Wnd
->rectClient
.top
;
1536 width
= lpOldClientRect
->right
- xfrom
; height
= lpOldClientRect
->bottom
- yfrom
;
1537 updateRgn
= CreateRectRgn32( 0, 0, width
, height
);
1538 CombineRgn32( newVisRgn
, newVisRgn
, updateRgn
, RGN_AND
);
1539 SetRectRgn32( updateRgn
, 0, 0, Wnd
->rectClient
.right
- xto
,
1540 Wnd
->rectClient
.bottom
- yto
);
1544 xfrom
= lpOldWndRect
->left
; yfrom
= lpOldWndRect
->top
;
1545 xto
= Wnd
->rectWindow
.left
; yto
= Wnd
->rectWindow
.top
;
1546 width
= lpOldWndRect
->right
- xfrom
; height
= lpOldWndRect
->bottom
- yfrom
;
1547 updateRgn
= CreateRectRgn32( xto
- Wnd
->rectClient
.left
,
1548 yto
- Wnd
->rectClient
.top
,
1549 Wnd
->rectWindow
.right
- Wnd
->rectClient
.left
,
1550 Wnd
->rectWindow
.bottom
- Wnd
->rectClient
.top
);
1553 CombineRgn32( newVisRgn
, newVisRgn
, updateRgn
, RGN_AND
);
1555 /* substract new visRgn from target rect to get a region that won't be copied */
1557 update
= CombineRgn32( updateRgn
, updateRgn
, newVisRgn
, RGN_DIFF
);
1559 /* Blt valid bits using parent window DC */
1561 if( my
!= NULLREGION
&& (xfrom
!= xto
|| yfrom
!= yto
) )
1564 /* compute clipping region in parent client coordinates */
1566 OffsetRgn32( newVisRgn
, Wnd
->rectClient
.left
, Wnd
->rectClient
.top
);
1567 CombineRgn32( oldVisRgn
, oldVisRgn
, newVisRgn
, RGN_OR
);
1569 hDC
= GetDCEx32( Wnd
->parent
->hwndSelf
, oldVisRgn
,
1570 DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
|
1571 DCX_CACHE
| DCX_CLIPSIBLINGS
);
1573 BitBlt32( hDC
, xto
, yto
, width
, height
, hDC
, xfrom
, yfrom
, SRCCOPY
);
1574 ReleaseDC32( Wnd
->parent
->hwndSelf
, hDC
);
1577 if( update
!= NULLREGION
)
1578 PAINT_RedrawWindow( Wnd
->hwndSelf
, NULL
, updateRgn
, RDW_INVALIDATE
|
1579 RDW_FRAME
| RDW_ALLCHILDREN
| RDW_ERASE
, RDW_C_USEHRGN
);
1580 else if( uFlags
& SMC_DRAWFRAME
) Wnd
->flags
|= WIN_NEEDS_NCPAINT
;
1581 DeleteObject32( updateRgn
);
1584 /* erase uncovered areas */
1586 if( !(uFlags
& SMC_NOPARENTERASE
) && (other
!= NULLREGION
) )
1587 PAINT_RedrawWindow( Wnd
->parent
->hwndSelf
, NULL
, dirtyRgn
,
1588 RDW_INVALIDATE
| RDW_ALLCHILDREN
| RDW_ERASE
, RDW_C_USEHRGN
);
1589 DeleteObject32(dirtyRgn
);
1590 DeleteObject32(newVisRgn
);
1595 /***********************************************************************
1596 * WINPOS_FindDeskTopXWindow
1598 * Find the actual X window which needs be restacked.
1599 * Used by WINPOS_SetXWindowPos().
1601 static Window
WINPOS_FindDeskTopXWindow( WND
*wndPtr
)
1603 if (!(wndPtr
->flags
& WIN_MANAGED
))
1604 return wndPtr
->window
;
1607 Window window
, root
, parent
, *children
;
1609 window
= wndPtr
->window
;
1612 XQueryTree( display
, window
, &root
, &parent
,
1613 &children
, &nchildren
);
1622 /***********************************************************************
1623 * WINPOS_SetXWindowPos
1625 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1627 static void WINPOS_SetXWindowPos( WINDOWPOS16
*winpos
)
1629 XWindowChanges winChanges
;
1631 WND
*wndPtr
= WIN_FindWndPtr( winpos
->hwnd
);
1633 if (!(winpos
->flags
& SWP_NOSIZE
))
1635 winChanges
.width
= winpos
->cx
;
1636 winChanges
.height
= winpos
->cy
;
1637 changeMask
|= CWWidth
| CWHeight
;
1639 /* Tweak dialog window size hints */
1641 if ((wndPtr
->flags
& WIN_MANAGED
) &&
1642 (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
))
1644 XSizeHints
*size_hints
= XAllocSizeHints();
1648 long supplied_return
;
1650 XGetWMSizeHints( display
, wndPtr
->window
, size_hints
,
1651 &supplied_return
, XA_WM_NORMAL_HINTS
);
1652 size_hints
->min_width
= size_hints
->max_width
= winpos
->cx
;
1653 size_hints
->min_height
= size_hints
->max_height
= winpos
->cy
;
1654 XSetWMSizeHints( display
, wndPtr
->window
, size_hints
,
1655 XA_WM_NORMAL_HINTS
);
1660 if (!(winpos
->flags
& SWP_NOMOVE
))
1662 winChanges
.x
= winpos
->x
;
1663 winChanges
.y
= winpos
->y
;
1664 changeMask
|= CWX
| CWY
;
1666 if (!(winpos
->flags
& SWP_NOZORDER
))
1668 winChanges
.stack_mode
= Below
;
1669 changeMask
|= CWStackMode
;
1671 if (winpos
->hwndInsertAfter
== HWND_TOP
) winChanges
.stack_mode
= Above
;
1672 else if (winpos
->hwndInsertAfter
!= HWND_BOTTOM
)
1674 WND
* insertPtr
= WIN_FindWndPtr( winpos
->hwndInsertAfter
);
1677 stack
[0] = WINPOS_FindDeskTopXWindow( insertPtr
);
1678 stack
[1] = WINPOS_FindDeskTopXWindow( wndPtr
);
1680 /* for stupid window managers (i.e. all of them) */
1682 XRestackWindows(display
, stack
, 2);
1683 changeMask
&= ~CWStackMode
;
1686 if (!changeMask
) return;
1688 XReconfigureWMWindow( display
, wndPtr
->window
, 0, changeMask
, &winChanges
);
1692 /***********************************************************************
1693 * SetWindowPos (USER.232)
1695 BOOL16
SetWindowPos16( HWND16 hwnd
, HWND16 hwndInsertAfter
, INT16 x
, INT16 y
,
1696 INT16 cx
, INT16 cy
, WORD flags
)
1698 return SetWindowPos32(hwnd
,(INT32
)(INT16
)hwndInsertAfter
,x
,y
,cx
,cy
,flags
);
1701 /***********************************************************************
1702 * SetWindowPos (USER32.519)
1704 BOOL32
SetWindowPos32( HWND32 hwnd
, HWND32 hwndInsertAfter
, INT32 x
, INT32 y
,
1705 INT32 cx
, INT32 cy
, WORD flags
)
1707 WINDOWPOS16
*winpos
;
1709 RECT16 newWindowRect
, newClientRect
, oldWindowRect
;
1711 HWND32 tempInsertAfter
= 0;
1715 dprintf_win(stddeb
,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
1716 hwnd
, x
, y
, x
+cx
, y
+cy
, flags
);
1717 /* Check window handle */
1719 if (hwnd
== GetDesktopWindow32()) return FALSE
;
1720 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
1722 if (wndPtr
->dwStyle
& WS_VISIBLE
) flags
&= ~SWP_SHOWWINDOW
;
1725 uFlags
|= SMC_NOPARENTERASE
;
1726 flags
&= ~SWP_HIDEWINDOW
;
1727 if (!(flags
& SWP_SHOWWINDOW
)) flags
|= SWP_NOREDRAW
;
1730 /* Check for windows that may not be resized
1731 FIXME: this should be done only for Windows 3.0 programs
1732 if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
1733 flags |= SWP_NOSIZE | SWP_NOMOVE;
1735 /* Check dimensions */
1737 if (cx
<= 0) cx
= 1;
1738 if (cy
<= 0) cy
= 1;
1742 if (hwnd
== hwndActive
) flags
|= SWP_NOACTIVATE
; /* Already active */
1743 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== cx
) &&
1744 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== cy
))
1745 flags
|= SWP_NOSIZE
; /* Already the right size */
1746 if ((wndPtr
->rectWindow
.left
== x
) && (wndPtr
->rectWindow
.top
== y
))
1747 flags
|= SWP_NOMOVE
; /* Already the right position */
1749 /* Check hwndInsertAfter */
1751 if (!(flags
& (SWP_NOZORDER
| SWP_NOACTIVATE
)))
1753 /* Ignore TOPMOST flags when activating a window */
1754 /* _and_ moving it in Z order. */
1755 if ((hwndInsertAfter
== HWND_TOPMOST
) ||
1756 (hwndInsertAfter
== HWND_NOTOPMOST
))
1757 hwndInsertAfter
= HWND_TOP
;
1759 /* TOPMOST not supported yet */
1760 if ((hwndInsertAfter
== HWND_TOPMOST
) ||
1761 (hwndInsertAfter
== HWND_NOTOPMOST
)) hwndInsertAfter
= HWND_TOP
;
1763 /* hwndInsertAfter must be a sibling of the window */
1764 if ((hwndInsertAfter
!= HWND_TOP
) && (hwndInsertAfter
!= HWND_BOTTOM
))
1766 WND
* wnd
= WIN_FindWndPtr(hwndInsertAfter
);
1767 if( wnd
->parent
!= wndPtr
->parent
) return FALSE
;
1768 if( wnd
->next
== wndPtr
) flags
|= SWP_NOZORDER
;
1770 else if (!(wndPtr
->window
))
1771 /* FIXME: the following optimization is no good for "X-ed" windows */
1772 if (hwndInsertAfter
== HWND_TOP
)
1773 flags
|= ( wndPtr
->parent
->child
== wndPtr
)? SWP_NOZORDER
: 0;
1774 else /* HWND_BOTTOM */
1775 flags
|= ( wndPtr
->next
)? 0: SWP_NOZORDER
;
1777 /* Fill the WINDOWPOS structure */
1779 if (!(winpos
= SEGPTR_NEW(WINDOWPOS16
))) return FALSE
;
1780 winpos
->hwnd
= hwnd
;
1781 winpos
->hwndInsertAfter
= hwndInsertAfter
;
1786 winpos
->flags
= flags
;
1788 /* Send WM_WINDOWPOSCHANGING message */
1790 if (!(flags
& SWP_NOSENDCHANGING
))
1791 SendMessage16( hwnd
, WM_WINDOWPOSCHANGING
, 0,
1792 (LPARAM
)SEGPTR_GET(winpos
) );
1794 /* Calculate new position and size */
1796 newWindowRect
= wndPtr
->rectWindow
;
1797 newClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1798 : wndPtr
->rectClient
;
1800 if (!(winpos
->flags
& SWP_NOSIZE
))
1802 newWindowRect
.right
= newWindowRect
.left
+ winpos
->cx
;
1803 newWindowRect
.bottom
= newWindowRect
.top
+ winpos
->cy
;
1805 if (!(winpos
->flags
& SWP_NOMOVE
))
1807 newWindowRect
.left
= winpos
->x
;
1808 newWindowRect
.top
= winpos
->y
;
1809 newWindowRect
.right
+= winpos
->x
- wndPtr
->rectWindow
.left
;
1810 newWindowRect
.bottom
+= winpos
->y
- wndPtr
->rectWindow
.top
;
1812 OffsetRect16( &newClientRect
, winpos
->x
- wndPtr
->rectWindow
.left
,
1813 winpos
->y
- wndPtr
->rectWindow
.top
);
1816 winpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1818 /* Reposition window in Z order */
1820 if (!(winpos
->flags
& SWP_NOZORDER
))
1822 /* reorder owned popups if hwnd is top-level window
1824 if( wndPtr
->parent
== WIN_GetDesktop() )
1825 hwndInsertAfter
= WINPOS_ReorderOwnedPopups( hwndInsertAfter
,
1830 WIN_UnlinkWindow( winpos
->hwnd
);
1831 WIN_LinkWindow( winpos
->hwnd
, hwndInsertAfter
);
1833 else WINPOS_MoveWindowZOrder( winpos
->hwnd
, hwndInsertAfter
);
1836 if ( !wndPtr
->window
&& !(flags
& SWP_NOREDRAW
) &&
1837 (!(flags
& SWP_NOMOVE
) || !(flags
& SWP_NOSIZE
) || (flags
& SWP_FRAMECHANGED
)) )
1838 visRgn
= DCE_GetVisRgn(hwnd
, DCX_WINDOW
| DCX_CLIPSIBLINGS
);
1841 /* Send WM_NCCALCSIZE message to get new client area */
1842 if( (flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1844 result
= WINPOS_SendNCCalcSize( winpos
->hwnd
, TRUE
, &newWindowRect
,
1845 &wndPtr
->rectWindow
, &wndPtr
->rectClient
,
1846 SEGPTR_GET(winpos
), &newClientRect
);
1848 /* FIXME: WVR_ALIGNxxx */
1850 if( newClientRect
.left
!= wndPtr
->rectClient
.left
||
1851 newClientRect
.top
!= wndPtr
->rectClient
.top
)
1852 winpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1854 if( (newClientRect
.right
- newClientRect
.left
!=
1855 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
1856 (newClientRect
.bottom
- newClientRect
.top
!=
1857 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
1858 winpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1861 if( !(flags
& SWP_NOMOVE
) && (newClientRect
.left
!= wndPtr
->rectClient
.left
||
1862 newClientRect
.top
!= wndPtr
->rectClient
.top
) )
1863 winpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1865 /* Update active DCEs */
1867 if( !(flags
& SWP_NOZORDER
) || (flags
& SWP_HIDEWINDOW
) || (flags
& SWP_SHOWWINDOW
)
1868 || (memcmp(&newWindowRect
,&wndPtr
->rectWindow
,sizeof(RECT16
))
1869 && wndPtr
->dwStyle
& WS_VISIBLE
) )
1873 UnionRect16(&rect
,&newWindowRect
,&wndPtr
->rectWindow
);
1874 DCE_InvalidateDCE(wndPtr
->parent
, &rect
);
1877 /* change geometry */
1879 oldWindowRect
= wndPtr
->rectWindow
;
1883 RECT16 oldClientRect
= wndPtr
->rectClient
;
1885 tempInsertAfter
= winpos
->hwndInsertAfter
;
1887 winpos
->hwndInsertAfter
= hwndInsertAfter
;
1889 /* postpone geometry change */
1891 if( !(flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
)) )
1893 WINPOS_SetXWindowPos( winpos
);
1894 winpos
->hwndInsertAfter
= tempInsertAfter
;
1896 else uFlags
|= SMC_SETXPOS
;
1898 wndPtr
->rectWindow
= newWindowRect
;
1899 wndPtr
->rectClient
= newClientRect
;
1901 if( !(flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
)) )
1902 if( (oldClientRect
.left
- oldWindowRect
.left
!=
1903 newClientRect
.left
- newWindowRect
.left
) ||
1904 (oldClientRect
.top
- oldWindowRect
.top
!=
1905 newClientRect
.top
- newWindowRect
.top
) || winpos
->flags
& SWP_NOCOPYBITS
)
1907 PAINT_RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|
1908 RDW_ALLCHILDREN
| RDW_FRAME
| RDW_ERASE
, 0 );
1910 if( winpos
->flags
& SWP_FRAMECHANGED
)
1915 if( oldClientRect
.right
> newClientRect
.right
)
1917 rect
.left
= newClientRect
.right
; rect
.top
= newClientRect
.top
;
1918 rect
.right
= oldClientRect
.right
; rect
.bottom
= newClientRect
.bottom
;
1920 PAINT_RedrawWindow( wndPtr
->hwndSelf
, &rect
, 0,
1921 RDW_INVALIDATE
| RDW_FRAME
| RDW_ALLCHILDREN
, 0 );
1923 if( oldClientRect
.bottom
> newClientRect
.bottom
)
1925 rect
.left
= newClientRect
.left
; rect
.top
= newClientRect
.bottom
;
1926 rect
.right
= (wErase
)?oldClientRect
.right
:newClientRect
.right
;
1927 rect
.bottom
= oldClientRect
.bottom
;
1929 PAINT_RedrawWindow( wndPtr
->hwndSelf
, &rect
, 0,
1930 RDW_INVALIDATE
| RDW_FRAME
| RDW_ALLCHILDREN
, 0 );
1932 if( !wErase
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
1937 RECT16 oldClientRect
= wndPtr
->rectClient
;
1939 wndPtr
->rectWindow
= newWindowRect
;
1940 wndPtr
->rectClient
= newClientRect
;
1942 if( oldClientRect
.bottom
- oldClientRect
.top
==
1943 newClientRect
.bottom
- newClientRect
.top
) result
&= ~WVR_VREDRAW
;
1945 if( oldClientRect
.right
- oldClientRect
.left
==
1946 newClientRect
.right
- newClientRect
.left
) result
&= ~WVR_HREDRAW
;
1948 if( !(flags
& (SWP_NOREDRAW
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) )
1950 uFlags
|= ((winpos
->flags
& SWP_NOCOPYBITS
) ||
1951 (result
>= WVR_HREDRAW
&& result
< WVR_VALIDRECTS
)) ? SMC_NOCOPY
: 0;
1952 uFlags
|= (winpos
->flags
& SWP_FRAMECHANGED
) ? SMC_DRAWFRAME
: 0;
1954 if( (winpos
->flags
& SWP_AGG_NOGEOMETRYCHANGE
) != SWP_AGG_NOGEOMETRYCHANGE
)
1955 uFlags
= WINPOS_SizeMoveClean(wndPtr
, visRgn
, &oldWindowRect
,
1956 &oldClientRect
, uFlags
);
1959 /* adjust frame and do not erase parent */
1961 if( winpos
->flags
& SWP_FRAMECHANGED
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
1962 if( winpos
->flags
& SWP_NOZORDER
) uFlags
|= SMC_NOPARENTERASE
;
1965 DeleteObject32(visRgn
);
1968 if (flags
& SWP_SHOWWINDOW
)
1970 wndPtr
->dwStyle
|= WS_VISIBLE
;
1973 if( uFlags
& SMC_SETXPOS
)
1975 WINPOS_SetXWindowPos( winpos
);
1976 winpos
->hwndInsertAfter
= tempInsertAfter
;
1978 XMapWindow( display
, wndPtr
->window
);
1982 if (!(flags
& SWP_NOREDRAW
))
1983 PAINT_RedrawWindow( winpos
->hwnd
, NULL
, 0,
1984 RDW_INVALIDATE
| RDW_ALLCHILDREN
|
1985 RDW_FRAME
| RDW_ERASENOW
| RDW_ERASE
, 0 );
1988 else if (flags
& SWP_HIDEWINDOW
)
1990 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
1993 XUnmapWindow( display
, wndPtr
->window
);
1994 if( uFlags
& SMC_SETXPOS
)
1996 WINPOS_SetXWindowPos( winpos
);
1997 winpos
->hwndInsertAfter
= tempInsertAfter
;
2002 if (!(flags
& SWP_NOREDRAW
))
2004 RECT32 rect
= { oldWindowRect
.left
, oldWindowRect
.top
,
2005 oldWindowRect
.right
, oldWindowRect
.bottom
};
2006 PAINT_RedrawWindow( wndPtr
->parent
->hwndSelf
, &rect
, 0,
2007 RDW_INVALIDATE
| RDW_ALLCHILDREN
| RDW_ERASE
| RDW_ERASENOW
, 0);
2009 uFlags
|= SMC_NOPARENTERASE
;
2012 if ((winpos
->hwnd
== GetFocus32()) ||
2013 IsChild32( winpos
->hwnd
, GetFocus32()))
2015 /* Revert focus to parent */
2016 SetFocus32( GetParent32(winpos
->hwnd
) );
2018 if (hwnd
== CARET_GetHwnd()) DestroyCaret32();
2020 if (winpos
->hwnd
== hwndActive
)
2022 /* Activate previously active window if possible */
2023 HWND32 newActive
= hwndPrevActive
;
2024 if (!IsWindow32(newActive
) || (newActive
== winpos
->hwnd
))
2026 newActive
= GetTopWindow32( GetDesktopWindow32() );
2027 if (newActive
== winpos
->hwnd
)
2028 newActive
= wndPtr
->next
? wndPtr
->next
->hwndSelf
: 0;
2030 WINPOS_ChangeActiveWindow( newActive
, FALSE
);
2034 /* Activate the window */
2036 if (!(flags
& SWP_NOACTIVATE
))
2037 WINPOS_ChangeActiveWindow( winpos
->hwnd
, FALSE
);
2039 /* Repaint the window */
2041 if (wndPtr
->window
) EVENT_Synchronize(); /* Wait for all expose events */
2043 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
2045 if (!(flags
& SWP_DEFERERASE
) && !(uFlags
& SMC_NOPARENTERASE
) )
2048 CONV_RECT16TO32( &oldWindowRect
, &rect
);
2049 PAINT_RedrawWindow( wndPtr
->parent
->hwndSelf
, (wndPtr
->flags
& WIN_SAVEUNDER_OVERRIDE
)
2050 ? &rect
: NULL
, 0, RDW_ALLCHILDREN
| RDW_ERASENOW
|
2051 ((wndPtr
->flags
& WIN_SAVEUNDER_OVERRIDE
) ? RDW_INVALIDATE
: 0), 0 );
2052 wndPtr
->flags
&= ~WIN_SAVEUNDER_OVERRIDE
;
2054 else if( wndPtr
->parent
== WIN_GetDesktop() && wndPtr
->parent
->flags
& WIN_NEEDS_ERASEBKGND
)
2055 PAINT_RedrawWindow( wndPtr
->parent
->hwndSelf
, NULL
, 0, RDW_NOCHILDREN
| RDW_ERASENOW
, 0 );
2057 /* And last, send the WM_WINDOWPOSCHANGED message */
2059 dprintf_win(stddeb
,"\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2061 if ( ((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
) &&
2062 !(winpos
->flags
& SWP_NOSENDCHANGING
))
2063 SendMessage16( winpos
->hwnd
, WM_WINDOWPOSCHANGED
,
2064 0, (LPARAM
)SEGPTR_GET(winpos
) );
2066 SEGPTR_FREE(winpos
);
2071 /***********************************************************************
2072 * BeginDeferWindowPos16 (USER.259)
2074 HDWP16
BeginDeferWindowPos16( INT16 count
)
2076 return BeginDeferWindowPos32( count
);
2080 /***********************************************************************
2081 * BeginDeferWindowPos32 (USER32.8)
2083 HDWP32
BeginDeferWindowPos32( INT32 count
)
2088 if (count
<= 0) return 0;
2089 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS32
) );
2090 if (!handle
) return 0;
2091 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
2092 pDWP
->actualCount
= 0;
2093 pDWP
->suggestedCount
= count
;
2095 pDWP
->wMagic
= DWP_MAGIC
;
2096 pDWP
->hwndParent
= 0;
2101 /***********************************************************************
2102 * DeferWindowPos16 (USER.260)
2104 HDWP16
DeferWindowPos16( HDWP16 hdwp
, HWND16 hwnd
, HWND16 hwndAfter
,
2105 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, UINT16 flags
)
2107 return DeferWindowPos32( hdwp
, hwnd
, (INT32
)(INT16
)hwndAfter
,
2108 x
, y
, cx
, cy
, flags
);
2112 /***********************************************************************
2113 * DeferWindowPos32 (USER32.127)
2115 HDWP32
DeferWindowPos32( HDWP32 hdwp
, HWND32 hwnd
, HWND32 hwndAfter
,
2116 INT32 x
, INT32 y
, INT32 cx
, INT32 cy
, UINT32 flags
)
2120 HDWP32 newhdwp
= hdwp
;
2123 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
2124 if (!pDWP
) return 0;
2125 if (hwnd
== GetDesktopWindow32()) return 0;
2127 /* All the windows of a DeferWindowPos() must have the same parent */
2129 parent
= WIN_FindWndPtr( hwnd
)->parent
->hwndSelf
;
2130 if (pDWP
->actualCount
== 0) pDWP
->hwndParent
= parent
;
2131 else if (parent
!= pDWP
->hwndParent
)
2133 USER_HEAP_FREE( hdwp
);
2137 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2139 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2141 /* Merge with the other changes */
2142 if (!(flags
& SWP_NOZORDER
))
2144 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
2146 if (!(flags
& SWP_NOMOVE
))
2148 pDWP
->winPos
[i
].x
= x
;
2149 pDWP
->winPos
[i
].y
= y
;
2151 if (!(flags
& SWP_NOSIZE
))
2153 pDWP
->winPos
[i
].cx
= cx
;
2154 pDWP
->winPos
[i
].cy
= cy
;
2156 pDWP
->winPos
[i
].flags
&= flags
& (SWP_NOSIZE
| SWP_NOMOVE
|
2157 SWP_NOZORDER
| SWP_NOREDRAW
|
2158 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2160 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2165 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2167 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2168 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS32
) );
2169 if (!newhdwp
) return 0;
2170 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
2171 pDWP
->suggestedCount
++;
2173 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2174 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2175 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2176 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2177 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2178 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2179 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2180 pDWP
->actualCount
++;
2185 /***********************************************************************
2186 * EndDeferWindowPos16 (USER.261)
2188 BOOL16
EndDeferWindowPos16( HDWP16 hdwp
)
2190 return EndDeferWindowPos32( hdwp
);
2194 /***********************************************************************
2195 * EndDeferWindowPos32 (USER32.172)
2197 BOOL32
EndDeferWindowPos32( HDWP32 hdwp
)
2200 WINDOWPOS32
*winpos
;
2204 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
2205 if (!pDWP
) return FALSE
;
2206 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
2208 if (!(res
= SetWindowPos32( winpos
->hwnd
, winpos
->hwndInsertAfter
,
2209 winpos
->x
, winpos
->y
, winpos
->cx
,
2210 winpos
->cy
, winpos
->flags
))) break;
2212 USER_HEAP_FREE( hdwp
);
2217 /***********************************************************************
2218 * TileChildWindows (USER.199)
2220 void TileChildWindows( HWND16 parent
, WORD action
)
2222 printf("STUB TileChildWindows(%04x, %d)\n", parent
, action
);
2225 /***********************************************************************
2226 * CascageChildWindows (USER.198)
2228 void CascadeChildWindows( HWND16 parent
, WORD action
)
2230 printf("STUB CascadeChildWindows(%04x, %d)\n", parent
, action
);