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