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  * Conversion parameters:
26  * inFile  = GtkSocket.html
27  * outPack = gtk
28  * outFile = Socket
29  * strct   = GtkSocket
30  * realStrct=
31  * ctorStrct=
32  * clss    = Socket
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_socket_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * module aliases:
48  * local aliases:
49  * 	- Window -> gulong
50  * overrides:
51  */
52 
53 module gtk.Socket;
54 
55 public  import gtkc.gtktypes;
56 
57 private import gtkc.gtk;
58 private import glib.ConstructionException;
59 private import gobject.ObjectG;
60 
61 private import gobject.Signals;
62 public  import gtkc.gdktypes;
63 
64 
65 private import gtk.Container;
66 
67 /**
68  * Together with GtkPlug, GtkSocket provides the ability to embed
69  * widgets from one process into another process in a fashion that
70  * is transparent to the user. One process creates a GtkSocket widget
71  * and passes that widget's window ID to the other process, which then
72  * creates a GtkPlug with that window ID. Any widgets contained in the
73  * GtkPlug then will appear inside the first application's window.
74  *
75  * The socket's window ID is obtained by using gtk_socket_get_id().
76  * Before using this function, the socket must have been realized,
77  * and for hence, have been added to its parent.
78  *
79  * $(DDOC_COMMENT example)
80  *
81  * Note that if you pass the window ID of the socket to another
82  * process that will create a plug in the socket, you must make
83  * sure that the socket widget is not destroyed until that plug
84  * is created. Violating this rule will cause unpredictable
85  * consequences, the most likely consequence being that the plug
86  * will appear as a separate toplevel window. You can check if
87  * the plug has been created by using gtk_socket_get_plug_window().
88  * If it returns a non-NULL value, then the plug has been
89  * successfully created inside of the socket.
90  *
91  * When GTK+ is notified that the embedded window has been destroyed,
92  * then it will destroy the socket as well. You should always,
93  * therefore, be prepared for your sockets to be destroyed at any
94  * time when the main event loop is running. To prevent this from
95  * happening, you can connect to the "plug-removed" signal.
96  *
97  * The communication between a GtkSocket and a GtkPlug follows the
98  * XEmbed
99  * protocol. This protocol has also been implemented in other toolkits,
100  * e.g. Qt, allowing the same level of
101  * integration when embedding a Qt widget
102  * in GTK or vice versa.
103  *
104  * Note
105  *
106  * The GtkPlug and GtkSocket widgets are only available when GTK+
107  * is compiled for the X11 platform and GDK_WINDOWING_X11 is defined.
108  * They can only be used on a GdkX11Display. To use GtkPlug and
109  * GtkSocket, you need to include the gtk/gtkx.h
110  * header.
111  */
112 public class Socket : Container
113 {
114 	
115 	/** the main Gtk struct */
116 	protected GtkSocket* gtkSocket;
117 	
118 	
119 	/** Get the main Gtk struct */
120 	public GtkSocket* getSocketStruct()
121 	{
122 		return gtkSocket;
123 	}
124 	
125 	
126 	/** the main Gtk struct as a void* */
127 	protected override void* getStruct()
128 	{
129 		return cast(void*)gtkSocket;
130 	}
131 	
132 	/**
133 	 * Sets our main struct and passes it to the parent class
134 	 */
135 	public this (GtkSocket* gtkSocket)
136 	{
137 		super(cast(GtkContainer*)gtkSocket);
138 		this.gtkSocket = gtkSocket;
139 	}
140 	
141 	protected override void setStruct(GObject* obj)
142 	{
143 		super.setStruct(obj);
144 		gtkSocket = cast(GtkSocket*)obj;
145 	}
146 	
147 	/**
148 	 */
149 	int[string] connectedSignals;
150 	
151 	void delegate(Socket)[] onPlugAddedListeners;
152 	/**
153 	 * This signal is emitted when a client is successfully
154 	 * added to the socket.
155 	 */
156 	void addOnPlugAdded(void delegate(Socket) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
157 	{
158 		if ( !("plug-added" in connectedSignals) )
159 		{
160 			Signals.connectData(
161 			getStruct(),
162 			"plug-added",
163 			cast(GCallback)&callBackPlugAdded,
164 			cast(void*)this,
165 			null,
166 			connectFlags);
167 			connectedSignals["plug-added"] = 1;
168 		}
169 		onPlugAddedListeners ~= dlg;
170 	}
171 	extern(C) static void callBackPlugAdded(GtkSocket* socketStruct, Socket _socket)
172 	{
173 		foreach ( void delegate(Socket) dlg ; _socket.onPlugAddedListeners )
174 		{
175 			dlg(_socket);
176 		}
177 	}
178 	
179 	bool delegate(Socket)[] onPlugRemovedListeners;
180 	/**
181 	 * This signal is emitted when a client is removed from the socket.
182 	 * The default action is to destroy the GtkSocket widget, so if you
183 	 * want to reuse it you must add a signal handler that returns TRUE.
184 	 * TRUE to stop other handlers from being invoked.
185 	 * See Also
186 	 * GtkPlug, XEmbed
187 	 */
188 	void addOnPlugRemoved(bool delegate(Socket) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
189 	{
190 		if ( !("plug-removed" in connectedSignals) )
191 		{
192 			Signals.connectData(
193 			getStruct(),
194 			"plug-removed",
195 			cast(GCallback)&callBackPlugRemoved,
196 			cast(void*)this,
197 			null,
198 			connectFlags);
199 			connectedSignals["plug-removed"] = 1;
200 		}
201 		onPlugRemovedListeners ~= dlg;
202 	}
203 	extern(C) static gboolean callBackPlugRemoved(GtkSocket* socketStruct, Socket _socket)
204 	{
205 		foreach ( bool delegate(Socket) dlg ; _socket.onPlugRemovedListeners )
206 		{
207 			if ( dlg(_socket) )
208 			{
209 				return 1;
210 			}
211 		}
212 		
213 		return 0;
214 	}
215 	
216 	
217 	/**
218 	 * Create a new empty GtkSocket.
219 	 * Throws: ConstructionException GTK+ fails to create the object.
220 	 */
221 	public this ()
222 	{
223 		// GtkWidget * gtk_socket_new (void);
224 		auto p = gtk_socket_new();
225 		if(p is null)
226 		{
227 			throw new ConstructionException("null returned by gtk_socket_new()");
228 		}
229 		this(cast(GtkSocket*) p);
230 	}
231 	
232 	/**
233 	 * Adds an XEMBED client, such as a GtkPlug, to the GtkSocket. The
234 	 * client may be in the same process or in a different process.
235 	 * To embed a GtkPlug in a GtkSocket, you can either create the
236 	 * GtkPlug with gtk_plug_new (0), call
237 	 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
238 	 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
239 	 * window ID for the socket, and call gtk_plug_new() passing in that
240 	 * ID.
241 	 * The GtkSocket must have already be added into a toplevel window
242 	 *  before you can make this call.
243 	 * Params:
244 	 * window = the Window of a client participating in the XEMBED protocol.
245 	 */
246 	public void addId(gulong window)
247 	{
248 		// void gtk_socket_add_id (GtkSocket *socket_,  Window window);
249 		gtk_socket_add_id(gtkSocket, window);
250 	}
251 	
252 	/**
253 	 * Gets the window ID of a GtkSocket widget, which can then
254 	 * be used to create a client embedded inside the socket, for
255 	 * instance with gtk_plug_new().
256 	 * The GtkSocket must have already be added into a toplevel window
257 	 * before you can make this call.
258 	 * Returns: the window ID for the socket
259 	 */
260 	public gulong getId()
261 	{
262 		// Window gtk_socket_get_id (GtkSocket *socket_);
263 		return gtk_socket_get_id(gtkSocket);
264 	}
265 	
266 	/**
267 	 * Retrieves the window of the plug. Use this to check if the plug has
268 	 * been created inside of the socket.
269 	 * Since 2.14
270 	 * Signal Details
271 	 * The "plug-added" signal
272 	 * void user_function (GtkSocket *socket_,
273 	 *  gpointer user_data) : Run Last
274 	 * This signal is emitted when a client is successfully
275 	 * added to the socket.
276 	 * Returns: the window of the plug if available, or NULL. [transfer none]
277 	 */
278 	public GdkWindow* getPlugWindow()
279 	{
280 		// GdkWindow * gtk_socket_get_plug_window (GtkSocket *socket_);
281 		return gtk_socket_get_plug_window(gtkSocket);
282 	}
283 }