From 4d3acc90d7c9ea39daf50f937ceff878074fc613 Mon Sep 17 00:00:00 2001 From: Bill Su Date: Thu, 14 Dec 2023 19:17:32 -0500 Subject: [PATCH] wxGenericValidator: add wxColourPickerCtrl support --- include/wx/valgen.h | 4 ++++ interface/wx/valgen.h | 4 ++-- src/common/valgen.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/wx/valgen.h b/include/wx/valgen.h index c389cbfc81..9ce773f3c6 100644 --- a/include/wx/valgen.h +++ b/include/wx/valgen.h @@ -16,6 +16,7 @@ class WXDLLIMPEXP_FWD_BASE wxDateTime; class WXDLLIMPEXP_FWD_BASE wxFileName; +class WXDLLIMPEXP_FWD_CORE wxColour; // ---------------------------------------------------------------------------- // wxGenericValidator performs data transfer between many standard controls and @@ -49,6 +50,8 @@ public: wxGenericValidator(float* val); // wxTextCtrl wxGenericValidator(double* val); + // wxColourPickerCtrl + wxGenericValidator(wxColour* val); wxGenericValidator(const wxGenericValidator& copyFrom); @@ -84,6 +87,7 @@ protected: wxFileName* m_pFileName; float* m_pFloat; double* m_pDouble; + wxColour* m_pColour; private: wxDECLARE_CLASS(wxGenericValidator); diff --git a/interface/wx/valgen.h b/interface/wx/valgen.h index cec4c063b7..6951dc22ac 100644 --- a/interface/wx/valgen.h +++ b/interface/wx/valgen.h @@ -15,14 +15,14 @@ - wxButton, wxRadioButton, wxToggleButton, wxBitmapToggleButton, wxSpinButton - wxCheckBox, wxRadioBox, wxComboBox, wxListBox, wxCheckListBox - wxGauge, wxSlider, wxScrollBar, wxChoice, wxStaticText - - wxSpinCtrl, wxTextCtrl + - wxSpinCtrl, wxTextCtrl, wxColourPickerCtrl It checks the type of the window and uses an appropriate type for it. For example, wxButton and wxTextCtrl transfer data to and from a wxString variable; wxListBox uses a wxArrayInt; wxCheckBox uses a boolean. @since 3.2.5 - A wxLB_SINGLE wxListBox can also use an int. + A wxLB_SINGLE wxListBox can also use an int. wxColourPickerCtrl support. For more information, please see @ref overview_validator. diff --git a/src/common/valgen.cpp b/src/common/valgen.cpp index 6724651b48..0edfd52468 100644 --- a/src/common/valgen.cpp +++ b/src/common/valgen.cpp @@ -41,6 +41,9 @@ #if wxUSE_TOGGLEBTN #include "wx/tglbtn.h" #endif +#if wxUSE_COLOURPICKERCTRL + #include +#endif #include "wx/filename.h" #include "wx/valgen.h" @@ -99,6 +102,12 @@ wxGenericValidator::wxGenericValidator(double *val) m_pDouble = val; } +wxGenericValidator::wxGenericValidator(wxColour* val) +{ + Initialize(); + m_pColour = val; +} + wxGenericValidator::wxGenericValidator(const wxGenericValidator& val) : wxValidator() { @@ -119,6 +128,7 @@ bool wxGenericValidator::Copy(const wxGenericValidator& val) m_pFileName = val.m_pFileName; m_pFloat = val.m_pFloat; m_pDouble = val.m_pDouble; + m_pColour = val.m_pColour; return true; } @@ -424,6 +434,20 @@ bool wxGenericValidator::TransferToWindow() } } else #endif + + // colour controls +#if wxUSE_COLOURPICKERCTRL + if (wxDynamicCast(m_validatorWindow, wxColourPickerCtrl)) + { + wxColourPickerCtrl* pControl = (wxColourPickerCtrl*)m_validatorWindow; + if (m_pColour) + { + pControl->SetColour(*m_pColour); + + return true; + } + } else +#endif { // to match the last 'else' above } @@ -734,6 +758,19 @@ bool wxGenericValidator::TransferFromWindow() } } else #endif +#if wxUSE_COLOURPICKERCTRL + if (wxDynamicCast(m_validatorWindow, wxColourPickerCtrl)) + { + wxColourPickerCtrl* pControl = (wxColourPickerCtrl*)m_validatorWindow; + if (m_pColour) + { + *m_pColour = pControl->GetColour(); + + return true; + } + } + else +#endif // unrecognized control, or bad pointer return false; @@ -756,6 +793,7 @@ void wxGenericValidator::Initialize() m_pFileName = nullptr; m_pFloat = nullptr; m_pDouble = nullptr; + m_pColour = nullptr; } #endif // wxUSE_VALIDATORS