+public:
+ wxClipboardEndRetrieve( Display* display, Window window )
+ : m_display( display ), m_window( window ) { }
+ ~wxClipboardEndRetrieve()
+ {
+ while( XmClipboardEndRetrieve( m_display, m_window )
+ == XmClipboardLocked );
+ }
+private:
+ Display* m_display;
+ Window m_window;
+};
+
+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( 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];
+ }
+ }
+ }