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