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

@@ -1490,10 +1490,11 @@ public:
// this function usually returns Null variant.
wxVariant GetDefaultValue() const;
// Returns maximum allowed length of property's text value.
// Returns maximum allowed length of the text the user can enter in
// the property text editor.
int GetMaxLength() const
{
return (int) m_maxLen;
return m_maxLen;
}
// Determines, recursively, if all children are not unspecified.
@@ -2038,11 +2039,10 @@ protected:
FlagType m_flags;
// Maximum length (mainly for string properties). Could be in some sort of
// Maximum length (for string properties). Could be in some sort of
// wxBaseStringProperty, but currently, for maximum flexibility and
// compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
// so short int will fit in just fine.
short m_maxLen;
// compatibility, we'll stick it here.
int m_maxLen;
// Root has 0, categories etc. at that level 1, etc.
unsigned char m_depth;

View File

@@ -2001,7 +2001,13 @@ inline void wxPGProperty::SetEditor( const wxString& editorName )
inline bool wxPGProperty::SetMaxLength( int maxLen )
{
return GetGrid()->SetPropertyMaxLength(this,maxLen);
const wxPGEditor* editorClass = GetEditorClass();
if ( editorClass != wxPGEditor_TextCtrl &&
editorClass != wxPGEditor_TextCtrlAndButton )
return false;
m_maxLen = wxMax(maxLen, 0); // shouldn't be a nagative value
return true;
}
// -----------------------------------------------------------------------