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:
@@ -1490,10 +1490,11 @@ public:
|
|||||||
// this function usually returns Null variant.
|
// this function usually returns Null variant.
|
||||||
wxVariant GetDefaultValue() const;
|
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
|
int GetMaxLength() const
|
||||||
{
|
{
|
||||||
return (int) m_maxLen;
|
return m_maxLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determines, recursively, if all children are not unspecified.
|
// Determines, recursively, if all children are not unspecified.
|
||||||
@@ -2038,11 +2039,10 @@ protected:
|
|||||||
|
|
||||||
FlagType m_flags;
|
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
|
// wxBaseStringProperty, but currently, for maximum flexibility and
|
||||||
// compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
|
// compatibility, we'll stick it here.
|
||||||
// so short int will fit in just fine.
|
int m_maxLen;
|
||||||
short m_maxLen;
|
|
||||||
|
|
||||||
// Root has 0, categories etc. at that level 1, etc.
|
// Root has 0, categories etc. at that level 1, etc.
|
||||||
unsigned char m_depth;
|
unsigned char m_depth;
|
||||||
|
@@ -2001,7 +2001,13 @@ inline void wxPGProperty::SetEditor( const wxString& editorName )
|
|||||||
|
|
||||||
inline bool wxPGProperty::SetMaxLength( int maxLen )
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@@ -1577,7 +1577,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxPGProperty* GetMainParent() const;
|
wxPGProperty* GetMainParent() 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.
|
||||||
|
|
||||||
|
@remarks
|
||||||
|
0 is returned if length is not explicitly limited and the text can be
|
||||||
|
as long as it is supported by the underlying native text control
|
||||||
|
widget.
|
||||||
*/
|
*/
|
||||||
int GetMaxLength() const;
|
int GetMaxLength() const;
|
||||||
|
|
||||||
@@ -1932,7 +1939,12 @@ public:
|
|||||||
void SetLabel( const wxString& label );
|
void SetLabel( const wxString& label );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set max length of text in text editor.
|
Set maximum length of the text the user can enter in the text editor.
|
||||||
|
If it is 0, the length is not limited and the text can be as long as
|
||||||
|
it is supported by the underlying native text control widget.
|
||||||
|
|
||||||
|
@return
|
||||||
|
Returns @true if maximum length was set.
|
||||||
*/
|
*/
|
||||||
bool SetMaxLength( int maxLen );
|
bool SetMaxLength( int maxLen );
|
||||||
|
|
||||||
|
@@ -1053,7 +1053,19 @@ public:
|
|||||||
void SetPropertyImage( wxPGPropArg id, wxBitmap& bmp );
|
void SetPropertyImage( wxPGPropArg id, wxBitmap& bmp );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets max length of property's text.
|
Sets maximum length of text in property text editor.
|
||||||
|
|
||||||
|
@param id
|
||||||
|
Property name or pointer.
|
||||||
|
@param maxLen
|
||||||
|
Maximum number of characters of the text the user can enter in
|
||||||
|
the text editor. If it is 0, the length is not limited and the text
|
||||||
|
can be as long as it is supported by the the underlying native text
|
||||||
|
control widget.
|
||||||
|
@return
|
||||||
|
Returns @true if maximum length was set.
|
||||||
|
@see
|
||||||
|
wxPGProperty::SetMaxLength.
|
||||||
*/
|
*/
|
||||||
bool SetPropertyMaxLength( wxPGPropArg id, int maxLen );
|
bool SetPropertyMaxLength( wxPGPropArg id, int maxLen );
|
||||||
|
|
||||||
|
@@ -666,20 +666,18 @@ bool wxPropertyGridInterface::SetPropertyMaxLength( wxPGPropArg id, int maxLen )
|
|||||||
{
|
{
|
||||||
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
|
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
|
// Adjust control if selected currently
|
||||||
if ( pg == p->GetGrid() && p == m_pState->GetSelection() )
|
if ( pg == p->GetGrid() && p == m_pState->GetSelection() )
|
||||||
{
|
{
|
||||||
wxWindow* wnd = pg->GetEditorControl();
|
wxWindow* wnd = pg->GetEditorControl();
|
||||||
wxTextCtrl* tc = wxDynamicCast(wnd,wxTextCtrl);
|
wxTextCtrl* tc = wxDynamicCast(wnd, wxTextCtrl);
|
||||||
if ( tc )
|
wxCHECK_MSG(tc, false, "Text ctrl is expected here");
|
||||||
tc->SetMaxLength( maxLen );
|
tc->SetMaxLength(maxLen);
|
||||||
else
|
|
||||||
// Not a text ctrl
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user