Merge branch 'valgen-wxlb_single' of https://github.com/wsu-cb/wxWidgets
Extend wxGenericValidator to work with single selection wxListBox, 3-state wxCheckBox and wxColourPickerCtrl. See #24134.
This commit is contained in:
commit
68eaff5c02
4 changed files with 128 additions and 1 deletions
|
|
@ -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
|
||||
|
|
@ -33,6 +34,7 @@ public:
|
|||
// wxCheckBox, wxRadioButton, wx(Bitmap)ToggleButton
|
||||
wxGenericValidator(bool* val);
|
||||
// wxChoice, wxGauge, wxRadioBox, wxScrollBar, wxSlider, wxSpinButton
|
||||
// single-selection wxListBox
|
||||
wxGenericValidator(int* val);
|
||||
// wxComboBox, wxTextCtrl, wxButton, wxStaticText (read-only)
|
||||
wxGenericValidator(wxString* val);
|
||||
|
|
@ -48,6 +50,10 @@ public:
|
|||
wxGenericValidator(float* val);
|
||||
// wxTextCtrl
|
||||
wxGenericValidator(double* val);
|
||||
// wxColourPickerCtrl
|
||||
wxGenericValidator(wxColour* val);
|
||||
// wxCheckBox
|
||||
wxGenericValidator(wxCheckBoxState* val);
|
||||
|
||||
wxGenericValidator(const wxGenericValidator& copyFrom);
|
||||
|
||||
|
|
@ -83,6 +89,8 @@ protected:
|
|||
wxFileName* m_pFileName;
|
||||
float* m_pFloat;
|
||||
double* m_pDouble;
|
||||
wxColour* m_pColour;
|
||||
wxCheckBoxState* m_pCheckBoxState;
|
||||
|
||||
private:
|
||||
wxDECLARE_CLASS(wxGenericValidator);
|
||||
|
|
|
|||
|
|
@ -162,6 +162,11 @@ public:
|
|||
const wxString& name = wxListBoxNameStr);
|
||||
///@}
|
||||
|
||||
/**
|
||||
return true if the listbox allows multiple selection
|
||||
*/
|
||||
bool HasMultipleSelection() const
|
||||
|
||||
/**
|
||||
Deselects an item in the list box.
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,16 @@
|
|||
- wxButton, wxRadioButton, wxToggleButton, wxBitmapToggleButton, wxSpinButton
|
||||
- wxCheckBox, wxRadioBox, wxComboBox, wxListBox, wxCheckListBox
|
||||
- wxGauge, wxSlider, wxScrollBar, wxChoice, wxStaticText
|
||||
- wxSpinCtrl, wxTextCtrl
|
||||
- wxSpinCtrl, wxTextCtrl, wxColourPickerCtrl (since wxWidgets 3.3.0 or later).
|
||||
|
||||
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. wxColourPickerCtrl support.
|
||||
A 3-state wxCheckBox can use wxCheckBoxState.
|
||||
|
||||
For more information, please see @ref overview_validator.
|
||||
|
||||
@library{wxcore}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@
|
|||
#if wxUSE_TOGGLEBTN
|
||||
#include "wx/tglbtn.h"
|
||||
#endif
|
||||
#if wxUSE_COLOURPICKERCTRL
|
||||
#include "wx/clrpicker.h"
|
||||
#endif
|
||||
#include "wx/filename.h"
|
||||
|
||||
#include "wx/valgen.h"
|
||||
|
|
@ -99,6 +102,18 @@ wxGenericValidator::wxGenericValidator(double *val)
|
|||
m_pDouble = val;
|
||||
}
|
||||
|
||||
wxGenericValidator::wxGenericValidator(wxColour* val)
|
||||
{
|
||||
Initialize();
|
||||
m_pColour = val;
|
||||
}
|
||||
|
||||
wxGenericValidator::wxGenericValidator(wxCheckBoxState* val)
|
||||
{
|
||||
Initialize();
|
||||
m_pCheckBoxState = val;
|
||||
}
|
||||
|
||||
wxGenericValidator::wxGenericValidator(const wxGenericValidator& val)
|
||||
: wxValidator()
|
||||
{
|
||||
|
|
@ -119,6 +134,8 @@ 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;
|
||||
m_pCheckBoxState = val.m_pCheckBoxState;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -139,6 +156,11 @@ bool wxGenericValidator::TransferToWindow()
|
|||
pControl->SetValue(*m_pBool);
|
||||
return true;
|
||||
}
|
||||
else if (m_pCheckBoxState && pControl->Is3State())
|
||||
{
|
||||
pControl->Set3StateValue(*m_pCheckBoxState);
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#if wxUSE_RADIOBTN
|
||||
|
|
@ -377,6 +399,17 @@ bool wxGenericValidator::TransferToWindow()
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!pControl->HasMultipleSelection(),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
pControl->Check(*m_pInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
|
|
@ -398,6 +431,31 @@ bool wxGenericValidator::TransferToWindow()
|
|||
for ( i = 0 ; i < count; i++ )
|
||||
pControl->SetSelection(m_pArrayInt->Item(i));
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!pControl->HasMultipleSelection(),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
pControl->SetSelection(*m_pInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
} 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
|
||||
|
|
@ -425,6 +483,11 @@ bool wxGenericValidator::TransferFromWindow()
|
|||
*m_pBool = pControl->GetValue() ;
|
||||
return true;
|
||||
}
|
||||
else if (m_pCheckBoxState && pControl->Is3State())
|
||||
{
|
||||
*m_pCheckBoxState = pControl->Get3StateValue();
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#if wxUSE_RADIOBTN
|
||||
|
|
@ -654,6 +717,26 @@ bool wxGenericValidator::TransferFromWindow()
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!pControl->HasMultipleSelection(),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
|
||||
size_t i,
|
||||
count = pControl->GetCount();
|
||||
for ( i = 0; i < count; i++ )
|
||||
{
|
||||
if (pControl->IsChecked(i))
|
||||
{
|
||||
*m_pInt = i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
|
|
@ -676,10 +759,35 @@ bool wxGenericValidator::TransferFromWindow()
|
|||
m_pArrayInt->Add(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!pControl->HasMultipleSelection(),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
|
||||
*m_pInt = pControl->GetSelection();
|
||||
|
||||
return true;
|
||||
}
|
||||
} 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;
|
||||
|
|
@ -702,6 +810,8 @@ void wxGenericValidator::Initialize()
|
|||
m_pFileName = nullptr;
|
||||
m_pFloat = nullptr;
|
||||
m_pDouble = nullptr;
|
||||
m_pColour = nullptr;
|
||||
m_pCheckBoxState = nullptr;
|
||||
}
|
||||
|
||||
#endif // wxUSE_VALIDATORS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue