Don't set maximum text length for non-text wxPG properties

Setting the limit for the length of the text the user can enter in the text editor makes sense only for properties having text editors so in wxPGProperty::SetMaxLength() should be done a check whether to actually set a limit or not depending on the kind of editor used.
wxPropertyGridInterface::SetPropertyMaxLength() should be implemented on top of wxPGProperty::SetMaxLength() to proceed only if maximum length was actually set.
This commit is contained in:
Artur Wieczorek
2019-05-26 00:39:48 +02:00
parent e45c6b0dd1
commit 7a29f5dd2c
5 changed files with 46 additions and 18 deletions

View File

@@ -666,20 +666,18 @@ bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id, int maxLen )
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
wxPropertyGrid* pg = m_pState->GetGrid();
if ( !p->SetMaxLength(maxLen) )
return false;
p->m_maxLen = (short) maxLen;
wxPropertyGrid* pg = m_pState->GetGrid();
// Adjust control if selected currently
if ( pg == p->GetGrid() && p == m_pState->GetSelection() )
{
wxWindow* wnd = pg->GetEditorControl();
wxTextCtrl* tc = wxDynamicCast(wnd,wxTextCtrl);
if ( tc )
tc->SetMaxLength( maxLen );
else
// Not a text ctrl
return false;
wxTextCtrl* tc = wxDynamicCast(wnd, wxTextCtrl);
wxCHECK_MSG(tc, false, "Text ctrl is expected here");
tc->SetMaxLength(maxLen);
}
return true;