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
This commit is contained in:
@@ -540,6 +540,7 @@ wxGTK:
|
|||||||
|
|
||||||
- Allow building wxGTK3 with Broadway backend (Kolya Kosenko).
|
- Allow building wxGTK3 with Broadway backend (Kolya Kosenko).
|
||||||
- Provide native implementation of wxNotificationMessage using libnotify.
|
- Provide native implementation of wxNotificationMessage using libnotify.
|
||||||
|
- Generate clipboard events for wxComboBox and not only wxTextCtrl.
|
||||||
- Improve drag-and-drop of URLs.
|
- Improve drag-and-drop of URLs.
|
||||||
|
|
||||||
wxMSW:
|
wxMSW:
|
||||||
|
@@ -52,6 +52,10 @@ public:
|
|||||||
void SendMaxLenEvent();
|
void SendMaxLenEvent();
|
||||||
|
|
||||||
protected:
|
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 void DoSetValue(const wxString& value, int flags);
|
||||||
virtual wxString DoGetValue() const;
|
virtual wxString DoGetValue() const;
|
||||||
|
|
||||||
|
@@ -124,6 +124,7 @@ protected:
|
|||||||
void OnCloseup(wxCommandEvent& event);
|
void OnCloseup(wxCommandEvent& event);
|
||||||
void OnComboBox(wxCommandEvent& event);
|
void OnComboBox(wxCommandEvent& event);
|
||||||
void OnComboText(wxCommandEvent& event);
|
void OnComboText(wxCommandEvent& event);
|
||||||
|
void OnComboTextPasted(wxClipboardTextEvent& event);
|
||||||
|
|
||||||
void OnCheckOrRadioBox(wxCommandEvent& event);
|
void OnCheckOrRadioBox(wxCommandEvent& event);
|
||||||
|
|
||||||
@@ -215,6 +216,7 @@ BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
|
|||||||
EVT_COMBOBOX_CLOSEUP(ComboPage_Combo, ComboboxWidgetsPage::OnCloseup)
|
EVT_COMBOBOX_CLOSEUP(ComboPage_Combo, ComboboxWidgetsPage::OnCloseup)
|
||||||
EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
|
EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
|
||||||
EVT_TEXT_ENTER(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_CHECKBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox)
|
||||||
EVT_RADIOBOX(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)
|
void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
long sel = event.GetInt();
|
long sel = event.GetInt();
|
||||||
|
@@ -171,6 +171,7 @@ protected:
|
|||||||
|
|
||||||
void OnText(wxCommandEvent& event);
|
void OnText(wxCommandEvent& event);
|
||||||
void OnTextEnter(wxCommandEvent& event);
|
void OnTextEnter(wxCommandEvent& event);
|
||||||
|
void OnTextPasted(wxClipboardTextEvent& event);
|
||||||
|
|
||||||
void OnCheckOrRadioBox(wxCommandEvent& event);
|
void OnCheckOrRadioBox(wxCommandEvent& event);
|
||||||
|
|
||||||
@@ -326,6 +327,7 @@ BEGIN_EVENT_TABLE(TextWidgetsPage, WidgetsPage)
|
|||||||
|
|
||||||
EVT_TEXT(TextPage_Textctrl, TextWidgetsPage::OnText)
|
EVT_TEXT(TextPage_Textctrl, TextWidgetsPage::OnText)
|
||||||
EVT_TEXT_ENTER(TextPage_Textctrl, TextWidgetsPage::OnTextEnter)
|
EVT_TEXT_ENTER(TextPage_Textctrl, TextWidgetsPage::OnTextEnter)
|
||||||
|
EVT_TEXT_PASTE(TextPage_Textctrl, TextWidgetsPage::OnTextPasted)
|
||||||
|
|
||||||
EVT_CHECKBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
|
EVT_CHECKBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
|
||||||
EVT_RADIOBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
|
EVT_RADIOBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
|
||||||
@@ -921,6 +923,12 @@ void TextWidgetsPage::OnTextEnter(wxCommandEvent& event)
|
|||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextWidgetsPage::OnTextPasted(wxClipboardTextEvent& event)
|
||||||
|
{
|
||||||
|
wxLogMessage("Text pasted from clipboard.");
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
CreateText();
|
CreateText();
|
||||||
|
@@ -60,6 +60,7 @@ gtkcombobox_popupshown_callback(GObject *WXUNUSED(gobject),
|
|||||||
event.SetEventObject( combo );
|
event.SetEventObject( combo );
|
||||||
combo->HandleWindowEvent( event );
|
combo->HandleWindowEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -167,6 +168,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
|
|||||||
|
|
||||||
g_signal_connect_after (entry, "changed",
|
g_signal_connect_after (entry, "changed",
|
||||||
G_CALLBACK (gtkcombobox_text_changed_callback), this);
|
G_CALLBACK (gtkcombobox_text_changed_callback), this);
|
||||||
|
|
||||||
|
GTKConnectClipboardSignals(GTK_WIDGET(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect_after (m_widget, "changed",
|
g_signal_connect_after (m_widget, "changed",
|
||||||
|
@@ -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"
|
// "mark_set"
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -829,12 +787,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
g_signal_connect (m_text, "copy-clipboard",
|
GTKConnectClipboardSignals(m_text);
|
||||||
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);
|
|
||||||
|
|
||||||
m_cursor = wxCursor( wxCURSOR_IBEAM );
|
m_cursor = wxCursor( wxCURSOR_IBEAM );
|
||||||
|
|
||||||
|
@@ -39,11 +39,9 @@
|
|||||||
// signal handlers implementation
|
// signal handlers implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
|
|
||||||
// "insert_text" handler for GtkEntry
|
// "insert_text" handler for GtkEntry
|
||||||
static void
|
extern "C"
|
||||||
|
void
|
||||||
wx_gtk_insert_text_callback(GtkEditable *editable,
|
wx_gtk_insert_text_callback(GtkEditable *editable,
|
||||||
const gchar * WXUNUSED(new_text),
|
const gchar * WXUNUSED(new_text),
|
||||||
gint WXUNUSED(new_text_length),
|
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"
|
} // extern "C"
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -147,6 +190,19 @@ void wxTextEntry::Remove(long from, long to)
|
|||||||
// clipboard operations
|
// 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()
|
void wxTextEntry::Copy()
|
||||||
{
|
{
|
||||||
gtk_editable_copy_clipboard(GetEditable());
|
gtk_editable_copy_clipboard(GetEditable());
|
||||||
|
Reference in New Issue
Block a user