]> git.saurik.com Git - wxWidgets.git/commitdiff
Generate clipboard events for wxComboBox in wxGTK too.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 29 Jul 2012 22:08:15 +0000 (22:08 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 29 Jul 2012 22:08:15 +0000 (22:08 +0000)
These events were only generated for wxTextCtrl but should be sent for
non-readonly wxComboBox too, so refactor the code to allow its reuse from
wxComboBox.

Also add EVT_TEXT_PASTE handlers for both controls to the widgets sample for
testing.

Closes #14520.

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

docs/changes.txt
include/wx/gtk/textentry.h
samples/widgets/combobox.cpp
samples/widgets/textctrl.cpp
src/gtk/combobox.cpp
src/gtk/textctrl.cpp
src/gtk/textentry.cpp

index bbb0e9ec638df9396c7d790e6970d4c360f0c60e..3c52f5d3fbc4028340dd8719fafa657cc83c25ca 100644 (file)
@@ -540,6 +540,7 @@ wxGTK:
 
 - Allow building wxGTK3 with Broadway backend (Kolya Kosenko).
 - Provide native implementation of wxNotificationMessage using libnotify.
+- Generate clipboard events for wxComboBox and not only wxTextCtrl.
 - Improve drag-and-drop of URLs.
 
 wxMSW:
index 8b47b758e17a6e4c03dbe1045e1b994d4d2f8996..a2ec262c84db87f88673bf89d5819e90c81352b3 100644 (file)
@@ -52,6 +52,10 @@ public:
     void SendMaxLenEvent();
 
 protected:
+    // This method must be called from the derived class Create() to connect
+    // the handlers for the clipboard (cut/copy/paste) events.
+    void GTKConnectClipboardSignals(GtkWidget* entry);
+
     virtual void DoSetValue(const wxString& value, int flags);
     virtual wxString DoGetValue() const;
 
index a36f3a008502e465a2def7b8c229e393081a8191..23fd516a01d3bb5781efcb5797af33186c27cacc 100644 (file)
@@ -124,6 +124,7 @@ protected:
     void OnCloseup(wxCommandEvent& event);
     void OnComboBox(wxCommandEvent& event);
     void OnComboText(wxCommandEvent& event);
+    void OnComboTextPasted(wxClipboardTextEvent& event);
 
     void OnCheckOrRadioBox(wxCommandEvent& event);
 
@@ -215,6 +216,7 @@ BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
     EVT_COMBOBOX_CLOSEUP(ComboPage_Combo, ComboboxWidgetsPage::OnCloseup)
     EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
     EVT_TEXT_ENTER(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
+    EVT_TEXT_PASTE(ComboPage_Combo, ComboboxWidgetsPage::OnComboTextPasted)
 
     EVT_CHECKBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox)
     EVT_RADIOBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox)
@@ -662,6 +664,12 @@ void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event)
     }
 }
 
+void ComboboxWidgetsPage::OnComboTextPasted(wxClipboardTextEvent& event)
+{
+    wxLogMessage("Text pasted from clipboard.");
+    event.Skip();
+}
+
 void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event)
 {
     long sel = event.GetInt();
index ee87e1a6af8c60b19e4869a2e11b1134cffacb6d..c69f23d0b5127ace47b82fddca3de58e5093019e 100644 (file)
@@ -171,6 +171,7 @@ protected:
 
     void OnText(wxCommandEvent& event);
     void OnTextEnter(wxCommandEvent& event);
+    void OnTextPasted(wxClipboardTextEvent& event);
 
     void OnCheckOrRadioBox(wxCommandEvent& event);
 
@@ -326,6 +327,7 @@ BEGIN_EVENT_TABLE(TextWidgetsPage, WidgetsPage)
 
     EVT_TEXT(TextPage_Textctrl, TextWidgetsPage::OnText)
     EVT_TEXT_ENTER(TextPage_Textctrl, TextWidgetsPage::OnTextEnter)
+    EVT_TEXT_PASTE(TextPage_Textctrl, TextWidgetsPage::OnTextPasted)
 
     EVT_CHECKBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
     EVT_RADIOBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
@@ -921,6 +923,12 @@ void TextWidgetsPage::OnTextEnter(wxCommandEvent& event)
     event.Skip();
 }
 
+void TextWidgetsPage::OnTextPasted(wxClipboardTextEvent& event)
+{
+    wxLogMessage("Text pasted from clipboard.");
+    event.Skip();
+}
+
 void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
 {
     CreateText();
index a67b4a852b8a759a40ea2eb039a2810bdb453dd9..35a5e0fec81560896a0fb2a21167b88f5a2f50d2 100644 (file)
@@ -60,6 +60,7 @@ gtkcombobox_popupshown_callback(GObject *WXUNUSED(gobject),
     event.SetEventObject( combo );
     combo->HandleWindowEvent( event );
 }
+
 }
 
 //-----------------------------------------------------------------------------
@@ -167,6 +168,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
 
         g_signal_connect_after (entry, "changed",
                                 G_CALLBACK (gtkcombobox_text_changed_callback), this);
+
+        GTKConnectClipboardSignals(GTK_WIDGET(entry));
     }
 
     g_signal_connect_after (m_widget, "changed",
index eedc7c026f6bbe7f20d79c6406a17285f2bf2868..15c7981c77fb51eb8d366e5c0f6d4cbfc61de96d 100644 (file)
@@ -555,48 +555,6 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
 }
 }
 
-//-----------------------------------------------------------------------------
-//  clipboard events: "copy-clipboard", "cut-clipboard", "paste-clipboard"
-//-----------------------------------------------------------------------------
-
-// common part of the event handlers below
-static void
-handle_text_clipboard_callback( GtkWidget *widget, wxTextCtrl *win,
-                                wxEventType eventType, const gchar * signal_name)
-{
-    wxClipboardTextEvent event( eventType, win->GetId() );
-    event.SetEventObject( win );
-    if ( win->HandleWindowEvent( event ) )
-    {
-        // don't let the default processing to take place if we did something
-        // ourselves in the event handler
-        g_signal_stop_emission_by_name (widget, signal_name);
-    }
-}
-
-extern "C" {
-static void
-gtk_copy_clipboard_callback( GtkWidget *widget, wxTextCtrl *win )
-{
-    handle_text_clipboard_callback(
-        widget, win, wxEVT_COMMAND_TEXT_COPY, "copy-clipboard" );
-}
-
-static void
-gtk_cut_clipboard_callback( GtkWidget *widget, wxTextCtrl *win )
-{
-    handle_text_clipboard_callback(
-        widget, win, wxEVT_COMMAND_TEXT_CUT, "cut-clipboard" );
-}
-
-static void
-gtk_paste_clipboard_callback( GtkWidget *widget, wxTextCtrl *win )
-{
-    handle_text_clipboard_callback(
-        widget, win, wxEVT_COMMAND_TEXT_PASTE, "paste-clipboard" );
-}
-}
-
 //-----------------------------------------------------------------------------
 //  "mark_set"
 //-----------------------------------------------------------------------------
@@ -829,12 +787,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
     }
 
 
-    g_signal_connect (m_text, "copy-clipboard",
-                      G_CALLBACK (gtk_copy_clipboard_callback), this);
-    g_signal_connect (m_text, "cut-clipboard",
-                      G_CALLBACK (gtk_cut_clipboard_callback), this);
-    g_signal_connect (m_text, "paste-clipboard",
-                      G_CALLBACK (gtk_paste_clipboard_callback), this);
+    GTKConnectClipboardSignals(m_text);
 
     m_cursor = wxCursor( wxCURSOR_IBEAM );
 
index 4a91420d1256d74dfbb1afc74096326a8137887b..1354841812ad59f911dfe9d9f50551c124229937 100644 (file)
 // signal handlers implementation
 // ============================================================================
 
-extern "C"
-{
-
 // "insert_text" handler for GtkEntry
-static void
+extern "C"
+void
 wx_gtk_insert_text_callback(GtkEditable *editable,
                             const gchar * WXUNUSED(new_text),
                             gint WXUNUSED(new_text_length),
@@ -74,6 +72,51 @@ wx_gtk_insert_text_callback(GtkEditable *editable,
     }
 }
 
+//-----------------------------------------------------------------------------
+//  clipboard events: "copy-clipboard", "cut-clipboard", "paste-clipboard"
+//-----------------------------------------------------------------------------
+
+// common part of the event handlers below
+static void
+DoHandleClipboardCallback( GtkWidget *widget,
+                           wxWindow *win,
+                           wxEventType eventType,
+                           const gchar* signal_name)
+{
+    wxClipboardTextEvent event( eventType, win->GetId() );
+    event.SetEventObject( win );
+    if ( win->HandleWindowEvent( event ) )
+    {
+        // don't let the default processing to take place if we did something
+        // ourselves in the event handler
+        g_signal_stop_emission_by_name (widget, signal_name);
+    }
+}
+
+extern "C"
+{
+
+static void
+wx_gtk_copy_clipboard_callback( GtkWidget *widget, wxWindow *win )
+{
+    DoHandleClipboardCallback(
+        widget, win, wxEVT_COMMAND_TEXT_COPY, "copy-clipboard" );
+}
+
+static void
+wx_gtk_cut_clipboard_callback( GtkWidget *widget, wxWindow *win )
+{
+    DoHandleClipboardCallback(
+        widget, win, wxEVT_COMMAND_TEXT_CUT, "cut-clipboard" );
+}
+
+static void
+wx_gtk_paste_clipboard_callback( GtkWidget *widget, wxWindow *win )
+{
+    DoHandleClipboardCallback(
+        widget, win, wxEVT_COMMAND_TEXT_PASTE, "paste-clipboard" );
+}
+
 } // extern "C"
 
 // ============================================================================
@@ -147,6 +190,19 @@ void wxTextEntry::Remove(long from, long to)
 // clipboard operations
 // ----------------------------------------------------------------------------
 
+void wxTextEntry::GTKConnectClipboardSignals(GtkWidget* entry)
+{
+    g_signal_connect(entry, "copy-clipboard",
+                     G_CALLBACK (wx_gtk_copy_clipboard_callback),
+                     GetEditableWindow());
+    g_signal_connect(entry, "cut-clipboard",
+                     G_CALLBACK (wx_gtk_cut_clipboard_callback),
+                     GetEditableWindow());
+    g_signal_connect(entry, "paste-clipboard",
+                     G_CALLBACK (wx_gtk_paste_clipboard_callback),
+                     GetEditableWindow());
+}
+
 void wxTextEntry::Copy()
 {
     gtk_editable_copy_clipboard(GetEditable());