<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Chapter 20. Plugs and Sockets</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Programming with gtkmm"> <link rel="up" href="index.html" title="Programming with gtkmm"> <link rel="prev" href="sec-recentchooser.html" title="RecentChooser"> <link rel="next" href="sec-plugs-sockets-example.html" title="Plugs and Sockets Example"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">Chapter 20. Plugs and Sockets</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="sec-recentchooser.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center"> </th> <td width="20%" align="right"> <a accesskey="n" href="sec-plugs-sockets-example.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="chapter" title="Chapter 20. Plugs and Sockets"> <div class="titlepage"><div><div><h2 class="title"> <a name="chapter-plugs-sockets"></a>Chapter 20. Plugs and Sockets</h2></div></div></div> <div class="toc"> <p><b>Table of Contents</b></p> <ul> <li><span class="sect1"><a href="chapter-plugs-sockets.html#sec-plugs-sockets-overview">Overview</a></span></li> <li><span class="sect1"><a href="sec-plugs-sockets-example.html">Plugs and Sockets Example</a></span></li> </ul> </div> <div class="sect1" title="Overview"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-plugs-sockets-overview"></a>Overview</h2></div></div></div> <p> From time to time, it may be useful to be able to embed a widget from another application within your application. <span class="application">gtkmm</span> allows you to do this with the <code class="classname">Gtk::Socket</code> and <code class="classname">Gtk::Plug</code> classes. It is not anticipated that very many applications will need this functionality, but in the rare case that you need to display a widget that is running in a completely different process, these classes can be very helpful. </p> <p> The communication between a <code class="classname">Socket</code> and a <code class="classname">Plug</code> follows the XEmbed protocol. This protocol has also been implemented in other toolkits (e.g. Qt), which allows the same level of integration when embedding a Qt widget in GTK+ or vice versa. </p> <p> The way that <code class="classname">Sockets</code> and <code class="classname">Plugs</code> work together is through their window ids. Both a <code class="classname">Socket</code> and a <code class="classname">Plug</code> have IDs that can be retrieved with their <code class="methodname">get_id()</code> member functions. The use of these IDs will be explained below in <a class="xref" href="chapter-plugs-sockets.html#sec-connecting-plugs-sockets" title="Connecting Plugs and Sockets">the section called “Connecting Plugs and Sockets”</a>. </p> <div class="sect2" title="Sockets"> <div class="titlepage"><div><div><h3 class="title"> <a name="sec-sockets"></a>Sockets</h3></div></div></div> <p> A <code class="classname">Socket</code> is a special kind of container widget that provides the ability to embed widgets from one process into another process in a way that is transparent to the user. </p> </div> <div class="sect2" title="Plugs"> <div class="titlepage"><div><div><h3 class="title"> <a name="sec-plugs"></a>Plugs</h3></div></div></div> <p> A <code class="classname">Plug</code> is a special kind of Window that can be plugged into a <code class="classname">Socket</code>. Besides the normal properties and methods of <code class="classname">Gtk::Window</code>, a <code class="classname">Plug</code> provides a constructor that takes the ID of a <code class="classname">Socket</code>, which will automatically embed the <code class="classname">Plug</code> into the <code class="classname">Socket</code> that matches that ID. </p> <p> Since a <code class="classname">Plug</code> is just a special type of <code class="classname">Gtk::Window</code> class, you can add containers or widgets to it like you would to any other window. </p> </div> <div class="sect2" title="Connecting Plugs and Sockets"> <div class="titlepage"><div><div><h3 class="title"> <a name="sec-connecting-plugs-sockets"></a>Connecting Plugs and Sockets</h3></div></div></div> <p> After a <code class="classname">Socket</code> or <code class="classname">Plug</code> object is realized, you can obtain its ID with its <code class="methodname">get_id()</code> function. This ID can then be shared with other processes so that other processes know how to connect to eachother. </p> <p> There are two basic strategies that can be used: </p> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> Create a <code class="classname">Socket</code> object in one process and pass the ID of that <code class="classname">Socket</code> to another process so that it can create a <code class="classname">Plug</code> object by specifying the given <code class="classname">Socket</code> ID in its constructor. There is no way to assign a <code class="classname">Plug</code> to a particular <code class="classname">Socket</code> after creation, so you must pass the <code class="classname">Socket</code> ID to the <code class="classname">Plug</code>'s constructor. </p></li> <li class="listitem"><p> Create a <code class="classname">Plug</code> independantly from any particular <code class="classname">Socket</code> and pass the ID of the <code class="classname">Plug</code> to other processes that need to use it. The ID of the <code class="classname">Plug</code> can be associated with a particular <code class="classname">Socket</code> object using the <code class="methodname">Socket::add_id()</code> function. This is the approach used in the example below. </p></li> </ul></div> <p> </p> </div> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="sec-recentchooser.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"> </td> <td width="40%" align="right"> <a accesskey="n" href="sec-plugs-sockets-example.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">RecentChooser </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> Plugs and Sockets Example</td> </tr> </table> </div> </body> </html>