Créer  Editer  FrontPage  Index  Chercher  Changements  History  RSS  Login

Gtk::Socket

class Gtk::Socket

Together with Gtk::Plug, Gtk::Socket provides the ability to embed widgets from one process into another process in a fashion that is transparent to the user. One process creates a Gtk::Socket widget and, passes the that widget's window ID to the other process, which then creates a Gtk::Plug with that window ID. Any widgets contained in the Gtk::Plug then will appear inside the first applications window. The socket's window ID is obtained by using Gtk::Socket#id. Before using this method, the socket must have been realized, and for hence, have been added to its parent.

Example 1. Obtaining the window ID of a socket.

socket = Gtk::Socket.new
socket.show
parent.add(socket)

# The following call is only necessary if one of
# the ancestors of the socket is not yet visible.
socket.realize
puts "The ID of the sockets window is #{socket.id}"

Note that if you pass the window ID of the socket to another process that will create a plug in the socket, you must make sure that the socket widget is not destroyed until that plug is created. Violating this rule will cause unpredictable consequences, the most likely consequence being that the plug will appear as a separate toplevel window. You can check if the plug has been created by examining the Gtk::Socket#plug_window. If this field is non-nil, then the plug has been successfully created inside of the socket. When GTK+ is notified that the embedded window has been destroyed, then it will destroy the socket as well. You should always, therefore, be prepared for your sockets to be destroyed at any time when the main event loop is running. The communication between a Gtk::Socket and a Gtk::Plug follows the XEmbed protocol. This protocol has also been implemented in other toolkits, e.g. Qt, allowing the same level of integration when embedding a Qt widget in GTK or vice versa.

Class Methods

Gtk::Socket.new
Create a new empty Gtk::Socket.

Instance Methods

add_id(window_id)
Adds an XEMBED client, such as a Gtk::Plug, to the Gtk::Socket. The client may be in the same process or in a different process. To embed a Gtk::Plug in a Gtk::Socket, you can either create the Gtk::Plug with Gtk::Plug.new(0), call Gtk::Plug#id to get the window ID of the plug, and then pass that to the Gtk::Socket#add_id, or you can call Gtk::Socket#id to get the window ID for the socket, and call Gtk::Plug.new passing in that ID. The Gtk::Socket must have already be added into a toplevel window before you can make this call.
  • window_id: the window ID of a client participating in the XEMBED protocol.
  • Returns: self
id
Gets the window ID of a Gtk::Socket widget, which can then be used to create a client embedded inside the socket, for instance with Gtk::Plug.new. The Gtk::Socket must have already be added into a toplevel window before you can make this call.
  • Returns: the window ID for the socket
plug_window
Returns plug_window value. You can check if the plug has been created.
Dernière modification:2011/06/22 20:57:36
Mots clef:
Références:[Gtk::Widget] [Gtk::Plug] [Gtk::Socket]