]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkplug.c
Drop the Motif DND protocol
[~andy/gtk] / gtk / gtkplug.c
index 8cb9a4e1839620012a944f83c991d27a2d7e0392..01fc9799e5225122b89be82f71bcc7932ae11edb 100644 (file)
@@ -12,8 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.Free
  */
 
 /* By Owen Taylor <otaylor@gtk.org>              98/4/4 */
  * SECTION:gtkplug
  * @Short_description: Toplevel for embedding into other processes
  * @Title: GtkPlug
+ * @include: gtk/gtkx.h
  * @See_also: #GtkSocket
  *
- * Together with #GtkSocket, #GtkPlug provides the ability
- * to embed widgets from one process into another process
- * in a fashion that is transparent to the user. One
- * process creates a #GtkSocket widget and passes the
- * ID of that widget's window to the other process,
- * which then creates a #GtkPlug with that window ID.
- * Any widgets contained in the #GtkPlug then will appear
- * inside the first application's window.
+ * Together with #GtkSocket, #GtkPlug provides the ability to embed
+ * widgets from one process into another process in a fashion that is
+ * transparent to the user. One process creates a #GtkSocket widget
+ * and passes the ID of that widget's window to the other process,
+ * which then creates a #GtkPlug with that window ID. Any widgets
+ * contained in the #GtkPlug then will appear inside the first
+ * application's window.
  *
  * The communication between a #GtkSocket and a #GtkPlug follows the
  * <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
- * protocol. This protocol has also been implemented in other toolkits, e.g.
- * <application>Qt</application>, allowing the same level of integration
- * when embedding a <application>Qt</application> widget in GTK or vice versa.
+ * protocol. This protocol has also been implemented in other toolkits,
+ * e.g. <application>Qt</application>, allowing the same level of
+ * integration when embedding a <application>Qt</application> widget
+ * in GTK+ or vice versa.
  *
  * <note>
- * The #GtkPlug and #GtkSocket widgets are only available when GTK is
- * compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
- * They can only be used on a #GdkX11Display.
+ * The #GtkPlug and #GtkSocket widgets are only available when GTK+
+ * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
+ * They can only be used on a #GdkX11Display. To use #GtkPlug and
+ * #GtkSocket, you need to include the <filename>gtk/gtkx.h</filename>
+ * header.
  * </note>
  */
 
@@ -180,6 +182,8 @@ gtk_plug_class_init (GtkPlugClass *class)
 
   widget_class->focus = gtk_plug_focus;
 
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_PANEL);
+
   container_class->check_resize = gtk_plug_check_resize;
 
   window_class->set_focus = gtk_plug_set_focus;
@@ -243,7 +247,6 @@ gtk_plug_init (GtkPlug *plug)
 
 /**
  * gtk_plug_handle_modality_on:
- *
  * @plug: a #GtkPlug
  *
  * Called from the GtkPlug backend when the corresponding socket has
@@ -267,7 +270,6 @@ gtk_plug_handle_modality_on (GtkPlug *plug)
 
 /**
  * gtk_plug_handle_modality_off:
- *
  * @plug: a #GtkPlug
  *
  * Called from the GtkPlug backend when the corresponding socket has
@@ -439,16 +441,16 @@ _gtk_plug_add_to_socket (GtkPlug   *plug,
   g_signal_emit_by_name (socket_, "plug-added");
 }
 
-/**
- * _gtk_plug_send_delete_event:
+/*
+ * gtk_plug_send_delete_event:
  * @widget: a #GtkWidget
  *
  * Send a GDK_DELETE event to the @widget and destroy it if
  * necessary. Internal GTK function, called from this file or the
  * backend-specific GtkPlug implementation.
  */
-void
-_gtk_plug_send_delete_event (GtkWidget *widget)
+static void
+gtk_plug_send_delete_event (GtkWidget *widget)
 {
   GdkEvent *event = gdk_event_new (GDK_DELETE);
 
@@ -528,7 +530,7 @@ _gtk_plug_remove_from_socket (GtkPlug   *plug,
     gtk_widget_destroy (GTK_WIDGET (socket_));
 
   if (window)
-    _gtk_plug_send_delete_event (widget);
+    gtk_plug_send_delete_event (widget);
 
   g_object_unref (plug);
 
@@ -662,11 +664,8 @@ gtk_plug_finalize (GObject *object)
   GtkPlugPrivate *priv = plug->priv;
 
   if (priv->grabbed_keys)
-    {
-      g_hash_table_destroy (priv->grabbed_keys);
-      priv->grabbed_keys = NULL;
-    }
-  
+    g_hash_table_destroy (priv->grabbed_keys);
+
   G_OBJECT_CLASS (gtk_plug_parent_class)->finalize (object);
 }
 
@@ -678,7 +677,7 @@ gtk_plug_unrealize (GtkWidget *widget)
 
   if (priv->socket_window != NULL)
     {
-      gdk_window_set_user_data (priv->socket_window, NULL);
+      gtk_widget_unregister_window (widget, priv->socket_window);
       g_object_unref (priv->socket_window);
       priv->socket_window = NULL;
 
@@ -718,7 +717,6 @@ xembed_set_info (GdkWindow     *window,
 
 /**
  * gtk_plug_focus_first_last:
- *
  * @plug: a #GtkPlug
  * @direction: a direction
  *
@@ -881,7 +879,7 @@ gtk_plug_filter_func (GdkXEvent *gdk_xevent,
              {
                GtkWidget *widget = GTK_WIDGET (plug);
 
-                gdk_window_set_user_data (priv->socket_window, NULL);
+                gtk_widget_unregister_window (widget, priv->socket_window);
                g_object_unref (priv->socket_window);
                priv->socket_window = NULL;
 
@@ -897,7 +895,7 @@ gtk_plug_filter_func (GdkXEvent *gdk_xevent,
                if (xre->parent == GDK_WINDOW_XID (gdk_screen_get_root_window (screen)))
                  {
                    GTK_NOTE (PLUGSOCKET, g_message ("GtkPlug: calling gtk_plug_send_delete_event()"));
-                   _gtk_plug_send_delete_event (widget);
+                   gtk_plug_send_delete_event (widget);
 
                    g_object_notify (G_OBJECT (plug), "embedded");
                  }
@@ -934,15 +932,17 @@ gtk_plug_filter_func (GdkXEvent *gdk_xevent,
                  break; /* FIXME: shouldn't this unref the plug? i.e. "goto done;" instead */
              }
 
-            g_hash_table_iter_init (&iter, priv->grabbed_keys);
-
-            while (g_hash_table_iter_next (&iter, &key, NULL))
+            if (priv->grabbed_keys)
               {
-                GrabbedKey *grabbed_key = key;
-
-                _gtk_xembed_send_message (priv->socket_window, XEMBED_GTK_GRAB_KEY, 0,
-                                          grabbed_key->accelerator_key,
-                                          grabbed_key->accelerator_mods);
+                g_hash_table_iter_init (&iter, priv->grabbed_keys);
+                while (g_hash_table_iter_next (&iter, &key, NULL))
+                  {
+                    GrabbedKey *grabbed_key = key;
+
+                    _gtk_xembed_send_message (priv->socket_window, XEMBED_GTK_GRAB_KEY, 0,
+                                              grabbed_key->accelerator_key,
+                                              grabbed_key->accelerator_mods);
+                  }
               }
 
            if (!was_embedded)
@@ -982,6 +982,10 @@ gtk_plug_filter_func (GdkXEvent *gdk_xevent,
         gdk_event_set_device (event, keyboard);
 
         keymap = gdk_keymap_get_for_display (display);
+
+        event->key.group = gdk_x11_keymap_get_group_for_state (keymap, xevent->xkey.state);
+        event->key.is_modifier = gdk_x11_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
+
         gdk_keymap_translate_keyboard_state (keymap,
                                              event->key.hardware_keycode,
                                              event->key.state,
@@ -996,10 +1000,6 @@ gtk_plug_filter_func (GdkXEvent *gdk_xevent,
         event->key.length = 0;
         event->key.string = g_strdup ("");
 
-        /* FIXME: These should be filled in properly */
-        event->key.group = 0;
-        event->key.is_modifier = FALSE;
-
         return_val = GDK_FILTER_TRANSLATE;
       }
     }
@@ -1088,12 +1088,10 @@ gtk_plug_realize (GtkWidget *widget)
       gtk_widget_set_window (widget, gdk_window);
     }
 
-  gdk_window_set_user_data (gdk_window, window);
+  gtk_widget_register_window (widget, gdk_window);
 
   gtk_style_context_set_background (gtk_widget_get_style_context (widget),
                                     gdk_window);
-
-  gdk_window_enable_synchronized_configure (gdk_window);
 }
 
 static void
@@ -1127,14 +1125,14 @@ gtk_plug_map (GtkWidget *widget)
       GtkBin *bin = GTK_BIN (widget);
       GtkPlug *plug = GTK_PLUG (widget);
       GtkWidget *child;
-      
+
       gtk_widget_set_mapped (widget, TRUE);
 
       child = gtk_bin_get_child (bin);
       if (child != NULL &&
           gtk_widget_get_visible (child) &&
-         !gtk_widget_get_mapped (child))
-       gtk_widget_map (child);
+          !gtk_widget_get_mapped (child))
+        gtk_widget_map (child);
 
       xembed_set_info (gtk_widget_get_window (GTK_WIDGET (plug)), XEMBED_MAPPED);
 
@@ -1153,6 +1151,7 @@ gtk_plug_unmap (GtkWidget *widget)
     {
       GtkPlug *plug = GTK_PLUG (widget);
       GdkWindow *window;
+      GtkWidget *child;
 
       window = gtk_widget_get_window (widget);
 
@@ -1160,6 +1159,10 @@ gtk_plug_unmap (GtkWidget *widget)
 
       gdk_window_hide (window);
 
+      child = gtk_bin_get_child (GTK_BIN (widget));
+      if (child != NULL)
+        gtk_widget_unmap (child);
+
       xembed_set_info (gtk_widget_get_window (GTK_WIDGET (plug)), 0);
 
       gdk_synthesize_window_state (window,
@@ -1341,7 +1344,7 @@ gtk_plug_keys_changed (GtkWindow *window)
   if (old_grabbed_keys)
     {
       if (priv->socket_window)
-       g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
+        g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
       g_hash_table_destroy (old_grabbed_keys);
     }
 }