// this method must be called by GTK+ callbacks to indicate that we got the
// result for our clipboard operation
- static void OnDone(wxClipboard *clipboard)
+ static void OnDone(wxClipboard * WXUNUSED_UNLESS_DEBUG(clipboard))
{
wxASSERT_MSG( clipboard == ms_clipboard,
_T("got notification for alien clipboard") );
ms_clipboard = NULL;
}
+ // this method should be called if it's possible that no async clipboard
+ // operation is currently in progress (like it can be the case when the
+ // clipboard is cleared but not because we asked about it), it should only
+ // be called if such situation is expected -- otherwise call OnDone() which
+ // would assert in this case
+ static void OnDoneIfInProgress(wxClipboard *clipboard)
+ {
+ if ( ms_clipboard )
+ OnDone(clipboard);
+ }
+
private:
static wxClipboard *ms_clipboard;
if ( !clipboard )
return TRUE;
- wxON_BLOCK_EXIT1(wxClipboardSync::OnDone, clipboard);
+ // notice the use of OnDoneIfInProgress() here instead of just OnDone():
+ // it's perfectly possible that we're receiving this notification from GTK+
+ // even though we hadn't cleared the clipboard ourselves but because
+ // another application (or even another window in the same program)
+ // acquired it
+ wxON_BLOCK_EXIT1(wxClipboardSync::OnDoneIfInProgress, clipboard);
wxClipboard::Kind kind;
if (event->selection == GDK_SELECTION_PRIMARY)
if (size == 0) return;
- void *d = malloc(size);
- wxON_BLOCK_EXIT1(free, d);
+ wxCharBuffer buf(size);
- // Text data will be in UTF8 in Unicode mode.
- data->GetDataHere( selection_data->target, d );
+ // text data must be returned in UTF8 if format is wxDF_UNICODETEXT
+ data->GetDataHere( format, buf.data() );
- // NB: GTK+ requires special treatment of UTF8_STRING data, the text
- // would show as UTF-8 data interpreted as latin1 (?) in other
- // GTK+ apps if we used gtk_selection_data_set()
+ // use UTF8_STRING format if requested in Unicode build but just plain
+ // STRING one in ANSI or if explicitly asked in Unicode
+#if wxUSE_UNICODE
if (format == wxDataFormat(wxDF_UNICODETEXT))
{
gtk_selection_data_set_text(
selection_data,
- (const gchar*)d,
+ (const gchar*)buf.data(),
size );
}
else
+#endif
{
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
- (unsigned char*) d,
+ (const guchar*)buf.data(),
size );
}
}
{
Clear();
- if ( m_clipboardWidget )
- gtk_widget_destroy( m_clipboardWidget );
- if ( m_targetsWidget )
- gtk_widget_destroy( m_targetsWidget );
+ gtk_widget_destroy( m_clipboardWidget );
+ gtk_widget_destroy( m_targetsWidget );
}
// ----------------------------------------------------------------------------
void wxClipboard::GTKClearData(Kind kind)
{
- wxDataObject *&data = Data();
+ wxDataObject *&data = Data(kind);
if ( data )
{
delete data;
{
gtk_selection_add_target
(
- GTK_WIDGET(m_clipboardWidget),
+ m_clipboardWidget,
GTKGetClipboardAtom(),
atom,
0 // info (same as client data) unused