Comitted GTK part of clipboard patch, that

enables non-unicode strings to be seen in
    Unicode apps. This is relevant since KDE
    apps paste non-Unicode text.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26218 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2004-03-15 22:46:48 +00:00
parent c19bd0a37a
commit c7d6d88330
8 changed files with 133 additions and 37 deletions

View File

@@ -335,21 +335,35 @@ public:
// implement base class pure virtuals // implement base class pure virtuals
// ---------------------------------- // ----------------------------------
#if wxUSE_UNICODE && defined(__WXGTK20__)
virtual size_t GetFormatCount(Direction WXUNUSED(dir) = Get) const { return 2; }
virtual void GetAllFormats(wxDataFormat *formats,
wxDataObjectBase::Direction WXUNUSED(dir) = Get) const;
virtual size_t GetDataSize() const { return GetDataSize(GetPreferredFormat()); }
virtual bool GetDataHere(void *buf) const { return GetDataHere(GetPreferredFormat(), buf); }
virtual bool SetData(size_t len, const void *buf) { return SetData(GetPreferredFormat(), len, buf); }
size_t GetDataSize(const wxDataFormat& format) const;
bool GetDataHere(const wxDataFormat& format, void *pBuf) const;
bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf);
#else
virtual size_t GetDataSize() const; virtual size_t GetDataSize() const;
virtual bool GetDataHere(void *buf) const; virtual bool GetDataHere(void *buf) const;
virtual bool SetData(size_t len, const void *buf); virtual bool SetData(size_t len, const void *buf);
private:
wxString m_text;
// virtual function hiding supression
size_t GetDataSize(const wxDataFormat& format) const size_t GetDataSize(const wxDataFormat& format) const
{ return(wxDataObjectSimple::GetDataSize(format)); } { return(wxDataObjectSimple::GetDataSize(format)); }
bool GetDataHere(const wxDataFormat& format, void *pBuf) const bool GetDataHere(const wxDataFormat& format, void *pBuf) const
{ return(wxDataObjectSimple::GetDataHere(format, pBuf)); } { return(wxDataObjectSimple::GetDataHere(format, pBuf)); }
bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf) bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf)
{ return(wxDataObjectSimple::SetData(format, nLen, pBuf)); } { return(wxDataObjectSimple::SetData(format, nLen, pBuf)); }
#endif
private:
wxString m_text;
DECLARE_NO_COPY_CLASS(wxTextDataObject) DECLARE_NO_COPY_CLASS(wxTextDataObject)
}; };

View File

@@ -237,42 +237,74 @@ bool wxDataObjectComposite::SetData(const wxDataFormat& format,
// wxTextDataObject // wxTextDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if defined(__WXGTK20__) && wxUSE_UNICODE
size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
{
if (format == wxDF_UNICODETEXT)
{
// Use UTF8 not UCS4
wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() );
return strlen( (const char*) buffer ) + 1;
}
else // == wxDF_TEXT
{
wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() );
return strlen( (const char*) buffer ) + 1;
}
}
bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{
if (format == wxDF_UNICODETEXT)
{
// Use UTF8 not UCS4
wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() );
strcpy( (char*) buf, (const char*) buffer );
}
else
{
wxCharBuffer buffer = wxConvLibc.cWX2MB( GetText().c_str() );
strcpy( (char*) buf, (const char*) buffer );
}
return TRUE;
}
bool wxTextDataObject::SetData(const wxDataFormat& format,
size_t WXUNUSED(len), const void *buf)
{
if (format == wxDF_UNICODETEXT)
SetText( wxConvUTF8.cMB2WX( (const char*) buf ) );
else
SetText( wxConvLibc.cMB2WX( (const char*) buf ) );
return TRUE;
}
#else
size_t wxTextDataObject::GetDataSize() const size_t wxTextDataObject::GetDataSize() const
{ {
#if defined(__WXGTK20__) && wxUSE_UNICODE
// Use UTF8 not UCS4
wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() );
return strlen( (const char*) buffer ) + 1;
#else
return GetTextLength() * sizeof(wxChar); return GetTextLength() * sizeof(wxChar);
#endif
} }
bool wxTextDataObject::GetDataHere(void *buf) const bool wxTextDataObject::GetDataHere(void *buf) const
{ {
#if defined(__WXGTK20__) && wxUSE_UNICODE
// Use UTF8 not UCS4
wxCharBuffer buffer = wxConvUTF8.cWX2MB( GetText().c_str() );
strcpy( (char*) buf, (const char*) buffer );
#else
wxStrcpy((wxChar *)buf, GetText().c_str()); wxStrcpy((wxChar *)buf, GetText().c_str());
#endif
return TRUE; return TRUE;
} }
bool wxTextDataObject::SetData(size_t WXUNUSED(len), const void *buf) bool wxTextDataObject::SetData(size_t WXUNUSED(len), const void *buf)
{ {
#if defined(__WXGTK20__) && wxUSE_UNICODE
// Use UTF8 not UCS4
SetText( wxConvUTF8.cMB2WX( (const char*) buf ) );
#else
SetText(wxString((const wxChar *)buf)); SetText(wxString((const wxChar *)buf));
#endif
return TRUE; return TRUE;
} }
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFileDataObjectBase // wxFileDataObjectBase
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -144,10 +144,8 @@ bool wxBitmapButton::Create( wxWindow *parent,
m_widget = gtk_button_new(); m_widget = gtk_button_new();
#if (GTK_MINOR_VERSION > 0)
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
#endif
if (m_bmpNormal.Ok()) if (m_bmpNormal.Ok())
{ {

View File

@@ -40,6 +40,10 @@
GdkAtom g_clipboardAtom = 0; GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0; GdkAtom g_targetsAtom = 0;
#if defined(__WXGTK20__) && wxUSE_UNICODE
extern GdkAtom g_altTextAtom;
#endif
// the trace mask we use with wxLogTrace() - call // the trace mask we use with wxLogTrace() - call
// wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here // wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here
// (there will be a *lot* of them!) // (there will be a *lot* of them!)
@@ -169,13 +173,16 @@ selection_received( GtkWidget *WXUNUSED(widget),
return; return;
} }
/* make sure we got the data in the correct form (selection type). #if 0
if so, copy data to target object */ This seems to cause problems somehow
// make sure we got the data in the correct form (selection type).
// if so, copy data to target object
if (selection_data->type != GDK_SELECTION_TYPE_STRING) if (selection_data->type != GDK_SELECTION_TYPE_STRING)
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
} }
#endif
data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data ); data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
@@ -499,6 +506,15 @@ bool wxClipboard::IsSupported( const wxDataFormat& format )
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
#if defined(__WXGTK20__) && wxUSE_UNICODE
if (!m_formatSupported && format == wxDataFormat(wxDF_UNICODETEXT))
{
// Another try with plain STRING format
extern GdkAtom g_altTextAtom;
return IsSupported(g_altTextAtom);
}
#endif
if (!m_formatSupported) return FALSE; if (!m_formatSupported) return FALSE;
return TRUE; return TRUE;

View File

@@ -28,6 +28,7 @@
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
GdkAtom g_textAtom = 0; GdkAtom g_textAtom = 0;
GdkAtom g_altTextAtom = 0;
GdkAtom g_pngAtom = 0; GdkAtom g_pngAtom = 0;
GdkAtom g_fileAtom = 0; GdkAtom g_fileAtom = 0;
@@ -77,12 +78,9 @@ void wxDataFormat::SetType( wxDataFormatId type )
{ {
PrepareFormats(); PrepareFormats();
if (type == wxDF_UNICODETEXT)
type = wxDF_TEXT;
m_type = type; m_type = type;
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT || m_type == wxDF_UNICODETEXT)
m_format = g_textAtom; m_format = g_textAtom;
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)
@@ -144,6 +142,7 @@ void wxDataFormat::PrepareFormats()
if (!g_textAtom) if (!g_textAtom)
#if wxUSE_UNICODE #if wxUSE_UNICODE
g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE ); g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE );
g_altTextAtom = gdk_atom_intern( "STRING", FALSE );
#else #else
g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE ); g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
#endif #endif
@@ -192,6 +191,18 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir)
} }
} }
// ----------------------------------------------------------------------------
// wxTextDataObject
// ----------------------------------------------------------------------------
#if defined(__WXGTK20__) && wxUSE_UNICODE
void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir) const
{
*formats++ = GetPreferredFormat();
*formats = g_altTextAtom;
}
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFileDataObject // wxFileDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -144,10 +144,8 @@ bool wxBitmapButton::Create( wxWindow *parent,
m_widget = gtk_button_new(); m_widget = gtk_button_new();
#if (GTK_MINOR_VERSION > 0)
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
#endif
if (m_bmpNormal.Ok()) if (m_bmpNormal.Ok())
{ {

View File

@@ -40,6 +40,10 @@
GdkAtom g_clipboardAtom = 0; GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0; GdkAtom g_targetsAtom = 0;
#if defined(__WXGTK20__) && wxUSE_UNICODE
extern GdkAtom g_altTextAtom;
#endif
// the trace mask we use with wxLogTrace() - call // the trace mask we use with wxLogTrace() - call
// wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here // wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here
// (there will be a *lot* of them!) // (there will be a *lot* of them!)
@@ -169,13 +173,16 @@ selection_received( GtkWidget *WXUNUSED(widget),
return; return;
} }
/* make sure we got the data in the correct form (selection type). #if 0
if so, copy data to target object */ This seems to cause problems somehow
// make sure we got the data in the correct form (selection type).
// if so, copy data to target object
if (selection_data->type != GDK_SELECTION_TYPE_STRING) if (selection_data->type != GDK_SELECTION_TYPE_STRING)
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
} }
#endif
data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data ); data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
@@ -499,6 +506,15 @@ bool wxClipboard::IsSupported( const wxDataFormat& format )
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
#if defined(__WXGTK20__) && wxUSE_UNICODE
if (!m_formatSupported && format == wxDataFormat(wxDF_UNICODETEXT))
{
// Another try with plain STRING format
extern GdkAtom g_altTextAtom;
return IsSupported(g_altTextAtom);
}
#endif
if (!m_formatSupported) return FALSE; if (!m_formatSupported) return FALSE;
return TRUE; return TRUE;

View File

@@ -28,6 +28,7 @@
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
GdkAtom g_textAtom = 0; GdkAtom g_textAtom = 0;
GdkAtom g_altTextAtom = 0;
GdkAtom g_pngAtom = 0; GdkAtom g_pngAtom = 0;
GdkAtom g_fileAtom = 0; GdkAtom g_fileAtom = 0;
@@ -77,12 +78,9 @@ void wxDataFormat::SetType( wxDataFormatId type )
{ {
PrepareFormats(); PrepareFormats();
if (type == wxDF_UNICODETEXT)
type = wxDF_TEXT;
m_type = type; m_type = type;
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT || m_type == wxDF_UNICODETEXT)
m_format = g_textAtom; m_format = g_textAtom;
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)
@@ -144,6 +142,7 @@ void wxDataFormat::PrepareFormats()
if (!g_textAtom) if (!g_textAtom)
#if wxUSE_UNICODE #if wxUSE_UNICODE
g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE ); g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE );
g_altTextAtom = gdk_atom_intern( "STRING", FALSE );
#else #else
g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE ); g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
#endif #endif
@@ -192,6 +191,18 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir)
} }
} }
// ----------------------------------------------------------------------------
// wxTextDataObject
// ----------------------------------------------------------------------------
#if defined(__WXGTK20__) && wxUSE_UNICODE
void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir) const
{
*formats++ = GetPreferredFormat();
*formats = g_altTextAtom;
}
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFileDataObject // wxFileDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------