Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Window related functions |
| 3 | * |
| 4 | * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard |
| 5 | * Copyright 1993 David Metcalfe |
| 6 | * Copyright 1995, 1996 Alex Korobka |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include "config.h" |
| 24 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Dmitry Timoshkov | de70d2b | 2001-06-19 03:32:44 +0000 | [diff] [blame] | 26 | #include <stdlib.h> |
James Liggett | 60a9750 | 2006-08-22 17:14:11 -0700 | [diff] [blame^] | 27 | #include <stdio.h> |
Patrik Stridvall | ba78aac | 2003-08-08 21:07:23 +0000 | [diff] [blame] | 28 | #ifdef HAVE_UNISTD_H |
| 29 | # include <unistd.h> |
| 30 | #endif |
Dmitry Timoshkov | de70d2b | 2001-06-19 03:32:44 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | 64c0e2a | 2003-11-21 21:48:36 +0000 | [diff] [blame] | 32 | #include <X11/Xlib.h> |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 33 | #include <X11/Xresource.h> |
| 34 | #include <X11/Xutil.h> |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 35 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 36 | #include "windef.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 37 | #include "winbase.h" |
| 38 | #include "wingdi.h" |
Dmitry Timoshkov | de70d2b | 2001-06-19 03:32:44 +0000 | [diff] [blame] | 39 | #include "winreg.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 40 | #include "winuser.h" |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 41 | #include "wine/unicode.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 42 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 43 | #include "x11drv.h" |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 44 | #include "wine/debug.h" |
| 45 | #include "wine/server.h" |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 46 | #include "win.h" |
Ove Kaaven | 77e7fd7 | 2002-01-21 18:41:27 +0000 | [diff] [blame] | 47 | #include "mwm.h" |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 48 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 49 | WINE_DEFAULT_DEBUG_CHANNEL(x11drv); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 50 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 51 | /* X context to associate a hwnd to an X window */ |
| 52 | XContext winContext = 0; |
| 53 | |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 54 | /* X context to associate a struct x11drv_win_data to an hwnd */ |
| 55 | static XContext win_data_context; |
| 56 | |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 57 | static const char whole_window_prop[] = "__wine_x11_whole_window"; |
| 58 | static const char icon_window_prop[] = "__wine_x11_icon_window"; |
| 59 | static const char managed_prop[] = "__wine_x11_managed"; |
| 60 | static const char visual_id_prop[] = "__wine_x11_visual_id"; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 61 | |
James Liggett | 60a9750 | 2006-08-22 17:14:11 -0700 | [diff] [blame^] | 62 | /* for XDG systray icons */ |
| 63 | #define SYSTEM_TRAY_REQUEST_DOCK 0 |
| 64 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 65 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 66 | * is_window_managed |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 67 | * |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 68 | * Check if a given window should be managed |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 69 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 70 | inline static BOOL is_window_managed( HWND hwnd ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 71 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 72 | DWORD style, ex_style; |
| 73 | |
Alexandre Julliard | 5954602 | 2002-05-23 16:32:32 +0000 | [diff] [blame] | 74 | if (!managed_mode) return FALSE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 75 | /* tray window is always managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 76 | ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE ); |
| 77 | if (ex_style & WS_EX_TRAYWINDOW) return TRUE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 78 | /* child windows are not managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 79 | style = GetWindowLongW( hwnd, GWL_STYLE ); |
| 80 | if (style & WS_CHILD) return FALSE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 81 | /* windows with caption are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 82 | if ((style & WS_CAPTION) == WS_CAPTION) return TRUE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 83 | /* tool windows are not managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 84 | if (ex_style & WS_EX_TOOLWINDOW) return FALSE; |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 85 | /* windows with thick frame are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 86 | if (style & WS_THICKFRAME) return TRUE; |
Jerry Jenkins | 4e6fab5 | 2003-12-13 00:05:53 +0000 | [diff] [blame] | 87 | /* application windows are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 88 | if (ex_style & WS_EX_APPWINDOW) return TRUE; |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 89 | /* full-screen popup windows are managed */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 90 | if (style & WS_POPUP) |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 91 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 92 | RECT rect; |
| 93 | GetWindowRect( hwnd, &rect ); |
| 94 | if ((rect.right - rect.left) == screen_width && (rect.bottom - rect.top) == screen_height) |
| 95 | return TRUE; |
Alex Pasadyn | d18c8ca | 2004-02-06 05:17:55 +0000 | [diff] [blame] | 96 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 97 | /* default: not managed */ |
| 98 | return FALSE; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
| 102 | /*********************************************************************** |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 103 | * X11DRV_is_window_rect_mapped |
| 104 | * |
| 105 | * Check if the X whole window should be mapped based on its rectangle |
| 106 | */ |
| 107 | BOOL X11DRV_is_window_rect_mapped( const RECT *rect ) |
| 108 | { |
| 109 | /* don't map if rect is empty */ |
| 110 | if (IsRectEmpty( rect )) return FALSE; |
| 111 | |
| 112 | /* don't map if rect is off-screen */ |
Alexandre Julliard | 7f8ad0a | 2004-04-28 00:31:21 +0000 | [diff] [blame] | 113 | if (rect->left >= (int)screen_width || rect->top >= (int)screen_height) return FALSE; |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 114 | if (rect->right < 0 || rect->bottom < 0) return FALSE; |
| 115 | |
| 116 | return TRUE; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 121 | * get_window_attributes |
| 122 | * |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 123 | * Fill the window attributes structure for an X window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 124 | */ |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 125 | static int get_window_attributes( Display *display, struct x11drv_win_data *data, |
| 126 | XSetWindowAttributes *attr ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 127 | { |
Alexandre Julliard | c44410d | 2006-03-28 12:21:37 +0200 | [diff] [blame] | 128 | if (!data->managed && |
| 129 | root_window == DefaultRootWindow( display ) && |
| 130 | data->whole_window != root_window && |
| 131 | is_window_managed( data->hwnd )) |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 132 | { |
| 133 | data->managed = TRUE; |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 134 | SetPropA( data->hwnd, managed_prop, (HANDLE)1 ); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 135 | } |
| 136 | attr->override_redirect = !data->managed; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 137 | attr->colormap = X11DRV_PALETTE_PaletteXColormap; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 138 | attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0); |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 139 | attr->cursor = x11drv_thread_data()->cursor; |
Alexandre Julliard | 2431a64 | 2005-07-27 15:22:58 +0000 | [diff] [blame] | 140 | return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 141 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 142 | |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 143 | |
| 144 | /*********************************************************************** |
Alexandre Julliard | 911a177 | 2002-08-20 00:36:45 +0000 | [diff] [blame] | 145 | * X11DRV_sync_window_style |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 146 | * |
| 147 | * Change the X window attributes when the window style has changed. |
| 148 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 149 | void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 150 | { |
| 151 | XSetWindowAttributes attr; |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 152 | int mask = get_window_attributes( display, data, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 153 | |
| 154 | wine_tsx11_lock(); |
Alexandre Julliard | 6d5f544 | 2006-03-06 21:02:59 +0100 | [diff] [blame] | 155 | if (data->whole_window != DefaultRootWindow(display)) |
| 156 | XChangeWindowAttributes( display, data->whole_window, mask, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 157 | wine_tsx11_unlock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | /*********************************************************************** |
| 162 | * get_window_changes |
| 163 | * |
| 164 | * fill the window changes structure |
| 165 | */ |
| 166 | static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new ) |
| 167 | { |
| 168 | int mask = 0; |
| 169 | |
| 170 | if (old->right - old->left != new->right - new->left ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 171 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 172 | if (!(changes->width = new->right - new->left)) changes->width = 1; |
| 173 | mask |= CWWidth; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 174 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 175 | if (old->bottom - old->top != new->bottom - new->top) |
| 176 | { |
| 177 | if (!(changes->height = new->bottom - new->top)) changes->height = 1; |
| 178 | mask |= CWHeight; |
| 179 | } |
| 180 | if (old->left != new->left) |
| 181 | { |
| 182 | changes->x = new->left; |
| 183 | mask |= CWX; |
| 184 | } |
| 185 | if (old->top != new->top) |
| 186 | { |
| 187 | changes->y = new->top; |
| 188 | mask |= CWY; |
| 189 | } |
| 190 | return mask; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /*********************************************************************** |
| 195 | * create_icon_window |
| 196 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 197 | static Window create_icon_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 198 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 199 | XSetWindowAttributes attr; |
| 200 | |
| 201 | attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 202 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 203 | attr.bit_gravity = NorthWestGravity; |
| 204 | attr.backing_store = NotUseful/*WhenMapped*/; |
Lionel Ulmer | 1fc39be | 2001-07-12 22:27:56 +0000 | [diff] [blame] | 205 | attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 206 | |
Alexandre Julliard | 649637f | 2001-06-26 21:10:11 +0000 | [diff] [blame] | 207 | wine_tsx11_lock(); |
| 208 | data->icon_window = XCreateWindow( display, root_window, 0, 0, |
| 209 | GetSystemMetrics( SM_CXICON ), |
| 210 | GetSystemMetrics( SM_CYICON ), |
| 211 | 0, screen_depth, |
| 212 | InputOutput, visual, |
Lionel Ulmer | 1fc39be | 2001-07-12 22:27:56 +0000 | [diff] [blame] | 213 | CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr ); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 214 | XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd ); |
Alexandre Julliard | 649637f | 2001-06-26 21:10:11 +0000 | [diff] [blame] | 215 | wine_tsx11_unlock(); |
| 216 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 217 | TRACE( "created %lx\n", data->icon_window ); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 218 | SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 219 | return data->icon_window; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | |
| 224 | /*********************************************************************** |
| 225 | * destroy_icon_window |
| 226 | */ |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 227 | static void destroy_icon_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 228 | { |
| 229 | if (!data->icon_window) return; |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 230 | if (x11drv_thread_data()->cursor_window == data->icon_window) |
| 231 | x11drv_thread_data()->cursor_window = None; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 232 | wine_tsx11_lock(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 233 | XDeleteContext( display, data->icon_window, winContext ); |
| 234 | XDestroyWindow( display, data->icon_window ); |
| 235 | data->icon_window = 0; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 236 | wine_tsx11_unlock(); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 237 | RemovePropA( data->hwnd, icon_window_prop ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | |
| 241 | /*********************************************************************** |
| 242 | * set_icon_hints |
| 243 | * |
| 244 | * Set the icon wm hints |
| 245 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 246 | static void set_icon_hints( Display *display, struct x11drv_win_data *data, |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 247 | XWMHints *hints, HICON hIcon ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 248 | { |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 249 | if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); |
| 250 | if (data->hWMIconMask) DeleteObject( data->hWMIconMask); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 251 | data->hWMIconBitmap = 0; |
| 252 | data->hWMIconMask = 0; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 253 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 254 | if (!data->managed) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 255 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 256 | destroy_icon_window( display, data ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 257 | hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint); |
| 258 | } |
| 259 | else if (!hIcon) |
| 260 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 261 | if (!data->icon_window) create_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 262 | hints->icon_window = data->icon_window; |
| 263 | hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 264 | } |
| 265 | else |
| 266 | { |
| 267 | HBITMAP hbmOrig; |
| 268 | RECT rcMask; |
| 269 | BITMAP bmMask; |
| 270 | ICONINFO ii; |
| 271 | HDC hDC; |
| 272 | |
| 273 | GetIconInfo(hIcon, &ii); |
| 274 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 275 | GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask); |
| 276 | rcMask.top = 0; |
| 277 | rcMask.left = 0; |
| 278 | rcMask.right = bmMask.bmWidth; |
| 279 | rcMask.bottom = bmMask.bmHeight; |
| 280 | |
| 281 | hDC = CreateCompatibleDC(0); |
| 282 | hbmOrig = SelectObject(hDC, ii.hbmMask); |
| 283 | InvertRect(hDC, &rcMask); |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 284 | SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */ |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 285 | SelectObject(hDC, hbmOrig); |
| 286 | DeleteDC(hDC); |
| 287 | |
| 288 | data->hWMIconBitmap = ii.hbmColor; |
| 289 | data->hWMIconMask = ii.hbmMask; |
| 290 | |
Alexandre Julliard | 5fd1326 | 2005-03-27 18:30:51 +0000 | [diff] [blame] | 291 | hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap); |
| 292 | hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 293 | destroy_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 294 | hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
James Liggett | 60a9750 | 2006-08-22 17:14:11 -0700 | [diff] [blame^] | 298 | /*********************************************************************** |
| 299 | * systray_dock_window |
| 300 | * |
| 301 | * Docks the given X window with the NETWM system tray. |
| 302 | */ |
| 303 | static void systray_dock_window( Display *display, struct x11drv_win_data *data ) |
| 304 | { |
| 305 | static Atom systray_atom; |
| 306 | Window systray_window; |
| 307 | |
| 308 | wine_tsx11_lock(); |
| 309 | if (!systray_atom) |
| 310 | { |
| 311 | if (DefaultScreen( display ) == 0) |
| 312 | systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0); |
| 313 | else |
| 314 | { |
| 315 | char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */ |
| 316 | sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) ); |
| 317 | systray_atom = XInternAtom( display, systray_buffer, False ); |
| 318 | } |
| 319 | } |
| 320 | systray_window = XGetSelectionOwner( display, systray_atom ); |
| 321 | wine_tsx11_unlock(); |
| 322 | |
| 323 | TRACE("Docking tray icon %p\n", data->hwnd); |
| 324 | |
| 325 | if (systray_window != None) |
| 326 | { |
| 327 | XEvent ev; |
| 328 | unsigned long info[2]; |
| 329 | |
| 330 | /* Put the window offscreen so it isn't mapped. The window _cannot_ be |
| 331 | * mapped if we intend to dock with an XEMBED tray. If the window is |
| 332 | * mapped when we dock, it may become visible as a child of the root |
| 333 | * window after it docks, which isn't the proper behavior. |
| 334 | * |
| 335 | * For more information on this problem, see |
| 336 | * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */ |
| 337 | |
| 338 | SetWindowPos( data->hwnd, NULL, screen_width + 1, screen_height + 1, |
| 339 | 0, 0, SWP_NOZORDER | SWP_NOSIZE ); |
| 340 | |
| 341 | /* set XEMBED protocol data on the window */ |
| 342 | info[0] = 0; /* protocol version */ |
| 343 | info[1] = 1; /* mapped = true */ |
| 344 | |
| 345 | wine_tsx11_lock(); |
| 346 | XChangeProperty( display, data->whole_window, |
| 347 | x11drv_atom(_XEMBED_INFO), |
| 348 | x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, |
| 349 | (unsigned char*)info, 2 ); |
| 350 | wine_tsx11_unlock(); |
| 351 | |
| 352 | /* send the docking request message */ |
| 353 | ZeroMemory( &ev, sizeof(ev) ); |
| 354 | ev.xclient.type = ClientMessage; |
| 355 | ev.xclient.window = systray_window; |
| 356 | ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE ); |
| 357 | ev.xclient.format = 32; |
| 358 | ev.xclient.data.l[0] = CurrentTime; |
| 359 | ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK; |
| 360 | ev.xclient.data.l[2] = data->whole_window; |
| 361 | ev.xclient.data.l[3] = 0; |
| 362 | ev.xclient.data.l[4] = 0; |
| 363 | |
| 364 | wine_tsx11_lock(); |
| 365 | XSendEvent( display, systray_window, False, NoEventMask, &ev ); |
| 366 | wine_tsx11_unlock(); |
| 367 | |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | int val = 1; |
| 372 | |
| 373 | /* fall back to he KDE hints if the WM doesn't support XEMBED'ed |
| 374 | * systrays */ |
| 375 | |
| 376 | wine_tsx11_lock(); |
| 377 | XChangeProperty( display, data->whole_window, |
| 378 | x11drv_atom(KWM_DOCKWINDOW), |
| 379 | x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace, |
| 380 | (unsigned char*)&val, 1 ); |
| 381 | XChangeProperty( display, data->whole_window, |
| 382 | x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR), |
| 383 | XA_WINDOW, 32, PropModeReplace, |
| 384 | (unsigned char*)&data->whole_window, 1 ); |
| 385 | wine_tsx11_unlock(); |
| 386 | } |
| 387 | } |
| 388 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 389 | |
| 390 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 391 | * set_size_hints |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 392 | * |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 393 | * set the window size hints |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 394 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 395 | static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 396 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 397 | XSizeHints* size_hints; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 398 | |
| 399 | if ((size_hints = XAllocSizeHints())) |
| 400 | { |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 401 | size_hints->flags = 0; |
| 402 | |
| 403 | if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */ |
| 404 | { |
| 405 | size_hints->win_gravity = StaticGravity; |
| 406 | size_hints->x = data->whole_rect.left; |
| 407 | size_hints->y = data->whole_rect.top; |
| 408 | size_hints->flags |= PWinGravity | PPosition; |
| 409 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 410 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 411 | if ( !(style & WS_THICKFRAME) ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 412 | { |
| 413 | size_hints->max_width = data->whole_rect.right - data->whole_rect.left; |
| 414 | size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top; |
| 415 | size_hints->min_width = size_hints->max_width; |
| 416 | size_hints->min_height = size_hints->max_height; |
| 417 | size_hints->flags |= PMinSize | PMaxSize; |
| 418 | } |
| 419 | XSetWMNormalHints( display, data->whole_window, size_hints ); |
| 420 | XFree( size_hints ); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | |
| 425 | /*********************************************************************** |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 426 | * get_process_name |
| 427 | * |
| 428 | * get the name of the current process for setting class hints |
| 429 | */ |
| 430 | static char *get_process_name(void) |
| 431 | { |
| 432 | static char *name; |
| 433 | |
| 434 | if (!name) |
| 435 | { |
| 436 | WCHAR module[MAX_PATH]; |
| 437 | DWORD len = GetModuleFileNameW( 0, module, MAX_PATH ); |
| 438 | if (len && len < MAX_PATH) |
| 439 | { |
| 440 | char *ptr; |
| 441 | WCHAR *p, *appname = module; |
| 442 | |
| 443 | if ((p = strrchrW( appname, '/' ))) appname = p + 1; |
| 444 | if ((p = strrchrW( appname, '\\' ))) appname = p + 1; |
| 445 | len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL ); |
| 446 | if ((ptr = HeapAlloc( GetProcessHeap(), 0, len ))) |
| 447 | { |
| 448 | WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL ); |
| 449 | name = ptr; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | return name; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | /*********************************************************************** |
Alexandre Julliard | 911a177 | 2002-08-20 00:36:45 +0000 | [diff] [blame] | 458 | * X11DRV_set_wm_hints |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 459 | * |
| 460 | * Set the window manager hints for a newly-created window |
| 461 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 462 | void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 463 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 464 | Window group_leader; |
| 465 | XClassHint *class_hints; |
| 466 | XWMHints* wm_hints; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 467 | Atom protocols[3]; |
| 468 | MwmHints mwm_hints; |
Ulrich Czekalla | 032bdc9 | 2003-11-20 22:09:51 +0000 | [diff] [blame] | 469 | Atom dndVersion = 4; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 470 | int i; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 471 | DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 472 | DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE ); |
| 473 | HWND owner = GetWindow( data->hwnd, GW_OWNER ); |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 474 | char *process_name = get_process_name(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 475 | |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 476 | if (data->hwnd == GetDesktopWindow()) |
| 477 | { |
Alexandre Julliard | c44410d | 2006-03-28 12:21:37 +0200 | [diff] [blame] | 478 | if (data->whole_window == DefaultRootWindow(display)) return; |
Alexandre Julliard | ba1517f | 2006-03-27 22:16:04 +0200 | [diff] [blame] | 479 | /* force some styles for the desktop to get the correct decorations */ |
| 480 | style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; |
| 481 | owner = 0; |
| 482 | } |
| 483 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 484 | /* transient for hint */ |
| 485 | if (owner) |
| 486 | { |
| 487 | Window owner_win = X11DRV_get_whole_window( owner ); |
| 488 | wine_tsx11_lock(); |
| 489 | XSetTransientForHint( display, data->whole_window, owner_win ); |
| 490 | wine_tsx11_unlock(); |
| 491 | group_leader = owner_win; |
| 492 | } |
| 493 | else group_leader = data->whole_window; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 494 | |
| 495 | wine_tsx11_lock(); |
| 496 | |
| 497 | /* wm protocols */ |
| 498 | i = 0; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 499 | protocols[i++] = x11drv_atom(WM_DELETE_WINDOW); |
| 500 | protocols[i++] = x11drv_atom(_NET_WM_PING); |
| 501 | if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS); |
| 502 | XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 503 | XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 504 | |
| 505 | /* class hints */ |
| 506 | if ((class_hints = XAllocClassHint())) |
| 507 | { |
Andrew Talbot | 55e20a7 | 2006-06-26 20:56:16 +0100 | [diff] [blame] | 508 | static char wine[] = "Wine"; |
| 509 | |
Alexandre Julliard | c7dbffc | 2005-07-01 16:16:00 +0000 | [diff] [blame] | 510 | class_hints->res_name = process_name; |
Andrew Talbot | 55e20a7 | 2006-06-26 20:56:16 +0100 | [diff] [blame] | 511 | class_hints->res_class = wine; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 512 | XSetClassHint( display, data->whole_window, class_hints ); |
| 513 | XFree( class_hints ); |
| 514 | } |
| 515 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 516 | /* size hints */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 517 | set_size_hints( display, data, style ); |
James Liggett | 60a9750 | 2006-08-22 17:14:11 -0700 | [diff] [blame^] | 518 | |
| 519 | /* Dock system tray windows. */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 520 | if (ex_style & WS_EX_TRAYWINDOW) |
James Liggett | 60a9750 | 2006-08-22 17:14:11 -0700 | [diff] [blame^] | 521 | systray_dock_window( display, data ); |
Ove Kaaven | 77e7fd7 | 2002-01-21 18:41:27 +0000 | [diff] [blame] | 522 | |
Mike Hearn | 34dd455 | 2003-05-04 02:27:20 +0000 | [diff] [blame] | 523 | /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */ |
| 524 | XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
| 525 | /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */ |
| 526 | i = getpid(); |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 527 | XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 528 | XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1); |
Ove Kaaven | 77e7fd7 | 2002-01-21 18:41:27 +0000 | [diff] [blame] | 529 | |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 530 | /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 531 | if (ex_style & WS_EX_TOOLWINDOW) |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 532 | { |
| 533 | Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY); |
| 534 | XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE), |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 535 | XA_ATOM, 32, PropModeReplace, (unsigned char*)&a, 1); |
Mike Hearn | 27d972f | 2003-12-04 21:54:13 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 538 | mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; |
| 539 | mwm_hints.functions = 0; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 540 | if ((style & WS_CAPTION) == WS_CAPTION) mwm_hints.functions |= MWM_FUNC_MOVE; |
| 541 | if (style & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE; |
| 542 | if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE; |
| 543 | if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE; |
| 544 | if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE; |
Maxime Bellengé | ca6cb6b | 2005-03-08 18:58:25 +0000 | [diff] [blame] | 545 | if (ex_style & WS_EX_APPWINDOW) mwm_hints.functions |= MWM_FUNC_MOVE; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 546 | mwm_hints.decorations = 0; |
Maxime Bellengé | ca6cb6b | 2005-03-08 18:58:25 +0000 | [diff] [blame] | 547 | if ((style & WS_CAPTION) == WS_CAPTION) |
| 548 | { |
| 549 | mwm_hints.decorations |= MWM_DECOR_TITLE; |
| 550 | if (style & WS_SYSMENU) mwm_hints.decorations |= MWM_DECOR_MENU; |
| 551 | if (style & WS_MINIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MINIMIZE; |
| 552 | if (style & WS_MAXIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MAXIMIZE; |
| 553 | } |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 554 | if (ex_style & WS_EX_DLGMODALFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER; |
| 555 | else if (style & WS_THICKFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH; |
| 556 | else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER; |
| 557 | else if (style & WS_BORDER) mwm_hints.decorations |= MWM_DECOR_BORDER; |
| 558 | else if (!(style & (WS_CHILD|WS_POPUP))) mwm_hints.decorations |= MWM_DECOR_BORDER; |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 559 | |
| 560 | XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS), |
| 561 | x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace, |
Hans Leidekker | ac147fe | 2005-03-22 21:17:34 +0000 | [diff] [blame] | 562 | (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 563 | |
Ulrich Czekalla | 032bdc9 | 2003-11-20 22:09:51 +0000 | [diff] [blame] | 564 | XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware), |
| 565 | XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 ); |
| 566 | |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 567 | wm_hints = XAllocWMHints(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 568 | wine_tsx11_unlock(); |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 569 | |
| 570 | /* wm hints */ |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 571 | if (wm_hints) |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 572 | { |
| 573 | wm_hints->flags = InputHint | StateHint | WindowGroupHint; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 574 | wm_hints->input = !(style & WS_DISABLED); |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 575 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 576 | set_icon_hints( display, data, wm_hints, |
Dmitry Timoshkov | 39f960b | 2005-02-15 21:51:06 +0000 | [diff] [blame] | 577 | (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON ) ); |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 578 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 579 | wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState; |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 580 | wm_hints->window_group = group_leader; |
| 581 | |
| 582 | wine_tsx11_lock(); |
| 583 | XSetWMHints( display, data->whole_window, wm_hints ); |
| 584 | XFree(wm_hints); |
| 585 | wine_tsx11_unlock(); |
| 586 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
| 590 | /*********************************************************************** |
| 591 | * X11DRV_set_iconic_state |
| 592 | * |
| 593 | * Set the X11 iconic state according to the window style. |
| 594 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 595 | void X11DRV_set_iconic_state( HWND hwnd ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 596 | { |
| 597 | Display *display = thread_display(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 598 | struct x11drv_win_data *data; |
| 599 | RECT rect; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 600 | XWMHints* wm_hints; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 601 | DWORD style = GetWindowLongW( hwnd, GWL_STYLE ); |
| 602 | BOOL iconic = (style & WS_MINIMIZE) != 0; |
| 603 | |
| 604 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | c44410d | 2006-03-28 12:21:37 +0200 | [diff] [blame] | 605 | if (!data->whole_window || data->whole_window == DefaultRootWindow(display)) return; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 606 | |
| 607 | GetWindowRect( hwnd, &rect ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 608 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 609 | wine_tsx11_lock(); |
| 610 | |
| 611 | if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints(); |
| 612 | wm_hints->flags |= StateHint | IconPositionHint; |
| 613 | wm_hints->initial_state = iconic ? IconicState : NormalState; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 614 | wm_hints->icon_x = rect.left; |
| 615 | wm_hints->icon_y = rect.top; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 616 | XSetWMHints( display, data->whole_window, wm_hints ); |
| 617 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 618 | if (style & WS_VISIBLE) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 619 | { |
| 620 | if (iconic) |
| 621 | XIconifyWindow( display, data->whole_window, DefaultScreen(display) ); |
| 622 | else |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 623 | if (X11DRV_is_window_rect_mapped( &rect )) |
Alexandre Julliard | 59b7d34 | 2004-04-27 23:32:01 +0000 | [diff] [blame] | 624 | XMapWindow( display, data->whole_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | XFree(wm_hints); |
| 628 | wine_tsx11_unlock(); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | /*********************************************************************** |
| 633 | * X11DRV_window_to_X_rect |
| 634 | * |
| 635 | * Convert a rect from client to X window coordinates |
| 636 | */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 637 | void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 638 | { |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 639 | RECT rc; |
| 640 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 641 | if (!data->managed) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 642 | if (IsRectEmpty( rect )) return; |
| 643 | |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 644 | rc.top = rc.bottom = rc.left = rc.right = 0; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 645 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 646 | AdjustWindowRectEx( &rc, GetWindowLongW( data->hwnd, GWL_STYLE ) & ~(WS_HSCROLL|WS_VSCROLL), |
| 647 | FALSE, GetWindowLongW( data->hwnd, GWL_EXSTYLE ) ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 648 | |
Alexandre Julliard | 8cd1f71 | 2001-07-20 18:37:37 +0000 | [diff] [blame] | 649 | rect->left -= rc.left; |
| 650 | rect->right -= rc.right; |
| 651 | rect->top -= rc.top; |
| 652 | rect->bottom -= rc.bottom; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 653 | if (rect->top >= rect->bottom) rect->bottom = rect->top + 1; |
| 654 | if (rect->left >= rect->right) rect->right = rect->left + 1; |
| 655 | } |
| 656 | |
| 657 | |
| 658 | /*********************************************************************** |
| 659 | * X11DRV_X_to_window_rect |
| 660 | * |
| 661 | * Opposite of X11DRV_window_to_X_rect |
| 662 | */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 663 | void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 664 | { |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 665 | if (!data->managed) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 666 | if (IsRectEmpty( rect )) return; |
| 667 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 668 | AdjustWindowRectEx( rect, GetWindowLongW( data->hwnd, GWL_STYLE ) & ~(WS_HSCROLL|WS_VSCROLL), |
| 669 | FALSE, GetWindowLongW( data->hwnd, GWL_EXSTYLE )); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 670 | |
| 671 | if (rect->top >= rect->bottom) rect->bottom = rect->top + 1; |
| 672 | if (rect->left >= rect->right) rect->right = rect->left + 1; |
| 673 | } |
| 674 | |
| 675 | |
| 676 | /*********************************************************************** |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 677 | * X11DRV_sync_window_position |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 678 | * |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 679 | * Synchronize the X window position with the Windows one |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 680 | */ |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 681 | void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data, |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 682 | UINT swp_flags, const RECT *new_client_rect, |
| 683 | const RECT *new_whole_rect ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 684 | { |
| 685 | XWindowChanges changes; |
| 686 | int mask; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 687 | RECT old_whole_rect; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 688 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 689 | old_whole_rect = data->whole_rect; |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 690 | data->whole_rect = *new_whole_rect; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 691 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 692 | data->client_rect = *new_client_rect; |
| 693 | OffsetRect( &data->client_rect, -data->whole_rect.left, -data->whole_rect.top ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 694 | |
Alexandre Julliard | 3217e53 | 2006-03-29 18:27:01 +0200 | [diff] [blame] | 695 | if (!data->whole_window || data->lock_changes) return; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 696 | |
| 697 | mask = get_window_changes( &changes, &old_whole_rect, &data->whole_rect ); |
| 698 | |
| 699 | if (!(swp_flags & SWP_NOZORDER)) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 700 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 701 | /* find window that this one must be after */ |
| 702 | HWND prev = GetWindow( data->hwnd, GW_HWNDPREV ); |
| 703 | while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)) |
| 704 | prev = GetWindow( prev, GW_HWNDPREV ); |
| 705 | if (!prev) /* top child */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 706 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 707 | changes.stack_mode = Above; |
| 708 | mask |= CWStackMode; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 709 | } |
| 710 | else |
| 711 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 712 | /* should use stack_mode Below but most window managers don't get it right */ |
| 713 | /* so move it above the next one in Z order */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 714 | HWND next = GetWindow( data->hwnd, GW_HWNDNEXT ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 715 | while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE)) |
| 716 | next = GetWindow( next, GW_HWNDNEXT ); |
| 717 | if (next) |
Alexandre Julliard | 08eac70 | 2003-05-19 19:08:57 +0000 | [diff] [blame] | 718 | { |
| 719 | changes.stack_mode = Above; |
| 720 | changes.sibling = X11DRV_get_whole_window(next); |
| 721 | mask |= CWStackMode | CWSibling; |
| 722 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 726 | if (mask) |
| 727 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 728 | DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE ); |
| 729 | |
Dan Kegel | 0fd521f | 2003-01-08 21:09:25 +0000 | [diff] [blame] | 730 | TRACE( "setting win %lx pos %ld,%ld,%ldx%ld after %lx changes=%x\n", |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 731 | data->whole_window, data->whole_rect.left, data->whole_rect.top, |
| 732 | data->whole_rect.right - data->whole_rect.left, |
| 733 | data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask ); |
| 734 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 735 | wine_tsx11_lock(); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 736 | if (mask & (CWWidth|CWHeight)) set_size_hints( display, data, style ); |
| 737 | XReconfigureWMWindow( display, data->whole_window, |
| 738 | DefaultScreen(display), mask, &changes ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 739 | wine_tsx11_unlock(); |
| 740 | } |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 744 | /********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 745 | * create_whole_window |
| 746 | * |
| 747 | * Create the whole X window for a given window |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 748 | */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 749 | static Window create_whole_window( Display *display, struct x11drv_win_data *data, DWORD style ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 750 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 751 | int cx, cy, mask; |
| 752 | XSetWindowAttributes attr; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 753 | XIM xim; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 754 | RECT rect; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 755 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 756 | rect = data->window_rect; |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 757 | X11DRV_window_to_X_rect( data, &rect ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 758 | |
| 759 | if (!(cx = rect.right - rect.left)) cx = 1; |
| 760 | if (!(cy = rect.bottom - rect.top)) cy = 1; |
| 761 | |
Alexandre Julliard | 6bb18e2 | 2006-03-27 15:33:43 +0200 | [diff] [blame] | 762 | mask = get_window_attributes( display, data, &attr ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 763 | |
| 764 | /* set the attributes that don't change over the lifetime of the window */ |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 765 | attr.bit_gravity = NorthWestGravity; |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 766 | attr.backing_store = NotUseful; |
Alexandre Julliard | 2431a64 | 2005-07-27 15:22:58 +0000 | [diff] [blame] | 767 | attr.event_mask = (ExposureMask | PointerMotionMask | |
| 768 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | |
| 769 | KeyPressMask | KeyReleaseMask | StructureNotifyMask | |
| 770 | FocusChangeMask | KeymapStateMask); |
| 771 | mask |= CWBitGravity | CWBackingStore | CWEventMask; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 772 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 773 | wine_tsx11_lock(); |
| 774 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 775 | data->whole_rect = rect; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 776 | data->whole_window = XCreateWindow( display, root_window, rect.left, rect.top, cx, cy, |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 777 | 0, screen_depth, InputOutput, visual, |
| 778 | mask, &attr ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 779 | |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 780 | if (!data->whole_window) |
| 781 | { |
| 782 | wine_tsx11_unlock(); |
| 783 | return 0; |
| 784 | } |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 785 | XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 786 | |
| 787 | /* non-maximized child must be at bottom of Z order */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 788 | if ((style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 789 | { |
| 790 | XWindowChanges changes; |
| 791 | changes.stack_mode = Below; |
| 792 | XConfigureWindow( display, data->whole_window, CWStackMode, &changes ); |
| 793 | } |
Alexandre Julliard | 704d035 | 2001-07-12 02:49:31 +0000 | [diff] [blame] | 794 | wine_tsx11_unlock(); |
| 795 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 796 | xim = x11drv_thread_data()->xim; |
| 797 | if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 798 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 799 | X11DRV_set_wm_hints( display, data ); |
| 800 | |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 801 | SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 802 | return data->whole_window; |
| 803 | } |
| 804 | |
| 805 | |
| 806 | /********************************************************************** |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 807 | * destroy_whole_window |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 808 | * |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 809 | * Destroy the whole X window for a given window. |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 810 | */ |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 811 | static void destroy_whole_window( Display *display, struct x11drv_win_data *data ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 812 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 813 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 814 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 815 | if (!data->whole_window) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 816 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 817 | TRACE( "win %p xwin %lx\n", data->hwnd, data->whole_window ); |
| 818 | if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 819 | wine_tsx11_lock(); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 820 | XDeleteContext( display, data->whole_window, winContext ); |
Alexandre Julliard | 6d5f544 | 2006-03-06 21:02:59 +0100 | [diff] [blame] | 821 | if (data->whole_window != DefaultRootWindow(display)) |
| 822 | XDestroyWindow( display, data->whole_window ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 823 | data->whole_window = 0; |
| 824 | if (data->xic) |
| 825 | { |
| 826 | XUnsetICFocus( data->xic ); |
| 827 | XDestroyIC( data->xic ); |
| 828 | } |
Alexandre Julliard | 975f1b2 | 2006-05-09 17:32:40 +0200 | [diff] [blame] | 829 | /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */ |
| 830 | XFlush( display ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 831 | wine_tsx11_unlock(); |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 832 | RemovePropA( data->hwnd, whole_window_prop ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | |
| 836 | /***************************************************************** |
| 837 | * SetWindowText (X11DRV.@) |
| 838 | */ |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 839 | void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 840 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 841 | Display *display = thread_display(); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 842 | UINT count; |
| 843 | char *buffer; |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 844 | char *utf8_buffer; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 845 | Window win; |
Kusanagi Kouichi | 44dcf6a | 2003-06-20 23:29:06 +0000 | [diff] [blame] | 846 | XTextProperty prop; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 847 | |
Alexandre Julliard | c44410d | 2006-03-28 12:21:37 +0200 | [diff] [blame] | 848 | if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display)) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 849 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 850 | /* allocate new buffer for window text */ |
Dmitry Timoshkov | 8a8d1b9 | 2003-07-09 04:22:57 +0000 | [diff] [blame] | 851 | count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL); |
Dmitry Timoshkov | 4bc0b28 | 2001-08-22 18:04:00 +0000 | [diff] [blame] | 852 | if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 853 | { |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 854 | ERR("Not enough memory for window text\n"); |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 855 | return; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 856 | } |
Dmitry Timoshkov | 8a8d1b9 | 2003-07-09 04:22:57 +0000 | [diff] [blame] | 857 | WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 858 | |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 859 | count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL); |
| 860 | if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count ))) |
| 861 | { |
| 862 | ERR("Not enough memory for window text in UTF-8\n"); |
Michael Stefaniuc | 1493433 | 2004-12-14 11:38:50 +0000 | [diff] [blame] | 863 | HeapFree( GetProcessHeap(), 0, buffer ); |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 864 | return; |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 865 | } |
| 866 | WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL); |
| 867 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 868 | wine_tsx11_lock(); |
Kusanagi Kouichi | 44dcf6a | 2003-06-20 23:29:06 +0000 | [diff] [blame] | 869 | if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success) |
| 870 | { |
| 871 | XSetWMName( display, win, &prop ); |
| 872 | XSetWMIconName( display, win, &prop ); |
| 873 | XFree( prop.value ); |
| 874 | } |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 875 | /* |
| 876 | Implements a NET_WM UTF-8 title. It should be without a trailing \0, |
| 877 | according to the standard |
| 878 | ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ). |
| 879 | */ |
Alexandre Julliard | d09c328 | 2003-11-20 04:24:18 +0000 | [diff] [blame] | 880 | XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING), |
| 881 | 8, PropModeReplace, (unsigned char *) utf8_buffer, count); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 882 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 883 | |
Ilya Konstantinov | 560ca32 | 2001-10-02 18:44:56 +0000 | [diff] [blame] | 884 | HeapFree( GetProcessHeap(), 0, utf8_buffer ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 885 | HeapFree( GetProcessHeap(), 0, buffer ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 886 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
| 890 | /*********************************************************************** |
| 891 | * DestroyWindow (X11DRV.@) |
| 892 | */ |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 893 | void X11DRV_DestroyWindow( HWND hwnd ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 894 | { |
Alexandre Julliard | 9428f06 | 2002-06-14 00:08:40 +0000 | [diff] [blame] | 895 | struct x11drv_thread_data *thread_data = x11drv_thread_data(); |
| 896 | Display *display = thread_data->display; |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 897 | struct x11drv_win_data *data; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 898 | |
Alexandre Julliard | 2997fc5 | 2005-07-18 13:20:18 +0000 | [diff] [blame] | 899 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 900 | |
Alexandre Julliard | 2fb7c87 | 2005-03-25 16:47:04 +0000 | [diff] [blame] | 901 | free_window_dce( data ); |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 902 | destroy_whole_window( display, data ); |
| 903 | destroy_icon_window( display, data ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 904 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 905 | if (thread_data->last_focus == hwnd) thread_data->last_focus = 0; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 906 | if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap ); |
| 907 | if (data->hWMIconMask) DeleteObject( data->hWMIconMask); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 908 | wine_tsx11_lock(); |
Alexandre Julliard | e551555 | 2005-02-09 14:01:40 +0000 | [diff] [blame] | 909 | XDeleteContext( display, (XID)hwnd, win_data_context ); |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 910 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 911 | HeapFree( GetProcessHeap(), 0, data ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 915 | static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd ) |
| 916 | { |
| 917 | struct x11drv_win_data *data; |
| 918 | |
| 919 | if ((data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data)))) |
| 920 | { |
| 921 | data->hwnd = hwnd; |
| 922 | data->whole_window = 0; |
| 923 | data->icon_window = 0; |
| 924 | data->xic = 0; |
| 925 | data->managed = FALSE; |
| 926 | data->dce = NULL; |
Alexandre Julliard | 3217e53 | 2006-03-29 18:27:01 +0200 | [diff] [blame] | 927 | data->lock_changes = 0; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 928 | data->hWMIconBitmap = 0; |
| 929 | data->hWMIconMask = 0; |
| 930 | |
| 931 | wine_tsx11_lock(); |
| 932 | if (!winContext) winContext = XUniqueContext(); |
| 933 | if (!win_data_context) win_data_context = XUniqueContext(); |
| 934 | XSaveContext( display, (XID)hwnd, win_data_context, (char *)data ); |
| 935 | wine_tsx11_unlock(); |
| 936 | } |
| 937 | return data; |
| 938 | } |
| 939 | |
| 940 | |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 941 | /* fill in the desktop X window id in the x11drv_win_data structure */ |
| 942 | static void get_desktop_xwin( Display *display, struct x11drv_win_data *data ) |
| 943 | { |
| 944 | RECT rect; |
| 945 | Window win = (Window)GetPropA( data->hwnd, whole_window_prop ); |
| 946 | |
| 947 | if (win) |
| 948 | { |
Alexandre Julliard | bec4990 | 2006-03-28 16:55:03 +0200 | [diff] [blame] | 949 | unsigned int width, height; |
| 950 | |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 951 | /* retrieve the real size of the desktop */ |
| 952 | SERVER_START_REQ( get_window_rectangles ) |
| 953 | { |
| 954 | req->handle = data->hwnd; |
Alexandre Julliard | bec4990 | 2006-03-28 16:55:03 +0200 | [diff] [blame] | 955 | wine_server_call( req ); |
| 956 | width = reply->window.right - reply->window.left; |
| 957 | height = reply->window.bottom - reply->window.top; |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 958 | } |
| 959 | SERVER_END_REQ; |
Alexandre Julliard | bec4990 | 2006-03-28 16:55:03 +0200 | [diff] [blame] | 960 | data->whole_window = win; |
| 961 | if (win != root_window) X11DRV_init_desktop( win, width, height ); |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 962 | } |
| 963 | else |
| 964 | { |
| 965 | VisualID visualid; |
| 966 | |
| 967 | wine_tsx11_lock(); |
| 968 | visualid = XVisualIDFromVisual(visual); |
| 969 | wine_tsx11_unlock(); |
| 970 | SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window ); |
| 971 | SetPropA( data->hwnd, visual_id_prop, (HANDLE)visualid ); |
| 972 | data->whole_window = root_window; |
| 973 | SetRect( &rect, 0, 0, screen_width, screen_height ); |
| 974 | X11DRV_set_window_pos( data->hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL ); |
| 975 | if (root_window != DefaultRootWindow( display )) |
| 976 | { |
| 977 | data->managed = TRUE; |
| 978 | SetPropA( data->hwnd, managed_prop, (HANDLE)1 ); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 983 | /********************************************************************** |
| 984 | * CreateDesktopWindow (X11DRV.@) |
| 985 | */ |
| 986 | BOOL X11DRV_CreateDesktopWindow( HWND hwnd ) |
| 987 | { |
| 988 | Display *display = thread_display(); |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 989 | struct x11drv_win_data *data; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 990 | |
| 991 | if (!(data = alloc_win_data( display, hwnd ))) return FALSE; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 992 | |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 993 | get_desktop_xwin( display, data ); |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 994 | |
| 995 | return TRUE; |
| 996 | } |
| 997 | |
| 998 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 999 | /********************************************************************** |
| 1000 | * CreateWindow (X11DRV.@) |
| 1001 | */ |
Gerard Patel | ad36303 | 2001-06-06 21:26:50 +0000 | [diff] [blame] | 1002 | BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode ) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1003 | { |
| 1004 | Display *display = thread_display(); |
| 1005 | WND *wndPtr; |
| 1006 | struct x11drv_win_data *data; |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1007 | HWND insert_after; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1008 | RECT rect; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1009 | DWORD style; |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 1010 | CBT_CREATEWNDA cbtc; |
Robert Shearman | caec602 | 2005-03-23 10:26:15 +0000 | [diff] [blame] | 1011 | CREATESTRUCTA cbcs; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1012 | BOOL ret = FALSE; |
| 1013 | |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1014 | if (!(data = alloc_win_data( display, hwnd ))) return FALSE; |
| 1015 | |
Michael Cardenas | f0b6b9a | 2002-05-07 01:52:15 +0000 | [diff] [blame] | 1016 | if (cs->cx > 65535) |
| 1017 | { |
| 1018 | ERR( "invalid window width %d\n", cs->cx ); |
| 1019 | cs->cx = 65535; |
| 1020 | } |
| 1021 | if (cs->cy > 65535) |
| 1022 | { |
Evan Deaubl | 627423d | 2004-08-26 18:11:29 +0000 | [diff] [blame] | 1023 | ERR( "invalid window height %d\n", cs->cy ); |
Michael Cardenas | f0b6b9a | 2002-05-07 01:52:15 +0000 | [diff] [blame] | 1024 | cs->cy = 65535; |
| 1025 | } |
Alexandre Julliard | 25b6493 | 2004-12-09 16:58:00 +0000 | [diff] [blame] | 1026 | if (cs->cx < 0) |
| 1027 | { |
| 1028 | ERR( "invalid window width %d\n", cs->cx ); |
| 1029 | cs->cx = 0; |
| 1030 | } |
| 1031 | if (cs->cy < 0) |
| 1032 | { |
| 1033 | ERR( "invalid window height %d\n", cs->cy ); |
| 1034 | cs->cy = 0; |
| 1035 | } |
Michael Cardenas | f0b6b9a | 2002-05-07 01:52:15 +0000 | [diff] [blame] | 1036 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1037 | /* initialize the dimensions before sending WM_GETMINMAXINFO */ |
| 1038 | SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy ); |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 1039 | X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL ); |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1040 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1041 | /* create an X window if it's a top level window */ |
Alexandre Julliard | e419cb8 | 2005-07-07 20:33:29 +0000 | [diff] [blame] | 1042 | if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow()) |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1043 | { |
| 1044 | if (!create_whole_window( display, data, cs->style )) goto failed; |
| 1045 | } |
Alexandre Julliard | db6608a | 2006-03-27 22:43:03 +0200 | [diff] [blame] | 1046 | else if (hwnd == GetDesktopWindow()) |
| 1047 | { |
| 1048 | get_desktop_xwin( display, data ); |
| 1049 | } |
Alexandre Julliard | 649637f | 2001-06-26 21:10:11 +0000 | [diff] [blame] | 1050 | |
Alexandre Julliard | 2fb7c87 | 2005-03-25 16:47:04 +0000 | [diff] [blame] | 1051 | /* get class or window DC if needed */ |
| 1052 | alloc_window_dce( data ); |
| 1053 | |
Rein Klazes | 0f2f2b3 | 2002-01-09 19:09:06 +0000 | [diff] [blame] | 1054 | /* Call the WH_CBT hook */ |
Alexandre Julliard | 2fb7c87 | 2005-03-25 16:47:04 +0000 | [diff] [blame] | 1055 | |
Robert Shearman | caec602 | 2005-03-23 10:26:15 +0000 | [diff] [blame] | 1056 | /* the window style passed to the hook must be the real window style, |
| 1057 | * rather than just the window style that the caller to CreateWindowEx |
| 1058 | * passed in, so we have to copy the original CREATESTRUCT and get the |
| 1059 | * the real style. */ |
| 1060 | cbcs = *cs; |
| 1061 | cbcs.style = GetWindowLongW(hwnd, GWL_STYLE); |
| 1062 | |
| 1063 | cbtc.lpcs = &cbcs; |
Dmitry Timoshkov | c99317a | 2003-10-24 04:21:46 +0000 | [diff] [blame] | 1064 | cbtc.hwndInsertAfter = HWND_TOP; |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 1065 | if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode )) |
Rein Klazes | 0f2f2b3 | 2002-01-09 19:09:06 +0000 | [diff] [blame] | 1066 | { |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 1067 | TRACE("CBT-hook returned !0\n"); |
| 1068 | goto failed; |
Rein Klazes | 0f2f2b3 | 2002-01-09 19:09:06 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1071 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */ |
| 1072 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD))) |
| 1073 | { |
| 1074 | POINT maxSize, maxPos, minTrack, maxTrack; |
| 1075 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1076 | WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack); |
| 1077 | if (maxSize.x < cs->cx) cs->cx = maxSize.x; |
| 1078 | if (maxSize.y < cs->cy) cs->cy = maxSize.y; |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1079 | if (cs->cx < 0) cs->cx = 0; |
| 1080 | if (cs->cy < 0) cs->cy = 0; |
| 1081 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1082 | SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy ); |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 1083 | if (!X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL )) return FALSE; |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1084 | } |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1085 | |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1086 | /* send WM_NCCREATE */ |
Alexandre Julliard | e0315e4 | 2002-10-31 02:38:20 +0000 | [diff] [blame] | 1087 | TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1088 | if (unicode) |
| 1089 | ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs ); |
| 1090 | else |
| 1091 | ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs ); |
| 1092 | if (!ret) |
| 1093 | { |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1094 | WARN("aborted by WM_xxCREATE!\n"); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1095 | return FALSE; |
| 1096 | } |
| 1097 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1098 | /* make sure the window is still valid */ |
| 1099 | if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1100 | if (data->whole_window) X11DRV_sync_window_style( display, data ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1101 | |
| 1102 | /* send WM_NCCALCSIZE */ |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1103 | rect = data->window_rect; |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1104 | SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect ); |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1105 | |
| 1106 | if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE; |
Alexandre Julliard | 5defa49 | 2004-12-07 17:31:53 +0000 | [diff] [blame] | 1107 | |
| 1108 | /* yes, even if the CBT hook was called with HWND_TOP */ |
| 1109 | insert_after = ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP; |
| 1110 | |
Alexandre Julliard | ae661da | 2005-02-03 13:40:12 +0000 | [diff] [blame] | 1111 | X11DRV_set_window_pos( hwnd, insert_after, &wndPtr->rectWindow, &rect, 0, NULL ); |
Alexandre Julliard | 883cff4 | 2001-06-12 04:02:10 +0000 | [diff] [blame] | 1112 | |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1113 | TRACE( "win %p window %ld,%ld,%ld,%ld client %ld,%ld,%ld,%ld whole %ld,%ld,%ld,%ld X client %ld,%ld,%ld,%ld xwin %x\n", |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1114 | hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top, |
| 1115 | wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, |
| 1116 | wndPtr->rectClient.left, wndPtr->rectClient.top, |
| 1117 | wndPtr->rectClient.right, wndPtr->rectClient.bottom, |
| 1118 | data->whole_rect.left, data->whole_rect.top, |
| 1119 | data->whole_rect.right, data->whole_rect.bottom, |
| 1120 | data->client_rect.left, data->client_rect.top, |
| 1121 | data->client_rect.right, data->client_rect.bottom, |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1122 | (unsigned int)data->whole_window ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1123 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1124 | WIN_ReleasePtr( wndPtr ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1125 | |
Gerard Patel | ad36303 | 2001-06-06 21:26:50 +0000 | [diff] [blame] | 1126 | if (unicode) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1127 | ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1); |
| 1128 | else |
| 1129 | ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1); |
| 1130 | |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1131 | if (!ret) return FALSE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1132 | |
Dmitry Timoshkov | 6dba0a7 | 2005-02-03 16:40:20 +0000 | [diff] [blame] | 1133 | NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0); |
| 1134 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1135 | /* Send the size messages */ |
| 1136 | |
Alexandre Julliard | 6382ffa | 2005-01-20 20:07:42 +0000 | [diff] [blame] | 1137 | if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return FALSE; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1138 | if (!(wndPtr->flags & WIN_NEED_SIZE)) |
| 1139 | { |
Alexandre Julliard | 6382ffa | 2005-01-20 20:07:42 +0000 | [diff] [blame] | 1140 | RECT rect = wndPtr->rectClient; |
| 1141 | WIN_ReleasePtr( wndPtr ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1142 | /* send it anyway */ |
Alexandre Julliard | 6382ffa | 2005-01-20 20:07:42 +0000 | [diff] [blame] | 1143 | if (((rect.right-rect.left) <0) ||((rect.bottom-rect.top)<0)) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1144 | WARN("sending bogus WM_SIZE message 0x%08lx\n", |
Alexandre Julliard | 6382ffa | 2005-01-20 20:07:42 +0000 | [diff] [blame] | 1145 | MAKELONG(rect.right-rect.left, rect.bottom-rect.top)); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1146 | SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED, |
Alexandre Julliard | 6382ffa | 2005-01-20 20:07:42 +0000 | [diff] [blame] | 1147 | MAKELONG(rect.right-rect.left, rect.bottom-rect.top)); |
| 1148 | SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( rect.left, rect.top ) ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1149 | } |
Alexandre Julliard | 6382ffa | 2005-01-20 20:07:42 +0000 | [diff] [blame] | 1150 | else WIN_ReleasePtr( wndPtr ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1151 | |
| 1152 | /* Show the window, maximizing or minimizing if needed */ |
| 1153 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1154 | style = GetWindowLongW( hwnd, GWL_STYLE ); |
| 1155 | if (style & (WS_MINIMIZE | WS_MAXIMIZE)) |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1156 | { |
| 1157 | extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/ |
| 1158 | |
| 1159 | RECT newPos; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1160 | UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE; |
Alexandre Julliard | f936428 | 2005-01-21 10:32:13 +0000 | [diff] [blame] | 1161 | WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1162 | WINPOS_MinMaximize( hwnd, swFlag, &newPos ); |
Vitaliy Margolen | aae7632 | 2005-11-30 12:32:22 +0100 | [diff] [blame] | 1163 | |
| 1164 | swFlag = SWP_FRAMECHANGED | SWP_NOZORDER; /* Frame always gets changed */ |
| 1165 | if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE; |
| 1166 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1167 | SetWindowPos( hwnd, 0, newPos.left, newPos.top, |
| 1168 | newPos.right, newPos.bottom, swFlag ); |
| 1169 | } |
| 1170 | |
| 1171 | return TRUE; |
| 1172 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1173 | failed: |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 1174 | X11DRV_DestroyWindow( hwnd ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1175 | return FALSE; |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | /*********************************************************************** |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1180 | * X11DRV_get_win_data |
| 1181 | * |
| 1182 | * Return the X11 data structure associated with a window. |
| 1183 | */ |
| 1184 | struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd ) |
| 1185 | { |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1186 | char *data; |
Alexandre Julliard | e551555 | 2005-02-09 14:01:40 +0000 | [diff] [blame] | 1187 | |
| 1188 | if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL; |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1189 | return (struct x11drv_win_data *)data; |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | /*********************************************************************** |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1194 | * X11DRV_get_whole_window |
| 1195 | * |
| 1196 | * Return the X window associated with the full area of a window |
| 1197 | */ |
| 1198 | Window X11DRV_get_whole_window( HWND hwnd ) |
| 1199 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1200 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 1201 | |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 1202 | if (!data) return (Window)GetPropA( hwnd, whole_window_prop ); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1203 | return data->whole_window; |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1207 | /*********************************************************************** |
| 1208 | * X11DRV_get_ic |
| 1209 | * |
| 1210 | * Return the X input context associated with a window |
| 1211 | */ |
| 1212 | XIC X11DRV_get_ic( HWND hwnd ) |
| 1213 | { |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1214 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1215 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1216 | if (!data) return 0; |
| 1217 | return data->xic; |
Alexandre Julliard | 8b6a219 | 2003-01-23 01:28:12 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1221 | /***************************************************************** |
| 1222 | * SetParent (X11DRV.@) |
| 1223 | */ |
| 1224 | HWND X11DRV_SetParent( HWND hwnd, HWND parent ) |
| 1225 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1226 | Display *display = thread_display(); |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1227 | WND *wndPtr; |
| 1228 | BOOL ret; |
| 1229 | HWND old_parent = 0; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1230 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1231 | /* Windows hides the window first, then shows it again |
| 1232 | * including the WM_SHOWWINDOW messages and all */ |
Alexandre Julliard | fb0ff05 | 2001-10-16 21:58:58 +0000 | [diff] [blame] | 1233 | BOOL was_visible = ShowWindow( hwnd, SW_HIDE ); |
| 1234 | |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1235 | wndPtr = WIN_GetPtr( hwnd ); |
| 1236 | if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return 0; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1237 | |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1238 | SERVER_START_REQ( set_parent ) |
| 1239 | { |
| 1240 | req->handle = hwnd; |
| 1241 | req->parent = parent; |
| 1242 | if ((ret = !wine_server_call( req ))) |
| 1243 | { |
| 1244 | old_parent = reply->old_parent; |
| 1245 | wndPtr->parent = parent = reply->full_parent; |
| 1246 | } |
| 1247 | |
| 1248 | } |
| 1249 | SERVER_END_REQ; |
| 1250 | WIN_ReleasePtr( wndPtr ); |
| 1251 | if (!ret) return 0; |
| 1252 | |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1253 | if (parent != old_parent) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1254 | { |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1255 | struct x11drv_win_data *data = X11DRV_get_win_data( hwnd ); |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1256 | |
Alexandre Julliard | 4d32a47 | 2005-03-25 10:38:56 +0000 | [diff] [blame] | 1257 | if (!data) return 0; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1258 | |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1259 | if (parent != GetDesktopWindow()) /* a child window */ |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1260 | { |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1261 | if (old_parent == GetDesktopWindow()) |
| 1262 | { |
| 1263 | /* destroy the old X windows */ |
| 1264 | destroy_whole_window( display, data ); |
| 1265 | destroy_icon_window( display, data ); |
Dmitry Timoshkov | d5e1804 | 2005-05-24 11:44:59 +0000 | [diff] [blame] | 1266 | if (data->managed) |
| 1267 | { |
| 1268 | data->managed = FALSE; |
Alexandre Julliard | af50ad6 | 2005-07-07 17:30:57 +0000 | [diff] [blame] | 1269 | RemovePropA( data->hwnd, managed_prop ); |
Dmitry Timoshkov | d5e1804 | 2005-05-24 11:44:59 +0000 | [diff] [blame] | 1270 | } |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1271 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1272 | } |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1273 | else /* new top level window */ |
| 1274 | { |
| 1275 | /* FIXME: we ignore errors since we can't really recover anyway */ |
| 1276 | create_whole_window( display, data, GetWindowLongW( hwnd, GWL_STYLE ) ); |
| 1277 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1278 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1279 | |
| 1280 | /* SetParent additionally needs to make hwnd the topmost window |
| 1281 | in the x-order and send the expected WM_WINDOWPOSCHANGING and |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1282 | WM_WINDOWPOSCHANGED notification messages. |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1283 | */ |
| 1284 | SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, |
Alexandre Julliard | fb0ff05 | 2001-10-16 21:58:58 +0000 | [diff] [blame] | 1285 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1286 | /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler |
| 1287 | * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */ |
| 1288 | |
Alexandre Julliard | d56ccaa | 2005-01-28 17:25:50 +0000 | [diff] [blame] | 1289 | return old_parent; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1293 | /***************************************************************** |
| 1294 | * SetFocus (X11DRV.@) |
| 1295 | * |
| 1296 | * Set the X focus. |
| 1297 | * Explicit colormap management seems to work only with OLVWM. |
| 1298 | */ |
| 1299 | void X11DRV_SetFocus( HWND hwnd ) |
| 1300 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1301 | Display *display = thread_display(); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1302 | struct x11drv_win_data *data; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1303 | XWindowAttributes win_attr; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1304 | |
| 1305 | /* Only mess with the X focus if there's */ |
| 1306 | /* no desktop window and if the window is not managed by the WM. */ |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1307 | if (root_window != DefaultRootWindow(display)) return; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1308 | |
| 1309 | if (!hwnd) /* If setting the focus to 0, uninstall the colormap */ |
| 1310 | { |
Alexandre Julliard | 2496c08 | 2003-11-21 00:17:33 +0000 | [diff] [blame] | 1311 | wine_tsx11_lock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1312 | if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE) |
Alexandre Julliard | 2496c08 | 2003-11-21 00:17:33 +0000 | [diff] [blame] | 1313 | XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap ); |
| 1314 | wine_tsx11_unlock(); |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1315 | return; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1316 | } |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1317 | |
| 1318 | hwnd = GetAncestor( hwnd, GA_ROOT ); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1319 | |
| 1320 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Todd Mokros | 88ac4b9 | 2005-08-22 09:14:21 +0000 | [diff] [blame] | 1321 | if (data->managed || !data->whole_window) return; |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1322 | |
| 1323 | /* Set X focus and install colormap */ |
| 1324 | wine_tsx11_lock(); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1325 | if (XGetWindowAttributes( display, data->whole_window, &win_attr ) && |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1326 | (win_attr.map_state == IsViewable)) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1327 | { |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1328 | /* If window is not viewable, don't change anything */ |
Alexandre Julliard | dc4fe77 | 2001-06-04 21:55:17 +0000 | [diff] [blame] | 1329 | |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1330 | /* we must not use CurrentTime (ICCCM), so try to use last message time instead */ |
| 1331 | /* FIXME: this is not entirely correct */ |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1332 | XSetInputFocus( display, data->whole_window, RevertToParent, |
Jeremy White | 77502e7 | 2005-01-14 17:06:40 +0000 | [diff] [blame] | 1333 | /* CurrentTime */ |
| 1334 | GetMessageTime() - EVENT_x11_time_to_win32_time(0)); |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1335 | if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE) |
| 1336 | XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap ); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1337 | } |
Alexandre Julliard | 0801ffc | 2001-08-24 00:26:59 +0000 | [diff] [blame] | 1338 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1342 | /********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1343 | * SetWindowIcon (X11DRV.@) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1344 | * |
| 1345 | * hIcon or hIconSm has changed (or is being initialised for the |
| 1346 | * first time). Complete the X11 driver-specific initialisation |
| 1347 | * and set the window hints. |
| 1348 | * |
| 1349 | * This is not entirely correct, may need to create |
| 1350 | * an icon window and set the pixmap as a background |
| 1351 | */ |
Alexandre Julliard | 446d832 | 2003-12-31 23:51:52 +0000 | [diff] [blame] | 1352 | void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon ) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1353 | { |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 1354 | Display *display = thread_display(); |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1355 | struct x11drv_win_data *data; |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1356 | XWMHints* wm_hints; |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1357 | |
Alexandre Julliard | 446d832 | 2003-12-31 23:51:52 +0000 | [diff] [blame] | 1358 | if (type != ICON_BIG) return; /* nothing to do here */ |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1359 | |
Alexandre Julliard | fc5ce14 | 2005-01-17 19:17:47 +0000 | [diff] [blame] | 1360 | if (!(data = X11DRV_get_win_data( hwnd ))) return; |
Alexandre Julliard | f777d70 | 2005-01-31 16:34:07 +0000 | [diff] [blame] | 1361 | if (!data->whole_window) return; |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1362 | if (!data->managed) return; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 1363 | |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1364 | wine_tsx11_lock(); |
| 1365 | if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints(); |
| 1366 | wine_tsx11_unlock(); |
| 1367 | if (wm_hints) |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1368 | { |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1369 | set_icon_hints( display, data, wm_hints, icon ); |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 1370 | wine_tsx11_lock(); |
Alexandre Julliard | d7726c3 | 2005-02-01 18:53:59 +0000 | [diff] [blame] | 1371 | XSetWMHints( display, data->whole_window, wm_hints ); |
| 1372 | XFree( wm_hints ); |
Alexandre Julliard | e9119c1 | 2002-09-24 18:36:51 +0000 | [diff] [blame] | 1373 | wine_tsx11_unlock(); |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1374 | } |
Alexandre Julliard | 9ae0fe5 | 2001-04-24 23:28:52 +0000 | [diff] [blame] | 1375 | } |