<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Copy</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> <link rel="home" href="index.html" title="Programming with gtkmm 3"> <link rel="up" href="chapter-clipboard.html" title="Chapter 19. The Clipboard"> <link rel="prev" href="chapter-clipboard.html" title="Chapter 19. The Clipboard"> <link rel="next" href="sec-clipboard-paste.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="chapter-clipboard.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 19. The Clipboard</th> <td width="20%" align="right"> <a accesskey="n" href="sec-clipboard-paste.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-clipboard-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 response to a paste. </p> <p>For instance, </p> <pre class="programlisting">Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get(); //Targets: std::vector<Gtk::TargetEntry> targets; targets.push_back( Gtk::TargetEntry("example_custom_target") ); targets.push_back( Gtk::TargetEntry("UTF8_STRING") ); refClipboard->set( targets, sigc::mem_fun(*this, &ExampleWindow::on_clipboard_get), sigc::mem_fun(*this, &ExampleWindow::on_clipboard_clear) );</pre> <p>Your callback will then provide the stored 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 std::string 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="chapter-clipboard.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-paste.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Chapter 19. 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>