Merge pull request #10683 from Mazyod/mac-editbox-fix

Fix editbox on Mac
This commit is contained in:
minggo 2015-03-11 10:00:50 +08:00
commit c701f89329
2 changed files with 19 additions and 3 deletions

View File

@ -50,6 +50,7 @@
@property(nonatomic, retain) NSMutableDictionary* placeholderAttributes;
@property(nonatomic, readonly, getter = isEditState) BOOL editState;
@property(nonatomic, assign) void* editBox;
@property(nonatomic, assign, getter = isSecure) BOOL secure;
-(id) initWithFrame: (NSRect) frameRect editBox: (void*) editBox;
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance;

View File

@ -97,6 +97,7 @@
@synthesize placeholderAttributes = placeholderAttributes_;
@synthesize editState = editState_;
@synthesize editBox = editBox_;
@synthesize secure = secure_;
- (id) getNSWindow
{
@ -125,6 +126,7 @@
if (self)
{
editState_ = NO;
secure_ = NO;
self.textField = [[[NSTextField alloc] initWithFrame:frameRect] autorelease];
self.secureTextField = [[[NSSecureTextField alloc] initWithFrame:frameRect] autorelease];
@ -163,6 +165,16 @@
[[[self getNSWindow] contentView] doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
}
-(void) setSecure:(BOOL)secure
{
NSAssert(secure, @"Can only set this flag to true");
secure_ = secure;
[textField_.superview addSubview:secureTextField_];
[textField_ removeFromSuperview];
}
-(void) setPosition:(NSPoint) pos
{
NSRect frame = [textField_ frame];
@ -183,10 +195,14 @@
-(void) openKeyboard
{
if ([textField_ superview]) {
NSView *contentView = [[self getNSWindow] contentView];
if (!secure_) {
[contentView addSubview:textField_];
[textField_ becomeFirstResponder];
}
else {
[contentView addSubview:secureTextField_];
[secureTextField_ becomeFirstResponder];
}
}
@ -412,8 +428,7 @@ void EditBoxImplMac::setInputFlag(EditBox::InputFlag inputFlag)
switch (inputFlag)
{
case EditBox::InputFlag::PASSWORD:
[_sysEdit.textField.superview addSubview:_sysEdit.secureTextField];
[_sysEdit.textField removeFromSuperview];
_sysEdit.secure = YES;
break;
case EditBox::InputFlag::INITIAL_CAPS_WORD:
CCLOGWARN("INITIAL_CAPS_WORD not implemented");