<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Paste</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="chapter-clipboard.html" title="Chapter 17. The Clipboard"> <link rel="prev" href="sec-clipboard-copy.html" title="Copy"> <link rel="next" href="sec-clipboard-examples.html" title="Examples"> </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">Paste</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="sec-clipboard-copy.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 17. The Clipboard</th> <td width="20%" align="right"> <a accesskey="n" href="sec-clipboard-examples.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" title="Paste"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-clipboard-paste"></a>Paste</h2></div></div></div> <p> When the user asks to paste data from the <code class="classname">Clipboard</code>, you should request a specific format and provide a callback method which will be called with the actual data. For instance: </p> <pre class="programlisting">refClipboard->request_contents("example_custom_target", sigc::mem_fun(*this, &ExampleWindow::on_clipboard_received) );</pre> <p>Here is an example callback method: </p> <pre class="programlisting">void ExampleWindow::on_clipboard_received( const Gtk::SelectionData& selection_data) { Glib::ustring clipboard_data = selection_data.get_data_as_string(); //Do something with the pasted data. }</pre> <div class="sect2" title="Discovering the available targets"> <div class="titlepage"><div><div><h3 class="title"> <a name="dnd-discovering-targets"></a>Discovering the available targets</h3></div></div></div> <p> To find out what targets are currently available on the <code class="classname">Clipboard</code> for pasting, call the <code class="methodname">request_targets()</code> method, specifying a method to be called with the information. For instance: </p> <pre class="programlisting">refClipboard->request_targets( sigc::mem_fun(*this, &ExampleWindow::on_clipboard_received_targets) );</pre> <p> In your callback, compare the list of available targets with those that your application supports for pasting. You could enable or disable a Paste menu item, depending on whether pasting is currently possible. For instance: </p> <pre class="programlisting">void ExampleWindow::on_clipboard_received_targets( const Glib::StringArrayHandle& targets_array) { // Get the list of available clipboard targets: std::list<std::string> targets = targets_array; const bool bPasteIsPossible = std::find(targets.begin(), targets.end(), example_target_custom) != targets.end(); // Enable/Disable the Paste button appropriately: m_Button_Paste.set_sensitive(bPasteIsPossible); }</pre> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="sec-clipboard-copy.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-clipboard.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="sec-clipboard-examples.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Copy </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"> Examples</td> </tr> </table> </div> </body> </html>