]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/clipbrd.cpp
Added Unix implementation of platform specific files for OS/2.
[wxWidgets.git] / src / motif / clipbrd.cpp
index 17f2e17e277dd7fbfc5a3d3d6d776635ec2b9f2c..6d13b5b35cffa26bcaa8a7f4f37c1041b5785b3a 100644 (file)
@@ -9,11 +9,20 @@
 // Licence:    wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation
 #pragma implementation "clipbrd.h"
 #endif
 
+#ifdef __VMS
+#include "wx/vms_x_fix.h"
+#define XtWindow XTWINDOW
+#define XtScreen XTSCREEN
+#define XtParent XTPARENT
+#define XtIsRealized XTISREALIZED
+#define XtDisplay XTDISPLAY
+#endif
+
 #include "wx/defs.h"
 
 #if wxUSE_CLIPBOARD
 #include "wx/dataobj.h"
 #include "wx/ptr_scpd.h"
 
-#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxDataObjectList);
-
 #ifdef __VMS__
 #pragma message disable nosimpint
+
 #endif
 #include <Xm/Xm.h>
 #include <Xm/CutPaste.h>
@@ -151,6 +158,29 @@ bool wxGetClipboardFormatName(wxDataFormat dataFormat, char *formatName,
 // wxClipboard
 //-----------------------------------------------------------------------------
 
+struct wxDataIdToDataObject
+{
+    wxDataIdToDataObject( wxDataObject* o, long d, size_t s )
+        : object( o ), size( s ), dataId( d ) { }
+
+    wxDataObject* object;
+    size_t        size;
+    long          dataId;
+};
+
+#include "wx/listimpl.cpp"
+
+WX_DEFINE_LIST(wxDataObjectList);
+WX_DEFINE_LIST(wxDataIdToDataObjectList);
+
+#if wxCHECK_LESSTIF()
+static void wxClipboardCallback( Widget widget, int* data_id,
+                                 int* priv, int* reason );
+#else
+static void wxClipboardCallback( Widget widget, long* data_id,
+                                 long* priv, int* reason );
+#endif
+
 IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
 
 wxClipboard::wxClipboard()
@@ -165,14 +195,18 @@ wxClipboard::~wxClipboard()
 
 void wxClipboard::Clear()
 {
-    wxDataObjectList::Node* node = m_data.GetFirst();
+    wxDataObjectList::compatibility_iterator node = m_data.GetFirst();
     while (node)
     {
-        wxDataObject* data = node->GetData();
-        delete data;
+        delete node->GetData();
         node = node->GetNext();
     }
     m_data.Clear();
+
+    for( wxDataIdToDataObjectList::compatibility_iterator node2 = m_idToObject.GetFirst();
+         node2; node2 = node2->GetNext() )
+        delete node->GetData();
+    m_idToObject.Clear();
 }
 
 bool wxClipboard::Open()
@@ -197,6 +231,47 @@ bool wxClipboard::SetData( wxDataObject *data )
 wxDECLARE_SCOPED_ARRAY( wxDataFormat, wxDataFormatScopedArray );
 wxDEFINE_SCOPED_ARRAY( wxDataFormat, wxDataFormatScopedArray );
 
+#if wxCHECK_LESSTIF()
+void wxClipboardCallback( Widget xwidget, int* data_id,
+                          int* priv, int* reason )
+#else
+void wxClipboardCallback( Widget xwidget, long* data_id,
+                          long* priv, int* reason )
+#endif
+{
+    Display* xdisplay = XtDisplay( xwidget );
+    Window xwindow = XtWindow( xwidget );
+    wxDataObject* dobj = NULL;
+    size_t size = 0;
+
+    for( wxDataIdToDataObjectList::compatibility_iterator node2 =
+             wxTheClipboard->m_idToObject.GetFirst();
+         node2; node2 = node2->GetNext() )
+    {
+        wxDataIdToDataObject* dido = node2->GetData();
+        if( dido->dataId == *data_id )
+        {
+            dobj = dido->object;
+            size = dido->size;
+            break;
+        }
+    }
+
+    if( !dobj ) return;
+
+    wxCharBuffer buffer(size);
+    size_t count = dobj->GetFormatCount( wxDataObject::Get );
+    wxDataFormatScopedArray dfarr( new wxDataFormat[count] );
+    dobj->GetAllFormats( dfarr.get(), wxDataObject::Get );
+
+    if( !dobj->GetDataHere( dfarr[*priv], buffer.data() ) )
+        return;
+
+    while( XmClipboardCopyByName( xdisplay, xwindow, *data_id,
+                                  buffer.data(), size, 0 )
+           == XmClipboardLocked );
+}
+
 bool wxClipboard::AddData( wxDataObject *data )
 {
     wxCHECK_MSG( data, false, "data is invalid" );
@@ -205,7 +280,8 @@ bool wxClipboard::AddData( wxDataObject *data )
     m_data.Append( data );
 
     Display* xdisplay = wxGlobalDisplay();
-    Window xwindow = XtWindow( (Widget)wxTheApp->GetTopLevelWidget() );
+    Widget xwidget = (Widget)wxTheApp->GetTopLevelWidget();
+    Window xwindow = XtWindow( xwidget );
     wxXmString label( wxTheApp->GetAppName() );
     Time timestamp = XtLastTimestampProcessed( xdisplay );
     long itemId;
@@ -213,8 +289,8 @@ bool wxClipboard::AddData( wxDataObject *data )
     int retval;
 
     while( ( retval = XmClipboardStartCopy( xdisplay, xwindow, label(),
-                                            timestamp, (Widget)NULL,
-                                            (XmCutPasteProc)NULL,
+                                            timestamp, xwidget,
+                                            wxClipboardCallback,
                                             &itemId ) )
            == XmClipboardLocked );
     if( retval != XmClipboardSuccess )
@@ -227,17 +303,15 @@ bool wxClipboard::AddData( wxDataObject *data )
     for( size_t i = 0; i < count; ++i )
     {
         size_t size = data->GetDataSize( dfarr[i] );
-        wxCharBuffer buffer(size);
-
-        if( !data->GetDataHere( dfarr[i], buffer.data() ) )
-            continue;
-
+        long data_id;
         wxString id = dfarr[i].GetId();
 
         while( ( retval = XmClipboardCopy( xdisplay, xwindow, itemId,
                                            wxConstCast(id.c_str(), char),
-                                           buffer.data(), size, 0, NULL ) )
+                                           NULL, size, i, &data_id ) )
                == XmClipboardLocked );
+
+        m_idToObject.Append( new wxDataIdToDataObject( data, data_id, size ) );
     }
 
     while( XmClipboardEndCopy( xdisplay, xwindow, itemId )