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.
This commit is contained in:
Vadim Zeitlin
2019-04-20 21:18:23 +02:00
parent 06d15be780
commit 5b7114b4d7
3 changed files with 13 additions and 9 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);
}
}