]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/clipbrd.cpp
Fix wxListCtrlXmlHandler so that it accepts icon with wxLC_LIST and wxLC_REPORT style...
[wxWidgets.git] / src / gtk1 / clipbrd.cpp
index 4a09a5006f6b48d082f63a30fb2f70bea4aca97e..2c5b0ff8859c0448a076200bde02c5f357b36849 100644 (file)
 #ifndef WX_PRECOMP
     #include "wx/log.h"
     #include "wx/utils.h"
 #ifndef WX_PRECOMP
     #include "wx/log.h"
     #include "wx/utils.h"
+    #include "wx/dataobj.h"
 #endif
 
 #endif
 
-#include "wx/dataobj.h"
-
 #include <glib.h>
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
@@ -36,7 +35,7 @@ GdkAtom  g_timestampAtom   = 0;
 // 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!)
 // 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!)
-static const wxChar *TRACE_CLIPBOARD = _T("clipboard");
+#define TRACE_CLIPBOARD "clipboard"
 
 //-----------------------------------------------------------------------------
 // reminder
 
 //-----------------------------------------------------------------------------
 // reminder
@@ -84,7 +83,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
             if ( strcmp(atom_name, "TARGETS") )
             {
                 wxLogTrace( TRACE_CLIPBOARD,
             if ( strcmp(atom_name, "TARGETS") )
             {
                 wxLogTrace( TRACE_CLIPBOARD,
-                            _T("got unsupported clipboard target") );
+                            wxT("got unsupported clipboard target") );
 
                 clipboard->m_waiting = false;
                 g_free(atom_name);
 
                 clipboard->m_waiting = false;
                 g_free(atom_name);
@@ -93,12 +92,10 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
             g_free(atom_name);
         }
 
             g_free(atom_name);
         }
 
-#ifdef __WXDEBUG__
         wxDataFormat clip( selection_data->selection );
         wxLogTrace( TRACE_CLIPBOARD,
                     wxT("selection received for targets, clipboard %s"),
                     clip.GetId().c_str() );
         wxDataFormat clip( selection_data->selection );
         wxLogTrace( TRACE_CLIPBOARD,
                     wxT("selection received for targets, clipboard %s"),
                     clip.GetId().c_str() );
-#endif // __WXDEBUG__
 
         // the atoms we received, holding a list of targets (= formats)
         GdkAtom *atoms = (GdkAtom *)selection_data->data;
 
         // the atoms we received, holding a list of targets (= formats)
         GdkAtom *atoms = (GdkAtom *)selection_data->data;
@@ -219,8 +216,7 @@ selection_clear_clip( GtkWidget *WXUNUSED(widget), GdkEventSelection *event )
         {
             wxLogTrace(TRACE_CLIPBOARD, wxT("wxClipboard will get cleared" ));
 
         {
             wxLogTrace(TRACE_CLIPBOARD, wxT("wxClipboard will get cleared" ));
 
-            delete wxTheClipboard->m_data;
-            wxTheClipboard->m_data = (wxDataObject*) NULL;
+            wxDELETE(wxTheClipboard->m_data);
         }
     }
 
         }
     }
 
@@ -260,23 +256,21 @@ selection_handler( GtkWidget *WXUNUSED(widget),
                                (guchar*)&(timestamp),
                                sizeof(timestamp));
         wxLogTrace(TRACE_CLIPBOARD,
                                (guchar*)&(timestamp),
                                sizeof(timestamp));
         wxLogTrace(TRACE_CLIPBOARD,
-                   _T("Clipboard TIMESTAMP requested, returning timestamp=%u"),
+                   wxT("Clipboard TIMESTAMP requested, returning timestamp=%u"),
                    timestamp);
         return;
     }
 
     wxDataFormat format( selection_data->target );
 
                    timestamp);
         return;
     }
 
     wxDataFormat format( selection_data->target );
 
-#ifdef __WXDEBUG__
     wxLogTrace(TRACE_CLIPBOARD,
     wxLogTrace(TRACE_CLIPBOARD,
-               _T("clipboard data in format %s, GtkSelectionData is target=%s type=%s selection=%s timestamp=%u"),
+               wxT("clipboard data in format %s, GtkSelectionData is target=%s type=%s selection=%s timestamp=%u"),
                format.GetId().c_str(),
                wxString::FromAscii(gdk_atom_name(selection_data->target)).c_str(),
                wxString::FromAscii(gdk_atom_name(selection_data->type)).c_str(),
                wxString::FromAscii(gdk_atom_name(selection_data->selection)).c_str(),
                GPOINTER_TO_UINT( signal_data )
                );
                format.GetId().c_str(),
                wxString::FromAscii(gdk_atom_name(selection_data->target)).c_str(),
                wxString::FromAscii(gdk_atom_name(selection_data->type)).c_str(),
                wxString::FromAscii(gdk_atom_name(selection_data->selection)).c_str(),
                GPOINTER_TO_UINT( signal_data )
                );
-#endif
 
     if (!data->IsSupportedFormat( format )) return;
 
 
     if (!data->IsSupportedFormat( format )) return;
 
@@ -314,8 +308,8 @@ wxClipboard::wxClipboard()
     m_ownsClipboard = false;
     m_ownsPrimarySelection = false;
 
     m_ownsClipboard = false;
     m_ownsPrimarySelection = false;
 
-    m_data = (wxDataObject*) NULL;
-    m_receivedData = (wxDataObject*) NULL;
+    m_data = NULL;
+    m_receivedData = NULL;
 
     /* we use m_targetsWidget to query what formats are available */
 
 
     /* we use m_targetsWidget to query what formats are available */
 
@@ -348,8 +342,6 @@ wxClipboard::wxClipboard()
 
     m_formatSupported = false;
     m_targetRequested = 0;
 
     m_formatSupported = false;
     m_targetRequested = 0;
-
-    m_usePrimary = false;
 }
 
 wxClipboard::~wxClipboard()
 }
 
 wxClipboard::~wxClipboard()
@@ -374,7 +366,7 @@ void wxClipboard::Clear()
         {
             m_waiting = true;
 
         {
             m_waiting = true;
 
-            gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom,
+            gtk_selection_owner_set( NULL, g_clipboardAtom,
                                      (guint32) GDK_CURRENT_TIME );
 
             while (m_waiting) gtk_main_iteration();
                                      (guint32) GDK_CURRENT_TIME );
 
             while (m_waiting) gtk_main_iteration();
@@ -384,17 +376,13 @@ void wxClipboard::Clear()
         {
             m_waiting = true;
 
         {
             m_waiting = true;
 
-            gtk_selection_owner_set( (GtkWidget*) NULL, GDK_SELECTION_PRIMARY,
+            gtk_selection_owner_set( NULL, GDK_SELECTION_PRIMARY,
                                      (guint32) GDK_CURRENT_TIME );
 
             while (m_waiting) gtk_main_iteration();
         }
 
                                      (guint32) GDK_CURRENT_TIME );
 
             while (m_waiting) gtk_main_iteration();
         }
 
-        if (m_data)
-        {
-            delete m_data;
-            m_data = (wxDataObject*) NULL;
-        }
+        wxDELETE(m_data);
 
 #if wxUSE_THREADS
         /* re-enable GUI threads */
 
 #if wxUSE_THREADS
         /* re-enable GUI threads */
@@ -620,8 +608,25 @@ bool wxClipboard::GetData( wxDataObject& data )
 
         while (m_waiting) gtk_main_iteration();
 
 
         while (m_waiting) gtk_main_iteration();
 
-        /* this is a true error as we checked for the presence of such data before */
-        wxCHECK_MSG( m_formatSupported, false, wxT("error retrieving data from clipboard") );
+        /*
+           Normally this is a true error as we checked for the presence of such
+           data before, but there are applications that may return an empty
+           string (e.g. Gnumeric-1.6.1 on Linux if an empty cell is copied)
+           which would produce a false error message here, so we check for the
+           size of the string first. In ansi, GetDataSize returns an extra
+           value (for the closing null?), with unicode, the exact number of
+           tokens is given (that is more than 1 for special characters)
+           (tested with Gnumeric-1.6.1 and OpenOffice.org-2.0.2)
+         */
+#if wxUSE_UNICODE
+        if ( format != wxDF_UNICODETEXT || data.GetDataSize(format) > 0 )
+#else // !UNICODE
+        if ( format != wxDF_TEXT || data.GetDataSize(format) > 1 )
+#endif // UNICODE / !UNICODE
+        {
+            wxCHECK_MSG( m_formatSupported, false,
+                         wxT("error retrieving data from clipboard") );
+        }
 
         /* return success */
         delete[] array;
 
         /* return success */
         delete[] array;