X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/60d66be369d360e1528e4dd4bb65a909a8c6ac9a..e733c4ce1e24cf7e4b0b0d8362fc59aaa7a7641c:/src/osx/cocoa/textctrl.mm diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 4d4398e2d2..7ec0ff8bca 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) // Created: 1998-01-01 -// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -50,6 +49,8 @@ #include "wx/osx/private.h" #include "wx/osx/cocoa/private/textimpl.h" +#include "wx/cocoa/autorelease.h" + @interface NSView(EditableView) - (BOOL)isEditable; - (void)setEditable:(BOOL)flag; @@ -111,6 +112,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; @interface wxMaximumLengthFormatter : NSFormatter { int maxLength; + wxTextEntry* field; } @end @@ -148,12 +150,17 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; int len = [*partialStringPtr length]; if ( maxLength > 0 && len > maxLength ) { - // TODO wxEVT_TEXT_MAXLEN + field->SendMaxLenEvent(); return NO; } return YES; } +- (void) setTextEntry:(wxTextEntry*) tf +{ + field = tf; +} + @end @implementation wxNSSecureTextField @@ -183,9 +190,9 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; if ( impl ) { NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); - NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + NSView* otherView = wxOSXGetViewFromResponder(responder); - wxWidgetImpl* otherWindow = impl->FindFromWXWidget(otherView); + wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView); impl->DoNotifyFocusEvent( false, otherWindow ); } } @@ -341,9 +348,9 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; if ( impl ) { NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); - NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + NSView* otherView = wxOSXGetViewFromResponder(responder); - wxWidgetImpl* otherWindow = impl->FindFromWXWidget(otherView); + wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView); impl->DoNotifyFocusEvent( false, otherWindow ); } } @@ -515,9 +522,9 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; } NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); - NSView* otherView = [responder isKindOfClass:[NSView class]] ? (NSView*)responder : nil; + NSView* otherView = wxOSXGetViewFromResponder(responder); - wxWidgetImpl* otherWindow = impl->FindFromWXWidget(otherView); + wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView); impl->DoNotifyFocusEvent( false, otherWindow ); } } @@ -792,6 +799,7 @@ wxNSTextFieldControl::~wxNSTextFieldControl() wxString wxNSTextFieldControl::GetStringValue() const { + wxAutoNSAutoreleasePool pool; return wxCFStringRef::AsString([m_textField stringValue], m_wxPeer->GetFont().GetEncoding()); } @@ -805,6 +813,7 @@ void wxNSTextFieldControl::SetMaxLength(unsigned long len) { wxMaximumLengthFormatter* formatter = [[[wxMaximumLengthFormatter alloc] init] autorelease]; [formatter setMaxLength:len]; + [formatter setTextEntry:GetTextEntry()]; [m_textField setFormatter:formatter]; }