4 * Copyright 1998,1999 Patrik Stridvall
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(ttydrv);
18 WND_DRIVER TTYDRV_WND_Driver =
20 TTYDRV_WND_ForceWindowRaise,
21 TTYDRV_WND_SetHostAttr
24 #define SWP_AGG_NOGEOMETRYCHANGE \
25 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
26 #define SWP_AGG_NOPOSCHANGE \
27 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
28 #define SWP_AGG_STATUSFLAGS \
29 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
31 /**********************************************************************
32 * CreateWindow (TTYDRV.@)
34 BOOL TTYDRV_CreateWindow( HWND hwnd )
37 WND *wndPtr = WIN_FindWndPtr( hwnd );
39 INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
41 TRACE("(%x)\n", hwnd);
43 /* Only create top-level windows */
44 if (wndPtr->dwStyle & WS_CHILD)
46 WIN_ReleaseWndPtr( wndPtr );
50 if (!wndPtr->parent) /* desktop */
54 int x = wndPtr->rectWindow.left;
55 int y = wndPtr->rectWindow.top;
56 int cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
57 int cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
59 window = subwin( root_window, cy/cellHeight, cx/cellWidth,
60 y/cellHeight, x/cellWidth);
64 wndPtr->pDriverData = window;
65 WIN_ReleaseWndPtr( wndPtr );
66 #else /* defined(WINE_CURSES) */
67 FIXME("(%x): stub\n", hwnd);
68 #endif /* defined(WINE_CURSES) */
72 /***********************************************************************
73 * DestroyWindow (TTYDRV.@)
75 BOOL TTYDRV_DestroyWindow( HWND hwnd )
78 WND *wndPtr = WIN_FindWndPtr( hwnd );
79 WINDOW *window = wndPtr->pDriverData;
81 TRACE("(%x)\n", hwnd);
83 if (window && window != root_window) delwin(window);
84 wndPtr->pDriverData = NULL;
85 WIN_ReleaseWndPtr( wndPtr );
86 #else /* defined(WINE_CURSES) */
87 FIXME("(%x): stub\n", hwnd);
88 #endif /* defined(WINE_CURSES) */
92 /***********************************************************************
93 * TTYDRV_WND_ForceWindowRaise
95 void TTYDRV_WND_ForceWindowRaise(WND *wndPtr)
97 FIXME("(%p): stub\n", wndPtr);
100 /***********************************************************************
101 * TTYDRV_WND_SetHostAttr
103 BOOL TTYDRV_WND_SetHostAttr(WND *wndPtr, INT attr, INT value)
105 FIXME("(%p): stub\n", wndPtr);
111 /***********************************************************************
114 * Change region from DC-origin relative coordinates to screen coords.
117 static void DCE_OffsetVisRgn( HDC hDC, HRGN hVisRgn )
120 if (!(dc = DC_GetDCPtr( hDC ))) return;
122 OffsetRgn( hVisRgn, dc->DCOrgX, dc->DCOrgY );
124 GDI_ReleaseObj( hDC );
128 /***********************************************************************
131 * Calculate the visible rectangle of a window (i.e. the client or
132 * window area clipped by the client area of all ancestors) in the
133 * corresponding coordinates. Return FALSE if the visible region is empty.
135 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
137 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
139 if (wndPtr->dwStyle & WS_VISIBLE)
141 INT xoffset = lprect->left;
142 INT yoffset = lprect->top;
144 while ((wndPtr = WIN_LockWndPtr(wndPtr->parent)))
146 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
148 WIN_ReleaseWndPtr(wndPtr);
152 xoffset += wndPtr->rectClient.left;
153 yoffset += wndPtr->rectClient.top;
154 OffsetRect( lprect, wndPtr->rectClient.left,
155 wndPtr->rectClient.top );
157 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
158 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
159 (lprect->left >= wndPtr->rectClient.right) ||
160 (lprect->right <= wndPtr->rectClient.left) ||
161 (lprect->top >= wndPtr->rectClient.bottom) ||
162 (lprect->bottom <= wndPtr->rectClient.top) )
164 WIN_ReleaseWndPtr(wndPtr);
168 lprect->left = max( lprect->left, wndPtr->rectClient.left );
169 lprect->right = min( lprect->right, wndPtr->rectClient.right );
170 lprect->top = max( lprect->top, wndPtr->rectClient.top );
171 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
173 WIN_ReleaseWndPtr(wndPtr);
175 OffsetRect( lprect, -xoffset, -yoffset );
180 SetRectEmpty( lprect );
185 /***********************************************************************
188 * Go through the linked list of windows from pWndStart to pWndEnd,
189 * adding to the clip region the intersection of the target rectangle
190 * with an offset window rectangle.
192 static BOOL DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
193 HRGN hrgnClip, LPRECT lpRect, int x, int y )
197 for (WIN_LockWndPtr(pWndStart); (pWndStart && (pWndStart != pWndEnd)); WIN_UpdateWndPtr(&pWndStart,pWndStart->next))
199 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
201 rect.left = pWndStart->rectWindow.left + x;
202 rect.top = pWndStart->rectWindow.top + y;
203 rect.right = pWndStart->rectWindow.right + x;
204 rect.bottom = pWndStart->rectWindow.bottom + y;
206 if( IntersectRect( &rect, &rect, lpRect ))
208 if(!REGION_UnionRectWithRgn( hrgnClip, &rect )) break;
211 WIN_ReleaseWndPtr(pWndStart);
212 return (pWndStart == pWndEnd);
216 /***********************************************************************
219 * Return the visible region of a window, i.e. the client or window area
220 * clipped by the client area of all ancestors, and then optionally
221 * by siblings and children.
223 static HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
227 WND *wndPtr = WIN_FindWndPtr( hwnd );
228 WND *childWnd = WIN_FindWndPtr( hwndChild );
230 /* Get visible rectangle and create a region with it. */
232 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
234 if((hrgnVis = CreateRectRgnIndirect( &rect )))
236 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
237 INT xoffset, yoffset;
241 /* Compute obscured region for the visible rectangle by
242 * clipping children, siblings, and ancestors. Note that
243 * DCE_GetVisRect() returns a rectangle either in client
244 * or in window coordinates (for DCX_WINDOW request). */
246 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
248 if( flags & DCX_WINDOW )
250 /* adjust offsets since child window rectangles are
251 * in client coordinates */
253 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
254 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
257 xoffset = yoffset = 0;
259 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip, &rect, xoffset, yoffset );
262 /* We may need to clip children of child window, if a window with PARENTDC
263 * class style and CLIPCHILDREN window style (like in Free Agent 16
264 * preference dialogs) gets here, we take the region for the parent window
265 * but apparently still need to clip the children of the child window... */
267 if( (cflags & DCX_CLIPCHILDREN) && childWnd && childWnd->child )
269 if( flags & DCX_WINDOW )
271 /* adjust offsets since child window rectangles are
272 * in client coordinates */
274 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
275 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
278 xoffset = yoffset = 0;
280 /* client coordinates of child window */
281 xoffset += childWnd->rectClient.left;
282 yoffset += childWnd->rectClient.top;
284 DCE_AddClipRects( childWnd->child, NULL, hrgnClip,
285 &rect, xoffset, yoffset );
288 /* sibling window rectangles are in client
289 * coordinates of the parent window */
291 if (flags & DCX_WINDOW)
293 xoffset = -wndPtr->rectWindow.left;
294 yoffset = -wndPtr->rectWindow.top;
298 xoffset = -wndPtr->rectClient.left;
299 yoffset = -wndPtr->rectClient.top;
302 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
303 DCE_AddClipRects( wndPtr->parent->child,
304 wndPtr, hrgnClip, &rect, xoffset, yoffset );
306 /* Clip siblings of all ancestors that have the
307 * WS_CLIPSIBLINGS style
310 while (wndPtr->parent)
312 WIN_UpdateWndPtr(&wndPtr,wndPtr->parent);
313 xoffset -= wndPtr->rectClient.left;
314 yoffset -= wndPtr->rectClient.top;
315 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
317 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
318 hrgnClip, &rect, xoffset, yoffset );
322 /* Now once we've got a jumbo clip region we have
323 * to substract it from the visible rectangle.
325 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
326 DeleteObject( hrgnClip );
330 DeleteObject( hrgnVis );
336 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
337 WIN_ReleaseWndPtr(wndPtr);
338 WIN_ReleaseWndPtr(childWnd);
343 /***********************************************************************
346 * Set the drawable, origin and dimensions for the DC associated to
349 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
351 WND *wndPtr = WIN_FindWndPtr(hwnd);
354 HRGN hrgnVisible = 0;
356 if (!wndPtr) return FALSE;
358 if (!(dc = DC_GetDCPtr( hdc )))
360 WIN_ReleaseWndPtr( wndPtr );
364 if(flags & DCX_WINDOW)
366 dc->DCOrgX = wndPtr->rectWindow.left;
367 dc->DCOrgY = wndPtr->rectWindow.top;
371 dc->DCOrgX = wndPtr->rectClient.left;
372 dc->DCOrgY = wndPtr->rectClient.top;
374 updateVisRgn = (dc->flags & DC_DIRTY) != 0;
375 GDI_ReleaseObj( hdc );
379 if (flags & DCX_PARENTCLIP)
381 WND *parentPtr = WIN_LockWndPtr(wndPtr->parent);
383 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
387 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
388 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
390 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
392 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
393 wndPtr->hwndSelf, flags );
394 if( flags & DCX_WINDOW )
395 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
396 -wndPtr->rectWindow.top );
398 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
399 -wndPtr->rectClient.top );
400 DCE_OffsetVisRgn( hdc, hrgnVisible );
403 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
404 WIN_ReleaseWndPtr(parentPtr);
408 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
409 DCE_OffsetVisRgn( hdc, hrgnVisible );
411 SelectVisRgn16( hdc, hrgnVisible );
414 /* apply additional region operation (if any) */
416 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
418 if( !hrgnVisible ) hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
420 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgn);
423 CombineRgn( hrgnVisible, hrgn, 0, RGN_COPY );
424 DCE_OffsetVisRgn( hdc, hrgnVisible );
425 CombineRgn( hrgnVisible, InquireVisRgn16( hdc ), hrgnVisible,
426 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
427 SelectVisRgn16( hdc, hrgnVisible );
430 if (hrgnVisible) DeleteObject( hrgnVisible );
432 WIN_ReleaseWndPtr( wndPtr );
437 /***********************************************************************
438 * SetWindowPos (TTYDRV.@)
440 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
443 RECT newWindowRect, newClientRect;
445 HWND hwndActive = GetForegroundWindow();
447 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
448 winpos->hwnd, winpos->x, winpos->y,
449 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
451 /* ------------------------------------------------------------------------ CHECKS */
453 /* Check window handle */
455 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
456 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
458 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
459 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
460 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
462 /* Fix redundant flags */
464 if(wndPtr->dwStyle & WS_VISIBLE)
465 winpos->flags &= ~SWP_SHOWWINDOW;
468 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
469 winpos->flags &= ~SWP_HIDEWINDOW;
472 if ( winpos->cx < 0 ) winpos->cx = 0;
473 if ( winpos->cy < 0 ) winpos->cy = 0;
475 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
476 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
477 winpos->flags |= SWP_NOSIZE; /* Already the right size */
479 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
480 winpos->flags |= SWP_NOMOVE; /* Already the right position */
482 if (winpos->hwnd == hwndActive)
483 winpos->flags |= SWP_NOACTIVATE; /* Already active */
484 else if ( (wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD )
486 if(!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
488 winpos->flags &= ~SWP_NOZORDER;
489 winpos->hwndInsertAfter = HWND_TOP;
494 /* Check hwndInsertAfter */
496 /* FIXME: TOPMOST not supported yet */
497 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
498 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
500 /* hwndInsertAfter must be a sibling of the window */
501 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
503 WND* wnd = WIN_FindWndPtr(winpos->hwndInsertAfter);
506 if( wnd->parent != wndPtr->parent )
509 WIN_ReleaseWndPtr(wnd);
512 /* don't need to change the Zorder of hwnd if it's already inserted
513 * after hwndInsertAfter or when inserting hwnd after itself.
515 if(( wnd->next == wndPtr ) || (winpos->hwnd == winpos->hwndInsertAfter))
516 winpos->flags |= SWP_NOZORDER;
518 WIN_ReleaseWndPtr(wnd);
521 Pos: /* ------------------------------------------------------------------------ MAIN part */
523 /* Send WM_WINDOWPOSCHANGING message */
525 if (!(winpos->flags & SWP_NOSENDCHANGING))
526 SendMessageA( wndPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos );
528 /* Calculate new position and size */
530 newWindowRect = wndPtr->rectWindow;
531 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
532 : wndPtr->rectClient;
534 if (!(winpos->flags & SWP_NOSIZE))
536 newWindowRect.right = newWindowRect.left + winpos->cx;
537 newWindowRect.bottom = newWindowRect.top + winpos->cy;
539 if (!(winpos->flags & SWP_NOMOVE))
541 newWindowRect.left = winpos->x;
542 newWindowRect.top = winpos->y;
543 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
544 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
546 OffsetRect( &newClientRect, winpos->x - wndPtr->rectWindow.left,
547 winpos->y - wndPtr->rectWindow.top );
550 if( winpos->hwndInsertAfter == HWND_TOP )
551 winpos->flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
553 if( winpos->hwndInsertAfter == HWND_BOTTOM )
554 winpos->flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
556 if( !(winpos->flags & SWP_NOZORDER) )
557 if( GetWindow(winpos->hwndInsertAfter, GW_HWNDNEXT) == wndPtr->hwndSelf )
558 winpos->flags |= SWP_NOZORDER;
560 /* Common operations */
562 /* Send WM_NCCALCSIZE message to get new client area */
563 if( (winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
565 WINPOS_SendNCCalcSize( winpos->hwnd, TRUE, &newWindowRect,
566 &wndPtr->rectWindow, &wndPtr->rectClient,
567 winpos, &newClientRect );
570 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
572 if ( WIN_UnlinkWindow( winpos->hwnd ) )
573 WIN_LinkWindow( winpos->hwnd, winpos->hwndInsertAfter );
576 /* FIXME: actually do something with WVR_VALIDRECTS */
578 wndPtr->rectWindow = newWindowRect;
579 wndPtr->rectClient = newClientRect;
581 if( winpos->flags & SWP_SHOWWINDOW )
583 wndPtr->dwStyle |= WS_VISIBLE;
585 else if( winpos->flags & SWP_HIDEWINDOW )
587 wndPtr->dwStyle &= ~WS_VISIBLE;
590 /* ------------------------------------------------------------------------ FINAL */
592 /* repaint invalidated region (if any)
594 * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
595 * and force update after ChangeActiveWindow() to avoid painting frames twice.
598 if( !(winpos->flags & SWP_NOREDRAW) )
600 RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0,
601 RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN );
602 if (wndPtr->parent->hwndSelf == GetDesktopWindow() ||
603 wndPtr->parent->parent->hwndSelf == GetDesktopWindow())
605 RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0,
606 RDW_ERASENOW | RDW_NOCHILDREN );
610 if (!(winpos->flags & SWP_NOACTIVATE))
611 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
613 /* And last, send the WM_WINDOWPOSCHANGED message */
615 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
617 if ((((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
618 !(winpos->flags & SWP_NOSENDCHANGING)) )
619 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
623 WIN_ReleaseWndPtr(wndPtr);