2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
21 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(x11drv);
29 extern Pixmap X11DRV_BITMAP_Pixmap( HBITMAP );
31 #define HAS_DLGFRAME(style,exStyle) \
32 (((exStyle) & WS_EX_DLGMODALFRAME) || \
33 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
35 /* X context to associate a hwnd to an X window */
36 XContext winContext = 0;
38 Atom wmProtocols = None;
39 Atom wmDeleteWindow = None;
40 Atom wmTakeFocus = None;
41 Atom dndProtocol = None;
42 Atom dndSelection = None;
43 Atom wmChangeState = None;
44 Atom kwmDockWindow = None;
45 Atom _kde_net_wm_system_tray_window_for = None; /* KDE 2 Final */
48 /***********************************************************************
51 * Check if a given window should be managed
53 inline static BOOL is_window_managed( WND *win )
55 if (!Options.managed) return FALSE;
57 /* tray window is always managed */
58 if (win->dwExStyle & WS_EX_TRAYWINDOW) return TRUE;
59 /* child windows are not managed */
60 if (win->dwStyle & WS_CHILD) return FALSE;
61 /* tool windows are not managed */
62 if (win->dwExStyle & WS_EX_TOOLWINDOW) return FALSE;
63 /* windows with caption or thick frame are managed */
64 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) return TRUE;
65 if (win->dwStyle & WS_THICKFRAME) return TRUE;
66 /* default: not managed */
71 /***********************************************************************
74 * Check if a given window is a top level X11 window
76 inline static BOOL is_window_top_level( WND *win )
78 return (root_window == DefaultRootWindow(gdi_display) &&
79 win->parent->hwndSelf == GetDesktopWindow());
83 /***********************************************************************
84 * is_client_window_mapped
86 * Check if the X client window should be mapped
88 inline static BOOL is_client_window_mapped( WND *win )
90 struct x11drv_win_data *data = win->pDriverData;
91 return !(win->dwStyle & WS_MINIMIZE) && !IsRectEmpty( &data->client_rect );
95 /***********************************************************************
96 * get_window_attributes
98 * Fill the window attributes structure for an X window.
99 * Returned cursor must be freed by caller.
101 static int get_window_attributes( Display *display, WND *win, XSetWindowAttributes *attr )
103 BOOL is_top_level = is_window_top_level( win );
104 BOOL managed = is_top_level && is_window_managed( win );
106 if (managed) win->dwExStyle |= WS_EX_MANAGED;
107 else win->dwExStyle &= ~WS_EX_MANAGED;
109 attr->override_redirect = !managed;
110 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
111 attr->save_under = ((win->clsStyle & CS_SAVEBITS) != 0);
113 attr->event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
114 ButtonPressMask | ButtonReleaseMask);
115 if (is_window_top_level( win ))
117 attr->event_mask |= StructureNotifyMask | FocusChangeMask;
118 attr->cursor = X11DRV_GetCursor( display, GlobalLock16(GetCursor()) );
120 return (CWOverrideRedirect | CWSaveUnder | CWEventMask | CWColormap | CWCursor);
124 /***********************************************************************
127 * Change the X window attributes when the window style has changed.
129 static void sync_window_style( Display *display, WND *win )
131 XSetWindowAttributes attr;
135 mask = get_window_attributes( display, win, &attr );
136 XChangeWindowAttributes( display, get_whole_window(win), mask, &attr );
137 if (attr.cursor) XFreeCursor( display, attr.cursor );
142 /***********************************************************************
145 * fill the window changes structure
147 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
151 if (old->right - old->left != new->right - new->left )
153 if (!(changes->width = new->right - new->left)) changes->width = 1;
156 if (old->bottom - old->top != new->bottom - new->top)
158 if (!(changes->height = new->bottom - new->top)) changes->height = 1;
161 if (old->left != new->left)
163 changes->x = new->left;
166 if (old->top != new->top)
168 changes->y = new->top;
175 /***********************************************************************
178 static Window create_icon_window( Display *display, WND *win )
180 struct x11drv_win_data *data = win->pDriverData;
181 XSetWindowAttributes attr;
183 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
184 ButtonPressMask | ButtonReleaseMask);
185 attr.bit_gravity = NorthWestGravity;
186 attr.backing_store = NotUseful/*WhenMapped*/;
187 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
190 data->icon_window = XCreateWindow( display, root_window, 0, 0,
191 GetSystemMetrics( SM_CXICON ),
192 GetSystemMetrics( SM_CYICON ),
195 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
196 XSaveContext( display, data->icon_window, winContext, (char *)win->hwndSelf );
199 TRACE( "created %lx\n", data->icon_window );
200 SetPropA( win->hwndSelf, "__wine_x11_icon_window", (HANDLE)data->icon_window );
201 return data->icon_window;
206 /***********************************************************************
207 * destroy_icon_window
209 inline static void destroy_icon_window( Display *display, WND *win )
211 struct x11drv_win_data *data = win->pDriverData;
213 if (!data->icon_window) return;
215 XDeleteContext( display, data->icon_window, winContext );
216 XDestroyWindow( display, data->icon_window );
217 data->icon_window = 0;
219 RemovePropA( win->hwndSelf, "__wine_x11_icon_window" );
223 /***********************************************************************
226 * Set the icon wm hints
228 static void set_icon_hints( Display *display, WND *wndPtr, XWMHints *hints )
230 X11DRV_WND_DATA *data = wndPtr->pDriverData;
231 HICON hIcon = GetClassLongA( wndPtr->hwndSelf, GCL_HICON );
233 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
234 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
235 data->hWMIconBitmap = 0;
236 data->hWMIconMask = 0;
238 if (!(wndPtr->dwExStyle & WS_EX_MANAGED))
240 destroy_icon_window( display, wndPtr );
241 hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint);
245 if (!data->icon_window) create_icon_window( display, wndPtr );
246 hints->icon_window = data->icon_window;
247 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
257 GetIconInfo(hIcon, &ii);
259 X11DRV_CreateBitmap(ii.hbmMask);
260 X11DRV_CreateBitmap(ii.hbmColor);
262 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
265 rcMask.right = bmMask.bmWidth;
266 rcMask.bottom = bmMask.bmHeight;
268 hDC = CreateCompatibleDC(0);
269 hbmOrig = SelectObject(hDC, ii.hbmMask);
270 InvertRect(hDC, &rcMask);
271 SelectObject(hDC, hbmOrig);
274 data->hWMIconBitmap = ii.hbmColor;
275 data->hWMIconMask = ii.hbmMask;
277 hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap);
278 hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask);
279 destroy_icon_window( display, wndPtr );
280 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
285 /***********************************************************************
288 * set the window size hints
290 static void set_size_hints( Display *display, WND *win )
292 XSizeHints* size_hints;
293 struct x11drv_win_data *data = win->pDriverData;
295 if ((size_hints = XAllocSizeHints()))
297 size_hints->win_gravity = StaticGravity;
298 size_hints->x = data->whole_rect.left;
299 size_hints->y = data->whole_rect.top;
300 size_hints->flags = PWinGravity | PPosition;
302 if (HAS_DLGFRAME( win->dwStyle, win->dwExStyle ))
304 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
305 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
306 size_hints->min_width = size_hints->max_width;
307 size_hints->min_height = size_hints->max_height;
308 size_hints->flags |= PMinSize | PMaxSize;
310 XSetWMNormalHints( display, data->whole_window, size_hints );
316 /***********************************************************************
319 * Set the window manager hints for a newly-created window
321 static void set_wm_hints( Display *display, WND *win )
323 struct x11drv_win_data *data = win->pDriverData;
325 XClassHint *class_hints;
334 protocols[i++] = wmDeleteWindow;
335 if (wmTakeFocus) protocols[i++] = wmTakeFocus;
336 XSetWMProtocols( display, data->whole_window, protocols, i );
339 if ((class_hints = XAllocClassHint()))
341 class_hints->res_name = "wine";
342 class_hints->res_class = "Wine";
343 XSetClassHint( display, data->whole_window, class_hints );
344 XFree( class_hints );
347 /* transient for hint */
350 struct x11drv_win_data *owner_data = win->owner->pDriverData;
351 XSetTransientForHint( display, data->whole_window, owner_data->whole_window );
352 group_leader = owner_data->whole_window;
354 else group_leader = data->whole_window;
357 set_size_hints( display, win );
359 /* systray properties (KDE only for now) */
360 if (win->dwExStyle & WS_EX_TRAYWINDOW)
363 if (kwmDockWindow != None)
364 TSXChangeProperty( display, data->whole_window, kwmDockWindow, kwmDockWindow,
365 32, PropModeReplace, (char*)&val, 1 );
366 if (_kde_net_wm_system_tray_window_for != None)
367 TSXChangeProperty( display, data->whole_window, _kde_net_wm_system_tray_window_for,
368 XA_WINDOW, 32, PropModeReplace, (char*)&data->whole_window, 1 );
374 if ((wm_hints = TSXAllocWMHints()))
376 wm_hints->flags = InputHint | StateHint | WindowGroupHint;
377 /* use globally active model if take focus is supported,
378 * passive model otherwise (cf. ICCCM) */
379 wm_hints->input = !wmTakeFocus;
381 set_icon_hints( display, win, wm_hints );
383 wm_hints->initial_state = (win->dwStyle & WS_MINIMIZE) ? IconicState : NormalState;
384 wm_hints->window_group = group_leader;
387 XSetWMHints( display, data->whole_window, wm_hints );
394 /***********************************************************************
395 * X11DRV_set_iconic_state
397 * Set the X11 iconic state according to the window style.
399 void X11DRV_set_iconic_state( WND *win )
401 Display *display = thread_display();
402 struct x11drv_win_data *data = win->pDriverData;
404 BOOL iconic = IsIconic( win->hwndSelf );
408 if (iconic) XUnmapWindow( display, data->client_window );
409 else if (is_client_window_mapped( win )) XMapWindow( display, data->client_window );
411 if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
412 wm_hints->flags |= StateHint | IconPositionHint;
413 wm_hints->initial_state = iconic ? IconicState : NormalState;
414 wm_hints->icon_x = win->rectWindow.left;
415 wm_hints->icon_y = win->rectWindow.top;
416 XSetWMHints( display, data->whole_window, wm_hints );
418 if (win->dwStyle & WS_VISIBLE)
421 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
423 if (!IsRectEmpty( &win->rectWindow )) XMapWindow( display, data->whole_window );
431 /***********************************************************************
432 * X11DRV_window_to_X_rect
434 * Convert a rect from client to X window coordinates
436 void X11DRV_window_to_X_rect( WND *win, RECT *rect )
440 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
441 if (IsRectEmpty( rect )) return;
443 rc.top = rc.bottom = rc.left = rc.right = 0;
445 AdjustWindowRectEx( &rc, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
447 rect->left -= rc.left;
448 rect->right -= rc.right;
450 rect->bottom -= rc.bottom;
451 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
452 if (rect->left >= rect->right) rect->right = rect->left + 1;
456 /***********************************************************************
457 * X11DRV_X_to_window_rect
459 * Opposite of X11DRV_window_to_X_rect
461 void X11DRV_X_to_window_rect( WND *win, RECT *rect )
463 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
464 if (IsRectEmpty( rect )) return;
466 AdjustWindowRectEx( rect, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
468 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
469 if (rect->left >= rect->right) rect->right = rect->left + 1;
473 /***********************************************************************
474 * X11DRV_sync_whole_window_position
476 * Synchronize the X whole window position with the Windows one
478 int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder )
480 XWindowChanges changes;
482 struct x11drv_win_data *data = win->pDriverData;
483 RECT whole_rect = win->rectWindow;
485 X11DRV_window_to_X_rect( win, &whole_rect );
486 mask = get_window_changes( &changes, &data->whole_rect, &whole_rect );
490 /* find window that this one must be after */
491 WND *prev = win->parent->child;
492 if (prev == win) /* top child */
494 changes.stack_mode = Above;
499 while (prev && prev->next != win) prev = prev->next;
502 changes.stack_mode = Below;
503 changes.sibling = get_whole_window(prev);
504 mask |= CWStackMode | CWSibling;
506 else ERR( "previous window not found for %x, list corrupted?\n", win->hwndSelf );
510 data->whole_rect = whole_rect;
514 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
515 data->whole_window, whole_rect.left, whole_rect.top,
516 whole_rect.right - whole_rect.left, whole_rect.bottom - whole_rect.top,
517 changes.sibling, mask );
519 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
520 if (is_window_top_level( win ))
522 if (mask & (CWWidth|CWHeight)) set_size_hints( display, win );
523 XReconfigureWMWindow( display, data->whole_window,
524 DefaultScreen(display), mask, &changes );
526 else XConfigureWindow( display, data->whole_window, mask, &changes );
533 /***********************************************************************
534 * X11DRV_sync_client_window_position
536 * Synchronize the X client window position with the Windows one
538 int X11DRV_sync_client_window_position( Display *display, WND *win )
540 XWindowChanges changes;
542 struct x11drv_win_data *data = win->pDriverData;
543 RECT client_rect = win->rectClient;
545 OffsetRect( &client_rect, -data->whole_rect.left, -data->whole_rect.top );
547 if ((mask = get_window_changes( &changes, &data->client_rect, &client_rect )))
549 BOOL was_mapped = is_client_window_mapped( win );
551 TRACE( "setting win %lx pos %d,%d,%dx%d (was %d,%d,%dx%d) after %lx changes=%x\n",
552 data->client_window, client_rect.left, client_rect.top,
553 client_rect.right - client_rect.left, client_rect.bottom - client_rect.top,
554 data->client_rect.left, data->client_rect.top,
555 data->client_rect.right - data->client_rect.left,
556 data->client_rect.bottom - data->client_rect.top,
557 changes.sibling, mask );
558 data->client_rect = client_rect;
560 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
561 if (was_mapped && !is_client_window_mapped( win ))
562 XUnmapWindow( display, data->client_window );
563 XConfigureWindow( display, data->client_window, mask, &changes );
564 if (!was_mapped && is_client_window_mapped( win ))
565 XMapWindow( display, data->client_window );
572 /***********************************************************************
573 * X11DRV_register_window
575 * Associate an X window to a HWND.
577 void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data )
580 XSaveContext( display, data->whole_window, winContext, (char *)hwnd );
581 XSaveContext( display, data->client_window, winContext, (char *)hwnd );
586 /**********************************************************************
589 static void create_desktop( Display *display, WND *wndPtr )
591 X11DRV_WND_DATA *data = wndPtr->pDriverData;
594 winContext = XUniqueContext();
595 wmProtocols = XInternAtom( display, "WM_PROTOCOLS", False );
596 wmDeleteWindow = XInternAtom( display, "WM_DELETE_WINDOW", False );
597 /* wmTakeFocus = XInternAtom( display, "WM_TAKE_FOCUS", False );*/
598 wmTakeFocus = 0; /* not yet */
599 dndProtocol = XInternAtom( display, "DndProtocol" , False );
600 dndSelection = XInternAtom( display, "DndSelection" , False );
601 wmChangeState = XInternAtom (display, "WM_CHANGE_STATE", False);
602 kwmDockWindow = XInternAtom( display, "KWM_DOCKWINDOW", False );
603 _kde_net_wm_system_tray_window_for = XInternAtom( display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False );
606 data->whole_window = data->client_window = root_window;
608 SetPropA( wndPtr->hwndSelf, "__wine_x11_whole_window", (HANDLE)root_window );
609 SetPropA( wndPtr->hwndSelf, "__wine_x11_client_window", (HANDLE)root_window );
610 SetPropA( wndPtr->hwndSelf, "__wine_x11_visual_id", (HANDLE)XVisualIDFromVisual(visual) );
612 if (root_window != DefaultRootWindow(display)) X11DRV_create_desktop_thread();
616 /**********************************************************************
617 * create_whole_window
619 * Create the whole X window for a given window
621 static Window create_whole_window( Display *display, WND *win )
623 struct x11drv_win_data *data = win->pDriverData;
625 XSetWindowAttributes attr;
628 BOOL is_top_level = is_window_top_level( win );
630 rect = win->rectWindow;
631 X11DRV_window_to_X_rect( win, &rect );
633 if (!(cx = rect.right - rect.left)) cx = 1;
634 if (!(cy = rect.bottom - rect.top)) cy = 1;
636 parent = get_client_window( win->parent );
640 mask = get_window_attributes( display, win, &attr );
642 /* set the attributes that don't change over the lifetime of the window */
643 attr.bit_gravity = ForgetGravity;
644 attr.win_gravity = NorthWestGravity;
645 attr.backing_store = NotUseful/*WhenMapped*/;
646 mask |= CWBitGravity | CWWinGravity | CWBackingStore;
648 data->whole_rect = rect;
649 data->whole_window = XCreateWindow( display, parent, rect.left, rect.top, cx, cy,
650 0, screen_depth, InputOutput, visual,
652 if (attr.cursor) XFreeCursor( display, attr.cursor );
654 if (!data->whole_window)
660 /* non-maximized child must be at bottom of Z order */
661 if ((win->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
663 XWindowChanges changes;
664 changes.stack_mode = Below;
665 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
670 if (is_top_level) set_wm_hints( display, win );
672 return data->whole_window;
676 /**********************************************************************
677 * create_client_window
679 * Create the client window for a given window
681 static Window create_client_window( Display *display, WND *win )
683 struct x11drv_win_data *data = win->pDriverData;
684 RECT rect = data->whole_rect;
685 XSetWindowAttributes attr;
687 OffsetRect( &rect, -data->whole_rect.left, -data->whole_rect.top );
688 data->client_rect = rect;
690 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
691 ButtonPressMask | ButtonReleaseMask);
692 attr.bit_gravity = (win->clsStyle & (CS_VREDRAW | CS_HREDRAW)) ?
693 ForgetGravity : NorthWestGravity;
694 attr.backing_store = NotUseful/*WhenMapped*/;
697 data->client_window = XCreateWindow( display, data->whole_window, 0, 0,
698 max( rect.right - rect.left, 1 ),
699 max( rect.bottom - rect.top, 1 ),
702 CWEventMask | CWBitGravity | CWBackingStore, &attr );
703 if (data->client_window && is_client_window_mapped( win ))
704 XMapWindow( display, data->client_window );
706 return data->client_window;
710 /*****************************************************************
711 * SetWindowText (X11DRV.@)
713 BOOL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
715 Display *display = thread_display();
718 static UINT text_cp = (UINT)-1;
720 WND *wndPtr = WIN_FindWndPtr( hwnd );
722 if (!wndPtr) return FALSE;
723 if ((win = get_whole_window(wndPtr)))
725 if (text_cp == (UINT)-1)
730 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", &hkey))
733 DWORD type, count = sizeof(buffer);
734 if(!RegQueryValueExA(hkey, "TextCP", 0, &type, buffer, &count))
735 text_cp = atoi(buffer);
738 TRACE("text_cp = %u\n", text_cp);
741 /* allocate new buffer for window text */
742 count = WideCharToMultiByte(text_cp, 0, text, -1, NULL, 0, NULL, NULL);
743 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count * sizeof(WCHAR) )))
745 ERR("Not enough memory for window text\n");
746 WIN_ReleaseWndPtr( wndPtr );
749 WideCharToMultiByte(text_cp, 0, text, -1, buffer, count, NULL, NULL);
752 XStoreName( display, win, buffer );
753 XSetIconName( display, win, buffer );
756 HeapFree( GetProcessHeap(), 0, buffer );
758 WIN_ReleaseWndPtr( wndPtr );
763 /***********************************************************************
764 * DestroyWindow (X11DRV.@)
766 BOOL X11DRV_DestroyWindow( HWND hwnd )
768 Display *display = thread_display();
769 WND *wndPtr = WIN_FindWndPtr( hwnd );
770 X11DRV_WND_DATA *data = wndPtr->pDriverData;
772 if (!data) goto done;
774 if (data->whole_window)
776 TRACE( "win %x xwin %lx/%lx\n", hwnd, data->whole_window, data->client_window );
778 XSync( gdi_display, False ); /* flush any reference to this drawable in GDI queue */
779 XDeleteContext( display, data->whole_window, winContext );
780 XDeleteContext( display, data->client_window, winContext );
781 XDestroyWindow( display, data->whole_window ); /* this destroys client too */
782 destroy_icon_window( display, wndPtr );
786 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
787 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
788 HeapFree( GetProcessHeap(), 0, data );
789 wndPtr->pDriverData = NULL;
791 WIN_ReleaseWndPtr( wndPtr );
796 /**********************************************************************
797 * CreateWindow (X11DRV.@)
799 BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
801 Display *display = thread_display();
803 struct x11drv_win_data *data;
807 if (!(data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data)))) return FALSE;
808 data->whole_window = 0;
809 data->client_window = 0;
810 data->icon_window = 0;
811 data->hWMIconBitmap = 0;
812 data->hWMIconMask = 0;
814 wndPtr = WIN_FindWndPtr( hwnd );
815 wndPtr->pDriverData = data;
819 SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
820 create_desktop( display, wndPtr );
821 WIN_ReleaseWndPtr( wndPtr );
825 if (!create_whole_window( display, wndPtr )) goto failed;
826 if (!create_client_window( display, wndPtr )) goto failed;
827 TSXSync( display, False );
829 WIN_ReleaseWndPtr( wndPtr );
831 SetPropA( hwnd, "__wine_x11_whole_window", (HANDLE)data->whole_window );
832 SetPropA( hwnd, "__wine_x11_client_window", (HANDLE)data->client_window );
834 /* send WM_NCCREATE */
835 TRACE( "hwnd %x cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
837 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
839 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
842 X11DRV_DestroyWindow( hwnd );
846 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return FALSE;
848 sync_window_style( display, wndPtr );
850 /* send WM_NCCALCSIZE */
851 rect = wndPtr->rectWindow;
852 SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
853 if (rect.left > rect.right || rect.top > rect.bottom) rect = wndPtr->rectWindow;
854 wndPtr->rectClient = rect;
855 X11DRV_sync_client_window_position( display, wndPtr );
856 X11DRV_register_window( display, hwnd, data );
858 TRACE( "win %x window %d,%d,%d,%d client %d,%d,%d,%d whole %d,%d,%d,%d X client %d,%d,%d,%d xwin %x/%x\n",
859 hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
860 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
861 wndPtr->rectClient.left, wndPtr->rectClient.top,
862 wndPtr->rectClient.right, wndPtr->rectClient.bottom,
863 data->whole_rect.left, data->whole_rect.top,
864 data->whole_rect.right, data->whole_rect.bottom,
865 data->client_rect.left, data->client_rect.top,
866 data->client_rect.right, data->client_rect.bottom,
867 (unsigned int)data->whole_window, (unsigned int)data->client_window );
869 if ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
870 WIN_LinkWindow( hwnd, HWND_BOTTOM );
872 WIN_LinkWindow( hwnd, HWND_TOP );
874 WIN_ReleaseWndPtr( wndPtr );
877 ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
879 ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
883 WIN_UnlinkWindow( hwnd );
884 X11DRV_DestroyWindow( hwnd );
888 /* Send the size messages */
890 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return FALSE;
891 if (!(wndPtr->flags & WIN_NEED_SIZE))
894 if (((wndPtr->rectClient.right-wndPtr->rectClient.left) <0)
895 ||((wndPtr->rectClient.bottom-wndPtr->rectClient.top)<0))
896 WARN("sending bogus WM_SIZE message 0x%08lx\n",
897 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
898 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
899 SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
900 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
901 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
902 SendMessageW( hwnd, WM_MOVE, 0,
903 MAKELONG( wndPtr->rectClient.left, wndPtr->rectClient.top ) );
906 /* Show the window, maximizing or minimizing if needed */
908 if (wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE))
910 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
913 UINT swFlag = (wndPtr->dwStyle & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
914 wndPtr->dwStyle &= ~(WS_MAXIMIZE | WS_MINIMIZE);
915 WINPOS_MinMaximize( hwnd, swFlag, &newPos );
916 swFlag = ((wndPtr->dwStyle & WS_CHILD) || GetActiveWindow())
917 ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
918 : SWP_NOZORDER | SWP_FRAMECHANGED;
919 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
920 newPos.right, newPos.bottom, swFlag );
923 WIN_ReleaseWndPtr( wndPtr );
928 X11DRV_DestroyWindow( wndPtr->hwndSelf );
929 WIN_ReleaseWndPtr( wndPtr );
934 /***********************************************************************
935 * X11DRV_get_client_window
937 * Return the X window associated with the client area of a window
939 Window X11DRV_get_client_window( HWND hwnd )
942 WND *win = WIN_FindWndPtr( hwnd );
945 struct x11drv_win_data *data = win->pDriverData;
946 ret = data->client_window;
947 WIN_ReleaseWndPtr( win );
953 /***********************************************************************
954 * X11DRV_get_whole_window
956 * Return the X window associated with the full area of a window
958 Window X11DRV_get_whole_window( HWND hwnd )
961 WND *win = WIN_FindWndPtr( hwnd );
964 struct x11drv_win_data *data = win->pDriverData;
965 ret = data->whole_window;
966 WIN_ReleaseWndPtr( win );
972 /***********************************************************************
973 * X11DRV_get_top_window
975 * Return the X window associated with the top-level parent of a window
977 Window X11DRV_get_top_window( HWND hwnd )
980 WND *win = WIN_FindWndPtr( hwnd );
981 while (win && win->parent->hwndSelf != GetDesktopWindow())
982 WIN_UpdateWndPtr( &win, win->parent );
985 struct x11drv_win_data *data = win->pDriverData;
986 ret = data->whole_window;
987 WIN_ReleaseWndPtr( win );
993 /*****************************************************************
994 * SetParent (X11DRV.@)
996 HWND X11DRV_SetParent( HWND hwnd, HWND parent )
998 Display *display = thread_display();
1004 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
1006 dwStyle = wndPtr->dwStyle;
1008 if (!parent) parent = GetDesktopWindow();
1010 if (!(pWndParent = WIN_FindWndPtr(parent)))
1012 WIN_ReleaseWndPtr( wndPtr );
1016 /* Windows hides the window first, then shows it again
1017 * including the WM_SHOWWINDOW messages and all */
1018 if (dwStyle & WS_VISIBLE) ShowWindow( hwnd, SW_HIDE );
1020 retvalue = wndPtr->parent->hwndSelf; /* old parent */
1021 if (pWndParent != wndPtr->parent)
1023 struct x11drv_win_data *data = wndPtr->pDriverData;
1025 WIN_UnlinkWindow(wndPtr->hwndSelf);
1026 wndPtr->parent = pWndParent;
1027 WIN_LinkWindow(wndPtr->hwndSelf, HWND_TOP);
1029 if (parent != GetDesktopWindow()) /* a child window */
1031 if (!(wndPtr->dwStyle & WS_CHILD) && wndPtr->wIDmenu)
1033 DestroyMenu( (HMENU)wndPtr->wIDmenu );
1034 wndPtr->wIDmenu = 0;
1038 if (is_window_top_level( wndPtr )) set_wm_hints( display, wndPtr );
1040 sync_window_style( display, wndPtr );
1041 XReparentWindow( display, data->whole_window, get_client_window(pWndParent),
1042 data->whole_rect.left, data->whole_rect.top );
1043 wine_tsx11_unlock();
1045 WIN_ReleaseWndPtr( pWndParent );
1046 WIN_ReleaseWndPtr( wndPtr );
1048 /* SetParent additionally needs to make hwnd the topmost window
1049 in the x-order and send the expected WM_WINDOWPOSCHANGING and
1050 WM_WINDOWPOSCHANGED notification messages.
1052 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0,
1053 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|
1054 ((dwStyle & WS_VISIBLE)?SWP_SHOWWINDOW:0));
1055 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1056 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
1062 /*******************************************************************
1063 * EnableWindow (X11DRV.@)
1065 BOOL X11DRV_EnableWindow( HWND hwnd, BOOL enable )
1067 Display *display = thread_display();
1072 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1074 retvalue = ((wndPtr->dwStyle & WS_DISABLED) != 0);
1076 if (enable && (wndPtr->dwStyle & WS_DISABLED))
1079 wndPtr->dwStyle &= ~WS_DISABLED;
1081 if (wndPtr->dwExStyle & WS_EX_MANAGED)
1084 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
1085 wm_hints = XAllocWMHints();
1088 wm_hints->flags |= InputHint;
1089 wm_hints->input = TRUE;
1090 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
1093 wine_tsx11_unlock();
1096 SendMessageA( hwnd, WM_ENABLE, TRUE, 0 );
1098 else if (!enable && !(wndPtr->dwStyle & WS_DISABLED))
1100 SendMessageA( wndPtr->hwndSelf, WM_CANCELMODE, 0, 0 );
1102 /* Disable window */
1103 wndPtr->dwStyle |= WS_DISABLED;
1105 if (wndPtr->dwExStyle & WS_EX_MANAGED)
1108 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
1109 wm_hints = XAllocWMHints();
1112 wm_hints->flags |= InputHint;
1113 wm_hints->input = FALSE;
1114 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
1117 wine_tsx11_unlock();
1120 if (hwnd == GetFocus())
1121 SetFocus( 0 ); /* A disabled window can't have the focus */
1123 if (hwnd == GetCapture())
1124 ReleaseCapture(); /* A disabled window can't capture the mouse */
1126 SendMessageA( hwnd, WM_ENABLE, FALSE, 0 );
1128 WIN_ReleaseWndPtr(wndPtr);
1133 /*****************************************************************
1134 * SetFocus (X11DRV.@)
1137 * Explicit colormap management seems to work only with OLVWM.
1139 void X11DRV_SetFocus( HWND hwnd )
1141 Display *display = thread_display();
1142 XWindowAttributes win_attr;
1144 WND *wndPtr = WIN_FindWndPtr( hwnd );
1147 if (!wndPtr) return;
1149 /* Only mess with the X focus if there's */
1150 /* no desktop window and if the window is not managed by the WM. */
1151 if (root_window != DefaultRootWindow(display)) goto done;
1153 while (w && !get_whole_window(w)) w = w->parent;
1155 if (w->dwExStyle & WS_EX_MANAGED) goto done;
1157 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1159 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1160 TSXUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1162 else if ((win = get_whole_window(w)))
1164 /* Set X focus and install colormap */
1166 if (XGetWindowAttributes( display, win, &win_attr ) &&
1167 (win_attr.map_state == IsViewable))
1169 /* If window is not viewable, don't change anything */
1171 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1172 /* FIXME: this is not entirely correct */
1173 XSetInputFocus( display, win, RevertToParent,
1174 /*CurrentTime*/ GetMessageTime() + X11DRV_server_startticks );
1175 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1176 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1178 wine_tsx11_unlock();
1182 WIN_ReleaseWndPtr( wndPtr );
1186 /**********************************************************************
1187 * SetWindowIcon (X11DRV.@)
1189 * hIcon or hIconSm has changed (or is being initialised for the
1190 * first time). Complete the X11 driver-specific initialisation
1191 * and set the window hints.
1193 * This is not entirely correct, may need to create
1194 * an icon window and set the pixmap as a background
1196 HICON X11DRV_SetWindowIcon( HWND hwnd, HICON icon, BOOL small )
1198 Display *display = thread_display();
1199 WND *wndPtr = WIN_FindWndPtr( hwnd );
1200 int index = small ? GCL_HICONSM : GCL_HICON;
1203 if (!wndPtr) return 0;
1205 old = GetClassLongW( hwnd, index );
1206 SetClassLongW( hwnd, index, icon );
1208 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE |
1209 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1211 if (wndPtr->dwExStyle & WS_EX_MANAGED)
1213 Window win = get_whole_window(wndPtr);
1214 XWMHints* wm_hints = TSXGetWMHints( display, win );
1216 if (!wm_hints) wm_hints = TSXAllocWMHints();
1219 set_icon_hints( display, wndPtr, wm_hints );
1220 TSXSetWMHints( display, win, wm_hints );
1221 TSXFree( wm_hints );
1225 WIN_ReleaseWndPtr( wndPtr );