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

@@ -10,11 +10,46 @@
This class represents the colour chooser dialog.
Starting from wxWidgets 3.1.3 and currently in the MSW port only, this
dialog generates wxEVT_COLOUR_CHANGED events while it is being shown, i.e.
from inside its ShowModal() method, that notify the program about the
change of the currently selected colour and allow it to e.g. preview the
effect of selecting this colour. Note that if you react to this event, you
should also correctly revert to the previously selected colour if the
dialog is cancelled by the user.
Example of using this class with dynamic feedback for the selected colour:
@code
// Some function for redrawing using the given colour. Ideally, it
// shouldn't do anything if the colour is the same as the one used
// before.
void Redraw(const wxColour& colour);
wxColourData data;
data.SetColour(initialColourToUse);
wxColourData dlg(this, &data);
dlg.Bind(wxEVT_COLOUR_CHANGED, [](wxColourDialogEvent& event) {
Redraw(event.GetColour());
});
if ( dlg.ShowModal() == wxID_OK ) {
// Colour did change.
} else {
// Colour didn't change.
}
// This call is unnecessary under platforms generating
// wxEVT_COLOUR_CHANGED if the dialog was accepted and unnecessary
// under the platforms not generating this event if it was cancelled,
// so we could check for the different cases explicitly to avoid it,
// but it's simpler to just always call it.
Redraw(data.GetColour());
@endcode
@library{wxcore}
@category{cmndlg}
@see @ref overview_cmndlg_colour, wxColour, wxColourData,
wxGetColourFromUser()
wxColourDialogEvent, wxGetColourFromUser()
*/
class wxColourDialog : public wxDialog
{
@@ -55,7 +90,30 @@ public:
virtual int ShowModal();
};
/**
This event class is used for the events generated by wxColourDialog.
@beginEventTable{wxColourPickerEvent}
@event{EVT_COLOUR_CHANGED(id, func)}
Generated whenever the currently selected colour in the dialog
changes. This event is currently only implemented in wxMSW.
@endEventTable
@library{wxcore}
@category{events}
@see wxColourDialog
@since 3.1.3
*/
class wxColourDialogEvent : public wxCommandEvent
{
public:
/**
Retrieve the colour the user has just selected.
*/
wxColour GetColour() const;
};
// ============================================================================
// Global functions/macros