Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 130

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<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.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="chapter-clipboard.html" title="Chapter 17. 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 17. 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" title="Copy">
<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 repsonse to a paste.
</p>
<p>For instance,
</p>
<pre class="programlisting">Glib::RefPtr&lt;Gtk::Clipboard&gt; refClipboard = Gtk::Clipboard::get();

//Targets:
std::list&lt;Gtk::TargetEntry&gt; listTargets;
listTargets.push_back( Gtk::TargetEntry("example_custom_target") );
listTargets.push_back( Gtk::TargetEntry("UTF8_STRING") );

refClipboard-&gt;set( listTargets,
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_get),
    sigc::mem_fun(*this, &amp;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&amp; 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="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 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>