bool wxClipboard::IsSupported(const wxDataFormat& format) { Display* xdisplay = wxGlobalDisplay(); Window xwindow = XtWindow( (Widget)wxTheApp->GetTopLevelRealizedWidget() ); bool isSupported = false; int retval, count; unsigned long max_name_length; wxString id = format.GetId(); while( ( retval = XmClipboardLock( xdisplay, xwindow ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length ) == XmClipboardSuccess ) { wxCharBuffer buf( max_name_length + 1 ); unsigned long copied; for( int i = 0; i < count; ++i ) { if( XmClipboardInquireFormat( xdisplay, xwindow, i + 1, (XtPointer)buf.data(), max_name_length, &copied ) != XmClipboardSuccess ) continue; buf.data()[copied] = '\0'; if( buf == id ) { isSupported = true; break; } } } XmClipboardUnlock( xdisplay, xwindow, False ); return isSupported; }
static int motClipboardIsAvailable(const char* format_name) { Window window = motClipboardGetWindow(); int count, i; unsigned long max_length, length; char* str; /* number of targets that exists on the clipboard */ if (XmClipboardInquireCount(iupmot_display, window, &count, &max_length) != ClipboardSuccess) return 0; str = iupStrGetMemory(max_length+1); for (i = 1; i<=count; i++) { if (XmClipboardInquireFormat(iupmot_display, window, i, str, max_length+1, &length)==ClipboardSuccess) { if (iupStrEqualNoCase(str, format_name)) return 1; } } return 0; }
bool wxClipboard::GetData( wxDataObject& data ) { wxCHECK_MSG( m_open, false, "clipboard not open" ); Display* xdisplay = wxGlobalDisplay(); Window xwindow = XtWindow( (Widget)wxTheApp->GetTopLevelRealizedWidget() ); Time timestamp = XtLastTimestampProcessed( xdisplay ); wxDataFormat chosenFormat; int retval; /////////////////////////////////////////////////////////////////////////// // determine if the cliboard holds any format we like /////////////////////////////////////////////////////////////////////////// while( ( retval = XmClipboardStartRetrieve( xdisplay, xwindow, timestamp ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; wxClipboardEndRetrieve endRetrieve( xdisplay, xwindow ); int count; unsigned long max_name_length; size_t dfcount = data.GetFormatCount( wxDataObject::Set ); wxDataFormatScopedArray dfarr(dfcount); data.GetAllFormats( dfarr.get(), wxDataObject::Set ); if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length ) == XmClipboardSuccess ) { wxCharBuffer buf( max_name_length + 1 ); unsigned long copied; for( int i = 0; i < count; ++i ) { if( XmClipboardInquireFormat( xdisplay, xwindow, i + 1, (XtPointer)buf.data(), max_name_length, &copied ) != XmClipboardSuccess ) continue; buf.data()[copied] = '\0'; // try preferred format if( buf == data.GetPreferredFormat( wxDataObject::Set ).GetId() ) { chosenFormat = data.GetPreferredFormat( wxDataObject::Set ); break; } // try all other formats for( size_t i = 0; i < dfcount; ++i ) { if( buf == dfarr[i].GetId() ) chosenFormat = dfarr[i]; } } } if( chosenFormat == wxDF_INVALID ) return false; /////////////////////////////////////////////////////////////////////////// // now retrieve the data /////////////////////////////////////////////////////////////////////////// unsigned long length, dummy1; long dummy2; wxString id = chosenFormat.GetId(); while( ( retval = XmClipboardInquireLength( xdisplay, xwindow, id.char_str(), &length ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; wxCharBuffer buf(length); while( ( retval = XmClipboardRetrieve( xdisplay, xwindow, id.char_str(), (XtPointer)buf.data(), length, &dummy1, &dummy2 ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; if( !data.SetData( chosenFormat, length, buf.data() ) ) return false; return true; }