[14481] | 1 | /* GTK - The GIMP Toolkit |
---|
| 2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
| 3 | * |
---|
| 4 | * This library is free software; you can redistribute it and/or |
---|
| 5 | * modify it under the terms of the GNU Library General Public |
---|
| 6 | * License as published by the Free Software Foundation; either |
---|
| 7 | * version 2 of the License, or (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This library is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 12 | * Library General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU Library General Public |
---|
| 15 | * License along with this library; if not, write to the Free |
---|
| 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | /* By Owen Taylor <otaylor@gtk.org> 98/4/4 */ |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS |
---|
| 23 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
| 24 | * files for a list of changes. These files are distributed with |
---|
| 25 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include "gdk/gdkx.h" |
---|
| 29 | #include "gdk/gdkkeysyms.h" |
---|
| 30 | #include "gtkwindow.h" |
---|
| 31 | #include "gtksignal.h" |
---|
| 32 | #include "gtksocket.h" |
---|
| 33 | #include "gtkdnd.h" |
---|
| 34 | |
---|
| 35 | /* Forward declararations */ |
---|
| 36 | |
---|
| 37 | static void gtk_socket_class_init (GtkSocketClass *klass); |
---|
| 38 | static void gtk_socket_init (GtkSocket *socket); |
---|
| 39 | static void gtk_socket_realize (GtkWidget *widget); |
---|
| 40 | static void gtk_socket_unrealize (GtkWidget *widget); |
---|
| 41 | static void gtk_socket_size_request (GtkWidget *widget, |
---|
| 42 | GtkRequisition *requisition); |
---|
| 43 | static void gtk_socket_size_allocate (GtkWidget *widget, |
---|
| 44 | GtkAllocation *allocation); |
---|
| 45 | static gint gtk_socket_focus_in_event (GtkWidget *widget, |
---|
| 46 | GdkEventFocus *event); |
---|
| 47 | static void gtk_socket_claim_focus (GtkSocket *socket); |
---|
| 48 | static gint gtk_socket_focus_out_event (GtkWidget *widget, |
---|
| 49 | GdkEventFocus *event); |
---|
| 50 | static void gtk_socket_send_configure_event (GtkSocket *socket); |
---|
| 51 | static gint gtk_socket_focus (GtkContainer *container, |
---|
| 52 | GtkDirectionType direction); |
---|
| 53 | static GdkFilterReturn gtk_socket_filter_func (GdkXEvent *gdk_xevent, |
---|
| 54 | GdkEvent *event, |
---|
| 55 | gpointer data); |
---|
| 56 | |
---|
| 57 | /* From Tk */ |
---|
| 58 | #define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20 |
---|
| 59 | |
---|
| 60 | /* Local data */ |
---|
| 61 | |
---|
| 62 | static GtkWidgetClass *parent_class = NULL; |
---|
| 63 | |
---|
| 64 | guint |
---|
| 65 | gtk_socket_get_type () |
---|
| 66 | { |
---|
| 67 | static guint socket_type = 0; |
---|
| 68 | |
---|
| 69 | if (!socket_type) |
---|
| 70 | { |
---|
| 71 | static const GtkTypeInfo socket_info = |
---|
| 72 | { |
---|
| 73 | "GtkSocket", |
---|
| 74 | sizeof (GtkSocket), |
---|
| 75 | sizeof (GtkSocketClass), |
---|
| 76 | (GtkClassInitFunc) gtk_socket_class_init, |
---|
| 77 | (GtkObjectInitFunc) gtk_socket_init, |
---|
[15780] | 78 | /* reserved_1 */ NULL, |
---|
| 79 | /* reserved_2 */ NULL, |
---|
| 80 | (GtkClassInitFunc) NULL, |
---|
[14481] | 81 | }; |
---|
| 82 | |
---|
| 83 | socket_type = gtk_type_unique (gtk_container_get_type (), &socket_info); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | return socket_type; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | static void |
---|
| 90 | gtk_socket_class_init (GtkSocketClass *class) |
---|
| 91 | { |
---|
| 92 | GtkObjectClass *object_class; |
---|
| 93 | GtkWidgetClass *widget_class; |
---|
| 94 | GtkContainerClass *container_class; |
---|
| 95 | |
---|
| 96 | object_class = (GtkObjectClass*) class; |
---|
| 97 | widget_class = (GtkWidgetClass*) class; |
---|
| 98 | container_class = (GtkContainerClass*) class; |
---|
| 99 | |
---|
| 100 | parent_class = gtk_type_class (GTK_TYPE_CONTAINER); |
---|
| 101 | |
---|
| 102 | widget_class->realize = gtk_socket_realize; |
---|
| 103 | widget_class->unrealize = gtk_socket_unrealize; |
---|
| 104 | widget_class->size_request = gtk_socket_size_request; |
---|
| 105 | widget_class->size_allocate = gtk_socket_size_allocate; |
---|
| 106 | widget_class->focus_in_event = gtk_socket_focus_in_event; |
---|
| 107 | widget_class->focus_out_event = gtk_socket_focus_out_event; |
---|
| 108 | |
---|
| 109 | container_class->focus = gtk_socket_focus; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | static void |
---|
| 113 | gtk_socket_init (GtkSocket *socket) |
---|
| 114 | { |
---|
| 115 | socket->request_width = 0; |
---|
| 116 | socket->request_height = 0; |
---|
| 117 | socket->current_width = 0; |
---|
| 118 | socket->current_height = 0; |
---|
| 119 | |
---|
| 120 | socket->plug_window = NULL; |
---|
| 121 | socket->same_app = FALSE; |
---|
| 122 | socket->focus_in = FALSE; |
---|
| 123 | socket->have_size = FALSE; |
---|
| 124 | socket->need_map = FALSE; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | GtkWidget* |
---|
| 128 | gtk_socket_new () |
---|
| 129 | { |
---|
| 130 | GtkSocket *socket; |
---|
| 131 | |
---|
| 132 | socket = gtk_type_new (gtk_socket_get_type ()); |
---|
| 133 | |
---|
| 134 | return GTK_WIDGET (socket); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | void |
---|
| 138 | gtk_socket_steal (GtkSocket *socket, guint32 id) |
---|
| 139 | { |
---|
| 140 | GtkWidget *widget; |
---|
| 141 | |
---|
| 142 | widget = GTK_WIDGET (socket); |
---|
| 143 | |
---|
| 144 | socket->plug_window = gdk_window_lookup (id); |
---|
| 145 | |
---|
| 146 | gdk_error_trap_push (); |
---|
| 147 | |
---|
| 148 | if (socket->plug_window && socket->plug_window->user_data) |
---|
| 149 | { |
---|
| 150 | /* |
---|
| 151 | GtkWidget *child_widget; |
---|
| 152 | |
---|
| 153 | child_widget = GTK_WIDGET (socket->plug_window->user_data); |
---|
| 154 | */ |
---|
| 155 | |
---|
| 156 | g_warning("Stealing from same app not yet implemented"); |
---|
| 157 | |
---|
| 158 | socket->same_app = TRUE; |
---|
| 159 | } |
---|
| 160 | else |
---|
| 161 | { |
---|
| 162 | socket->plug_window = gdk_window_foreign_new (id); |
---|
| 163 | if (!socket->plug_window) /* was deleted before we could get it */ |
---|
| 164 | { |
---|
| 165 | gdk_error_trap_pop (); |
---|
| 166 | return; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | socket->same_app = FALSE; |
---|
| 170 | socket->have_size = FALSE; |
---|
| 171 | |
---|
| 172 | XSelectInput (GDK_DISPLAY (), |
---|
| 173 | GDK_WINDOW_XWINDOW(socket->plug_window), |
---|
| 174 | StructureNotifyMask | PropertyChangeMask); |
---|
| 175 | |
---|
| 176 | gtk_widget_queue_resize (widget); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | gdk_window_hide (socket->plug_window); |
---|
| 180 | gdk_window_reparent (socket->plug_window, widget->window, 0, 0); |
---|
| 181 | |
---|
| 182 | gdk_flush (); |
---|
| 183 | gdk_error_trap_pop (); |
---|
| 184 | |
---|
| 185 | socket->need_map = TRUE; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | static void |
---|
| 189 | gtk_socket_realize (GtkWidget *widget) |
---|
| 190 | { |
---|
| 191 | GtkSocket *socket; |
---|
| 192 | GdkWindowAttr attributes; |
---|
| 193 | gint attributes_mask; |
---|
| 194 | XWindowAttributes xattrs; |
---|
| 195 | |
---|
| 196 | g_return_if_fail (widget != NULL); |
---|
| 197 | g_return_if_fail (GTK_IS_SOCKET (widget)); |
---|
| 198 | |
---|
| 199 | socket = GTK_SOCKET (widget); |
---|
| 200 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
---|
| 201 | |
---|
| 202 | attributes.window_type = GDK_WINDOW_CHILD; |
---|
| 203 | attributes.x = widget->allocation.x; |
---|
| 204 | attributes.y = widget->allocation.y; |
---|
| 205 | attributes.width = widget->allocation.width; |
---|
| 206 | attributes.height = widget->allocation.height; |
---|
| 207 | attributes.wclass = GDK_INPUT_OUTPUT; |
---|
| 208 | attributes.visual = gtk_widget_get_visual (widget); |
---|
| 209 | attributes.colormap = gtk_widget_get_colormap (widget); |
---|
| 210 | attributes.event_mask = GDK_FOCUS_CHANGE_MASK; |
---|
| 211 | |
---|
| 212 | attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; |
---|
| 213 | |
---|
| 214 | widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), |
---|
| 215 | &attributes, attributes_mask); |
---|
| 216 | gdk_window_set_user_data (widget->window, socket); |
---|
| 217 | |
---|
| 218 | widget->style = gtk_style_attach (widget->style, widget->window); |
---|
| 219 | gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); |
---|
| 220 | |
---|
| 221 | XGetWindowAttributes (GDK_DISPLAY (), |
---|
| 222 | GDK_WINDOW_XWINDOW (widget->window), |
---|
| 223 | &xattrs); |
---|
| 224 | |
---|
| 225 | XSelectInput (GDK_DISPLAY (), |
---|
| 226 | GDK_WINDOW_XWINDOW(widget->window), |
---|
| 227 | xattrs.your_event_mask | |
---|
| 228 | SubstructureNotifyMask | SubstructureRedirectMask); |
---|
| 229 | |
---|
| 230 | gdk_window_add_filter (widget->window, gtk_socket_filter_func, widget); |
---|
| 231 | |
---|
| 232 | GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); |
---|
| 233 | |
---|
| 234 | /* We sync here so that we make sure that if the XID for |
---|
| 235 | * our window is passed to another application, SubstructureRedirectMask |
---|
| 236 | * will be set by the time the other app creates its window. |
---|
| 237 | */ |
---|
| 238 | gdk_flush(); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | static void |
---|
| 242 | gtk_socket_unrealize (GtkWidget *widget) |
---|
| 243 | { |
---|
| 244 | GtkSocket *socket; |
---|
| 245 | |
---|
| 246 | g_return_if_fail (widget != NULL); |
---|
| 247 | g_return_if_fail (GTK_IS_SOCKET (widget)); |
---|
| 248 | |
---|
| 249 | socket = GTK_SOCKET (widget); |
---|
| 250 | |
---|
| 251 | if (socket->plug_window) |
---|
| 252 | { |
---|
| 253 | GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket)); |
---|
| 254 | if (toplevel && GTK_IS_WINDOW (toplevel)) |
---|
| 255 | gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel), |
---|
| 256 | GDK_WINDOW_XWINDOW (socket->plug_window)); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
---|
| 260 | (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | static void |
---|
| 264 | gtk_socket_size_request (GtkWidget *widget, |
---|
| 265 | GtkRequisition *requisition) |
---|
| 266 | { |
---|
| 267 | GtkSocket *socket; |
---|
| 268 | |
---|
| 269 | g_return_if_fail (widget != NULL); |
---|
| 270 | g_return_if_fail (GTK_IS_SOCKET (widget)); |
---|
| 271 | g_return_if_fail (requisition != NULL); |
---|
| 272 | |
---|
| 273 | socket = GTK_SOCKET (widget); |
---|
| 274 | |
---|
| 275 | if (!socket->have_size && socket->plug_window) |
---|
| 276 | { |
---|
| 277 | XSizeHints hints; |
---|
| 278 | long supplied; |
---|
| 279 | |
---|
| 280 | gdk_error_trap_push (); |
---|
| 281 | |
---|
| 282 | if (XGetWMNormalHints (GDK_DISPLAY(), |
---|
| 283 | GDK_WINDOW_XWINDOW (socket->plug_window), |
---|
| 284 | &hints, &supplied)) |
---|
| 285 | { |
---|
| 286 | /* This is obsolete, according the X docs, but many programs |
---|
| 287 | * still use it */ |
---|
| 288 | if (hints.flags & (PSize | USSize)) |
---|
| 289 | { |
---|
| 290 | socket->request_width = hints.width; |
---|
| 291 | socket->request_height = hints.height; |
---|
| 292 | } |
---|
| 293 | else if (hints.flags & PMinSize) |
---|
| 294 | { |
---|
| 295 | socket->request_width = hints.min_width; |
---|
| 296 | socket->request_height = hints.min_height; |
---|
| 297 | } |
---|
| 298 | else if (hints.flags & PBaseSize) |
---|
| 299 | { |
---|
| 300 | socket->request_width = hints.base_width; |
---|
| 301 | socket->request_height = hints.base_height; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | socket->have_size = TRUE; /* don't check again? */ |
---|
| 305 | |
---|
| 306 | gdk_error_trap_pop (); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | requisition->width = MAX (socket->request_width, 1); |
---|
| 310 | requisition->height = MAX (socket->request_height, 1); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | static void |
---|
| 314 | gtk_socket_size_allocate (GtkWidget *widget, |
---|
| 315 | GtkAllocation *allocation) |
---|
| 316 | { |
---|
| 317 | GtkSocket *socket; |
---|
| 318 | |
---|
| 319 | g_return_if_fail (widget != NULL); |
---|
| 320 | g_return_if_fail (GTK_IS_SOCKET (widget)); |
---|
| 321 | g_return_if_fail (allocation != NULL); |
---|
| 322 | |
---|
| 323 | socket = GTK_SOCKET (widget); |
---|
| 324 | |
---|
| 325 | widget->allocation = *allocation; |
---|
| 326 | if (GTK_WIDGET_REALIZED (widget)) |
---|
| 327 | { |
---|
| 328 | gdk_window_move_resize (widget->window, |
---|
| 329 | allocation->x, allocation->y, |
---|
| 330 | allocation->width, allocation->height); |
---|
| 331 | |
---|
| 332 | if (socket->plug_window) |
---|
| 333 | { |
---|
| 334 | gdk_error_trap_push (); |
---|
| 335 | |
---|
| 336 | if (!socket->need_map && |
---|
| 337 | (allocation->width == socket->current_width) && |
---|
| 338 | (allocation->height == socket->current_height)) |
---|
| 339 | { |
---|
| 340 | gtk_socket_send_configure_event (socket); |
---|
| 341 | GTK_NOTE(PLUGSOCKET, |
---|
| 342 | g_message ("GtkSocket - allocated no change: %d %d", |
---|
| 343 | allocation->width, allocation->height)); |
---|
| 344 | } |
---|
| 345 | else |
---|
| 346 | { |
---|
| 347 | gdk_window_move_resize (socket->plug_window, |
---|
| 348 | 0, 0, |
---|
| 349 | allocation->width, allocation->height); |
---|
| 350 | GTK_NOTE(PLUGSOCKET, |
---|
| 351 | g_message ("GtkSocket - allocated: %d %d", |
---|
| 352 | allocation->width, allocation->height)); |
---|
| 353 | socket->current_width = allocation->width; |
---|
| 354 | socket->current_height = allocation->height; |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | if (socket->need_map) |
---|
| 358 | { |
---|
| 359 | gdk_window_show (socket->plug_window); |
---|
| 360 | socket->need_map = FALSE; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | gdk_flush (); |
---|
| 364 | gdk_error_trap_pop (); |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | static gint |
---|
| 370 | gtk_socket_focus_in_event (GtkWidget *widget, GdkEventFocus *event) |
---|
| 371 | { |
---|
| 372 | GtkSocket *socket; |
---|
| 373 | g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE); |
---|
| 374 | socket = GTK_SOCKET (widget); |
---|
| 375 | |
---|
| 376 | if (socket->focus_in && socket->plug_window) |
---|
| 377 | { |
---|
| 378 | gdk_error_trap_push (); |
---|
| 379 | XSetInputFocus (GDK_DISPLAY (), |
---|
| 380 | GDK_WINDOW_XWINDOW (socket->plug_window), |
---|
| 381 | RevertToParent, GDK_CURRENT_TIME); |
---|
| 382 | gdk_flush(); |
---|
| 383 | gdk_error_trap_pop (); |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | return TRUE; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | static gint |
---|
| 390 | gtk_socket_focus_out_event (GtkWidget *widget, GdkEventFocus *event) |
---|
| 391 | { |
---|
| 392 | GtkWidget *toplevel; |
---|
| 393 | GtkSocket *socket; |
---|
| 394 | |
---|
| 395 | g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE); |
---|
| 396 | socket = GTK_SOCKET (widget); |
---|
| 397 | |
---|
| 398 | toplevel = gtk_widget_get_ancestor (widget, gtk_window_get_type()); |
---|
| 399 | |
---|
| 400 | if (toplevel) |
---|
| 401 | { |
---|
| 402 | XSetInputFocus (GDK_DISPLAY (), |
---|
| 403 | GDK_WINDOW_XWINDOW (toplevel->window), |
---|
| 404 | RevertToParent, CurrentTime); /* FIXME? */ |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | socket->focus_in = FALSE; |
---|
| 408 | |
---|
| 409 | return TRUE; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | static void |
---|
| 413 | gtk_socket_claim_focus (GtkSocket *socket) |
---|
| 414 | { |
---|
| 415 | |
---|
| 416 | socket->focus_in = TRUE; |
---|
| 417 | |
---|
| 418 | /* Oh, the trickery... */ |
---|
| 419 | |
---|
| 420 | GTK_WIDGET_SET_FLAGS (socket, GTK_CAN_FOCUS); |
---|
| 421 | gtk_widget_grab_focus (GTK_WIDGET (socket)); |
---|
| 422 | GTK_WIDGET_UNSET_FLAGS (socket, GTK_CAN_FOCUS); |
---|
| 423 | |
---|
| 424 | /* FIXME: we might grab the focus even if we don't have |
---|
| 425 | * it as an app... (and see _focus_in ()) */ |
---|
| 426 | if (socket->plug_window) |
---|
| 427 | { |
---|
| 428 | gdk_error_trap_push (); |
---|
| 429 | XSetInputFocus (GDK_DISPLAY (), |
---|
| 430 | GDK_WINDOW_XWINDOW (socket->plug_window), |
---|
| 431 | RevertToParent, GDK_CURRENT_TIME); |
---|
| 432 | gdk_flush (); |
---|
| 433 | gdk_error_trap_pop (); |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | static gint |
---|
| 438 | gtk_socket_focus (GtkContainer *container, GtkDirectionType direction) |
---|
| 439 | { |
---|
| 440 | GtkSocket *socket; |
---|
| 441 | |
---|
| 442 | g_return_val_if_fail (GTK_IS_SOCKET (container), FALSE); |
---|
| 443 | |
---|
| 444 | socket = GTK_SOCKET (container); |
---|
| 445 | |
---|
| 446 | if (!socket->focus_in && socket->plug_window) |
---|
| 447 | { |
---|
| 448 | XEvent xevent; |
---|
| 449 | |
---|
| 450 | gtk_socket_claim_focus (socket); |
---|
| 451 | |
---|
| 452 | xevent.xkey.type = KeyPress; |
---|
| 453 | xevent.xkey.display = GDK_DISPLAY (); |
---|
| 454 | xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window); |
---|
| 455 | xevent.xkey.root = GDK_ROOT_WINDOW (); /* FIXME */ |
---|
| 456 | xevent.xkey.time = GDK_CURRENT_TIME; /* FIXME */ |
---|
| 457 | /* FIXME, the following might cause big problems for |
---|
| 458 | * non-GTK apps */ |
---|
| 459 | xevent.xkey.x = 0; |
---|
| 460 | xevent.xkey.y = 0; |
---|
| 461 | xevent.xkey.x_root = 0; |
---|
| 462 | xevent.xkey.y_root = 0; |
---|
| 463 | xevent.xkey.state = 0; |
---|
| 464 | xevent.xkey.same_screen = TRUE; /* FIXME ? */ |
---|
| 465 | |
---|
| 466 | switch (direction) |
---|
| 467 | { |
---|
| 468 | case GTK_DIR_UP: |
---|
| 469 | xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Up); |
---|
| 470 | break; |
---|
| 471 | case GTK_DIR_DOWN: |
---|
| 472 | xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Down); |
---|
| 473 | break; |
---|
| 474 | case GTK_DIR_LEFT: |
---|
| 475 | xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Left); |
---|
| 476 | break; |
---|
| 477 | case GTK_DIR_RIGHT: |
---|
| 478 | xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Right); |
---|
| 479 | break; |
---|
| 480 | case GTK_DIR_TAB_FORWARD: |
---|
| 481 | xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab); |
---|
| 482 | break; |
---|
| 483 | case GTK_DIR_TAB_BACKWARD: |
---|
| 484 | xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab); |
---|
| 485 | xevent.xkey.state = ShiftMask; |
---|
| 486 | break; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | |
---|
| 490 | gdk_error_trap_push (); |
---|
| 491 | XSendEvent (gdk_display, |
---|
| 492 | GDK_WINDOW_XWINDOW (socket->plug_window), |
---|
| 493 | False, NoEventMask, &xevent); |
---|
| 494 | gdk_flush(); |
---|
| 495 | gdk_error_trap_pop (); |
---|
| 496 | |
---|
| 497 | return TRUE; |
---|
| 498 | } |
---|
| 499 | else |
---|
| 500 | { |
---|
| 501 | return FALSE; |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | static void |
---|
| 506 | gtk_socket_send_configure_event (GtkSocket *socket) |
---|
| 507 | { |
---|
| 508 | XEvent event; |
---|
| 509 | |
---|
| 510 | g_return_if_fail (socket->plug_window != NULL); |
---|
| 511 | |
---|
| 512 | event.xconfigure.type = ConfigureNotify; |
---|
| 513 | event.xconfigure.display = gdk_display; |
---|
| 514 | |
---|
| 515 | event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window); |
---|
| 516 | event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window); |
---|
| 517 | |
---|
| 518 | event.xconfigure.x = 0; |
---|
| 519 | event.xconfigure.y = 0; |
---|
| 520 | event.xconfigure.width = GTK_WIDGET(socket)->allocation.width; |
---|
| 521 | event.xconfigure.height = GTK_WIDGET(socket)->allocation.height; |
---|
| 522 | |
---|
| 523 | event.xconfigure.border_width = 0; |
---|
| 524 | event.xconfigure.above = None; |
---|
| 525 | event.xconfigure.override_redirect = False; |
---|
| 526 | |
---|
| 527 | gdk_error_trap_push (); |
---|
| 528 | XSendEvent (gdk_display, |
---|
| 529 | GDK_WINDOW_XWINDOW (socket->plug_window), |
---|
| 530 | False, NoEventMask, &event); |
---|
| 531 | gdk_flush (); |
---|
| 532 | gdk_error_trap_pop (); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | static void |
---|
| 536 | gtk_socket_add_window (GtkSocket *socket, guint32 xid) |
---|
| 537 | { |
---|
| 538 | socket->plug_window = gdk_window_lookup (xid); |
---|
| 539 | socket->same_app = TRUE; |
---|
| 540 | |
---|
| 541 | if (!socket->plug_window) |
---|
| 542 | { |
---|
| 543 | GtkWidget *toplevel; |
---|
| 544 | GdkDragProtocol protocol; |
---|
| 545 | |
---|
| 546 | socket->plug_window = gdk_window_foreign_new (xid); |
---|
| 547 | if (!socket->plug_window) /* Already gone */ |
---|
| 548 | return; |
---|
| 549 | |
---|
| 550 | socket->same_app = FALSE; |
---|
| 551 | |
---|
| 552 | gdk_error_trap_push (); |
---|
| 553 | XSelectInput (GDK_DISPLAY (), |
---|
| 554 | GDK_WINDOW_XWINDOW(socket->plug_window), |
---|
| 555 | StructureNotifyMask | PropertyChangeMask); |
---|
| 556 | |
---|
| 557 | if (gdk_drag_get_protocol (xid, &protocol)) |
---|
| 558 | gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window, |
---|
| 559 | protocol, TRUE); |
---|
| 560 | gdk_flush (); |
---|
| 561 | gdk_error_trap_pop (); |
---|
| 562 | |
---|
| 563 | gdk_window_add_filter (socket->plug_window, |
---|
| 564 | gtk_socket_filter_func, socket); |
---|
| 565 | |
---|
| 566 | /* Add a pointer to the socket on our toplevel window */ |
---|
| 567 | |
---|
| 568 | toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket)); |
---|
| 569 | if (toplevel && GTK_IS_WINDOW (toplevel)) |
---|
| 570 | { |
---|
| 571 | gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid); |
---|
| 572 | } |
---|
| 573 | } |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | static GdkFilterReturn |
---|
| 577 | gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) |
---|
| 578 | { |
---|
| 579 | GtkSocket *socket; |
---|
| 580 | GtkWidget *widget; |
---|
| 581 | XEvent *xevent; |
---|
| 582 | |
---|
| 583 | GdkFilterReturn return_val; |
---|
| 584 | |
---|
| 585 | socket = GTK_SOCKET (data); |
---|
| 586 | widget = GTK_WIDGET (socket); |
---|
| 587 | xevent = (XEvent *)gdk_xevent; |
---|
| 588 | |
---|
| 589 | return_val = GDK_FILTER_CONTINUE; |
---|
| 590 | |
---|
| 591 | switch (xevent->type) |
---|
| 592 | { |
---|
| 593 | case CreateNotify: |
---|
| 594 | { |
---|
| 595 | XCreateWindowEvent *xcwe = &xevent->xcreatewindow; |
---|
| 596 | |
---|
| 597 | if (!socket->plug_window) |
---|
| 598 | { |
---|
| 599 | gtk_socket_add_window (socket, xcwe->window); |
---|
[15780] | 600 | if (!socket->plug_window) |
---|
| 601 | break; |
---|
[14481] | 602 | |
---|
| 603 | gdk_error_trap_push (); |
---|
| 604 | gdk_window_move_resize(socket->plug_window, |
---|
| 605 | 0, 0, |
---|
| 606 | widget->allocation.width, |
---|
| 607 | widget->allocation.height); |
---|
| 608 | gdk_flush (); |
---|
| 609 | gdk_error_trap_pop (); |
---|
| 610 | |
---|
| 611 | socket->request_width = xcwe->width; |
---|
| 612 | socket->request_height = xcwe->height; |
---|
| 613 | socket->have_size = TRUE; |
---|
| 614 | |
---|
| 615 | GTK_NOTE(PLUGSOCKET, |
---|
| 616 | g_message ("GtkSocket - window created with size: %d %d", |
---|
| 617 | socket->request_width, |
---|
| 618 | socket->request_height)); |
---|
| 619 | |
---|
| 620 | gtk_widget_queue_resize (widget); |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | return_val = GDK_FILTER_REMOVE; |
---|
| 624 | |
---|
| 625 | break; |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | case ConfigureRequest: |
---|
| 629 | { |
---|
| 630 | XConfigureRequestEvent *xcre = &xevent->xconfigurerequest; |
---|
| 631 | |
---|
| 632 | if (!socket->plug_window) |
---|
| 633 | gtk_socket_add_window (socket, xcre->window); |
---|
[15780] | 634 | |
---|
| 635 | if (!socket->plug_window) |
---|
| 636 | break; |
---|
[14481] | 637 | |
---|
| 638 | if (xcre->window == GDK_WINDOW_XWINDOW (socket->plug_window)) |
---|
| 639 | { |
---|
| 640 | if (xcre->value_mask & (CWWidth | CWHeight)) |
---|
| 641 | { |
---|
| 642 | socket->request_width = xcre->width; |
---|
| 643 | socket->request_height = xcre->height; |
---|
| 644 | socket->have_size = TRUE; |
---|
| 645 | |
---|
| 646 | GTK_NOTE(PLUGSOCKET, |
---|
| 647 | g_message ("GtkSocket - configure request: %d %d", |
---|
| 648 | socket->request_width, |
---|
| 649 | socket->request_height)); |
---|
| 650 | |
---|
| 651 | gtk_widget_queue_resize (widget); |
---|
| 652 | } |
---|
| 653 | else if (xcre->value_mask & (CWX | CWY)) |
---|
| 654 | { |
---|
| 655 | gtk_socket_send_configure_event (socket); |
---|
| 656 | } |
---|
| 657 | /* Ignore stacking requests. */ |
---|
| 658 | |
---|
| 659 | return_val = GDK_FILTER_REMOVE; |
---|
| 660 | } |
---|
| 661 | break; |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | case DestroyNotify: |
---|
| 665 | { |
---|
| 666 | XDestroyWindowEvent *xdwe = &xevent->xdestroywindow; |
---|
| 667 | |
---|
| 668 | if (socket->plug_window && |
---|
| 669 | (xdwe->window == GDK_WINDOW_XWINDOW (socket->plug_window))) |
---|
| 670 | { |
---|
| 671 | GtkWidget *toplevel; |
---|
| 672 | |
---|
| 673 | GTK_NOTE(PLUGSOCKET, |
---|
| 674 | g_message ("GtkSocket - destroy notify")); |
---|
| 675 | |
---|
| 676 | toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket)); |
---|
| 677 | if (toplevel && GTK_IS_WINDOW (toplevel)) |
---|
| 678 | gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel), xdwe->window); |
---|
| 679 | gdk_window_destroy_notify (socket->plug_window); |
---|
| 680 | gtk_widget_destroy (widget); |
---|
| 681 | |
---|
| 682 | socket->plug_window = NULL; |
---|
| 683 | |
---|
| 684 | return_val = GDK_FILTER_REMOVE; |
---|
| 685 | } |
---|
| 686 | break; |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | case FocusIn: |
---|
| 690 | if (xevent->xfocus.mode == EMBEDDED_APP_WANTS_FOCUS) |
---|
| 691 | { |
---|
| 692 | gtk_socket_claim_focus (socket); |
---|
| 693 | } |
---|
| 694 | else if (xevent->xfocus.detail == NotifyInferior) |
---|
| 695 | { |
---|
| 696 | #if 0 |
---|
| 697 | GtkWidget *toplevel; |
---|
| 698 | toplevel = gtk_widget_get_ancestor (widget, gtk_window_get_type()); |
---|
| 699 | |
---|
| 700 | if (toplevel) |
---|
| 701 | { |
---|
| 702 | XSetInputFocus (GDK_DISPLAY (), |
---|
| 703 | GDK_WINDOW_XWINDOW (toplevel->window), |
---|
| 704 | RevertToParent, CurrentTime); /* FIXME? */ |
---|
| 705 | } |
---|
| 706 | #endif |
---|
| 707 | } |
---|
| 708 | return_val = GDK_FILTER_REMOVE; |
---|
| 709 | break; |
---|
| 710 | case FocusOut: |
---|
| 711 | return_val = GDK_FILTER_REMOVE; |
---|
| 712 | break; |
---|
| 713 | case MapRequest: |
---|
| 714 | if (!socket->plug_window) |
---|
| 715 | gtk_socket_add_window (socket, xevent->xmaprequest.window); |
---|
| 716 | |
---|
[15780] | 717 | if (!socket->plug_window) |
---|
| 718 | break; |
---|
| 719 | |
---|
[14481] | 720 | if (xevent->xmaprequest.window == |
---|
| 721 | GDK_WINDOW_XWINDOW (socket->plug_window)) |
---|
| 722 | { |
---|
| 723 | GTK_NOTE(PLUGSOCKET, |
---|
| 724 | g_message ("GtkSocket - Map Request")); |
---|
| 725 | |
---|
| 726 | gdk_error_trap_push (); |
---|
| 727 | gdk_window_show (socket->plug_window); |
---|
| 728 | gdk_flush (); |
---|
| 729 | gdk_error_trap_pop (); |
---|
| 730 | |
---|
| 731 | return_val = GDK_FILTER_REMOVE; |
---|
| 732 | } |
---|
| 733 | break; |
---|
| 734 | case PropertyNotify: |
---|
[15780] | 735 | if (!socket->plug_window) |
---|
| 736 | break; |
---|
| 737 | |
---|
[14481] | 738 | if (xevent->xproperty.window == |
---|
| 739 | GDK_WINDOW_XWINDOW (socket->plug_window)) |
---|
| 740 | { |
---|
| 741 | GdkDragProtocol protocol; |
---|
| 742 | |
---|
| 743 | if ((xevent->xproperty.atom == gdk_atom_intern ("XdndAware", FALSE)) || |
---|
| 744 | (xevent->xproperty.atom == gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE))) |
---|
| 745 | { |
---|
| 746 | gdk_error_trap_push (); |
---|
| 747 | if (gdk_drag_get_protocol (xevent->xproperty.window, &protocol)) |
---|
| 748 | gtk_drag_dest_set_proxy (GTK_WIDGET (socket), |
---|
| 749 | socket->plug_window, |
---|
| 750 | protocol, TRUE); |
---|
| 751 | gdk_flush (); |
---|
| 752 | gdk_error_trap_pop (); |
---|
| 753 | } |
---|
| 754 | return_val = GDK_FILTER_REMOVE; |
---|
| 755 | } |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | return return_val; |
---|
| 759 | } |
---|