From 5b7114b4d749b9eaeeec8aefaa1b3dc2b1a0a132 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Apr 2019 21:18:23 +0200 Subject: [PATCH] Send correct event directly from wxGenericColourButton Instead of sending wxEVT_COLOURPICKER_CHANGED event from the button itself and then catching it in wxColourPickerCtrl and resending an event from the control from there, just send the event originating from the correct object directly. This allows to slightly simplify the code and will be especially useful for other events, to be added in the upcoming commits, to avoid having to write the same forwarding code for all of them. --- src/common/clrpickercmn.cpp | 5 +---- src/generic/clrpickerg.cpp | 10 +++++++--- src/gtk/clrpicker.cpp | 7 +++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/common/clrpickercmn.cpp b/src/common/clrpickercmn.cpp index f22482a2cd..a7597e979e 100644 --- a/src/common/clrpickercmn.cpp +++ b/src/common/clrpickercmn.cpp @@ -129,10 +129,7 @@ void wxColourPickerCtrl::OnColourChange(wxColourPickerEvent &ev) { UpdateTextCtrlFromPicker(); - // the wxColourPickerWidget sent us a colour-change notification. - // forward this event to our parent - wxColourPickerEvent event(this, GetId(), ev.GetColour()); - GetEventHandler()->ProcessEvent(event); + ev.Skip(); } #endif // wxUSE_COLOURPICKERCTRL diff --git a/src/generic/clrpickerg.cpp b/src/generic/clrpickerg.cpp index 58cd06ab8a..f9c923f1fc 100644 --- a/src/generic/clrpickerg.cpp +++ b/src/generic/clrpickerg.cpp @@ -91,9 +91,13 @@ void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev)) ms_data = dlg.GetColourData(); SetColour(ms_data.GetColour()); - // fire an event - wxColourPickerEvent event(this, GetId(), m_colour); - GetEventHandler()->ProcessEvent(event); + // Fire the corresponding event: note that we want it to appear as + // originating from our parent, which is the user-visible window, and not + // this button itself, which is just an implementation detail. + wxWindow* const parent = GetParent(); + wxColourPickerEvent event(parent, parent->GetId(), m_colour); + + ProcessWindowEvent(event); } } diff --git a/src/gtk/clrpicker.cpp b/src/gtk/clrpicker.cpp index 856421e94e..54f01a4d09 100644 --- a/src/gtk/clrpicker.cpp +++ b/src/gtk/clrpicker.cpp @@ -50,8 +50,11 @@ static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget, #endif p->GTKSetColour(gdkColor); - // fire the colour-changed event - wxColourPickerEvent event(p, p->GetId(), p->GetColour()); + // Fire the corresponding event: note that we want it to appear as + // originating from our parent, which is the user-visible window, and not + // this button itself, which is just an implementation detail. + wxWindow* const parent = p->GetParent(); + wxColourPickerEvent event(parent, parent->GetId(), p->GetColour()); p->HandleWindowEvent(event); } }