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 gtk.c.functions; 35 public import gtk.c.types; 36 public import gtkc.gtktypes; 37 private import std.algorithm; 38 39 40 /** 41 * Together with #GtkSocket, #GtkPlug provides the ability to embed 42 * widgets from one process into another process in a fashion that is 43 * transparent to the user. One process creates a #GtkSocket widget 44 * and passes the ID of that widget’s window to the other process, 45 * which then creates a #GtkPlug with that window ID. Any widgets 46 * contained in the #GtkPlug then will appear inside the first 47 * application’s window. 48 * 49 * The communication between a #GtkSocket and a #GtkPlug follows the 50 * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec). 51 * This protocol has also been implemented in other toolkits, e.g. Qt, 52 * allowing the same level of 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` header. 59 */ 60 public class Plug : Window 61 { 62 /** the main Gtk struct */ 63 protected GtkPlug* gtkPlug; 64 65 /** Get the main Gtk struct */ 66 public GtkPlug* getPlugStruct(bool transferOwnership = false) 67 { 68 if (transferOwnership) 69 ownedRef = false; 70 return gtkPlug; 71 } 72 73 /** the main Gtk struct as a void* */ 74 protected override void* getStruct() 75 { 76 return cast(void*)gtkPlug; 77 } 78 79 protected override void setStruct(GObject* obj) 80 { 81 gtkPlug = cast(GtkPlug*)obj; 82 super.setStruct(obj); 83 } 84 85 /** 86 * Sets our main struct and passes it to the parent class. 87 */ 88 public this (GtkPlug* gtkPlug, bool ownedRef = false) 89 { 90 this.gtkPlug = gtkPlug; 91 super(cast(GtkWindow*)gtkPlug, ownedRef); 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 * Returns: 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 * Returns: 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 * Returns: %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 * Returns: 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 * Returns: 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 protected class OnEmbeddedDelegateWrapper 223 { 224 void delegate(Plug) dlg; 225 gulong handlerId; 226 227 this(void delegate(Plug) dlg) 228 { 229 this.dlg = dlg; 230 onEmbeddedListeners ~= this; 231 } 232 233 void remove(OnEmbeddedDelegateWrapper source) 234 { 235 foreach(index, wrapper; onEmbeddedListeners) 236 { 237 if (wrapper.handlerId == source.handlerId) 238 { 239 onEmbeddedListeners[index] = null; 240 onEmbeddedListeners = std.algorithm.remove(onEmbeddedListeners, index); 241 break; 242 } 243 } 244 } 245 } 246 OnEmbeddedDelegateWrapper[] onEmbeddedListeners; 247 248 /** 249 * Gets emitted when the plug becomes embedded in a socket. 250 */ 251 gulong addOnEmbedded(void delegate(Plug) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 252 { 253 auto wrapper = new OnEmbeddedDelegateWrapper(dlg); 254 wrapper.handlerId = Signals.connectData( 255 this, 256 "embedded", 257 cast(GCallback)&callBackEmbedded, 258 cast(void*)wrapper, 259 cast(GClosureNotify)&callBackEmbeddedDestroy, 260 connectFlags); 261 return wrapper.handlerId; 262 } 263 264 extern(C) static void callBackEmbedded(GtkPlug* plugStruct, OnEmbeddedDelegateWrapper wrapper) 265 { 266 wrapper.dlg(wrapper.outer); 267 } 268 269 extern(C) static void callBackEmbeddedDestroy(OnEmbeddedDelegateWrapper wrapper, GClosure* closure) 270 { 271 wrapper.remove(wrapper); 272 } 273 }