Send wxEVT_COLOUR_CHANGED from wxColourDialog under MSW

Add support for a new event sent by wxColourDialog, currently only under
MSW, when the colour currently selected in it changes.

Based on work by Trylz, see https://github.com/wxWidgets/wxWidgets/pull/1219
This commit is contained in:
Vadim Zeitlin
2019-04-20 21:47:42 +02:00
parent 5b7114b4d7
commit 35c16935f1
7 changed files with 228 additions and 14 deletions

View File

@@ -31,6 +31,52 @@
#define wxColourDialog wxGenericColourDialog
#endif
// Under some platforms (currently only wxMSW) wxColourDialog can send events
// of this type while it is shown.
//
// Notice that this class is almost identical to wxColourPickerEvent but it
// doesn't really sense to reuse the same class for both controls.
class WXDLLIMPEXP_CORE wxColourDialogEvent : public wxCommandEvent
{
public:
wxColourDialogEvent()
{
}
wxColourDialogEvent(wxEventType evtType,
wxColourDialog* dialog,
const wxColour& colour)
: wxCommandEvent(evtType, dialog->GetId()),
m_colour(colour)
{
SetEventObject(dialog);
}
// default copy ctor and dtor are ok
wxColour GetColour() const { return m_colour; }
void SetColour(const wxColour& colour) { m_colour = colour; }
virtual wxEvent *Clone() const wxOVERRIDE
{
return new wxColourDialogEvent(*this);
}
private:
wxColour m_colour;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourDialogEvent);
};
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COLOUR_CHANGED, wxColourDialogEvent);
#define wxColourDialogEventHandler(func) \
wxEVENT_HANDLER_CAST(wxColourDialogEventFunction, func)
#define EVT_COLOUR_CHANGED(id, fn) \
wx__DECLARE_EVT1(wxEVT_COLOUR_CHANGED, id, wxColourDialogEventHandler(fn))
// get the colour from user and return it
WXDLLIMPEXP_CORE wxColour wxGetColourFromUser(wxWindow *parent = NULL,
const wxColour& colInit = wxNullColour,

View File

@@ -44,6 +44,9 @@ public:
// called from the hook procedure on WM_INITDIALOG reception
virtual void MSWOnInitDone(WXHWND hDlg);
// called from the hook procedure
void MSWCheckIfCurrentChanged(WXCOLORREF currentCol);
protected:
// common part of all ctors
void Init();
@@ -57,6 +60,9 @@ protected:
wxColourData m_colourData;
wxString m_title;
// Currently selected colour, used while the dialog is being shown.
WXCOLORREF m_currentCol;
// indicates that the dialog should be centered in this direction if non 0
// (set by DoCentre(), used by MSWOnInitDone())
int m_centreDir;