lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: [lmi] Where's 'wxDataFormat("Link")' implemented?


From: Vadim Zeitlin
Subject: Re[2]: [lmi] Where's 'wxDataFormat("Link")' implemented?
Date: Mon, 25 Feb 2008 17:55:40 +0100

On Mon, 25 Feb 2008 16:38:37 +0000 Greg Chicares <address@hidden> wrote:

GC> Now I've got this, and I'm wondering if it can be simplified further:
GC> 
GC> /// Return whatever plain text the clipboard contains, or an empty
GC> /// string if it contains none.
GC> ///
GC> /// Throw an exception if the clipboard cannot be locked.
GC> 
GC> std::string ClipboardEx::GetText()
GC> {
GC>     wxClipboardLocker lock;
GC>     if(!lock)
GC>         {
GC>         fatal_error() << "Unable to lock clipboard." << LMI_FLUSH;
GC>         }
GC> 
GC>     if(!wxTheClipboard->IsSupported(wxDF_TEXT))
GC>         {
GC>         return std::string();
GC>         }
GC> 
GC>     wxTextDataObject z;
GC>     wxTheClipboard->GetData(z);
GC>     return std::string(z.GetText());
GC> }
GC> 
GC> Is it safe to remove the special case
GC>     if(!wxTheClipboard->IsSupported(wxDF_TEXT)) [...return early]
GC> and rely on the last three lines to return an empty string if
GC> there's no wxDF_TEXT on the clipboard, without even bothering to
GC> check the return code of GetData()?

 This should currently work (under all platforms) and while I'm not
completely sure if this is by design or by accident, I think the code above
should work in any case because:

a) using IsSupported() doesn't guarantee that the data in this format is
   still available by the time GetData() is called anyhow so GetData()
   should be prepared to deal with this case

b) it seems logical to either not modify the wxDataObject passed to it at
   all if data is not available (as it does now) or maybe reset it but it
   doesn't matter in this case

c) wxTextDataObject contains an empty string initially and, again, while
   this is not strictly documented it really the only thing that makes
   sense

 So yes, it should be safe to just call GetData() directly.

 Regards,
VZ





reply via email to

[Prev in Thread] Current Thread [Next in Thread]