Merge branch 'master' into atrstring

This commit is contained in:
Ross Boucher committed 2008-11-10 10:34:36 -08:00
commit bf72b5cd13
61 files changed
+2744 -700

No files matched your search

+5 -1
View File
@@ -21,6 +21,7 @@
*/
@import "CALayer.j"
@import "CPAlert.j"
@import "CPAnimation.j"
@import "CPApplication.j"
@import "CPButton.j"
@@ -35,6 +36,8 @@
@import "CPDocument.j"
@import "CPDocumentController.j"
@import "CPEvent.j"
@import "CPFlashMovie.j"
@import "CPFlashView.j"
@import "CPFont.j"
@import "CPFontManager.j"
@import "CPGeometry.j"
@@ -47,13 +50,14 @@
@import "CPPopUpButton.j"
@import "CPProgressIndicator.j"
@import "CPResponder.j"
@import "CPScroller.j"
@import "CPScrollView.j"
@import "CPScroller.j"
@import "CPSecureTextField.j"
@import "CPSegmentedControl.j"
@import "CPShadow.j"
@import "CPSlider.j"
@import "CPSplitView.j"
@import "CPTabView.j"
@import "CPTextField.j"
@import "CPToolbar.j"
@import "CPToolbarItem.j"
+3 -13
View File
@@ -35,23 +35,13 @@
<key>Name</key>
<string>Debug</string>
<key>Flags</key>
<string>-DDEBUG</string>
<key>Settings</key>
<dict>
<key>PREPROCESS</key>
<true/>
</dict>
<string>-DDEBUG -g</string>
</dict>
<dict>
<key>Name</key>
<string>Release</string>
<key>Settings</key>
<dict>
<key>PREPROCESS</key>
<true/>
<key>PREINTERPRET</key>
<true/>
</dict>
<key>Flags</key>
<string>-O</string>
</dict>
</array>
</dict>
+241
View File
@@ -0,0 +1,241 @@
/*
* CPAlert.j
* AppKit
*
* Created by Jake MacMullin.
* Copyright 2008, Jake MacMullin.
*
* 11/10/2008 Ross Boucher
* - Make it conform to style guidelines, general cleanup and ehancements
*
* 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 <Foundation/CPObject.j>
import <Foundation/CPString.j>
import <AppKit/CPApplication.j>
import <AppKit/CPButton.j>
import <AppKit/CPColor.j>
import <AppKit/CPFont.j>
import <AppKit/CPImage.j>
import <AppKit/CPImageView.j>
import <AppKit/CPPanel.j>
import <AppKit/CPTextField.j>
/*
@global
@group CPAlertStyle
*/
CPWarningAlertStyle = 0;
/*
@global
@group CPAlertStyle
*/
CPInformationalAlertStyle = 1;
/*
@global
@group CPAlertStyle
*/
CPCriticalAlertStyle = 2;
var CPAlertWarningImage,
CPAlertInformationImage,
CPAlertErrorImage;
/*
CPAlert is an alert panel that can be displayed modally to present the
user with a message and one or more options.
It can be used to display an information message (<pre>CPInformationalAlertStyle</pre>),
a warning message (<pre>CPWarningAlertStyle</pre> - which is the default), or a critical
alert (<pre>CPCriticalAlertStyle</pre>). In each case the user can be presented with one
or more options by adding buttons using the <pre>addButtonWithTitle:</pre> method.
The panel is displayed modally by calling <pre>runModal</pre> and once the user has
dismissed the panel, a message will be sent to the panel's delegate (if set), informing
it which button was clicked (see delegate methods).
@delegate -(void)alertDidEnd:(CPAlert)theAlert returnCode:(int)returnCode;
Called when the user dismisses the alert by clicking one of the buttons.
@param theAlert the alert panel that the user dismissed
@param returnCode the index of the button that the user clicked (starting from 0,
representing the first button added to the alert which appears on the
right, 1 representing the next button to the left and so on)
*/
@implementation CPAlert : CPObject
{
CPPanel _alertPanel;
CPTextField _messageLabel;
CPImageView _alertImageView;
CPAlertStyle _alertStyle;
int _buttonCount;
id _delegate;
}
+ (void)initialize
{
if (self != CPAlert)
return;
var bundle = [CPBundle bundleForClass:[self class]];
CPAlertWarningImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPAlert/dialog-warning.png"]
size:CGSizeMake(32,32)];
CPAlertInformationImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPAlert/dialog-information.png"]
size:CGSizeMake(32,32)];
CPAlertErrorImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPAlert/dialog-error.png"]
size:CGSizeMake(32,32)];
}
/*!
Initializes a <pre>CPAlert</pre> panel with the default alert style (<pre>CPWarningAlertStyle</pre>).
*/
- (id)init
{
self = [super init];
if (self)
{
_buttonCount = 0;
_alertStyle = CPWarningAlertStyle;
_alertPanel = [[CPPanel alloc] initWithContentRect:CGRectMake(0, 0, 300, 150) styleMask:CPHUDBackgroundWindowMask|CPTitledWindowMask];
[_alertPanel setFloatingPanel:YES];
[_alertPanel center];
_messageLabel = [[CPTextField alloc] initWithFrame: CGRectMake(70,10, 200, 100)];
[_messageLabel setFont: [CPFont fontWithName: "Helvetica Neue" size: 12.0]];
[_messageLabel setTextColor: [CPColor whiteColor]];
[_messageLabel setLineBreakMode:CPLineBreakByWordWrapping];
[[_alertPanel contentView] addSubview: _messageLabel];
_alertImageView = [[CPImageView alloc] initWithFrame:CGRectMake(25,12,32,32)];
[[_alertPanel contentView] addSubview: _alertImageView];
}
return self;
}
/*!
Sets the receiver’s delegate.
@param delegate - Delegate for the alert. nil removes the delegate.
*/
- (void)setDelegate:(id)delegate
{
_delegate = delegate;
}
/*!
Gets the receiver's delegate.
*/
- (void)delegate
{
return _delegate;
}
/*!
Sets the alert style of the receiver.
@param style - Alert style for the alert.
*/
- (void)setAlertStyle:(CPAlertStyle)style
{
_alertStyle = style;
}
/*!
Gets the alert style.
*/
- (CPAlertStyle)alertStyle
{
return _alertStyle;
}
/*!
Set’s the receiver’s message text, or title, to a given text.
@param messageText - Message text for the alert.
*/
- (void)setMessageText:(CPString)messageText
{
[_messageLabel setStringValue:messageText];
}
/*!
Return's the receiver's message text body.
*/
- (CPString)messageText
{
return [_messageLabel stringValue];
}
/*!
Adds a button with a given title to the receiver.
Buttons will be added starting from the right hand side of the <pre>CPAlert</pre> panel.
The first button will have the index 0, the second button 1 and so on.
You really shouldn't need more than 3 buttons.
*/
- (void)addButtonWithTitle:(CPString)title
{
var button = [[CPButton alloc] initWithFrame:CGRectMake(190 - (_buttonCount * 90),80,80,18)];
[button setTitle:title];
[button setTarget:self];
[button setTag:_buttonCount];
[button setBezelStyle:CPHUDBezelStyle];
[button setAction:@selector(_notifyDelegate:)];
[[_alertPanel contentView] addSubview:button];
_buttonCount++;
}
/*!
Displays the <pre>CPAlert</pre> panel as a modal dialog. The user will not be
able to interact with any other controls until s/he has dismissed the alert
by clicking on one of the buttons.
*/
- (void)runModal
{
switch (_alertStyle)
{
case CPWarningAlertStyle: [_alertImageView setImage:CPAlertWarningImage];
break;
case CPInformationalAlertStyle: [_alertImageView setImage:CPAlertInformationImage];
break;
case CPCriticalAlertStyle: [_alertImageView setImage:CPAlertErrorImage];
break;
}
[CPApp runModalForWindow:_alertPanel];
}
/* @ignore */
- (void)_notifyDelegate:(id)button
{
if (_delegate && [_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
[_delegate alertDidEnd:self returnCode:[button tag]];
[CPApp abortModal];
[_alertPanel close];
}
+8 -9
View File
@@ -137,7 +137,7 @@ CPColorPickerViewHeight = 370;
[CPApp sendAction:@selector(changeColor:) to:nil from:self];
if (_target && _action)
objj_msgSend(_target, _action, self);
[CPApp sendAction:_action to:_target from:self];
[[CPNotificationCenter defaultCenter]
postNotificationName:CPColorPanelColorDidChangeNotification
@@ -149,14 +149,13 @@ CPColorPickerViewHeight = 370;
@param bool whether or not to update the picker
@ignore
*/
-(void)setColor:(CPColor)aColor updatePicker:(BOOL)bool
{
[self setColor: aColor];
if(bool)
[_activePicker setColor: _color];
}
- (void)setColor:(CPColor)aColor updatePicker:(BOOL)bool
{
[self setColor:aColor];
if (bool)
[_activePicker setColor:_color];
}
/*!
Returns the panel's currently selected color.
+8 -8
View File
@@ -126,9 +126,9 @@
brightnessBarView._DOMElement.appendChild(_brightnessBarImage);
_brightnessSlider = [[CPSlider alloc] initWithFrame: CPRectMake(0, aFrame.size.height - 22, aFrame.size.width, 12)];
[_brightnessSlider setMaxValue: 100.0];
[_brightnessSlider setMinValue: 0.0];
[_brightnessSlider setValue: 100.0];
[_brightnessSlider setMaxValue: 100.0];
[_brightnessSlider setMinValue: 0.0];
[_brightnessSlider setFloatValue:100.0];
[_brightnessSlider setTarget: self];
[_brightnessSlider setAction: @selector(brightnessSliderDidChange:)];
@@ -157,7 +157,7 @@
{
var hue = [_hueSaturationView angle],
saturation = [_hueSaturationView distance],
brightness = [_brightnessSlider value];
brightness = [_brightnessSlider floatValue];
[_hueSaturationView setWheelBrightness: brightness / 100.0];
_brightnessBarImage.style.backgroundColor = "#"+[[CPColor colorWithHue: hue saturation: saturation brightness: 100] hexString];
@@ -187,11 +187,11 @@
{
var hsb = [newColor hsbComponents];
[_hueSaturationView setPositionToColor: newColor];
[_brightnessSlider setValue: hsb[2]];
[_hueSaturationView setWheelBrightness: hsb[2] / 100.0];
[_hueSaturationView setPositionToColor:newColor];
[_brightnessSlider setFloatValue:hsb[2]];
[_hueSaturationView setWheelBrightness:hsb[2] / 100.0];
_brightnessBarImage.style.backgroundColor = "#"+[[CPColor colorWithHue: hsb[0] saturation: hsb[1] brightness: 100] hexString];
_brightnessBarImage.style.backgroundColor = "#"+[[CPColor colorWithHue:hsb[0] saturation:hsb[1] brightness:100] hexString];
}
@end
+89 -14
View File
@@ -38,6 +38,7 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
@implementation CPColorWell : CPControl
{
BOOL _active;
BOOL _bordered;
CPColor _color;
CPView _wellView;
@@ -50,30 +51,56 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
if (self)
{
_active = NO;
_bordered = YES;
_color = [CPColor whiteColor];
[self drawBezelWithHighlight:NO];
[self drawWellInside:CGRectInset([self bounds], 3.0, 3.0)];
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter
addObserver:self
selector:@selector(colorWellDidBecomeExclusive:)
name:_CPColorWellDidBecomeExclusiveNotification
object:nil];
[defaultCenter
addObserver:self
selector:@selector(colorPanelWillClose:)
name:CPWindowWillCloseNotification
object:[CPColorPanel sharedColorPanel]];
[self _registerForNotifications];
}
return self;
}
- (void)_registerForNotifications
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter
addObserver:self
selector:@selector(colorWellDidBecomeExclusive:)
name:_CPColorWellDidBecomeExclusiveNotification
object:nil];
[defaultCenter
addObserver:self
selector:@selector(colorPanelWillClose:)
name:CPWindowWillCloseNotification
object:[CPColorPanel sharedColorPanel]];
}
/*!
Returns whether the color well is bordered
*/
- (BOOL)isBordered
{
return _bordered;
}
/*!
Sets the color well's current color.
*/
- (void)setBordered:(BOOL)bordered
{
if (_bordered == bordered)
return;
_bordered = bordered;
[self drawWellInside:CGRectInset([self bounds], 3.0, 3.0)];
}
// Managing Color From Color Wells
/*!
@@ -226,3 +253,51 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
}
@end
var CPColorWellColorKey = "CPColorWellColorKey",
CPColorWellBorderedKey = "CPColorWellBorderedKey";
@implementation CPColorWell (CPCoding)
/*!
Initializes the color well by unarchiving data from <code>aCoder</code>.
@param aCoder the coder containing the archived <objj>CPColorWell</objj>.
*/
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
_active = NO;
_bordered = [aCoder decodeObjectForKey:CPColorWellBorderedKey];
_color = [aCoder decodeObjectForKey:CPColorWellColorKey];
[self _registerForNotifications];
}
return self;
}
/*!
Archives this button into the provided coder.
@param aCoder the coder to which the color well's instance data will be written.
*/
- (void)encodeWithCoder:(CPCoder)aCoder
{
// We do this in order to avoid encoding the _wellView, which
// should just automatically be created programmatically as needed.
var actualSubviews = _subviews;
_subviews = [_subviews copy];
[_subviews removeObjectIdenticalTo:_wellView];
[super encodeWithCoder:aCoder];
_subviews = actualSubviews;
[aCoder encodeObject:_color forKey:CPColorWellColorKey];
[aCoder encodeObject:_bordered forKey:CPColorWellBorderedKey];
}
@end
+148 -54
View File
@@ -69,14 +69,14 @@ CPSmallControlSize = 1;
*/
CPMiniControlSize = 2;
CPControlNormalBackgroundColor = @"CPControlNormalBackgroundColor";
CPControlSelectedBackgroundColor = @"CPControlSelectedBackgroundColor";
CPControlHighlightedBackgroundColor = @"CPControlHighlightedBackgroundColor";
CPControlDisabledBackgroundColor = @"CPControlDisabledBackgroundColor";
CPControlNormalBackgroundColor = "CPControlNormalBackgroundColor";
CPControlSelectedBackgroundColor = "CPControlSelectedBackgroundColor";
CPControlHighlightedBackgroundColor = "CPControlHighlightedBackgroundColor";
CPControlDisabledBackgroundColor = "CPControlDisabledBackgroundColor";
CPControlTextDidBeginEditingNotification=@"CPControlTextDidBeginEditingNotification";
CPControlTextDidChangeNotification=@"CPControlTextDidChangeNotification";
CPControlTextDidEndEditingNotification=@"CPControlTextDidEndEditingNotification";
CPControlTextDidBeginEditingNotification = "CPControlTextDidBeginEditingNotification";
CPControlTextDidChangeNotification = "CPControlTextDidChangeNotification";
CPControlTextDidEndEditingNotification = "CPControlTextDidEndEditingNotification";
var CPControlBlackColor = [CPColor blackColor];
@@ -99,9 +99,6 @@ var CPControlBlackColor = [CPColor blackColor];
SEL _action;
int _sendActionOn;
CPColor _backgroundColor;
CPColor _highlightedBackgroundColor;
CPDictionary _backgroundColors;
CPString _currentBackgroundColorName;
}
@@ -275,20 +272,34 @@ var CPControlBlackColor = [CPColor blackColor];
[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,18 +318,36 @@ 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];
var doubleValue = parseFloat(_value, 10);
return isNaN(doubleValue) ? 0.0 : doubleValue;
}
/*!
Set's the receiver's double value
*/
- (void)setDoubleValue:(id)anObject
- (void)setDoubleValue:(double)anObject
{
[self setObjectValue:anObject];
}
@@ -326,15 +355,34 @@ var CPControlBlackColor = [CPColor blackColor];
/*!
Returns the receiver's int value
*/
- (id)intValue
- (int)intValue
{
return _value ? parseInt(_value, 10) : 0;
var intValue = parseInt(_value, 10);
return isNaN(intValue) ? 0.0 : intValue;
}
/*!
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
{
var intValue = parseInt(_value, 10);
return isNaN(intValue) ? 0.0 : intValue;
}
/*!
Set's the receiver's int value
*/
- (void)setIntegerValue:(int)anObject
{
[self setObjectValue:anObject];
}
@@ -342,19 +390,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];
@@ -398,7 +488,7 @@ var CPControlBlackColor = [CPColor blackColor];
if([note object] != self)
return;
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidBeginEditingNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:@"CPFieldEditor"]];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidBeginEditingNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:"CPFieldEditor"]];
}
- (void)textDidChange:(CPNotification)note
@@ -407,7 +497,7 @@ var CPControlBlackColor = [CPColor blackColor];
if([note object] != self)
return;
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidChangeNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:@"CPFieldEditor"]];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidChangeNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:"CPFieldEditor"]];
}
- (void)textDidEndEditing:(CPNotification)note
@@ -416,7 +506,7 @@ var CPControlBlackColor = [CPColor blackColor];
if([note object] != self)
return;
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidEndEditingNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:@"CPFieldEditor"]];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidEndEditingNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:"CPFieldEditor"]];
}
/*
@@ -435,13 +525,14 @@ var CPControlBlackColor = [CPColor blackColor];
@end
var CPControlIsEnabledKey = @"CPControlIsEnabledKey",
CPControlAlignmentKey = @"CPControlAlignmentKey",
CPControlFontKey = @"CPControlFontKey",
CPControlTextColorKey = @"CPControlTextColorKey",
CPControlTargetKey = @"CPControlTargetKey",
CPControlActionKey = @"CPControlActionKey",
CPControlSendActionOnKey = @"CPControlSendActionOnKey";
var CPControlValueKey = "CPControlValueKey",
CPControlIsEnabledKey = "CPControlIsEnabledKey",
CPControlAlignmentKey = "CPControlAlignmentKey",
CPControlFontKey = "CPControlFontKey",
CPControlTextColorKey = "CPControlTextColorKey",
CPControlTargetKey = "CPControlTargetKey",
CPControlActionKey = "CPControlActionKey",
CPControlSendActionOnKey = "CPControlSendActionOnKey";
@implementation CPControl (CPCoding)
@@ -456,7 +547,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 +557,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 +571,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];
@@ -498,9 +592,9 @@ var _CPControlSizeIdentifiers = [],
_CPControlCachedColorWithPatternImages = {},
_CPControlCachedThreePartImagePattern = {};
_CPControlSizeIdentifiers[CPRegularControlSize] = @"Regular";
_CPControlSizeIdentifiers[CPSmallControlSize] = @"Small";
_CPControlSizeIdentifiers[CPMiniControlSize] = @"Mini";
_CPControlSizeIdentifiers[CPRegularControlSize] = "Regular";
_CPControlSizeIdentifiers[CPSmallControlSize] = "Small";
_CPControlSizeIdentifiers[CPMiniControlSize] = "Mini";
function _CPControlIdentifierForControlSize(aControlSize)
{
@@ -511,7 +605,7 @@ function _CPControlColorWithPatternImage(sizes, aClassName)
{
var index = 1,
count = arguments.length,
identifier = @"";
identifier = "";
for (; index < count; ++index)
identifier += arguments[index];
@@ -522,7 +616,7 @@ function _CPControlColorWithPatternImage(sizes, aClassName)
{
var bundle = [CPBundle bundleForClass:[CPControl class]];
color = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:aClassName + "/" + identifier + @".png"] size:sizes[identifier]]];
color = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:aClassName + "/" + identifier + ".png"] size:sizes[identifier]]];
_CPControlCachedColorWithPatternImages[identifier] = color;
}
@@ -534,7 +628,7 @@ function _CPControlThreePartImages(sizes, aClassName)
{
var index = 1,
count = arguments.length,
identifier = @"";
identifier = "";
for (; index < count; ++index)
identifier += arguments[index];
@@ -549,9 +643,9 @@ function _CPControlThreePartImages(sizes, aClassName)
sizes = sizes[identifier];
images = [
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + @"0.png"] size:sizes[0]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + @"1.png"] size:sizes[1]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + @"2.png"] size:sizes[2]]
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "0.png"] size:sizes[0]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "1.png"] size:sizes[1]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "2.png"] size:sizes[2]]
];
_CPControlCachedThreePartImages[identifier] = images;
@@ -564,7 +658,7 @@ function _CPControlThreePartImagePattern(isVertical, sizes, aClassName)
{
var index = 2,
count = arguments.length,
identifier = @"";
identifier = "";
for (; index < count; ++index)
identifier += arguments[index];
@@ -579,9 +673,9 @@ function _CPControlThreePartImagePattern(isVertical, sizes, aClassName)
sizes = sizes[identifier];
color = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + @"0.png"] size:sizes[0]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + @"1.png"] size:sizes[1]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + @"2.png"] size:sizes[2]]
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "0.png"] size:sizes[0]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "1.png"] size:sizes[1]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "2.png"] size:sizes[2]]
] isVertical:isVertical]];
_CPControlCachedThreePartImagePattern[identifier] = color;
+1 -1
View File
@@ -42,7 +42,7 @@ CPImageDidLoadNotification = @"CPImageDidLoadNotification";
- (CPString)pathForResource:(CPString)aFilename
{
return [self bundlePath] + "Resources/" + aFilename;
return [self resourcePath] + '/' + aFilename;
}
@end
+80 -8
View File
@@ -25,7 +25,6 @@
@import <Foundation/CPNotificationCenter.j>
@import <Foundation/CPString.j>
@import "_CPImageAndTitleView.j"
@import "CPApplication.j"
@import "CPClipView.j"
@import "CPMenuItem.j"
@@ -46,6 +45,7 @@ var _CPMenuBarVisible = NO,
_CPMenuBarTitle = @"",
_CPMenuBarIconImage = nil,
_CPMenuBarIconImageAlphaValue = 1.0,
_CPMenuBarAttributes = nil,
_CPMenuBarSharedWindow = nil;
/*! @class CPMenu
@@ -93,6 +93,10 @@ var _CPMenuBarVisible = NO,
[_CPMenuBarSharedWindow setIconImage:_CPMenuBarIconImage];
[_CPMenuBarSharedWindow setIconImageAlphaValue:_CPMenuBarIconImageAlphaValue];
[_CPMenuBarSharedWindow setColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarBackgroundColor"]];
[_CPMenuBarSharedWindow setTextColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTextColor"]];
[_CPMenuBarSharedWindow setTitleColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTitleColor"]];
[_CPMenuBarSharedWindow orderFront:self];
}
else
@@ -126,6 +130,41 @@ var _CPMenuBarVisible = NO,
return _CPMenuBarImage;
}
+ (void)setMenuBarAttributes:(CPDictionary)attributes
{
if (_CPMenuBarAttributes == attributes)
return;
_CPMenuBarAttributes = [attributes copy];
var textColor = [attributes objectForKey:@"CPMenuBarTextColor"],
titleColor = [attributes objectForKey:@"CPMenuBarTitleColor"];
if (!textColor && titleColor)
[_CPMenuBarAttributes setObject:titleColor forKey:@"CPMenuBarTextColor"];
else if (textColor && !titleColor)
[_CPMenuBarAttributes setObject:textColor forKey:@"CPMenuBarTitleColor"];
else if (!textColor && !titleColor)
{
[_CPMenuBarAttributes setObject:[CPColor blackColor] forKey:@"CPMenuBarTextColor"];
[_CPMenuBarAttributes setObject:[CPColor blackColor] forKey:@"CPMenuBarTitleColor"];
}
if (_CPMenuBarSharedWindow)
{
[_CPMenuBarSharedWindow setColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarBackgroundColor"]];
[_CPMenuBarSharedWindow setTextColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTextColor"]];
[_CPMenuBarSharedWindow setTitleColor:[_CPMenuBarAttributes objectForKey:@"CPMenuBarTitleColor"]];
}
}
+ (CPDictionary)menuBarAttributes
{
return _CPMenuBarAttributes;
}
+ (void)_setMenuBarIconImageAlphaValue:(float)anAlphaValue
{
_CPMenuBarIconImageAlphaValue = anAlphaValue;
@@ -1312,6 +1351,9 @@ var _CPMenuBarWindowBackgroundColor = nil,
CPImageView _iconImageView;
CPTextField _titleField;
CPColor _textColor;
CPColor _titleColor;
}
+ (void)initialize
@@ -1321,8 +1363,6 @@ var _CPMenuBarWindowBackgroundColor = nil,
var bundle = [CPBundle bundleForClass:self];
_CPMenuBarWindowBackgroundColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"_CPMenuBarWindow/_CPMenuBarWindowBackground.png"] size:CGSizeMake(1.0, 18.0)]];
_CPMenuBarWindowFont = [CPFont systemFontOfSize:11.0];
}
@@ -1340,7 +1380,6 @@ var _CPMenuBarWindowBackgroundColor = nil,
var contentView = [self contentView];
[contentView setBackgroundColor:_CPMenuBarWindowBackgroundColor];
[contentView setAutoresizesSubviews:NO];
[self setBecomesKeyOnlyIfNeeded:YES];
@@ -1350,11 +1389,9 @@ var _CPMenuBarWindowBackgroundColor = nil,
[contentView addSubview:_iconImageView];
_titleField = [[_CPImageAndTitleView alloc] initWithFrame:CGRectMakeZero()];
_titleField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_titleField setFont:[CPFont boldSystemFontOfSize:12.0]];
[_titleField setImagePosition:CPImageLeft];
[_titleField setAlignment:CPCenterTextAlignment];
[contentView addSubview:_titleField];
@@ -1376,7 +1413,7 @@ var _CPMenuBarWindowBackgroundColor = nil,
document.title = bundleName;
#endif
[_titleField setTitle:aTitle];
[_titleField setStringValue:aTitle];
[_titleField sizeToFit];
[self tile];
@@ -1395,6 +1432,39 @@ var _CPMenuBarWindowBackgroundColor = nil,
[_iconImageView setAlphaValue:anAlphaValue];
}
- (void)setColor:(CPColor)aColor
{
if (!aColor)
{
if (!_CPMenuBarWindowBackgroundColor)
_CPMenuBarWindowBackgroundColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[_CPMenuBarWindow class]] pathForResource:@"_CPMenuBarWindow/_CPMenuBarWindowBackground.png"] size:CGSizeMake(1.0, 18.0)]];
[[self contentView] setBackgroundColor:_CPMenuBarWindowBackgroundColor];
}
else
[[self contentView] setBackgroundColor:aColor];
}
- (void)setTextColor:(CPColor)aColor
{
if (_textColor == aColor)
return;
_textColor = aColor;
[_menuItemViews makeObjectsPerformSelector:@selector(setTextColor:) withObject:_textColor];
}
- (void)setTitleColor:(CPColor)aColor
{
if (_titleColor == aColor)
return;
_titleColor = aColor;
[_titleField setTextColor:aColor ? aColor : [CPColor blackColor]];
}
- (void)setMenu:(CPMenu)aMenu
{
if (_menu == aMenu)
@@ -1465,6 +1535,7 @@ var _CPMenuBarWindowBackgroundColor = nil,
[menuItemView setShowsStateColumn:NO];
[menuItemView setBelongsToMenuBar:YES];
[menuItemView setFont:_CPMenuBarWindowFont];
[menuItemView setTextColor:_textColor];
[menuItemView setHidden:[item isHidden]];
[menuItemView synchronizeWithMenuItem];
@@ -1497,6 +1568,7 @@ var _CPMenuBarWindowBackgroundColor = nil,
[menuItemView setShowsStateColumn:NO];
[menuItemView setBelongsToMenuBar:YES];
[menuItemView setFont:_CPMenuBarWindowFont];
[menuItemView setTextColor:_textColor];
[menuItemView setHidden:[menuItem isHidden]];
[menuItemView synchronizeWithMenuItem];
+76 -28
View File
@@ -135,7 +135,12 @@
*/
- (void)setHidden:(BOOL)isHidden
{
if (_isHidden == isHidden)
return;
_isHidden = isHidden;
[_menu itemChanged:self];
}
/*!
@@ -154,7 +159,9 @@
if (_isHidden)
return YES;
if ([[[_menu supermenu] indexOfItemWithSubmenu:_menu] isHiddenOrHasHiddenAncestor])
var supermenu = [_menu supermenu];
if ([[supermenu itemAtIndex:[supermenu indexOfItemWithSubmenu:_menu]] isHiddenOrHasHiddenAncestor])
return YES;
return NO;
@@ -830,10 +837,7 @@ var LEFT_MARGIN = 3.0,
var _CPMenuItemSelectionColor = nil,
_CPMenuItemDefaultStateImages = [],
_CPMenuItemDefaultStateHighlightedImages = [],
_CPMenuItemViewMenuBarArrowImage = nil,
_CPMenuItemViewMenuBarArrowActivatedImage = nil;
_CPMenuItemDefaultStateHighlightedImages = [];
/*
@ignore
@@ -843,6 +847,7 @@ var _CPMenuItemSelectionColor = nil,
CPMenuItem _menuItem;
CPFont _font;
CPColor _textColor;
CGSize _minSize;
BOOL _isDirty;
@@ -851,7 +856,7 @@ var _CPMenuItemSelectionColor = nil,
CPImageView _stateView;
_CPImageAndTitleView _imageAndTitleView;
CPImageView _submenuImageView;
CPView _submenuView;
}
+ (void)initialize
@@ -923,8 +928,8 @@ var _CPMenuItemSelectionColor = nil,
[_stateView removeFromSuperview];
_stateView = nil;
[_submenuImageView removeFromSuperview];
_submenuImageView = nil;
[_submenuView removeFromSuperview];
_submenuView = nil;
_minSize = [view frame].size;
@@ -985,11 +990,11 @@ var _CPMenuItemSelectionColor = nil,
if (!font)
font = _font;
[_imageAndTitleView setFont:font];
[_imageAndTitleView setImage:[_menuItem image]];
[_imageAndTitleView setTitle:[_menuItem title]];
[_imageAndTitleView setTextColor:[_menuItem isEnabled] ? [CPColor blackColor] : [CPColor darkGrayColor]];
[_imageAndTitleView setTextColor:[self textColor]];
[_imageAndTitleView setFrameOrigin:CGPointMake(x, 0.0)];
[_imageAndTitleView sizeToFit];
@@ -1001,24 +1006,21 @@ var _CPMenuItemSelectionColor = nil,
// Submenu Arrow
if ([_menuItem hasSubmenu])
{
if (!_submenuImageView)
if (!_submenuView)
{
_submenuImageView = [[CPImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 10.0)];
_submenuView = [[_CPMenuItemArrowView alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 10.0)];
[self addSubview:_submenuImageView];
[self addSubview:_submenuView];
}
if (_belongsToMenuBar && !_CPMenuItemViewMenuBarArrowImage)
_CPMenuItemViewMenuBarArrowImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[_CPMenuItemView class]] pathForResource:@"_CPMenuItemView/_CPMenuItemViewMenuBarArrow.png"] size:CGSizeMake(10.0, 10.0)];
[_submenuImageView setHidden:NO];
[_submenuImageView setImage:_belongsToMenuBar ? _CPMenuItemViewMenuBarArrowImage : nil];
[_submenuImageView setFrameOrigin:CGPointMake(x, (CGRectGetHeight(frame) - 10.0) / 2.0)];
[_submenuView setHidden:NO];
[_submenuView setColor:_belongsToMenuBar ? [self textColor] : nil];
[_submenuView setFrameOrigin:CGPointMake(x, (CGRectGetHeight(frame) - 10.0) / 2.0)];
x += 10.0;
}
else
[_submenuImageView setHidden:YES];
[_submenuView setHidden:YES];
_minSize = CGSizeMake(x + (_belongsToMenuBar ? 0.0 : RIGHT_MARGIN), CGRectGetHeight(frame));
@@ -1052,7 +1054,7 @@ var _CPMenuItemSelectionColor = nil,
else
{
[_imageAndTitleView setTextColor:shouldHighlight ? [CPColor whiteColor] : [CPColor blackColor]];
[_imageAndTitleView setTextColor:shouldHighlight ? [CPColor whiteColor] : [self textColor]];
if (shouldHighlight)
[self setBackgroundColor:_CPMenuItemSelectionColor];
@@ -1079,16 +1081,13 @@ var _CPMenuItemSelectionColor = nil,
if (shouldActivate)
{
if (!_CPMenuItemViewMenuBarArrowActivatedImage)
_CPMenuItemViewMenuBarArrowActivatedImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[_CPMenuItemView class]] pathForResource:@"_CPMenuItemView/_CPMenuItemViewMenuBarArrowActivated.png"] size:CGSizeMake(10.0, 10.0)];
[_imageAndTitleView setTextColor:[CPColor whiteColor]];
[_submenuImageView setImage:_CPMenuItemViewMenuBarArrowActivatedImage];
[_submenuView setColor:[CPColor whiteColor]];
}
else
{
[_imageAndTitleView setTextColor:[CPColor blackColor]];
[_submenuImageView setImage:_CPMenuItemViewMenuBarArrowImage];
[_imageAndTitleView setTextColor:[self textColor]];
[_submenuView setColor:[self textColor]];
}
}
@@ -1097,7 +1096,7 @@ var _CPMenuItemSelectionColor = nil,
if (![_menuItem hasSubmenu])
return NO;
return CGRectContainsPoint([_submenuImageView frame], [self convertPoint:[anEvent locationInWindow] fromView:nil]);
return CGRectContainsPoint([_submenuView frame], [self convertPoint:[anEvent locationInWindow] fromView:nil]);
}
- (BOOL)isHidden
@@ -1120,5 +1119,54 @@ var _CPMenuItemSelectionColor = nil,
[self setDirty];
}
- (void)setTextColor:(CPColor)aColor
{
if (_textColor == aColor)
return;
_textColor = aColor;
[_imageAndTitleView setTextColor:[self textColor]];
[_submenuView setColor:[self textColor]];
}
- (CPColor)textColor
{
return [_menuItem isEnabled] ? (_textColor ? _textColor : [CPColor blackColor]) : [CPColor darkGrayColor];
}
@end
@implementation _CPMenuItemArrowView : CPView
{
CPColor _color;
}
- (void)setColor:(CPColor)aColor
{
if (_color == aColor)
return;
_color = aColor;
[self setNeedsDisplay:YES];
}
- (void)drawRect:(CGRect)aRect
{
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextBeginPath(context);
CGContextMoveToPoint(context, 1.0, 4.0);
CGContextAddLineToPoint(context, 9.0, 4.0);
CGContextAddLineToPoint(context, 5.0, 8.0);
CGContextAddLineToPoint(context, 1.0, 4.0);
CGContextClosePath(context);
CGContextSetFillColor(context, _color);
CGContextFillPath(context);
}
@end
-3
View File
@@ -324,19 +324,16 @@ var CPPopUpButtonArrowsImage = nil;
{
[defaultCenter
removeObserver:self
selector:@selector(menuDidAddItem:)
name:CPMenuDidAddItemNotification
object:_menu];
[defaultCenter
removeObserver:self
selector:@selector(menuDidChangeItem:)
name:CPMenuDidChangeItemNotification
object:_menu];
[defaultCenter
removeObserver:self
selector:@selector(menuDidRemoveItem:)
name:CPMenuDidRemoveItemNotification
object:_menu];
}
+5
View File
@@ -364,7 +364,12 @@
*/
- (void)setAutohidesScrollers:(BOOL)autohidesScrollers
{
if (_autohidesScrollers == autohidesScrollers)
return;
_autohidesScrollers = autohidesScrollers;
[self reflectScrolledClipView:_contentView];
}
/*!
+73 -33
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;
@@ -58,11 +57,11 @@ var CPSliderHorizontalKnobImage = nil,
var bundle = [CPBundle bundleForClass:self];
CPSliderKnobImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSlider/CPSliderKnobRegular.png"] size:CPSizeMake(11.0, 11.0)],
CPSliderKnobPushedImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSlider/CPSliderKnobRegularPushed.png"] size:CPSizeMake(11.0, 11.0)],
CPSliderHorizontalBarLeftImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSlider/CPSliderTrackHorizontalLeft.png"] size:CPSizeMake(2.0, 4.0)],
CPSliderHorizontalBarRightImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSlider/CPSliderTrackHorizontalRight.png"] size:CPSizeMake(2.0, 4.0)],
CPSliderHorizontalBarCenterImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSlider/CPSliderTrackHorizontalCenter.png"] size:CPSizeMake(1.0, 4.0)];
CPSliderKnobImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPSlider/CPSliderKnobRegular.png"] size:CPSizeMake(11.0, 11.0)],
CPSliderKnobPushedImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPSlider/CPSliderKnobRegularPushed.png"] size:CPSizeMake(11.0, 11.0)],
CPSliderHorizontalBarLeftImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPSlider/CPSliderTrackHorizontalLeft.png"] size:CPSizeMake(2.0, 4.0)],
CPSliderHorizontalBarRightImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPSlider/CPSliderTrackHorizontalRight.png"] size:CPSizeMake(2.0, 4.0)],
CPSliderHorizontalBarCenterImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPSlider/CPSliderTrackHorizontalCenter.png"] size:CPSizeMake(1.0, 4.0)];
}
- (id)initWithFrame:(CGRect)aFrame
@@ -80,6 +79,8 @@ var CPSliderHorizontalKnobImage = nil,
_knobSize = [[self knobImage] size];
_isVertical = [self isVertical];
[self setContinuous:YES];
[_knob setFrameOrigin:[self knobPosition]];
[self addSubview:_bar];
@@ -91,7 +92,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 +128,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 +250,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 +300,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 +334,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,36 +358,46 @@ 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];
if (_sendActionOn & CPLeftMouseUpMask)
[self sendAction:_action to:_target];
//[super mouseUp:anEvent];
}
- (void)mouseDown:(CPEvent)anEvent
{
[_knob setFrameOrigin:[self constrainKnobPosition:[self convertPoint:[anEvent locationInWindow] fromView:nil]]];
_value = [self valueForKnobPosition:[_knob frame].origin];
[super setObjectValue:[self valueForKnobPosition:[_knob frame].origin]];
[[self knob] setImage: [self pushedKnobImage]];
[self sendAction:_action to:_target];
[[self knob] setImage:[self pushedKnobImage]];
if (_sendActionOn & CPLeftMouseDraggedMask)
[self sendAction:_action to:_target];
//[super mouseDown:anEvent];
}
- (void)mouseDragged:(CPEvent)anEvent
{
[_knob setFrameOrigin:[self constrainKnobPosition:[self convertPoint:[anEvent locationInWindow] fromView:nil]]];
_value = [self valueForKnobPosition:[_knob frame].origin];
[self sendAction:_action to:_target];
[super setObjectValue:[self valueForKnobPosition:[_knob frame].origin]];
if (_sendActionOn & CPLeftMouseDraggedMask)
[self sendAction:_action to:_target];
//[super mouseDown:anEvent];
}
@end
var CPSliderMinValueKey = @"CPSliderMinValueKey",
CPSliderMaxValueKey = @"CPSliderMaxValueKey",
CPSliderValueKey = @"CPSliderValueKey";
var CPSliderMinValueKey = "CPSliderMinValueKey",
CPSliderMaxValueKey = "CPSliderMaxValueKey",
CPSliderAltIncrValueKey = "CPSliderAltIncrValueKey",
CPSliderIsVerticalKey = "CPSliderIsVerticalKey";
@implementation CPSlider (CPCoding)
@@ -374,9 +412,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 +445,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
+30 -30
View File
@@ -93,28 +93,28 @@
switch(this)
{
case _redValue: [_redSlider setValue: MAX(MIN(ROUND(this.value), 255) / 255.0, 0)];
[self sliderChanged: _redSlider];
case _redValue: [_redSlider setFloatValue:MAX(MIN(ROUND(this.value), 255) / 255.0, 0)];
//[self sliderChanged: _redSlider];
break;
case _greenValue: [_greenSlider setValue: MAX(MIN(ROUND(this.value), 255) / 255.0, 0)];
[self sliderChanged: _greenSlider];
case _greenValue: [_greenSlider setFloatValue:MAX(MIN(ROUND(this.value), 255) / 255.0, 0)];
//[self sliderChanged: _greenSlider];
break;
case _blueValue: [_blueSlider setValue: MAX(MIN(ROUND(this.value), 255) / 255.0, 0)];
[self sliderChanged: _blueSlider];
case _blueValue: [_blueSlider setFloatValue:MAX(MIN(ROUND(this.value), 255) / 255.0, 0)];
//[self sliderChanged: _blueSlider];
break;
case _hueValue: [_hueSlider setValue: MAX(MIN(ROUND(this.value), 360), 0)];
[self sliderChanged: _hueSlider];
case _hueValue: [_hueSlider setFloatValue:MAX(MIN(ROUND(this.value), 360), 0)];
//[self sliderChanged: _hueSlider];
break;
case _saturationValue: [_saturationSlider setValue: MAX(MIN(ROUND(this.value), 100), 0)];
[self sliderChanged: _saturationSlider];
case _saturationValue: [_saturationSlider setFloatValue:MAX(MIN(ROUND(this.value), 100), 0)];
//[self sliderChanged: _saturationSlider];
break;
case _brightnessValue: [_brightnessSlider setValue: MAX(MIN(ROUND(this.value), 100), 0)];
[self sliderChanged: _brightnessSlider];
case _brightnessValue: [_brightnessSlider setFloatValue:MAX(MIN(ROUND(this.value), 100), 0)];
//[self sliderChanged: _brightnessSlider];
break;
}
@@ -339,18 +339,18 @@
{
case _hueSlider:
case _saturationSlider:
case _brightnessSlider: newColor = [CPColor colorWithHue: [_hueSlider value]
saturation: [_saturationSlider value]
brightness: [_brightnessSlider value]];
case _brightnessSlider: newColor = [CPColor colorWithHue: [_hueSlider floatValue]
saturation: [_saturationSlider floatValue]
brightness: [_brightnessSlider floatValue]];
[self updateRGBSliders: newColor];
break;
case _redSlider:
case _greenSlider:
case _blueSlider: newColor = [CPColor colorWithCalibratedRed: [_redSlider value]
green: [_greenSlider value]
blue: [_blueSlider value]
case _blueSlider: newColor = [CPColor colorWithCalibratedRed: [_redSlider floatValue]
green: [_greenSlider floatValue]
blue: [_blueSlider floatValue]
alpha: 1.0];
[self updateHSBSliders: newColor];
@@ -374,9 +374,9 @@
{
var hsb = [aColor hsbComponents];
[_hueSlider setValue: hsb[0]];
[_saturationSlider setValue: hsb[1]];
[_brightnessSlider setValue: hsb[2]];
[_hueSlider setFloatValue:hsb[0]];
[_saturationSlider setFloatValue:hsb[1]];
[_brightnessSlider setFloatValue:hsb[2]];
}
- (void)updateHex:(CPColor)aColor
@@ -388,20 +388,20 @@
{
var rgb = [aColor components];
[_redSlider setValue: rgb[0]];
[_greenSlider setValue: rgb[1]];
[_blueSlider setValue: rgb[2]];
[_redSlider setFloatValue:rgb[0]];
[_greenSlider setFloatValue:rgb[1]];
[_blueSlider setFloatValue:rgb[2]];
}
- (void)updateLabels
{
_hueValue.value = ROUND([_hueSlider value]);
_saturationValue.value = ROUND([_saturationSlider value]);
_brightnessValue.value = ROUND([_brightnessSlider value]);
_hueValue.value = ROUND([_hueSlider floatValue]);
_saturationValue.value = ROUND([_saturationSlider floatValue]);
_brightnessValue.value = ROUND([_brightnessSlider floatValue]);
_redValue.value = ROUND([_redSlider value] * 255);
_greenValue.value = ROUND([_greenSlider value] * 255);
_blueValue.value = ROUND([_blueSlider value] * 255);
_redValue.value = ROUND([_redSlider floatValue] * 255);
_greenValue.value = ROUND([_greenSlider floatValue] * 255);
_blueValue.value = ROUND([_blueSlider floatValue] * 255);
}
+149 -56
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;
@@ -150,9 +152,11 @@ var _CPTextFieldSquareBezelColor = nil;
if (self)
{
_value = @"";
_placeholderString = @"";
_value = "";
_placeholderString = "";
_sendActionOn = CPKeyUpMask | CPKeyDownMask;
#if PLATFORM(DOM)
_DOMTextElement = document.createElement("div");
_DOMTextElement.style.position = "absolute";
@@ -267,33 +271,102 @@ 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)
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 +380,7 @@ var _CPTextFieldSquareBezelColor = nil;
{
var string = [self stringValue];
[self setStringValue:@""];
[self setStringValue:""];
#if PLATFORM(DOM)
var element = [[self class] _inputElement];
@@ -327,8 +400,10 @@ var _CPTextFieldSquareBezelColor = nil;
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 +414,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 +424,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 +446,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,10 +474,10 @@ 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 === "")
if (!_value)
[self setStringValue:[self placeholderString]];
#endif
@@ -514,7 +592,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 +600,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];
}
/*
@@ -570,7 +648,7 @@ var _CPTextFieldSquareBezelColor = nil;
_placeholderString = aStringValue;
//if there is no set value, automatically display the placeholder
if (!_value || _value === "")
if (!_value)
[self setStringValue:aStringValue];
}
@@ -580,7 +658,7 @@ var _CPTextFieldSquareBezelColor = nil;
- (void)sizeToFit
{
#if PLATFORM(DOM)
var size = [_value ? _value : @" " sizeWithFont:[self font]];
var size = [(_value || " ") sizeWithFont:[self font]];
[self setFrameSize:CGSizeMake(size.width + 2 * HORIZONTAL_PADDING, size.height + TOP_PADDING + BOTTOM_PADDING)];
#endif
@@ -603,10 +681,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 +708,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 +722,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 +746,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 -1
View File
@@ -430,6 +430,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
// Determine all the items that have flexible width.
// Also determine the height of the toolbar.
// NOTE: height is height without top margin, and bottom margin/label.
var index = _visibleItems.length,
height = 0.0;
@@ -511,7 +512,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
itemWidth = MAX([self minWidthForItem:item], viewWidth),
viewHeight = MAX([item minSize].height, MIN([item maxSize].height, height));
viewHeight = CGRectGetHeight(viewFrame);
// itemWidth != viewWidth. itemWidth is MAX(size of view, size of label). If the label is larger,
// *center* the view, don't resize it.
+82 -24
View File
@@ -77,7 +77,9 @@ var _CPToolbarSeparatorItemView = nil;
BOOL _isEnabled;
CPImage _image;
CPImage _alternateImage;
CPView _view;
CGSize _minSize;
CGSize _maxSize;
@@ -98,6 +100,9 @@ var _CPToolbarSeparatorItemView = nil;
{
_itemIdentifier = anItemIdentifier;
_tag = 0;
_isEnabled = YES;
_minSize = CGSizeMakeZero();
_maxSize = CGSizeMakeZero();
@@ -165,6 +170,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (CPString)toolTip
{
if ([_view respondsToSelector:@selector(toolTip)])
return [_view toolTip];
return _toolTip;
}
@@ -174,6 +182,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setToolTip:(CPString)aToolTip
{
if ([_view respondsToSelector:@selector(setToolTip:)])
[view setToolTip:aToolTip];
_toolTip = aToolTip;
}
@@ -182,6 +193,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (int)tag
{
if ([_view respondsToSelector:@selector(tag)])
return [_view tag];
return _tag;
}
@@ -191,6 +205,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setTag:(int)aTag
{
if ([_view respondsToSelector:@selector(setTag:)])
[_view setTag:aTag];
_tag = aTag;
}
@@ -199,6 +216,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (id)target
{
if (_view)
return [_view respondsToSelector:@selector(target)] ? [_view target] : nil;
return _target;
}
@@ -209,7 +229,11 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setTarget:(id)aTarget
{
_target = aTarget;
if (!_view)
_target = aTarget;
else if ([_view respondsToSelector:@selector(setTarget:)])
[_view setTarget:aTarget];
}
/*!
@@ -217,6 +241,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (SEL)action
{
if (_view)
return [_view respondsToSelector:@selector(action)] ? [_view action] : nil;
return _action;
}
@@ -226,7 +253,11 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setAction:(SEL)anAction
{
_action = anAction;
if (!_view)
_action = anAction;
else if ([_view respondsToSelector:@selector(setAction:)])
[_view setAction:anAction];
}
/*!
@@ -234,6 +265,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (BOOL)isEnabled
{
if ([_view respondsToSelector:@selector(isEnabled)])
return [_view isEnabled];
return _isEnabled;
}
@@ -241,9 +275,12 @@ var _CPToolbarSeparatorItemView = nil;
Sets whether the item is enabled.
@param aFlag <code>YES</code> enables the item
*/
- (void)setEnabled:(BOOL)aFlag
- (void)setEnabled:(BOOL)shouldBeEnabled
{
_isEnabled = aFlag;
if ([_view respondsToSelector:@selector(setEnabled:)])
[_view setEnabled:shouldBeEnabled];
_isEnabled = shouldBeEnabled;
}
/*!
@@ -251,6 +288,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (CPImage)image
{
if ([_view respondsToSelector:@selector(image)])
return [_view image];
return _image;
}
@@ -260,22 +300,24 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setImage:(CPImage)anImage
{
if ([_view respondsToSelector:@selector(setImage:)])
[_view setImage:anImage];
_image = anImage;
// FIXME: We can't keep assuming this.
[_view setImage:anImage];
if (!_image)
return;
var imageSize = [_image size];
if (_minSize.width == 0 && _minSize.height == 0 &&
_maxSize.width == 0 && _maxSize.height == 0 &&
(imageSize.width > 0 || imageSize.height > 0))
_maxSize.width == 0 && _maxSize.height == 0)
{
[self setMinSize:imageSize];
[self setMaxSize:imageSize];
var imageSize = [_image size];
if (imageSize.width > 0 || imageSize.height > 0)
{
[self setMinSize:imageSize];
[self setMaxSize:imageSize];
}
}
}
@@ -285,10 +327,10 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setAlternateImage:(CPImage)anImage
{
_alternateImage = anImage;
if ([_view respondsToSelector:@selector(setAlternateImage:)])
[_view setAlternateImage:anImage];
// FIXME: We can't keep assuming this.
[_view setAlternateImage:anImage];
_alternateImage = anImage;
}
/*!
@@ -296,6 +338,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (CPImage)alternateImage
{
if ([_view respondsToSelector:@selector(alternateIamge)])
return [_view alternateImage];
return _alternateImage;
}
@@ -313,7 +358,20 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setView:(CPView)aView
{
if (_view == aView)
return;
_view = aView;
if (_view)
{
// Tags get forwarded.
if (_tag !== 0 && [_view respondsToSelector:@selector(setTag:)])
[_view setTag:_tag];
_target = nil;
_action = nil;
}
}
/*!
@@ -394,21 +452,21 @@ CPToolbarItemVisibilityPriorityUser
{
var copy = [[[self class] alloc] initWithItemIdentifier:_itemIdentifier];
if (_view)
[copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]];
[copy setLabel:_label];
[copy setPaletteLabel:_paletteLabel];
[copy setToolTip:_toolTip];
[copy setToolTip:[self toolTip]];
[copy setTag:_tag];
[copy setTarget:_target];
[copy setAction:_action];
[copy setTag:[self tag]];
[copy setTarget:[self target]];
[copy setAction:[self action]];
[copy setEnabled:_isEnabled];
[copy setEnabled:[self isEnabled]];
[copy setImage:_image];
[copy setAlternateImage:_alternateImage];
if (_view)
[copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]];
[copy setMinSize:_minSize];
[copy setMaxSize:_maxSize];
+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
+5
View File
@@ -35,6 +35,11 @@ CPSharedDOMWindowBridge = nil;
var ExcludedDOMElements = [];
// Define up here so compressor knows about em.
var CPDOMWindowGetFrame,
CPDOMEventGetClickCount,
CPDOMEventStop;
@implementation CPDOMWindowBridge : CPObject
{
CPArray _orderedWindows;
+58
View File
@@ -0,0 +1,58 @@
These graphics come from the Tango Desktop Project (http://tango.freedesktop.org/Tango_Desktop_Project).
They are released under the Creative Commons Attribution Share-Alike license, full text below.
(license available from CC here: http://creativecommons.org/licenses/by-sa/2.5/)
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
1. Definitions
"Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
"Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
"Licensor" means the individual or entity that offers the Work under the terms of this License.
"Original Author" means the individual or entity who created the Work.
"Work" means the copyrightable work of authorship offered under the terms of this License.
"You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
"License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.
2. Fair Use Rights. Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.
3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
to create and reproduce Derivative Works;
to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
For the avoidance of doubt, where the work is a musical composition:
Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).
The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.
4. Restrictions.The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.
5. Representations, Warranties and Disclaimer
UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. Termination
This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
8. Miscellaneous
Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

+1
View File
@@ -238,6 +238,7 @@
[_titleField setAlignment:_alignment];
[_titleField setTextColor:_textColor];
[_titleField setHidden:_imagePosition == CPImageOnly];
[_titleField setHitTests:NO];
[self addSubview:_titleField];
}
+6 -1
View File
@@ -61,7 +61,12 @@
- (CPString)resourcePath
{
return [self bundlePath] + "Resources/";
var path = [self bundlePath];
if (path.length)
path += '/';
return path + "Resources";
}
- (Class)principalClass
+1 -1
View File
@@ -363,7 +363,7 @@ var _CPKeyedArchiverStringClass = Nil,
*/
- (void)encodeNumber:(CPNumber)aNumber forKey:(CPString)aKey
{
[_plistObject setObject:_CPKeyedArchiverEncodeObject(self, aNuumber, NO) forKey:aKey];
[_plistObject setObject:_CPKeyedArchiverEncodeObject(self, aNumber, NO) forKey:aKey];
}
/*!
+30 -4
View File
@@ -452,6 +452,21 @@ var CPStringHashes = new objj_dictionary();
return CPOrderedSame;
}
/*!
Compares the receiver to the specified string, using options in range.
@param aString the string with which to compare the range of the receiver specified by range.
@param aMask the options to use for the comparison
@param range the range of the receiver over which to perform the comparison. The range must not exceed the bounds of the receiver.
@return the result of the comparison
*/
- (CPComparisonResult)compare:(CPString)aString options:(int)aMask range:(CPRange)range
{
var lhs = [self substringWithRange:range],
rhs = aString;
return [lhs compare:rhs options:aMask];
}
/*!
Returns <code>YES</code> if the receiver starts
with the specified string. If <code>aString</code>
@@ -595,13 +610,24 @@ var CPStringHashes = new objj_dictionary();
}
/*!
Until this is corrected
@ignore
Deletes the last path component of a string.
This method assumes that the string's content is a '/'
separated file system path.
*/
- (CPString)stringByDeletingLastPathComponent
{
// FIXME: this is wrong: a/a/ returns a/a/.
return substr(0, lastIndexOf('/') + 1);
var path = self,
start = length - 1;
while (path.charAt(start) === '/')
start--;
path = path.substr(0, path.lastIndexOf('/', start));
if (path === "" && charAt(0) === '/')
return '/';
return path;
}
- (CPString)stringByStandardizingPath
+4 -14
View File
@@ -16,24 +16,14 @@
<dict>
<key>Name</key>
<string>Debug</string>
<key>Settings</key>
<dict>
<key>PREPROCESS</key>
<true/>
<key>FLAGS</key>
<string>-DDEBUG</string>
</dict>
<key>Flags</key>
<string>-DDEBUG -g</string>
</dict>
<dict>
<key>Name</key>
<string>Release</string>
<key>Settings</key>
<dict>
<key>PREPROCESS</key>
<true/>
<key>PREINTERPRET</key>
<true/>
</dict>
<key>Flags</key>
<string>-O</string>
</dict>
</array>
</dict>
+3 -3
View File
@@ -30,14 +30,14 @@
<mkdir dir = "${Build.Products}" />
<concat destfile = "${Build.Products}/Objecive-J.concat">
<concat destfile = "${Build.Products}/Objective-J.concat">
<filelist refid = "Files.Objective-J" />
</concat>
<!-- Rhino Version -->
<mkdir dir = "${Build.Products}/Rhino" />
<preprocess file = "${Build.Products}/Objecive-J.concat" output = "${Build.Products}/Rhino/Objective-J.js">
<preprocess file = "${Build.Products}/Objective-J.concat" output = "${Build.Products}/Rhino/Objective-J.js">
<arguments>
<arg value = "-DRHINO"/>
</arguments>
@@ -48,7 +48,7 @@
<!-- Browser Version -->
<mkdir dir = "${Build.Products}/Browser" />
<preprocess file = "${Build.Products}/Objecive-J.concat" output = "${Build.Products}/Browser/Objective-J.preprocessed" />
<preprocess file = "${Build.Products}/Objective-J.concat" output = "${Build.Products}/Browser/Objective-J.preprocessed" />
<mkdir dir = "${Build.Objective-J}/Objective-J" />
+1 -1
View File
@@ -202,7 +202,7 @@ function fragment_evaluate_file(aFragment)
// Grab the file's fragments if it has them, or preprocess it if not.
if (!aFile.fragments)
aFile.fragments = objj_preprocess(aFile.contents, aFile.bundle, aFile);
aFile.fragments = objj_preprocess(aFile.contents, aFile.bundle, aFile, OBJJ_PREPROCESSOR_DEBUG_SYMBOLS);
var fragments = aFile.fragments,
count = fragments.length,
+21 -14
View File
@@ -20,13 +20,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
function objj_preprocess(/*String*/ aString, /*objj_bundle*/ aBundle, /*objj_file*/ aSourceFile)
OBJJ_PREPROCESSOR_DEBUG_SYMBOLS = 1 << 0;
function objj_preprocess(/*String*/ aString, /*objj_bundle*/ aBundle, /*objj_file*/ aSourceFile, /*unsigned*/ flags)
{
try
{
OBJJ_CURRENT_BUNDLE = aBundle;
return new objj_preprocessor(aString, aSourceFile).fragments();
return new objj_preprocessor(aString, aSourceFile, flags).fragments();
}
catch (anException)
{
@@ -133,7 +135,7 @@ objj_stringBuffer.prototype.isEmpty = function()
return (this.atoms.length === 0);
}
var objj_preprocessor = function(aString, aSourceFile)
var objj_preprocessor = function(aString, aSourceFile, flags)
{
this._currentClass = "";
this._currentSuperClass = "";
@@ -142,6 +144,7 @@ var objj_preprocessor = function(aString, aSourceFile)
this._fragments = [];
this._preprocessed = new objj_stringBuffer();
this._tokens = new objj_lexer(aString);
this._flags = flags;
this.preprocess(this._tokens, this._preprocessed);
this.fragment();
@@ -563,10 +566,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 +587,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");
@@ -735,8 +739,11 @@ objj_preprocessor.prototype.method = function(tokens)
CONCAT(buffer, "new objj_method(sel_getUid(\"");
CONCAT(buffer, selector);
CONCAT(buffer, "\"), function ");
CONCAT(buffer, "$" + this._currentClass + "__" + selector.replace(/:/g, "_"));
CONCAT(buffer, "\"), function");
if (this._flags & OBJJ_PREPROCESSOR_DEBUG_SYMBOLS)
CONCAT(buffer, " $" + this._currentClass + "__" + selector.replace(/:/g, "_"));
CONCAT(buffer, "(self, _cmd");
for(; index < count; ++index)
@@ -810,7 +817,7 @@ objj_preprocessor.prototype.preprocess = function(tokens, /*objj_stringBuffer*/
// Skip everything until the next open curly brace.
while((token = tokens.next()) && token != TOKEN_OPEN_BRACE)
CONCAT(bfufer, token);
CONCAT(buffer, token);
// Place the open curly brace as well, and the function name
CONCAT(buffer, token + "\n \"__FIREBUG_FNAME__" + functionName + "\".length;\n");
-36
View File
@@ -9,42 +9,6 @@ var STATIC_MAGIC_NUMBER = "@STATIC",
var STATIC_EXTENSION = "sj";
function objj_preprocess_file(aFilePath, fileContents, checkSyntax)
{
// Preprocess contents into fragments.
var fragments = objj_preprocess(fileContents, { path:"/x" }, { path:aFilePath}),
index = 0,
count = fragments.length,
preprocessed = MARKER_PATH + ';' + aFilePath.length() + ';' + aFilePath;
// Writer preprocessed fragments out.
for (; index < count; ++index)
{
var fragment = fragments[index];
if (IS_FILE(fragment))
preprocessed += (IS_LOCAL(fragment) ? MARKER_IMPORT_LOCAL : MARKER_IMPORT_STD) + ';' + GET_PATH(fragment).length + ';' + GET_PATH(fragment);
else
{
if (checkSyntax)
{
try
{
new Function(GET_CODE(fragment));
}
catch (e)
{
e.fragment = fragment;
throw e;
}
}
preprocessed += MARKER_CODE + ';' + GET_CODE(fragment).length + ';' + GET_CODE(fragment);
}
}
return preprocessed;
}
function objj_decompile(aString, bundle)
{
var stream = new objj_markedStream(aString);
+1 -1
View File
@@ -46,7 +46,7 @@ the Cappuccino Tools:
1. Download the Cappuccino Tools from http://cappuccino.org/tools.
2. Unarchive the downloaded file.
3. Run: chmod +x install-tools
4. Run: sudo ./install-tools
4. Run: sudo sh ./install-tools
5. Set your environment variables:
export PATH=$PATH:/usr/local/bin
export OBJJ_HOME=/usr/local/share/objj
+20 -1
View File
@@ -56,9 +56,28 @@ import <Foundation/CPString.j>
];
for (var i = 0; i < testStrings.length; i++)
[self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
[self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
}
- (void)testStringByDeletingLastPathComponent
{
var testStrings = [
["/tmp/scratch.tiff", "/tmp"],
["/tmp/lock/", "/tmp"],
["/tmp/", "/"],
["/tmp", "/"],
["/", "/"],
["scratch.tiff", ""],
["a/b/c/d//////", "a/b/c"],
["a/b/././././c/d/./././", "a/b/././././c/d/./."],
[@"a/b/././././d////", "a/b/./././."],
[@"~/a", "~"],
[@"~/a/", "~"],
[@"../../", ".."]
];
for (var i = 0; i < testStrings.length; i++)
[self assert:[testStrings[i][0] stringByDeletingLastPathComponent] equals:testStrings[i][1]];
}
@end
+1
View File
@@ -33,6 +33,7 @@ ln -sf $INSTALL_DIR/share/objj/bin/objjc $INSTALL_DIR/bin/objjc
ln -sf $INSTALL_DIR/share/objj/bin/steam $INSTALL_DIR/bin/steam
ln -sf $INSTALL_DIR/share/objj/bin/bake $INSTALL_DIR/bin/bake
ln -sf $INSTALL_DIR/share/objj/bin/press $INSTALL_DIR/bin/press
ln -sf $INSTALL_DIR/share/objj/bin/cplutil $INSTALL_DIR/bin/cplutil
chmod +x $INSTALL_DIR/bin/nib2cib
chmod +x $INSTALL_DIR/bin/objj
File diff suppressed because it is too large. Load diff
+1
View File
@@ -11,6 +11,7 @@
<file name = "steam/build.xml" />
<file name = "bake/build.xml" />
<file name = "press/build.xml" />
<file name = "cplutil/build.xml" />
<file name = "Utilities/build.xml" />
<file name = "NewApplication/build.xml" />
</filelist>
+56
View File
@@ -0,0 +1,56 @@
<?xml version = "1.0"?>
<project name = "cplutil" default = "build" basedir = "." >
<import file = "../../common.xml" />
<property name = "Build.Products" location = "${Build}/cplutil.build/${Configuration}" />
<property name = "Build.cplutil" location = "${Build}/${Configuration}/cplutil" />
<target name = "clean">
<delete dir = "${Build.cplutil}" verbose = "true" />
<delete dir = "${Build.Products}" verbose = "true" />
</target>
<target name = "build">
<mkdir dir = "${Build.Products}" />
<concat destfile = "${Build.Products}/cplutil.js">
<filelist>
<file name="${basedir}/../Utilities/bridge.js" />
<file name="${basedir}/../Utilities/regex-bridge.js" />
<file name="${Build}/Objective-J.build/\${Configuration}/Rhino/Objective-J.js" />
<file name="${basedir}/cplutil.js" />
</filelist>
</concat>
<mkdir dir = "${Build.cplutil}" />
<jsc>
<arguments>
<arg line = "-o cplutil.class" />
<arg value = "-nosource" />
<arg value = "${Build.Products}/cplutil.js" />
</arguments>
</jsc>
<move file = "${Build.Products}/cplutil.class" tofile = "${Build.cplutil}/cplutil.class" />
<copy file = "cplutil" tofile = "${Build.cplutil}/cplutil" />
<chmod file = "${Build.cplutil}/cplutil" perm = "+x" />
</target>
<target name = "release" depends = "build">
<antcall target = "prepare-release" />
<copy file = "${Build.cplutil}/cplutil" tofile = "${Build.Cappuccino.Tools.Bin}/cplutil" />
<chmod file = "${Build.Cappuccino.Tools.Bin}/cplutil" perm = "+x" />
<copy file = "${Build.cplutil}/cplutil.class" tofile = "${Build.Cappuccino.Tools.Lib}/cplutil.class" />
</target>
</project>
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
# if OBJJ_HOME isn't set, try to determine it
if [ -z $OBJJ_HOME ]; then
# get path of the executable
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
# resolve symlinks
if [ -h $SELF_PATH ]; then
SELF_PATH=`readlink $SELF_PATH`
fi
# get second ancestor directory
SELF_DIR=`dirname $SELF_PATH`
export OBJJ_HOME=`dirname $SELF_DIR`
# check to ensure it exists, print message
if [ -d $OBJJ_HOME ]; then
echo "OBJJ_HOME not set, defaulting to $OBJJ_HOME" 1>&2
else
echo "OBJJ_HOME not set, default at $OBJJ_HOME doesn't exist, exiting" 1>&2
exit 2
fi
fi
OBJJ_LIB="$OBJJ_HOME/lib"
CLASSPATH="$OBJJ_LIB:$OBJJ_LIB/js.jar"
# convert paths for Cygwin
if [[ `uname` == CYGWIN* ]]; then
CLASSPATH=`cygpath -wp "$CLASSPATH"`
fi
java -classpath $CLASSPATH cplutil $@
+103
View File
@@ -0,0 +1,103 @@
importPackage(java.lang);
importClass(java.io.File);
importClass(java.io.BufferedReader);
importClass(java.io.FileReader);
importClass(java.io.BufferedWriter);
importClass(java.io.FileWriter);
function printUsage()
{
print("this is where you say the usage");
}
function main()
{
if (arguments.length < 1)
return printUsage();
var allFiles = NO,
format = nil,
filePaths = [],
outPath = nil,
outExtension = nil;
index = 0,
count = arguments.length;
for (; index < count; ++index)
{
var argument = arguments[index];
if (argument.charAt(0) === '-' && !allFiles)
{
if (filePaths.length > 0)
return printUsage();
else if (argument === "-convert")
format = arguments[++index];
else if (argument === "-o")
outPath = arguments[++index];
else if (argument === "-e")
outExtension = arguments[++index];
else if (argument === "--")
allFiles = YES;
else if (argument === "-help")
return printUsage();
}
else
filePaths.push(arguments[index]);
}
index = 0;
count = filePaths.length;
for (; index < count; ++index)
{
// Read the plist file
var file = new File(filePaths[index]),
reader = new BufferedReader(new FileReader(file)),
fileContents = "";
// Get contents of the file
while (reader.ready())
fileContents += reader.readLine() + '\n';
reader.close();
var data = new objj_data();
data.string = fileContents;
var plistObject = new CPPropertyListCreateFromData(data);
if (format === "280north1")
data = CPPropertyListCreate280NorthData(plistObject);
else if (format === "xml1")
data = CPPropertyListCreateXMLData(plistObject);
var outFile = file;
if (outPath)
outFile = new File(outPath);
// else if (outExtension)
// Write out file
var writer = new BufferedWriter(new FileWriter(outFile));
writer.write(data.string);
writer.close();
}
}
main.apply(main, arguments);
+6 -9
View File
@@ -22,24 +22,21 @@
@import "NSButton.j"
@import "NSCell.j"
@import "NSColor.j"
@import "NSColorWell.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
+60
View File
@@ -0,0 +1,60 @@
/*
* NSColorWell.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/CPColorWell.j>
@import "NSCell.j"
@import "NSControl.j"
@implementation CPColorWell (NSCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
{
self = [super NS_initWithCoder:aCoder];
if (self)
{
[self setBordered:[aCoder decodeBoolForKey:"NSIsBordered"]];
[self setColor:[aCoder decodeBoolForKey:"NSColor"]];
}
return self;
}
@end
@implementation NSColorWell : CPColorWell
{
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self NS_initWithCoder:aCoder];
}
- (Class)classForKeyedArchiver
{
return [CPColorWell 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
+2
View File
@@ -51,6 +51,8 @@
<copy file = "${Build.objjc}/objjc.class" tofile = "${Build.Cappuccino.Tools.Lib}/objjc.class" />
<copy file = "shrinksafe.jar" tofile = "${Build.Cappuccino.Tools.Lib}/shrinksafe.jar" />
</target>
</project>
+138 -47
View File
@@ -8,27 +8,86 @@ importClass(java.io.BufferedWriter);
importClass(java.io.FileWriter);
function exec(command)
{
var p = Packages.java.lang.Runtime.getRuntime().exec(command);//jsArrayToJavaArray(command));
var reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(p.getInputStream()));
while (s = reader.readLine())
System.out.println(s);
var reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(p.getErrorStream()));
while (s = reader.readLine())
System.out.println(s);
var result = p.waitFor();
return result;
OBJJ_PREPROCESSOR_PREPROCESS = 1 << 10;
OBJJ_PREPROCESSOR_COMPRESS = 1 << 11;
OBJJ_PREPROCESSOR_SYNTAX = 1 << 12;
function exec(/*Array*/ command, /*Boolean*/ showOutput)
{
var line = "",
output = "",
process = Packages.java.lang.Runtime.getRuntime().exec(command),//jsArrayToJavaArray(command));
reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getInputStream()));
while (line = reader.readLine())
{
if (showOutput)
System.out.println(line);
output += line + '\n';
}
reader = new Packages.java.io.BufferedReader(new Packages.java.io.InputStreamReader(process.getErrorStream()));
while (line = reader.readLine())
System.out.println(line);
try
{
if (process.waitFor() != 0)
System.err.println("exit value = " + process.exitValue());
}
catch (anException)
{
System.err.println(anException);
}
return output;
}
function preprocess(aFilePath, outFilePath, gccArgs, shouldObjjPreprocess, shouldCheckSyntax)
function compress(/*String*/ aCode, /*Object*/ flags, /*File*/ tmpFile)
{
var writer = new BufferedWriter(new FileWriter(tmpFile));
writer.write(aCode);
writer.close();
return exec(["java", "-jar", OBJJ_HOME + "/lib/shrinksafe.jar", "-c", tmpFile.getCanonicalPath()]);
}
//#define SET_CONTEXT(aFragment, aContext) aFragment.context = aContext
//#define GET_CONTEXT(aFragment) aFragment.context
//#define SET_TYPE(aFragment, aType) aFragment.type = (aType)
//#define GET_TYPE(aFragment) aFragment.type
function GET_CODE(aFragment) { return aFragment.info; }
//#define SET_CODE(aFragment, aCode) aFragment.info = (aCode)
function GET_PATH(aFragment) { return aFragment.info; }
//#define SET_PATH(aFragment, aPath) aFragment.info = aPath
//#define GET_BUNDLE(aFragment) aFragment.bundle
//#define SET_BUNDLE(aFragment, aBundle) aFragment.bundle = aBundle
//#define GET_FILE(aFragment) aFragment.file
//#define SET_FILE(aFragment, aFile) aFragment.file = aFile
function IS_FILE(aFragment) { return (aFragment.type & FRAGMENT_FILE); }
function IS_LOCAL(aFragment) { return (aFragment.type & FRAGMENT_LOCAL); }
//#define IS_IMPORT(aFragment) (aFragment.type & FRAGMENT_IMPORT)
function preprocess(aFilePath, outFilePath, gccArgs, flags)
{
print("Statically Preprocessing " + aFilePath);
var shouldObjjPreprocess = flags & OBJJ_PREPROCESSOR_PREPROCESS,
shouldCheckSyntax = flags & OBJJ_PREPROCESSOR_SYNTAX,
shouldCompress = flags & OBJJ_PREPROCESSOR_COMPRESS;
// FIXME: figure out why this doesn't work on Windows/Cygwin
//var tmpFile = java.io.File.createTempFile("OBJJC", "");
var tmpFile = new java.io.File(outFilePath+".tmp");
@@ -59,32 +118,58 @@ function preprocess(aFilePath, outFilePath, gccArgs, shouldObjjPreprocess, shoul
reader.close();
var results;
try
{
results = objj_preprocess_file(new File(aFilePath).getName(), fileContents, shouldCheckSyntax);
}
catch (e)
{
if (e.fragment)
{
var lines = e.fragment.info.split("\n"),
PAD = 3;
System.out.println(
"Syntax error in "+e.fragment.file.path+
" on preprocessed line number "+e.lineNumber+"\n"+
"\t"+lines.slice(e.lineNumber-1-PAD<0 ? 0 : e.lineNumber-1-PAD, e.lineNumber+PAD).join("\n\t"));
}
else
System.out.println("Unknown error: " + e);
System.exit(1);
}
// Preprocess contents into fragments.
var filePath = new String(new File(aFilePath).getName()),
fragments = objj_preprocess(fileContents, { path:"/x" }, {path:filePath}, flags),
index = 0,
count = fragments.length,
preprocessed = MARKER_PATH + ';' + filePath.length + ';' + filePath;
// Writer preprocessed fragments out.
for (; index < count; ++index)
{
var fragment = fragments[index];
if (IS_FILE(fragment))
preprocessed += (IS_LOCAL(fragment) ? MARKER_IMPORT_LOCAL : MARKER_IMPORT_STD) + ';' + GET_PATH(fragment).length + ';' + GET_PATH(fragment);
else
{
var code = GET_CODE(fragment);
if (shouldCheckSyntax)
{
try
{
new Function(GET_CODE(fragment));
}
catch (e)
{
var lines = e.fragment.info.split("\n"),
PAD = 3;
System.out.println(
"Syntax error in "+e.fragment.file.path+
" on preprocessed line number "+e.lineNumber+"\n"+
"\t"+lines.slice(e.lineNumber-1-PAD<0 ? 0 : e.lineNumber-1-PAD, e.lineNumber+PAD).join("\n\t"));
System.exit(1);
}
}
if (shouldCompress)
{
code = compress("function(){" + code + '}', 0, tmpFile);
code = code.substr("function(){".length, code.length - "function(){};\n\n".length);
}
preprocessed += MARKER_CODE + ';' + code.length + ';' + code;
}
}
// Write file.
var writer = new BufferedWriter(new FileWriter(outFilePath));
writer.write(results);
writer.write(preprocessed);
writer.close();
}
@@ -98,9 +183,9 @@ function main()
gccArgs = [],
shouldObjjPreprocess = true,
shouldCheckSyntax = true;
flags = OBJJ_PREPROCESSOR_PREPROCESS | OBJJ_PREPROCESSOR_SYNTAX;
for (; index < count; ++index)
{
if (args[index] == "-o")
@@ -109,24 +194,30 @@ function main()
outFilePaths.push(args[index]);
}
else if (args[index].indexOf("-D") == 0)
else if (args[index].indexOf("-D") === 0)
gccArgs.push(args[index])
else if (args[index].indexOf("-U") == 0)
else if (args[index].indexOf("-U") === 0)
gccArgs.push(args[index]);
else if (args[index].indexOf("-E") == 0)
shouldObjjPreprocess = false;
else if (args[index].indexOf("-E") === 0)
flags &= ~OBJJ_PREPROCESSOR_PREPROCESS;
else if (args[index].indexOf("-S") == 0)
shouldCheckSyntax = false;
else if (args[index].indexOf("-S") === 0)
flags &= ~OBJJ_PREPROCESSOR_SYNTAX;
else if (args[index].indexOf("-g") === 0)
flags |= OBJJ_PREPROCESSOR_DEBUG_SYMBOLS;
else if (args[index].indexOf("-O") === 0)
flags |= OBJJ_PREPROCESSOR_COMPRESS;
else
filePaths.push(args[index]);
}
for (index = 0, count = filePaths.length; index < count; ++index)
preprocess(filePaths[index], outFilePaths[index], gccArgs, shouldObjjPreprocess, shouldCheckSyntax);
preprocess(filePaths[index], outFilePaths[index], gccArgs, flags);
}
args = arguments;
Binary file not shown.
+7 -3
View File
@@ -32,7 +32,7 @@ function main()
{
case "--main":
if (args.length)
mainFile = args.shift();
mainFilename = args.shift();
else
usageError = true;
break;
@@ -107,7 +107,7 @@ function main()
{
var xmlOutput = new Packages.java.io.ByteArrayOutputStream();
outputTransformer(xmlOutput, aResponse.xml, "UTF-8");
__fakeResponse.xml = String(xmlOutput.toString());
__fakeResponse.text = CPPropertyListCreate280NorthData(CPPropertyListCreateFromXMLData({ string:String(xmlOutput.toString())})).string;
//CPLog.trace("SERIALIZED: " + __fakeResponse.xml.substring(0,100));
}
@@ -204,7 +204,11 @@ function main()
bundle.path = aResponse.filePath;
if (aResponse.success)
bundle.info = CPPropertyListCreateFromXMLData({ string : aResponse.xml });
{
var data = new objj_data();
data.string = aResponse.text;
bundle.info = CPPropertyListCreateFrom280NorthData(data);
}
else
bundle.info = new objj_dictionary();
+2 -2
View File
@@ -105,7 +105,7 @@
<element name = "arguments" optional = "true" />
<sequential>
<exec executable = "gcc" output = "@{output}">
<exec executable = "gcc" output = "@{output}" error = "@{output}.err">
<!-- Preprocessing only -->
<arg value = "-E" />
<!-- Interpret files as C source files (instead of treating them as object files); this option is given to make the compiler preprocess them -->
@@ -123,4 +123,4 @@
</macrodef>
</project>
</project>