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