From: Vadim Zeitlin Date: Sun, 29 Jul 2012 22:08:15 +0000 (+0000) Subject: Generate clipboard events for wxComboBox in wxGTK too. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1043456035b60331b7faed24e69f81e94bd2cf85 Generate clipboard events for wxComboBox in wxGTK too. 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 --- diff --git a/docs/changes.txt b/docs/changes.txt index bbb0e9ec63..3c52f5d3fb 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/gtk/textentry.h b/include/wx/gtk/textentry.h index 8b47b758e1..a2ec262c84 100644 --- a/include/wx/gtk/textentry.h +++ b/include/wx/gtk/textentry.h @@ -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; diff --git a/samples/widgets/combobox.cpp b/samples/widgets/combobox.cpp index a36f3a0085..23fd516a01 100644 --- a/samples/widgets/combobox.cpp +++ b/samples/widgets/combobox.cpp @@ -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(); diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index ee87e1a6af..c69f23d0b5 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -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(); diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index a67b4a852b..35a5e0fec8 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -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", diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index eedc7c026f..15c7981c77 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -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 ); diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 4a91420d12..1354841812 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -39,11 +39,9 @@ // 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());