From be809e82f229a2acc44636403ddac88e16f0ac9d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 11 Jan 2007 01:34:08 +0000 Subject: [PATCH] suppress spurious error message when copying from clipboard brought empty string (patch 1630108) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44193 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/clipbrd.cpp | 21 +++++++++++++++++++-- src/gtk1/clipbrd.cpp | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 903cd48b71..0067d971bc 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -630,8 +630,25 @@ bool wxClipboard::GetData( wxDataObject& data ) 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") ); + /* + 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. In 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 special 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") ); + } /* return success */ delete[] array; diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 7f02601153..fc8309b47b 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -619,8 +619,25 @@ bool wxClipboard::GetData( wxDataObject& data ) 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") ); + /* + 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. In 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 special 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") ); + } /* return success */ delete[] array; -- 2.47.2