- /* store requested format to be asked for by callbacks */
- m_targetRequested = format;
-
- wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
-
- /* start query */
- m_formatSupported = FALSE;
-
- /* ask for clipboard contents. this will set
- m_formatSupported to TRUE if m_targetRequested
- is supported.
- also, we have to wait for the "answer" from the
- clipboard owner which is an asynchronous process.
- therefore we set m_waiting = TRUE here and wait
- until the callback "targets_selection_received"
- sets it to FALSE */
-
- m_waiting = TRUE;
-
- wxLogTrace( TRACE_CLIPBOARD,
- wxT("wxClipboard::GetData: format found, start convert") );
-
- gtk_selection_convert( m_clipboardWidget,
- m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
- : g_clipboardAtom,
- m_targetRequested,
- (guint32) GDK_CURRENT_TIME );
-
- while (m_waiting) gtk_main_iteration();
-
- /* this is a true error as we checked for the presence of such data before */
- wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
+ {
+ wxClipboardSync sync(*this);
+
+ gtk_selection_convert(m_clipboardWidget,
+ GTKGetClipboardAtom(),
+ format,
+ (guint32) GDK_CURRENT_TIME );
+ } // wait until we get the results
+
+ /*
+ Normally this is a true error as we checked for the presence of such
+ data before, but there are applications that may return an empty
+ string (e.g. Gnumeric-1.6.1 on Linux if an empty cell is copied)
+ which would produce a false error message here, so we check for the
+ size of the string first. With ANSI, GetDataSize returns an extra
+ value (for the closing null?), with unicode, the exact number of
+ tokens is given (that is more than 1 for non-ASCII characters)
+ (tested with Gnumeric-1.6.1 and OpenOffice.org-2.0.2)
+ */
+#if wxUSE_UNICODE
+ if ( format != wxDF_UNICODETEXT || data.GetDataSize(format) > 0 )
+#else // !UNICODE
+ if ( format != wxDF_TEXT || data.GetDataSize(format) > 1 )
+#endif // UNICODE / !UNICODE
+ {
+ wxCHECK_MSG( m_formatSupported, false,
+ wxT("error retrieving data from clipboard") );
+ }