Created
June 6, 2009 20:58
-
-
Save davidcann/125002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* DCTextArea.j | |
* | |
* Created by David Cann on __Date__. | |
* Copyright 2008 __MyCompanyName__. All rights reserved. | |
*/ | |
@import <Foundation/CPObject.j> | |
@implementation DCTextArea : CPControl { | |
var _DOMTextElement; | |
bool required @accessors; | |
CPString name @accessors; | |
} | |
- (id)initWithFrame:(CGRect)aFrame { | |
self = [super initWithFrame:aFrame]; | |
if (self) { | |
var padding = 2; | |
var border = 2; | |
_DOMTextElement = document.createElement("textarea"); | |
_DOMTextElement.style.position = "absolute"; | |
_DOMTextElement.style.top = "0px"; | |
_DOMTextElement.style.left = "0px"; | |
_DOMTextElement.style.width = ([self frame].size.width - (padding * 2) - border) + "px"; | |
_DOMTextElement.style.height = ([self frame].size.height - (padding * 2) - (border * 2)) + "px"; | |
_DOMTextElement.style.whiteSpace = "pre"; | |
_DOMTextElement.style.zIndex = 100; | |
if (!isIE) { | |
_DOMTextElement.style.font = _DOMElement.style.font; | |
} | |
_DOMTextElement.style.padding = padding +"px"; | |
_DOMTextElement.style.margin = "0px"; | |
_DOMTextElement.style.border = "1px solid #999999"; | |
_DOMElement.appendChild(_DOMTextElement); | |
_DOMElement.style.overflow = "visible"; // so the native browser focus glow is visible | |
} | |
return self; | |
} | |
- (BOOL)becomeFirstResponder { | |
[super becomeFirstResponder]; | |
[CPTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(focus) userInfo:nil repeats:NO]; | |
return YES; | |
} | |
- (void)focus { | |
_DOMTextElement.focus(); | |
} | |
- (void)setStringValue:(CPString)aString { | |
[super setStringValue:aString]; | |
_DOMTextElement.value = aString; | |
} | |
- (CPString)stringValue { | |
return _DOMTextElement.value; | |
} | |
- (void)setEnabled:(bool)yesNo { | |
[super setEnabled:yesNo]; | |
if ([self isEnabled] == YES) { | |
_DOMTextElement.disabled = false; | |
[self setAlphaValue:1]; | |
} else { | |
_DOMTextElement.disabled = true; | |
[self setAlphaValue:0.6]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment