]> git.saurik.com Git - wxWidgets.git/commitdiff
A bit more or multi-format clipboard.
authorRobert Roebling <robert@roebling.de>
Thu, 21 Oct 1999 16:53:38 +0000 (16:53 +0000)
committerRobert Roebling <robert@roebling.de>
Thu, 21 Oct 1999 16:53:38 +0000 (16:53 +0000)
  Added == operator to wxDataFormat for standard types (again).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/dataform.h
include/wx/gtk/dataobj2.h
include/wx/gtk1/dataform.h
include/wx/gtk1/dataobj2.h
src/gtk/clipbrd.cpp
src/gtk1/clipbrd.cpp

index a0618e01af5761bb53481c6d630e325d6652fe8e..9da24dd2577100c6bf83eeb9266a2006e1322035 100644 (file)
@@ -32,6 +32,10 @@ public:
         { return m_format == (NativeFormat)format; }
     bool operator!=(NativeFormat format) const
         { return m_format != (NativeFormat)format; }
         { return m_format == (NativeFormat)format; }
     bool operator!=(NativeFormat format) const
         { return m_format != (NativeFormat)format; }
+    bool operator==(wxDataFormatId format) const
+        { return m_type == (wxDataFormatId)format; }
+    bool operator!=(wxDataFormatId format) const
+        { return m_type != (wxDataFormatId)format; }
 
     // explicit and implicit conversions to NativeFormat which is one of
     // standard data types (implicit conversion is useful for preserving the
 
     // explicit and implicit conversions to NativeFormat which is one of
     // standard data types (implicit conversion is useful for preserving the
index 9751638eb9e6c79387fabf4a6e38d1590b5b5586..fee8e27832848a3df3a709adb41e8e1abf022c17 100644 (file)
@@ -32,8 +32,6 @@ public:
     // override base class virtual to update PNG data too
     virtual void SetBitmap(const wxBitmap& bitmap);
 
     // override base class virtual to update PNG data too
     virtual void SetBitmap(const wxBitmap& bitmap);
 
-    void *GetPngData() const { return m_pngData; }
-
     // implement base class pure virtuals
     // ----------------------------------
 
     // implement base class pure virtuals
     // ----------------------------------
 
index a0618e01af5761bb53481c6d630e325d6652fe8e..9da24dd2577100c6bf83eeb9266a2006e1322035 100644 (file)
@@ -32,6 +32,10 @@ public:
         { return m_format == (NativeFormat)format; }
     bool operator!=(NativeFormat format) const
         { return m_format != (NativeFormat)format; }
         { return m_format == (NativeFormat)format; }
     bool operator!=(NativeFormat format) const
         { return m_format != (NativeFormat)format; }
+    bool operator==(wxDataFormatId format) const
+        { return m_type == (wxDataFormatId)format; }
+    bool operator!=(wxDataFormatId format) const
+        { return m_type != (wxDataFormatId)format; }
 
     // explicit and implicit conversions to NativeFormat which is one of
     // standard data types (implicit conversion is useful for preserving the
 
     // explicit and implicit conversions to NativeFormat which is one of
     // standard data types (implicit conversion is useful for preserving the
index 9751638eb9e6c79387fabf4a6e38d1590b5b5586..fee8e27832848a3df3a709adb41e8e1abf022c17 100644 (file)
@@ -32,8 +32,6 @@ public:
     // override base class virtual to update PNG data too
     virtual void SetBitmap(const wxBitmap& bitmap);
 
     // override base class virtual to update PNG data too
     virtual void SetBitmap(const wxBitmap& bitmap);
 
-    void *GetPngData() const { return m_pngData; }
-
     // implement base class pure virtuals
     // ----------------------------------
 
     // implement base class pure virtuals
     // ----------------------------------
 
index b9f24728221167d079f6ca724b21fc4f74f5611a..dc455e90c510afa1d0bcd0ffcceed8b304a82a0e 100644 (file)
@@ -102,11 +102,9 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
 
     for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
     {
 
     for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
     {
-/*
-        char *name = gdk_atom_name (atoms[i]);
-        if (name) printf( "Format available: %s.\n", name ); */
+        wxDataFormat format( atoms[i] );
       
       
-        if (atoms[i] == clipboard->m_targetRequested)
+        if (format == clipboard->m_targetRequested)
         {
             clipboard->m_waiting = FALSE;
             clipboard->m_formatSupported = TRUE;
         {
             clipboard->m_waiting = FALSE;
             clipboard->m_formatSupported = TRUE;
@@ -161,60 +159,13 @@ selection_received( GtkWidget *WXUNUSED(widget),
 
     /* make sure we got the data in the correct form (selection type).
        if so, copy data to target object */
 
     /* make sure we got the data in the correct form (selection type).
        if so, copy data to target object */
-    
-    switch (format.GetType())
+    if (selection_data->type != GDK_SELECTION_TYPE_STRING)
     {
     {
-        case wxDF_TEXT:
-       {
-            if (selection_data->type != GDK_SELECTION_TYPE_STRING)
-            {
-                clipboard->m_waiting = FALSE;
-                return;
-            }
-           
-           wxTextDataObject *text_object = (wxTextDataObject *) data_object;
-           
-           wxString text = (const char*) selection_data->data;
-           
-           text_object->SetText( text );
-           
-           break;
-       }
-       
-       case wxDF_BITMAP:
-       {
-            if (selection_data->type != GDK_SELECTION_TYPE_STRING)
-            {
-                clipboard->m_waiting = FALSE;
-                return;
-            }
-           
-           wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
-           
-           bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data );
-           
-           break;
-       }
-       
-       case wxDF_PRIVATE:
-       {
-            if (selection_data->type != GDK_SELECTION_TYPE_STRING)
-            {
-                clipboard->m_waiting = FALSE;
-                return;
-            }
-           
-           data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
-           
-           break;
-       }
-       
-       default:
-       {
-            clipboard->m_waiting = FALSE;
-           return;
-       }
+        clipboard->m_waiting = FALSE;
+        return;
     }
     }
+           
+    data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
     
     wxTheClipboard->m_formatSupported = TRUE;
     clipboard->m_waiting = FALSE;
     
     wxTheClipboard->m_formatSupported = TRUE;
     clipboard->m_waiting = FALSE;
@@ -276,6 +227,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
 
     if (!data->IsSupportedFormat( format )) return;
   
 
     if (!data->IsSupportedFormat( format )) return;
   
+    /* this will fail for composite formats */
     if (format.GetType() == wxDF_TEXT)
     {
        wxTextDataObject *text_object = (wxTextDataObject*) data;
     if (format.GetType() == wxDF_TEXT)
     {
        wxTextDataObject *text_object = (wxTextDataObject*) data;
@@ -298,22 +250,6 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
        return;
     }
 
        return;
     }
 
-    if (format.GetType() == wxDF_BITMAP)
-    {
-       wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
-           
-       if (bitmap_object->GetDataSize() == 0) return;
-           
-        gtk_selection_data_set( 
-            selection_data, 
-           GDK_SELECTION_TYPE_STRING, 
-           8*sizeof(gchar), 
-           (unsigned char*) bitmap_object->GetPngData(), 
-           (int) bitmap_object->GetDataSize() );
-           
-       return;
-    }
-
     int size = data->GetDataSize( format );
     
     if (size == 0) return;
     int size = data->GetDataSize( format );
     
     if (size == 0) return;
@@ -551,8 +487,10 @@ bool wxClipboard::IsOpened() const
 
 bool wxClipboard::IsSupported( const wxDataFormat& format )
 {
 
 bool wxClipboard::IsSupported( const wxDataFormat& format )
 {
-    /* store requested format to be asked for by callbacks */
+    /* reentrance problems */
+    if (m_open) return TRUE;
     
     
+    /* store requested format to be asked for by callbacks */
     m_targetRequested = format;
   
     wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
     m_targetRequested = format;
   
     wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
@@ -591,15 +529,19 @@ bool wxClipboard::GetData( wxDataObject& data )
     
     for (size_t i = 0; i < data.GetFormatCount(); i++)
     {
     
     for (size_t i = 0; i < data.GetFormatCount(); i++)
     {
+        wxDataFormat format( array[i] );
+    
+        wxLogDebug( wxT("wxClipboard::GetData: request format %s"), format.GetId().c_str() );
+    
         /* is data supported by clipboard ? */
         /* is data supported by clipboard ? */
-        if (!IsSupported( array[i] ))
+        if (!IsSupported( format ))
           continue;
     
         /* store pointer to data object to be filled up by callbacks */
         m_receivedData = &data;
     
         /* store requested format to be asked for by callbacks */
           continue;
     
         /* store pointer to data object to be filled up by callbacks */
         m_receivedData = &data;
     
         /* store requested format to be asked for by callbacks */
-        m_targetRequested = array[i];
+        m_targetRequested = format;
   
         wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
     
   
         wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
     
@@ -617,6 +559,8 @@ bool wxClipboard::GetData( wxDataObject& data )
 
         m_waiting = TRUE;
 
 
         m_waiting = TRUE;
 
+        wxLogDebug( wxT("wxClipboard::GetData: format found, start convert") );
+    
         gtk_selection_convert( m_clipboardWidget,
                           m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, 
                           m_targetRequested,
         gtk_selection_convert( m_clipboardWidget,
                           m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, 
                           m_targetRequested,
index b9f24728221167d079f6ca724b21fc4f74f5611a..dc455e90c510afa1d0bcd0ffcceed8b304a82a0e 100644 (file)
@@ -102,11 +102,9 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
 
     for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
     {
 
     for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
     {
-/*
-        char *name = gdk_atom_name (atoms[i]);
-        if (name) printf( "Format available: %s.\n", name ); */
+        wxDataFormat format( atoms[i] );
       
       
-        if (atoms[i] == clipboard->m_targetRequested)
+        if (format == clipboard->m_targetRequested)
         {
             clipboard->m_waiting = FALSE;
             clipboard->m_formatSupported = TRUE;
         {
             clipboard->m_waiting = FALSE;
             clipboard->m_formatSupported = TRUE;
@@ -161,60 +159,13 @@ selection_received( GtkWidget *WXUNUSED(widget),
 
     /* make sure we got the data in the correct form (selection type).
        if so, copy data to target object */
 
     /* make sure we got the data in the correct form (selection type).
        if so, copy data to target object */
-    
-    switch (format.GetType())
+    if (selection_data->type != GDK_SELECTION_TYPE_STRING)
     {
     {
-        case wxDF_TEXT:
-       {
-            if (selection_data->type != GDK_SELECTION_TYPE_STRING)
-            {
-                clipboard->m_waiting = FALSE;
-                return;
-            }
-           
-           wxTextDataObject *text_object = (wxTextDataObject *) data_object;
-           
-           wxString text = (const char*) selection_data->data;
-           
-           text_object->SetText( text );
-           
-           break;
-       }
-       
-       case wxDF_BITMAP:
-       {
-            if (selection_data->type != GDK_SELECTION_TYPE_STRING)
-            {
-                clipboard->m_waiting = FALSE;
-                return;
-            }
-           
-           wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
-           
-           bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data );
-           
-           break;
-       }
-       
-       case wxDF_PRIVATE:
-       {
-            if (selection_data->type != GDK_SELECTION_TYPE_STRING)
-            {
-                clipboard->m_waiting = FALSE;
-                return;
-            }
-           
-           data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
-           
-           break;
-       }
-       
-       default:
-       {
-            clipboard->m_waiting = FALSE;
-           return;
-       }
+        clipboard->m_waiting = FALSE;
+        return;
     }
     }
+           
+    data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
     
     wxTheClipboard->m_formatSupported = TRUE;
     clipboard->m_waiting = FALSE;
     
     wxTheClipboard->m_formatSupported = TRUE;
     clipboard->m_waiting = FALSE;
@@ -276,6 +227,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
 
     if (!data->IsSupportedFormat( format )) return;
   
 
     if (!data->IsSupportedFormat( format )) return;
   
+    /* this will fail for composite formats */
     if (format.GetType() == wxDF_TEXT)
     {
        wxTextDataObject *text_object = (wxTextDataObject*) data;
     if (format.GetType() == wxDF_TEXT)
     {
        wxTextDataObject *text_object = (wxTextDataObject*) data;
@@ -298,22 +250,6 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
        return;
     }
 
        return;
     }
 
-    if (format.GetType() == wxDF_BITMAP)
-    {
-       wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
-           
-       if (bitmap_object->GetDataSize() == 0) return;
-           
-        gtk_selection_data_set( 
-            selection_data, 
-           GDK_SELECTION_TYPE_STRING, 
-           8*sizeof(gchar), 
-           (unsigned char*) bitmap_object->GetPngData(), 
-           (int) bitmap_object->GetDataSize() );
-           
-       return;
-    }
-
     int size = data->GetDataSize( format );
     
     if (size == 0) return;
     int size = data->GetDataSize( format );
     
     if (size == 0) return;
@@ -551,8 +487,10 @@ bool wxClipboard::IsOpened() const
 
 bool wxClipboard::IsSupported( const wxDataFormat& format )
 {
 
 bool wxClipboard::IsSupported( const wxDataFormat& format )
 {
-    /* store requested format to be asked for by callbacks */
+    /* reentrance problems */
+    if (m_open) return TRUE;
     
     
+    /* store requested format to be asked for by callbacks */
     m_targetRequested = format;
   
     wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
     m_targetRequested = format;
   
     wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
@@ -591,15 +529,19 @@ bool wxClipboard::GetData( wxDataObject& data )
     
     for (size_t i = 0; i < data.GetFormatCount(); i++)
     {
     
     for (size_t i = 0; i < data.GetFormatCount(); i++)
     {
+        wxDataFormat format( array[i] );
+    
+        wxLogDebug( wxT("wxClipboard::GetData: request format %s"), format.GetId().c_str() );
+    
         /* is data supported by clipboard ? */
         /* is data supported by clipboard ? */
-        if (!IsSupported( array[i] ))
+        if (!IsSupported( format ))
           continue;
     
         /* store pointer to data object to be filled up by callbacks */
         m_receivedData = &data;
     
         /* store requested format to be asked for by callbacks */
           continue;
     
         /* store pointer to data object to be filled up by callbacks */
         m_receivedData = &data;
     
         /* store requested format to be asked for by callbacks */
-        m_targetRequested = array[i];
+        m_targetRequested = format;
   
         wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
     
   
         wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
     
@@ -617,6 +559,8 @@ bool wxClipboard::GetData( wxDataObject& data )
 
         m_waiting = TRUE;
 
 
         m_waiting = TRUE;
 
+        wxLogDebug( wxT("wxClipboard::GetData: format found, start convert") );
+    
         gtk_selection_convert( m_clipboardWidget,
                           m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, 
                           m_targetRequested,
         gtk_selection_convert( m_clipboardWidget,
                           m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, 
                           m_targetRequested,