]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't connect to the same signal multiple times in wxGTK wxClipboard.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 15 Feb 2013 12:40:13 +0000 (12:40 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 15 Feb 2013 12:40:13 +0000 (12:40 +0000)
We called g_signal_connect("selection_get") in wxClipboard code each time its
AddData() method was called. This resulted in progressive but noticeable
slowdown as the handler was called more and more times.

Only connect to the handler once now.

Closes #15038.

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

include/wx/gtk/clipbrd.h
src/gtk/clipbrd.cpp

index 4af988f80cf4ab9a4b8084f9647c8fd14cfa8739..ff24ad33dc3bd84ac8da9472724a10dc27d4d983 100644 (file)
@@ -118,6 +118,9 @@ private:
     GtkWidget *m_clipboardWidget;  // for getting and offering data
     GtkWidget *m_targetsWidget;    // for getting list of supported formats
 
+    // ID of the connection to "selection_get" signal, initially 0.
+    unsigned long m_idSelectionGetHandler;
+
     bool m_open;
     bool m_formatSupported;
 
index 8b3d228a4f3394cd3c045051ca3c64589a19596b..e41b5e654cad13c69ab2efb60171c7f054814447 100644 (file)
@@ -434,6 +434,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
 
 wxClipboard::wxClipboard()
 {
+    m_idSelectionGetHandler = 0;
+
     m_open = false;
 
     m_dataPrimary =
@@ -642,9 +644,13 @@ bool wxClipboard::AddData( wxDataObject *data )
         AddSupportedTarget(format);
     }
 
-    g_signal_connect (m_clipboardWidget, "selection_get",
+    if ( !m_idSelectionGetHandler )
+    {
+        m_idSelectionGetHandler = g_signal_connect (
+                      m_clipboardWidget, "selection_get",
                       G_CALLBACK (selection_handler),
                       GUINT_TO_POINTER (gtk_get_current_event_time()) );
+    }
 
     // tell the world we offer clipboard data
     return SetSelectionOwner();