Numerous improvements and nib2cib support for CPControl, CPSlider, CPTextField, CPWebView, etc.

Fixed broken @accessors preprocessing.
This commit is contained in:
Tom Robinson committed 2008-10-27 04:54:43 -07:00
1 parent 745df353c4
commit 7a3fab1d6d
18 files changed
+746 -200

No files matched your search

+132 -24
View File
@@ -99,9 +99,6 @@ var CPControlBlackColor = [CPColor blackColor];
SEL _action;
int _sendActionOn;
CPColor _backgroundColor;
CPColor _highlightedBackgroundColor;
CPDictionary _backgroundColors;
CPString _currentBackgroundColorName;
}
@@ -265,6 +262,22 @@ var CPControlBlackColor = [CPColor blackColor];
[super mouseUp:anEvent];
}
- (void)mouseDown:(CPEvent)anEvent
{
if (_sendActionOn & CPLeftMouseDownMask && CPRectContainsPoint([self bounds], [self convertPoint:[anEvent locationInWindow] fromView:nil]))
[self sendAction:_action to:_target];
[super mouseDown:anEvent];
}
- (void)mouseDragged:(CPEvent)anEvent
{
if (_sendActionOn & CPLeftMouseDraggedMask && CPRectContainsPoint([self bounds], [self convertPoint:[anEvent locationInWindow] fromView:nil]))
[self sendAction:_action to:_target];
[super mouseDragged:anEvent];
}
/*!
Causes <code>anAction</code> to be sent to <code>anObject</code>.
@param anAction the action to send
@@ -272,23 +285,38 @@ var CPControlBlackColor = [CPColor blackColor];
*/
- (void)sendAction:(SEL)anAction to:(id)anObject
{
//CPLog.debug("Sending action: " + anAction + " from " + self + " to " + anObject);
[CPApp sendAction:anAction to:anObject from:self];
}
/*!
Returns the receiver's float value
*/
- (float)floatValue
- (int)sendActionOn:(int)mask
{
return _value ? parseFloat(_value, 10) : 0.0;
var previousMask = _sendActionOn;
_sendActionOn = mask;
return previousMask;
}
/*!
Sets the receiver's float value
Returns whether the control can continuously send its action messages.
*/
- (void)setFloatValue:(float)aValue
- (BOOL)isContinuous
{
[self setObjectValue:aValue];
// Some subclasses should redefine this with CPLeftMouseDraggedMask
return (_sendActionOn & CPPeriodicMask) != 0;
}
/*!
Sets whether the cell can continuously send its action messages.
*/
- (void)setContinuous:(BOOL)flag
{
// Some subclasses should redefine this with CPLeftMouseDraggedMask
if (flag)
_sendActionOn |= CPPeriodicMask;
else
_sendActionOn &= ~CPPeriodicMask;
}
/*!
@@ -307,10 +335,27 @@ var CPControlBlackColor = [CPColor blackColor];
_value = anObject;
}
/*!
Returns the receiver's float value
*/
- (float)floatValue
{
var floatValue = parseFloat(_value, 10);
return isNaN(floatValue) ? 0.0 : floatValue;
}
/*!
Sets the receiver's float value
*/
- (void)setFloatValue:(float)aValue
{
[self setObjectValue:aValue];
}
/*!
Returns the receiver's double value
*/
- (id)doubleValue
- (double)doubleValue
{
return [self floatValue];
}
@@ -318,7 +363,7 @@ var CPControlBlackColor = [CPColor blackColor];
/*!
Set's the receiver's double value
*/
- (void)setDoubleValue:(id)anObject
- (void)setDoubleValue:(double)anObject
{
[self setObjectValue:anObject];
}
@@ -326,15 +371,32 @@ var CPControlBlackColor = [CPColor blackColor];
/*!
Returns the receiver's int value
*/
- (id)intValue
- (int)intValue
{
return _value ? parseInt(_value, 10) : 0;
return FLOOR([self floatValue]);
}
/*!
Set's the receiver's int value
*/
- (void)setIntValue:(id)anObject
- (void)setIntValue:(int)anObject
{
[self setObjectValue:anObject];
}
/*!
Returns the receiver's int value
*/
- (int)integerValue
{
return FLOOR([self floatValue]);
}
/*!
Set's the receiver's int value
*/
- (void)setIntegerValue:(int)anObject
{
[self setObjectValue:anObject];
}
@@ -342,19 +404,61 @@ var CPControlBlackColor = [CPColor blackColor];
/*!
Returns the receiver's int value
*/
- (id)stringValue
- (CPString)stringValue
{
return _value ? ""+_value : "";
return _value ? String(_value) : "";
}
/*!
Set's the receiver's int value
*/
- (void)setStringValue:(id)anObject
- (void)setStringValue:(CPString)anObject
{
[self setObjectValue:anObject];
}
- (void)takeDoubleValueFrom:(id)sender
{
if ([sender respondsToSelector:@selector(doubleValue)])
[self setDoubleValue:[sender doubleValue]];
}
- (void)takeFloatValueFrom:(id)sender
{
if ([sender respondsToSelector:@selector(floatValue)])
[self setFloatValue:[sender floatValue]];
}
- (void)takeIntegerValueFrom:(id)sender
{
if ([sender respondsToSelector:@selector(integerValue)])
[self setIntegerValue:[sender integerValue]];
}
- (void)takeIntValueFrom:(id)sender
{
if ([sender respondsToSelector:@selector(intValue)])
[self setIntValue:[sender intValue]];
}
- (void)takeObjectValueFrom:(id)sender
{
if ([sender respondsToSelector:@selector(objectValue)])
[self setObjectValue:[sender objectValue]];
}
- (void)takeStringValueFrom:(id)sender
{
if ([sender respondsToSelector:@selector(stringValue)])
[self setStringValue:[sender stringValue]];
}
- (void)setBackgroundColor:(CPColor)aColor
{
_backgroundColors = [CPDictionary dictionary];
@@ -435,7 +539,8 @@ var CPControlBlackColor = [CPColor blackColor];
@end
var CPControlIsEnabledKey = @"CPControlIsEnabledKey",
var CPControlValueKey = @"CPControlValueKey",
CPControlIsEnabledKey = @"CPControlIsEnabledKey",
CPControlAlignmentKey = @"CPControlAlignmentKey",
CPControlFontKey = @"CPControlFontKey",
CPControlTextColorKey = @"CPControlTextColorKey",
@@ -456,7 +561,9 @@ var CPControlIsEnabledKey = @"CPControlIsEnabledKey",
if (self)
{
[self setEnabled:[aCoder decodeIntForKey:CPControlIsEnabledKey]];
[self setObjectValue:[aCoder decodeObjectForKey:CPControlValueKey]];
[self setEnabled:[aCoder decodeBoolForKey:CPControlIsEnabledKey]];
[self setAlignment:[aCoder decodeIntForKey:CPControlAlignmentKey]];
[self setFont:[aCoder decodeObjectForKey:CPControlFontKey]];
@@ -464,8 +571,7 @@ var CPControlIsEnabledKey = @"CPControlIsEnabledKey",
[self setTarget:[aCoder decodeObjectForKey:CPControlTargetKey]];
[self setAction:[aCoder decodeObjectForKey:CPControlActionKey]];
_sendActionOn = [aCoder decodeIntForKey:CPControlSendActionOnKey];
[self sendActionOn:[aCoder decodeIntForKey:CPControlSendActionOnKey]];
}
return self;
@@ -479,7 +585,9 @@ var CPControlIsEnabledKey = @"CPControlIsEnabledKey",
{
[super encodeWithCoder:aCoder];
[aCoder encodeInt:_isEnabled forKey:CPControlIsEnabledKey];
[aCoder encodeObject:_value forKey:CPControlValueKey];
[aCoder encodeBool:_isEnabled forKey:CPControlIsEnabledKey];
[aCoder encodeInt:_alignment forKey:CPControlAlignmentKey];
[aCoder encodeObject:_font forKey:CPControlFontKey];
+58 -26
View File
@@ -34,15 +34,14 @@ var CPSliderHorizontalKnobImage = nil,
*/
@implementation CPSlider : CPControl
{
double _value;
double _minValue;
double _maxValue;
double _altIncrementValue;
BOOL _isVertical;
CPView _bar;
CPView _knob;
BOOL _isVertical;
CPImageView _standardKnob;
CPView _standardVerticalBar;
CPView _standardHorizontalBar;
@@ -91,7 +90,7 @@ var CPSliderHorizontalKnobImage = nil,
- (void)setFrameSize:(CGSize)aSize
{
if(aSize.height > 21.0)
if (aSize.height > 21.0)
aSize.height = 21.0;
if (_isVertical != [self isVertical])
@@ -127,6 +126,33 @@ var CPSliderHorizontalKnobImage = nil,
return _altIncrementValue;
}
/*!
Sets the value the slider will be incremented if the user holds the <code>ALT</code> key.
*/
- (void)setAltIncrementValue:(double)anIncrementValue
{
_altIncrementValue = anIncrementValue;
}
/*!
Returns whether the control can continuously send its action messages.
*/
- (BOOL)isContinuous
{
return (_sendActionOn & CPLeftMouseDraggedMask) != 0;
}
/*!
Sets whether the cell can continuously send its action messages.
*/
- (void)setContinuous:(BOOL)flag
{
if (flag)
_sendActionOn |= CPLeftMouseDraggedMask;
else
_sendActionOn &= ~CPLeftMouseDraggedMask;
}
/*!
Returns the thickness of the slider's knob. This value is in pixels,
and is the size of the knob along the slider's track.
@@ -222,14 +248,6 @@ var CPSliderHorizontalKnobImage = nil,
}
}
/*!
Sets the value the slider will be incremented if the user holds the <code>ALT</code> key.
*/
- (void)setAltIncrementValue:(double)anIncrementValue
{
_altIncrementValue = anIncrementValue;
}
/*!
Returns <code>YES</code> if the slider is vertical.
*/
@@ -280,20 +298,28 @@ var CPSliderHorizontalKnobImage = nil,
/*!
Sets the slider's value
@param aValue the new slider value
@deprecated Use setFloatValue, setObjectValue, etc
*/
- (void)setValue:(double)aValue
{
_value = aValue;
[_knob setFrameOrigin:[self knobPosition]];
[self setObjectValue:aValue];
}
/*!
Returns the slider's value
@deprecated Use floatValue, objectValue, etc
*/
- (double)value
{
return _value;
return [self floatValue];
}
- (void)setObjectValue:(id)anObject
{
[super setObjectValue:anObject];
if (_knob)
[_knob setFrameOrigin:[self knobPosition]];
}
/*
@@ -306,7 +332,7 @@ var CPSliderHorizontalKnobImage = nil,
return CPPointMake(0.0, 0.0);
else
return CPPointMake(
((_value - _minValue) / (_maxValue - _minValue)) * (CPRectGetWidth([self frame]) - CPRectGetWidth([_knob frame])),
(([self floatValue] - _minValue) / (_maxValue - _minValue)) * (CPRectGetWidth([self frame]) - CPRectGetWidth([_knob frame])),
(CPRectGetHeight([self frame]) - CPRectGetHeight([_knob frame])) / 2.0);
}
@@ -330,10 +356,12 @@ var CPSliderHorizontalKnobImage = nil,
- (void)mouseUp:(CPEvent)anEvent
{
[[self knob] setImage: [self knobImage]];
[[self knob] setImage:[self knobImage]];
if ([_target respondsToSelector:@selector(sliderDidFinish:)])
[_target sliderDidFinish:self];
[super mouseUp:anEvent];
}
- (void)mouseDown:(CPEvent)anEvent
@@ -342,8 +370,9 @@ var CPSliderHorizontalKnobImage = nil,
_value = [self valueForKnobPosition:[_knob frame].origin];
[[self knob] setImage: [self pushedKnobImage]];
[self sendAction:_action to:_target];
[[self knob] setImage:[self pushedKnobImage]];
[super mouseDown:anEvent];
}
- (void)mouseDragged:(CPEvent)anEvent
@@ -351,15 +380,16 @@ var CPSliderHorizontalKnobImage = nil,
[_knob setFrameOrigin:[self constrainKnobPosition:[self convertPoint:[anEvent locationInWindow] fromView:nil]]];
_value = [self valueForKnobPosition:[_knob frame].origin];
[self sendAction:_action to:_target];
[super mouseDragged:anEvent];
}
@end
var CPSliderMinValueKey = @"CPSliderMinValueKey",
CPSliderMaxValueKey = @"CPSliderMaxValueKey",
CPSliderValueKey = @"CPSliderValueKey";
var CPSliderMinValueKey = @"CPSliderMinValueKey",
CPSliderMaxValueKey = @"CPSliderMaxValueKey",
CPSliderAltIncrValueKey = @"CPSliderAltIncrValueKey",
CPSliderIsVerticalKey = @"CPSliderIsVerticalKey";
@implementation CPSlider (CPCoding)
@@ -374,9 +404,10 @@ var CPSliderMinValueKey = @"CPSliderMinValueKey",
if (self)
{
_value = [aCoder decodeDoubleForKey:CPSliderValueKey];
_minValue = [aCoder decodeDoubleForKey:CPSliderMinValueKey];
_maxValue = [aCoder decodeDoubleForKey:CPSliderMaxValueKey];
_altIncrementValue = [aCoder decodeDoubleForKey:CPSliderAltIncrValueKey];
_isVertical = [aCoder decodeDoubleForKey:CPSliderIsVerticalKey];
_bar = [self bar];
_knob = [self knob];
@@ -406,9 +437,10 @@ var CPSliderMinValueKey = @"CPSliderMinValueKey",
_subviews = subviews;
[aCoder encodeDouble:_value forKey:CPSliderValueKey];
[aCoder encodeDouble:_minValue forKey:CPSliderMinValueKey];
[aCoder encodeDouble:_maxValue forKey:CPSliderMaxValueKey];
[aCoder encodeDouble:_altIncrementValue forKey:CPSliderAltIncrValueKey];
[aCoder encodeBool:_isVertical forKey:CPSliderIsVerticalKey];
}
@end
+150 -52
View File
@@ -79,7 +79,8 @@ var TOP_PADDING = 4.0,
var CPTextFieldDOMInputElement = nil;
#endif
var _CPTextFieldSquareBezelColor = nil;
var _CPTextFieldSquareBezelColor = nil,
_CPTextFieldRoundedBezelColor = nil;
@implementation CPString (CPTextFieldAdditions)
@@ -98,17 +99,18 @@ var _CPTextFieldSquareBezelColor = nil;
*/
@implementation CPTextField : CPControl
{
BOOL _isEditable;
BOOL _isSelectable;
BOOL _isBordered;
BOOL _isBezeled;
CPTextFieldBezelStyle _bezelStyle;
BOOL _isEditable;
BOOL _isSelectable;
id _value;
id _placeholderString;
BOOL _drawsBackground;
CPLineBreakMode _lineBreakMode;
CPColor _textFieldBackgroundColor;
id _placeholderString;
id _delegate;
@@ -153,6 +155,8 @@ var _CPTextFieldSquareBezelColor = nil;
_value = @"";
_placeholderString = @"";
_sendActionOn = CPKeyUpMask | CPKeyDownMask;
#if PLATFORM(DOM)
_DOMTextElement = document.createElement("div");
_DOMTextElement.style.position = "absolute";
@@ -267,33 +271,103 @@ var _CPTextFieldSquareBezelColor = nil;
return _isBordered;
}
/*!
Sets whether the textfield will have a background drawn.
@param shouldDrawBackground <code>YES</code> makes the textfield draw a background
*/
- (void)setDrawsBackground:(BOOL)shouldDrawBackground
{
if (_drawsBackground == shouldDrawBackground)
return;
_drawsBackground = shouldDrawBackground;
[self _updateBackground];
}
/*!
Returns <code>YES</code> if the textfield draws a background.
*/
- (BOOL)drawsBackground
{
return _drawsBackground;
}
/*!
Sets the background color, which is shown for non-bezeled text fields with drawsBackground set to YES
@param aColor The background color
*/
- (void)setTextFieldBackgroundColor:(BOOL)aColor
{
if (_textFieldBackgroundColor == aColor)
return;
_textFieldBackgroundColor = aColor;
[self _updateBackground];
}
/*!
Returns the background color.
*/
- (BOOL)textFieldBackgroundColor
{
return _textFieldBackgroundColor;
}
/* @ignore */
- (void)_updateBackground
{
if (_isBordered && _bezelStyle == CPTextFieldSquareBezel && _isBezeled)
CPLog.trace(_CPTextFieldSquareBezelColor + "," + _isBezeled + "," + _bezelStyle + "," + _drawsBackground);
if (_isBezeled)
{
if (!_CPTextFieldSquareBezelColor)
if (_bezelStyle == CPTextFieldSquareBezel)
{
var bundle = [CPBundle bundleForClass:[CPTextField class]];
if (!_CPTextFieldSquareBezelColor)
{
var bundle = [CPBundle bundleForClass:[CPTextField class]];
_CPTextFieldSquareBezelColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare0.png"] size:CGSizeMake(2.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare1.png"] size:CGSizeMake(1.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare2.png"] size:CGSizeMake(2.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare3.png"] size:CGSizeMake(2.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare5.png"] size:CGSizeMake(2.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare6.png"] size:CGSizeMake(2.0, 2.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare7.png"] size:CGSizeMake(1.0, 2.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare8.png"] size:CGSizeMake(2.0, 2.0)]
]]];
_CPTextFieldSquareBezelColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare0.png"] size:CGSizeMake(2.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare1.png"] size:CGSizeMake(1.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare2.png"] size:CGSizeMake(2.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare3.png"] size:CGSizeMake(2.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare5.png"] size:CGSizeMake(2.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare6.png"] size:CGSizeMake(2.0, 2.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare7.png"] size:CGSizeMake(1.0, 2.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelSquare8.png"] size:CGSizeMake(2.0, 2.0)]
]]];
}
[self setBackgroundColor:_CPTextFieldSquareBezelColor];
}
else if (_bezelStyle == CPTextFieldRoundedBezel)
{
if (!_CPTextFieldRoundedBezelColor)
{
var bundle = [CPBundle bundleForClass:[CPTextField class]];
_CPTextFieldRoundedBezelColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelRounded0.png"] size:CGSizeMake(12.0, 22.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelRounded1.png"] size:CGSizeMake(16.0, 22.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPTextField/CPTextFieldBezelRounded2.png"] size:CGSizeMake(12.0, 22.0)]
] isVertical:NO]];
}
[self setBackgroundColor:_CPTextFieldRoundedBezelColor];
}
[self setBackgroundColor:_CPTextFieldSquareBezelColor];
}
else
[self setBackgroundColor:nil];
{
if (_drawsBackground)
[self setBackgroundColor:_textFieldBackgroundColor];
else
[self setBackgroundColor:nil];
// FIXME: do something for bordered textfields
//if (_isBordered)
}
}
/* @ignore */
@@ -307,7 +381,7 @@ var _CPTextFieldSquareBezelColor = nil;
{
var string = [self stringValue];
[self setStringValue:@""];
[self setStringValue:""];
#if PLATFORM(DOM)
var element = [[self class] _inputElement];
@@ -323,12 +397,18 @@ var _CPTextFieldSquareBezelColor = nil;
//element.style.top = _DOMTextElement.style.top;
_DOMElement.appendChild(element);
window.setTimeout(function() { element.focus(); }, 0.0);
window.setTimeout(function()
{
element.focus();
[[CPRunLoop currentRunLoop] performSelectors];
}, 0.0);
element.onblur = function ()
{
[self setObjectValue:element.value];
[self sendAction:[self action] to:[self target]];
[[self window] makeFirstResponder:nil];
[[CPRunLoop currentRunLoop] performSelectors];
};
//element.onblur = function() { objj_debug_print_backtrace(); }
@@ -339,7 +419,7 @@ var _CPTextFieldSquareBezelColor = nil;
//all key presses might trigger the delegate method controlTextDidChange:
//record the current string value before we allow this keydown to propagate
_textDidChangeValue = [self stringValue];
[[CPRunLoop currentRunLoop] performSelectors];
return true;
}
@@ -349,13 +429,15 @@ var _CPTextFieldSquareBezelColor = nil;
if (aDOMEvent.keyCode == 13)
{
if(aDOMEvent.preventDefault)
if (aDOMEvent.preventDefault)
aDOMEvent.preventDefault();
else if(aDOMEvent.stopPropagation)
if (aDOMEvent.stopPropagation)
aDOMEvent.stopPropagation();
aDOMEvent.cancelBubble = true;
element.blur();
}
}
[[CPRunLoop currentRunLoop] performSelectors];
};
//inspect keyup to detect changes in order to trigger controlTextDidChange: delegate method
@@ -369,11 +451,12 @@ var _CPTextFieldSquareBezelColor = nil;
//call to CPControls methods for posting the notification
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
}
[[CPRunLoop currentRunLoop] performSelectors];
};
// If current value is the placeholder value, remove it to allow user to update.
if ([string lowercaseString] == [[self placeholderString] lowercaseString])
[self setStringValue:@""];
[self setStringValue:""];
//post CPControlTextDidBeginEditingNotification
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
@@ -396,7 +479,7 @@ var _CPTextFieldSquareBezelColor = nil;
element.onkeypress = nil;
_DOMElement.removeChild(element);
[self setStringValue:element.value];
[self setStringValue:element.value]; // redundant?
// If textfield has no value, then display the placeholderValue
if (!_value || _value === "")
@@ -514,7 +597,7 @@ var _CPTextFieldSquareBezelColor = nil;
/*!
Returns the string the text field.
*/
- (CPString)stringValue
- (id)objectValue
{
// All of this needs to be better.
#if PLATFORM(DOM)
@@ -522,10 +605,10 @@ var _CPTextFieldSquareBezelColor = nil;
return [[self class] _inputElement].value;
#endif
//if the content is the same as the placeholder value, return "" instead
if ([_value lowercaseString] == [[self placeholderString] lowercaseString])
if ([super objectValue] == [self placeholderString])
return "";
return [super stringValue];
return [super objectValue];
}
/*
@@ -603,10 +686,15 @@ var _CPTextFieldSquareBezelColor = nil;
@end
var CPTextFieldIsSelectableKey = @"CPTextFieldIsSelectableKey",
CPTextFieldLineBreakModeKey = @"CPTextFieldLineBreakModeKey",
CPTextFieldStringValueKey = @"CPTextFieldStringValueKey",
CPTextFieldIsEditableKey = @"CPTextFieldIsEditableKey";
var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
CPTextFieldIsSelectableKey = "CPTextFieldIsSelectableKey",
CPTextFieldIsBorderedKey = "CPTextFieldIsBorderedKey",
CPTextFieldIsBezeledKey = "CPTextFieldIsBezeledKey",
CPTextFieldBezelStyleKey = "CPTextFieldBezelStyleKey",
CPTextFieldDrawsBackgroundKey = "CPTextFieldDrawsBackgroundKey",
CPTextFieldLineBreakModeKey = "CPTextFieldLineBreakModeKey",
CPTextFieldBackgroundColorKey = "CPTextFieldBackgroundColorKey",
CPTextFieldPlaceholderStringKey = "CPTextFieldPlaceholderStringKey";
@implementation CPTextField (CPCoding)
@@ -625,11 +713,8 @@ var CPTextFieldIsSelectableKey = @"CPTextFieldIsSelectableKey",
if (self)
{
var bounds = [self bounds];
_value = @"";
#if PLATFORM(DOM)
var bounds = [self bounds];
_DOMTextElement.style.position = "absolute";
_DOMTextElement.style.top = TOP_PADDING + "px";
_DOMTextElement.style.left = HORIZONTAL_PADDING + "px";
@@ -642,10 +727,17 @@ var CPTextFieldIsSelectableKey = @"CPTextFieldIsSelectableKey",
#endif
[self setEditable:[aCoder decodeBoolForKey:CPTextFieldIsEditableKey]];
[self setSelectable:[aCoder decodeBoolForKey:CPTextFieldIsSelectableKey]];
[self setLineBreakMode:[aCoder decodeIntForKey:CPTextFieldLineBreakModeKey]];
[self setSelectable:[aCoder decodeBoolForKey:CPTextFieldIsSelectableKey]];
[self setStringValue:[aCoder decodeObjectForKey:CPTextFieldStringValueKey]];
[self setBordered:[aCoder decodeBoolForKey:CPTextFieldIsBorderedKey]];
[self setBezeled:[aCoder decodeBoolForKey:CPTextFieldIsBezeledKey]];
[self setBezelStyle:[aCoder decodeIntForKey:CPTextFieldBezelStyleKey]];
[self setDrawsBackground:[aCoder decodeBoolForKey:CPTextFieldDrawsBackgroundKey]];
[self setLineBreakMode:[aCoder decodeIntForKey:CPTextFieldLineBreakModeKey]];
[self setTextFieldBackgroundColor:[aCoder decodeObjectForKey:CPTextFieldBackgroundColorKey]];
[self setPlaceholderString:[aCoder decodeObjectForKey:CPTextFieldPlaceholderStringKey]];
}
return self;
@@ -659,12 +751,18 @@ var CPTextFieldIsSelectableKey = @"CPTextFieldIsSelectableKey",
{
[super encodeWithCoder:aCoder];
[aCoder encodeBool:_isSelectable forKey:CPTextFieldIsSelectableKey];
[aCoder encodeInt:_lineBreakMode forKey:CPTextFieldLineBreakModeKey];
[aCoder encodeObject:_value forKey:CPTextFieldStringValueKey];
[aCoder encodeBool:_isEditable forKey:CPTextFieldIsEditableKey];
[aCoder encodeBool:_isSelectable forKey:CPTextFieldIsSelectableKey];
[aCoder encodeBool:_isBordered forKey:CPTextFieldIsBorderedKey];
[aCoder encodeBool:_isBezeled forKey:CPTextFieldIsBezeledKey];
[aCoder encodeInt:_bezelStyle forKey:CPTextFieldBezelStyleKey];
[aCoder encodeBool:_drawsBackground forKey:CPTextFieldDrawsBackgroundKey];
[aCoder encodeInt:_lineBreakMode forKey:CPTextFieldLineBreakModeKey];
[aCoder encodeObject:_textFieldBackgroundColor forKey:CPTextFieldBackgroundColorKey];
[aCoder encodeObject:_placeholderString forKey:CPTextFieldPlaceholderStringKey];
}
@end
+2
View File
@@ -1794,6 +1794,8 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
_displayHash = [self hash];
[self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]];
[self setNeedsDisplay:YES];
}
return self;
+122 -55
View File
@@ -71,45 +71,91 @@ CPWebViewProgressFinishedNotification = "CPWebViewProgressFinishedNoti
_mainFrameURL = nil;
_backwardStack = [];
_forwardStack = [];
_ignoreLoadEvent = NO;
_iframe = document.createElement("iframe");
_iframe.name = "iframe_" + Math.floor(Math.random()*10000);
_iframe.style.width = "100%";
_iframe.style.height = "100%";
_iframe.style.borderWidth = "0px";
var loadCallback = function() {
// HACK: this block handles the case where we don't know about loads initiated by the user clicking a link
if (!_ignoreLoadEvent)
{
// post the start load notification
[self _startedLoading];
if (_mainFrameURL)
[_backwardStack addObject:_mainFrameURL];
// FIXME: this doesn't actually get the right URL for different domains. Probably not be possible due to browser security restrictions.
_mainFrameURL = _iframe.src;
[_forwardStack removeAllObjects];
}
_ignoreLoadEvent = NO;
[self _finishedLoading]
}
if (_iframe.addEventListener)
_iframe.addEventListener("load", loadCallback, false);
else if (_iframe.attachEvent)
_iframe.attachEvent("onload", loadCallback);
_DOMElement.appendChild(_iframe);
[self _initDOMWithFrame:aFrame];
}
return self;
}
- (id)_initDOMWithFrame:(CPRect)aFrame
{
_ignoreLoadEvent = NO;
_iframe = document.createElement("iframe");
_iframe.name = "iframe_" + Math.floor(Math.random()*10000);
_iframe.style.width = "100%";
_iframe.style.height = "100%";
_iframe.style.borderWidth = "0px";
[self setDrawsBackground:YES];
var loadCallback = function() {
// HACK: this block handles the case where we don't know about loads initiated by the user clicking a link
if (!_ignoreLoadEvent)
{
// post the start load notification
[self _startedLoading];
if (_mainFrameURL)
[_backwardStack addObject:_mainFrameURL];
// FIXME: this doesn't actually get the right URL for different domains. Probably not be possible due to browser security restrictions.
_mainFrameURL = _iframe.src;
[_forwardStack removeAllObjects];
}
_ignoreLoadEvent = NO;
[self _finishedLoading]
}
if (_iframe.addEventListener)
_iframe.addEventListener("load", loadCallback, false);
else if (_iframe.attachEvent)
_iframe.attachEvent("onload", loadCallback);
_DOMElement.appendChild(_iframe);
}
// IBActions
- (IBAction)takeStringURLFrom:(id)sender
{
[self setMainFrameURL:[sender stringValue]];
}
- (IBAction)goBack:(id)sender
{
[self goBack];
}
- (IBAction)goForward:(id)sender
{
[self goForward];
}
- (IBAction)stopLoading:(id)sender
{
// FIXME: what to do?
}
- (IBAction)reload:(id)sender
{
[self _loadMainFrameURL];
}
- (IBAction)print:(id)sender
{
try
{
[self window].print();
}
catch (e)
{
alert('Please click the webpage and select "Print" from the "File" menu');
}
}
- (BOOL)drawsBackground
{
return _iframe.style.backgroundColor != "";
@@ -120,11 +166,6 @@ CPWebViewProgressFinishedNotification = "CPWebViewProgressFinishedNoti
_iframe.style.backgroundColor = drawsBackround ? "white" : "";
}
- (CPString)mainFrameURL
{
return _mainFrameURL;
}
- (void)_loadMainFrameURL
{
[self _startedLoading];
@@ -149,19 +190,19 @@ CPWebViewProgressFinishedNotification = "CPWebViewProgressFinishedNoti
[_frameLoadDelegate webView:self didFinishLoadForFrame:nil]; // FIXME: give this a frame somehow?
}
- (CPString)mainFrameURL
{
return _mainFrameURL;
}
- (void)setMainFrameURL:(CPString)URLString
{
if (_mainFrameURL)
[_backwardStack addObject:_mainFrameURL];
_mainFrameURL = URLString;
[_forwardStack removeAllObjects];
[self _loadMainFrameURL];
}
- (IBAction)takeStringURLFrom:(id)sender
{
[self setMainFrameURL:[sender stringValue]];
[self _loadMainFrameURL];
}
- (BOOL)goBack
@@ -196,16 +237,6 @@ CPWebViewProgressFinishedNotification = "CPWebViewProgressFinishedNoti
return NO;
}
- (IBAction)goBack:(id)sender
{
[self goBack];
}
- (IBAction)goForward:(id)sender
{
[self goForward];
}
- (BOOL)canGoBack
{
return (_backwardStack.length > 0);
@@ -377,3 +408,39 @@ CPWebViewProgressFinishedNotification = "CPWebViewProgressFinishedNoti
}
@end
@implementation CPWebView (CPCoding)
/*!
Initializes the web view from the data in a coder.
@param aCoder the coder from which to read the data
@return the initialized web view
*/
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
// FIXME: encode/decode these?
_mainFrameURL = nil;
_backwardStack = [];
_forwardStack = [];
[self _initDOMWithFrame:[self frame]];
}
return self;
}
/*!
Writes out the web view's instance information to a coder.
@param aCoder the coder to which to write the data
*/
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
}
@end
Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

+9 -8
View File
@@ -563,10 +563,12 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe
for (ivar_name in accessors)
{
var accessor = accessors[name],
property = accessor["property"] || name,
getterName = accessor["getter"] || property,
getterCode = "(id)" + getterName + "\n{\nreturn " + name + ";\n}";
var accessor = accessors[ivar_name],
property = accessor["property"] || ivar_name;
// getter
var getterName = accessor["getter"] || property,
getterCode = "(id)" + getterName + "\n{\nreturn " + ivar_name + ";\n}";
if (IS_NOT_EMPTY(instance_methods))
CONCAT(instance_methods, ",\n");
@@ -582,16 +584,15 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe
if (!setterName)
{
var start = property.charAt(0) == '_' ? 1 : 0;
setterName = "set" + property.substr(start, 1).toUpperCase() + property.substring(start + 1) + ":";
setterName = (start ? "_" : "") + "set" + property.substr(start, 1).toUpperCase() + property.substring(start + 1) + ":";
}
var setterCode = "(void)" + setterName + "(id)newValue\n{\n";
if (accessor["copy"])
setterCode += "if (" + name + " !== newValue)\n" + name + " = [newValue copy];\n}";
setterCode += "if (" + ivar_name + " !== newValue)\n" + ivar_name + " = [newValue copy];\n}";
else
setterCode += name + " = newValue;\n}";
setterCode += ivar_name + " = newValue;\n}";
if (IS_NOT_EMPTY(instance_methods))
CONCAT(instance_methods, ",\n");
+5 -9
View File
@@ -22,24 +22,20 @@
@import "NSButton.j"
@import "NSCell.j"
@import "NSColor.j"
@import "NSControl.j"
@import "NSCustomObject.j"
@import "NSCustomView.j"
@import "NSFont.j"
@import "NSIBObjectData.j"
print("1");
@import "NSNibConnector.j"
print("1");
@import "NSResponder.j"
print("1");
@import "NSSlider.j"
print("1");
@import "NSView.j"
print("1");
@import "NSWindowTemplate.j"
print("1");
@import "NSSplitView.j"
print("1");
@import "NSTextField.j"
@import "NSView.j"
@import "NSWindowTemplate.j"
@import "WebView.j"
function CP_NSMapClassName(aClassName)
{
-3
View File
@@ -45,9 +45,6 @@
[self setBezelStyle:[cell bezelStyle]];
[self setBordered:[cell isBordered]];
// FIXME
_sendActionOn = CPLeftMouseUpMask;
}
return self;
+40 -16
View File
@@ -27,11 +27,22 @@
@import "NSFont.j"
@implementation NSCell : CPObject
{
CPFont _font;
id _contents;
int _state @accessors(readonly, getter=state);
BOOL _isHighlighted @accessors(readonly, getter=isHighlighted);
BOOL _isEnabled @accessors(readonly, getter=isEnabled);
BOOL _isEditable @accessors(readonly, getter=isEditable);
BOOL _isBordered @accessors(readonly, getter=isBordered);
BOOL _isBezeled @accessors(readonly, getter=isBezeled);
BOOL _isSelectable @accessors(readonly, getter=isSelectable);
BOOL _isScrollable @accessors(readonly, getter=isScrollable);
BOOL _isContinuous @accessors(readonly, getter=isContinuous);
BOOL _wraps @accessors(readonly, getter=wraps);
CPTextAlignment _alignment @accessors(readonly, getter=alignment);
CPControlSize _controlSize @accessors(readonly, getter=controlSize);
id _objectValue @accessors(readonly, getter=objectValue);
CPFont _font @accessors(readonly, getter=font);
}
- (id)initWithCoder:(CPCoder)aCoder
@@ -40,8 +51,24 @@
if (self)
{
_font = [aCoder decodeObjectForKey:@"NSFont"];
_contents = [aCoder decodeObjectForKey:@"NSContents"];
var flags = [aCoder decodeIntForKey:@"NSCellFlags"],
flags2 = [aCoder decodeIntForKey:@"NSCellFlags2"];
_state = (flags & 0x80000000) ? CPOnState : CPOffState;
_isHighlighted = (flags & 0x40000000) ? YES : NO;
_isEnabled = (flags & 0x20000000) ? NO : YES;
_isEditable = (flags & 0x10000000) ? YES : NO;
_isBordered = (flags & 0x00800000) ? YES : NO;
_isBezeled = (flags & 0x00400000) ? YES : NO;
_isSelectable = (flags & 0x00200000) ? YES : NO;
_isScrollable = (flags & 0x00100000) ? YES : NO;
_isContinuous = (flags & 0x00080100) ? YES : NO;
_wraps = (flags & 0x00100000) ? NO : YES;
_alignment = (flags2 & 0x1c000000) >> 26;
_controlSize = (flags2 & 0xE0000) >> 17;
_objectValue = [aCoder decodeObjectForKey:@"NSContents"];
_font = [aCoder decodeObjectForKey:@"NSFont"];
}
return self;
@@ -52,18 +79,15 @@
return nil;
}
//- (void)encodeWithCoder:(CPCoder)aCoder
//{
- (CPFont)font
- (CPString)stringValue
{
return _font;
}
- (id)contents
{
return _contents;
if ([_objectValue isKindOfClass:[CPString class]])
return _objectValue;
if ([_objectValue respondsToSelector:@selector(attributedStringValue)])
return [_objectValue attributedStringValue];
return "";
}
@end
+58
View File
@@ -0,0 +1,58 @@
/*
* NSColor.j
* nib2cib
*
* Created by Thomas Robinson.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <AppKit/CPColor.j>
var NSUnknownColorSpaceModel = -1,
NSGrayColorSpaceModel = 0,
NSRGBColorSpaceModel = 1,
NSCMYKColorSpaceModel = 2,
NSLABColorSpaceModel = 3,
NSDeviceNColorSpaceModel = 4,
NSIndexedColorSpaceModel = 5,
NSPatternColorSpaceModel = 6;
@implementation CPColor (NSCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
{
//var colorSpace = [aCoder decodeIntForKey:@"NSColorSpace"];
return self = [CPColor blueColor];
}
@end
@implementation NSColor : CPColor
{
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self NS_initWithCoder:aCoder];
}
- (Class)classForKeyedArchiver
{
return [CPColor class];
}
@end
+6 -1
View File
@@ -34,12 +34,17 @@
if (self)
{
[self sendActionOn:CPLeftMouseUpMask];
var cell = [aCoder decodeObjectForKey:@"NSCell"];
_value = [cell contents];
[self setObjectValue:[cell objectValue]];
[self setFont:[cell font]];
[self setAlignment:[cell alignment]];
[self setEnabled:[aCoder decodeObjectForKey:@"NSEnabled"]];
[self setContinuous:[cell isContinuous]];
}
return self;
+2 -3
View File
@@ -34,9 +34,8 @@
_source = [aCoder decodeObjectForKey:@"NSSource"];
_destination = [aCoder decodeObjectForKey:@"NSDestination"];
_label = [aCoder decodeObjectForKey:@"NSLabel"];
#if DEBUG
CPLog(@"Connection: " + [_source description] + " " + [_destination description] + " " + _label);
#endif
CPLog.debug(@"Connection: " + [_source description] + " " + [_destination description] + " " + _label);
}
return self;
+27 -3
View File
@@ -33,10 +33,12 @@
if (self)
{
_minValue = [aCoder decodeDoubleForKey:@"NSMinValue"];
_maxValue = [aCoder decodeDoubleForKey:@"NSMaxValue"];
var cell = [aCoder decodeObjectForKey:@"NSCell"];
//_value = [aCoder decodeDoubleForKey:@"NSValue"];
_minValue = [cell minValue];
_maxValue = [cell maxValue];
_altIncrementValue = [cell altIncrementValue];
_isVertical = [cell isVertical];
}
return self;
@@ -62,5 +64,27 @@
@implementation NSSliderCell : NSCell
{
double _minValue @accessors(readonly, getter=minValue);
double _maxValue @accessors(readonly, getter=maxValue);
double _altIncrementValue @accessors(readonly, getter=altIncrementValue);
BOOL _vertical @accessors(readonly, getter=isVertical);
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
_objectValue = [aCoder decodeDoubleForKey:@"NSValue"];
_minValue = [aCoder decodeDoubleForKey:@"NSMinValue"];
_maxValue = [aCoder decodeDoubleForKey:@"NSMaxValue"];
_altIncrementValue = [aCoder decodeDoubleForKey:@"NSAltIncValue"];
_isVertical = [aCoder decodeBoolForKey:@"NSVertical"];
}
return self;
}
@end
+82
View File
@@ -0,0 +1,82 @@
@import <AppKit/CPTextField.j>
@import "NSControl.j"
@import "NSCell.j"
@implementation CPTextField (NSCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
{
self = [super NS_initWithCoder:aCoder];
if (self)
{
var cell = [aCoder decodeObjectForKey:@"NSCell"];
[self sendActionOn:CPKeyUpMask|CPKeyDownMask];
[self setEditable:[cell isEditable]];
[self setSelectable:[cell isSelectable]];
[self setBordered:[cell isBordered]];
[self setBezeled:[cell isBezeled]];
[self setBezelStyle:[cell bezelStyle]];
[self setDrawsBackground:[cell drawsBackground]];
//[self setLineBreakMode:???];
[self setTextFieldBackgroundColor:[cell backgroundColor]];
[self setPlaceholderString:[cell placeholderString]];
[self setTextColor:[cell textColor]];
CPLog.debug([self stringValue] + " => isBordered=" + [self isBordered] + ", isBezeled=" + [self isBezeled] + ", bezelStyle=" + [self bezelStyle] + "("+[cell stringValue]+", " + [cell placeholderString] + ")");
}
return self;
}
@end
@implementation NSTextField : CPTextField
{
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self NS_initWithCoder:aCoder];
}
- (Class)classForKeyedArchiver
{
return [CPTextField class];
}
@end
@implementation NSTextFieldCell : NSCell
{
CPTextFieldBezelStyle _bezelStyle @accessors(readonly, getter=bezelStyle);
BOOL _drawsBackground @accessors(readonly, getter=drawsBackground);
CPColor _backgroundColor @accessors(readonly, getter=backgroundColor);
CPColor _textColor @accessors(readonly, getter=textColor);
CPString _placeholderString @accessors(readonly, getter=placeholderString);
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
_bezelStyle = [aCoder decodeObjectForKey:@"NSTextBezelStyle"] || CPTextFieldSquareBezel;
_drawsBackground = [aCoder decodeBoolForKey:@"NSDrawsBackground"];
_backgroundColor = [aCoder decodeObjectForKey:@"NSBackgroundColor"];
_textColor = [aCoder decodeObjectForKey:@"NSTextColor"];
_placeholderString = [aCoder decodeObjectForKey:@"NSPlaceholderString"];
}
return self;
}
@end
+53
View File
@@ -0,0 +1,53 @@
/*
* WebView.j
* nib2cib
*
* Created by Thomas Robinson.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <AppKit/CPWebView.j>
@implementation CPWebView (CPCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
{
if (self = [super NS_initWithCoder:aCoder])
{
}
return self;
}
@end
@implementation WebView : CPWebView
{
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self NS_initWithCoder:aCoder];
}
- (Class)classForKeyedArchiver
{
return [CPWebView class];
}
@end