- if (clipOwner) {
- if (clipOwner->formats.Member(format))
- return clipOwner->GetData(format, length);
- else
- return NULL;
- } else if (cbString) {
- if (!strcmp(format, "TEXT("))
- return copystring(cbString);
- else
- return NULL;
- } else {
- if (wxOpenClipboard()) {
- receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
- length);
- wxCloseClipboard();
- } else
- receivedString = NULL;
-
- return receivedString;
+ 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( new wxDataFormat[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];
+ }
+ }