1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.Socket;
26 
27 private import gdk.Window;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Container;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * Together with #GtkPlug, #GtkSocket provides the ability to embed
41  * widgets from one process into another process in a fashion that
42  * is transparent to the user. One process creates a #GtkSocket widget
43  * and passes that widget’s window ID to the other process, which then
44  * creates a #GtkPlug with that window ID. Any widgets contained in the
45  * #GtkPlug then will appear inside the first application’s window.
46  * 
47  * The socket’s window ID is obtained by using gtk_socket_get_id().
48  * Before using this function, the socket must have been realized,
49  * and for hence, have been added to its parent.
50  * 
51  * ## Obtaining the window ID of a socket.
52  * 
53  * |[<!-- language="C" -->
54  * GtkWidget *socket = gtk_socket_new ();
55  * gtk_widget_show (socket);
56  * gtk_container_add (GTK_CONTAINER (parent), socket);
57  * 
58  * // The following call is only necessary if one of
59  * // the ancestors of the socket is not yet visible.
60  * gtk_widget_realize (socket);
61  * g_print ("The ID of the sockets window is %#x\n",
62  * gtk_socket_get_id (socket));
63  * ]|
64  * 
65  * Note that if you pass the window ID of the socket to another
66  * process that will create a plug in the socket, you must make
67  * sure that the socket widget is not destroyed until that plug
68  * is created. Violating this rule will cause unpredictable
69  * consequences, the most likely consequence being that the plug
70  * will appear as a separate toplevel window. You can check if
71  * the plug has been created by using gtk_socket_get_plug_window().
72  * If it returns a non-%NULL value, then the plug has been
73  * successfully created inside of the socket.
74  * 
75  * When GTK+ is notified that the embedded window has been destroyed,
76  * then it will destroy the socket as well. You should always,
77  * therefore, be prepared for your sockets to be destroyed at any
78  * time when the main event loop is running. To prevent this from
79  * happening, you can connect to the #GtkSocket::plug-removed signal.
80  * 
81  * The communication between a #GtkSocket and a #GtkPlug follows the
82  * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec).
83  * This protocol has also been implemented in other toolkits, e.g. Qt,
84  * allowing the same level of integration when embedding a Qt widget
85  * in GTK or vice versa.
86  * 
87  * The #GtkPlug and #GtkSocket widgets are only available when GTK+
88  * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
89  * They can only be used on a #GdkX11Display. To use #GtkPlug and
90  * #GtkSocket, you need to include the `gtk/gtkx.h` header.
91  */
92 public class Socket : Container
93 {
94 	/** the main Gtk struct */
95 	protected GtkSocket* gtkSocket;
96 
97 	/** Get the main Gtk struct */
98 	public GtkSocket* getSocketStruct(bool transferOwnership = false)
99 	{
100 		if (transferOwnership)
101 			ownedRef = false;
102 		return gtkSocket;
103 	}
104 
105 	/** the main Gtk struct as a void* */
106 	protected override void* getStruct()
107 	{
108 		return cast(void*)gtkSocket;
109 	}
110 
111 	/**
112 	 * Sets our main struct and passes it to the parent class.
113 	 */
114 	public this (GtkSocket* gtkSocket, bool ownedRef = false)
115 	{
116 		this.gtkSocket = gtkSocket;
117 		super(cast(GtkContainer*)gtkSocket, ownedRef);
118 	}
119 
120 
121 	/** */
122 	public static GType getType()
123 	{
124 		return gtk_socket_get_type();
125 	}
126 
127 	/**
128 	 * Create a new empty #GtkSocket.
129 	 *
130 	 * Returns: the new #GtkSocket.
131 	 *
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this()
135 	{
136 		auto p = gtk_socket_new();
137 
138 		if(p is null)
139 		{
140 			throw new ConstructionException("null returned by new");
141 		}
142 
143 		this(cast(GtkSocket*) p);
144 	}
145 
146 	/**
147 	 * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket.  The
148 	 * client may be in the same process or in a different process.
149 	 *
150 	 * To embed a #GtkPlug in a #GtkSocket, you can either create the
151 	 * #GtkPlug with `gtk_plug_new (0)`, call
152 	 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
153 	 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
154 	 * window ID for the socket, and call gtk_plug_new() passing in that
155 	 * ID.
156 	 *
157 	 * The #GtkSocket must have already be added into a toplevel window
158 	 * before you can make this call.
159 	 *
160 	 * Params:
161 	 *     window = the Window of a client participating in the XEMBED protocol.
162 	 */
163 	public void addId(ulong window)
164 	{
165 		gtk_socket_add_id(gtkSocket, window);
166 	}
167 
168 	/**
169 	 * Gets the window ID of a #GtkSocket widget, which can then
170 	 * be used to create a client embedded inside the socket, for
171 	 * instance with gtk_plug_new().
172 	 *
173 	 * The #GtkSocket must have already be added into a toplevel window
174 	 * before you can make this call.
175 	 *
176 	 * Returns: the window ID for the socket
177 	 */
178 	public ulong getId()
179 	{
180 		return gtk_socket_get_id(gtkSocket);
181 	}
182 
183 	/**
184 	 * Retrieves the window of the plug. Use this to check if the plug has
185 	 * been created inside of the socket.
186 	 *
187 	 * Returns: the window of the plug if
188 	 *     available, or %NULL
189 	 *
190 	 * Since: 2.14
191 	 */
192 	public Window getPlugWindow()
193 	{
194 		auto p = gtk_socket_get_plug_window(gtkSocket);
195 
196 		if(p is null)
197 		{
198 			return null;
199 		}
200 
201 		return ObjectG.getDObject!(Window)(cast(GdkWindow*) p);
202 	}
203 
204 	/**
205 	 * This signal is emitted when a client is successfully
206 	 * added to the socket.
207 	 */
208 	gulong addOnPlugAdded(void delegate(Socket) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
209 	{
210 		return Signals.connect(this, "plug-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
211 	}
212 
213 	/**
214 	 * This signal is emitted when a client is removed from the socket.
215 	 * The default action is to destroy the #GtkSocket widget, so if you
216 	 * want to reuse it you must add a signal handler that returns %TRUE.
217 	 *
218 	 * Returns: %TRUE to stop other handlers from being invoked.
219 	 */
220 	gulong addOnPlugRemoved(bool delegate(Socket) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
221 	{
222 		return Signals.connect(this, "plug-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
223 	}
224 }