[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Where's 'wxDataFormat("Link")' implemented?
From: |
Greg Chicares |
Subject: |
Re: [lmi] Where's 'wxDataFormat("Link")' implemented? |
Date: |
Mon, 25 Feb 2008 16:38:37 +0000 |
User-agent: |
Thunderbird 2.0.0.9 (Windows/20071031) |
On 2008-02-25 04:06Z, Greg Chicares wrote:
[...consolidating and simplifying lmi clipboard code, and in
particular making it ignore any data format other than wxDF_TEXT]
> Changed 20080224T1711Z.
Now I've got this, and I'm wondering if it can be simplified further:
/// Return whatever plain text the clipboard contains, or an empty
/// string if it contains none.
///
/// Throw an exception if the clipboard cannot be locked.
std::string ClipboardEx::GetText()
{
wxClipboardLocker lock;
if(!lock)
{
fatal_error() << "Unable to lock clipboard." << LMI_FLUSH;
}
if(!wxTheClipboard->IsSupported(wxDF_TEXT))
{
return std::string();
}
wxTextDataObject z;
wxTheClipboard->GetData(z);
return std::string(z.GetText());
}
Is it safe to remove the special case
if(!wxTheClipboard->IsSupported(wxDF_TEXT)) [...return early]
and rely on the last three lines to return an empty string if
there's no wxDF_TEXT on the clipboard, without even bothering to
check the return code of GetData()? That simplification seems
to work fine with msw, but I thought I'd better ask first for
fear of undefined behavior in some case on some platform.
(I explicitly construct a std::string on the last line in order
to avoid any potential problem with automatic conversion from
wxString.)