From e5d6aa2208e2cede142bd2cf703a75cbdff5df92 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 21 Oct 1999 16:53:38 +0000 Subject: [PATCH] A bit more or multi-format clipboard. 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 | 4 ++ include/wx/gtk/dataobj2.h | 2 - include/wx/gtk1/dataform.h | 4 ++ include/wx/gtk1/dataobj2.h | 2 - src/gtk/clipbrd.cpp | 94 ++++++++------------------------------ src/gtk1/clipbrd.cpp | 94 ++++++++------------------------------ 6 files changed, 46 insertions(+), 154 deletions(-) diff --git a/include/wx/gtk/dataform.h b/include/wx/gtk/dataform.h index a0618e01af..9da24dd257 100644 --- a/include/wx/gtk/dataform.h +++ b/include/wx/gtk/dataform.h @@ -32,6 +32,10 @@ public: { 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 diff --git a/include/wx/gtk/dataobj2.h b/include/wx/gtk/dataobj2.h index 9751638eb9..fee8e27832 100644 --- a/include/wx/gtk/dataobj2.h +++ b/include/wx/gtk/dataobj2.h @@ -32,8 +32,6 @@ public: // 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 // ---------------------------------- diff --git a/include/wx/gtk1/dataform.h b/include/wx/gtk1/dataform.h index a0618e01af..9da24dd257 100644 --- a/include/wx/gtk1/dataform.h +++ b/include/wx/gtk1/dataform.h @@ -32,6 +32,10 @@ public: { 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 diff --git a/include/wx/gtk1/dataobj2.h b/include/wx/gtk1/dataobj2.h index 9751638eb9..fee8e27832 100644 --- a/include/wx/gtk1/dataobj2.h +++ b/include/wx/gtk1/dataobj2.h @@ -32,8 +32,6 @@ public: // 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 // ---------------------------------- diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index b9f2472822..dc455e90c5 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -102,11 +102,9 @@ targets_selection_received( GtkWidget *WXUNUSED(widget), for (unsigned int i=0; ilength/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; @@ -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 */ - - 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; @@ -276,6 +227,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data if (!data->IsSupportedFormat( format )) return; + /* this will fail for composite formats */ if (format.GetType() == wxDF_TEXT) { wxTextDataObject *text_object = (wxTextDataObject*) data; @@ -298,22 +250,6 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data 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; @@ -551,8 +487,10 @@ bool wxClipboard::IsOpened() const 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") ); @@ -591,15 +529,19 @@ bool wxClipboard::GetData( wxDataObject& data ) 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 ? */ - 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 */ - m_targetRequested = array[i]; + m_targetRequested = format; wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); @@ -617,6 +559,8 @@ bool wxClipboard::GetData( wxDataObject& data ) 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, diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index b9f2472822..dc455e90c5 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -102,11 +102,9 @@ targets_selection_received( GtkWidget *WXUNUSED(widget), for (unsigned int i=0; ilength/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; @@ -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 */ - - 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; @@ -276,6 +227,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data if (!data->IsSupportedFormat( format )) return; + /* this will fail for composite formats */ if (format.GetType() == wxDF_TEXT) { wxTextDataObject *text_object = (wxTextDataObject*) data; @@ -298,22 +250,6 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data 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; @@ -551,8 +487,10 @@ bool wxClipboard::IsOpened() const 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") ); @@ -591,15 +529,19 @@ bool wxClipboard::GetData( wxDataObject& data ) 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 ? */ - 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 */ - m_targetRequested = array[i]; + m_targetRequested = format; wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); @@ -617,6 +559,8 @@ bool wxClipboard::GetData( wxDataObject& data ) 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, -- 2.45.2