]> git.saurik.com Git - wxWidgets.git/commitdiff
Comitted GTK part of clipboard patch, that
authorRobert Roebling <robert@roebling.de>
Mon, 15 Mar 2004 22:46:48 +0000 (22:46 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 15 Mar 2004 22:46:48 +0000 (22:46 +0000)
    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

include/wx/dataobj.h
src/common/dobjcmn.cpp
src/gtk/bmpbuttn.cpp
src/gtk/clipbrd.cpp
src/gtk/dataobj.cpp
src/gtk1/bmpbuttn.cpp
src/gtk1/clipbrd.cpp
src/gtk1/dataobj.cpp

index 958db8d70620912b24101370c141c8c969eed16a..085487c62f32db7d29fc2e8185687d75f8c6f499 100644 (file)
@@ -335,21 +335,35 @@ public:
 
     // 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 bool GetDataHere(void *buf) const;
     virtual bool SetData(size_t len, const void *buf);
 
-private:
-    wxString m_text;
-
-    // virtual function hiding supression
     size_t GetDataSize(const wxDataFormat& format) const
         { return(wxDataObjectSimple::GetDataSize(format)); }
     bool GetDataHere(const wxDataFormat& format, void *pBuf) const
         { return(wxDataObjectSimple::GetDataHere(format, pBuf)); }
     bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf)
         { return(wxDataObjectSimple::SetData(format, nLen, pBuf)); }
+#endif
 
+private:
+    wxString m_text;
+    
     DECLARE_NO_COPY_CLASS(wxTextDataObject)
 };
 
index 55c16a374918af2ed6e0a183f675767c3f6e3db1..c70c712265752b7671eaefeea559ec25aad36881 100644 (file)
@@ -237,42 +237,74 @@ bool wxDataObjectComposite::SetData(const wxDataFormat& format,
 // wxTextDataObject
 // ----------------------------------------------------------------------------
 
-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;
+
+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
+{
     return GetTextLength() * sizeof(wxChar);
-#endif
 }
 
 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());
-#endif
 
     return TRUE;
 }
 
 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));
-#endif
 
     return TRUE;
 }
 
+#endif
+
 // ----------------------------------------------------------------------------
 // wxFileDataObjectBase
 // ----------------------------------------------------------------------------
index 6d463b364bd23e15bd91db337ea12747294b2913..dda20401468d7d2ed77799a590d1de78b0913f6b 100644 (file)
@@ -144,10 +144,8 @@ bool wxBitmapButton::Create( wxWindow *parent,
 
     m_widget = gtk_button_new();
 
-#if (GTK_MINOR_VERSION > 0)
     if (style & wxNO_BORDER)
        gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
-#endif
 
     if (m_bmpNormal.Ok())
     {
index 8ba52502f1882389bdd021ccc26615ad03ebebcb..6faf83eaadcda452f6d4bfd3edd6e6322b1beeef 100644 (file)
 GdkAtom  g_clipboardAtom   = 0;
 GdkAtom  g_targetsAtom     = 0;
 
+#if defined(__WXGTK20__) && wxUSE_UNICODE
+extern GdkAtom g_altTextAtom;
+#endif
+
 // the trace mask we use with wxLogTrace() - call
 // wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here
 // (there will be a *lot* of them!)
@@ -169,13 +173,16 @@ selection_received( GtkWidget *WXUNUSED(widget),
         return;
     }
 
-    /* make sure we got the data in the correct form (selection type).
-       if so, copy data to target object */
+#if 0
+    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)
     {
         clipboard->m_waiting = FALSE;
         return;
     }
+#endif
 
     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();
 
+#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;
 
     return TRUE;
index 84b89dbef67dc7f02fe9bd85d98c6fb2b379df99..aa7455040f24ff6a01ebb2f95800561d24480ff3 100644 (file)
@@ -28,6 +28,7 @@
 //-------------------------------------------------------------------------
 
 GdkAtom  g_textAtom        = 0;
+GdkAtom  g_altTextAtom     = 0;
 GdkAtom  g_pngAtom         = 0;
 GdkAtom  g_fileAtom        = 0;
 
@@ -77,12 +78,9 @@ void wxDataFormat::SetType( wxDataFormatId type )
 {
     PrepareFormats();
     
-    if (type == wxDF_UNICODETEXT)
-       type = wxDF_TEXT;
-
     m_type = type;
     
-    if (m_type == wxDF_TEXT)
+    if (m_type == wxDF_TEXT || m_type == wxDF_UNICODETEXT)
         m_format = g_textAtom;
     else
     if (m_type == wxDF_BITMAP)
@@ -144,6 +142,7 @@ void wxDataFormat::PrepareFormats()
     if (!g_textAtom)
 #if wxUSE_UNICODE
         g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE );
+        g_altTextAtom = gdk_atom_intern( "STRING", FALSE );
 #else
         g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
 #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
 // ----------------------------------------------------------------------------
index 6d463b364bd23e15bd91db337ea12747294b2913..dda20401468d7d2ed77799a590d1de78b0913f6b 100644 (file)
@@ -144,10 +144,8 @@ bool wxBitmapButton::Create( wxWindow *parent,
 
     m_widget = gtk_button_new();
 
-#if (GTK_MINOR_VERSION > 0)
     if (style & wxNO_BORDER)
        gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
-#endif
 
     if (m_bmpNormal.Ok())
     {
index 8ba52502f1882389bdd021ccc26615ad03ebebcb..6faf83eaadcda452f6d4bfd3edd6e6322b1beeef 100644 (file)
 GdkAtom  g_clipboardAtom   = 0;
 GdkAtom  g_targetsAtom     = 0;
 
+#if defined(__WXGTK20__) && wxUSE_UNICODE
+extern GdkAtom g_altTextAtom;
+#endif
+
 // the trace mask we use with wxLogTrace() - call
 // wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here
 // (there will be a *lot* of them!)
@@ -169,13 +173,16 @@ selection_received( GtkWidget *WXUNUSED(widget),
         return;
     }
 
-    /* make sure we got the data in the correct form (selection type).
-       if so, copy data to target object */
+#if 0
+    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)
     {
         clipboard->m_waiting = FALSE;
         return;
     }
+#endif
 
     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();
 
+#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;
 
     return TRUE;
index 84b89dbef67dc7f02fe9bd85d98c6fb2b379df99..aa7455040f24ff6a01ebb2f95800561d24480ff3 100644 (file)
@@ -28,6 +28,7 @@
 //-------------------------------------------------------------------------
 
 GdkAtom  g_textAtom        = 0;
+GdkAtom  g_altTextAtom     = 0;
 GdkAtom  g_pngAtom         = 0;
 GdkAtom  g_fileAtom        = 0;
 
@@ -77,12 +78,9 @@ void wxDataFormat::SetType( wxDataFormatId type )
 {
     PrepareFormats();
     
-    if (type == wxDF_UNICODETEXT)
-       type = wxDF_TEXT;
-
     m_type = type;
     
-    if (m_type == wxDF_TEXT)
+    if (m_type == wxDF_TEXT || m_type == wxDF_UNICODETEXT)
         m_format = g_textAtom;
     else
     if (m_type == wxDF_BITMAP)
@@ -144,6 +142,7 @@ void wxDataFormat::PrepareFormats()
     if (!g_textAtom)
 #if wxUSE_UNICODE
         g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE );
+        g_altTextAtom = gdk_atom_intern( "STRING", FALSE );
 #else
         g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
 #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
 // ----------------------------------------------------------------------------