Commit 5ee3a444 authored by Matthias Clasen's avatar Matthias Clasen
Browse files

Remove sealed members from GtkSocket

parent 53845f08
......@@ -33,6 +33,7 @@
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkplugprivate.h"
#include "gtksocketprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkwindowprivate.h"
......@@ -346,8 +347,8 @@ _gtk_plug_add_to_socket (GtkPlug *plug,
gtk_plug_set_is_child (plug, TRUE);
priv->same_app = TRUE;
socket_->same_app = TRUE;
socket_->plug_widget = widget;
socket_->priv->same_app = TRUE;
socket_->priv->plug_widget = widget;
priv->socket_window = gtk_widget_get_window (GTK_WIDGET (socket_));
g_object_ref (priv->socket_window);
......@@ -436,14 +437,14 @@ _gtk_plug_remove_from_socket (GtkPlug *plug,
gtk_widget_unparent (GTK_WIDGET (plug));
_gtk_widget_set_in_reparent (widget, FALSE);
socket_->plug_widget = NULL;
if (socket_->plug_window != NULL)
socket_->priv->plug_widget = NULL;
if (socket_->priv->plug_window != NULL)
{
g_object_unref (socket_->plug_window);
socket_->plug_window = NULL;
g_object_unref (socket_->priv->plug_window);
socket_->priv->plug_window = NULL;
}
socket_->same_app = FALSE;
socket_->priv->same_app = FALSE;
priv->same_app = FALSE;
if (priv->socket_window != NULL)
......
......@@ -91,36 +91,37 @@ void
_gtk_socket_windowing_end_embedding_toplevel (GtkSocket *socket)
{
gtk_window_remove_embedded_xid (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (socket))),
GDK_WINDOW_XID (socket->plug_window));
GDK_WINDOW_XID (socket->priv->plug_window));
}
void
_gtk_socket_windowing_size_request (GtkSocket *socket)
{
GtkSocketPrivate *private = socket->priv;
XSizeHints hints;
long supplied;
gdk_error_trap_push ();
socket->request_width = 1;
socket->request_height = 1;
private->request_width = 1;
private->request_height = 1;
if (XGetWMNormalHints (GDK_WINDOW_XDISPLAY (socket->plug_window),
GDK_WINDOW_XID (socket->plug_window),
if (XGetWMNormalHints (GDK_WINDOW_XDISPLAY (private->plug_window),
GDK_WINDOW_XID (private->plug_window),
&hints, &supplied))
{
if (hints.flags & PMinSize)
{
socket->request_width = MAX (hints.min_width, 1);
socket->request_height = MAX (hints.min_height, 1);
private->request_width = MAX (hints.min_width, 1);
private->request_height = MAX (hints.min_height, 1);
}
else if (hints.flags & PBaseSize)
{
socket->request_width = MAX (hints.base_width, 1);
socket->request_height = MAX (hints.base_height, 1);
private->request_width = MAX (hints.base_width, 1);
private->request_height = MAX (hints.base_height, 1);
}
}
socket->have_size = TRUE;
private->have_size = TRUE;
gdk_error_trap_pop_ignored ();
}
......@@ -131,11 +132,11 @@ _gtk_socket_windowing_send_key_event (GtkSocket *socket,
gboolean mask_key_presses)
{
XKeyEvent xkey;
GdkScreen *screen = gdk_window_get_screen (socket->plug_window);
GdkScreen *screen = gdk_window_get_screen (socket->priv->plug_window);
memset (&xkey, 0, sizeof (xkey));
xkey.type = (gdk_event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
xkey.window = GDK_WINDOW_XID (socket->plug_window);
xkey.window = GDK_WINDOW_XID (socket->priv->plug_window);
xkey.root = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
xkey.subwindow = None;
xkey.time = gdk_event->key.time;
......@@ -148,8 +149,8 @@ _gtk_socket_windowing_send_key_event (GtkSocket *socket,
xkey.same_screen = True;/* FIXME ? */
gdk_error_trap_push ();
XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window),
GDK_WINDOW_XID (socket->plug_window),
XSendEvent (GDK_WINDOW_XDISPLAY (socket->priv->plug_window),
GDK_WINDOW_XID (socket->priv->plug_window),
False,
(mask_key_presses ? KeyPressMask : NoEventMask),
(XEvent *)&xkey);
......@@ -161,10 +162,10 @@ _gtk_socket_windowing_focus_change (GtkSocket *socket,
gboolean focus_in)
{
if (focus_in)
_gtk_xembed_send_focus_message (socket->plug_window,
_gtk_xembed_send_focus_message (socket->priv->plug_window,
XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT);
else
_gtk_xembed_send_message (socket->plug_window,
_gtk_xembed_send_message (socket->priv->plug_window,
XEMBED_FOCUS_OUT, 0, 0, 0);
}
......@@ -172,7 +173,7 @@ void
_gtk_socket_windowing_update_active (GtkSocket *socket,
gboolean active)
{
_gtk_xembed_send_message (socket->plug_window,
_gtk_xembed_send_message (socket->priv->plug_window,
active ? XEMBED_WINDOW_ACTIVATE : XEMBED_WINDOW_DEACTIVATE,
0, 0, 0);
}
......@@ -181,7 +182,7 @@ void
_gtk_socket_windowing_update_modality (GtkSocket *socket,
gboolean modality)
{
_gtk_xembed_send_message (socket->plug_window,
_gtk_xembed_send_message (socket->priv->plug_window,
modality ? XEMBED_MODALITY_ON : XEMBED_MODALITY_OFF,
0, 0, 0);
}
......@@ -206,7 +207,7 @@ _gtk_socket_windowing_focus (GtkSocket *socket,
break;
}
_gtk_xembed_send_focus_message (socket->plug_window, XEMBED_FOCUS_IN, detail);
_gtk_xembed_send_focus_message (socket->priv->plug_window, XEMBED_FOCUS_IN, detail);
}
void
......@@ -216,20 +217,20 @@ _gtk_socket_windowing_send_configure_event (GtkSocket *socket)
XConfigureEvent xconfigure;
gint x, y;
g_return_if_fail (socket->plug_window != NULL);
g_return_if_fail (socket->priv->plug_window != NULL);
memset (&xconfigure, 0, sizeof (xconfigure));
xconfigure.type = ConfigureNotify;
xconfigure.event = GDK_WINDOW_XID (socket->plug_window);
xconfigure.window = GDK_WINDOW_XID (socket->plug_window);
xconfigure.event = GDK_WINDOW_XID (socket->priv->plug_window);
xconfigure.window = GDK_WINDOW_XID (socket->priv->plug_window);
/* The ICCCM says that synthetic events should have root relative
* coordinates. We still aren't really ICCCM compliant, since
* we don't send events when the real toplevel is moved.
*/
gdk_error_trap_push ();
gdk_window_get_origin (socket->plug_window, &x, &y);
gdk_window_get_origin (socket->priv->plug_window, &x, &y);
gdk_error_trap_pop_ignored ();
gtk_widget_get_allocation (GTK_WIDGET(socket), &allocation);
......@@ -243,8 +244,8 @@ _gtk_socket_windowing_send_configure_event (GtkSocket *socket)
xconfigure.override_redirect = False;
gdk_error_trap_push ();
XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window),
GDK_WINDOW_XID (socket->plug_window),
XSendEvent (GDK_WINDOW_XDISPLAY (socket->priv->plug_window),
GDK_WINDOW_XID (socket->priv->plug_window),
False, NoEventMask, (XEvent *)&xconfigure);
gdk_error_trap_pop_ignored ();
}
......@@ -253,7 +254,7 @@ void
_gtk_socket_windowing_select_plug_window_input (GtkSocket *socket)
{
XSelectInput (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (socket))),
GDK_WINDOW_XID (socket->plug_window),
GDK_WINDOW_XID (socket->priv->plug_window),
StructureNotifyMask | PropertyChangeMask);
}
......@@ -262,36 +263,38 @@ _gtk_socket_windowing_embed_get_info (GtkSocket *socket)
{
unsigned long version;
unsigned long flags;
GtkSocketPrivate *private = socket->priv;
socket->xembed_version = -1;
if (xembed_get_info (socket->plug_window, &version, &flags))
private->xembed_version = -1;
if (xembed_get_info (private->plug_window, &version, &flags))
{
socket->xembed_version = MIN (GTK_XEMBED_PROTOCOL_VERSION, version);
socket->is_mapped = (flags & XEMBED_MAPPED) != 0;
private->xembed_version = MIN (GTK_XEMBED_PROTOCOL_VERSION, version);
private->is_mapped = (flags & XEMBED_MAPPED) != 0;
}
else
{
/* FIXME, we should probably actually check the state before we started */
socket->is_mapped = TRUE;
private->is_mapped = TRUE;
}
}
void
_gtk_socket_windowing_embed_notify (GtkSocket *socket)
{
GtkSocketPrivate *private = socket->priv;
#ifdef HAVE_XFIXES
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (socket));
gdk_error_trap_push ();
XFixesChangeSaveSet (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (socket->plug_window),
GDK_WINDOW_XID (private->plug_window),
SetModeInsert, SaveSetRoot, SaveSetUnmap);
gdk_error_trap_pop_ignored ();
#endif
_gtk_xembed_send_message (socket->plug_window,
_gtk_xembed_send_message (private->plug_window,
XEMBED_EMBEDDED_NOTIFY, 0,
GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (socket))),
socket->xembed_version);
private->xembed_version);
}
static gboolean
......@@ -419,14 +422,16 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
GtkWidget *widget;
GdkDisplay *display;
XEvent *xevent;
GtkSocketPrivate *private;
GdkFilterReturn return_val;
socket = GTK_SOCKET (data);
private = socket->priv;
return_val = GDK_FILTER_CONTINUE;
if (socket->plug_widget)
if (private->plug_widget)
return return_val;
widget = GTK_WIDGET (socket);
......@@ -455,11 +460,11 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
{
XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
if (!socket->plug_window)
if (!private->plug_window)
{
_gtk_socket_add_window (socket, xcwe->window, FALSE);
if (socket->plug_window)
if (private->plug_window)
{
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - window created"));
}
......@@ -474,19 +479,17 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
{
XConfigureRequestEvent *xcre = &xevent->xconfigurerequest;
if (!socket->plug_window)
if (!private->plug_window)
_gtk_socket_add_window (socket, xcre->window, FALSE);
if (socket->plug_window)
if (private->plug_window)
{
GtkSocketPrivate *private = _gtk_socket_get_private (socket);
if (xcre->value_mask & (CWWidth | CWHeight))
{
GTK_NOTE (PLUGSOCKET,
g_message ("GtkSocket - configure request: %d %d",
socket->request_width,
socket->request_height));
private->request_width,
private->request_height));
private->resize_count++;
gtk_widget_queue_resize (widget);
......@@ -509,13 +512,13 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
/* Note that we get destroy notifies both from SubstructureNotify on
* our window and StructureNotify on socket->plug_window
*/
if (socket->plug_window && (xdwe->window == GDK_WINDOW_XID (socket->plug_window)))
if (private->plug_window && (xdwe->window == GDK_WINDOW_XID (private->plug_window)))
{
gboolean result;
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - destroy notify"));
gdk_window_destroy_notify (socket->plug_window);
gdk_window_destroy_notify (private->plug_window);
_gtk_socket_end_embedding (socket);
g_object_ref (widget);
......@@ -540,12 +543,12 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
return_val = GDK_FILTER_REMOVE;
break;
case MapRequest:
if (!socket->plug_window)
if (!private->plug_window)
{
_gtk_socket_add_window (socket, xevent->xmaprequest.window, FALSE);
}
if (socket->plug_window)
if (private->plug_window)
{
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - Map Request"));
......@@ -554,15 +557,15 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
}
break;
case PropertyNotify:
if (socket->plug_window &&
xevent->xproperty.window == GDK_WINDOW_XID (socket->plug_window))
if (private->plug_window &&
xevent->xproperty.window == GDK_WINDOW_XID (private->plug_window))
{
GdkDragProtocol protocol;
if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_NORMAL_HINTS"))
{
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - received PropertyNotify for plug's WM_NORMAL_HINTS"));
socket->have_size = FALSE;
private->have_size = FALSE;
gtk_widget_queue_resize (widget);
return_val = GDK_FILTER_REMOVE;
}
......@@ -574,7 +577,7 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
xevent->xproperty.window,
&protocol))
gtk_drag_dest_set_proxy (GTK_WIDGET (socket),
socket->plug_window,
private->plug_window,
protocol, TRUE);
gdk_error_trap_pop_ignored ();
......@@ -584,9 +587,9 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
{
unsigned long flags;
if (xembed_get_info (socket->plug_window, NULL, &flags))
if (xembed_get_info (private->plug_window, NULL, &flags))
{
gboolean was_mapped = socket->is_mapped;
gboolean was_mapped = private->is_mapped;
gboolean is_mapped = (flags & XEMBED_MAPPED) != 0;
if (was_mapped != is_mapped)
......@@ -596,7 +599,7 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
else
{
gdk_error_trap_push ();
gdk_window_show (socket->plug_window);
gdk_window_show (private->plug_window);
gdk_error_trap_pop_ignored ();
_gtk_socket_unmap_notify (socket);
......@@ -615,12 +618,12 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
window = gtk_widget_get_window (widget);
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - ReparentNotify received"));
if (!socket->plug_window &&
if (!private->plug_window &&
xre->parent == GDK_WINDOW_XID (window))
{
_gtk_socket_add_window (socket, xre->window, FALSE);
if (socket->plug_window)
if (private->plug_window)
{
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - window reparented"));
}
......@@ -629,8 +632,8 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
}
else
{
if (socket->plug_window &&
xre->window == GDK_WINDOW_XID (socket->plug_window) &&
if (private->plug_window &&
xre->window == GDK_WINDOW_XID (private->plug_window) &&
xre->parent != GDK_WINDOW_XID (window))
{
gboolean result;
......@@ -650,8 +653,8 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent,
break;
}
case UnmapNotify:
if (socket->plug_window &&
xevent->xunmap.window == GDK_WINDOW_XID (socket->plug_window))
if (private->plug_window &&
xevent->xunmap.window == GDK_WINDOW_XID (private->plug_window))
{
GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - Unmap notify"));
......
......@@ -158,29 +158,15 @@ enum {
static guint socket_signals[LAST_SIGNAL] = { 0 };
/*
* _gtk_socket_get_private:
*
* @socket: a #GtkSocket
*
* Returns the private data associated with a GtkSocket, creating it
* first if necessary.
*/
GtkSocketPrivate *
_gtk_socket_get_private (GtkSocket *socket)
{
return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate);
}
G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER)
static void
gtk_socket_finalize (GObject *object)
{
GtkSocket *socket = GTK_SOCKET (object);
g_object_unref (socket->accel_group);
socket->accel_group = NULL;
GtkSocketPrivate *priv = socket->priv;
g_object_unref (priv->accel_group);
G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
}
......@@ -213,7 +199,7 @@ gtk_socket_class_init (GtkSocketClass *class)
/* We don't want to show_all the in-process plug, if any.
*/
widget_class->show_all = gtk_widget_show;
container_class->remove = gtk_socket_remove;
container_class->forall = gtk_socket_forall;
......@@ -258,20 +244,26 @@ gtk_socket_class_init (GtkSocketClass *class)
static void
gtk_socket_init (GtkSocket *socket)
{
socket->request_width = 0;
socket->request_height = 0;
socket->current_width = 0;
socket->current_height = 0;
socket->plug_window = NULL;
socket->plug_widget = NULL;
socket->focus_in = FALSE;
socket->have_size = FALSE;
socket->need_map = FALSE;
socket->active = FALSE;
socket->accel_group = gtk_accel_group_new ();
g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
GtkSocketPrivate *priv;
priv = G_TYPE_INSTANCE_GET_PRIVATE (socket,
GTK_TYPE_SOCKET,
GtkSocketPrivate);
socket->priv = priv;
priv->request_width = 0;
priv->request_height = 0;
priv->current_width = 0;
priv->current_height = 0;
priv->plug_window = NULL;
priv->plug_widget = NULL;
priv->focus_in = FALSE;
priv->have_size = FALSE;
priv->need_map = FALSE;
priv->active = FALSE;
priv->accel_group = gtk_accel_group_new ();
g_object_set_data (G_OBJECT (priv->accel_group), I_("gtk-socket"), socket);
}
/**
......@@ -363,7 +355,7 @@ gtk_socket_get_plug_window (GtkSocket *socket)
{
g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
return socket->plug_window;
return socket->priv->plug_window;
}
static void
......@@ -422,33 +414,34 @@ gtk_socket_realize (GtkWidget *widget)
void
_gtk_socket_end_embedding (GtkSocket *socket)
{
GtkSocketPrivate *private = _gtk_socket_get_private (socket);
GtkSocketPrivate *private = socket->priv;
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
if (GTK_IS_WINDOW (toplevel))
_gtk_socket_windowing_end_embedding_toplevel (socket);
g_object_unref (socket->plug_window);
socket->plug_window = NULL;
socket->current_width = 0;
socket->current_height = 0;
g_object_unref (private->plug_window);
private->plug_window = NULL;
private->current_width = 0;
private->current_height = 0;
private->resize_count = 0;
gtk_accel_group_disconnect (socket->accel_group, NULL);
gtk_accel_group_disconnect (private->accel_group, NULL);
}
static void
gtk_socket_unrealize (GtkWidget *widget)
{
GtkSocket *socket = GTK_SOCKET (widget);
GtkSocketPrivate *private = socket->priv;
gtk_widget_set_realized (widget, FALSE);
if (socket->plug_widget)
if (private->plug_widget)
{
_gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
_gtk_plug_remove_from_socket (GTK_PLUG (private->plug_widget), socket);
}
else if (socket->plug_window)
else if (private->plug_window)
{
_gtk_socket_end_embedding (socket);
}
......@@ -462,18 +455,19 @@ gtk_socket_get_preferred_width (GtkWidget *widget,
gint *natural)
{
GtkSocket *socket = GTK_SOCKET (widget);
GtkSocketPrivate *private = socket->priv;
if (socket->plug_widget)
if (private->plug_widget)
{
gtk_widget_get_preferred_width (socket->plug_widget, minimum, natural);
gtk_widget_get_preferred_width (private->plug_widget, minimum, natural);
}
else
{
if (socket->is_mapped && !socket->have_size && socket->plug_window)
if (private->is_mapped && !private->have_size && private->plug_window)
_gtk_socket_windowing_size_request (socket);
if (socket->is_mapped && socket->have_size)
*minimum = *natural = MAX (socket->request_width, 1);
if (private->is_mapped && private->have_size)
*minimum = *natural = MAX (private->request_width, 1);
else
*minimum = *natural = 1;
}
......@@ -485,18 +479,19 @@ gtk_socket_get_preferred_height (GtkWidget *widget,
gint *natural)
{
GtkSocket *socket = GTK_SOCKET (widget);
GtkSocketPrivate *private = socket->priv;
if (socket->plug_widget)
if (private->plug_widget)
{
gtk_widget_get_preferred_height (socket->plug_widget, minimum, natural);
gtk_widget_get_preferred_height (private->plug_widget, minimum, natural);
}
else
{
if (socket->is_mapped && !socket->have_size && socket->plug_window)
if (private->is_mapped && !private->have_size && private->plug_window)
_gtk_socket_windowing_size_request (socket);
if (socket->is_mapped && socket->have_size)
*minimum = *natural = MAX (socket->request_height, 1);
if (private->is_mapped && private->have_size)
*minimum = *natural = MAX (private->request_height, 1);
else
*minimum = *natural = 1;
}
......@@ -507,6 +502,7 @@ gtk_socket_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkSocket *socket = GTK_SOCKET (widget);
GtkSocketPrivate *private = socket->priv;
gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
......@@ -515,7 +511,7 @@ gtk_socket_size_allocate (GtkWidget *widget,
allocation->x, allocation->y,
allocation->width, allocation->height);
if (socket->plug_widget)
if (private->plug_widget)
{
GtkAllocation child_allocation;
......@@ -524,18 +520,16 @@ gtk_socket_size_allocate (GtkWidget *widget,
child_allocation.width = allocation->width;
child_allocation.height = allocation->height;
gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
gtk_widget_size_allocate (private->plug_widget, &child_allocation);
}
else if (socket->plug_window)
else if (private->plug_window)
{
GtkSocketPrivate *private = _gtk_socket_get_private (socket);
gdk_error_trap_push ();
if (allocation->width != socket->current_width ||
allocation->height != socket->current_height)
if (allocation->width != private->current_width ||
allocation->height != private->current_height)
{
gdk_window_move_resize (socket->plug_window,
gdk_window_move_resize (private->plug_window,