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.Plug;
26 
27 private import gdk.Display;
28 private import gdk.Window : GdkWin = Window;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.Widget;
33 private import gtk.Window;
34 public  import gtkc.gdktypes;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 
38 
39 /**
40  * Together with #GtkSocket, #GtkPlug provides the ability to embed
41  * widgets from one process into another process in a fashion that is
42  * transparent to the user. One process creates a #GtkSocket widget
43  * and passes the ID of that widget’s window to the other process,
44  * which then creates a #GtkPlug with that window ID. Any widgets
45  * contained in the #GtkPlug then will appear inside the first
46  * application’s window.
47  * 
48  * The communication between a #GtkSocket and a #GtkPlug follows the
49  * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec).
50  * This protocol has also been implemented in other toolkits, e.g. Qt,
51  * allowing the same level of integration when embedding a Qt widget
52  * in GTK+ or vice versa.
53  * 
54  * The #GtkPlug and #GtkSocket widgets are only available when GTK+
55  * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
56  * They can only be used on a #GdkX11Display. To use #GtkPlug and
57  * #GtkSocket, you need to include the `gtk/gtkx.h` header.
58  */
59 public class Plug : Window
60 {
61 	/** the main Gtk struct */
62 	protected GtkPlug* gtkPlug;
63 
64 	/** Get the main Gtk struct */
65 	public GtkPlug* getPlugStruct()
66 	{
67 		return gtkPlug;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected override void* getStruct()
72 	{
73 		return cast(void*)gtkPlug;
74 	}
75 
76 	protected override void setStruct(GObject* obj)
77 	{
78 		gtkPlug = cast(GtkPlug*)obj;
79 		super.setStruct(obj);
80 	}
81 
82 	/**
83 	 * Sets our main struct and passes it to the parent class.
84 	 */
85 	public this (GtkPlug* gtkPlug, bool ownedRef = false)
86 	{
87 		this.gtkPlug = gtkPlug;
88 		super(cast(GtkWindow*)gtkPlug, ownedRef);
89 	}
90 
91 	/**
92 	 */
93 
94 	public static GType getType()
95 	{
96 		return gtk_plug_get_type();
97 	}
98 
99 	/**
100 	 * Creates a new plug widget inside the #GtkSocket identified
101 	 * by @socket_id. If @socket_id is 0, the plug is left “unplugged” and
102 	 * can later be plugged into a #GtkSocket by  gtk_socket_add_id().
103 	 *
104 	 * Params:
105 	 *     socketId = the window ID of the socket, or 0.
106 	 *
107 	 * Return: the new #GtkPlug widget.
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(ulong socketId)
112 	{
113 		auto p = gtk_plug_new(socketId);
114 		
115 		if(p is null)
116 		{
117 			throw new ConstructionException("null returned by new");
118 		}
119 		
120 		this(cast(GtkPlug*) p);
121 	}
122 
123 	/**
124 	 * Create a new plug widget inside the #GtkSocket identified by socket_id.
125 	 *
126 	 * Params:
127 	 *     display = the #GdkDisplay on which @socket_id is displayed
128 	 *     socketId = the XID of the socket’s window.
129 	 *
130 	 * Return: the new #GtkPlug widget.
131 	 *
132 	 * Since: 2.2
133 	 *
134 	 * Throws: ConstructionException GTK+ fails to create the object.
135 	 */
136 	public this(Display display, ulong socketId)
137 	{
138 		auto p = gtk_plug_new_for_display((display is null) ? null : display.getDisplayStruct(), socketId);
139 		
140 		if(p is null)
141 		{
142 			throw new ConstructionException("null returned by new_for_display");
143 		}
144 		
145 		this(cast(GtkPlug*) p);
146 	}
147 
148 	/**
149 	 * Finish the initialization of @plug for a given #GtkSocket identified by
150 	 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
151 	 *
152 	 * Params:
153 	 *     socketId = the XID of the socket’s window.
154 	 */
155 	public void construct(ulong socketId)
156 	{
157 		gtk_plug_construct(gtkPlug, socketId);
158 	}
159 
160 	/**
161 	 * Finish the initialization of @plug for a given #GtkSocket identified by
162 	 * @socket_id which is currently displayed on @display.
163 	 * This function will generally only be used by classes deriving from #GtkPlug.
164 	 *
165 	 * Params:
166 	 *     display = the #GdkDisplay associated with @socket_id’s
167 	 *         #GtkSocket.
168 	 *     socketId = the XID of the socket’s window.
169 	 *
170 	 * Since: 2.2
171 	 */
172 	public void constructForDisplay(Display display, ulong socketId)
173 	{
174 		gtk_plug_construct_for_display(gtkPlug, (display is null) ? null : display.getDisplayStruct(), socketId);
175 	}
176 
177 	/**
178 	 * Determines whether the plug is embedded in a socket.
179 	 *
180 	 * Return: %TRUE if the plug is embedded in a socket
181 	 *
182 	 * Since: 2.14
183 	 */
184 	public bool getEmbedded()
185 	{
186 		return gtk_plug_get_embedded(gtkPlug) != 0;
187 	}
188 
189 	/**
190 	 * Gets the window ID of a #GtkPlug widget, which can then
191 	 * be used to embed this window inside another window, for
192 	 * instance with gtk_socket_add_id().
193 	 *
194 	 * Return: the window ID for the plug
195 	 */
196 	public ulong getId()
197 	{
198 		return gtk_plug_get_id(gtkPlug);
199 	}
200 
201 	/**
202 	 * Retrieves the socket the plug is embedded in.
203 	 *
204 	 * Return: the window of the socket, or %NULL
205 	 *
206 	 * Since: 2.14
207 	 */
208 	public GdkWin getSocketWindow()
209 	{
210 		auto p = gtk_plug_get_socket_window(gtkPlug);
211 		
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 		
217 		return ObjectG.getDObject!(GdkWin)(cast(GdkWindow*) p);
218 	}
219 
220 	int[string] connectedSignals;
221 
222 	void delegate(Plug)[] onEmbeddedListeners;
223 	/**
224 	 * Gets emitted when the plug becomes embedded in a socket.
225 	 */
226 	void addOnEmbedded(void delegate(Plug) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
227 	{
228 		if ( "embedded" !in connectedSignals )
229 		{
230 			Signals.connectData(
231 				this,
232 				"embedded",
233 				cast(GCallback)&callBackEmbedded,
234 				cast(void*)this,
235 				null,
236 				connectFlags);
237 			connectedSignals["embedded"] = 1;
238 		}
239 		onEmbeddedListeners ~= dlg;
240 	}
241 	extern(C) static void callBackEmbedded(GtkPlug* plugStruct, Plug _plug)
242 	{
243 		foreach ( void delegate(Plug) dlg; _plug.onEmbeddedListeners )
244 		{
245 			dlg(_plug);
246 		}
247 	}
248 }