Release 980913
[wine/multimedia.git] / windows / win.c
blob575457b39ee78459f2bed7f0328f3e839f339c40
1 /*
2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <X11/Xatom.h>
11 #include "options.h"
12 #include "class.h"
13 #include "win.h"
14 #include "heap.h"
15 #include "user.h"
16 #include "dce.h"
17 #include "sysmetrics.h"
18 #include "cursoricon.h"
19 #include "heap.h"
20 #include "hook.h"
21 #include "menu.h"
22 #include "message.h"
23 #include "nonclient.h"
24 #include "queue.h"
25 #include "winpos.h"
26 #include "color.h"
27 #include "shm_main_blk.h"
28 #include "dde_proc.h"
29 #include "clipboard.h"
30 #include "winproc.h"
31 #include "thread.h"
32 #include "process.h"
33 #include "debug.h"
34 #include "winerror.h"
36 /* Desktop window */
37 static WND *pWndDesktop = NULL;
39 static HWND32 hwndSysModal = 0;
41 static WORD wDragWidth = 4;
42 static WORD wDragHeight= 3;
44 /***********************************************************************
45 * WIN_FindWndPtr
47 * Return a pointer to the WND structure corresponding to a HWND.
49 WND * WIN_FindWndPtr( HWND32 hwnd )
51 WND * ptr;
53 if (!hwnd || HIWORD(hwnd)) return NULL;
54 ptr = (WND *) USER_HEAP_LIN_ADDR( hwnd );
55 if (ptr->dwMagic != WND_MAGIC) return NULL;
56 if (ptr->hwndSelf != hwnd)
58 ERR( win, "Can't happen: hwnd %04x self pointer is %04x\n",
59 hwnd, ptr->hwndSelf );
60 return NULL;
62 return ptr;
66 /***********************************************************************
67 * WIN_DumpWindow
69 * Dump the content of a window structure to stderr.
71 void WIN_DumpWindow( HWND32 hwnd )
73 WND *ptr;
74 char className[80];
75 int i;
77 if (!(ptr = WIN_FindWndPtr( hwnd )))
79 WARN( win, "%04x is not a window handle\n", hwnd );
80 return;
83 if (!GetClassName32A( hwnd, className, sizeof(className ) ))
84 strcpy( className, "#NULL#" );
86 TRACE( win, "Window %04x (%p):\n", hwnd, ptr );
87 DUMP( "next=%p child=%p parent=%p owner=%p class=%p '%s'\n"
88 "inst=%04x taskQ=%04x updRgn=%04x active=%04x dce=%p idmenu=%08x\n"
89 "style=%08lx exstyle=%08lx wndproc=%08x text='%s'\n"
90 "client=%d,%d-%d,%d window=%d,%d-%d,%d"
91 "sysmenu=%04x flags=%04x props=%p vscroll=%p hscroll=%p\n",
92 ptr->next, ptr->child, ptr->parent, ptr->owner,
93 ptr->class, className, ptr->hInstance, ptr->hmemTaskQ,
94 ptr->hrgnUpdate, ptr->hwndLastActive, ptr->dce, ptr->wIDmenu,
95 ptr->dwStyle, ptr->dwExStyle, (UINT32)ptr->winproc,
96 ptr->text ? ptr->text : "",
97 ptr->rectClient.left, ptr->rectClient.top, ptr->rectClient.right,
98 ptr->rectClient.bottom, ptr->rectWindow.left, ptr->rectWindow.top,
99 ptr->rectWindow.right, ptr->rectWindow.bottom, ptr->hSysMenu,
100 ptr->flags, ptr->pProp, ptr->pVScroll, ptr->pHScroll );
102 if (ptr->class->cbWndExtra)
104 DUMP( "extra bytes:" );
105 for (i = 0; i < ptr->class->cbWndExtra; i++)
106 DUMP( " %02x", *((BYTE*)ptr->wExtra+i) );
107 DUMP( "\n" );
109 DUMP( "\n" );
113 /***********************************************************************
114 * WIN_WalkWindows
116 * Walk the windows tree and print each window on stderr.
118 void WIN_WalkWindows( HWND32 hwnd, int indent )
120 WND *ptr;
121 char className[80];
123 ptr = hwnd ? WIN_FindWndPtr( hwnd ) : pWndDesktop;
124 if (!ptr)
126 WARN( win, "Invalid window handle %04x\n", hwnd );
127 return;
130 if (!indent) /* first time around */
131 DUMP( "%-16.16s %-8.8s %-6.6s %-17.17s %-8.8s %s\n",
132 "hwnd", " wndPtr", "queue", "Class Name", " Style", " WndProc");
134 while (ptr)
136 DUMP( "%*s%04x%*s", indent, "", ptr->hwndSelf, 13-indent,"");
138 GlobalGetAtomName16(ptr->class->atomName,className,sizeof(className));
140 DUMP( "%08lx %-6.4x %-17.17s %08x %08x\n",
141 (DWORD)ptr, ptr->hmemTaskQ, className,
142 (UINT32)ptr->dwStyle, (UINT32)ptr->winproc );
144 if (ptr->child) WIN_WalkWindows( ptr->child->hwndSelf, indent+1 );
145 ptr = ptr->next;
150 /***********************************************************************
151 * WIN_GetXWindow
153 * Return the X window associated to a window.
155 Window WIN_GetXWindow( HWND32 hwnd )
157 WND *wndPtr = WIN_FindWndPtr( hwnd );
158 while (wndPtr && !wndPtr->window) wndPtr = wndPtr->parent;
159 return wndPtr ? wndPtr->window : 0;
163 /***********************************************************************
164 * WIN_UnlinkWindow
166 * Remove a window from the siblings linked list.
168 BOOL32 WIN_UnlinkWindow( HWND32 hwnd )
170 WND *wndPtr, **ppWnd;
172 if (!(wndPtr = WIN_FindWndPtr( hwnd )) || !wndPtr->parent) return FALSE;
173 ppWnd = &wndPtr->parent->child;
174 while (*ppWnd != wndPtr) ppWnd = &(*ppWnd)->next;
175 *ppWnd = wndPtr->next;
176 return TRUE;
180 /***********************************************************************
181 * WIN_LinkWindow
183 * Insert a window into the siblings linked list.
184 * The window is inserted after the specified window, which can also
185 * be specified as HWND_TOP or HWND_BOTTOM.
187 BOOL32 WIN_LinkWindow( HWND32 hwnd, HWND32 hwndInsertAfter )
189 WND *wndPtr, **ppWnd;
191 if (!(wndPtr = WIN_FindWndPtr( hwnd )) || !wndPtr->parent) return FALSE;
193 if ((hwndInsertAfter == HWND_TOP) || (hwndInsertAfter == HWND_BOTTOM))
195 ppWnd = &wndPtr->parent->child; /* Point to first sibling hwnd */
196 if (hwndInsertAfter == HWND_BOTTOM) /* Find last sibling hwnd */
197 while (*ppWnd) ppWnd = &(*ppWnd)->next;
199 else /* Normal case */
201 WND * afterPtr = WIN_FindWndPtr( hwndInsertAfter );
202 if (!afterPtr) return FALSE;
203 ppWnd = &afterPtr->next;
205 wndPtr->next = *ppWnd;
206 *ppWnd = wndPtr;
207 return TRUE;
211 /***********************************************************************
212 * WIN_FindWinToRepaint
214 * Find a window that needs repaint.
216 HWND32 WIN_FindWinToRepaint( HWND32 hwnd, HQUEUE16 hQueue )
218 HWND32 hwndRet;
219 WND *pWnd = pWndDesktop;
221 /* Note: the desktop window never gets WM_PAINT messages
222 * The real reason why is because Windows DesktopWndProc
223 * does ValidateRgn inside WM_ERASEBKGND handler.
226 pWnd = hwnd ? WIN_FindWndPtr( hwnd ) : pWndDesktop->child;
228 for ( ; pWnd ; pWnd = pWnd->next )
230 if (!(pWnd->dwStyle & WS_VISIBLE))
232 TRACE(win, "skipping window %04x\n",
233 pWnd->hwndSelf );
234 continue;
236 if ((pWnd->hmemTaskQ == hQueue) &&
237 (pWnd->hrgnUpdate || (pWnd->flags & WIN_INTERNAL_PAINT))) break;
239 if (pWnd->child )
240 if ((hwndRet = WIN_FindWinToRepaint( pWnd->child->hwndSelf, hQueue )) )
241 return hwndRet;
244 if (!pWnd) return 0;
246 hwndRet = pWnd->hwndSelf;
248 /* look among siblings if we got a transparent window */
249 while (pWnd && ((pWnd->dwExStyle & WS_EX_TRANSPARENT) ||
250 !(pWnd->hrgnUpdate || (pWnd->flags & WIN_INTERNAL_PAINT))))
252 pWnd = pWnd->next;
254 if (pWnd) hwndRet = pWnd->hwndSelf;
255 TRACE(win,"found %04x\n",hwndRet);
256 return hwndRet;
260 /***********************************************************************
261 * WIN_DestroyWindow
263 * Destroy storage associated to a window. "Internals" p.358
265 static WND* WIN_DestroyWindow( WND* wndPtr )
267 HWND32 hwnd = wndPtr->hwndSelf;
268 WND *pWnd;
270 TRACE(win, "%04x\n", wndPtr->hwndSelf );
272 #ifdef CONFIG_IPC
273 if (main_block)
274 DDE_DestroyWindow(wndPtr->hwndSelf);
275 #endif /* CONFIG_IPC */
277 /* free child windows */
279 while ((pWnd = wndPtr->child))
280 wndPtr->child = WIN_DestroyWindow( pWnd );
282 SendMessage32A( wndPtr->hwndSelf, WM_NCDESTROY, 0, 0);
284 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
286 WINPOS_CheckInternalPos( hwnd );
287 if( hwnd == GetCapture32()) ReleaseCapture();
289 /* free resources associated with the window */
291 TIMER_RemoveWindowTimers( wndPtr->hwndSelf );
292 PROPERTY_RemoveWindowProps( wndPtr );
294 wndPtr->dwMagic = 0; /* Mark it as invalid */
296 if ((wndPtr->hrgnUpdate) || (wndPtr->flags & WIN_INTERNAL_PAINT))
298 if (wndPtr->hrgnUpdate > 1) DeleteObject32( wndPtr->hrgnUpdate );
299 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
302 /* toss stale messages from the queue */
304 if( wndPtr->hmemTaskQ )
306 int pos;
307 BOOL32 bPostQuit = FALSE;
308 WPARAM32 wQuitParam = 0;
309 MESSAGEQUEUE* msgQ = (MESSAGEQUEUE*) GlobalLock16(wndPtr->hmemTaskQ);
311 while( (pos = QUEUE_FindMsg(msgQ, hwnd, 0, 0)) != -1 )
313 if( msgQ->messages[pos].msg.message == WM_QUIT )
315 bPostQuit = TRUE;
316 wQuitParam = msgQ->messages[pos].msg.wParam;
318 QUEUE_RemoveMsg(msgQ, pos);
320 /* repost WM_QUIT to make sure this app exits its message loop */
321 if( bPostQuit ) PostQuitMessage32(wQuitParam);
322 wndPtr->hmemTaskQ = 0;
325 if (!(wndPtr->dwStyle & WS_CHILD))
326 if (wndPtr->wIDmenu) DestroyMenu32( (HMENU32)wndPtr->wIDmenu );
327 if (wndPtr->hSysMenu) DestroyMenu32( wndPtr->hSysMenu );
328 if (wndPtr->window) EVENT_DestroyWindow( wndPtr );
329 DCE_FreeWindowDCE( wndPtr ); /* Always do this to catch orphaned DCs */
330 WINPROC_FreeProc( wndPtr->winproc, WIN_PROC_WINDOW );
331 wndPtr->hwndSelf = 0;
332 wndPtr->class->cWindows--;
333 wndPtr->class = NULL;
334 pWnd = wndPtr->next;
336 USER_HEAP_FREE( hwnd );
337 return pWnd;
340 /***********************************************************************
341 * WIN_ResetQueueWindows
343 * Reset the queue of all the children of a given window.
344 * Return TRUE if something was done.
346 BOOL32 WIN_ResetQueueWindows( WND* wnd, HQUEUE16 hQueue, HQUEUE16 hNew )
348 BOOL32 ret = FALSE;
350 if (hNew) /* Set a new queue */
352 for (wnd = wnd->child; (wnd); wnd = wnd->next)
354 if (wnd->hmemTaskQ == hQueue)
356 wnd->hmemTaskQ = hNew;
357 ret = TRUE;
359 if (wnd->child)
360 ret |= WIN_ResetQueueWindows( wnd->child, hQueue, hNew );
363 else /* Queue is being destroyed */
365 while (wnd->child)
367 WND *tmp = wnd->child;
368 ret = FALSE;
369 while (tmp)
371 if (tmp->hmemTaskQ == hQueue)
373 DestroyWindow32( tmp->hwndSelf );
374 ret = TRUE;
375 break;
377 if (tmp->child && WIN_ResetQueueWindows(tmp->child,hQueue,0))
378 ret = TRUE;
379 else
380 tmp = tmp->next;
382 if (!ret) break;
385 return ret;
388 /***********************************************************************
389 * WIN_CreateDesktopWindow
391 * Create the desktop window.
393 BOOL32 WIN_CreateDesktopWindow(void)
395 CLASS *class;
396 HWND32 hwndDesktop;
398 TRACE(win,"Creating desktop window\n");
400 if (!ICONTITLE_Init() ||
401 !WINPOS_CreateInternalPosAtom() ||
402 !(class = CLASS_FindClassByAtom( DESKTOP_CLASS_ATOM, 0 )))
403 return FALSE;
405 hwndDesktop = USER_HEAP_ALLOC( sizeof(WND)+class->cbWndExtra );
406 if (!hwndDesktop) return FALSE;
407 pWndDesktop = (WND *) USER_HEAP_LIN_ADDR( hwndDesktop );
409 pWndDesktop->next = NULL;
410 pWndDesktop->child = NULL;
411 pWndDesktop->parent = NULL;
412 pWndDesktop->owner = NULL;
413 pWndDesktop->class = class;
414 pWndDesktop->dwMagic = WND_MAGIC;
415 pWndDesktop->hwndSelf = hwndDesktop;
416 pWndDesktop->hInstance = 0;
417 pWndDesktop->rectWindow.left = 0;
418 pWndDesktop->rectWindow.top = 0;
419 pWndDesktop->rectWindow.right = SYSMETRICS_CXSCREEN;
420 pWndDesktop->rectWindow.bottom = SYSMETRICS_CYSCREEN;
421 pWndDesktop->rectClient = pWndDesktop->rectWindow;
422 pWndDesktop->text = NULL;
423 pWndDesktop->hmemTaskQ = 0; /* Desktop does not belong to a task */
424 pWndDesktop->hrgnUpdate = 0;
425 pWndDesktop->hwndLastActive = hwndDesktop;
426 pWndDesktop->dwStyle = WS_VISIBLE | WS_CLIPCHILDREN |
427 WS_CLIPSIBLINGS;
428 pWndDesktop->dwExStyle = 0;
429 pWndDesktop->dce = NULL;
430 pWndDesktop->pVScroll = NULL;
431 pWndDesktop->pHScroll = NULL;
432 pWndDesktop->pProp = NULL;
433 pWndDesktop->wIDmenu = 0;
434 pWndDesktop->helpContext = 0;
435 pWndDesktop->flags = 0;
436 pWndDesktop->window = rootWindow;
437 pWndDesktop->hSysMenu = 0;
438 pWndDesktop->userdata = 0;
440 pWndDesktop->winproc = (WNDPROC16)class->winproc;
442 EVENT_RegisterWindow( pWndDesktop );
443 SendMessage32A( hwndDesktop, WM_NCCREATE, 0, 0 );
444 pWndDesktop->flags |= WIN_NEEDS_ERASEBKGND;
445 return TRUE;
449 /***********************************************************************
450 * WIN_CreateWindowEx
452 * Implementation of CreateWindowEx().
454 static HWND32 WIN_CreateWindowEx( CREATESTRUCT32A *cs, ATOM classAtom,
455 BOOL32 win32, BOOL32 unicode )
457 CLASS *classPtr;
458 WND *wndPtr;
459 HWND16 hwnd, hwndLinkAfter;
460 POINT32 maxSize, maxPos, minTrack, maxTrack;
461 LRESULT (CALLBACK *localSend32)(HWND32, UINT32, WPARAM32, LPARAM);
463 TRACE(win, "%s %s %08lx %08lx %d,%d %dx%d %04x %04x %08x %p\n",
464 unicode ? debugres_w((LPWSTR)cs->lpszName) : debugres_a(cs->lpszName),
465 unicode ? debugres_w((LPWSTR)cs->lpszClass) : debugres_a(cs->lpszClass),
466 cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
467 cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
469 /* Find the parent window */
471 if (cs->hwndParent)
473 /* Make sure parent is valid */
474 if (!IsWindow32( cs->hwndParent ))
476 WARN( win, "Bad parent %04x\n", cs->hwndParent );
477 return 0;
479 } else if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
480 WARN( win, "No parent for child window\n" );
481 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
484 /* Find the window class */
485 if (!(classPtr = CLASS_FindClassByAtom( classAtom, win32?cs->hInstance:GetExePtr(cs->hInstance) )))
487 char buffer[256];
488 GlobalGetAtomName32A( classAtom, buffer, sizeof(buffer) );
489 WARN( win, "Bad class '%s'\n", buffer );
490 return 0;
493 /* Fix the coordinates */
495 if (cs->x == CW_USEDEFAULT32)
497 PDB32 *pdb = PROCESS_Current();
498 if ( !(cs->style & (WS_CHILD | WS_POPUP))
499 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
501 cs->x = pdb->env_db->startup_info->dwX;
502 cs->y = pdb->env_db->startup_info->dwY;
504 else
506 cs->x = 0;
507 cs->y = 0;
510 if (cs->cx == CW_USEDEFAULT32)
512 PDB32 *pdb = PROCESS_Current();
513 if ( !(cs->style & (WS_CHILD | WS_POPUP))
514 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
516 cs->cx = pdb->env_db->startup_info->dwXSize;
517 cs->cy = pdb->env_db->startup_info->dwYSize;
519 else
521 cs->cx = 600; /* FIXME */
522 cs->cy = 400;
526 /* Create the window structure */
528 if (!(hwnd = USER_HEAP_ALLOC( sizeof(*wndPtr) + classPtr->cbWndExtra
529 - sizeof(wndPtr->wExtra) )))
531 TRACE(win, "out of memory\n" );
532 return 0;
535 /* Fill the window structure */
537 wndPtr = (WND *) USER_HEAP_LIN_ADDR( hwnd );
538 wndPtr->next = NULL;
539 wndPtr->child = NULL;
541 if ((cs->style & WS_CHILD) && cs->hwndParent)
543 wndPtr->parent = WIN_FindWndPtr( cs->hwndParent );
544 wndPtr->owner = NULL;
546 else
548 wndPtr->parent = pWndDesktop;
549 if (!cs->hwndParent || (cs->hwndParent == pWndDesktop->hwndSelf))
550 wndPtr->owner = NULL;
551 else
552 wndPtr->owner = WIN_GetTopParentPtr(WIN_FindWndPtr(cs->hwndParent));
555 wndPtr->window = 0;
556 wndPtr->class = classPtr;
557 wndPtr->winproc = classPtr->winproc;
558 wndPtr->dwMagic = WND_MAGIC;
559 wndPtr->hwndSelf = hwnd;
560 wndPtr->hInstance = cs->hInstance;
561 wndPtr->text = NULL;
562 wndPtr->hmemTaskQ = GetTaskQueue(0);
563 wndPtr->hrgnUpdate = 0;
564 wndPtr->hwndLastActive = hwnd;
565 wndPtr->dwStyle = cs->style & ~WS_VISIBLE;
566 wndPtr->dwExStyle = cs->dwExStyle;
567 wndPtr->wIDmenu = 0;
568 wndPtr->helpContext = 0;
569 wndPtr->flags = win32 ? WIN_ISWIN32 : 0;
570 wndPtr->pVScroll = NULL;
571 wndPtr->pHScroll = NULL;
572 wndPtr->pProp = NULL;
573 wndPtr->userdata = 0;
574 wndPtr->hSysMenu = (wndPtr->dwStyle & WS_SYSMENU)
575 ? MENU_GetSysMenu( hwnd, 0 ) : 0;
577 if (classPtr->cbWndExtra) memset( wndPtr->wExtra, 0, classPtr->cbWndExtra);
579 /* Call the WH_CBT hook */
581 hwndLinkAfter = (cs->style & WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
583 if (HOOK_IsHooked( WH_CBT ))
585 CBT_CREATEWND32A cbtc;
586 LRESULT ret;
588 cbtc.lpcs = cs;
589 cbtc.hwndInsertAfter = hwndLinkAfter;
590 ret = unicode ? HOOK_CallHooks32W(WH_CBT, HCBT_CREATEWND, hwnd, (LPARAM)&cbtc)
591 : HOOK_CallHooks32A(WH_CBT, HCBT_CREATEWND, hwnd, (LPARAM)&cbtc);
592 if (ret)
594 TRACE(win, "CBT-hook returned 0\n");
595 USER_HEAP_FREE( hwnd );
596 return 0;
600 /* Increment class window counter */
602 classPtr->cWindows++;
604 /* Correct the window style */
606 if (!(cs->style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
608 wndPtr->dwStyle |= WS_CAPTION | WS_CLIPSIBLINGS;
609 wndPtr->flags |= WIN_NEED_SIZE;
611 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) wndPtr->dwStyle &= ~WS_THICKFRAME;
613 /* Get class or window DC if needed */
615 if (classPtr->style & CS_OWNDC) wndPtr->dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
616 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
617 else wndPtr->dce = NULL;
619 /* Insert the window in the linked list */
621 WIN_LinkWindow( hwnd, hwndLinkAfter );
623 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
625 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
627 WINPOS_GetMinMaxInfo( wndPtr, &maxSize, &maxPos, &minTrack, &maxTrack);
628 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
629 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
630 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
631 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
634 if(cs->style & WS_CHILD)
636 if(cs->cx < 0) cs->cx = 0;
637 if(cs->cy < 0) cs->cy = 0;
639 else
641 if (cs->cx <= 0) cs->cx = 1;
642 if (cs->cy <= 0) cs->cy = 1;
645 wndPtr->rectWindow.left = cs->x;
646 wndPtr->rectWindow.top = cs->y;
647 wndPtr->rectWindow.right = cs->x + cs->cx;
648 wndPtr->rectWindow.bottom = cs->y + cs->cy;
649 wndPtr->rectClient = wndPtr->rectWindow;
651 /* Create the X window (only for top-level windows, and then only */
652 /* when there's no desktop window) */
654 if (!(cs->style & WS_CHILD) && (rootWindow == DefaultRootWindow(display)))
656 XSetWindowAttributes win_attr;
658 if (Options.managed && ((cs->style & (WS_DLGFRAME | WS_THICKFRAME)) ||
659 (cs->dwExStyle & WS_EX_DLGMODALFRAME)))
661 win_attr.event_mask = ExposureMask | KeyPressMask |
662 KeyReleaseMask | PointerMotionMask |
663 ButtonPressMask | ButtonReleaseMask |
664 FocusChangeMask | StructureNotifyMask;
665 win_attr.override_redirect = FALSE;
666 wndPtr->flags |= WIN_MANAGED;
668 else
670 win_attr.event_mask = ExposureMask | KeyPressMask |
671 KeyReleaseMask | PointerMotionMask |
672 ButtonPressMask | ButtonReleaseMask |
673 FocusChangeMask;
674 win_attr.override_redirect = TRUE;
676 win_attr.colormap = COLOR_GetColormap();
677 win_attr.backing_store = Options.backingstore ? WhenMapped : NotUseful;
678 win_attr.save_under = ((classPtr->style & CS_SAVEBITS) != 0);
679 win_attr.cursor = CURSORICON_XCursor;
680 wndPtr->window = TSXCreateWindow( display, rootWindow, cs->x, cs->y,
681 cs->cx, cs->cy, 0, CopyFromParent,
682 InputOutput, CopyFromParent,
683 CWEventMask | CWOverrideRedirect |
684 CWColormap | CWCursor | CWSaveUnder |
685 CWBackingStore, &win_attr );
687 if ((wndPtr->flags & WIN_MANAGED) &&
688 (cs->dwExStyle & WS_EX_DLGMODALFRAME))
690 XSizeHints* size_hints = TSXAllocSizeHints();
692 if (size_hints)
694 size_hints->min_width = size_hints->max_width = cs->cx;
695 size_hints->min_height = size_hints->max_height = cs->cy;
696 size_hints->flags = (PSize | PMinSize | PMaxSize);
697 TSXSetWMSizeHints( display, wndPtr->window, size_hints,
698 XA_WM_NORMAL_HINTS );
699 TSXFree(size_hints);
703 if (cs->hwndParent) /* Get window owner */
705 Window win = WIN_GetXWindow( cs->hwndParent );
706 if (win) TSXSetTransientForHint( display, wndPtr->window, win );
708 EVENT_RegisterWindow( wndPtr );
711 /* Set the window menu */
713 if ((wndPtr->dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
715 if (cs->hMenu) SetMenu32(hwnd, cs->hMenu);
716 else
718 #if 0 /* FIXME: should check if classPtr->menuNameW can be used as is */
719 if (classPtr->menuNameA)
720 cs->hMenu = HIWORD(classPtr->menuNameA) ?
721 LoadMenu(cs->hInstance,SEGPTR_GET(classPtr->menuNameA)):
722 LoadMenu(cs->hInstance,(SEGPTR)classPtr->menuNameA);
723 #else
724 SEGPTR menuName = (SEGPTR)GetClassLong16( hwnd, GCL_MENUNAME );
725 if (menuName)
727 /* hInstance is still 16-bit in 980215 winelib */
728 if (HIWORD(cs->hInstance) || __winelib)
729 cs->hMenu = LoadMenu32A(cs->hInstance,PTR_SEG_TO_LIN(menuName));
730 else
731 /* doesn't work for winelib, since resources are unicode */
732 cs->hMenu = LoadMenu16(cs->hInstance,menuName);
734 if (cs->hMenu) SetMenu32( hwnd, cs->hMenu );
736 #endif
739 else wndPtr->wIDmenu = (UINT32)cs->hMenu;
741 /* Send the WM_CREATE message
742 * Perhaps we shouldn't allow width/height changes as well.
743 * See p327 in "Internals".
746 maxPos.x = wndPtr->rectWindow.left; maxPos.y = wndPtr->rectWindow.top;
748 localSend32 = unicode ? SendMessage32W : SendMessage32A;
749 if( (*localSend32)( hwnd, WM_NCCREATE, 0, (LPARAM)cs) )
751 WINPOS_SendNCCalcSize( hwnd, FALSE, &wndPtr->rectWindow,
752 NULL, NULL, 0, &wndPtr->rectClient );
753 OffsetRect32(&wndPtr->rectWindow, maxPos.x - wndPtr->rectWindow.left,
754 maxPos.y - wndPtr->rectWindow.top);
755 if( ((*localSend32)( hwnd, WM_CREATE, 0, (LPARAM)cs )) != -1 )
757 /* Send the size messages */
759 if (!(wndPtr->flags & WIN_NEED_SIZE))
761 /* send it anyway */
762 if (((wndPtr->rectClient.right-wndPtr->rectClient.left) <0)
763 ||((wndPtr->rectClient.bottom-wndPtr->rectClient.top)<0))
764 WARN(win,"sending bogus WM_SIZE message 0x%08lx\n",
765 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
766 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
767 SendMessage32A( hwnd, WM_SIZE, SIZE_RESTORED,
768 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
769 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
770 SendMessage32A( hwnd, WM_MOVE, 0,
771 MAKELONG( wndPtr->rectClient.left,
772 wndPtr->rectClient.top ) );
775 /* Show the window, maximizing or minimizing if needed */
777 if (wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE))
779 RECT16 newPos;
780 UINT16 swFlag = (wndPtr->dwStyle & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
781 wndPtr->dwStyle &= ~(WS_MAXIMIZE | WS_MINIMIZE);
782 WINPOS_MinMaximize( wndPtr, swFlag, &newPos );
783 swFlag = ((wndPtr->dwStyle & WS_CHILD) || GetActiveWindow32()) ? SWP_NOACTIVATE : 0;
784 SetWindowPos32( hwnd, 0, newPos.left, newPos.top,
785 newPos.right, newPos.bottom, SWP_FRAMECHANGED | swFlag );
788 if( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY) )
790 /* Notify the parent window only */
792 SendMessage32A( wndPtr->parent->hwndSelf, WM_PARENTNOTIFY,
793 MAKEWPARAM(WM_CREATE, wndPtr->wIDmenu), (LPARAM)hwnd );
794 if( !IsWindow32(hwnd) ) return 0;
797 if (cs->style & WS_VISIBLE) ShowWindow32( hwnd, SW_SHOW );
799 /* Call WH_SHELL hook */
801 if (!(wndPtr->dwStyle & WS_CHILD) && !wndPtr->owner)
802 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
804 TRACE(win, "created window %04x\n", hwnd);
805 return hwnd;
809 /* Abort window creation */
811 WARN(win, "aborted by WM_xxCREATE!\n");
812 WIN_UnlinkWindow( hwnd );
813 WIN_DestroyWindow( wndPtr );
814 return 0;
818 /***********************************************************************
819 * CreateWindow16 (USER.41)
821 HWND16 WINAPI CreateWindow16( LPCSTR className, LPCSTR windowName,
822 DWORD style, INT16 x, INT16 y, INT16 width,
823 INT16 height, HWND16 parent, HMENU16 menu,
824 HINSTANCE16 instance, LPVOID data )
826 return CreateWindowEx16( 0, className, windowName, style,
827 x, y, width, height, parent, menu, instance, data );
831 /***********************************************************************
832 * CreateWindowEx16 (USER.452)
834 HWND16 WINAPI CreateWindowEx16( DWORD exStyle, LPCSTR className,
835 LPCSTR windowName, DWORD style, INT16 x,
836 INT16 y, INT16 width, INT16 height,
837 HWND16 parent, HMENU16 menu,
838 HINSTANCE16 instance, LPVOID data )
840 ATOM classAtom;
841 CREATESTRUCT32A cs;
843 /* Find the class atom */
845 if (!(classAtom = GlobalFindAtom32A( className )))
847 fprintf( stderr, "CreateWindowEx16: bad class name " );
848 if (!HIWORD(className)) fprintf( stderr, "%04x\n", LOWORD(className) );
849 else fprintf( stderr, "'%s'\n", className );
850 return 0;
853 /* Fix the coordinates */
855 cs.x = (x == CW_USEDEFAULT16) ? CW_USEDEFAULT32 : (INT32)x;
856 cs.y = (y == CW_USEDEFAULT16) ? CW_USEDEFAULT32 : (INT32)y;
857 cs.cx = (width == CW_USEDEFAULT16) ? CW_USEDEFAULT32 : (INT32)width;
858 cs.cy = (height == CW_USEDEFAULT16) ? CW_USEDEFAULT32 : (INT32)height;
860 /* Create the window */
862 cs.lpCreateParams = data;
863 cs.hInstance = (HINSTANCE32)instance;
864 cs.hMenu = (HMENU32)menu;
865 cs.hwndParent = (HWND32)parent;
866 cs.style = style;
867 cs.lpszName = windowName;
868 cs.lpszClass = className;
869 cs.dwExStyle = exStyle;
870 return WIN_CreateWindowEx( &cs, classAtom, FALSE, FALSE );
874 /***********************************************************************
875 * CreateWindowEx32A (USER32.83)
877 HWND32 WINAPI CreateWindowEx32A( DWORD exStyle, LPCSTR className,
878 LPCSTR windowName, DWORD style, INT32 x,
879 INT32 y, INT32 width, INT32 height,
880 HWND32 parent, HMENU32 menu,
881 HINSTANCE32 instance, LPVOID data )
883 ATOM classAtom;
884 CREATESTRUCT32A cs;
886 /* Find the class atom */
888 if (!(classAtom = GlobalFindAtom32A( className )))
890 fprintf( stderr, "CreateWindowEx32A: bad class name " );
891 if (!HIWORD(className)) fprintf( stderr, "%04x\n", LOWORD(className) );
892 else fprintf( stderr, "'%s'\n", className );
893 return 0;
896 /* Create the window */
898 cs.lpCreateParams = data;
899 cs.hInstance = instance;
900 cs.hMenu = menu;
901 cs.hwndParent = parent;
902 cs.x = x;
903 cs.y = y;
904 cs.cx = width;
905 cs.cy = height;
906 cs.style = style;
907 cs.lpszName = windowName;
908 cs.lpszClass = className;
909 cs.dwExStyle = exStyle;
910 return WIN_CreateWindowEx( &cs, classAtom, TRUE, FALSE );
914 /***********************************************************************
915 * CreateWindowEx32W (USER32.84)
917 HWND32 WINAPI CreateWindowEx32W( DWORD exStyle, LPCWSTR className,
918 LPCWSTR windowName, DWORD style, INT32 x,
919 INT32 y, INT32 width, INT32 height,
920 HWND32 parent, HMENU32 menu,
921 HINSTANCE32 instance, LPVOID data )
923 ATOM classAtom;
924 CREATESTRUCT32W cs;
926 /* Find the class atom */
928 if (!(classAtom = GlobalFindAtom32W( className )))
930 if (HIWORD(className))
932 LPSTR cn = HEAP_strdupWtoA( GetProcessHeap(), 0, className );
933 WARN( win, "Bad class name '%s'\n",cn);
934 HeapFree( GetProcessHeap(), 0, cn );
936 else
937 WARN( win, "Bad class name %p\n", className );
938 return 0;
941 /* Create the window */
943 cs.lpCreateParams = data;
944 cs.hInstance = instance;
945 cs.hMenu = menu;
946 cs.hwndParent = parent;
947 cs.x = x;
948 cs.y = y;
949 cs.cx = width;
950 cs.cy = height;
951 cs.style = style;
952 cs.lpszName = windowName;
953 cs.lpszClass = className;
954 cs.dwExStyle = exStyle;
955 /* Note: we rely on the fact that CREATESTRUCT32A and */
956 /* CREATESTRUCT32W have the same layout. */
957 return WIN_CreateWindowEx( (CREATESTRUCT32A *)&cs, classAtom, TRUE, TRUE );
961 /***********************************************************************
962 * WIN_CheckFocus
964 static void WIN_CheckFocus( WND* pWnd )
966 if( GetFocus16() == pWnd->hwndSelf )
967 SetFocus16( (pWnd->dwStyle & WS_CHILD) ? pWnd->parent->hwndSelf : 0 );
970 /***********************************************************************
971 * WIN_SendDestroyMsg
973 static void WIN_SendDestroyMsg( WND* pWnd )
975 WIN_CheckFocus(pWnd);
977 if( CARET_GetHwnd() == pWnd->hwndSelf ) DestroyCaret32();
978 if( !pWnd->window ) CLIPBOARD_ResetOwner( pWnd );
980 SendMessage32A( pWnd->hwndSelf, WM_DESTROY, 0, 0);
982 if( IsWindow32(pWnd->hwndSelf) )
984 WND* pChild = pWnd->child;
985 while( pChild )
987 WIN_SendDestroyMsg( pChild );
988 pChild = pChild->next;
990 WIN_CheckFocus(pWnd);
992 else
993 WARN(win, "\tdestroyed itself while in WM_DESTROY!\n");
997 /***********************************************************************
998 * DestroyWindow16 (USER.53)
1000 BOOL16 WINAPI DestroyWindow16( HWND16 hwnd )
1002 return DestroyWindow32(hwnd);
1006 /***********************************************************************
1007 * DestroyWindow32 (USER32.135)
1009 BOOL32 WINAPI DestroyWindow32( HWND32 hwnd )
1011 WND * wndPtr;
1013 TRACE(win, "(%04x)\n", hwnd);
1015 /* Initialization */
1017 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1018 if (wndPtr == pWndDesktop) return FALSE; /* Can't destroy desktop */
1020 /* Call hooks */
1022 if( HOOK_CallHooks16( WH_CBT, HCBT_DESTROYWND, hwnd, 0L) )
1023 return FALSE;
1025 if (!(wndPtr->dwStyle & WS_CHILD) && !wndPtr->owner)
1027 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWDESTROYED, hwnd, 0L );
1028 /* FIXME: clean up palette - see "Internals" p.352 */
1031 if( !QUEUE_IsExitingQueue(wndPtr->hmemTaskQ) )
1032 if( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY) )
1034 /* Notify the parent window only */
1035 SendMessage32A( wndPtr->parent->hwndSelf, WM_PARENTNOTIFY,
1036 MAKEWPARAM(WM_DESTROY, wndPtr->wIDmenu), (LPARAM)hwnd );
1037 if( !IsWindow32(hwnd) ) return TRUE;
1040 if( wndPtr->window ) CLIPBOARD_ResetOwner( wndPtr ); /* before the window is unmapped */
1042 /* Hide the window */
1044 if (wndPtr->dwStyle & WS_VISIBLE)
1046 SetWindowPos32( hwnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW |
1047 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|
1048 ((QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))?SWP_DEFERERASE:0) );
1049 if (!IsWindow32(hwnd)) return TRUE;
1052 /* Recursively destroy owned windows */
1054 if( !(wndPtr->dwStyle & WS_CHILD) )
1056 /* make sure top menu popup doesn't get destroyed */
1057 MENU_PatchResidentPopup( (HQUEUE16)0xFFFF, wndPtr );
1059 for (;;)
1061 WND *siblingPtr = wndPtr->parent->child; /* First sibling */
1062 while (siblingPtr)
1064 if (siblingPtr->owner == wndPtr)
1065 if (siblingPtr->hmemTaskQ == wndPtr->hmemTaskQ)
1066 break;
1067 else
1068 siblingPtr->owner = NULL;
1069 siblingPtr = siblingPtr->next;
1071 if (siblingPtr) DestroyWindow32( siblingPtr->hwndSelf );
1072 else break;
1075 if( !Options.managed || EVENT_CheckFocus() )
1076 WINPOS_ActivateOtherWindow(wndPtr);
1078 if( wndPtr->owner &&
1079 wndPtr->owner->hwndLastActive == wndPtr->hwndSelf )
1080 wndPtr->owner->hwndLastActive = wndPtr->owner->hwndSelf;
1083 /* Send destroy messages */
1085 WIN_SendDestroyMsg( wndPtr );
1086 if (!IsWindow32(hwnd)) return TRUE;
1088 /* Unlink now so we won't bother with the children later on */
1090 if( wndPtr->parent ) WIN_UnlinkWindow(hwnd);
1092 /* Destroy the window storage */
1094 WIN_DestroyWindow( wndPtr );
1095 return TRUE;
1099 /***********************************************************************
1100 * CloseWindow16 (USER.43)
1102 BOOL16 WINAPI CloseWindow16( HWND16 hwnd )
1104 return CloseWindow32( hwnd );
1108 /***********************************************************************
1109 * CloseWindow32 (USER32.56)
1111 BOOL32 WINAPI CloseWindow32( HWND32 hwnd )
1113 WND * wndPtr = WIN_FindWndPtr( hwnd );
1114 if (!wndPtr || (wndPtr->dwStyle & WS_CHILD)) return FALSE;
1115 ShowWindow32( hwnd, SW_MINIMIZE );
1116 return TRUE;
1120 /***********************************************************************
1121 * OpenIcon16 (USER.44)
1123 BOOL16 WINAPI OpenIcon16( HWND16 hwnd )
1125 return OpenIcon32( hwnd );
1129 /***********************************************************************
1130 * OpenIcon32 (USER32.410)
1132 BOOL32 WINAPI OpenIcon32( HWND32 hwnd )
1134 if (!IsIconic32( hwnd )) return FALSE;
1135 ShowWindow32( hwnd, SW_SHOWNORMAL );
1136 return TRUE;
1140 /***********************************************************************
1141 * WIN_FindWindow
1143 * Implementation of FindWindow() and FindWindowEx().
1145 static HWND32 WIN_FindWindow( HWND32 parent, HWND32 child, ATOM className,
1146 LPCSTR title )
1148 WND *pWnd;
1149 CLASS *pClass = NULL;
1151 if (child)
1153 if (!(pWnd = WIN_FindWndPtr( child ))) return 0;
1154 if (parent)
1156 if (!pWnd->parent || (pWnd->parent->hwndSelf != parent)) return 0;
1158 else if (pWnd->parent != pWndDesktop) return 0;
1159 pWnd = pWnd->next;
1161 else
1163 if (!(pWnd = parent ? WIN_FindWndPtr(parent) : pWndDesktop)) return 0;
1164 pWnd = pWnd->child;
1166 if (!pWnd) return 0;
1168 /* For a child window, all siblings will have the same hInstance, */
1169 /* so we can look for the class once and for all. */
1171 if (className && (pWnd->dwStyle & WS_CHILD))
1173 if (!(pClass = CLASS_FindClassByAtom( className, pWnd->hInstance )))
1174 return 0;
1178 for ( ; pWnd; pWnd = pWnd->next)
1180 if (className && !(pWnd->dwStyle & WS_CHILD))
1182 if (!(pClass = CLASS_FindClassByAtom( className, GetExePtr(pWnd->hInstance))))
1183 continue; /* Skip this window */
1186 if (pClass && (pWnd->class != pClass))
1187 continue; /* Not the right class */
1189 /* Now check the title */
1191 if (!title) return pWnd->hwndSelf;
1192 if (pWnd->text && !strcmp( pWnd->text, title )) return pWnd->hwndSelf;
1194 return 0;
1199 /***********************************************************************
1200 * FindWindow16 (USER.50)
1202 HWND16 WINAPI FindWindow16( SEGPTR className, LPCSTR title )
1204 return FindWindowEx16( 0, 0, className, title );
1208 /***********************************************************************
1209 * FindWindowEx16 (USER.427)
1211 HWND16 WINAPI FindWindowEx16( HWND16 parent, HWND16 child,
1212 SEGPTR className, LPCSTR title )
1214 ATOM atom = 0;
1216 TRACE(win, "%04x %04x '%s' '%s'\n", parent,
1217 child, HIWORD(className)?(char *)PTR_SEG_TO_LIN(className):"",
1218 title ? title : "");
1220 if (className)
1222 /* If the atom doesn't exist, then no class */
1223 /* with this name exists either. */
1224 if (!(atom = GlobalFindAtom16( className ))) return 0;
1226 return WIN_FindWindow( parent, child, atom, title );
1230 /***********************************************************************
1231 * FindWindow32A (USER32.198)
1233 HWND32 WINAPI FindWindow32A( LPCSTR className, LPCSTR title )
1235 HWND32 ret = FindWindowEx32A( 0, 0, className, title );
1236 if (!ret) SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1237 return ret;
1241 /***********************************************************************
1242 * FindWindowEx32A (USER32.199)
1244 HWND32 WINAPI FindWindowEx32A( HWND32 parent, HWND32 child,
1245 LPCSTR className, LPCSTR title )
1247 ATOM atom = 0;
1249 if (className)
1251 /* If the atom doesn't exist, then no class */
1252 /* with this name exists either. */
1253 if (!(atom = GlobalFindAtom32A( className )))
1255 SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1256 return 0;
1259 return WIN_FindWindow( parent, child, atom, title );
1263 /***********************************************************************
1264 * FindWindowEx32W (USER32.200)
1266 HWND32 WINAPI FindWindowEx32W( HWND32 parent, HWND32 child,
1267 LPCWSTR className, LPCWSTR title )
1269 ATOM atom = 0;
1270 char *buffer;
1271 HWND32 hwnd;
1273 if (className)
1275 /* If the atom doesn't exist, then no class */
1276 /* with this name exists either. */
1277 if (!(atom = GlobalFindAtom32W( className )))
1279 SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1280 return 0;
1283 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1284 hwnd = WIN_FindWindow( parent, child, atom, buffer );
1285 HeapFree( GetProcessHeap(), 0, buffer );
1286 return hwnd;
1290 /***********************************************************************
1291 * FindWindow32W (USER32.201)
1293 HWND32 WINAPI FindWindow32W( LPCWSTR className, LPCWSTR title )
1295 return FindWindowEx32W( 0, 0, className, title );
1299 /**********************************************************************
1300 * WIN_GetDesktop
1302 WND *WIN_GetDesktop(void)
1304 return pWndDesktop;
1308 /**********************************************************************
1309 * GetDesktopWindow16 (USER.286)
1311 HWND16 WINAPI GetDesktopWindow16(void)
1313 return (HWND16)pWndDesktop->hwndSelf;
1317 /**********************************************************************
1318 * GetDesktopWindow32 (USER32.232)
1320 HWND32 WINAPI GetDesktopWindow32(void)
1322 return pWndDesktop->hwndSelf;
1326 /**********************************************************************
1327 * GetDesktopHwnd (USER.278)
1329 * Exactly the same thing as GetDesktopWindow(), but not documented.
1330 * Don't ask me why...
1332 HWND16 WINAPI GetDesktopHwnd(void)
1334 return (HWND16)pWndDesktop->hwndSelf;
1338 /*******************************************************************
1339 * EnableWindow16 (USER.34)
1341 BOOL16 WINAPI EnableWindow16( HWND16 hwnd, BOOL16 enable )
1343 return EnableWindow32( hwnd, enable );
1347 /*******************************************************************
1348 * EnableWindow32 (USER32.172)
1350 BOOL32 WINAPI EnableWindow32( HWND32 hwnd, BOOL32 enable )
1352 WND *wndPtr;
1354 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1355 if (enable && (wndPtr->dwStyle & WS_DISABLED))
1357 /* Enable window */
1358 wndPtr->dwStyle &= ~WS_DISABLED;
1359 SendMessage32A( hwnd, WM_ENABLE, TRUE, 0 );
1360 return TRUE;
1362 else if (!enable && !(wndPtr->dwStyle & WS_DISABLED))
1364 /* Disable window */
1365 wndPtr->dwStyle |= WS_DISABLED;
1366 if ((hwnd == GetFocus32()) || IsChild32( hwnd, GetFocus32() ))
1367 SetFocus32( 0 ); /* A disabled window can't have the focus */
1368 if ((hwnd == GetCapture32()) || IsChild32( hwnd, GetCapture32() ))
1369 ReleaseCapture(); /* A disabled window can't capture the mouse */
1370 SendMessage32A( hwnd, WM_ENABLE, FALSE, 0 );
1371 return FALSE;
1373 return ((wndPtr->dwStyle & WS_DISABLED) != 0);
1377 /***********************************************************************
1378 * IsWindowEnabled16 (USER.35)
1380 BOOL16 WINAPI IsWindowEnabled16(HWND16 hWnd)
1382 return IsWindowEnabled32(hWnd);
1386 /***********************************************************************
1387 * IsWindowEnabled32 (USER32.349)
1389 BOOL32 WINAPI IsWindowEnabled32(HWND32 hWnd)
1391 WND * wndPtr;
1393 if (!(wndPtr = WIN_FindWndPtr(hWnd))) return FALSE;
1394 return !(wndPtr->dwStyle & WS_DISABLED);
1398 /***********************************************************************
1399 * IsWindowUnicode (USER32.350)
1401 BOOL32 WINAPI IsWindowUnicode( HWND32 hwnd )
1403 WND * wndPtr;
1405 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return FALSE;
1406 return (WINPROC_GetProcType( wndPtr->winproc ) == WIN_PROC_32W);
1410 /**********************************************************************
1411 * GetWindowWord16 (USER.133)
1413 WORD WINAPI GetWindowWord16( HWND16 hwnd, INT16 offset )
1415 return GetWindowWord32( hwnd, offset );
1419 /**********************************************************************
1420 * GetWindowWord32 (USER32.314)
1422 WORD WINAPI GetWindowWord32( HWND32 hwnd, INT32 offset )
1424 WND * wndPtr = WIN_FindWndPtr( hwnd );
1425 if (!wndPtr) return 0;
1426 if (offset >= 0)
1428 if (offset + sizeof(WORD) > wndPtr->class->cbWndExtra)
1430 WARN( win, "Invalid offset %d\n", offset );
1431 return 0;
1433 return *(WORD *)(((char *)wndPtr->wExtra) + offset);
1435 switch(offset)
1437 case GWW_ID:
1438 if (HIWORD(wndPtr->wIDmenu))
1439 WARN( win,"GWW_ID: discards high bits of 0x%08x!\n",
1440 wndPtr->wIDmenu);
1441 return (WORD)wndPtr->wIDmenu;
1442 case GWW_HWNDPARENT:
1443 return wndPtr->parent ?
1444 wndPtr->parent->hwndSelf : (
1445 wndPtr->owner ?
1446 wndPtr->owner->hwndSelf :
1448 case GWW_HINSTANCE:
1449 if (HIWORD(wndPtr->hInstance))
1450 WARN(win,"GWW_HINSTANCE: discards high bits of 0x%08x!\n",
1451 wndPtr->hInstance);
1452 return (WORD)wndPtr->hInstance;
1453 default:
1454 WARN( win, "Invalid offset %d\n", offset );
1455 return 0;
1460 /**********************************************************************
1461 * WIN_GetWindowInstance
1463 HINSTANCE32 WIN_GetWindowInstance( HWND32 hwnd )
1465 WND * wndPtr = WIN_FindWndPtr( hwnd );
1466 if (!wndPtr) return (HINSTANCE32)0;
1467 return wndPtr->hInstance;
1471 /**********************************************************************
1472 * SetWindowWord16 (USER.134)
1474 WORD WINAPI SetWindowWord16( HWND16 hwnd, INT16 offset, WORD newval )
1476 return SetWindowWord32( hwnd, offset, newval );
1480 /**********************************************************************
1481 * SetWindowWord32 (USER32.524)
1483 WORD WINAPI SetWindowWord32( HWND32 hwnd, INT32 offset, WORD newval )
1485 WORD *ptr, retval;
1486 WND * wndPtr = WIN_FindWndPtr( hwnd );
1487 if (!wndPtr) return 0;
1488 if (offset >= 0)
1490 if (offset + sizeof(WORD) > wndPtr->class->cbWndExtra)
1492 WARN( win, "Invalid offset %d\n", offset );
1493 return 0;
1495 ptr = (WORD *)(((char *)wndPtr->wExtra) + offset);
1497 else switch(offset)
1499 case GWW_ID: ptr = (WORD *)&wndPtr->wIDmenu; break;
1500 case GWW_HINSTANCE: ptr = (WORD *)&wndPtr->hInstance; break;
1501 case GWW_HWNDPARENT: return SetParent32( hwnd, newval );
1502 default:
1503 WARN( win, "Invalid offset %d\n", offset );
1504 return 0;
1506 retval = *ptr;
1507 *ptr = newval;
1508 return retval;
1512 /**********************************************************************
1513 * WIN_GetWindowLong
1515 * Helper function for GetWindowLong().
1517 static LONG WIN_GetWindowLong( HWND32 hwnd, INT32 offset, WINDOWPROCTYPE type )
1519 LONG retval;
1520 WND * wndPtr = WIN_FindWndPtr( hwnd );
1521 if (!wndPtr) return 0;
1522 if (offset >= 0)
1524 if (offset + sizeof(LONG) > wndPtr->class->cbWndExtra)
1526 WARN( win, "Invalid offset %d\n", offset );
1527 return 0;
1529 retval = *(LONG *)(((char *)wndPtr->wExtra) + offset);
1530 /* Special case for dialog window procedure */
1531 if ((offset == DWL_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG))
1532 return (LONG)WINPROC_GetProc( (HWINDOWPROC)retval, type );
1533 return retval;
1535 switch(offset)
1537 case GWL_USERDATA: return wndPtr->userdata;
1538 case GWL_STYLE: return wndPtr->dwStyle;
1539 case GWL_EXSTYLE: return wndPtr->dwExStyle;
1540 case GWL_ID: return (LONG)wndPtr->wIDmenu;
1541 case GWL_WNDPROC: return (LONG)WINPROC_GetProc( wndPtr->winproc,
1542 type );
1543 case GWL_HWNDPARENT: return wndPtr->parent ?
1544 (HWND32)wndPtr->parent->hwndSelf : 0;
1545 case GWL_HINSTANCE: return wndPtr->hInstance;
1546 default:
1547 WARN( win, "Unknown offset %d\n", offset );
1549 return 0;
1553 /**********************************************************************
1554 * WIN_SetWindowLong
1556 * Helper function for SetWindowLong().
1558 static LONG WIN_SetWindowLong( HWND32 hwnd, INT32 offset, LONG newval,
1559 WINDOWPROCTYPE type )
1561 LONG *ptr, retval;
1562 WND * wndPtr = WIN_FindWndPtr( hwnd );
1563 STYLESTRUCT style;
1565 TRACE(win,"%x=%p %x %lx %x\n",hwnd, wndPtr, offset, newval, type);
1566 if (!wndPtr) return 0;
1567 if (offset >= 0)
1569 if (offset + sizeof(LONG) > wndPtr->class->cbWndExtra)
1571 WARN( win, "Invalid offset %d\n", offset );
1572 return 0;
1574 ptr = (LONG *)(((char *)wndPtr->wExtra) + offset);
1575 /* Special case for dialog window procedure */
1576 if ((offset == DWL_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG))
1578 retval = (LONG)WINPROC_GetProc( (HWINDOWPROC)*ptr, type );
1579 WINPROC_SetProc( (HWINDOWPROC *)ptr, (WNDPROC16)newval,
1580 type, WIN_PROC_WINDOW );
1581 return retval;
1584 else switch(offset)
1586 case GWL_ID:
1587 ptr = (DWORD*)&wndPtr->wIDmenu;
1588 break;
1589 case GWL_HINSTANCE:
1590 return SetWindowWord32( hwnd, offset, newval );
1591 case GWL_WNDPROC:
1592 retval = (LONG)WINPROC_GetProc( wndPtr->winproc, type );
1593 WINPROC_SetProc( &wndPtr->winproc, (WNDPROC16)newval,
1594 type, WIN_PROC_WINDOW );
1595 return retval;
1596 case GWL_STYLE:
1597 if (wndPtr->flags & WIN_ISWIN32)
1598 { style.styleOld = wndPtr->dwStyle;
1599 newval &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way */
1600 style.styleNew = newval | (style.styleOld & (WS_VISIBLE | WS_CHILD));
1602 SendMessage32A(hwnd,WM_STYLECHANGING,GWL_STYLE,(LPARAM)&style);
1603 wndPtr->dwStyle = style.styleNew;
1604 SendMessage32A(hwnd,WM_STYLECHANGED,GWL_STYLE,(LPARAM)&style);
1605 UpdateWindow32(hwnd);
1606 return style.styleOld;
1608 case GWL_USERDATA:
1609 ptr = &wndPtr->userdata;
1610 break;
1611 case GWL_EXSTYLE:
1612 if (wndPtr->flags & WIN_ISWIN32)
1613 { style.styleOld = wndPtr->dwExStyle;
1614 style.styleNew = newval;
1615 SendMessage32A(hwnd,WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&style);
1616 wndPtr->dwExStyle = newval;
1617 SendMessage32A(hwnd,WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&style);
1618 UpdateWindow32(hwnd);
1619 return style.styleOld;
1621 default:
1622 WARN( win, "Invalid offset %d\n", offset );
1623 return 0;
1625 retval = *ptr;
1626 *ptr = newval;
1627 return retval;
1631 /**********************************************************************
1632 * GetWindowLong16 (USER.135)
1634 LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
1636 return WIN_GetWindowLong( (HWND32)hwnd, offset, WIN_PROC_16 );
1640 /**********************************************************************
1641 * GetWindowLong32A (USER32.305)
1643 LONG WINAPI GetWindowLong32A( HWND32 hwnd, INT32 offset )
1645 return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32A );
1649 /**********************************************************************
1650 * GetWindowLong32W (USER32.306)
1652 LONG WINAPI GetWindowLong32W( HWND32 hwnd, INT32 offset )
1654 return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32W );
1658 /**********************************************************************
1659 * SetWindowLong16 (USER.136)
1661 LONG WINAPI SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
1663 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_16 );
1667 /**********************************************************************
1668 * SetWindowLong32A (USER32.517)
1670 LONG WINAPI SetWindowLong32A( HWND32 hwnd, INT32 offset, LONG newval )
1672 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32A );
1676 /**********************************************************************
1677 * SetWindowLong32W (USER32.518) Set window attribute
1679 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
1680 * value in a window's extra memory.
1682 * The _hwnd_ parameter specifies the window. is the handle to a
1683 * window that has extra memory. The _newval_ parameter contains the
1684 * new attribute or extra memory value. If positive, the _offset_
1685 * parameter is the byte-addressed location in the window's extra
1686 * memory to set. If negative, _offset_ specifies the window
1687 * attribute to set, and should be one of the following values:
1689 * GWL_EXSTYLE The window's extended window style
1691 * GWL_STYLE The window's window style.
1693 * GWL_WNDPROC Pointer to the window's window procedure.
1695 * GWL_HINSTANCE The window's pplication instance handle.
1697 * GWL_ID The window's identifier.
1699 * GWL_USERDATA The window's user-specified data.
1701 * If the window is a dialog box, the _offset_ parameter can be one of
1702 * the following values:
1704 * DWL_DLGPROC The address of the window's dialog box procedure.
1706 * DWL_MSGRESULT The return value of a message
1707 * that the dialog box procedure processed.
1709 * DWL_USER Application specific information.
1711 * RETURNS
1713 * If successful, returns the previous value located at _offset_. Otherwise,
1714 * returns 0.
1716 * NOTES
1718 * Extra memory for a window class is specified by a nonzero cbWndExtra
1719 * parameter of the WNDCLASS structure passed to RegisterClass() at the
1720 * time of class creation.
1722 * Using GWL_WNDPROC to set a new window procedure effectively creates
1723 * a window subclass. Use CallWindowProc() in the new windows procedure
1724 * to pass messages to the superclass's window procedure.
1726 * The user data is reserved for use by the application which created
1727 * the window.
1729 * Do not use GWL_STYLE to change the window's WS_DISABLE style;
1730 * instead, call the EnableWindow() function to change the window's
1731 * disabled state.
1733 * Do not use GWL_HWNDPARENT to reset the window's parent, use
1734 * SetParent() instead.
1736 * BUGS
1738 * GWL_STYLE does not dispatch WM_STYLE_... messages.
1740 * CONFORMANCE
1742 * ECMA-234, Win32
1745 LONG WINAPI SetWindowLong32W(
1746 HWND32 hwnd, /* window to alter */
1747 INT32 offset, /* offset, in bytes, of location to alter */
1748 LONG newval /* new value of location */
1750 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32W );
1754 /*******************************************************************
1755 * GetWindowText16 (USER.36)
1757 INT16 WINAPI GetWindowText16( HWND16 hwnd, SEGPTR lpString, INT16 nMaxCount )
1759 return (INT16)SendMessage16(hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
1763 /*******************************************************************
1764 * GetWindowText32A (USER32.309)
1766 INT32 WINAPI GetWindowText32A( HWND32 hwnd, LPSTR lpString, INT32 nMaxCount )
1768 return (INT32)SendMessage32A( hwnd, WM_GETTEXT, nMaxCount,
1769 (LPARAM)lpString );
1772 /*******************************************************************
1773 * InternalGetWindowText (USER32.326)
1775 INT32 WINAPI InternalGetWindowText(HWND32 hwnd,LPWSTR lpString,INT32 nMaxCount )
1777 FIXME(win,"(0x%08x,%s,0x%x),stub!\n",hwnd,debugstr_w(lpString),nMaxCount);
1778 return GetWindowText32W(hwnd,lpString,nMaxCount);
1782 /*******************************************************************
1783 * GetWindowText32W (USER32.312)
1785 INT32 WINAPI GetWindowText32W( HWND32 hwnd, LPWSTR lpString, INT32 nMaxCount )
1787 return (INT32)SendMessage32W( hwnd, WM_GETTEXT, nMaxCount,
1788 (LPARAM)lpString );
1792 /*******************************************************************
1793 * SetWindowText16 (USER.37)
1795 void WINAPI SetWindowText16( HWND16 hwnd, SEGPTR lpString )
1797 SendMessage16( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
1801 /*******************************************************************
1802 * SetWindowText32A (USER32.521)
1804 void WINAPI SetWindowText32A( HWND32 hwnd, LPCSTR lpString )
1806 SendMessage32A( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
1810 /*******************************************************************
1811 * SetWindowText32W (USER32.523)
1813 void WINAPI SetWindowText32W( HWND32 hwnd, LPCWSTR lpString )
1815 SendMessage32W( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
1819 /*******************************************************************
1820 * GetWindowTextLength16 (USER.38)
1822 INT16 WINAPI GetWindowTextLength16( HWND16 hwnd )
1824 return (INT16)SendMessage16( hwnd, WM_GETTEXTLENGTH, 0, 0 );
1828 /*******************************************************************
1829 * GetWindowTextLength32A (USER32.310)
1831 INT32 WINAPI GetWindowTextLength32A( HWND32 hwnd )
1833 return SendMessage32A( hwnd, WM_GETTEXTLENGTH, 0, 0 );
1836 /*******************************************************************
1837 * GetWindowTextLength32W (USER32.311)
1839 INT32 WINAPI GetWindowTextLength32W( HWND32 hwnd )
1841 return SendMessage32W( hwnd, WM_GETTEXTLENGTH, 0, 0 );
1845 /*******************************************************************
1846 * IsWindow16 (USER.47)
1848 BOOL16 WINAPI IsWindow16( HWND16 hwnd )
1850 return IsWindow32( hwnd );
1853 void WINAPI WIN16_IsWindow16( CONTEXT *context )
1855 WORD *stack = PTR_SEG_OFF_TO_LIN(SS_reg(context), SP_reg(context));
1856 HWND16 hwnd = (HWND16)stack[2];
1858 AX_reg(context) = IsWindow32( hwnd );
1859 ES_reg(context) = USER_HeapSel;
1863 /*******************************************************************
1864 * IsWindow32 (USER32.348)
1866 BOOL32 WINAPI IsWindow32( HWND32 hwnd )
1868 WND * wndPtr = WIN_FindWndPtr( hwnd );
1869 return ((wndPtr != NULL) && (wndPtr->dwMagic == WND_MAGIC));
1873 /*****************************************************************
1874 * GetParent16 (USER.46)
1876 HWND16 WINAPI GetParent16( HWND16 hwnd )
1878 return (HWND16)GetParent32( hwnd );
1882 /*****************************************************************
1883 * GetParent32 (USER32.278)
1885 HWND32 WINAPI GetParent32( HWND32 hwnd )
1887 WND *wndPtr = WIN_FindWndPtr(hwnd);
1888 if ((!wndPtr) || (!(wndPtr->dwStyle & (WS_POPUP|WS_CHILD)))) return 0;
1889 wndPtr = (wndPtr->dwStyle & WS_CHILD) ? wndPtr->parent : wndPtr->owner;
1890 return wndPtr ? wndPtr->hwndSelf : 0;
1893 /*****************************************************************
1894 * WIN_GetTopParent
1896 * Get the top-level parent for a child window.
1898 WND* WIN_GetTopParentPtr( WND* pWnd )
1900 while( pWnd && (pWnd->dwStyle & WS_CHILD)) pWnd = pWnd->parent;
1901 return pWnd;
1904 /*****************************************************************
1905 * WIN_GetTopParent
1907 * Get the top-level parent for a child window.
1909 HWND32 WIN_GetTopParent( HWND32 hwnd )
1911 WND *wndPtr = WIN_GetTopParentPtr ( WIN_FindWndPtr( hwnd ) );
1912 return wndPtr ? wndPtr->hwndSelf : 0;
1916 /*****************************************************************
1917 * SetParent16 (USER.233)
1919 HWND16 WINAPI SetParent16( HWND16 hwndChild, HWND16 hwndNewParent )
1921 return SetParent32( hwndChild, hwndNewParent );
1925 /*****************************************************************
1926 * SetParent32 (USER32.495)
1928 HWND32 WINAPI SetParent32( HWND32 hwndChild, HWND32 hwndNewParent )
1930 WND *wndPtr = WIN_FindWndPtr( hwndChild );
1931 WND *pWndParent = (hwndNewParent) ? WIN_FindWndPtr( hwndNewParent )
1932 : pWndDesktop;
1934 if( wndPtr && pWndParent && (wndPtr != pWndDesktop) )
1936 WND* pWndPrev = wndPtr->parent;
1938 if( pWndParent != pWndPrev )
1940 BOOL32 bFixupDCE = IsWindowVisible32(hwndChild);
1942 if ( wndPtr->window )
1944 /* Toplevel window needs to be reparented. Used by Tk 8.0 */
1946 TSXDestroyWindow( display, wndPtr->window );
1947 wndPtr->window = None;
1949 else if( bFixupDCE )
1950 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
1952 WIN_UnlinkWindow(hwndChild);
1953 wndPtr->parent = pWndParent;
1955 /* FIXME: Create an X counterpart for reparented top-level windows
1956 * when not in the desktop mode. */
1958 if ( pWndParent != pWndDesktop ) wndPtr->dwStyle |= WS_CHILD;
1959 WIN_LinkWindow(hwndChild, HWND_BOTTOM);
1961 if( bFixupDCE )
1963 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
1964 UpdateWindow32(hwndChild);
1967 return pWndPrev->hwndSelf;
1968 } /* failure */
1969 return 0;
1973 /*******************************************************************
1974 * IsChild16 (USER.48)
1976 BOOL16 WINAPI IsChild16( HWND16 parent, HWND16 child )
1978 return IsChild32(parent,child);
1982 /*******************************************************************
1983 * IsChild32 (USER32.339)
1985 BOOL32 WINAPI IsChild32( HWND32 parent, HWND32 child )
1987 WND * wndPtr = WIN_FindWndPtr( child );
1988 while (wndPtr && (wndPtr->dwStyle & WS_CHILD))
1990 wndPtr = wndPtr->parent;
1991 if (wndPtr->hwndSelf == parent) return TRUE;
1993 return FALSE;
1997 /***********************************************************************
1998 * IsWindowVisible16 (USER.49)
2000 BOOL16 WINAPI IsWindowVisible16( HWND16 hwnd )
2002 return IsWindowVisible32(hwnd);
2006 /***********************************************************************
2007 * IsWindowVisible32 (USER32.351)
2009 BOOL32 WINAPI IsWindowVisible32( HWND32 hwnd )
2011 WND *wndPtr = WIN_FindWndPtr( hwnd );
2012 while (wndPtr && (wndPtr->dwStyle & WS_CHILD))
2014 if (!(wndPtr->dwStyle & WS_VISIBLE)) return FALSE;
2015 wndPtr = wndPtr->parent;
2017 return (wndPtr && (wndPtr->dwStyle & WS_VISIBLE));
2021 /***********************************************************************
2022 * WIN_IsWindowDrawable
2024 * hwnd is drawable when it is visible, all parents are not
2025 * minimized, and it is itself not minimized unless we are
2026 * trying to draw its default class icon.
2028 BOOL32 WIN_IsWindowDrawable( WND* wnd, BOOL32 icon )
2030 if( (wnd->dwStyle & WS_MINIMIZE &&
2031 icon && wnd->class->hIcon) ||
2032 !(wnd->dwStyle & WS_VISIBLE) ) return FALSE;
2033 for(wnd = wnd->parent; wnd; wnd = wnd->parent)
2034 if( wnd->dwStyle & WS_MINIMIZE ||
2035 !(wnd->dwStyle & WS_VISIBLE) ) break;
2036 return (wnd == NULL);
2040 /*******************************************************************
2041 * GetTopWindow16 (USER.229)
2043 HWND16 WINAPI GetTopWindow16( HWND16 hwnd )
2045 return GetTopWindow32(hwnd);
2049 /*******************************************************************
2050 * GetTopWindow32 (USER.229)
2052 HWND32 WINAPI GetTopWindow32( HWND32 hwnd )
2054 WND * wndPtr = WIN_FindWndPtr( hwnd );
2055 if (wndPtr && wndPtr->child) return wndPtr->child->hwndSelf;
2056 else return 0;
2060 /*******************************************************************
2061 * GetWindow16 (USER.262)
2063 HWND16 WINAPI GetWindow16( HWND16 hwnd, WORD rel )
2065 return GetWindow32( hwnd,rel );
2069 /*******************************************************************
2070 * GetWindow32 (USER32.302)
2072 HWND32 WINAPI GetWindow32( HWND32 hwnd, WORD rel )
2074 WND * wndPtr = WIN_FindWndPtr( hwnd );
2075 if (!wndPtr) return 0;
2076 switch(rel)
2078 case GW_HWNDFIRST:
2079 if (wndPtr->parent) return wndPtr->parent->child->hwndSelf;
2080 else return 0;
2082 case GW_HWNDLAST:
2083 if (!wndPtr->parent) return 0; /* Desktop window */
2084 while (wndPtr->next) wndPtr = wndPtr->next;
2085 return wndPtr->hwndSelf;
2087 case GW_HWNDNEXT:
2088 if (!wndPtr->next) return 0;
2089 return wndPtr->next->hwndSelf;
2091 case GW_HWNDPREV:
2092 if (!wndPtr->parent) return 0; /* Desktop window */
2093 wndPtr = wndPtr->parent->child; /* First sibling */
2094 if (wndPtr->hwndSelf == hwnd) return 0; /* First in list */
2095 while (wndPtr->next)
2097 if (wndPtr->next->hwndSelf == hwnd) return wndPtr->hwndSelf;
2098 wndPtr = wndPtr->next;
2100 return 0;
2102 case GW_OWNER:
2103 return wndPtr->owner ? wndPtr->owner->hwndSelf : 0;
2105 case GW_CHILD:
2106 return wndPtr->child ? wndPtr->child->hwndSelf : 0;
2108 return 0;
2112 /*******************************************************************
2113 * GetNextWindow16 (USER.230)
2115 HWND16 WINAPI GetNextWindow16( HWND16 hwnd, WORD flag )
2117 if ((flag != GW_HWNDNEXT) && (flag != GW_HWNDPREV)) return 0;
2118 return GetWindow16( hwnd, flag );
2121 /*******************************************************************
2122 * ShowOwnedPopups16 (USER.265)
2124 void WINAPI ShowOwnedPopups16( HWND16 owner, BOOL16 fShow )
2126 ShowOwnedPopups32( owner, fShow );
2130 /*******************************************************************
2131 * ShowOwnedPopups32 (USER32.531)
2133 BOOL32 WINAPI ShowOwnedPopups32( HWND32 owner, BOOL32 fShow )
2135 WND *pWnd = pWndDesktop->child;
2136 while (pWnd)
2138 if (pWnd->owner && (pWnd->owner->hwndSelf == owner) &&
2139 (pWnd->dwStyle & WS_POPUP))
2140 ShowWindow32( pWnd->hwndSelf, fShow ? SW_SHOW : SW_HIDE );
2141 pWnd = pWnd->next;
2143 return TRUE;
2147 /*******************************************************************
2148 * GetLastActivePopup16 (USER.287)
2150 HWND16 WINAPI GetLastActivePopup16( HWND16 hwnd )
2152 return GetLastActivePopup32( hwnd );
2155 /*******************************************************************
2156 * GetLastActivePopup32 (USER32.256)
2158 HWND32 WINAPI GetLastActivePopup32( HWND32 hwnd )
2160 WND *wndPtr;
2161 wndPtr = WIN_FindWndPtr(hwnd);
2162 if (wndPtr == NULL) return hwnd;
2163 return wndPtr->hwndLastActive;
2167 /*******************************************************************
2168 * WIN_BuildWinArray
2170 * Build an array of pointers to the children of a given window.
2171 * The array must be freed with HeapFree(SystemHeap). Return NULL
2172 * when no windows are found.
2174 WND **WIN_BuildWinArray( WND *wndPtr, UINT32 bwaFlags, UINT32* pTotal )
2176 WND **list, **ppWnd;
2177 WND *pWnd;
2178 UINT32 count, skipOwned, skipHidden;
2179 DWORD skipFlags;
2181 skipHidden = bwaFlags & BWA_SKIPHIDDEN;
2182 skipOwned = bwaFlags & BWA_SKIPOWNED;
2183 skipFlags = (bwaFlags & BWA_SKIPDISABLED) ? WS_DISABLED : 0;
2184 if( bwaFlags & BWA_SKIPICONIC ) skipFlags |= WS_MINIMIZE;
2186 /* First count the windows */
2188 if (!wndPtr) wndPtr = pWndDesktop;
2189 for (pWnd = wndPtr->child, count = 0; pWnd; pWnd = pWnd->next)
2191 if( (pWnd->dwStyle & skipFlags) || (skipOwned && pWnd->owner) ) continue;
2192 if( !skipHidden || pWnd->dwStyle & WS_VISIBLE ) count++;
2195 if( count )
2197 /* Now build the list of all windows */
2199 if ((list = (WND **)HeapAlloc( SystemHeap, 0, sizeof(WND *) * (count + 1))))
2201 for (pWnd = wndPtr->child, ppWnd = list, count = 0; pWnd; pWnd = pWnd->next)
2203 if( (pWnd->dwStyle & skipFlags) || (skipOwned && pWnd->owner) ) continue;
2204 if( !skipHidden || pWnd->dwStyle & WS_VISIBLE )
2206 *ppWnd++ = pWnd;
2207 count++;
2210 *ppWnd = NULL;
2212 else count = 0;
2213 } else list = NULL;
2215 if( pTotal ) *pTotal = count;
2216 return list;
2220 /*******************************************************************
2221 * EnumWindows16 (USER.54)
2223 BOOL16 WINAPI EnumWindows16( WNDENUMPROC16 lpEnumFunc, LPARAM lParam )
2225 WND **list, **ppWnd;
2227 /* We have to build a list of all windows first, to avoid */
2228 /* unpleasant side-effects, for instance if the callback */
2229 /* function changes the Z-order of the windows. */
2231 if (!(list = WIN_BuildWinArray( pWndDesktop, 0, NULL ))) return FALSE;
2233 /* Now call the callback function for every window */
2235 for (ppWnd = list; *ppWnd; ppWnd++)
2237 /* Make sure that the window still exists */
2238 if (!IsWindow32((*ppWnd)->hwndSelf)) continue;
2239 if (!lpEnumFunc( (*ppWnd)->hwndSelf, lParam )) break;
2241 HeapFree( SystemHeap, 0, list );
2242 return TRUE;
2246 /*******************************************************************
2247 * EnumWindows32 (USER32.193)
2249 BOOL32 WINAPI EnumWindows32( WNDENUMPROC32 lpEnumFunc, LPARAM lParam )
2251 return (BOOL32)EnumWindows16( (WNDENUMPROC16)lpEnumFunc, lParam );
2255 /**********************************************************************
2256 * EnumTaskWindows16 (USER.225)
2258 BOOL16 WINAPI EnumTaskWindows16( HTASK16 hTask, WNDENUMPROC16 func,
2259 LPARAM lParam )
2261 WND **list, **ppWnd;
2262 HQUEUE16 hQueue = GetTaskQueue( hTask );
2264 /* This function is the same as EnumWindows(), */
2265 /* except for an added check on the window queue. */
2267 if (!(list = WIN_BuildWinArray( pWndDesktop, 0, NULL ))) return FALSE;
2269 /* Now call the callback function for every window */
2271 for (ppWnd = list; *ppWnd; ppWnd++)
2273 /* Make sure that the window still exists */
2274 if (!IsWindow32((*ppWnd)->hwndSelf)) continue;
2275 if ((*ppWnd)->hmemTaskQ != hQueue) continue; /* Check the queue */
2276 if (!func( (*ppWnd)->hwndSelf, lParam )) break;
2278 HeapFree( SystemHeap, 0, list );
2279 return TRUE;
2283 /**********************************************************************
2284 * EnumThreadWindows (USER32.190)
2286 BOOL32 WINAPI EnumThreadWindows( DWORD id, WNDENUMPROC32 func, LPARAM lParam )
2288 THDB *tdb = THREAD_ID_TO_THDB(id);
2290 return (BOOL16)EnumTaskWindows16(tdb->teb.htask16, (WNDENUMPROC16)func, lParam);
2294 /**********************************************************************
2295 * WIN_EnumChildWindows
2297 * Helper function for EnumChildWindows().
2299 static BOOL16 WIN_EnumChildWindows( WND **ppWnd, WNDENUMPROC16 func,
2300 LPARAM lParam )
2302 WND **childList;
2303 BOOL16 ret = FALSE;
2305 for ( ; *ppWnd; ppWnd++)
2307 /* Make sure that the window still exists */
2308 if (!IsWindow32((*ppWnd)->hwndSelf)) continue;
2309 /* Build children list first */
2310 childList = WIN_BuildWinArray( *ppWnd, BWA_SKIPOWNED, NULL );
2311 ret = func( (*ppWnd)->hwndSelf, lParam );
2312 if (childList)
2314 if (ret) ret = WIN_EnumChildWindows( childList, func, lParam );
2315 HeapFree( SystemHeap, 0, childList );
2317 if (!ret) return FALSE;
2319 return TRUE;
2323 /**********************************************************************
2324 * EnumChildWindows16 (USER.55)
2326 BOOL16 WINAPI EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func,
2327 LPARAM lParam )
2329 WND **list, *pParent;
2331 if (!(pParent = WIN_FindWndPtr( parent ))) return FALSE;
2332 if (!(list = WIN_BuildWinArray( pParent, BWA_SKIPOWNED, NULL ))) return FALSE;
2333 WIN_EnumChildWindows( list, func, lParam );
2334 HeapFree( SystemHeap, 0, list );
2335 return TRUE;
2339 /**********************************************************************
2340 * EnumChildWindows32 (USER32.178)
2342 BOOL32 WINAPI EnumChildWindows32( HWND32 parent, WNDENUMPROC32 func,
2343 LPARAM lParam )
2345 return (BOOL32)EnumChildWindows16( (HWND16)parent, (WNDENUMPROC16)func,
2346 lParam );
2350 /*******************************************************************
2351 * AnyPopup16 (USER.52)
2353 BOOL16 WINAPI AnyPopup16(void)
2355 return AnyPopup32();
2359 /*******************************************************************
2360 * AnyPopup32 (USER32.4)
2362 BOOL32 WINAPI AnyPopup32(void)
2364 WND *wndPtr;
2365 for (wndPtr = pWndDesktop->child; wndPtr; wndPtr = wndPtr->next)
2366 if (wndPtr->owner && (wndPtr->dwStyle & WS_VISIBLE)) return TRUE;
2367 return FALSE;
2371 /*******************************************************************
2372 * FlashWindow16 (USER.105)
2374 BOOL16 WINAPI FlashWindow16( HWND16 hWnd, BOOL16 bInvert )
2376 return FlashWindow32( hWnd, bInvert );
2380 /*******************************************************************
2381 * FlashWindow32 (USER32.202)
2383 BOOL32 WINAPI FlashWindow32( HWND32 hWnd, BOOL32 bInvert )
2385 WND *wndPtr = WIN_FindWndPtr(hWnd);
2387 TRACE(win,"%04x\n", hWnd);
2389 if (!wndPtr) return FALSE;
2391 if (wndPtr->dwStyle & WS_MINIMIZE)
2393 if (bInvert && !(wndPtr->flags & WIN_NCACTIVATED))
2395 HDC32 hDC = GetDC32(hWnd);
2397 if (!SendMessage16( hWnd, WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
2398 wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
2400 ReleaseDC32( hWnd, hDC );
2401 wndPtr->flags |= WIN_NCACTIVATED;
2403 else
2405 PAINT_RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE | RDW_ERASE |
2406 RDW_UPDATENOW | RDW_FRAME, 0 );
2407 wndPtr->flags &= ~WIN_NCACTIVATED;
2409 return TRUE;
2411 else
2413 WPARAM16 wparam;
2414 if (bInvert) wparam = !(wndPtr->flags & WIN_NCACTIVATED);
2415 else wparam = (hWnd == GetActiveWindow32());
2417 SendMessage16( hWnd, WM_NCACTIVATE, wparam, (LPARAM)0 );
2418 return wparam;
2423 /*******************************************************************
2424 * SetSysModalWindow16 (USER.188)
2426 HWND16 WINAPI SetSysModalWindow16( HWND16 hWnd )
2428 HWND32 hWndOldModal = hwndSysModal;
2429 hwndSysModal = hWnd;
2430 FIXME(win, "EMPTY STUB !! SetSysModalWindow(%04x) !\n", hWnd);
2431 return hWndOldModal;
2435 /*******************************************************************
2436 * GetSysModalWindow16 (USER.52)
2438 HWND16 WINAPI GetSysModalWindow16(void)
2440 return hwndSysModal;
2444 /*******************************************************************
2445 * GetWindowContextHelpId (USER32.303)
2447 DWORD WINAPI GetWindowContextHelpId( HWND32 hwnd )
2449 WND *wnd = WIN_FindWndPtr( hwnd );
2450 if (!wnd) return 0;
2451 return wnd->helpContext;
2455 /*******************************************************************
2456 * SetWindowContextHelpId (USER32.515)
2458 BOOL32 WINAPI SetWindowContextHelpId( HWND32 hwnd, DWORD id )
2460 WND *wnd = WIN_FindWndPtr( hwnd );
2461 if (!wnd) return FALSE;
2462 wnd->helpContext = id;
2463 return TRUE;
2467 /*******************************************************************
2468 * DRAG_QueryUpdate
2470 * recursively find a child that contains spDragInfo->pt point
2471 * and send WM_QUERYDROPOBJECT
2473 BOOL16 DRAG_QueryUpdate( HWND32 hQueryWnd, SEGPTR spDragInfo, BOOL32 bNoSend )
2475 BOOL16 wParam,bResult = 0;
2476 POINT32 pt;
2477 LPDRAGINFO ptrDragInfo = (LPDRAGINFO) PTR_SEG_TO_LIN(spDragInfo);
2478 WND *ptrQueryWnd = WIN_FindWndPtr(hQueryWnd),*ptrWnd;
2479 RECT32 tempRect;
2481 if( !ptrQueryWnd || !ptrDragInfo ) return 0;
2483 CONV_POINT16TO32( &ptrDragInfo->pt, &pt );
2485 GetWindowRect32(hQueryWnd,&tempRect);
2487 if( !PtInRect32(&tempRect,pt) ||
2488 (ptrQueryWnd->dwStyle & WS_DISABLED) )
2489 return 0;
2491 if( !(ptrQueryWnd->dwStyle & WS_MINIMIZE) )
2493 tempRect = ptrQueryWnd->rectClient;
2494 if(ptrQueryWnd->dwStyle & WS_CHILD)
2495 MapWindowPoints32( ptrQueryWnd->parent->hwndSelf, 0,
2496 (LPPOINT32)&tempRect, 2 );
2498 if (PtInRect32( &tempRect, pt))
2500 wParam = 0;
2502 for (ptrWnd = ptrQueryWnd->child; ptrWnd ;ptrWnd = ptrWnd->next)
2503 if( ptrWnd->dwStyle & WS_VISIBLE )
2505 GetWindowRect32( ptrWnd->hwndSelf, &tempRect );
2506 if (PtInRect32( &tempRect, pt )) break;
2509 if(ptrWnd)
2511 TRACE(msg,"hwnd = %04x, %d %d - %d %d\n",
2512 ptrWnd->hwndSelf, ptrWnd->rectWindow.left, ptrWnd->rectWindow.top,
2513 ptrWnd->rectWindow.right, ptrWnd->rectWindow.bottom );
2514 if( !(ptrWnd->dwStyle & WS_DISABLED) )
2515 bResult = DRAG_QueryUpdate(ptrWnd->hwndSelf, spDragInfo, bNoSend);
2518 if(bResult) return bResult;
2520 else wParam = 1;
2522 else wParam = 1;
2524 ScreenToClient16(hQueryWnd,&ptrDragInfo->pt);
2526 ptrDragInfo->hScope = hQueryWnd;
2528 bResult = ( bNoSend )
2529 ? ptrQueryWnd->dwExStyle & WS_EX_ACCEPTFILES
2530 : SendMessage16( hQueryWnd ,WM_QUERYDROPOBJECT ,
2531 (WPARAM16)wParam ,(LPARAM) spDragInfo );
2532 if( !bResult )
2533 CONV_POINT32TO16( &pt, &ptrDragInfo->pt );
2535 return bResult;
2539 /*******************************************************************
2540 * DragDetect (USER.465)
2542 BOOL16 WINAPI DragDetect16( HWND16 hWnd, POINT16 pt )
2544 POINT32 pt32;
2545 CONV_POINT16TO32( &pt, &pt32 );
2546 return DragDetect32( hWnd, pt32 );
2549 /*******************************************************************
2550 * DragDetect32 (USER32.151)
2552 BOOL32 WINAPI DragDetect32( HWND32 hWnd, POINT32 pt )
2554 MSG16 msg;
2555 RECT16 rect;
2557 rect.left = pt.x - wDragWidth;
2558 rect.right = pt.x + wDragWidth;
2560 rect.top = pt.y - wDragHeight;
2561 rect.bottom = pt.y + wDragHeight;
2563 SetCapture32(hWnd);
2565 while(1)
2567 while(PeekMessage16(&msg ,0 ,WM_MOUSEFIRST ,WM_MOUSELAST ,PM_REMOVE))
2569 if( msg.message == WM_LBUTTONUP )
2571 ReleaseCapture();
2572 return 0;
2574 if( msg.message == WM_MOUSEMOVE )
2576 if( !PtInRect16( &rect, MAKEPOINT16(msg.lParam) ) )
2578 ReleaseCapture();
2579 return 1;
2583 WaitMessage();
2585 return 0;
2588 /******************************************************************************
2589 * DragObject16 (USER.464)
2591 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
2592 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
2594 MSG16 msg;
2595 LPDRAGINFO lpDragInfo;
2596 SEGPTR spDragInfo;
2597 HCURSOR16 hDragCursor=0, hOldCursor=0, hBummer=0;
2598 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO));
2599 WND *wndPtr = WIN_FindWndPtr(hWnd);
2600 HCURSOR16 hCurrentCursor = 0;
2601 HWND16 hCurrentWnd = 0;
2603 lpDragInfo = (LPDRAGINFO) GlobalLock16(hDragInfo);
2604 spDragInfo = (SEGPTR) WIN16_GlobalLock16(hDragInfo);
2606 if( !lpDragInfo || !spDragInfo ) return 0L;
2608 hBummer = LoadCursor16(0, IDC_BUMMER16);
2610 if( !hBummer || !wndPtr )
2612 GlobalFree16(hDragInfo);
2613 return 0L;
2616 if(hCursor)
2618 if( !(hDragCursor = CURSORICON_IconToCursor(hCursor, FALSE)) )
2620 GlobalFree16(hDragInfo);
2621 return 0L;
2624 if( hDragCursor == hCursor ) hDragCursor = 0;
2625 else hCursor = hDragCursor;
2627 hOldCursor = SetCursor32(hDragCursor);
2630 lpDragInfo->hWnd = hWnd;
2631 lpDragInfo->hScope = 0;
2632 lpDragInfo->wFlags = wObj;
2633 lpDragInfo->hList = szList; /* near pointer! */
2634 lpDragInfo->hOfStruct = hOfStruct;
2635 lpDragInfo->l = 0L;
2637 SetCapture32(hWnd);
2638 ShowCursor32( TRUE );
2642 do{ WaitMessage(); }
2643 while( !PeekMessage16(&msg,0,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE) );
2645 *(lpDragInfo+1) = *lpDragInfo;
2647 lpDragInfo->pt = msg.pt;
2649 /* update DRAGINFO struct */
2650 TRACE(msg,"lpDI->hScope = %04x\n",lpDragInfo->hScope);
2652 if( DRAG_QueryUpdate(hwndScope, spDragInfo, FALSE) > 0 )
2653 hCurrentCursor = hCursor;
2654 else
2656 hCurrentCursor = hBummer;
2657 lpDragInfo->hScope = 0;
2659 if( hCurrentCursor )
2660 SetCursor32(hCurrentCursor);
2662 /* send WM_DRAGLOOP */
2663 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
2664 (LPARAM) spDragInfo );
2665 /* send WM_DRAGSELECT or WM_DRAGMOVE */
2666 if( hCurrentWnd != lpDragInfo->hScope )
2668 if( hCurrentWnd )
2669 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
2670 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO),
2671 HIWORD(spDragInfo)) );
2672 hCurrentWnd = lpDragInfo->hScope;
2673 if( hCurrentWnd )
2674 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
2676 else
2677 if( hCurrentWnd )
2678 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
2680 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
2682 ReleaseCapture();
2683 ShowCursor32( FALSE );
2685 if( hCursor )
2687 SetCursor32( hOldCursor );
2688 if (hDragCursor) DestroyCursor32( hDragCursor );
2691 if( hCurrentCursor != hBummer )
2692 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
2693 (WPARAM16)hWnd, (LPARAM)spDragInfo );
2694 else
2695 msg.lParam = 0;
2696 GlobalFree16(hDragInfo);
2698 return (DWORD)(msg.lParam);