supporting max len event
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74191 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -80,6 +80,8 @@ public:
|
|||||||
virtual void SetSelection(long from, long to);
|
virtual void SetSelection(long from, long to);
|
||||||
virtual void SetEditable(bool editable);
|
virtual void SetEditable(bool editable);
|
||||||
|
|
||||||
|
virtual bool SendMaxLenEvent();
|
||||||
|
|
||||||
// Implementation
|
// Implementation
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
|
@@ -111,6 +111,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
|
|||||||
@interface wxMaximumLengthFormatter : NSFormatter
|
@interface wxMaximumLengthFormatter : NSFormatter
|
||||||
{
|
{
|
||||||
int maxLength;
|
int maxLength;
|
||||||
|
wxTextEntry* field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -148,12 +149,17 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
|
|||||||
int len = [*partialStringPtr length];
|
int len = [*partialStringPtr length];
|
||||||
if ( maxLength > 0 && len > maxLength )
|
if ( maxLength > 0 && len > maxLength )
|
||||||
{
|
{
|
||||||
// TODO wxEVT_TEXT_MAXLEN
|
field->SendMaxLenEvent();
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setTextEntry:(wxTextEntry*) tf
|
||||||
|
{
|
||||||
|
field = tf;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation wxNSSecureTextField
|
@implementation wxNSSecureTextField
|
||||||
@@ -805,6 +811,7 @@ void wxNSTextFieldControl::SetMaxLength(unsigned long len)
|
|||||||
{
|
{
|
||||||
wxMaximumLengthFormatter* formatter = [[[wxMaximumLengthFormatter alloc] init] autorelease];
|
wxMaximumLengthFormatter* formatter = [[[wxMaximumLengthFormatter alloc] init] autorelease];
|
||||||
[formatter setMaxLength:len];
|
[formatter setMaxLength:len];
|
||||||
|
[formatter setTextEntry:GetTextEntry()];
|
||||||
[m_textField setFormatter:formatter];
|
[m_textField setFormatter:formatter];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -224,6 +224,23 @@ bool wxTextEntry::IsEditable() const
|
|||||||
return m_editable ;
|
return m_editable ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxTextEntry::SendMaxLenEvent()
|
||||||
|
{
|
||||||
|
wxWindow *win = GetEditableWindow();
|
||||||
|
wxCHECK_MSG( win, false, "can't send an event without a window" );
|
||||||
|
|
||||||
|
wxCommandEvent event(wxEVT_TEXT_MAXLEN, win->GetId());
|
||||||
|
|
||||||
|
// do not do this as it could be very inefficient if the text control
|
||||||
|
// contains a lot of text and we're not using ref-counted wxString
|
||||||
|
// implementation -- instead, event.GetString() will query the control for
|
||||||
|
// its current text if needed
|
||||||
|
//event.SetString(win->GetValue());
|
||||||
|
|
||||||
|
event.SetEventObject(win);
|
||||||
|
return win->HandleWindowEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Undo/redo
|
// Undo/redo
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user