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 * Conversion parameters: 26 * inFile = GtkSocket.html 27 * outPack = gtk 28 * outFile = Socket 29 * strct = GtkSocket 30 * realStrct= 31 * ctorStrct= 32 * clss = Socket 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_socket_ 41 * - gtk_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - gdk.Window 48 * structWrap: 49 * - GdkWindow* -> Window 50 * module aliases: 51 * local aliases: 52 * overrides: 53 */ 54 55 module gtk.Socket; 56 57 public import gtkc.gtktypes; 58 59 private import gtkc.gtk; 60 private import glib.ConstructionException; 61 private import gobject.ObjectG; 62 63 private import gobject.Signals; 64 public import gtkc.gdktypes; 65 66 private import gdk.Window; 67 68 69 70 private import gtk.Container; 71 72 /** 73 * Description 74 * Together with GtkPlug, GtkSocket provides the ability 75 * to embed widgets from one process into another process 76 * in a fashion that is transparent to the user. One 77 * process creates a GtkSocket widget and passes 78 * that widget's window ID to the other process, 79 * which then creates a GtkPlug with that window ID. 80 * Any widgets contained in the GtkPlug then will appear 81 * inside the first application's window. 82 * The socket's window ID is obtained by using 83 * gtk_socket_get_id(). Before using this function, 84 * the socket must have been realized, and for hence, 85 * have been added to its parent. 86 * $(DDOC_COMMENT example) 87 * Note that if you pass the window ID of the socket to another 88 * process that will create a plug in the socket, you 89 * must make sure that the socket widget is not destroyed 90 * until that plug is created. Violating this rule will 91 * cause unpredictable consequences, the most likely 92 * consequence being that the plug will appear as a 93 * separate toplevel window. You can check if the plug 94 * has been created by using gtk_socket_get_plug_window(). If 95 * it returns a non-NULL value, then the plug has been 96 * successfully created inside of the socket. 97 * When GTK+ is notified that the embedded window has been 98 * destroyed, then it will destroy the socket as well. You 99 * should always, therefore, be prepared for your sockets 100 * to be destroyed at any time when the main event loop 101 * is running. To prevent this from happening, you can 102 * connect to the "plug-removed" signal. 103 * The communication between a GtkSocket and a GtkPlug follows the 104 * XEmbed 105 * protocol. This protocol has also been implemented in other toolkits, e.g. 106 * Qt, allowing the same level of integration 107 * when embedding a Qt widget in GTK or vice versa. 108 * A socket can also be used to swallow arbitrary 109 * pre-existing top-level windows using gtk_socket_steal(), 110 * though the integration when this is done will not be as close 111 * as between a GtkPlug and a GtkSocket. 112 * Note 113 * The GtkPlug and GtkSocket widgets are currently not available 114 * on all platforms supported by GTK+. 115 */ 116 public class Socket : Container 117 { 118 119 /** the main Gtk struct */ 120 protected GtkSocket* gtkSocket; 121 122 123 public GtkSocket* getSocketStruct() 124 { 125 return gtkSocket; 126 } 127 128 129 /** the main Gtk struct as a void* */ 130 protected override void* getStruct() 131 { 132 return cast(void*)gtkSocket; 133 } 134 135 /** 136 * Sets our main struct and passes it to the parent class 137 */ 138 public this (GtkSocket* gtkSocket) 139 { 140 super(cast(GtkContainer*)gtkSocket); 141 this.gtkSocket = gtkSocket; 142 } 143 144 protected override void setStruct(GObject* obj) 145 { 146 super.setStruct(obj); 147 gtkSocket = cast(GtkSocket*)obj; 148 } 149 150 /** 151 */ 152 int[string] connectedSignals; 153 154 void delegate(Socket)[] onPlugAddedListeners; 155 /** 156 * This signal is emitted when a client is successfully 157 * added to the socket. 158 */ 159 void addOnPlugAdded(void delegate(Socket) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 160 { 161 if ( !("plug-added" in connectedSignals) ) 162 { 163 Signals.connectData( 164 getStruct(), 165 "plug-added", 166 cast(GCallback)&callBackPlugAdded, 167 cast(void*)this, 168 null, 169 connectFlags); 170 connectedSignals["plug-added"] = 1; 171 } 172 onPlugAddedListeners ~= dlg; 173 } 174 extern(C) static void callBackPlugAdded(GtkSocket* socketStruct, Socket _socket) 175 { 176 foreach ( void delegate(Socket) dlg ; _socket.onPlugAddedListeners ) 177 { 178 dlg(_socket); 179 } 180 } 181 182 bool delegate(Socket)[] onPlugRemovedListeners; 183 /** 184 * This signal is emitted when a client is removed from the socket. 185 * The default action is to destroy the GtkSocket widget, so if you 186 * want to reuse it you must add a signal handler that returns TRUE. 187 * TRUE to stop other handlers from being invoked. 188 * See Also 189 * GtkPlug, XEmbed 190 */ 191 void addOnPlugRemoved(bool delegate(Socket) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 192 { 193 if ( !("plug-removed" in connectedSignals) ) 194 { 195 Signals.connectData( 196 getStruct(), 197 "plug-removed", 198 cast(GCallback)&callBackPlugRemoved, 199 cast(void*)this, 200 null, 201 connectFlags); 202 connectedSignals["plug-removed"] = 1; 203 } 204 onPlugRemovedListeners ~= dlg; 205 } 206 extern(C) static gboolean callBackPlugRemoved(GtkSocket* socketStruct, Socket _socket) 207 { 208 foreach ( bool delegate(Socket) dlg ; _socket.onPlugRemovedListeners ) 209 { 210 if ( dlg(_socket) ) 211 { 212 return 1; 213 } 214 } 215 216 return 0; 217 } 218 219 220 /** 221 * Create a new empty GtkSocket. 222 * Throws: ConstructionException GTK+ fails to create the object. 223 */ 224 public this () 225 { 226 // GtkWidget * gtk_socket_new (void); 227 auto p = gtk_socket_new(); 228 if(p is null) 229 { 230 throw new ConstructionException("null returned by gtk_socket_new()"); 231 } 232 this(cast(GtkSocket*) p); 233 } 234 235 /** 236 * Warning 237 * gtk_socket_steal is deprecated and should not be used in newly-written code. 238 * Reparents a pre-existing toplevel window into a GtkSocket. This is 239 * meant to embed clients that do not know about embedding into a 240 * GtkSocket, however doing so is inherently unreliable, and using 241 * this function is not recommended. 242 * The GtkSocket must have already be added into a toplevel window 243 * before you can make this call. 244 * Params: 245 * wid = the window ID of an existing toplevel window. 246 */ 247 public void steal(GdkNativeWindow wid) 248 { 249 // void gtk_socket_steal (GtkSocket *socket_, GdkNativeWindow wid); 250 gtk_socket_steal(gtkSocket, wid); 251 } 252 253 /** 254 * Adds an XEMBED client, such as a GtkPlug, to the GtkSocket. The 255 * client may be in the same process or in a different process. 256 * To embed a GtkPlug in a GtkSocket, you can either create the 257 * GtkPlug with gtk_plug_new (0), call 258 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the 259 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the 260 * window ID for the socket, and call gtk_plug_new() passing in that 261 * ID. 262 * The GtkSocket must have already be added into a toplevel window 263 * before you can make this call. 264 * Params: 265 * windowId = the window ID of a client participating in the XEMBED protocol. 266 */ 267 public void addId(GdkNativeWindow windowId) 268 { 269 // void gtk_socket_add_id (GtkSocket *socket_, GdkNativeWindow window_id); 270 gtk_socket_add_id(gtkSocket, windowId); 271 } 272 273 /** 274 * Gets the window ID of a GtkSocket widget, which can then 275 * be used to create a client embedded inside the socket, for 276 * instance with gtk_plug_new(). 277 * The GtkSocket must have already be added into a toplevel window 278 * before you can make this call. 279 * Returns: the window ID for the socket 280 */ 281 public GdkNativeWindow getId() 282 { 283 // GdkNativeWindow gtk_socket_get_id (GtkSocket *socket_); 284 return gtk_socket_get_id(gtkSocket); 285 } 286 287 /** 288 * Retrieves the window of the plug. Use this to check if the plug has 289 * been created inside of the socket. 290 * Since 2.14 291 * Signal Details 292 * The "plug-added" signal 293 * void user_function (GtkSocket *socket_, 294 * gpointer user_data) : Run Last 295 * This signal is emitted when a client is successfully 296 * added to the socket. 297 * Returns: the window of the plug if available, or NULL. [transfer none] 298 */ 299 public Window getPlugWindow() 300 { 301 // GdkWindow * gtk_socket_get_plug_window (GtkSocket *socket_); 302 auto p = gtk_socket_get_plug_window(gtkSocket); 303 304 if(p is null) 305 { 306 return null; 307 } 308 309 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 310 } 311 }