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 	public static GType getType()
94 	{
95 		return gtk_plug_get_type();
96 	}
97 
98 	/**
99 	 * Creates a new plug widget inside the #GtkSocket identified
100 	 * by @socket_id. If @socket_id is 0, the plug is left “unplugged” and
101 	 * can later be plugged into a #GtkSocket by  gtk_socket_add_id().
102 	 *
103 	 * Params:
104 	 *     socketId = the window ID of the socket, or 0.
105 	 *
106 	 * Return: the new #GtkPlug widget.
107 	 *
108 	 * Throws: ConstructionException GTK+ fails to create the object.
109 	 */
110 	public this(ulong socketId)
111 	{
112 		auto p = gtk_plug_new(socketId);
113 		
114 		if(p is null)
115 		{
116 			throw new ConstructionException("null returned by new");
117 		}
118 		
119 		this(cast(GtkPlug*) p);
120 	}
121 
122 	/**
123 	 * Create a new plug widget inside the #GtkSocket identified by socket_id.
124 	 *
125 	 * Params:
126 	 *     display = the #GdkDisplay on which @socket_id is displayed
127 	 *     socketId = the XID of the socket’s window.
128 	 *
129 	 * Return: the new #GtkPlug widget.
130 	 *
131 	 * Since: 2.2
132 	 *
133 	 * Throws: ConstructionException GTK+ fails to create the object.
134 	 */
135 	public this(Display display, ulong socketId)
136 	{
137 		auto p = gtk_plug_new_for_display((display is null) ? null : display.getDisplayStruct(), socketId);
138 		
139 		if(p is null)
140 		{
141 			throw new ConstructionException("null returned by new_for_display");
142 		}
143 		
144 		this(cast(GtkPlug*) p);
145 	}
146 
147 	/**
148 	 * Finish the initialization of @plug for a given #GtkSocket identified by
149 	 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
150 	 *
151 	 * Params:
152 	 *     socketId = the XID of the socket’s window.
153 	 */
154 	public void construct(ulong socketId)
155 	{
156 		gtk_plug_construct(gtkPlug, socketId);
157 	}
158 
159 	/**
160 	 * Finish the initialization of @plug for a given #GtkSocket identified by
161 	 * @socket_id which is currently displayed on @display.
162 	 * This function will generally only be used by classes deriving from #GtkPlug.
163 	 *
164 	 * Params:
165 	 *     display = the #GdkDisplay associated with @socket_id’s
166 	 *         #GtkSocket.
167 	 *     socketId = the XID of the socket’s window.
168 	 *
169 	 * Since: 2.2
170 	 */
171 	public void constructForDisplay(Display display, ulong socketId)
172 	{
173 		gtk_plug_construct_for_display(gtkPlug, (display is null) ? null : display.getDisplayStruct(), socketId);
174 	}
175 
176 	/**
177 	 * Determines whether the plug is embedded in a socket.
178 	 *
179 	 * Return: %TRUE if the plug is embedded in a socket
180 	 *
181 	 * Since: 2.14
182 	 */
183 	public bool getEmbedded()
184 	{
185 		return gtk_plug_get_embedded(gtkPlug) != 0;
186 	}
187 
188 	/**
189 	 * Gets the window ID of a #GtkPlug widget, which can then
190 	 * be used to embed this window inside another window, for
191 	 * instance with gtk_socket_add_id().
192 	 *
193 	 * Return: the window ID for the plug
194 	 */
195 	public ulong getId()
196 	{
197 		return gtk_plug_get_id(gtkPlug);
198 	}
199 
200 	/**
201 	 * Retrieves the socket the plug is embedded in.
202 	 *
203 	 * Return: the window of the socket, or %NULL
204 	 *
205 	 * Since: 2.14
206 	 */
207 	public GdkWin getSocketWindow()
208 	{
209 		auto p = gtk_plug_get_socket_window(gtkPlug);
210 		
211 		if(p is null)
212 		{
213 			return null;
214 		}
215 		
216 		return ObjectG.getDObject!(GdkWin)(cast(GdkWindow*) p);
217 	}
218 
219 	int[string] connectedSignals;
220 
221 	void delegate(Plug)[] onEmbeddedListeners;
222 	/**
223 	 * Gets emitted when the plug becomes embedded in a socket.
224 	 */
225 	void addOnEmbedded(void delegate(Plug) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
226 	{
227 		if ( "embedded" !in connectedSignals )
228 		{
229 			Signals.connectData(
230 				this,
231 				"embedded",
232 				cast(GCallback)&callBackEmbedded,
233 				cast(void*)this,
234 				null,
235 				connectFlags);
236 			connectedSignals["embedded"] = 1;
237 		}
238 		onEmbeddedListeners ~= dlg;
239 	}
240 	extern(C) static void callBackEmbedded(GtkPlug* plugStruct, Plug _plug)
241 	{
242 		foreach ( void delegate(Plug) dlg; _plug.onEmbeddedListeners )
243 		{
244 			dlg(_plug);
245 		}
246 	}
247 }