<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Copy</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2"> <link rel="start" href="index.html" title="Programming with gtkmm"> <link rel="up" href="ch17.html" title="Chapter 17. The Clipboard"> <link rel="prev" href="ch17.html" title="Chapter 17. The Clipboard"> <link rel="next" href="ch17s03.html" title="Paste"> </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">Copy</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="ch17.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="ch17s03.html"><img src="../icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" lang="en"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-drag_and_drop_copy"></a>Copy</h2></div></div></div> <p> When the user asks to copy some data, you should tell the <code class="classname">Clipboard</code> what targets are available, and provide the callback methods that it can use to get the data. At this point you should store a copy of the data, to be provided when the clipboard calls your callback method in repsonse to a paste. </p> <p>For instance, </p> <pre class="programlisting">Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get(); //Targets: std::list<Gtk::TargetEntry> listTargets; listTargets.push_back( Gtk::TargetEntry("example_custom_target") ); listTargets.push_back( Gtk::TargetEntry("UTF8_STRING") ); refClipboard->set( listTargets, sigc::mem_fun(*this, &ExampleWindow::on_clipboard_get), sigc::mem_fun(*this, &ExampleWindow::on_clipboard_clear) );</pre> <p>Your callback will then provide the store data when the user chooses to paste the data. For instance: </p> <pre class="programlisting">void ExampleWindow::on_clipboard_get( Gtk::SelectionData& selection_data, guint info) { const Glib::ustring target = selection_data.get_target(); if(target == "example_custom_target") selection_data.set("example_custom_target", m_ClipboardStore); }</pre> <p> The <code class="literal">ideal</code> example below can supply more than one clipboard target. </p> <p>The clear callback allows you to free the memory used by your stored data when the clipboard replaces its data with something else. </p> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="ch17.html"><img src="../icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="ch17.html"><img src="../icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="ch17s03.html"><img src="../icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Chapter 17. The Clipboard </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"> Paste</td> </tr> </table> </div> </body> </html>