Merge branch 'col-dialog-current'

Add events for current colour change in wxColourDialog and
wxColourPickerCtrl.

See https://github.com/wxWidgets/wxWidgets/pull/1301
This commit is contained in:
Vadim Zeitlin
2019-05-10 01:31:18 +02:00
14 changed files with 314 additions and 26 deletions

View File

@@ -734,20 +734,35 @@ MyFrame::~MyFrame()
#if wxUSE_COLOURDLG
void MyFrame::DoApplyColour(const wxColour& colour)
{
if ( colour == m_canvas->GetBackgroundColour() )
return;
m_canvas->SetBackgroundColour(colour);
m_canvas->ClearBackground();
m_canvas->Refresh();
}
void MyFrame::OnColourChanged(wxColourDialogEvent& event)
{
DoApplyColour(event.GetColour());
}
void MyFrame::ChooseColour(wxCommandEvent& event)
{
m_clrData.SetColour(m_canvas->GetBackgroundColour());
m_clrData.SetChooseAlpha(event.GetId() == DIALOGS_CHOOSE_COLOUR_ALPHA);
wxColourDialog dialog(this, &m_clrData);
dialog.Bind(wxEVT_COLOUR_CHANGED, &MyFrame::OnColourChanged, this);
dialog.SetTitle("Please choose the background colour");
if ( dialog.ShowModal() == wxID_OK )
{
m_clrData = dialog.GetColourData();
m_canvas->SetBackgroundColour(m_clrData.GetColour());
m_canvas->ClearBackground();
m_canvas->Refresh();
}
DoApplyColour(m_clrData.GetColour());
}
void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))

View File

@@ -506,6 +506,11 @@ public:
void OnExit(wxCommandEvent& event);
private:
#if wxUSE_COLOURDLG
void OnColourChanged(wxColourDialogEvent& event);
void DoApplyColour(const wxColour& colour);
#endif // wxUSE_COLOURDLG
#if wxUSE_DIRDLG
void DoDirChoose(int style);
#endif // wxUSE_DIRDLG

View File

@@ -83,6 +83,9 @@ protected:
void OnColourChange(wxColourPickerEvent &ev);
void OnColourCurrentChanged(wxColourPickerEvent &ev);
void OnColourDialogCancelled(wxColourPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev);
void OnButtonReset(wxCommandEvent &ev);
@@ -111,6 +114,8 @@ wxBEGIN_EVENT_TABLE(ColourPickerWidgetsPage, WidgetsPage)
EVT_BUTTON(PickerPage_Reset, ColourPickerWidgetsPage::OnButtonReset)
EVT_COLOURPICKER_CHANGED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourChange)
EVT_COLOURPICKER_CURRENT_CHANGED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourCurrentChanged)
EVT_COLOURPICKER_DIALOG_CANCELLED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourDialogCancelled)
EVT_CHECKBOX(wxID_ANY, ColourPickerWidgetsPage::OnCheckBox)
wxEND_EVENT_TABLE()
@@ -221,6 +226,18 @@ void ColourPickerWidgetsPage::OnColourChange(wxColourPickerEvent& event)
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
}
void ColourPickerWidgetsPage::OnColourCurrentChanged(wxColourPickerEvent& event)
{
wxLogMessage("The currently selected colour changed to '%s'",
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
}
void ColourPickerWidgetsPage::OnColourDialogCancelled(wxColourPickerEvent& event)
{
wxLogMessage("Colour selection dialog cancelled, current colour is '%s'",
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
}
void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent &event)
{
if (event.GetEventObject() == m_chkColourTextCtrl ||