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