Merge remote-tracking branch 'upstream/master' into CPAnimationContext

Conflicts:
	AppKit/CPCompatibility.j
This commit is contained in:
cacaodev
2014-02-21 20:39:35 +01:00
535 changed files with 39484 additions and 16295 deletions
+2
View File
@@ -11,5 +11,7 @@ xcuserdata/
!*.xcodeproj/project.pbxproj
*.xCodeSupport/
*.XcodeSupport/
*XcodeSupport/
Tests/Manual/**/*.xcodeproj
*.sublime-project
*.sublime-workspace
+1 -1
View File
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 0.8
install: ./bootstrap.sh --quiet --noprompt --directory ./narwhal
install: ./bootstrap.sh --noprompt --directory ./narwhal
script: jake test
env: PATH="$TRAVIS_BUILD_DIR/narwhal/bin:$PATH" CAPP_BUILD="$TRAVIS_BUILD_DIR/Build" NARWHAL_ENGINE=rhino
+151 -44
View File
@@ -41,6 +41,9 @@
@global CPApp
var CPAlertDelegate_alertShowHelp_ = 1 << 0,
CPAlertDelegate_alertDidEnd_returnCode_ = 1 << 1;
/*
@global
@group CPAlertStyle
@@ -59,6 +62,14 @@ CPCriticalAlertStyle = 2;
var bottomHeight = 71;
@protocol CPAlertDelegate <CPObject>
@optional
- (BOOL)alertShowHelp:(CPAlert)alert;
- (void)alertDidEnd:(CPAlert)theAlert returnCode:(int)returnCode;
@end
/*!
@ingroup appkit
@@ -83,31 +94,33 @@ var bottomHeight = 71;
*/
@implementation CPAlert : CPObject
{
BOOL _showHelp @accessors(property=showsHelp);
BOOL _showSuppressionButton @accessors(property=showsSuppressionButton);
BOOL _showHelp @accessors(property=showsHelp);
BOOL _showSuppressionButton @accessors(property=showsSuppressionButton);
CPAlertStyle _alertStyle @accessors(property=alertStyle);
CPString _title @accessors(property=title);
CPView _accessoryView @accessors(property=accessoryView);
CPImage _icon @accessors(property=icon);
CPAlertStyle _alertStyle @accessors(property=alertStyle);
CPString _title @accessors(property=title);
CPView _accessoryView @accessors(property=accessoryView);
CPImage _icon @accessors(property=icon);
CPArray _buttons @accessors(property=buttons, readonly);
CPCheckBox _suppressionButton @accessors(property=suppressionButton, readonly);
CPArray _buttons @accessors(property=buttons, readonly);
CPCheckBox _suppressionButton @accessors(property=suppressionButton, readonly);
id _delegate @accessors(property=delegate);
id _modalDelegate;
SEL _didEndSelector;
id <CPAlertDelegate> _delegate @accessors(property=delegate);
id _modalDelegate;
SEL _didEndSelector @accessors(property=didEndSelector);
Function _didEndBlock;
unsigned _implementedDelegateMethods;
_CPAlertThemeView _themeView @accessors(property=themeView, readonly);
CPWindow _window @accessors(property=window, readonly);
int _defaultWindowStyle;
_CPAlertThemeView _themeView @accessors(property=themeView, readonly);
CPWindow _window @accessors(property=window, readonly);
int _defaultWindowStyle;
CPImageView _alertImageView;
CPTextField _informativeLabel;
CPTextField _messageLabel;
CPButton _alertHelpButton;
CPImageView _alertImageView;
CPTextField _informativeLabel;
CPTextField _messageLabel;
CPButton _alertHelpButton;
BOOL _needsLayout;
BOOL _needsLayout;
}
#pragma mark Creating Alerts
@@ -186,6 +199,30 @@ var bottomHeight = 71;
return self;
}
#pragma mark -
#pragma mark Delegate
/*!
Set the delegate of the receiver
@param aDelegate the delegate object for the alert.
*/
- (void)setDelegate:(id <CPAlertDelegate>)aDelegate
{
if (_delegate === aDelegate)
return;
_delegate = aDelegate;
_implementedDelegateMethods = 0;
if ([_delegate respondsToSelector:@selector(alertShowHelp:)])
_implementedDelegateMethods |= CPAlertDelegate_alertShowHelp_;
if ([_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
_implementedDelegateMethods |= CPAlertDelegate_alertDidEnd_returnCode_;
}
#pragma mark Accessors
- (CPTheme)theme
@@ -224,16 +261,15 @@ var bottomHeight = 71;
}
/*! @deprecated
*/
- (void)setWindowStyle:(int)aStyle
/*! @deprecated */
- (void)setWindowStyle:(int)style
{
CPLog.warn("DEPRECATED: setWindowStyle: is deprecated. use setTheme: instead");
[self setTheme:(aStyle === CPHUDBackgroundWindowMask) ? [CPTheme defaultHudTheme] : [CPTheme defaultTheme]];
[self setTheme:(style === CPHUDBackgroundWindowMask) ? [CPTheme defaultHudTheme] : [CPTheme defaultTheme]];
}
/*! @deprecated
*/
/*! @deprecated */
- (int)windowStyle
{
CPLog.warn("DEPRECATED: windowStyle: is deprecated. use theme instead");
@@ -242,18 +278,19 @@ var bottomHeight = 71;
/*!
set the text of the alert's message
Set the text of the alert's message.
@param aText CPString containing the text
*/
- (void)setMessageText:(CPString)aText
- (void)setMessageText:(CPString)text
{
[_messageLabel setStringValue:aText];
[_messageLabel setStringValue:text];
_needsLayout = YES;
}
/*!
return the content of the message text
Return the content of the message text.
@return CPString containing the message text
*/
- (CPString)messageText
@@ -262,13 +299,13 @@ var bottomHeight = 71;
}
/*!
set the text of the alert's informative text
Set the text of the alert's informative text.
@param aText CPString containing the informative text
*/
- (void)setInformativeText:(CPString)aText
- (void)setInformativeText:(CPString)text
{
[_informativeLabel setStringValue:aText];
[_informativeLabel setStringValue:text];
_needsLayout = YES;
}
@@ -285,6 +322,7 @@ var bottomHeight = 71;
/*!
Sets the title of the alert window.
This API is not present in Cocoa.
@param aTitle CPString containing the window title
*/
- (void)setTitle:(CPString)aTitle
@@ -294,7 +332,7 @@ var bottomHeight = 71;
}
/*!
set the accessory view
Set the accessory view.
@param aView the accessory view
*/
@@ -305,7 +343,7 @@ var bottomHeight = 71;
}
/*!
set if alert shows the suppression button
Set if the alert shows the suppression button.
@param shouldShowSuppressionButton YES or NO
*/
@@ -596,6 +634,17 @@ var bottomHeight = 71;
[CPApp runModalForWindow:_window];
}
/*!
The same as \c runModal, but executes the code in \c block when the
alert is dismissed.
*/
- (void)runModalWithDidEndBlock:(Function /*(CPAlert alert, int returnCode)*/)block
{
_didEndBlock = block;
[self runModal];
}
/*!
Runs the receiver modally as an alert sheet attached to a specified window.
@@ -630,6 +679,20 @@ var bottomHeight = 71;
[self beginSheetModalForWindow:aWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
}
/*!
Runs the receiver modally as an alert sheet attached to a specified window.
Executes the code in \c block when the alert is dismissed.
@param window The parent window for the sheet.
@param block Code block to execute on dismissal
*/
- (void)beginSheetModalForWindow:(CPWindow)aWindow didEndBlock:(Function /*(CPAlert alert, int returnCode)*/)block
{
_didEndBlock = block;
[self beginSheetModalForWindow:aWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
}
#pragma mark Private
/*!
@@ -642,6 +705,7 @@ var bottomHeight = 71;
_window = [[CPPanel alloc] initWithContentRect:frame styleMask:forceStyle || _defaultWindowStyle];
[_window setLevel:CPStatusWindowLevel];
[_window setPlatformWindow:[[CPApp keyWindow] platformWindow]];
if (_title)
[_window setTitle:_title];
@@ -668,8 +732,7 @@ var bottomHeight = 71;
*/
- (@action)_showHelp:(id)aSender
{
if ([_delegate respondsToSelector:@selector(alertShowHelp:)])
[_delegate alertShowHelp:self];
[self _sendDelegateAlertShowHelp];
}
/*
@@ -696,18 +759,62 @@ var bottomHeight = 71;
*/
- (void)_alertDidEnd:(CPWindow)aWindow returnCode:(int)returnCode contextInfo:(id)contextInfo
{
if (_didEndSelector)
objj_msgSend(_modalDelegate, _didEndSelector, self, returnCode, contextInfo);
if (_didEndBlock)
{
if (typeof(_didEndBlock) === "function")
_didEndBlock(self, returnCode);
else
CPLog.warn("%s: didEnd block is not a function", [self description]);
_modalDelegate = nil;
_didEndSelector = nil;
if ([_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
[_delegate alertDidEnd:self returnCode:returnCode];
// didEnd blocks are transient
_didEndBlock = nil;
}
else if (_modalDelegate)
{
if (_didEndSelector)
objj_msgSend(_modalDelegate, _didEndSelector, self, returnCode, contextInfo);
}
else if (_delegate)
{
if (_didEndSelector)
objj_msgSend(_delegate, _didEndSelector, self, returnCode);
else
[self _sendDelegateAlertDidEndReturnCode:returnCode];
}
}
@end
@implementation CPAlert (CPAlertDelegate)
/*!
@ignore
Call the delegate alertDidEnd:returnCode
*/
- (void)_sendDelegateAlertDidEndReturnCode:(int)returnCode
{
if (!(_implementedDelegateMethods & CPAlertDelegate_alertDidEnd_returnCode_))
return;
[_delegate alertDidEnd:self returnCode:returnCode];
}
/*!
@ignore
Call the delegate alertShowHelp:
*/
- (BOOL)_sendDelegateAlertShowHelp
{
if (!(_implementedDelegateMethods & CPAlertDelegate_alertShowHelp_))
return YES;
return [_delegate alertShowHelp:self];
}
@end
@implementation _CPAlertThemeView : CPView
+ (CPString)defaultThemeClass
@@ -715,7 +822,7 @@ var bottomHeight = 71;
return @"alert";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"size": CGSizeMake(400.0, 110.0),
+3 -1
View File
@@ -236,7 +236,9 @@ ACTUAL_FRAME_RATE = 0;
ACTUAL_FRAME_RATE = 0;
_lastTime = new Date();
_timer = [CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(animationTimerDidFire:) userInfo:nil repeats:YES];
var timerInterval = _frameRate <= 0.0 ? 0.0001 : 1.0/_frameRate;
_timer = [CPTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(animationTimerDidFire:) userInfo:nil repeats:YES];
}
/*
+42 -65
View File
@@ -22,6 +22,7 @@
@import <Foundation/CPBundle.j>
@import "CPApplication_Constants.j"
@import "CPCompatibility.j"
@import "CPColorPanel.j"
@import "CPCursor.j"
@@ -34,28 +35,26 @@
@import "CPPanel.j"
@import "CPPlatform.j"
@import "CPWindowController.j"
@import "_CPPopoverWindow.j"
var CPMainCibFile = @"CPMainCibFile",
CPMainCibFileHumanFriendly = @"Main cib file base name",
CPEventModifierFlags = 0;
CPApp = nil;
CPApplicationWillFinishLaunchingNotification = @"CPApplicationWillFinishLaunchingNotification";
CPApplicationDidFinishLaunchingNotification = @"CPApplicationDidFinishLaunchingNotification";
CPApplicationWillTerminateNotification = @"CPApplicationWillTerminateNotification";
CPApplicationWillBecomeActiveNotification = @"CPApplicationWillBecomeActiveNotification";
CPApplicationDidBecomeActiveNotification = @"CPApplicationDidBecomeActiveNotification";
CPApplicationWillResignActiveNotification = @"CPApplicationWillResignActiveNotification";
CPApplicationDidResignActiveNotification = @"CPApplicationDidResignActiveNotification";
@protocol CPApplicationDelegate <CPObject>
CPTerminateNow = YES;
CPTerminateCancel = NO;
CPTerminateLater = -1; // not currently supported
@optional
- (void)applicationDidBecomeActive:(CPNotification)aNotification;
- (void)applicationDidChangeScreenParameters:(CPNotification)aNotification;
- (void)applicationDidFinishLaunching:(CPNotification)aNotification;
- (void)applicationDidResignActive:(CPNotification)aNotification;
- (void)applicationWillBecomeActive:(CPNotification)aNotification;
- (void)applicationWillFinishLaunching:(CPNotification)aNotification;
- (void)applicationWillResignActive:(CPNotification)aNotification;
- (void)applicationWillTerminate:(CPNotification)aNotification;
CPRunStoppedResponse = -1000;
CPRunAbortedResponse = -1001;
CPRunContinuesResponse = -1002;
@end
/*!
@ingroup appkit
@@ -84,36 +83,36 @@ CPRunContinuesResponse = -1002;
*/
@implementation CPApplication : CPResponder
{
CPArray _eventListeners;
int _eventListenerInsertionIndex;
CPArray _eventListeners;
int _eventListenerInsertionIndex;
CPEvent _currentEvent;
CPWindow _lastMouseMoveWindow;
CPEvent _currentEvent;
CPWindow _lastMouseMoveWindow;
CPArray _windows;
CPWindow _keyWindow;
CPWindow _mainWindow;
CPWindow _previousKeyWindow;
CPWindow _previousMainWindow;
CPArray _windows;
CPWindow _keyWindow;
CPWindow _mainWindow;
CPWindow _previousKeyWindow;
CPWindow _previousMainWindow;
CPDocumentController _documentController;
CPDocumentController _documentController;
CPModalSession _currentSession;
CPModalSession _currentSession;
//
id _delegate;
BOOL _finishedLaunching;
BOOL _isActive;
id <CPApplicationDelegate> _delegate;
BOOL _finishedLaunching;
BOOL _isActive;
CPDictionary _namedArgs;
CPArray _args;
CPString _fullArgsString;
CPDictionary _namedArgs;
CPArray _args;
CPString _fullArgsString;
CPImage _applicationIconImage;
CPImage _applicationIconImage;
CPPanel _aboutPanel;
CPPanel _aboutPanel;
CPThemeBlend _themeBlend @accessors(property=themeBlend);
CPThemeBlend _themeBlend @accessors(property=themeBlend);
}
/*!
@@ -159,7 +158,7 @@ CPRunContinuesResponse = -1002;
react to these events.
@param aDelegate the delegate object
*/
- (void)setDelegate:(id)aDelegate
- (void)setDelegate:(id <CPApplicationDelegate>)aDelegate
{
if (_delegate == aDelegate)
return;
@@ -173,7 +172,8 @@ CPRunContinuesResponse = -1002;
CPApplicationDidBecomeActiveNotification, @selector(applicationDidBecomeActive:),
CPApplicationWillResignActiveNotification, @selector(applicationWillResignActive:),
CPApplicationDidResignActiveNotification, @selector(applicationDidResignActive:),
CPApplicationWillTerminateNotification, @selector(applicationWillTerminate:)
CPApplicationWillTerminateNotification, @selector(applicationWillTerminate:),
CPApplicationDidChangeScreenParametersNotification, @selector(applicationDidChangeScreenParameters:)
],
count = [delegateNotifications count];
@@ -586,8 +586,8 @@ CPRunContinuesResponse = -1002;
/* @ignore */
- (BOOL)_handleKeyEquivalent:(CPEvent)anEvent
{
return [[self keyWindow] performKeyEquivalent:anEvent] ||
[[self mainMenu] performKeyEquivalent:anEvent];
return [[self keyWindow] performKeyEquivalent:anEvent] ||
[[self mainMenu] performKeyEquivalent:anEvent];
}
/*!
@@ -601,33 +601,10 @@ CPRunContinuesResponse = -1002;
var theWindow = [anEvent window];
#if PLATFORM(DOM)
var willPropagate = [[theWindow platformWindow] _willPropagateCurrentDOMEvent];
// temporarily pretend we won't propagate the event. we'll restore the saved value later
// we do this outside the if so that changes user code might make in _handleKeyEquiv. are preserved
[[theWindow platformWindow] _propagateCurrentDOMEvent:NO];
#endif
// Check if this is a candidate for key equivalent...
if ([anEvent _couldBeKeyEquivalent] && [self _handleKeyEquivalent:anEvent])
{
#if PLATFORM(DOM)
var characters = [anEvent characters],
modifierFlags = [anEvent modifierFlags];
// Unconditionally propagate on these keys to solve browser copy paste bugs
if ((characters == "c" || characters == "x" || characters == "v") && (modifierFlags & CPPlatformActionKeyMask))
[[theWindow platformWindow] _propagateCurrentDOMEvent:YES];
#endif
// The key equivalent was handled.
return;
}
#if PLATFORM(DOM)
// if we make it this far, then restore the original willPropagate value
[[theWindow platformWindow] _propagateCurrentDOMEvent:willPropagate];
#endif
if ([anEvent type] == CPMouseMoved)
{
@@ -1380,8 +1357,8 @@ var _CPAppBootstrapperActions = nil;
if (mainCibFile)
{
[mainBundle loadCibFile:mainCibFile
externalNameTable:@{ CPCibOwner: CPApp }
loadDelegate:self];
externalNameTable:@{ CPCibOwner: CPApp }
loadDelegate:self];
return YES;
}
@@ -1458,7 +1435,7 @@ var _CPAppBootstrapperActions = nil;
+ (void)cibDidFailToLoad:(CPCib)aCib
{
throw new Error("Could not load main cib file (Did you forget to nib2cib it?).");
throw new Error("Could not load main cib file. Did you forget to nib2cib it?");
}
+ (void)reset
+40
View File
@@ -0,0 +1,40 @@
/*
* CPApplication_Constants.j
* AppKit
*
* Created by Aparajita Fishman.
* Copyright 2013 The Cappuccino Project
*
* 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
*/
CPApp = nil;
CPApplicationWillFinishLaunchingNotification = @"CPApplicationWillFinishLaunchingNotification";
CPApplicationDidFinishLaunchingNotification = @"CPApplicationDidFinishLaunchingNotification";
CPApplicationWillTerminateNotification = @"CPApplicationWillTerminateNotification";
CPApplicationWillBecomeActiveNotification = @"CPApplicationWillBecomeActiveNotification";
CPApplicationDidBecomeActiveNotification = @"CPApplicationDidBecomeActiveNotification";
CPApplicationWillResignActiveNotification = @"CPApplicationWillResignActiveNotification";
CPApplicationDidResignActiveNotification = @"CPApplicationDidResignActiveNotification";
CPApplicationDidChangeScreenParametersNotification = @"CPApplicationDidChangeScreenParametersNotification";
CPTerminateNow = YES;
CPTerminateCancel = NO;
CPTerminateLater = -1; // not currently supported
CPRunStoppedResponse = -1000;
CPRunAbortedResponse = -1001;
CPRunContinuesResponse = -1002;
+2
View File
@@ -147,6 +147,8 @@ var DefaultLineWidth = 1.0;
{
_path = CGPathCreateMutable();
_lineWidth = [[self class] defaultLineWidth];
_lineDashesPhase = 0;
_lineDashes = [];
}
return self;
+1 -1
View File
@@ -76,7 +76,7 @@ CPBelowBottom = 6;
return @"box";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"background-color": [CPNull null],
+14 -14
View File
@@ -71,7 +71,7 @@
return "browser";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"image-control-resize": [CPNull null],
@@ -171,7 +171,7 @@
[self addColumn];
}
- (void)setLastColumn:(int)columnIndex
- (void)setLastColumn:(CPInteger)columnIndex
{
if (columnIndex >= _tableViews.length)
return;
@@ -181,7 +181,7 @@
if (columnIndex > 0)
[_tableViews[columnIndex - 1] setNeedsDisplay:YES];
[_tableViews[columnIndex] setNeedsDisplay:YES];
[[_tableViews.slice(indexPlusOne) valueForKey:"enclosingScrollView"]
@@ -291,7 +291,7 @@
[aTableView addTableColumn:column];
}
- (void)reloadColumn:(int)column
- (void)reloadColumn:(CPInteger)column
{
[[self tableViewInColumn:column] reloadData];
}
@@ -359,7 +359,7 @@
// ITEMS
- (id)itemAtRow:(int)row inColumn:(int)column
- (id)itemAtRow:(CPInteger)row inColumn:(CPInteger)column
{
return [_tableDelegates[column] childAtIndex:row];
}
@@ -369,7 +369,7 @@
return [_delegate respondsToSelector:@selector(browser:isLeafItem:)] && [_delegate browser:self isLeafItem:item];
}
- (id)parentForItemsInColumn:(int)column
- (id)parentForItemsInColumn:(CPInteger)column
{
return [_tableDelegates[column] _item];
}
@@ -652,7 +652,7 @@
[_tableViews makeObjectsPerformSelector:@selector(registerForDraggedTypes:) withObject:types];
}
- (BOOL)canDragRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(int)columnIndex withEvent:(CPEvent)dragEvent
- (BOOL)canDragRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(CPInteger)columnIndex withEvent:(CPEvent)dragEvent
{
if ([_delegate respondsToSelector:@selector(browser:canDragRowsWithIndexes:inColumn:withEvent:)])
return [_delegate browser:self canDragRowsWithIndexes:rowIndexes inColumn:columnIndex withEvent:dragEvent];
@@ -660,7 +660,7 @@
return YES;
}
- (CPImage)draggingImageForRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(int)columnIndex withEvent:(CPEvent)dragEvent offset:(CGPoint)dragImageOffset
- (CPImage)draggingImageForRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(CPInteger)columnIndex withEvent:(CPEvent)dragEvent offset:(CGPoint)dragImageOffset
{
if ([_delegate respondsToSelector:@selector(browser:draggingImageForRowsWithIndexes:inColumn:withEvent:offset:)])
return [_delegate browser:self draggingImageForRowsWithIndexes:rowIndexes inColumn:columnIndex withEvent:dragEvent offset:dragImageOffset];
@@ -668,7 +668,7 @@
return nil;
}
- (CPView)draggingViewForRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(int)columnIndex withEvent:(CPEvent)dragEvent offset:(CGPoint)dragImageOffset
- (CPView)draggingViewForRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(CPInteger)columnIndex withEvent:(CPEvent)dragEvent offset:(CGPoint)dragImageOffset
{
if ([_delegate respondsToSelector:@selector(browser:draggingViewForRowsWithIndexes:inColumn:withEvent:offset:)])
return [_delegate browser:self draggingViewForRowsWithIndexes:rowIndexes inColumn:columnIndex withEvent:dragEvent offset:dragImageOffset];
@@ -771,7 +771,7 @@
CPBrowser _browser @accessors;
}
- (void)initWithFrame:(CGRect)aFrame
- (id)initWithFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
@@ -902,12 +902,12 @@
[_browser selectRowIndexes:selectedIndexes inColumn:_index];
}
- (id)childAtIndex:(unsigned)index
- (id)childAtIndex:(CPUInteger)index
{
return [_delegate browser:_browser child:index ofItem:_item];
}
- (BOOL)tableView:(CPTableView)aTableView acceptDrop:(id)info row:(int)row dropOperation:(CPTableViewDropOperation)operation
- (BOOL)tableView:(CPTableView)aTableView acceptDrop:(id)info row:(CPInteger)row dropOperation:(CPTableViewDropOperation)operation
{
if ([_delegate respondsToSelector:@selector(browser:acceptDrop:atRow:column:dropOperation:)])
return [_delegate browser:_browser acceptDrop:info atRow:row column:_index dropOperation:operation];
@@ -915,7 +915,7 @@
return NO;
}
- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id)info proposedRow:(int)row proposedDropOperation:(CPTableViewDropOperation)operation
- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id)info proposedRow:(CPInteger)row proposedDropOperation:(CPTableViewDropOperation)operation
{
if ([_delegate respondsToSelector:@selector(browser:validateDrop:proposedRow:column:dropOperation:)])
return [_delegate browser:_browser validateDrop:info proposedRow:row column:_index dropOperation:operation];
@@ -995,7 +995,7 @@
[aCoder encodeObject:_highlightedBranchImage forKey:"_CPBrowserLeafViewHighlightedBranchImageKey"];
}
- (void)initWithCoder:(CPCoder)aCoder
- (id)initWithCoder:(CPCoder)aCoder
{
if (self = [super initWithCoder:aCoder])
{
+35 -26
View File
@@ -149,7 +149,7 @@ CPButtonImageOffset = 3.0;
return @"button";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"image": [CPNull null],
@@ -292,7 +292,7 @@ CPButtonImageOffset = 3.0;
}
/*!
Sets the button's next state to \c aState.
Sets the button's state to the next available state.
@param aState Possible states are any of the CPButton globals:
\c CPOffState, \c CPOnState, \c CPMixedState
*/
@@ -448,38 +448,47 @@ CPButtonImageOffset = 3.0;
{
switch (aButtonType)
{
case CPMomentaryLightButton: [self setHighlightsBy:CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPNoCellMask];
break;
case CPMomentaryLightButton:
[self setHighlightsBy:CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPNoCellMask];
break;
case CPMomentaryPushInButton: [self setHighlightsBy:CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPNoCellMask];
break;
case CPMomentaryPushInButton:
[self setHighlightsBy:CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPNoCellMask];
break;
case CPMomentaryChangeButton: [self setHighlightsBy:CPContentsCellMask];
[self setShowsStateBy:CPNoCellMask];
break;
case CPMomentaryChangeButton:
[self setHighlightsBy:CPContentsCellMask];
[self setShowsStateBy:CPNoCellMask];
break;
case CPPushOnPushOffButton: [self setHighlightsBy:CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPChangeBackgroundCellMask | CPChangeGrayCellMask];
break;
case CPPushOnPushOffButton:
[self setHighlightsBy:CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPChangeBackgroundCellMask | CPChangeGrayCellMask];
break;
case CPOnOffButton: [self setHighlightsBy:CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPChangeGrayCellMask | CPChangeBackgroundCellMask];
break;
case CPOnOffButton:
[self setHighlightsBy:CPChangeGrayCellMask | CPChangeBackgroundCellMask];
[self setShowsStateBy:CPChangeGrayCellMask | CPChangeBackgroundCellMask];
break;
case CPToggleButton: [self setHighlightsBy:CPPushInCellMask | CPContentsCellMask];
[self setShowsStateBy:CPContentsCellMask];
break;
case CPToggleButton:
[self setHighlightsBy:CPPushInCellMask | CPContentsCellMask];
[self setShowsStateBy:CPContentsCellMask];
break;
case CPSwitchButton: [CPException raise:CPInvalidArgumentException
reason:"The CPSwitchButton type is not supported in Cappuccino, use the CPCheckBox class instead."];
case CPSwitchButton:
[CPException raise:CPInvalidArgumentException
reason:"The CPSwitchButton type is not supported in Cappuccino, use the CPCheckBox class instead."];
case CPRadioButton: [CPException raise:CPInvalidArgumentException
reason:"The CPRadioButton type is not supported in Cappuccino, use the CPRadio class instead."];
case CPRadioButton:
[CPException raise:CPInvalidArgumentException
reason:"The CPRadioButton type is not supported in Cappuccino, use the CPRadio class instead."];
default: [CPException raise:CPInvalidArgumentException
reason:"Unknown button type."];
default:
[CPException raise:CPInvalidArgumentException
reason:"Unknown button type."];
}
[self setImageDimsWhenDisabled:YES];
+1 -1
View File
@@ -79,7 +79,7 @@
return @"button-bar";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"resize-control-inset": CGInsetMake(0.0, 0.0, 0.0, 0.0),
+284 -76
View File
@@ -32,6 +32,35 @@
@import "CPPasteboard.j"
@import "CPView.j"
var CPCollectionViewDelegate_collectionView_acceptDrop_index_dropOperation_ = 1 << 0,
CPCollectionViewDelegate_collectionView_canDragItemsAtIndexes_withEvent_ = 1 << 1,
CPCollectionViewDelegate_collectionView_writeItemsAtIndexes_toPasteboard_ = 1 << 2,
CPCollectionViewDelegate_collectionView_dragTypesForItemsAtIndexes_ = 1 << 3,
CPCollectionViewDelegate_collectionView_dataForItemsAtIndexes_forType_ = 1 << 4,
CPCollectionViewDelegate_collectionView_validateDrop_proposedIndex_dropOperation_ = 1 << 5,
CPCollectionViewDelegate_collectionView_didDoubleClickOnItemAtIndex_ = 1 << 6,
CPCollectionViewDelegate_collectionViewDidChangeSelection_ = 1 << 7,
CPCollectionViewDelegate_collectionView_menuForItemAtIndex_ = 1 << 8,
CPCollectionViewDelegate_collectionView_draggingViewForItemsAtIndexes_withEvent_offset = 1 << 9;
@protocol CPCollectionViewDelegate <CPObject>
@optional
- (BOOL)collectionView:(CPCollectionView)collectionView acceptDrop:(id)draggingInfo index:(CPInteger)index dropOperation:(CPCollectionViewDropOperation)dropOperation;
- (BOOL)collectionView:(CPCollectionView)collectionView canDragItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)event;
- (BOOL)collectionView:(CPCollectionView)collectionView writeItemsAtIndexes:(CPIndexSet)indexes toPasteboard:(CPPasteboard)pasteboard;
- (CPArray)collectionView:(CPCollectionView)collectionView dragTypesForItemsAtIndexes:(CPIndexSet)indexes;
- (CPData)collectionView:(CPCollectionView)collectionView dataForItemsAtIndexes:(CPIndexSet)indices forType:(CPString)aType;
- (CPDragOperation)collectionView:(CPCollectionView)collectionView validateDrop:(id)draggingInfo proposedIndex:(CPInteger)proposedDropIndex dropOperation:(CPCollectionViewDropOperation)proposedDropOperation;
- (CPMenu)collectionView:(CPCollectionView)collectionView menuForItemAtIndex:(CPInteger)anIndex;
- (CPView)collectionView:(CPCollectionView)collectionView dragginViewForItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)event offset:(CGPoint)dragImageOffset;
- (void)collectionView:(CPCollectionView)collectionView didDoubleClickOnItemAtIndex:(int)index;
- (void)collectionViewDidChangeSelection:(CPCollectionView)collectionView;
@end
/*!
@ingroup appkit
@class CPCollectionView
@@ -69,51 +98,52 @@ var HORIZONTAL_MARGIN = 2;
@implementation CPCollectionView : CPView
{
CPArray _content;
CPArray _items;
CPArray _content;
CPArray _items;
CPData _itemData;
CPCollectionViewItem _itemPrototype;
CPCollectionViewItem _itemForDragging;
CPMutableArray _cachedItems;
CPData _itemData;
CPCollectionViewItem _itemPrototype;
CPCollectionViewItem _itemForDragging;
CPMutableArray _cachedItems;
unsigned _maxNumberOfRows;
unsigned _maxNumberOfColumns;
unsigned _maxNumberOfRows;
unsigned _maxNumberOfColumns;
CGSize _minItemSize;
CGSize _maxItemSize;
CGSize _minItemSize;
CGSize _maxItemSize;
CPArray _backgroundColors;
CPArray _backgroundColors;
float _tileWidth;
float _tileWidth;
BOOL _isSelectable;
BOOL _allowsMultipleSelection;
BOOL _allowsEmptySelection;
CPIndexSet _selectionIndexes;
BOOL _isSelectable;
BOOL _allowsMultipleSelection;
BOOL _allowsEmptySelection;
CPIndexSet _selectionIndexes;
CGSize _itemSize;
CGSize _itemSize;
float _horizontalMargin;
float _verticalMargin;
float _horizontalMargin;
float _verticalMargin;
unsigned _numberOfRows;
unsigned _numberOfColumns;
unsigned _numberOfRows;
unsigned _numberOfColumns;
id _delegate;
id <CPCollectionViewDelegate> _delegate;
unsigned _implementedDelegateMethods;
CPEvent _mouseDownEvent;
CPEvent _mouseDownEvent;
BOOL _needsMinMaxItemSizeUpdate;
CGSize _storedFrameSize;
BOOL _needsMinMaxItemSizeUpdate;
CGSize _storedFrameSize;
BOOL _uniformSubviewsResizing @accessors(property=uniformSubviewsResizing);
BOOL _lockResizing;
BOOL _uniformSubviewsResizing @accessors(property=uniformSubviewsResizing);
BOOL _lockResizing;
CPInteger _currentDropIndex;
CPDragOperation _currentDragOperation;
CPInteger _currentDropIndex;
CPDragOperation _currentDragOperation;
_CPCollectionViewDropIndicator _dropView;
_CPCollectionViewDropIndicator _dropView;
}
- (id)initWithFrame:(CGRect)aFrame
@@ -168,6 +198,54 @@ var HORIZONTAL_MARGIN = 2;
[self setAutoresizingMask:0];
}
#pragma mark -
#pragma mark Delegate
/*!
Set the delegate of the receiver
@param aDelegate the delegate object for the collectionView.
*/
- (void)setDelegate:(id <CPCollectionViewDelegate>)aDelegate
{
if (_delegate === aDelegate)
return;
_delegate = aDelegate;
_implementedDelegateMethods = 0;
if ([_delegate respondsToSelector:@selector(collectionView:acceptDrop:index:dropOperation:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_acceptDrop_index_dropOperation_;
if ([_delegate respondsToSelector:@selector(collectionView:canDragItemsAtIndexes:withEvent:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_canDragItemsAtIndexes_withEvent_;
if ([_delegate respondsToSelector:@selector(collectionView:writeItemsAtIndexes:toPasteboard:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_writeItemsAtIndexes_toPasteboard_;
if ([_delegate respondsToSelector:@selector(collectionView:dragTypesForItemsAtIndexes:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_dragTypesForItemsAtIndexes_;
if ([_delegate respondsToSelector:@selector(collectionView:dataForItemsAtIndexes:forType:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_dataForItemsAtIndexes_forType_;
if ([_delegate respondsToSelector:@selector(collectionView:validateDrop:proposedIndex:dropOperation:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_validateDrop_proposedIndex_dropOperation_;
if ([_delegate respondsToSelector:@selector(collectionView:didDoubleClickOnItemAtIndex:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_didDoubleClickOnItemAtIndex_;
if ([_delegate respondsToSelector:@selector(collectionViewDidChangeSelection:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionViewDidChangeSelection_;
if ([_delegate respondsToSelector:@selector(collectionView:menuForItemAtIndex:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_menuForItemAtIndex_;
if ([_delegate respondsToSelector:@selector(collectionView:draggingViewForItemsAtIndexes:withEvent:offset:)])
_implementedDelegateMethods |= CPCollectionViewDelegate_collectionView_draggingViewForItemsAtIndexes_withEvent_offset;
}
/*!
Sets the item prototype to \c anItem
@param anItem the new item prototype.
@@ -455,12 +533,12 @@ var HORIZONTAL_MARGIN = 2;
[self tileIfNeeded:NO];
}
- (void)resizeSubviewsWithOldSize:(CPSize)oldBoundsSize
- (void)resizeSubviewsWithOldSize:(CGSize)oldBoundsSize
{
// Desactivate subviews autoresizing
}
- (void)resizeWithOldSuperviewSize:(CPSize)oldBoundsSize
- (void)resizeWithOldSuperviewSize:(CGSize)oldBoundsSize
{
if (_lockResizing)
return;
@@ -755,8 +833,8 @@ var HORIZONTAL_MARGIN = 2;
- (void)mouseUp:(CPEvent)anEvent
{
if ([_selectionIndexes count] && [anEvent clickCount] == 2 && [_delegate respondsToSelector:@selector(collectionView:didDoubleClickOnItemAtIndex:)])
[_delegate collectionView:self didDoubleClickOnItemAtIndex:[_selectionIndexes firstIndex]];
if ([_selectionIndexes count] && [anEvent clickCount] == 2)
[self _sendDelegateDidDoubleClickOnItemAtIndex:[_selectionIndexes firstIndex]];
}
- (void)mouseDown:(CPEvent)anEvent
@@ -784,6 +862,10 @@ var HORIZONTAL_MARGIN = 2;
var firstSelectedIndex = [[self selectionIndexes] firstIndex],
newSelectedRange = nil;
// This catches the case where the shift key is held down for the first selection.
if (firstSelectedIndex === CPNotFound)
firstSelectedIndex = index;
if (index < firstSelectedIndex)
newSelectedRange = CPMakeRange(index, (firstSelectedIndex - index) + 1);
else
@@ -826,7 +908,7 @@ var HORIZONTAL_MARGIN = 2;
[self tile];
}
- (void)setUniformSubviewsResizing:(float)flag
- (void)setUniformSubviewsResizing:(BOOL)flag
{
_uniformSubviewsResizing = flag;
[self tileIfNeeded:NO];
@@ -842,15 +924,6 @@ var HORIZONTAL_MARGIN = 2;
return _verticalMargin;
}
/*!
Sets the collection view's delegate
@param aDelegate the new delegate
*/
- (void)setDelegate:(id)aDelegate
{
_delegate = aDelegate;
}
/*!
Returns the collection view's delegate
*/
@@ -864,13 +937,13 @@ var HORIZONTAL_MARGIN = 2;
*/
- (CPMenu)menuForEvent:(CPEvent)theEvent
{
if (![[self delegate] respondsToSelector:@selector(collectionView:menuForItemAtIndex:)])
if (![self _delegateRespondsToCollectionViewMenuForItemAtIndex])
return [super menuForEvent:theEvent];
var location = [self convertPoint:[theEvent locationInWindow] fromView:nil],
index = [self _indexAtPoint:location];
return [_delegate collectionView:self menuForItemAtIndex:index];
return [self _sendDelegateMenuForItemAtIndex:index];
}
- (int)_indexAtPoint:(CGPoint)thePoint
@@ -888,12 +961,12 @@ var HORIZONTAL_MARGIN = 2;
return CPNotFound;
}
- (CPCollectionViewItem)itemAtIndex:(unsigned)anIndex
- (CPCollectionViewItem)itemAtIndex:(CPUInteger)anIndex
{
return [_items objectAtIndex:anIndex];
}
- (CGRect)frameForItemAtIndex:(unsigned)anIndex
- (CGRect)frameForItemAtIndex:(CPUInteger)anIndex
{
return [[[self itemAtIndex:anIndex] view] frame];
}
@@ -928,7 +1001,7 @@ var HORIZONTAL_MARGIN = 2;
*/
- (void)pasteboard:(CPPasteboard)aPasteboard provideDataForType:(CPString)aType
{
[aPasteboard setData:[_delegate collectionView:self dataForItemsAtIndexes:_selectionIndexes forType:aType] forType:aType];
[aPasteboard setData:[self _sendDelegateDataForItemsAtIndexes:_selectionIndexes forType:aType] forType:aType];
}
- (void)_createDropIndicatorIfNeeded
@@ -958,24 +1031,23 @@ var HORIZONTAL_MARGIN = 2;
(ABS(locationInWindow.y - mouseDownLocationInWindow.y) < 3))
return;
if (![_delegate respondsToSelector:@selector(collectionView:dragTypesForItemsAtIndexes:)])
if (![self _delegateRespondsToCollectionViewDragTypesForItemsAtIndexes])
return;
// If we don't have any selected items, we've clicked away, and thus the drag is meaningless.
if (![_selectionIndexes count])
return;
if ([_delegate respondsToSelector:@selector(collectionView:canDragItemsAtIndexes:withEvent:)] &&
![_delegate collectionView:self canDragItemsAtIndexes:_selectionIndexes withEvent:_mouseDownEvent])
if (![self _sendDelegateCanDragItemsAtIndexes:_selectionIndexes withEvent:_mouseDownEvent])
return;
// Set up the pasteboard
var dragTypes = [_delegate collectionView:self dragTypesForItemsAtIndexes:_selectionIndexes];
var dragTypes = [self _sendDelegateDragTypesForItemsAtIndexes:_selectionIndexes];
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:dragTypes owner:self];
var dragImageOffset = CGSizeMakeZero(),
view = [self _draggingViewForItemsAtIndexes:_selectionIndexes withEvent:_mouseDownEvent offset:dragImageOffset];
view = [self _sendDelegateDraggingViewForItemsAtIndexes:_selectionIndexes withEvent:_mouseDownEvent offset:dragImageOffset];
[view setFrameSize:_itemSize];
[view setAlphaValue:0.7];
@@ -992,14 +1064,6 @@ var HORIZONTAL_MARGIN = 2;
slideBack:YES];
}
- (CPView)_draggingViewForItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)anEvent offset:(CGPoint)offset
{
if ([_delegate respondsToSelector:@selector(collectionView:draggingViewForItemsAtIndexes:withEvent:offset:)])
return [_delegate collectionView:self draggingViewForItemsAtIndexes:indexes withEvent:anEvent offset:offset];
return [self draggingViewForItemsAtIndexes:indexes withEvent:anEvent offset:offset];
}
- (CPView)draggingViewForItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)event offset:(CGPoint)dragImageOffset
{
var idx = _content[[indexes firstIndex]];
@@ -1012,14 +1076,6 @@ var HORIZONTAL_MARGIN = 2;
return [_itemForDragging view];
}
- (BOOL)_canDragItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)anEvent
{
if ([self respondsToSelector:@selector(collectionView:canDragItemsAtIndexes:withEvent:)])
return [_delegate collectionView:self canDragItemsAtIndexes:indexes withEvent:anEvent];
return YES;
}
- (CPDragOperation)draggingEntered:(id)draggingInfo
{
var dropIndex = -1,
@@ -1057,16 +1113,14 @@ var HORIZONTAL_MARGIN = 2;
var result = CPDragOperationMove,
dropIndex = [self _dropIndexForDraggingInfo:draggingInfo proposedDropOperation:dropOperation];
if ([_delegate respondsToSelector:@selector(collectionView:validateDrop:proposedIndex:dropOperation:)])
if ([self _delegateRespondsToCollectionViewValidateDropProposedIndexDropOperation])
{
var dropIndexRef2 = @ref(dropIndex);
result = [_delegate collectionView:self validateDrop:draggingInfo proposedIndex:dropIndexRef2 dropOperation:dropOperation];
result = [self _sendDelegateValidateDrop:draggingInfo proposedIndex:dropIndexRef2 dropOperation:dropOperation];
if (result !== CPDragOperationNone)
{
dropIndex = dropIndexRef2();
}
}
dropIndexRef(dropIndex);
@@ -1100,7 +1154,7 @@ Not supported. Use -collectionView:dataForItemsAtIndexes:fortype:
var result = NO;
if (_currentDragOperation && _currentDropIndex !== -1)
result = [_delegate collectionView:self acceptDrop:draggingInfo index:_currentDropIndex dropOperation:1];
result = [self _sendDelegateAcceptDrop:draggingInfo index:_currentDropIndex dropOperation:1];
[self draggingEnded:draggingInfo]; // Is this correct ?
@@ -1318,13 +1372,14 @@ Not supported. Use -collectionView:dataForItemsAtIndexes:fortype:
[self interpretKeyEvents:[anEvent]];
}
- (void)setAutoresizingMask:(int)aMask
- (void)setAutoresizingMask:(unsigned)aMask
{
[super setAutoresizingMask:0];
}
@end
@implementation CPCollectionView (Deprecated)
- (CGRect)rectForItemAtIndex:(int)anIndex
@@ -1345,6 +1400,159 @@ Not supported. Use -collectionView:dataForItemsAtIndexes:fortype:
@end
@implementation CPCollectionView (CPCollectionViewDelegate)
/*
@ignore
Return YES if the delegate implements collectionView:validateDrop:proposedIndex:dropOperation:
*/
- (BOOL)_delegateRespondsToCollectionViewValidateDropProposedIndexDropOperation
{
return _implementedDelegateMethods & CPCollectionViewDelegate_collectionView_validateDrop_proposedIndex_dropOperation_;
}
/*
@ignore
Return YES if the delegate implements collectionView:menuForItemAtIndex:
*/
- (BOOL)_delegateRespondsToCollectionViewMenuForItemAtIndex
{
return _implementedDelegateMethods & CPCollectionViewDelegate_collectionView_menuForItemAtIndex_;
}
/*
@ignore
Return YES if the delegate implements collectionView:dragTypesForItemsAtIndexes:
*/
- (BOOL)_delegateRespondsToCollectionViewDragTypesForItemsAtIndexes
{
return _implementedDelegateMethods & CPCollectionViewDelegate_collectionView_dragTypesForItemsAtIndexes_;
}
/*!
@ignore
Call delegate collectionView:acceptDrop:index:dropOperation:
*/
- (BOOL)_sendDelegateAcceptDrop:(id)draggingInfo index:(CPInteger)index dropOperation:(CPCollectionViewDropOperation)dropOperation
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_acceptDrop_index_dropOperation_))
return NO;
return [_delegate collectionView:self acceptDrop:draggingInfo index:index dropOperation:dropOperation];
}
/*!
@ignore
Call delegate collectionView:canDragItemsAtIndexes:withEvent:
*/
- (BOOL)_sendDelegateCanDragItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)anEvent
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_canDragItemsAtIndexes_withEvent_))
return YES;
return [_delegate collectionView:self canDragItemsAtIndexes:indexes withEvent:anEvent];
}
/*!
@ignore
Call delegate collectionView:writeItemsAtIndexes:toPasteboard:
*/
- (BOOL)_sendDelegateWriteItemsAtIndexes:(CPIndexSet)indexes toPasteboard:(CPPasteboard)pasteboard
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_writeItemsAtIndexes_toPasteboard_))
return NO;
return [_delegate collectionView:self writeItemsAtIndexes:indexes toPasteboard:pasteboard];
}
/*!
@ignore
Call delegate collectionView:dragTypesForItemsAtIndexes:
*/
- (CPArray)_sendDelegateDragTypesForItemsAtIndexes:(CPIndexSet)indexes
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_dragTypesForItemsAtIndexes_))
return [];
return [_delegate collectionView:self dragTypesForItemsAtIndexes:indexes];
}
/*!
@ignore
Call delegate collectionView:dataForItemsAtIndexes:forType:
*/
- (CPData)_sendDelegateDataForItemsAtIndexes:(CPIndexSet)indexes forType:(CPString)aType
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_dataForItemsAtIndexes_forType_))
return nil;
return [_delegate collectionView:self dataForItemsAtIndexes:indexes forType:aType];
}
/*!
@ignore
Call delegate collectionView:validateDrop:proposedIndex:dropOperation:
*/
- (CPDragOperation)_sendDelegateValidateDrop:(id)draggingInfo proposedIndex:(CPInteger)proposedDropIndex dropOperation:(CPCollectionViewDropOperation)proposedDropOperation
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_validateDrop_proposedIndex_dropOperation_))
return CPDragOperationNone;
return [_delegate collectionView:self validateDrop:draggingInfo proposedIndex:proposedDropIndex dropOperation:proposedDropOperation];
}
/*!
@ignore
Call delegate collectionView:didDoubleClickOnItemAtIndex:
*/
- (void)_sendDelegateDidDoubleClickOnItemAtIndex:(int)index
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_didDoubleClickOnItemAtIndex_))
return;
return [_delegate collectionView:self didDoubleClickOnItemAtIndex:index];
}
/*!
@ignore
Call delegate collectionViewDidChangeSelection
*/
- (void)_sendDelegateCollectionViewDidChangeSelection:(CPCollectionView)collectionView
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionViewDidChangeSelection_))
return;
return [_delegate collectionViewDidChangeSelection:self];
}
/*!
@ignore
Call delegate collectionView:menuForItemAtIndex:
*/
- (void)_sendDelegateMenuForItemAtIndex:(CPInteger)anIndex
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_menuForItemAtIndex_))
return nil;
return [_delegate collectionView:self menuForItemAtIndex:anIndex];
}
/*!
@ignore
Call delegate draggingViewForItemsAtIndexes:withEvent:offset:
*/
- (CPView)_sendDelegateDraggingViewForItemsAtIndexes:(CPIndexSet)indexes withEvent:(CPEvent)anEvent offset:(CGPoint)dragImageOffset
{
if (!(_implementedDelegateMethods & CPCollectionViewDelegate_collectionView_draggingViewForItemsAtIndexes_withEvent_offset))
return [self draggingViewForItemsAtIndexes:indexes withEvent:anEvent offset:dragImageOffset];
return [_delegate collectionView:self draggingViewForItemsAtIndexes:indexes withEvent:anEvent offset:dragImageOffset];
}
@end
var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey",
CPCollectionViewMaxItemSizeKey = @"CPCollectionViewMaxItemSizeKey",
CPCollectionViewVerticalMarginKey = @"CPCollectionViewVerticalMarginKey",
+87 -20
View File
@@ -156,11 +156,15 @@ var cachedBlackColor,
}
/*!
Creates a new color in HSB space.
Creates a new color based on the given HSB components.
@param hue the hue value
@param saturation the saturation value
@param brightness the brightness value
Note: earlier versions of this method took a hue component as degrees between 0-360,
and saturation and brightness components as percent between 0-100. This method has
now been corrected to take all components in the 0-1 range as in Cocoa.
@param hue the hue component (0.0-1.0)
@param saturation the saturation component (0.0-1.0)
@param brightness the brightness component (0.0-1.0)
@return the initialized color
*/
@@ -169,25 +173,61 @@ var cachedBlackColor,
return [self colorWithHue:hue saturation:saturation brightness:brightness alpha:1.0];
}
/*!
Calibrated colors are not supported in Cappuccino.
This method has the same result as [CPColor colorWithHue:saturation:brightness:alpha:].
*/
+ (CPColor)colorWithCalibratedHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha
{
return [self colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha];
}
/*!
Creates a new color based on the given HSB components.
Note: earlier versions of this method took a hue component as degrees between 0-360,
and saturation and brightness components as percent between 0-100. This method has
now been corrected to take all components in the 0-1 range as in Cocoa.
@param hue the hue component (0.0-1.0)
@param saturation the saturation component (0.0-1.0)
@param brightness the brightness component (0.0-1.0)
@param alpha the opacity component (0.0-1.0)
@return the initialized color
*/
+ (CPColor)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha
{
// Clamp values.
hue = MAX(MIN(hue, 1.0), 0.0);
saturation = MAX(MIN(saturation, 1.0), 0.0);
brightness = MAX(MIN(brightness, 1.0), 0.0);
if (saturation === 0.0)
return [CPColor colorWithCalibratedWhite:brightness / 100.0 alpha:alpha];
return [CPColor colorWithCalibratedWhite:brightness alpha:alpha];
var f = hue % 60,
p = (brightness * (100 - saturation)) / 10000,
q = (brightness * (6000 - saturation * f)) / 600000,
t = (brightness * (6000 - saturation * (60 -f))) / 600000,
b = brightness / 100.0;
var f = (hue * 360) % 60,
p = (brightness * (1 - saturation)),
q = (brightness * (60 - saturation * f)) / 60,
t = (brightness * (60 - saturation * (60 - f))) / 60,
b = brightness;
switch (FLOOR(hue / 60))
switch (FLOOR(hue * 6))
{
case 0: return [CPColor colorWithCalibratedRed:b green:t blue:p alpha:alpha];
case 1: return [CPColor colorWithCalibratedRed:q green:b blue:p alpha:alpha];
case 2: return [CPColor colorWithCalibratedRed:p green:b blue:t alpha:alpha];
case 3: return [CPColor colorWithCalibratedRed:p green:q blue:b alpha:alpha];
case 4: return [CPColor colorWithCalibratedRed:t green:p blue:b alpha:alpha];
case 5: return [CPColor colorWithCalibratedRed:b green:p blue:q alpha:alpha];
case 0:
case 6:
return [CPColor colorWithCalibratedRed:b green:t blue:p alpha:alpha];
case 1:
return [CPColor colorWithCalibratedRed:q green:b blue:p alpha:alpha];
case 2:
return [CPColor colorWithCalibratedRed:p green:b blue:t alpha:alpha];
case 3:
return [CPColor colorWithCalibratedRed:p green:q blue:b alpha:alpha];
case 4:
return [CPColor colorWithCalibratedRed:t green:p blue:b alpha:alpha];
case 5:
return [CPColor colorWithCalibratedRed:b green:p blue:q alpha:alpha];
}
}
@@ -575,6 +615,9 @@ var cachedBlackColor,
/*!
Returns an array with the HSB values for this color.
The values are expressed as fractions between 0.0-1.0.
The index values are ordered as:
<pre>
<b>Index</b> <b>Component</b>
@@ -621,12 +664,36 @@ var cachedBlackColor,
}
return [
ROUND(hue * 360.0),
ROUND(saturation * 100.0),
ROUND(brightness * 100.0)
hue,
saturation,
brightness
];
}
/*!
Returns the hue component, the H in HSB, of the receiver.
*/
- (float)hueComponent
{
return [self hsbComponents][0];
}
/*!
Returns the saturation component, the S in HSB, of the receiver.
*/
- (float)saturationComponent
{
return [self hsbComponents][1];
}
/*!
Returns the brightness component, the B in HSB, of the receiver.
*/
- (float)brightnessComponent
{
return [self hsbComponents][2];
}
/*!
Returns the CSS representation of this color. The color will
be in one of the following forms:
+2 -2
View File
@@ -576,7 +576,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[aPasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_dragColor] forType:aType];
}
- (void)performDragOperation:(id <CPDraggingInfo>)aSender
- (void)performDragOperation:(id /*<CPDraggingInfo>*/)aSender
{
var location = [self convertPoint:[aSender draggingLocation] fromView:nil],
pasteboard = [aSender draggingPasteboard],
@@ -615,7 +615,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
return _colorPanel;
}
- (void)performDragOperation:(id <CPDraggingInfo>)aSender
- (void)performDragOperation:(id /*<CPDraggingInfo>*/)aSender
{
var pasteboard = [aSender draggingPasteboard];
+7 -7
View File
@@ -158,12 +158,12 @@
brightness = [_brightnessSlider floatValue];
[_hueSaturationView setWheelBrightness:brightness / 100.0];
[_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hue saturation:saturation brightness:100]];
[_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hue / 360.0 saturation:saturation / 100.0 brightness:1]];
var colorPanel = [self colorPanel],
opacity = [colorPanel opacity];
_cachedColor = [CPColor colorWithHue:hue saturation:saturation brightness:brightness alpha:opacity];
_cachedColor = [CPColor colorWithHue:hue / 360.0 saturation:saturation / 100.0 brightness:brightness / 100.0 alpha:opacity];
[[self colorPanel] setColor:_cachedColor];
}
@@ -194,10 +194,10 @@
var hsb = [newColor hsbComponents];
[_hueSaturationView setPositionToColor:newColor];
[_brightnessSlider setFloatValue:hsb[2]];
[_hueSaturationView setWheelBrightness:hsb[2] / 100.0];
[_brightnessSlider setFloatValue:hsb[2] * 100.0];
[_hueSaturationView setWheelBrightness:hsb[2]];
[_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hsb[0] saturation:hsb[1] brightness:100]];
[_brightnessSlider setBackgroundColor:[CPColor colorWithHue:hsb[0] saturation:hsb[1] brightness:1]];
}
- (CPImage)provideNewButtonImage
@@ -366,8 +366,8 @@
{
var hsb = [aColor hsbComponents],
bounds = [self bounds],
angle = [self degreesToRadians:hsb[0]],
distance = (hsb[1] / 100.0) * _radius;
angle = [self degreesToRadians:hsb[0] * 360.0],
distance = hsb[1] * _radius;
[self setAngle:angle distance:distance];
}
+1 -1
View File
@@ -58,7 +58,7 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
return @"colorwell";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"bezel-inset": CGInsetMakeZero(),
+5 -5
View File
@@ -58,7 +58,7 @@ var CPComboBoxTextSubview = @"text",
return "combobox";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"popup-button-size": CGSizeMake(21.0, 29.0),
@@ -171,7 +171,7 @@ var CPComboBoxTextSubview = @"text",
#pragma mark Setting a Delegate
- (id < CPComboBoxDelegate >)delegate
- (id /*< CPComboBoxDelegate >*/)delegate
{
return [super delegate];
}
@@ -182,7 +182,7 @@ var CPComboBoxTextSubview = @"text",
protocol, in actual fact it doesn't. Also note that the same
delegate may conform to the NSTextFieldDelegate protocol.
*/
- (void)setDelegate:(id < CPComboBoxDelegate >)aDelegate
- (void)setDelegate:(id /*< CPComboBoxDelegate >*/)aDelegate
{
var delegate = [self delegate];
@@ -231,7 +231,7 @@ var CPComboBoxTextSubview = @"text",
#pragma mark Setting a Data Source
- (id < CPComboBoxDataSource >)dataSource
- (id /*< CPComboBoxDataSource >*/)dataSource
{
if (!_usesDataSource)
[self _dataSourceWarningForMethod:_cmd condition:NO];
@@ -239,7 +239,7 @@ var CPComboBoxTextSubview = @"text",
return _dataSource;
}
- (void)setDataSource:(id < CPComboBoxDataSource >)aSource
- (void)setDataSource:(id /*< CPComboBoxDataSource >*/)aSource
{
if (!_usesDataSource)
[self _dataSourceWarningForMethod:_cmd condition:NO];
+46 -4
View File
@@ -46,7 +46,9 @@ CPHTMLDragAndDropFeature = 8;
CPJavaScriptInnerTextFeature = 9;
CPJavaScriptTextContentFeature = 10;
// In onpaste, oncopy and oncut events, the event has an event.clipboardData from which the current pasteboard contents can be read with event.clipboardData.getData.
CPJavaScriptClipboardEventsFeature = 11;
// window.clipboardData exists and can be read and written to at any time using window.clipboardData.getData/setData.
CPJavaScriptClipboardAccessFeature = 12;
CPJavaScriptCanvasDrawFeature = 13;
CPJavaScriptCanvasTransformFeature = 14;
@@ -76,11 +78,19 @@ CPInputOnInputEventFeature = 30;
CPFileAPIFeature = 31;
/*
When an absolutely positioned div (CPView) with an absolutely positioned canvas in it (CPView with drawRect:) moves things on top of the canvas (subviews) don't redraw correctly. E.g. if you have a bunch of text fields in a CPBox in a sheet which animates in, some of the text fields might not be visible because the CPBox has a canvas at the bottom and the box moved form offscreen to onscreen. This bug is probably very related: https://bugs.webkit.org/show_bug.cgi?id=67203
*/
CPCanvasParentDrawErrorsOnMovementBug = 1 << 0;
// The paste event is only sent if an input or textarea has focus.
CPJavaScriptPasteRequiresEditableTarget = 1 << 1;
// Redirecting the focus of the browser on keydown to an input for Cmd-V or Ctrl-V makes the paste fail.
CPJavaScriptPasteCantRefocus = 1 << 2;
var USER_AGENT = "",
PLATFORM_ENGINE = CPUnknownBrowserEngine,
PLATFORM_FEATURES = [],
@@ -118,6 +128,9 @@ else if (typeof window !== "undefined" && window.attachEvent) // Must follow Ope
// Tested in Internet Explore 8 and 9.
PLATFORM_FEATURES[CPInputSetFontOutsideOfDOM] = NO;
// IE allows free clipboard access.
PLATFORM_FEATURES[CPJavaScriptClipboardAccessFeature] = YES;
}
// WebKit
@@ -129,11 +142,8 @@ else if (USER_AGENT.indexOf("AppleWebKit/") != -1)
PLATFORM_FEATURES[CPCSSRGBAFeature] = YES;
PLATFORM_FEATURES[CPHTMLContentEditableFeature] = YES;
if (USER_AGENT.indexOf("Chrome") === -1)
PLATFORM_FEATURES[CPHTMLDragAndDropFeature] = YES;
PLATFORM_FEATURES[CPJavaScriptClipboardEventsFeature] = YES;
PLATFORM_FEATURES[CPJavaScriptClipboardAccessFeature] = YES;
PLATFORM_FEATURES[CPJavaScriptClipboardAccessFeature] = NO;
PLATFORM_FEATURES[CPJavaScriptShadowFeature] = YES;
var versionStart = USER_AGENT.indexOf("AppleWebKit/") + "AppleWebKit/".length,
@@ -159,7 +169,14 @@ else if (USER_AGENT.indexOf("AppleWebKit/") != -1)
PLATFORM_FEATURES[CPInput1PxLeftPadding] = YES;
if (USER_AGENT.indexOf("Chrome") === CPNotFound)
{
PLATFORM_FEATURES[CPSOPDisabledFromFileURLs] = YES;
PLATFORM_FEATURES[CPHTMLDragAndDropFeature] = YES;
// https://bugs.webkit.org/show_bug.cgi?id=75891
PLATFORM_BUGS |= CPJavaScriptPasteRequiresEditableTarget;
// https://bugs.webkit.org/show_bug.cgi?id=39689
PLATFORM_BUGS |= CPJavaScriptPasteCantRefocus;
}
// Assume this bug was introduced around Safari 5.1/Chrome 16. This could probably be tighter.
if (majorVersion > 533)
@@ -190,6 +207,17 @@ else if (USER_AGENT.indexOf("Gecko") !== -1) // Must follow KHTML check.
// Some day this might be fixed and should be version prefixed. No known fixed version yet.
PLATFORM_FEATURES[CPInput1PxLeftPadding] = YES;
// This was supposed to be added in Firefox 22, but when testing with the latest beta as of 2013-06-14
// it does not seem to work. It seems to exhibit the CPJavaScriptPasteRequiresEditableTarget problem,
// and in addition doesn't seem to work with our native copy code either.
/*if (version >= 22.0)
{
PLATFORM_FEATURES[CPJavaScriptClipboardEventsFeature] = YES;
// TODO File a bug at https://bugzilla.mozilla.org/. In other browsers, one can return "false" from the
// beforepaste event to indicate a paste should be enabled even that the DOMEvent.target is not editable.
PLATFORM_BUGS |= CPJavaScriptPasteRequiresEditableTarget;
}*/
}
// Feature-specific checks
@@ -324,6 +352,19 @@ function CPBrowserStyleProperty(aProperty)
r = candidates[PLATFORM_STYLE_JS_PROPERTIES['transition']] || nil;
break;
case 'transformorigin':
var candidates = {
'WebkitTransform' : 'WebkitTransformOrigin',
'MozTransform' : 'MozTransformOrigin',
'OTransform' : 'OTransformOrigin',
'msTransform' : 'MSTransformOrigin',
'transform' : 'transformOrigin'
};
r = candidates[PLATFORM_STYLE_JS_PROPERTIES['transform']] || nil;
break;
case 'animationend':
var candidates = {
'WebkitAnimation' : 'webkitAnimationEnd',
@@ -335,6 +376,7 @@ function CPBrowserStyleProperty(aProperty)
r = candidates[PLATFORM_STYLE_JS_PROPERTIES['animation']] || nil;
break;
default:
var prefixes = ["Webkit", "Moz", "O", "ms"],
strippedProperty = aProperty.split('-').join(' '),
+49 -7
View File
@@ -322,11 +322,11 @@ var CPControlBlackColor = [CPColor blackColor];
_previousTrackingLocation = currentLocation;
}
- (void)setState:(int)state
- (void)setState:(CPInteger)state
{
}
- (int)nextState
- (CPInteger)nextState
{
return 0;
}
@@ -530,7 +530,7 @@ var CPControlBlackColor = [CPColor blackColor];
return formattedValue;
}
return (_value === undefined || _value === nil) ? "" : String(_value);
return (_value === undefined || _value === nil) ? @"" : String(_value);
}
/*!
@@ -607,7 +607,7 @@ var CPControlBlackColor = [CPColor blackColor];
if ([note object] != self)
return;
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidBeginEditingNotification object:self userInfo:@{ "CPFieldEditor": [note object] }];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidBeginEditingNotification object:self userInfo:@{"CPFieldEditor": [note object]}];
}
- (void)textDidChange:(CPNotification)note
@@ -616,7 +616,7 @@ var CPControlBlackColor = [CPColor blackColor];
if ([note object] != self)
return;
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidChangeNotification object:self userInfo:@{ "CPFieldEditor": [note object] }];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidChangeNotification object:self userInfo:@{"CPFieldEditor": [note object]}];
}
- (void)textDidEndEditing:(CPNotification)note
@@ -627,7 +627,49 @@ var CPControlBlackColor = [CPColor blackColor];
[self _reverseSetBinding];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidEndEditingNotification object:self userInfo:@{ "CPFieldEditor": [note object] }];
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidEndEditingNotification object:self userInfo:[note userInfo]];
}
/*!
@ignore
Return the currentTextMovement needed by the delegate textDidEndEditing
This is going to check the currentEvent of the CPApp
*/
- (unsigned)_currentTextMovement
{
var currentEvent = [CPApp currentEvent],
keyCode = [currentEvent keyCode],
modifierFlags = [currentEvent modifierFlags];
switch (keyCode)
{
case CPEscapeKeyCode:
return CPCancelTextMovement;
case CPLeftArrowKeyCode:
return CPLeftTextMovement;
case CPRightArrowKeyCode:
return CPRightTextMovement;
case CPUpArrowKeyCode:
return CPUpTextMovement;
case CPDownArrowKeyCode:
return CPDownTextMovement;
case CPReturnKeyCode:
return CPReturnTextMovement;
case CPTabKeyCode:
if (modifierFlags & CPShiftKeyMask)
return CPBacktabTextMovement;
return CPTabTextMovement;
default:
return CPOtherTextMovement;
}
}
/*!
@@ -813,7 +855,7 @@ var CPControlBlackColor = [CPColor blackColor];
/*!
Returns the image scaling of the control.
*/
- (CPImageScaling)imageScaling
- (CPUInteger)imageScaling
{
return [self valueForThemeAttribute:@"image-scaling"];
}
+2 -1
View File
@@ -116,7 +116,8 @@ var currentCursor = nil,
- (void)push
{
currentCursor = cursorStack.push(self);
cursorStack.push(self);
currentCursor = self;
}
- (void)set
+42 -28
View File
@@ -30,6 +30,7 @@
@import <Foundation/CPDate.j>
@import <Foundation/CPDateFormatter.j>
@import <Foundation/CPLocale.j>
@import <Foundation/CPTimeZone.j>
@class CPStepper
@class CPApp
@@ -68,10 +69,9 @@ CPEraDatePickerElementFlag = 0x0100;
CPFont _textFont @accessors(property=textFont);
CPLocale _locale @accessors(property=locale);
//CPCalendar _calendar @accessors(property=calendar);
//CPTimeZone _timeZone @accessors(property=timeZone);
CPDateFormatter _formatter @accessors(property=formatter);
CPTimeZone _timeZone @accessors(property=timeZone);
id _delegate @accessors(property=delegate);
unsigned _datePickerElements @accessors(property=datePickerElements);
CPInteger _datePickerElements @accessors(property=datePickerElements);
CPInteger _datePickerMode @accessors(property=datePickerMode);
CPInteger _datePickerStyle @accessors(property=datePickerStyle);
CPInteger _timeInterval @accessors(property=timeInterval);
@@ -90,7 +90,7 @@ CPEraDatePickerElementFlag = 0x0100;
return @"datePicker";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"bezel-color": [CPColor clearColor],
@@ -135,10 +135,10 @@ CPEraDatePickerElementFlag = 0x0100;
@"clock-text-shadow-color": [CPColor clearColor],
@"clock-text-shadow-offset": CGSizeMakeZero(),
@"clock-font": [CPNull null],
@"second-hand-color": [CPColor clearColor],
@"hour-hand-color": [CPColor clearColor],
@"middle-hand-color": [CPColor clearColor],
@"minute-hand-color": [CPColor clearColor],
@"second-hand-image": [CPNull null],
@"hour-hand-image": [CPNull null],
@"middle-hand-image": [CPNull null],
@"minute-hand-image": [CPNull null],
@"size-clock": CGSizeMakeZero(),
@"second-hand-size": CGSizeMakeZero(),
@"hour-hand-size": CGSizeMakeZero(),
@@ -159,7 +159,7 @@ CPEraDatePickerElementFlag = 0x0100;
return [super _binderClassForBinding:theBinding];
}
- (id)_replacementKeyPathForBinding:(CPString)aBinding
- (CPString)_replacementKeyPathForBinding:(CPString)aBinding
{
if (aBinding == CPValueBinding)
return @"dateValue";
@@ -187,7 +187,6 @@ CPEraDatePickerElementFlag = 0x0100;
_datePickerElements = CPYearMonthDayDatePickerElementFlag | CPHourMinuteSecondDatePickerElementFlag;
_timeInterval = 0;
_implementedCDatePickerDelegateMethods = 0;
_formatter = [[CPDateFormatter alloc] init];
[self setObjectValue:[CPDate date]];
_minDate = [CPDate distantPast];
@@ -265,18 +264,12 @@ CPEraDatePickerElementFlag = 0x0100;
#pragma mark -
#pragma mark Setter
/*! Return the objectValue of the datePicker. The objectValue is made with the current formatter of the datePicker
/*! Return the objectValue of the datePicker. The objectValue should take the timeZoneEffect
*/
- (void)objectValue
- (id)objectValue
{
// try
// {
// return [_formatter stringFromDate:_dateValue];
// }
// catch(e)
// {
return _dateValue
// }
// TODO : add timeZone effect. How to do it because js ???
return _dateValue
}
/*! Set the objectValue ofhe datePier. It has to be a CPDate
@@ -313,7 +306,14 @@ CPEraDatePickerElementFlag = 0x0100;
aTimeInterval = MAX(MIN(aTimeInterval, [_maxDate timeIntervalSinceDate:aDateValue]), [_minDate timeIntervalSinceDate:aDateValue]);
if ([aDateValue isEqualToDate:_dateValue] && aTimeInterval == _timeInterval)
{
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield setDateValue:_dateValue];
else
[_datePickerCalendar setDateValue:_dateValue];
return;
}
if (_implementedCDatePickerDelegateMethods & CPDatePicker_validateProposedDateValue_timeInterval)
{
@@ -328,8 +328,8 @@ CPEraDatePickerElementFlag = 0x0100;
[self willChangeValueForKey:@"dateValue"];
_dateValue = aDateValue;
[super setObjectValue:_dateValue];
[self didChangeValueForKey:@"dateValue"];
[self didChangeValueForKey:@"objectValue"];
[self didChangeValueForKey:@"dateValue"];
[self willChangeValueForKey:@"timeInterval"];
_timeInterval = (_datePickerMode == CPSingleDateMode)? 0 : aTimeInterval;
@@ -370,7 +370,7 @@ CPEraDatePickerElementFlag = 0x0100;
/*! Set the syle of the datePicker
@param aDatePickerStyle the datePicker style
*/
- (void)setDatePickerStyle:(CPDate)aDatePickerStyle
- (void)setDatePickerStyle:(CPInteger)aDatePickerStyle
{
_datePickerStyle = aDatePickerStyle;
@@ -381,7 +381,7 @@ CPEraDatePickerElementFlag = 0x0100;
/*! Set the elements of the datePicker
@param aDatePickerElements the datePicker elements
*/
- (void)setDatePickerElements:(CPDate)aDatePickerElements
- (void)setDatePickerElements:(CPInteger)aDatePickerElements
{
_datePickerElements = aDatePickerElements;
@@ -392,7 +392,7 @@ CPEraDatePickerElementFlag = 0x0100;
/*! Set the mode of the datePicker
@param aDatePickerMode the datePicker mode
*/
- (void)setDatePickerMode:(CPDate)aDatePickerMode
- (void)setDatePickerMode:(CPInteger)aDatePickerMode
{
_datePickerMode = aDatePickerMode;
@@ -503,6 +503,23 @@ CPEraDatePickerElementFlag = 0x0100;
[self setNeedsLayout];
}
/*! Set the timeZone
@param aTimeZone
*/
- (void)setTimeZone:(CPTimeZone)aTimeZone
{
[self willChangeValueForKey:@"timeZone"];
_timeZone = aTimeZone;
[self didChangeValueForKey:@"timeZone"];
[self setNeedsLayout];
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield setDateValue:_dateValue];
else
[_datePickerCalendar setDateValue:_dateValue];
}
#pragma mark -
#pragma mark First responder methods
@@ -603,7 +620,6 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
CPDatePickerElementsKey = @"CPDatePickerElementsKey",
CPDatePickerStyleKey = @"CPDatePickerStyleKey",
CPLocaleKey = @"CPLocaleKey",
CPFormatterKey = @"CPFormatterKey",
CPBorderedKey = @"CPBorderedKey",
CPDateValueKey = @"CPDateValueKey";
@@ -623,7 +639,6 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
_datePickerElements = [aCoder decodeIntForKey:CPDatePickerElementsKey];
_datePickerStyle = [aCoder decodeIntForKey:CPDatePickerStyleKey];
_locale = [aCoder decodeObjectForKey:CPLocaleKey];
_formatter = [aCoder decodeObjectForKey:CPFormatterKey];
_dateValue = [aCoder decodeObjectForKey:CPDateValueKey];
_backgroundColor = [aCoder decodeObjectForKey:CPBackgroundColorKey];
_drawsBackground = [aCoder decodeBoolForKey:CPDrawsBackgroundKey];
@@ -646,7 +661,6 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
[aCoder encodeObject:_dateValue forKey:CPDateValueKey];;
[aCoder encodeObject:_textFont forKey:CPTextFontKey];
[aCoder encodeObject:_locale forKey:CPLocaleKey];
[aCoder encodeObject:_formatter forKey:CPFormatterKey];
[aCoder encodeObject:_backgroundColor forKey:CPBackgroundColorKey];
[aCoder encodeObject:_drawsBackground forKey:CPDrawsBackgroundKey];
[aCoder encodeObject:_isBordered forKey:CPBorderedKey];
@@ -683,4 +697,4 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
self.setMilliseconds(99);
}
@end
@end
+18 -3
View File
@@ -132,7 +132,10 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
*/
- (void)setDateValue:(CPDate)aDateValue
{
[_monthView setMonthForDate:aDateValue];
var dateValue = [aDateValue copy];
[dateValue _dateWithTimeZone:[_datePicker timeZone]];
[_monthView setMonthForDate:dateValue];
[_headerView setMonthForDate:[_monthView monthDate]];
[self setNeedsLayout];
@@ -442,6 +445,9 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
*/
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [_datePicker datePickerStyle] == CPTextFieldDatePickerStyle)
return;
var bounds = [self bounds],
dayNames = [self _dayNames],
width = CGRectGetWidth(bounds),
@@ -750,6 +756,9 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
*/
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [_datePicker datePickerStyle] == CPTextFieldDatePickerStyle)
return;
[super layoutSubviews];
[self tile];
@@ -1050,7 +1059,7 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
/*! Set a theme
*/
- (void)setThemeState:(CPThemeState)aState
- (BOOL)setThemeState:(CPThemeState)aState
{
[_textField setThemeState:aState];
[super setThemeState:aState];
@@ -1058,7 +1067,7 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
/*! Unset a theme
*/
- (void)unsetThemeState:(CPThemeState)aState
- (BOOL)unsetThemeState:(CPThemeState)aState
{
[_textField unsetThemeState:aState];
[super unsetThemeState:aState];
@@ -1130,6 +1139,9 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
*/
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [_datePicker datePickerStyle] == CPTextFieldDatePickerStyle)
return;
var bounds = [self bounds];
[_textField sizeToFit];
[_textField setFrameOrigin:CGPointMake(bounds.size.width / 2 - [_textField frameSize].width / 2 + [_datePicker valueForThemeAttribute:@"border-width"], bounds.size.height / 2 - [_textField frameSize].height / 2)];
@@ -1202,6 +1214,9 @@ var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [_datePicker datePickerStyle] == CPTextFieldDatePickerStyle)
return;
if ([_datePicker drawsBackground])
[self setBackgroundColor:[_datePicker backgroundColor]];
else
+84 -54
View File
@@ -1,4 +1,5 @@
/* _CPDatePickerClock.j
/*
* _CPDatePickerClock.j
* AppKit
*
* Created by Alexandre Wilhelm
@@ -24,9 +25,16 @@
@import "CPImageView.j"
@import "CALayer.j"
@class _CPCibCustomResource
@class CPDatePicker
@global CPHourMinuteSecondDatePickerElementFlag
@global CPTextFieldAndStepperDatePickerStyle
@global CPTextFieldDatePickerStyle
var RADIANS = Math.PI / 180;
@implementation _CPDatePickerClock : CPView
{
@@ -44,11 +52,6 @@
#pragma mark -
#pragma mark Init methods
/*! Init a new _CPDatePickerClock
@param aFrame
@param aDatePicker
@return a new instance of _CPDatePickerClock
*/
- (id)initWithFrame:(CGRect)aFrame datePicker:(CPDatePicker)aDatePicker
{
if (self = [super initWithFrame:aFrame])
@@ -110,8 +113,8 @@
[_rootLayer addSublayer:_middleHandLayer];
[_rootLayer setNeedsDisplay];
}
return self;
}
@@ -119,23 +122,27 @@
#pragma mark -
#pragma mark Layout methods
/*! Layout the subviews
*/
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [_datePicker datePickerStyle] == CPTextFieldDatePickerStyle)
return;
[super layoutSubviews];
var bounds = [self bounds];
var bounds = [self bounds],
dateValue = [[_datePicker dateValue] copy];
[self setBackgroundColor:[_datePicker valueForThemeAttribute:@"bezel-color-clock" inState:[_datePicker themeState]]];
[_middleHandLayer setBackgroundHandColor:[_datePicker valueForThemeAttribute:@"middle-hand-color" inState:[_datePicker themeState]]];
[_hourHandLayer setBackgroundHandColor:[_datePicker valueForThemeAttribute:@"hour-hand-color" inState:[_datePicker themeState]]];
[_minuteHandLayer setBackgroundHandColor:[_datePicker valueForThemeAttribute:@"minute-hand-color" inState:[_datePicker themeState]]];
[_secondHandLayer setBackgroundHandColor:[_datePicker valueForThemeAttribute:@"second-hand-color" inState:[_datePicker themeState]]];
[dateValue _dateWithTimeZone:[_datePicker timeZone]];
[self setBackgroundColor:[_datePicker currentValueForThemeAttribute:@"bezel-color-clock"]];
[_middleHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"middle-hand-image"]];
[_hourHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"hour-hand-image"]];
[_minuteHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"minute-hand-image"]];
[_secondHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"second-hand-image"]];
if ([_datePicker _isEnglishFormat])
{
if ([_datePicker dateValue].getHours() > 11)
if (dateValue.getHours() > 11)
[_PMAMTextField setStringValue:@"PM"]
else
[_PMAMTextField setStringValue:@"AM"];
@@ -149,9 +156,15 @@
[_PMAMTextField setHidden:YES];
}
[_hourHandLayer setRotationRadians:[self _hourPositionRadianForDate:[_datePicker dateValue]]];
[_minuteHandLayer setRotationRadians:[self _minutePositionRadianForDate:[_datePicker dateValue]]];
[_secondHandLayer setRotationRadians:[self _secondPositionRadianForDate:[_datePicker dateValue]]];
[_hourHandLayer setRotationRadians:[self _hourPositionRadianForDate:dateValue]];
[_minuteHandLayer setRotationRadians:[self _minutePositionRadianForDate:dateValue]];
[_secondHandLayer setRotationRadians:[self _secondPositionRadianForDate:dateValue]];
[_PMAMTextField setEnabled:_isEnabled];
[_hourHandLayer setEnabled:_isEnabled];
[_middleHandLayer setEnabled:_isEnabled];
[_secondHandLayer setEnabled:_isEnabled];
[_minuteHandLayer setEnabled:_isEnabled];
// Check if we have to display the hand second
if (([_datePicker datePickerElements] & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)
@@ -164,46 +177,41 @@
#pragma mark -
#pragma mark Getter Setter methods
#pragma mark Accessors
/*! Return the radian position of the hour
*/
- (float)_hourPositionRadianForDate:(CPDate)aDate
{
var hours = aDate.getHours() + aDate.getMinutes() / 60;
return (360 * hours / 12) * (Math.PI / 180)
return (360 * hours / 12) * RADIANS;
}
/*! Return the radian position of the second
*/
- (float)_secondPositionRadianForDate:(CPDate)aDate
{
return (360 * aDate.getSeconds() / 60) * (Math.PI / 180)
return (360 * aDate.getSeconds() / 60) * RADIANS;
}
/*! Return the radian position of the minute
*/
- (float)_minutePositionRadianForDate:(CPDate)aDate
{
var minutes = aDate.getMinutes() + aDate.getSeconds() / 60;
return (360 * minutes / 60) * (Math.PI / 180)
return (360 * minutes / 60) * RADIANS;
}
/*! Set enabled
@param aBoolean
*/
- (void)setEnabled:(BOOL)aBoolean
- (void)setEnabled:(BOOL)shouldEnable
{
_isEnabled = aBoolean;
[_PMAMTextField setEnabled:aBoolean];
[_hourHandLayer setEnabled:aBoolean];
[_middleHandLayer setEnabled:aBoolean];
[_secondHandLayer setEnabled:aBoolean];
[_minuteHandLayer setEnabled:aBoolean];
shouldEnable = !!shouldEnable;
if (shouldEnable === _isEnabled)
return;
_isEnabled = shouldEnable;
[self setNeedsLayout];
// FIXME: This is a workaround for an apparent bug in CALayer.
// Without pumping the event loop, the sublayers of _rootLayer
// (the hands) are not redrawn until an event occurs.
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
@end
@@ -213,6 +221,7 @@
{
BOOL _isEnabled @accessors(setter=setEnabled:, getter=isEnabled);
CPImage _image;
CALayer _imageLayer;
float _rotationRadians;
}
@@ -221,10 +230,6 @@
#pragma mark -
#pragma mark Init methods
/*! Init a new hand layer with an image. The image will be draw in a ImageLayer
@param anImage
@return a new instance of handLayer
*/
- (id)initWithSize:(CGSize)aSize
{
if (self = [super init])
@@ -238,6 +243,7 @@
[self addSublayer:_imageLayer];
}
return self;
}
@@ -245,8 +251,8 @@
#pragma mark -
#pragma mark Setter Getter methods
/*! Set the bounds of the layer. The imageLayer will be at the center of this bounds
@param aRect
/*!
Set the bounds of the layer. The imageLayer will be at the center of this bounds.
*/
- (void)setBounds:(CGRect)aRect
{
@@ -255,12 +261,22 @@
[_imageLayer setPosition:CGPointMake(CGRectGetMidX(aRect), CGRectGetMidY(aRect))];
}
/*! Set the rotation of the imageLayer
@param radians
*/
- (void)setImage:(CPImage)anImage
{
if (_image === anImage)
return;
if ([anImage isKindOfClass:[_CPCibCustomResource class]])
_image = [anImage imageFromCoder:nil];
else
_image = anImage;
[_imageLayer setNeedsDisplay];
}
- (void)setRotationRadians:(float)radians
{
if (_rotationRadians == radians)
if (_rotationRadians === radians)
return;
_rotationRadians = radians;
@@ -270,15 +286,29 @@
1.0, 1.0)];
}
- (void)setBackgroundHandColor:(CPColor)aColor
- (void)setEnabled:(BOOL)shouldEnable
{
[_imageLayer setBackgroundColor:aColor];
shouldEnable = !!shouldEnable;
if (_isEnabled === shouldEnable)
return;
_isEnabled = shouldEnable;
[self setNeedsDisplay];
[_imageLayer setNeedsDisplay];
}
- (void)setEnabled:(BOOL)aBoolean
- (void)imageDidLoad:(CPImage)anImage
{
_isEnabled = aBoolean;
[self setNeedsDisplay];
[_imageLayer setNeedsDisplay];
}
- (void)drawLayer:(CALayer)aLayer inContext:(CGContext)aContext
{
if ([_image loadStatus] != CPImageLoadStatusCompleted)
[_image setDelegate:self];
else
CGContextDrawImage(aContext, [aLayer bounds], _image);
}
@end
+426 -180
View File
@@ -22,6 +22,7 @@
@import "CPControl.j"
@import "CPFont.j"
@import "CPTextField.j"
@import "CPStepper.j"
@import <Foundation/CPArray.j>
@import <Foundation/CPObject.j>
@@ -30,7 +31,6 @@
@import <Foundation/CPLocale.j>
@class CPDatePicker
@class CPStepper
@global CPSingleDateMode
@global CPRangeDateMode
@@ -66,7 +66,6 @@ var CPZeroKeyCode = 48,
_CPDatePickerElementView _datePickerElementView;
CPDatePicker _datePicker;
CPStepper _stepper;
CPTimer _timerEdition;
}
@@ -101,7 +100,7 @@ var CPZeroKeyCode = 48,
#pragma mark -
#pragma mark Responder methods
#pragma mark Override responder methods
- (BOOL)becomeFirstResponder
{
@@ -116,7 +115,7 @@ var CPZeroKeyCode = 48,
- (BOOL)resignFirstResponder
{
// End the timer of editing
[self _endTimer];
[_currentTextField _endEditing];
// Don't forget to unbind, otherwise several steppers will increase or decrease
[_currentTextField unbind:@"objectValue"];
@@ -129,6 +128,10 @@ var CPZeroKeyCode = 48,
return YES;
}
- (BOOL)canBecomeKeyView
{
return NO;
}
#pragma mark -
#pragma mark Setter Getter methods
@@ -139,7 +142,9 @@ var CPZeroKeyCode = 48,
*/
- (void)setDateValue:(CPDate)aDateValue
{
[_datePickerElementView setDateValue:aDateValue];
var dateValue = [aDateValue copy];
[dateValue _dateWithTimeZone:[_datePicker timeZone]];
[_datePickerElementView setDateValue:dateValue];
}
/*! Set the widget enabled or not
@@ -177,6 +182,8 @@ var CPZeroKeyCode = 48,
- (void)_selecteTextFieldWithFlags:(unsigned)flags
{
[_datePickerElementView _updateResponderTextField];
// We select the firstTextField when the datePicker becomes firstResponder if _currentTextField is null. It can be null just when using tab
if (!_currentTextField)
{
@@ -197,7 +204,7 @@ var CPZeroKeyCode = 48,
return;
// End the timer of editing
[self _endTimer];
[_currentTextField _endEditing];
// Don't forget to unbind, otherwise several steppers will increase or decrease
[_currentTextField unbind:@"objectValue"];
@@ -210,7 +217,7 @@ var CPZeroKeyCode = 48,
if ([_currentTextField dateType] != CPAMPMDateType)
{
// We update the value of the stepper dependind on the textField
[_stepper setObjectValue:parseInt([_currentTextField objectValue])];
[_stepper setObjectValue:parseInt([_currentTextField stringValue])];
[_stepper setMaxValue:[_currentTextField maxNumber]];
[_stepper setMinValue:[_currentTextField minNumber]];
@@ -276,7 +283,7 @@ var CPZeroKeyCode = 48,
if (key == CPUpArrowFunctionKey)
{
[self _endTimer];
[_currentTextField _invalidTimer];
[_stepper setDoubleValue:parseInt([_currentTextField objectValue])];
[_stepper performClickUp:self];
return YES;
@@ -284,7 +291,7 @@ var CPZeroKeyCode = 48,
if (key == CPDownArrowFunctionKey)
{
[self _endTimer];
[_currentTextField _invalidTimer];
[_stepper setDoubleValue:parseInt([_currentTextField objectValue])];
[_stepper performClickDown:self];
return YES;
@@ -294,34 +301,37 @@ var CPZeroKeyCode = 48,
{
if (_currentTextField == _firstTextField && [anEvent keyCode] == CPTabKeyCode)
{
if ([_datePicker previousKeyView])
[[self window] makeFirstResponder:[_datePicker previousKeyView]];
var previousValidKeyView = [_datePicker previousValidKeyView];
if (previousValidKeyView)
[[self window] makeFirstResponder:previousValidKeyView];
return YES;
}
[self _selectTextField:[_currentTextField previousKeyView]];
[self _selectTextField:[_currentTextField previousTextField]];
return YES;
}
if (key == CPRightArrowFunctionKey || [anEvent keyCode] == CPTabKeyCode)
{
if (_currentTextField == _lastTextField && [anEvent keyCode] == CPTabKeyCode)
{
if ([_datePicker nextKeyView])
[[self window] makeFirstResponder:[_datePicker nextKeyView]];
var nextValidKeyView = [_datePicker nextValidKeyView];
if (nextValidKeyView)
[[self window] makeFirstResponder:nextValidKeyView];
return YES;
}
[self _selectTextField:[_currentTextField nextKeyView]];
[self _selectTextField:[_currentTextField nextTextField]];
return YES;
}
if ([anEvent keyCode] == CPReturnKeyCode && _timerEdition)
if ([anEvent keyCode] == CPReturnKeyCode)
{
[_timerEdition fire];
[_currentTextField _endEditing];
return YES;
}
@@ -348,84 +358,7 @@ var CPZeroKeyCode = 48,
return;
}
if ([anEvent keyCode] != CPDeleteKeyCode && [anEvent keyCode] != CPDeleteForwardKeyCode && [anEvent keyCode] < CPZeroKeyCode || [anEvent keyCode] > CPNineKeyCode)
return;
// Here, at the first editing we launch a timer to auto-finish the editing. There is another behavior when the user has already edited something
if (!_timerEdition)
{
_timerEdition = [CPTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(_timerKeyEvent:) userInfo:nil repeats:NO];
// Take care about the delete key
if ([anEvent keyCode] == CPDeleteKeyCode || [anEvent keyCode] == CPDeleteForwardKeyCode)
[_currentTextField setStringKeyValue:@""];
else
[_currentTextField setStringKeyValue:[anEvent characters]];
}
else
{
var newFireDate = [CPDate date],
key;
newFireDate.setSeconds(newFireDate.getSeconds() + 2);
[_timerEdition setFireDate:newFireDate];
// Take care about the delete key
if ([anEvent keyCode] == CPDeleteKeyCode || [anEvent keyCode] == CPDeleteForwardKeyCode)
key = [[_currentTextField stringValue] substringToIndex:[[_currentTextField stringValue] length] - 1];
else
key = [CPString stringWithFormat:@"%i%i",parseInt([_currentTextField stringValue]), parseInt([anEvent characters])];
[_currentTextField setStringKeyValue:key];
}
}
#pragma mark -
#pragma mark Timer event
/*! End of the timer
*/
- (void)_timerKeyEvent:(id)sender
{
_timerEdition = nil;
if (![[_currentTextField stringValue] isEqualToString:@" "] && ![[_currentTextField stringValue] isEqualToString:@" "])
{
var value = [_currentTextField stringValue];
if ([_datePicker _isEnglishFormat] && [_currentTextField dateType] == CPHourDateType)
{
if (![_datePickerElementView _isAMHour] && value != 12)
value = parseInt(value) + 12;
if (value == 12 && ![_datePickerElementView _isAMHour])
value = 12;
else if (value == 12)
value = 0;
}
[_currentTextField setObjectValue:value];
}
else
{
[_currentTextField setObjectValue:@"0"];
}
}
/*! We force to end the timer
*/
- (void)_endTimer
{
if (_timerEdition)
{
[_timerEdition invalidate];
[self _timerKeyEvent:_timerEdition];
_timerEdition = nil;
}
[_currentTextField setValueForKeyEvent:anEvent];
}
@@ -516,6 +449,7 @@ var CPZeroKeyCode = 48,
[_textFieldDay setDateType:CPDayDateType];
[_textFieldDay setDatePicker:_datePicker];
[_textFieldDay setAlignment:CPRightTextAlignment];
[_textFieldDay setDatePickerElementView:self];
[self addSubview:_textFieldDay];
_textFieldMonth = [_CPDatePickerElementTextField new];
@@ -524,6 +458,7 @@ var CPZeroKeyCode = 48,
[_textFieldMonth setDateType:CPMonthDateType];
[_textFieldMonth setDatePicker:_datePicker];
[_textFieldMonth setAlignment:CPRightTextAlignment];
[_textFieldMonth setDatePickerElementView:self];
[self addSubview:_textFieldMonth];
_textFieldYear = [_CPDatePickerElementTextField new];
@@ -532,6 +467,7 @@ var CPZeroKeyCode = 48,
[_textFieldYear setDateType:CPYearDateType];
[_textFieldYear setDatePicker:_datePicker];
[_textFieldYear setAlignment:CPRightTextAlignment];
[_textFieldYear setDatePickerElementView:self];
[self addSubview:_textFieldYear];
_textFieldHour = [_CPDatePickerElementTextField new];
@@ -540,6 +476,7 @@ var CPZeroKeyCode = 48,
[_textFieldHour setDateType:CPHourDateType];
[_textFieldHour setDatePicker:_datePicker];
[_textFieldHour setAlignment:CPRightTextAlignment];
[_textFieldHour setDatePickerElementView:self];
[self addSubview:_textFieldHour];
_textFieldMinute = [_CPDatePickerElementTextField new];
@@ -548,6 +485,7 @@ var CPZeroKeyCode = 48,
[_textFieldMinute setDateType:CPMinuteDateType];
[_textFieldMinute setDatePicker:_datePicker];
[_textFieldMinute setAlignment:CPRightTextAlignment];
[_textFieldMinute setDatePickerElementView:self];
[self addSubview:_textFieldMinute];
_textFieldSecond = [_CPDatePickerElementTextField new];
@@ -556,6 +494,7 @@ var CPZeroKeyCode = 48,
[_textFieldSecond setDateType:CPSecondDateType];
[_textFieldSecond setDatePicker:_datePicker];
[_textFieldSecond setAlignment:CPRightTextAlignment];
[_textFieldSecond setDatePickerElementView:self];
[self addSubview:_textFieldSecond];
_textFieldPMAM = [_CPDatePickerElementTextField new];
@@ -564,6 +503,7 @@ var CPZeroKeyCode = 48,
[_textFieldPMAM setDateType:CPAMPMDateType];
[_textFieldPMAM setDatePicker:_datePicker];
[_textFieldPMAM setAlignment:CPRightTextAlignment];
[_textFieldPMAM setDatePickerElementView:self];
[self addSubview:_textFieldPMAM];
_textFieldSeparatorOne = [CPTextField labelWithTitle:@"/"];
@@ -612,6 +552,13 @@ var CPZeroKeyCode = 48,
[_textFieldPMAM setStringValue:@"AM"];
}
/*! Set the day date value to the appropriate textField
@param aDayDateValue the day
*/
- (void)setDayDateValue:(CPString)aDayDateValue
{
[_textFieldDay setStringValue:aDayDateValue];
}
/*! Set the widget enabled or not
@param aBoolean
@@ -639,6 +586,65 @@ var CPZeroKeyCode = 48,
return [[_textFieldPMAM stringValue] isEqualToString:@"AM"];
}
- (CPDate)dateValue
{
var date = [[_datePicker dateValue] copy];
[date _dateWithTimeZone:[_datePicker timeZone]];
if (![_textFieldDay isHidden])
date.setDate([_textFieldDay stringValue]);
if (![_textFieldMonth isHidden])
date.setMonth(parseInt([_textFieldMonth stringValue]) - 1);
if (![_textFieldYear isHidden])
date.setFullYear([_textFieldYear stringValue]);
if (![_textFieldSecond isHidden])
date.setSeconds([_textFieldSecond stringValue]);
if (![_textFieldMinute isHidden])
date.setMinutes([_textFieldMinute stringValue]);
if (![_textFieldHour isHidden])
{
var hour = parseInt([_textFieldHour stringValue]),
currentHour = parseInt(date.getHours());
if (hour != currentHour)
{
if (([_datePicker _isEnglishFormat] || [_datePicker _isAmericanFormat]))
{
if (![self _isAMHour])
{
if (!(currentHour == 12 && hour == 11) && hour < 13)
hour = hour + 12;
}
else if (hour == 12 && currentHour != 11)
{
hour = 0;
}
else if (currentHour == 0 && hour == 11)
{
hour = 23;
}
else if (hour == 13)
{
hour = 1;
}
}
if (hour == 24)
hour = 0;
date.setHours(hour);
}
}
return date;
}
#pragma mark -
#pragma mark Notification methods
@@ -649,16 +655,19 @@ var CPZeroKeyCode = 48,
- (void)_datePickerElementTextFieldAMPMChangedNotification:(CPNotification)aNotification
{
var value = [[aNotification object] stringValue],
dateValue = [[_datePicker dateValue] copy];
dateValue = [[_datePicker dateValue] copy],
d = [dateValue copy];
[d _dateWithTimeZone:[_datePicker timeZone]];
if ([value isEqualToString:@"PM"])
{
if (dateValue.getHours() <= 11)
if (d.getHours() <= 11)
dateValue.setHours(dateValue.getHours() + 12);
}
else
{
if (dateValue.getHours() > 11)
if (d.getHours() > 11)
dateValue.setHours(dateValue.getHours() - 12);
}
@@ -671,6 +680,9 @@ var CPZeroKeyCode = 48,
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPClockAndCalendarDatePickerStyle)
return;
[super layoutSubviews];
var themeState = [_datePicker themeState];
@@ -1076,6 +1088,12 @@ var CPZeroKeyCode = 48,
/*! Update the nextTextField params of all of the textField. This is used to move the current textField with the arrows
*/
- (void)_updateKeyView
{
[self _updateNextTextField];
[self _updatePreviousTextField]
}
- (void)_updateNextTextField
{
var datePickerElements = [_datePicker datePickerElements],
firstTexField = _textFieldMonth,
@@ -1089,45 +1107,94 @@ var CPZeroKeyCode = 48,
}
if ((datePickerElements & CPYearMonthDayDatePickerElementFlag) == CPYearMonthDayDatePickerElementFlag)
[firstTexField setNextKeyView:secondTextField];
[firstTexField setNextTextField:secondTextField];
else
[firstTexField setNextKeyView:_textFieldYear];
[firstTexField setNextTextField:_textFieldYear];
[secondTextField setNextKeyView:_textFieldYear];
[secondTextField setNextTextField:_textFieldYear];
if (datePickerElements & CPHourMinuteSecondDatePickerElementFlag || datePickerElements & CPHourMinuteDatePickerElementFlag)
[_textFieldYear setNextKeyView:_textFieldHour];
[_textFieldYear setNextTextField:_textFieldHour];
else if (isEnglishFormat || (datePickerElements & CPYearMonthDayDatePickerElementFlag) == CPYearMonthDayDatePickerElementFlag)
[_textFieldYear setNextKeyView:firstTexField];
[_textFieldYear setNextTextField:firstTexField];
else
[_textFieldYear setNextKeyView:secondTextField];
[_textFieldYear setNextTextField:secondTextField];
[_textFieldHour setNextKeyView:_textFieldMinute];
[_textFieldHour setNextTextField:_textFieldMinute];
if ((datePickerElements & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)
[_textFieldMinute setNextKeyView:_textFieldSecond];
[_textFieldMinute setNextTextField:_textFieldSecond];
else if (isEnglishFormat)
[_textFieldMinute setNextKeyView:_textFieldPMAM];
[_textFieldMinute setNextTextField:_textFieldPMAM];
else if ((datePickerElements & CPYearMonthDayDatePickerElementFlag) == CPYearMonthDayDatePickerElementFlag)
[_textFieldMinute setNextKeyView:firstTexField];
[_textFieldMinute setNextTextField:firstTexField];
else if (datePickerElements & CPYearMonthDatePickerElementFlag)
[_textFieldMinute setNextKeyView:secondTextField];
[_textFieldMinute setNextTextField:secondTextField];
else
[_textFieldMinute setNextKeyView:_textFieldHour];
[_textFieldMinute setNextTextField:_textFieldHour];
if (isEnglishFormat)
[_textFieldSecond setNextKeyView:_textFieldPMAM];
[_textFieldSecond setNextTextField:_textFieldPMAM];
else if ((datePickerElements & CPYearMonthDayDatePickerElementFlag) == CPYearMonthDayDatePickerElementFlag)
[_textFieldSecond setNextKeyView:firstTexField];
[_textFieldSecond setNextTextField:firstTexField];
else if (datePickerElements & CPYearMonthDatePickerElementFlag)
[_textFieldSecond setNextKeyView:secondTextField];
[_textFieldSecond setNextTextField:secondTextField];
else
[_textFieldSecond setNextKeyView:_textFieldHour];
[_textFieldSecond setNextTextField:_textFieldHour];
if (datePickerElements & CPYearMonthDayDatePickerElementFlag)
[_textFieldPMAM setNextKeyView:_textFieldMonth];
[_textFieldPMAM setNextTextField:_textFieldMonth];
else
[_textFieldPMAM setNextKeyView:_textFieldHour];
[_textFieldPMAM setNextTextField:_textFieldHour];
}
- (void)_updatePreviousTextField
{
var datePickerElements = [_datePicker datePickerElements],
firstTexField = _textFieldMonth,
secondTextField = _textFieldDay,
isEnglishFormat = [_datePicker _isEnglishFormat];
if (!isEnglishFormat)
{
firstTexField = _textFieldDay;
secondTextField = _textFieldMonth;
}
if ((datePickerElements & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)
[_textFieldPMAM setPreviousTextField:_textFieldSecond];
else if (datePickerElements & CPHourMinuteDatePickerElementFlag)
[_textFieldPMAM setPreviousTextField:_textFieldMinute];
[_textFieldSecond setPreviousTextField:_textFieldMinute];
[_textFieldMinute setPreviousTextField:_textFieldHour];
if (datePickerElements & CPYearMonthDatePickerElementFlag)
[_textFieldHour setPreviousTextField:_textFieldYear];
else if (isEnglishFormat)
[_textFieldHour setPreviousTextField:_textFieldPMAM];
else if ((datePickerElements & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)
[_textFieldHour setPreviousTextField:_textFieldSecond];
else
[_textFieldHour setPreviousTextField:_textFieldMinute];
if (!isEnglishFormat)
[_textFieldYear setPreviousTextField:_textFieldMonth];
else if ((datePickerElements & CPYearMonthDayDatePickerElementFlag) == CPYearMonthDayDatePickerElementFlag)
[_textFieldYear setPreviousTextField:_textFieldDay];
else
[_textFieldYear setPreviousTextField:_textFieldMonth];
[secondTextField setPreviousTextField:firstTexField];
if (isEnglishFormat && datePickerElements & CPHourMinuteDatePickerElementFlag)
[firstTexField setPreviousTextField:_textFieldPMAM];
else if ((datePickerElements & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)
[firstTexField setPreviousTextField:_textFieldSecond];
else if (datePickerElements & CPHourMinuteDatePickerElementFlag)
[firstTexField setPreviousTextField:_textFieldMinute];
else
[firstTexField setPreviousTextField:_textFieldYear];
}
@end
@@ -1145,11 +1212,18 @@ var CPMonthDateType = 0,
*/
@implementation _CPDatePickerElementTextField : CPTextField
{
_CPDatePickerElementTextField _nextTextField @accessors(property=nextTextField);
_CPDatePickerElementTextField _previousTextField @accessors(property=previousTextField);
_CPDatePickerElementView _datePickerElementView @accessors(property=datePickerElementView);
CPDatePicker _datePicker @accessors(setter=setDatePicker:);
int _dateType @accessors(getter=dateType);
int _maxNumber @accessors(getter=maxNumber);
int _minNumber @accessors(getter=minNumber);
BOOL _firstEvent;
CPTimer _timerEdition;
}
@@ -1158,6 +1232,7 @@ var CPMonthDateType = 0,
- (BOOL)acceptFirstResponder
{
_firstEvent = YES;
return NO;
}
@@ -1259,38 +1334,128 @@ var CPMonthDateType = 0,
It's called when the user is editing with the keyboard
@param aStringValue a CPString
*/
- (void)setStringKeyValue:(id)anObjectValue
- (void)setValueForKeyEvent:(CPEvent)anEvent
{
if (_dateType == CPYearDateType)
{
if ([anObjectValue length] > 4)
return
var keyCode = [anEvent keyCode];
while ([anObjectValue length] < 4)
anObjectValue = " " + anObjectValue;
if (keyCode != CPDeleteKeyCode && keyCode != CPDeleteForwardKeyCode && keyCode < CPZeroKeyCode || keyCode > CPNineKeyCode)
return;
var newValue = [self stringValue].replace(/\s/g, ''),
length = [newValue length],
eventKeyValue = parseInt([anEvent characters]).toString();
if (keyCode == CPDeleteKeyCode || keyCode == CPDeleteForwardKeyCode)
{
[_timerEdition invalidate];
_timerEdition = nil;
newValue = [newValue substringToIndex:(length - 1)];
}
else
{
if ([anObjectValue length] > 2)
return
if (!_timerEdition)
{
_timerEdition = [CPTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(_timerKeyEvent:) userInfo:nil repeats:NO];
while ([anObjectValue length] < 2)
anObjectValue = " " + anObjectValue;
if (_firstEvent || !length)
newValue = eventKeyValue;
else
newValue = parseInt(newValue).toString() + eventKeyValue;
}
else
{
var newFireDate = [CPDate date];
newFireDate.setSeconds(newFireDate.getSeconds() + 2);
[_timerEdition setFireDate:newFireDate];
newValue = parseInt(newValue).toString() + eventKeyValue;
}
}
if (parseInt(anObjectValue) > [self _maxNumberWithMaxDate])
if (parseInt(newValue) > [self _maxNumberWithMaxDate] || ([_datePicker _isEnglishFormat] && _dateType == CPHourDateType && parseInt(newValue) > 12))
return;
if ([_datePicker _isEnglishFormat] && _dateType == CPHourDateType && parseInt(anObjectValue) > 12)
return;
_firstEvent = NO;
[super setObjectValue:anObjectValue];
[super setObjectValue:newValue];
}
/*!
End of the timer
*/
- (void)_timerKeyEvent:(id)sender
{
var stringValue = [self stringValue];
_timerEdition = nil;
if ([stringValue length])
{
if ([_datePicker _isEnglishFormat] && [self dateType] == CPHourDateType)
{
var isAMHour = [[self superview] _isAMHour];
if (!isAMHour && stringValue != 12)
stringValue = parseInt(stringValue) + 12;
if (stringValue == 12 && !isAMHour)
stringValue = 12;
else if (stringValue == 12)
stringValue = 0;
}
[self setObjectValue:stringValue];
}
}
/*!
We force to end the timer
*/
- (void)_invalidTimer
{
if (_timerEdition)
{
[_timerEdition invalidate];
_timerEdition = nil;
}
}
/*!
We force to end the timer and to update the objectValue of the datePicker
*/
- (void)_endEditing
{
if (_timerEdition)
[_timerEdition invalidate];
_timerEdition = nil;
var objectValue = [self stringValue];
if (![objectValue length])
objectValue = [self objectValue];
if ([_datePicker _isEnglishFormat] && [self dateType] == CPHourDateType)
{
var isAMHour = [[self superview] _isAMHour];
if (!isAMHour && objectValue != 12)
objectValue = parseInt(objectValue) + 12;
if (objectValue == 12 && !isAMHour)
objectValue = 12;
else if (objectValue == 12)
objectValue = 0;
}
[self setObjectValue:objectValue];
}
/*! Set the stringValue of the TextField. Add some zeros of there isn't 2/4 letters in the value. It's called at the end of the editing process
@param aStringValue a CPString
*/
- (void)setStringValue:(id)aStringValue
- (void)setStringValue:(CPString)aStringValue
{
if (_dateType == CPYearDateType)
{
@@ -1312,7 +1477,13 @@ var CPMonthDateType = 0,
}
while ([aStringValue length] < 2)
aStringValue = "0" + aStringValue;
{
if (_dateType == CPSecondDateType || _dateType == CPMinuteDateType)
aStringValue = @"0" + aStringValue;
else
aStringValue = @" " + aStringValue;
}
}
[super setObjectValue:aStringValue];
@@ -1325,12 +1496,20 @@ var CPMonthDateType = 0,
*/
- (void)setObjectValue:(id)anObjectValue
{
var dateValue = [[_datePicker dateValue] copy];
var dateValue = [[_datePicker dateValue] copy],
lengthString = [[self stringValue] length],
objectValue = parseInt(anObjectValue);
switch (_dateType)
{
case CPMonthDateType:
if (objectValue == 0 || !lengthString)
{
[self setStringValue:(dateValue.getMonth() + 1).toString()];
return;
}
var dateNextMonth = [dateValue copy];
dateNextMonth.setDate(1);
@@ -1339,76 +1518,81 @@ var CPMonthDateType = 0,
var numberDayNextMonth = [dateNextMonth _daysInMonth];
if (numberDayNextMonth < [dateValue _daysInMonth] && dateValue.getDate() > numberDayNextMonth)
dateValue.setDate(numberDayNextMonth);
[_datePickerElementView setDayDateValue:numberDayNextMonth.toString()];
dateValue.setMonth(parseInt(anObjectValue) - 1);
[super setObjectValue:objectValue];
break;
case CPDayDateType:
dateValue.setDate(parseInt(anObjectValue));
if (objectValue == 0 || !lengthString)
{
[self setStringValue:dateValue.getDate().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPYearDateType:
dateValue.setFullYear(parseInt(anObjectValue));
if (objectValue == 0 || !lengthString)
{
[self setStringValue:dateValue.getFullYear().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPHourDateType:
dateValue.setHours(parseInt(anObjectValue));
if (!lengthString)
{
[self setStringValue:dateValue.getHours().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPSecondDateType:
dateValue.setSeconds(parseInt(anObjectValue));
if (!lengthString)
{
[self setStringValue:dateValue.getSeconds().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPMinuteDateType:
dateValue.setMinutes(parseInt(anObjectValue));
if (!lengthString)
{
[self setStringValue:dateValue.getMinutes().toString()];
return;
}
[super setObjectValue:objectValue];
break;
}
[_datePicker setDateValue:dateValue];
}
var newDateValue = [_datePickerElementView dateValue],
timeZone = [_datePicker timeZone];
/*! Return the objectValue of the textField. Needed for the binding.
This returns the objectValue relative to the dateValue
*/
- (void)objectValue
{
var dateValue = [[_datePicker dateValue] copy];
switch (_dateType)
if (timeZone)
{
case CPMonthDateType:
return dateValue.getMonth() + 1;
break;
var secondsFromGMT = [timeZone secondsFromGMTForDate:newDateValue],
secondsFromGMTTimeZone = [timeZone secondsFromGMT];
case CPDayDateType:
return dateValue.getDate();
break;
case CPYearDateType:
return dateValue.getFullYear();
break;
case CPHourDateType:
return dateValue.getHours();
break;
case CPSecondDateType:
return dateValue.getSeconds();
break;
case CPMinuteDateType:
return dateValue.getMinutes();
break;
default:
return [super objectValue];
break;
newDateValue.setSeconds(newDateValue.getSeconds() + secondsFromGMT - secondsFromGMTTimeZone);
}
return [super objectValue];
[_datePicker setDateValue:newDateValue];
}
#pragma mark -
#pragma mark Mouse event
@@ -1438,7 +1622,69 @@ var CPMonthDateType = 0,
*/
- (void)makeDeselectable
{
_firstEvent = YES;
[self unsetThemeState:CPThemeStateSelected];
}
@end
#pragma mark -
#pragma mark Override
/*!
We override this method to get all the time the good width
*/
- (CGSize)_minimumFrameSize
{
var frameSize = [self frameSize],
contentInset = [self currentValueForThemeAttribute:@"content-inset"],
minSize = [self currentValueForThemeAttribute:@"min-size"],
maxSize = [self currentValueForThemeAttribute:@"max-size"],
lineBreakMode = [self lineBreakMode],
text = (_dateType == CPYearDateType) ? @"0000" : @"00",
textSize = CGSizeMakeCopy(frameSize),
font = [self currentValueForThemeAttribute:@"font"];
textSize.width -= contentInset.left + contentInset.right;
textSize.height -= contentInset.top + contentInset.bottom;
if (_dateType == CPAMPMDateType)
text = [self stringValue];
if (frameSize.width !== 0 &&
![self isBezeled] &&
(lineBreakMode === CPLineBreakByWordWrapping || lineBreakMode === CPLineBreakByCharWrapping))
{
textSize = [text sizeWithFont:font inWidth:textSize.width];
}
else
{
textSize = [text sizeWithFont:font];
// Account for possible fractional pixels at right edge
textSize.width += 1;
}
// Account for possible fractional pixels at bottom edge
textSize.height += 1;
frameSize.height = textSize.height + contentInset.top + contentInset.bottom;
if ([self isBezeled])
{
frameSize.height = MAX(frameSize.height, minSize.height);
if (maxSize.width > 0.0)
frameSize.width = MIN(frameSize.width, maxSize.width);
if (maxSize.height > 0.0)
frameSize.height = MIN(frameSize.height, maxSize.height);
}
else
frameSize.width = textSize.width + contentInset.left + contentInset.right;
frameSize.width = MAX(frameSize.width, minSize.width);
return frameSize;
}
@end
+11 -25
View File
@@ -244,11 +244,6 @@ var CPDocumentUntitledCount = 0;
{
}
- (CPWindowController)firstEligibleExistingWindowController
{
return nil;
}
// Creating and managing window controllers
/*!
Creates the window controller for this document.
@@ -261,6 +256,7 @@ var CPDocumentUntitledCount = 0;
- (void)makeViewAndWindowControllers
{
var viewCibName = [self viewCibName],
windowCibName = [self windowCibName],
viewController = nil,
windowController = nil;
@@ -268,31 +264,21 @@ var CPDocumentUntitledCount = 0;
if ([viewCibName length])
viewController = [[CPViewController alloc] initWithCibName:viewCibName bundle:nil owner:self];
// If we have a view controller, check if we have a free window for it.
if (viewController)
windowController = [self firstEligibleExistingWindowController];
// From a cib if we have one.
if ([windowCibName length])
windowController = [[CPWindowController alloc] initWithWindowCibName:windowCibName owner:self];
// If not, create one.
if (!windowController)
// If not you get a standard window capable of displaying multiple documents and view
else if (viewController)
{
var windowCibName = [self windowCibName];
var view = [viewController view],
viewFrame = [view frame];
// From a cib if we have one.
if ([windowCibName length])
windowController = [[CPWindowController alloc] initWithWindowCibName:windowCibName owner:self];
viewFrame.origin = CGPointMake(50, 50);
// If not you get a standard window capable of displaying multiple documents and view
else if (viewController)
{
var view = [viewController view],
viewFrame = [view frame];
var theWindow = [[CPWindow alloc] initWithContentRect:viewFrame styleMask:CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask];
viewFrame.origin = CGPointMake(50, 50);
var theWindow = [[CPWindow alloc] initWithContentRect:viewFrame styleMask:CPTitledWindowMask | CPClosableWindowMask | CPMiniaturizableWindowMask | CPResizableWindowMask];
windowController = [[CPWindowController alloc] initWithWindow:theWindow];
}
windowController = [[CPWindowController alloc] initWithWindow:theWindow];
}
if (windowController && viewController)
+35
View File
@@ -253,6 +253,14 @@ var CPSharedDocumentController = nil;
return _documents;
}
/*!
Returns the CPDocument object associated with the main window.
*/
- (CPDocument)currentDocument
{
return [[[CPApp mainWindow] windowController] document];
}
/*!
Adds \c aDocument under the control of the receiver.
@param aDocument the document to add
@@ -271,6 +279,33 @@ var CPSharedDocumentController = nil;
[_documents removeObjectIdenticalTo:aDocument];
}
/*!
Returns the document object whose window controller
owns a specified window.
*/
- (CPDocument)documentForWindow:(CPWindow)aWindow
{
return [[aWindow windowController] document];
}
/*!
Returns a Boolean value that indicates whether the receiver
has any documents with unsaved changes.
*/
- (BOOL)hasEditedDocuments
{
var iter = [_documents objectEnumerator],
obj;
while ((obj = [iter nextObject]) !== nil)
{
if ([obj isDocumentEdited])
return YES;
}
return NO;
}
- (CPString)defaultType
{
return [_documentTypes[0] objectForKey:@"CPBundleTypeName"];
+23
View File
@@ -68,6 +68,11 @@ var _CPEventPeriodicEventPeriod = 0,
float _deltaX;
float _deltaY;
float _deltaZ;
#if PLATFORM(DOM)
BOOL _suppressCappuccinoCut;
BOOL _suppressCappuccinoPaste;
#endif
}
/*!
@@ -473,6 +478,24 @@ var _CPEventPeriodicEventPeriod = 0,
return !firstResponderIsText;
}
/*!
Return YES if this event is a part of processing a browser controlled cut or paste event
where the browser will go ahead and do the work of cutting or pasting within the input
element after processing of this event. The implication is that it should not be done by
the CPTextField (or whatever else is controlling the input) since this would result in
nothing being cut (because the field already cut the text out), or a double paste
(because the field pasted as well as the browser).
*/
- (BOOL)_platformIsEffectingCutOrPaste
{
#if PLATFORM(DOM)
return _suppressCappuccinoCut || _suppressCappuccinoPaste;
#else
return NO;
#endif
}
/*!
Generates periodic events every \c aPeriod seconds.
+1 -1
View File
@@ -189,7 +189,7 @@ var IEFlashCLSID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
return @"CPFV_" + [self UID];
}
- (void)mouseMoved:(id)sommit
- (void)mouseMoved:(CPEvent)sommit
{
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
}
+1 -1
View File
@@ -208,7 +208,7 @@ following:
var systemSize = String(_CPFontSystemFontSize),
currentSize = String(CPFontCurrentSystemSize);
for (key in _CPSystemFontCache)
for (var key in _CPSystemFontCache)
{
if (_CPSystemFontCache.hasOwnProperty(key) &&
(key.indexOf(systemSize) === 0 || key.indexOf(currentSize) === 0))
+7 -2
View File
@@ -136,14 +136,19 @@ function CPAppKitImage(aFilename, aSize)
/*!
Initializes the image, by associating it with a filename. The image
denoted in \c aFilename is not actually loaded. It will
be loaded once needed.
denoted in \c aFilename is not actually loaded. It will be loaded
once needed.
@param aFilename the file containing the image
@param aSize the image's size
@return the initialized image
*/
- (id)initByReferencingFile:(CPString)aFilename size:(CGSize)aSize
{
// Quietly return nil like in Cocoa, rather than crashing later.
if (aFilename === undefined || aFilename === nil)
return nil;
self = [super init];
if (self)
+33 -40
View File
@@ -87,26 +87,37 @@ var CPImageViewEmptyPlaceholderImage = nil;
if (self)
{
#if PLATFORM(DOM)
_DOMImageElement = document.createElement("img");
_DOMImageElement.style.position = "absolute";
_DOMImageElement.style.left = "0px";
_DOMImageElement.style.top = "0px";
if ([CPPlatform supportsDragAndDrop])
{
_DOMImageElement.setAttribute("draggable", "true");
_DOMImageElement.style["-khtml-user-drag"] = "element";
}
CPDOMDisplayServerAppendChild(_DOMElement, _DOMImageElement);
_DOMImageElement.style.visibility = "hidden";
[self _createDOMImageElement];
#endif
}
return self;
}
- (void)_createDOMImageElement
{
#if PLATFORM(DOM)
if (_DOMImageElement)
return;
_DOMImageElement = document.createElement("img");
_DOMImageElement.style.position = "absolute";
_DOMImageElement.style.left = "0px";
_DOMImageElement.style.top = "0px";
if ([CPPlatform supportsDragAndDrop])
{
_DOMImageElement.setAttribute("draggable", "true");
_DOMImageElement.style["-khtml-user-drag"] = "element";
}
_DOMImageElement.style.visibility = "hidden";
AppKitTagDOMElement(self, _DOMImageElement);
CPDOMDisplayServerAppendChild(_DOMElement, _DOMImageElement);
#endif
}
/*!
Returns the view's image.
*/
@@ -138,6 +149,9 @@ var CPImageViewEmptyPlaceholderImage = nil;
var newImage = [self objectValue];
#if PLATFORM(DOM)
if (!_DOMImageElement)
[self _createDOMImageElement];
_DOMImageElement.src = newImage ? [newImage filename] : [CPImageViewEmptyPlaceholderImage filename];
#endif
@@ -253,7 +267,7 @@ var CPImageViewEmptyPlaceholderImage = nil;
[self setNeedsDisplay:YES];
}
- (unsigned)imageScaling
- (CPUInteger)imageScaling
{
return [self currentValueForThemeAttribute:@"image-scaling"];
}
@@ -488,7 +502,7 @@ var CPImageViewEmptyPlaceholderImage = nil;
[_source setImage:image];
}
- (void)valueForBinding:(CPString)aBinding
- (id)valueForBinding:(CPString)aBinding
{
var image = [_source image];
@@ -517,28 +531,12 @@ var CPImageViewImageKey = @"CPImageViewImageKey",
*/
- (id)initWithCoder:(CPCoder)aCoder
{
#if PLATFORM(DOM)
_DOMImageElement = document.createElement("img");
_DOMImageElement.style.position = "absolute";
_DOMImageElement.style.left = "0px";
_DOMImageElement.style.top = "0px";
_DOMImageElement.style.visibility = "hidden";
if ([CPPlatform supportsDragAndDrop])
{
_DOMImageElement.setAttribute("draggable", "true");
_DOMImageElement.style["-khtml-user-drag"] = "element";
}
if (typeof(appkit_tag_dom_elements) !== "undefined" && !!appkit_tag_dom_elements)
_DOMImageElement.setAttribute("data-cappuccino-view", [self className]);
#endif
self = [super initWithCoder:aCoder];
if (self)
{
#if PLATFORM(DOM)
_DOMElement.appendChild(_DOMImageElement);
[self _createDOMImageElement];
#endif
[self setHasShadow:[aCoder decodeBoolForKey:CPImageViewHasShadowKey]];
@@ -564,17 +562,12 @@ var CPImageViewImageKey = @"CPImageViewImageKey",
// We do this in order to avoid encoding the _shadowView, which
// should just automatically be created programmatically as needed.
if (_shadowView)
{
var actualSubviews = _subviews;
_subviews = [_subviews copy];
[_subviews removeObjectIdenticalTo:_shadowView];
}
[_shadowView removeFromSuperview];
[super encodeWithCoder:aCoder];
if (_shadowView)
_subviews = actualSubviews;
[self addSubview:_shadowView];
[aCoder encodeBool:_hasShadow forKey:CPImageViewHasShadowKey];
[aCoder encodeInt:_imageAlignment forKey:CPImageViewImageAlignmentKey];
+1 -1
View File
@@ -62,7 +62,7 @@ CPRatingLevelIndicatorStyle = 3;
return "level-indicator";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"bezel-color": [CPNull null],
+35 -16
View File
@@ -278,7 +278,7 @@ var _CPMenuBarVisible = NO,
@param aMenuItem the item to insert
@param anIndex the index in the menu to insert the item.
*/
- (void)insertItem:(CPMenuItem)aMenuItem atIndex:(unsigned)anIndex
- (void)insertItem:(CPMenuItem)aMenuItem atIndex:(CPUInteger)anIndex
{
[self insertObject:aMenuItem inItemsAtIndex:anIndex];
}
@@ -291,7 +291,7 @@ var _CPMenuBarVisible = NO,
@param anIndex the index location in the menu for the new item
@return the new menu item
*/
- (CPMenuItem)insertItemWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent atIndex:(unsigned)anIndex
- (CPMenuItem)insertItemWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent atIndex:(CPUInteger)anIndex
{
var item = [[CPMenuItem alloc] initWithTitle:aTitle action:anAction keyEquivalent:aKeyEquivalent];
@@ -335,7 +335,7 @@ var _CPMenuBarVisible = NO,
Removes the item at the specified index from the menu
@param anIndex the index of the item to remove
*/
- (void)removeItemAtIndex:(unsigned)anIndex
- (void)removeItemAtIndex:(CPUInteger)anIndex
{
[self removeObjectFromItemsAtIndex:anIndex];
}
@@ -355,7 +355,7 @@ var _CPMenuBarVisible = NO,
while (count--)
[_items[count] setMenu:nil];
_highlightedIndex = CPNotFound;
[self _highlightItemAtIndex:CPNotFound];
// Because we are changing _items directly, be sure to notify KVO
[self willChangeValueForKey:@"items"];
@@ -621,7 +621,7 @@ var _CPMenuBarVisible = NO,
*/
- (void)update
{
if (![self autoenablesItems])
if (!_autoenablesItems)
return;
var items = [self itemArray];
@@ -633,14 +633,24 @@ var _CPMenuBarVisible = NO,
if ([item hasSubmenu])
continue;
var validator = [CPApp targetForAction:[item action] to:[item target] from:item];
// If there are enabled bindings for the item, they override anything else
var binder = [CPBinder getBinding:CPEnabledBinding forObject:item];
if (binder)
{
[binder setValueFor:CPEnabledBinding];
return;
}
var validator = [CPApp targetForAction:[item action] to:[item target] from:item],
shouldBeEnabled = YES;
if (!validator)
{
// If targetForAction: returns nil, it could be that there is no action.
// If there is an action and nil is returned, no valid target could be found.
if ([item action] || [item target])
[item setEnabled:NO];
shouldBeEnabled = NO;
else
{
// Check to see if there is a target binding with an invalid selector
@@ -655,16 +665,18 @@ var _CPMenuBarVisible = NO,
selector = [options valueForKey:CPSelectorNameBindingOption];
if (target && selector && ![target respondsToSelector:CPSelectorFromString(selector)])
[item setEnabled:NO];
shouldBeEnabled = NO;
}
}
}
else if (![validator respondsToSelector:[item action]])
[item setEnabled:NO];
shouldBeEnabled = NO;
else if ([validator respondsToSelector:@selector(validateMenuItem:)])
[item setEnabled:[validator validateMenuItem:item]];
shouldBeEnabled = [validator validateMenuItem:item];
else if ([validator respondsToSelector:@selector(validateUserInterfaceItem:)])
[item setEnabled:[validator validateUserInterfaceItem:item]];
shouldBeEnabled = [validator validateUserInterfaceItem:item];
[item setEnabled:shouldBeEnabled];
}
[[_menuWindow _menuView] tile];
@@ -843,6 +855,9 @@ var _CPMenuBarVisible = NO,
+ (void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView withFont:(CPFont)aFont
{
// This is needed when we are making several rights click
[[_CPMenuManager sharedMenuManager] cancelActiveMenu];
[aMenu _menuWillOpen];
if (!aFont)
@@ -851,8 +866,6 @@ var _CPMenuBarVisible = NO,
var theWindow = [aView window],
menuWindow = [_CPMenuWindow menuWindowWithMenu:aMenu font:aFont];
[_CPMenuWindow poolMenuWindow:menuWindow];
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];
var constraintRect = [CPMenu _constraintRectForView:aView],
@@ -1048,7 +1061,7 @@ var _CPMenuBarVisible = NO,
Sends the action of the menu item at the specified index.
@param anIndex the index of the item
*/
- (void)performActionForItemAtIndex:(unsigned)anIndex
- (void)performActionForItemAtIndex:(CPUInteger)anIndex
{
var item = _items[anIndex];
@@ -1151,6 +1164,7 @@ var _CPMenuBarVisible = NO,
return;
[aMenuItem setMenu:self];
[self _highlightItemAtIndex:CPNotFound];
[_items insertObject:aMenuItem atIndex:anIndex];
[[CPNotificationCenter defaultCenter]
@@ -1165,6 +1179,7 @@ var _CPMenuBarVisible = NO,
return;
[[_items objectAtIndex:anIndex] setMenu:nil];
[self _highlightItemAtIndex:CPNotFound];
[_items removeObjectAtIndex:anIndex];
[[CPNotificationCenter defaultCenter]
@@ -1178,7 +1193,8 @@ var _CPMenuBarVisible = NO,
var CPMenuTitleKey = @"CPMenuTitleKey",
CPMenuNameKey = @"CPMenuNameKey",
CPMenuItemsKey = @"CPMenuItemsKey",
CPMenuShowsStateColumnKey = @"CPMenuShowsStateColumnKey";
CPMenuShowsStateColumnKey = @"CPMenuShowsStateColumnKey",
CPMenuAutoEnablesItemsKey = @"CPMenuAutoEnablesItemsKey";
@implementation CPMenu (CPCoding)
@@ -1200,7 +1216,7 @@ var CPMenuTitleKey = @"CPMenuTitleKey",
_showsStateColumn = ![aCoder containsValueForKey:CPMenuShowsStateColumnKey] || [aCoder decodeBoolForKey:CPMenuShowsStateColumnKey];
_autoenablesItems = YES;
_autoenablesItems = ![aCoder containsValueForKey:CPMenuAutoEnablesItemsKey] || [aCoder decodeBoolForKey:CPMenuAutoEnablesItemsKey];
[self setMinimumWidth:0];
}
@@ -1223,6 +1239,9 @@ var CPMenuTitleKey = @"CPMenuTitleKey",
if (!_showsStateColumn)
[aCoder encodeBool:_showsStateColumn forKey:CPMenuShowsStateColumnKey];
if (!_autoenablesItems)
[aCoder encodeBool:_autoenablesItems forKey:CPMenuAutoEnablesItemsKey];
}
@end
+9
View File
@@ -407,6 +407,15 @@ var STICKY_TIME_INTERVAL = 0.4,
[menu cancelTracking];
}
- (void)cancelActiveMenu
{
if (CPApp._activeMenu)
{
[self completeTracking];
_menuContainerStack = [];
}
}
- (void)completeTracking
{
var trackingMenu = [self trackingMenu];
+3 -2
View File
@@ -72,7 +72,8 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
+ (void)poolMenuWindow:(_CPMenuWindow)aMenuWindow
{
if (!aMenuWindow || _CPMenuWindowPool.length >= _CPMenuWindowPoolCapacity)
// FIXME :the poolMenuWindow is called too many times somewhere....
if (!aMenuWindow || _CPMenuWindowPool.length >= _CPMenuWindowPoolCapacity || [_CPMenuWindowPool containsObject:aMenuWindow])
return;
_CPMenuWindowPool.push(aMenuWindow);
@@ -434,7 +435,7 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
return "menu-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"menu-window-more-above-image": [CPNull null],
+3
View File
@@ -166,6 +166,9 @@ var CPMenuItemStringRepresentationDictionary = @{
if (_isEnabled === isEnabled)
return;
if (!isEnabled && [self isHighlighted])
[_menu _highlightItemAtIndex:CPNotFound];
_isEnabled = !!isEnabled;
[_menuItemView setDirty];
+5 -5
View File
@@ -49,7 +49,7 @@
return "menu-item-bar-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"horizontal-margin": 9.0,
@@ -84,25 +84,25 @@
return self;
}
- (CPColor)setTextColor:(CPColor)aColor
- (void)setTextColor:(CPColor)aColor
{
_textColor = aColor;
[self setNeedsLayout];
}
- (CPColor)setTextShadowColor:(CPColor)aColor
- (void)setTextShadowColor:(CPColor)aColor
{
_textShadowColor = aColor;
[self setNeedsLayout];
}
- (CPColor)setHighlightTextColor:(CPColor)aColor
- (void)setHighlightTextColor:(CPColor)aColor
{
_highlightTextColor = aColor;
[self setNeedsLayout];
}
- (CPColor)setHighlightTextShadowColor:(CPColor)aColor
- (void)setHighlightTextShadowColor:(CPColor)aColor
{
_highlightTextShadowColor = aColor;
[self setNeedsLayout];
+6 -1
View File
@@ -45,7 +45,7 @@
return "menu-item-standard-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"submenu-indicator-color": [CPNull null],
@@ -336,6 +336,11 @@
}
}
- (BOOL)isHighlighted
{
return _highlighted;
}
@end
@implementation _CPMenuItemSubmenuIndicatorView : CPView
+2 -3
View File
@@ -34,7 +34,7 @@
@implementation _CPMenuItemView : CPView
{
CPMenuItem _menuItem;
CPView _view;
CPView _view @accessors(property=view, readonly);
CPFont _font;
CPColor _textColor;
@@ -53,7 +53,7 @@
return "menu-item-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{};
}
@@ -112,7 +112,6 @@
_view = menuItemView;
}
}
else if ([_menuItem menu] == [CPApp mainMenu])
{
if (![_view isKindOfClass:[_CPMenuItemMenuBarView class]])
+5 -5
View File
@@ -51,7 +51,7 @@
CPCountedSet _observedKeys;
}
+ (id)initialize
+ (void)initialize
{
if (self !== [CPObjectController class])
return;
@@ -572,7 +572,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
}
}
- (void)insertObject:(id)anObject atIndex:(unsigned)anIndex
- (void)insertObject:(id)anObject atIndex:(CPUInteger)anIndex
{
for (var i = 0, count = [_observationProxies count]; i < count; i++)
{
@@ -592,7 +592,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
[super insertObject:anObject atIndex:anIndex];
}
- (void)removeObjectAtIndex:(unsigned)anIndex
- (void)removeObjectAtIndex:(CPUInteger)anIndex
{
var currentObject = [self objectAtIndex:anIndex];
@@ -614,7 +614,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
[super removeObjectAtIndex:anIndex];
}
- (_CPObservableArray)objectsAtIndexes:(CPIndexSet)theIndexes
- (CPArray)objectsAtIndexes:(CPIndexSet)theIndexes
{
return [_CPObservableArray arrayWithArray:[super objectsAtIndexes:theIndexes]];
}
@@ -629,7 +629,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
[self removeObjectAtIndex:[self count]];
}
- (void)replaceObjectAtIndex:(unsigned)anIndex withObject:(id)anObject
- (void)replaceObjectAtIndex:(CPUInteger)anIndex withObject:(id)anObject
{
var currentObject = [self objectAtIndex:anIndex];
+158 -46
View File
@@ -88,6 +88,57 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
#define SHOULD_SELECT_ITEM(anOutlineView, anItem) (!((anOutlineView)._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldSelectItem_) || [(anOutlineView)._outlineViewDelegate outlineView:(anOutlineView) shouldSelectItem:(anItem)])
@protocol CPOutlineViewDelegate <CPObject>
@optional
- (BOOL)outlineView:(CPOutlineView)anOutlineView isGroupItem:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldCollapseItem:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldEditTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldExpandItem:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldReorderColumn:(CPInteger)columnIndex toColumn:(CPInteger)newColumnIndex;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldSelectItem:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldSelectTableColumn:(CPTableColumn)aTableColumn;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldShowOutlineDisclosureControlForItem:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldShowViewExpansionForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldTrackView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldTypeSelectForEvent:(CPEvent)anEvent withCurrentSearchString:(CPString)searchString;
- (BOOL)selectionShouldChangeInOutlineView:(CPOutlineView)anOutlineView;
- (CPIndexSet)outlineView:(CPOutlineView)anOutlineView selectionIndexesForProposedSelection:(CPIndexSet)proposedSelectionIndexes;
- (CPMenu)outlineView:(CPOutlineView)anOutlineView menuForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (CPString)outlineView:(CPOutlineView)anOutlineView toolTipForView:(CPView)aView rect:(CGRect)aRect tableColumn:(CPTableColumn)aTableColumn item:(id)anItem mouseLocation:(CGPoint)mouseLocation;
- (CPString)outlineView:(CPOutlineView)anOutlineView typeSelectStringForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (CPView)outlineView:(CPOutlineView)anOutlineView dataViewForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (CPView)outlineView:(CPOutlineView)anOutlineView viewForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (float)outlineView:(CPOutlineView)anOutlineView heightOfRowByItem:(id)anItem;
- (float)outlineView:(CPOutlineView)anOutlineView sizeToFitWidthOfColumn:(CPTableColumn)aTableColumn;
- (id)outlineView:(CPOutlineView)anOutlineView nextTypeSelectMatchFromItem:(id)startItem toItem:(id)endItem forString:(CPString)searchString;
- (void)outlineView:(CPOutlineView)anOutlineView didClickTableColumn:(CPTableColumn)aTableColumn;
- (void)outlineView:(CPOutlineView)anOutlineView didDragTableColumn:(CPTableColumn)aTableColumn;
- (void)outlineView:(CPOutlineView)anOutlineView mouseDownInHeaderOfTableColumn:(CPTableColumn)aTableColumn;
- (void)outlineView:(CPOutlineView)anOutlineView willDisplayOutlineView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
- (void)outlineView:(CPOutlineView)anOutlineView willDisplayView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
@end
@protocol CPOutlineViewDataSource <CPObject>
@optional
- (BOOL)outlineView:(CPOutlineView)anOutlineView acceptDrop:(id /*<CPDraggingInfo>*/)info item:(id)anItem childIndex:(CPInteger)anIndex;
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldDeferDisplayingChildrenOfItem:(id)anItem;
- (BOOL)outlineView:(CPOutlineView)anOutlineView writeItems:(CPArray)items toPasteboard:(CPPasteboard)pboard;
- (CPArray)outlineView:(CPOutlineView)anOutlineView namesOfPromisedFilesDroppedAtDestination:(CPURL)dropDestination forDraggedItems:(CPArray)items;
- (CPDragOperation)outlineView:(CPOutlineView)anOutlineView validateDrop:(id /*<CPDraggingInfo>*/)info proposedItem:(id)anItem proposedChildIndex:(CPInteger)anIndex;
- (CPDragOperation)outlineView:(CPOutlineView)anOutlineView validateDrop:(id /*<CPDraggingInfo>*/)info proposedRow:(int)theRow proposedDropOperation:(CPTableViewDropOperation)theOperation;
- (id)outlineView:(CPOutlineView)anOutlineView itemForPersistentObject:(id)anObject;
- (id)outlineView:(CPOutlineView)anOutlineView objectValueforTableColumn:(CPTableColumn)aTableColumn byItem:(id)anItem;
- (id)outlineView:(CPOutlineView)anOutlineView persistentObjectForItem:(id)anItem;
- (void)outlineView:(CPOutlineView)anOutlineView setObjectValue:(id)anObject forTableColumn:(CPTableColumn)aTableColumn byItem:(id)anItem;
- (void)outlineView:(CPOutlineView)anOutlineView sortDescriptorsDidChange:(CPArray)oldDescriptors;
@end
/*!
@ingroup appkit
@class CPOutlineView
@@ -105,34 +156,34 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
*/
@implementation CPOutlineView : CPTableView
{
id _outlineViewDataSource;
id _outlineViewDelegate;
CPTableColumn _outlineTableColumn;
id <CPOutlineViewDataSource> _outlineViewDataSource;
id <CPOutlineViewDelegate> _outlineViewDelegate;
CPTableColumn _outlineTableColumn;
float _indentationPerLevel;
BOOL _indentationMarkerFollowsDataView;
float _indentationPerLevel;
BOOL _indentationMarkerFollowsDataView;
CPInteger _implementedOutlineViewDataSourceMethods;
CPInteger _implementedOutlineViewDelegateMethods;
CPInteger _implementedOutlineViewDataSourceMethods;
CPInteger _implementedOutlineViewDelegateMethods;
Object _rootItemInfo;
CPMutableArray _itemsForRows;
Object _itemInfosForItems;
Object _rootItemInfo;
CPMutableArray _itemsForRows;
Object _itemInfosForItems;
CPControl _disclosureControlPrototype;
CPArray _disclosureControlsForRows;
CPData _disclosureControlData;
CPArray _disclosureControlQueue;
CPControl _disclosureControlPrototype;
CPArray _disclosureControlsForRows;
CPData _disclosureControlData;
CPArray _disclosureControlQueue;
BOOL _shouldRetargetItem;
id _retargetedItem;
BOOL _shouldRetargetItem;
id _retargetedItem;
BOOL _shouldRetargetChildIndex;
CPInteger _retargedChildIndex;
CPTimer _dragHoverTimer;
id _dropItem;
BOOL _shouldRetargetChildIndex;
CPInteger _retargedChildIndex;
CPTimer _dragHoverTimer;
id _dropItem;
BOOL _coalesceSelectionNotificationState;
BOOL _coalesceSelectionNotificationState;
}
- (id)initWithFrame:(CGRect)aFrame
@@ -218,7 +269,7 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
If you want the drag to begin you should return YES and place the drag data on the pboard.
@code - (BOOL)outlineView:(CPOutlineView)outlineView writeItems:(CPArray)items toPasteboard:(CPPasteboard)pboard; @endcode
*/
- (void)setDataSource:(id)aDataSource
- (void)setDataSource:(id <CPOutlineViewDataSource>)aDataSource
{
if (_outlineViewDataSource === aDataSource)
return;
@@ -352,6 +403,10 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
*/
- (void)expandItem:(id)anItem expandChildren:(BOOL)shouldExpandChildren
{
if ([self _delegateRespondsToShouldExpandItem])
if ([_outlineViewDelegate outlineView:self shouldExpandItem:anItem] == NO)
return;
var itemInfo = null;
if (!anItem)
@@ -427,6 +482,10 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
if (!anItem)
return;
if ([self _delegateRespondsToShouldCollapseItem])
if ([_outlineViewDelegate outlineView:self shouldCollapseItem:anItem] == NO)
return;
var itemInfo = _itemInfosForItems[[anItem UID]];
if (!itemInfo)
@@ -721,16 +780,25 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
/*!
@ignore
Select or deselect rows, this is overridden because we need to change the color or the outline control.
Select or deselect rows, this is overridden because we need to change the color of the outline control.
*/
- (void)_performSelection:(BOOL)select forRow:(CPInteger)rowIndex context:(id)context
- (void)_setSelectedRowIndexes:(CPIndexSet)rows
{
[super _performSelection:select forRow:rowIndex context:context];
if (_disclosureControlsForRows.length)
{
var indexes = [_selectedRowIndexes copy];
[indexes removeIndexesInRange:CPMakeRange(_disclosureControlsForRows.length, _itemsForRows.length - _disclosureControlsForRows.length)];
[[_disclosureControlsForRows objectsAtIndexes:indexes] makeObjectsPerformSelector:@selector(unsetThemeState:) withObject:CPThemeStateSelected];
}
var control = _disclosureControlsForRows[rowIndex],
selector = select ? @"setThemeState:" : @"unsetThemeState:";
[super _setSelectedRowIndexes:rows];
[control performSelector:CPSelectorFromString(selector) withObject:CPThemeStateSelected];
if (_disclosureControlsForRows.length)
{
var indexes = [_selectedRowIndexes copy];
[indexes removeIndexesInRange:CPMakeRange(_disclosureControlsForRows.length, _itemsForRows.length - _disclosureControlsForRows.length)];
[[_disclosureControlsForRows objectsAtIndexes:indexes] makeObjectsPerformSelector:@selector(setThemeState:) withObject:CPThemeStateSelected];
}
}
/*!
@@ -809,7 +877,7 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
@code - (int)outlineView:(CPOutlineView)outlineView heightOfRowByItem:(id)anItem; @endcode
*/
- (void)setDelegate:(id)aDelegate
- (void)setDelegate:(id <CPOutlineViewDelegate>)aDelegate
{
if (_outlineViewDelegate === aDelegate)
return;
@@ -1061,7 +1129,7 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
@ignore
We need to offset the dataview and add the disclosure triangle.
*/
- (CPView)_dragViewForColumn:(int)theColumnIndex event:(CPEvent)theDragEvent offset:(CGPoint)theDragViewOffset
- (CPView)_dragViewForColumn:(CPInteger)theColumnIndex event:(CPEvent)theDragEvent offset:(CGPoint)theDragViewOffset
{
var dragView = [[_CPColumnDragView alloc] initWithLineColor:[self gridColor]],
tableColumn = [[self tableColumns] objectAtIndex:theColumnIndex],
@@ -1194,7 +1262,7 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
/*!
@ignore
*/
- (id)_parentItemForUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex atMouseOffset:(CGPoint)theOffset
- (id)_parentItemForUpperRow:(CPInteger)theUpperRowIndex andLowerRow:(CPInteger)theLowerRowIndex atMouseOffset:(CGPoint)theOffset
{
if (_shouldRetargetItem)
return _retargetedItem;
@@ -1224,7 +1292,7 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
/*!
@ignore
*/
- (CGRect)_rectForDropHighlightViewBetweenUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex offset:(CGPoint)theOffset
- (CGRect)_rectForDropHighlightViewBetweenUpperRow:(CPInteger)theUpperRowIndex andLowerRow:(CPInteger)theLowerRowIndex offset:(CGPoint)theOffset
{
// Call super and the update x to reflect the current indentation level
var rect = [super _rectForDropHighlightViewBetweenUpperRow:theUpperRowIndex andLowerRow:theLowerRowIndex offset:theOffset],
@@ -1540,12 +1608,12 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
[super keyDown:anEvent];
}
- (CPView)_viewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
- (CPView)_sendDelegateViewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
{
return [_outlineViewDelegate outlineView:self viewForTableColumn:aTableColumn item:[self itemAtRow:aRow]];
}
- (CPView)_dataViewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
- (CPView)_sendDelegateDataViewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
{
return [_outlineViewDelegate outlineView:self dataViewForTableColumn:aTableColumn item:[self itemAtRow:aRow]];
}
@@ -1565,6 +1633,34 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_;
}
- (BOOL)_delegateRespondsToShouldExpandItem
{
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldExpandItem_;
}
- (BOOL)_delegateRespondsToShouldCollapseItem
{
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldCollapseItem_;
}
/*!
@ignore
Return YES if the delegate implements outlineView:selectionIndexesForProposedSelection
*/
- (BOOL)_delegateRespondsToSelectionIndexesForProposedSelection
{
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_selectionIndexesForProposedSelection_;
}
/*!
@ignore
Return YES if the delegate implements outlineView:shouldSelectItem:
*/
- (BOOL)_delegateRespondsToShouldSelectRow
{
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldSelectItem_;
}
@end
// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever...
@@ -1762,7 +1858,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return [_outlineView._outlineViewDataSource outlineView:_outlineView writeItems:items toPasteboard:thePasteboard];
}
- (int)_childIndexForDropOperation:(CPTableViewDropOperation)theDropOperation row:(int)theRow offset:(CGPoint)theOffset
- (int)_childIndexForDropOperation:(CPTableViewDropOperation)theDropOperation row:(CPInteger)theRow offset:(CGPoint)theOffset
{
if (_outlineView._shouldRetargetChildIndex)
return _outlineView._retargedChildIndex;
@@ -1786,7 +1882,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return childIndex;
}
- (void)_parentItemForDropOperation:(CPTableViewDropOperation)theDropOperation row:(int)theRow offset:(CGPoint)theOffset
- (void)_parentItemForDropOperation:(CPTableViewDropOperation)theDropOperation row:(CPInteger)theRow offset:(CGPoint)theOffset
{
if (theDropOperation === CPTableViewDropAbove)
return [_outlineView _parentItemForUpperRow:theRow - 1 andLowerRow:theRow atMouseOffset:theOffset]
@@ -1794,8 +1890,8 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return [_outlineView itemAtRow:theRow];
}
- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id < CPDraggingInfo >)theInfo
proposedRow:(int)theRow proposedDropOperation:(CPTableViewDropOperation)theOperation
- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id /*< CPDraggingInfo >*/)theInfo
proposedRow:(CPInteger)theRow proposedDropOperation:(CPTableViewDropOperation)theOperation
{
if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_validateDrop_proposedItem_proposedChildIndex_))
return CPDragOperationNone;
@@ -1814,7 +1910,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return [_outlineView._outlineViewDataSource outlineView:_outlineView validateDrop:theInfo proposedItem:parentItem proposedChildIndex:childIndex];
}
- (BOOL)tableView:(CPTableView)aTableView acceptDrop:(id <CPDraggingInfo>)theInfo row:(int)theRow dropOperation:(CPTableViewDropOperation)theOperation
- (BOOL)tableView:(CPTableView)aTableView acceptDrop:(id /*<CPDraggingInfo>*/)theInfo row:(CPInteger)theRow dropOperation:(CPTableViewDropOperation)theOperation
{
if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_acceptDrop_item_childIndex_))
return NO;
@@ -1858,7 +1954,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return self;
}
- (BOOL)tableView:(CPTableView)theTableView shouldSelectRow:(int)theRow
- (BOOL)tableView:(CPTableView)theTableView shouldSelectRow:(CPInteger)theRow
{
return SHOULD_SELECT_ITEM(_outlineView, [_outlineView itemAtRow:theRow]);
}
@@ -1868,7 +1964,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return SELECTION_SHOULD_CHANGE(_outlineView);
}
- (BOOL)tableView:(CPTableView)aTableView shouldEditTableColumn:(CPTableColumn)aColumn row:(int)aRow
- (BOOL)tableView:(CPTableView)aTableView shouldEditTableColumn:(CPTableColumn)aColumn row:(CPInteger)aRow
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldEditTableColumn_item_))
return [_outlineView._outlineViewDelegate outlineView:_outlineView shouldEditTableColumn:aColumn item:[_outlineView itemAtRow:aRow]];
@@ -1876,7 +1972,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return NO;
}
- (float)tableView:(CPTableView)theTableView heightOfRow:(int)theRow
- (float)tableView:(CPTableView)theTableView heightOfRow:(CPInteger)theRow
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_heightOfRowByItem_))
return [_outlineView._outlineViewDelegate outlineView:_outlineView heightOfRowByItem:[_outlineView itemAtRow:theRow]];
@@ -1884,7 +1980,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return [theTableView rowHeight];
}
- (void)tableView:(CPTableView)aTableView willDisplayView:(id)aView forTableColumn:(CPTableColumn)aTableColumn row:(int)aRowIndex
- (void)tableView:(CPTableView)aTableView willDisplayView:(id)aView forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_willDisplayView_forTableColumn_item_))
{
@@ -1893,7 +1989,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
}
}
- (BOOL)tableView:(CPTableView)aTableView isGroupRow:(int)aRow
- (BOOL)tableView:(CPTableView)aTableView isGroupRow:(CPInteger)aRow
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_isGroupItem_))
return [_outlineView._outlineViewDelegate outlineView:_outlineView isGroupItem:[_outlineView itemAtRow:aRow]];
@@ -1901,7 +1997,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return NO;
}
- (CPMenu)tableView:(CPTableView)aTableView menuForTableColumn:(CPTableColumn)aTableColumn row:(int)aRow
- (CPMenu)tableView:(CPTableView)aTableView menuForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_menuForTableColumn_item_))
{
@@ -1914,6 +2010,22 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return [_outlineView menu] || [[_outlineView class] defaultMenu];
}
- (CPIndexSet)tableView:(CPTableView)aTableView selectionIndexesForProposedSelection:(CPIndexSet)anIndexSet
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_selectionIndexesForProposedSelection_))
return [_outlineView._outlineViewDelegate outlineView:_outlineView selectionIndexesForProposedSelection:anIndexSet];
return anIndexSet;
}
- (BOOL)tableView:(CPTableView)aTableView shouldSelectTableColumn:(CPTableColumn)aTableColumn
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldSelectTableColumn_))
return [_outlineView._outlineViewDelegate outlineView:_outlineView shouldSelectTableColumn:aTableColumn];
return YES;
}
@end
@implementation CPDisclosureButton : CPButton
@@ -1931,7 +2043,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
return self;
}
- (void)setState:(CPState)aState
- (void)setState:(CPInteger)aState
{
[super setState:aState];
+11 -4
View File
@@ -191,10 +191,12 @@ var CPPasteboards = nil,
_owners = @{};
_provided = @{};
var count = _types.length;
while (count--)
[_owners setObject:anOwner forKey:_types[count]];
if (anOwner)
{
var count = _types.length;
while (count--)
[_owners setObject:anOwner forKey:_types[count]];
}
if (_nativePasteboard && shouldUpdate)
{
@@ -205,6 +207,7 @@ var CPPasteboards = nil,
_nativePasteboard.declareTypes_(nativeTypes);
_changeCount = _nativePasteboard.changeCount();
}
return ++_changeCount;
}
@@ -243,6 +246,10 @@ var CPPasteboards = nil,
*/
- (void)setString:(CPString)aString forType:(CPString)aType
{
// Putting a non-string on the string pasteboard can lead to strange crashes.
if (aString && aString.isa && ![aString isKindOfClass:CPString])
[CPException raise:CPInvalidArgumentException reason:"CPPasteboard setString:forType: must be called with a string."];
[self setPropertyList:aString forType:aType];
}
+5 -5
View File
@@ -279,7 +279,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
Selects the item at the specified index
@param anIndex the index of the item to select
*/
- (void)setObjectValue:(int)anIndex
- (void)setObjectValue:(id)anIndex
{
var indexOfSelectedItem = [self objectValue];
@@ -344,7 +344,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
Returns the item at the specified index or \c nil if the item does not exist.
@param anIndex the index of the item to obtain
*/
- (CPMenuItem)itemAtIndex:(unsigned)anIndex
- (CPMenuItem)itemAtIndex:(CPUInteger)anIndex
{
return [[self menu] itemAtIndex:anIndex];
}
@@ -353,7 +353,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
Returns the title of the item at the specified index or \c nil if no item exists.
@param anIndex the index of the item
*/
- (CPString)itemTitleAtIndex:(unsigned)anIndex
- (CPString)itemTitleAtIndex:(CPUInteger)anIndex
{
return [[[self menu] itemAtIndex:anIndex] title];
}
@@ -838,7 +838,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
[self _setContentValuesIfNeeded:contentArray];
}
- (void)valueForBinding:(CPString)aBinding
- (id)valueForBinding:(CPString)aBinding
{
return [self _content];
}
@@ -910,7 +910,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
{
}
- (void)setValue:(id)aValue forBinding:(CPString)aBinding
- (void)setValue:(CPArray)aValue forBinding:(CPString)aBinding
{
[super _setContent:aValue];
}
+1
View File
@@ -238,6 +238,7 @@ Set the behavior of the CPPopover. It can be:
_popoverWindow = [[_CPPopoverWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:[self styleMaskForBehavior]];
}
[_popoverWindow setPlatformWindow:[[positioningView window] platformWindow]];
[_popoverWindow setAppearance:_appearance];
[_popoverWindow setAnimates:_animates];
[_popoverWindow setDelegate:self];
+1 -1
View File
@@ -152,7 +152,7 @@ CPRadioImageOffset = 4.0;
[_radioGroup _setSelectedRadio:self];
}
- (void)sendAction:(SEL)anAction to:(id)anObject
- (BOOL)sendAction:(SEL)anAction to:(id)anObject
{
[super sendAction:anAction to:anObject];
+1 -1
View File
@@ -356,7 +356,7 @@ CPDeleteForwardKeyCode = 46;
var CPResponderNextResponderKey = @"CPResponderNextResponderKey",
CPResponderMenuKey = @"CPResponderMenuKey";
@implementation CPResponder (CPCoding)
@implementation CPResponder (CPCoding) <CPCoding>
/*!
Initializes the responder with data from a coder.
+5 -5
View File
@@ -484,7 +484,7 @@
#pragma mark RuleEditor delegate methods
- (int)_queryNumberOfChildrenOfItem:(id)rowItem withRowType:(int)type
- (int)_queryNumberOfChildrenOfItem:(id)rowItem withRowType:(CPRuleEditorRowType)type
{
if (rowItem == nil)
{
@@ -494,7 +494,7 @@
return [[rowItem children] count];
}
- (id)_queryChild:(int)childIndex ofItem:(id)rowItem withRowType:(int)type
- (id)_queryChild:(int)childIndex ofItem:(id)rowItem withRowType:(CPRuleEditorRowType)type
{
if (rowItem == nil)
{
@@ -505,7 +505,7 @@
return [[rowItem children] objectAtIndex:childIndex];
}
- (id)_queryValueForItem:(id)rowItem inRow:(int)rowIndex
- (id)_queryValueForItem:(id)rowItem inRow:(CPInteger)rowIndex
{
return [rowItem displayValue];
}
@@ -516,7 +516,7 @@ var CPPredicateTemplatesKey = @"CPPredicateTemplates";
@implementation CPPredicateEditor (CPCoding)
- (id)initWithCoder:(id)aCoder
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
@@ -531,7 +531,7 @@ var CPPredicateTemplatesKey = @"CPPredicateTemplates";
return self;
}
- (void)encodeWithCoder:(id)aCoder
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_allTemplates forKey:CPPredicateTemplatesKey];
@@ -27,8 +27,7 @@
@import "CPMenuItem.j"
@import "CPTextField.j"
// NOTE: CPDatePicker is not implemented yet
@class CPDatePicker
@import "CPDatePicker.j"
CPUndefinedAttributeType = 0;
@@ -488,7 +487,36 @@ CPTransformableAttributeType = 1800;
- (id)copy
{
return [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:self]];
var views = [CPArray array];
var copy = [[[self class] alloc] init];
[copy _setTemplateType:_templateType];
[copy _setOptions:_predicateOptions];
[copy _setModifier:_predicateModifier];
[copy _setLeftAttributeType:_leftAttributeType];
[copy _setRightAttributeType:_rightAttributeType];
[copy setLeftIsWildcard:_leftIsWildcard];
[copy setRightIsWildcard:_rightIsWildcard];
[_views enumerateObjectsUsingBlock:function(aView, idx, stop)
{
var vcopy;
if ([aView implementsSelector:@selector(copy)])
{
vcopy = [aView copy];
}
else
{
vcopy = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:aView]];
}
[views addObject:vcopy];
}];
[copy setTemplateViews:views];
return copy;
}
+ (id)_operatorsForAttributeType:(CPAttributeType)attributeType
@@ -680,7 +708,7 @@ CPTransformableAttributeType = 1800;
view = [[CPCheckBox alloc] initWithFrame:CGRectMake(0, 0, 50, 26)];
}
else if (attributeType == CPDateAttributeType)
view = [[CPDatePicker alloc] initWithFrame:CGRectMake(0, 0, 150, 26)];
view = [[CPDatePicker alloc] initWithFrame:CGRectMake(0, 0, 180, 26)];
else
return nil;
@@ -702,12 +730,12 @@ CPTransformableAttributeType = 1800;
return textField;
}
- (void)_setOptions:(unsigned int)options
- (void)_setOptions:(unsigned)options
{
_predicateOptions = options;
}
- (void)_setModifier:(unsigned int)modifier
- (void)_setModifier:(unsigned)modifier
{
_predicateModifier = modifier;
}
@@ -797,5 +825,31 @@ var CPPredicateTemplateTypeKey = @"CPPredicateTemplateType",
[coder encodeObject:_views forKey:CPPredicateTemplateViewsKey];
}
@end
// Copy support for built-in types
@implementation CPDatePicker (CPCopying)
- (id)copy
{
var ret = [[[self class] alloc] initWithFrame:[self frame]];
[ret setTextFont:[self textFont]];
[ret setMinDate:[self minDate]];
[ret setMaxDate:[self maxDate]];
[ret setTimeInterval:[self timeInterval]];
[ret setDatePickerMode:[self datePickerMode]];
[ret setDatePickerElements:[self datePickerElements]];
[ret setDatePickerStyle:[self datePickerStyle]];
[ret setLocale:[self locale]];
[ret setDateValue:[self dateValue]];
[ret setBackgroundColor:[self backgroundColor]];
[ret setDrawsBackground:[self drawsBackground]];
[ret setBordered:[self isBordered]];
[ret _init];
return ret;
}
@end
/*! @endcond */
+27 -27
View File
@@ -122,7 +122,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
return @"rule-editor";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"alternating-row-colors": [CPNull null],
@@ -461,7 +461,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
@param row The index of a row in the receiver.
@return The currently chosen items for row @a row.
*/
- (id)criteriaForRow:(int)row
- (id)criteriaForRow:(CPInteger)row
{
var rowcache = [self _rowCacheForIndex:row];
if (rowcache)
@@ -480,7 +480,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
@return The chosen values (strings, views, or menu items) for row row.
@discussion The values returned are the same as those returned from the delegate method -#ruleEditor:displayValueForCriterion:inRow:
*/
- (CPMutableArray)displayValuesForRow:(int)row
- (CPMutableArray)displayValuesForRow:(CPInteger)row
{
var rowcache = [self _rowCacheForIndex:row];
if (rowcache)
@@ -503,7 +503,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
@param rowIndex The index of a row in the receiver.
@return The index of the parent of the row at @a rowIndex. If the row at @a rowIndex is a root row, returns @c -1.
*/
- (int)parentRowForRow:(int)rowIndex
- (int)parentRowForRow:(CPInteger)rowIndex
{
if (rowIndex < 0 || rowIndex >= [self numberOfRows])
[CPException raise:CPRangeException reason:_cmd + @" row " + rowIndex + " is out of range"];
@@ -544,7 +544,7 @@ TODO: implement
@return The type of the row at @a rowIndex.
@warning Raises a @c CPRangeException if rowIndex is less than @c 0 or greater than or equal to the number of rows.
*/
- (CPRuleEditorRowType)rowTypeForRow:(int)rowIndex
- (CPRuleEditorRowType)rowTypeForRow:(CPInteger)rowIndex
{
if (rowIndex < 0 || rowIndex > [self numberOfRows])
[CPException raise:CPRangeException reason:_cmd + @"row " + rowIndex + " is out of range"];
@@ -565,7 +565,7 @@ TODO: implement
@return The immediate subrows of the row at @a rowIndex.
@discussion Rows are numbered starting at @c 0.
*/
- (CPIndexSet)subrowIndexesForRow:(int)rowIndex
- (CPIndexSet)subrowIndexesForRow:(CPInteger)rowIndex
{
var object;
@@ -691,7 +691,7 @@ TODO: implement
@note Currently, @a shouldAnimate has no effect, rows are always animated when calling this method.
@see addRow:
*/
- (void)insertRowAtIndex:(int)rowIndex withType:(unsigned int)rowType asSubrowOfRow:(int)parentRow animate:(BOOL)shouldAnimate
- (void)insertRowAtIndex:(int)rowIndex withType:(unsigned int)rowType asSubrowOfRow:(CPInteger)parentRow animate:(BOOL)shouldAnimate
{
/*
TODO: raise exceptions if parentRow is greater than or equal to rowIndex, or if rowIndex would fall amongst the children of some other parent, or if the nesting mode forbids this configuration.
@@ -1313,7 +1313,7 @@ TODO: implement
return [_boundArrayOwner mutableArrayValueForKey:_boundArrayKeyPath];
}
- (BOOL)_nextUnusedItems:(CPArray)items andValues:(CPArray)values forRow:(int)rowIndex forRowType:(unsigned int)type
- (BOOL)_nextUnusedItems:(CPArray)items andValues:(CPArray)values forRow:(CPInteger)rowIndex forRowType:(unsigned int)type
{
var parentItem = [items lastObject], // if empty items array, this is NULL aka the root item;
childrenCount = [self _queryNumberOfChildrenOfItem:parentItem withRowType:type],
@@ -1375,7 +1375,7 @@ TODO: implement
return YES;
}
- (CPMutableArray)_getItemsAndValuesToAddForRow:(int)rowIndex ofType:(CPRuleEditorRowType)type
- (CPMutableArray)_getItemsAndValuesToAddForRow:(CPInteger)rowIndex ofType:(CPRuleEditorRowType)type
{
//var cachedItemsAndValues = _itemsAndValuesToAddForRowType[type];
//if (cachedItemsAndValues)
@@ -1418,7 +1418,7 @@ TODO: implement
[self insertRowAtIndex:insertIndex withType:type asSubrowOfRow:parentRowIndex animate:YES];
}
- (id)_insertNewRowAtIndex:(int)insertIndex ofType:(CPRuleEditorRowType)rowtype withParentRow:(int)parentRowIndex
- (id)_insertNewRowAtIndex:(int)insertIndex ofType:(CPRuleEditorRowType)rowtype withParentRow:(CPInteger)parentRowIndex
{
var row = [[[self rowClass] alloc] init],
itemsandvalues = [self _getItemsAndValuesToAddForRow:insertIndex ofType:rowtype],
@@ -1520,7 +1520,7 @@ TODO: implement
}
}
- (void)_changedItem:(id)fromItem toItem:(id)toItem inRow:(int)aRow atCriteriaIndex:(int)fromItemIndex
- (void)_changedItem:(id)fromItem toItem:(id)toItem inRow:(CPInteger)aRow atCriteriaIndex:(int)fromItemIndex
{
var criteria = [self criteriaForRow:aRow],
displayValues = [self displayValuesForRow:aRow],
@@ -1684,7 +1684,7 @@ TODO: implement
[super bind:aBinding toObject:observableController withKeyPath:aKeyPath options:options];
}
- (void)unbind:(id)object
- (void)unbind:(CPString)object
{
_rowClass = [_CPRuleEditorRowObject class];
[super unbind:object];
@@ -2005,7 +2005,7 @@ TODO: implement
return [_ruleDelegate ruleEditor:self child:childIndex forCriterion:item withRowType:type];
}
- (id)_queryValueForItem:(id)item inRow:(int)row
- (id)_queryValueForItem:(id)item inRow:(CPInteger)row
{
return [_ruleDelegate ruleEditor:self displayValueForCriterion:item inRow:row];
}
@@ -2026,12 +2026,12 @@ TODO: implement
_alignmentGridWidth = width;
}
- (BOOL)_validateItem:(id)item value:(id)value inRow:(int)row
- (BOOL)_validateItem:(id)item value:(id)value inRow:(CPInteger)row
{
return [self _queryCanSelectItem:item displayValue:value inRow:row];
}
- (BOOL)_queryCanSelectItem:(id)item displayValue:(id)value inRow:(int)row
- (BOOL)_queryCanSelectItem:(id)item displayValue:(id)value inRow:(CPInteger)row
{
return YES;
}
@@ -2128,7 +2128,7 @@ TODO: implement
return YES;
}
- (CPDragOperation)draggingEntered:(id < CPDraggingInfo >)sender
- (CPDragOperation)draggingEntered:(id /*< CPDraggingInfo >*/)sender
{
if ([sender draggingSource] === self)
{
@@ -2158,7 +2158,7 @@ TODO: implement
_subviewIndexOfDropLine = CPNotFound;
}
- (CPDragOperation)draggingUpdated:(id <CPDraggingInfo>)sender
- (CPDragOperation)draggingUpdated:(id /*<CPDraggingInfo>*/)sender
{
var point = [self convertPoint:[sender draggingLocation] fromView:nil],
y = point.y + _sliceHeight / 2,
@@ -2195,12 +2195,12 @@ TODO: implement
return CPDragOperationMove;
}
- (BOOL)prepareForDragOperation:(id < CPDraggingInfo >)sender
- (BOOL)prepareForDragOperation:(id /*< CPDraggingInfo >*/)sender
{
return (_subviewIndexOfDropLine !== CPNotFound);
}
- (BOOL)performDragOperation:(id < CPDraggingInfo >)info
- (BOOL)performDragOperation:(id /*< CPDraggingInfo >*/)info
{
var aboveInsertIndexCount = 0,
object,
@@ -2262,7 +2262,7 @@ TODO: implement
{
}
- (void)_setWindow:(id)window
- (void)_setWindow:(CPWindow)window
{
[super _setWindow:window];
}
@@ -2279,7 +2279,7 @@ TODO: implement
- (void)_postRowCountChangedNotificationOfType:(CPString)notificationName indexes:indexes
{
var userInfo = @{ "indexes": indexes };
var userInfo = indexes === nil ? @{} : @{ "indexes": indexes };
[[CPNotificationCenter defaultCenter] postNotificationName:notificationName object:self userInfo:userInfo];
}
@@ -2325,7 +2325,7 @@ TODO: implement
return YES;
}
- (void)_getAllAvailableItems:(id)items values:(id)values asChildrenOfItem:(id)parentItem inRow:(int)aRow
- (void)_getAllAvailableItems:(id)items values:(id)values asChildrenOfItem:(id)parentItem inRow:(CPInteger)aRow
{
var type,
indexofCriterion,
@@ -2426,7 +2426,7 @@ var CPRuleEditorAlignmentGridWidthKey = @"CPRuleEditorAlignmentGridWidth",
return self;
}
- (void)encodeWithCoder:(id)coder
- (void)encodeWithCoder:(CPCoder)coder
{
[super encodeWithCoder:coder];
@@ -2481,7 +2481,7 @@ var CriteriaKey = @"criteria",
return "<" + [self className] + ">\nsubrows = " + [subrows description] + "\ncriteria = " + [criteria description] + "\ndisplayValues = " + [displayValues description];
}
- (id)initWithCoder:(id)coder
- (id)initWithCoder:(CPCoder)coder
{
self = [super init];
if (self !== nil)
@@ -2495,7 +2495,7 @@ var CriteriaKey = @"criteria",
return self;
}
- (void)encodeWithCoder:(id)coder
- (void)encodeWithCoder:(CPCoder)coder
{
[coder encodeObject:subrows forKey:SubrowsKey];
[coder encodeObject:criteria forKey:CriteriaKey];
@@ -2534,7 +2534,7 @@ var CPBoundArrayKey = @"CPBoundArray";
return self;
}
- (id)initWithCoder:(id)coder
- (id)initWithCoder:(CPCoder)coder
{
if (self = [super init])
boundArray = [coder decodeObjectForKey:CPBoundArrayKey];
@@ -2542,7 +2542,7 @@ var CPBoundArrayKey = @"CPBoundArray";
return self;
}
- (void)encodeWithCoder:(id)coder
- (void)encodeWithCoder:(CPCoder)coder
{
[coder encodeObject:boundArray forKey:CPBoundArrayKey];
}
@@ -86,7 +86,7 @@ else if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
return self;
}
- (id)hitTest:(CGPoint)point
- (CPView)hitTest:(CGPoint)point
{
if (!CGRectContainsPoint([self frame], point) || ![self sliceIsEditable])
return nil;
@@ -100,12 +100,12 @@ else if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
return ![superview isKindOfClass:[_CPRuleEditorViewSlice]] || [superview isEditable];
}
- (BOOL)trackMouse:(CPEvent)theEvent
- (void)trackMouse:(CPEvent)theEvent
{
if (![self sliceIsEditable])
return NO;
return;
return [super trackMouse:theEvent];
[super trackMouse:theEvent];
}
- (CGRect)contentRectForBounds:(CGRect)bounds
@@ -522,7 +522,7 @@ var CONTROL_HEIGHT = 16.,
return self;
}
- (id)hitTest:(CGPoint)point
- (CPView)hitTest:(CGPoint)point
{
if (!CGRectContainsPoint([self frame], point))
return nil;
+27 -17
View File
@@ -34,34 +34,44 @@
/*! @ignore */
var _isSystemUsingOverlayScrollers = function()
var _isBrowserUsingOverlayScrollers = function()
{
#if PLATFORM(DOM)
var inner = document.createElement('p'),
outer = document.createElement('div');
/*
Even if the system supports overlay (Lion) scrollers,
the browser (e.g. FireFox *cough*) may not.
inner.style.width = "100%";
inner.style.height = "200px";
To determine if the browser is using overlay scrollbars,
we put a <p> element inside a shorter <div> and set its
overflow to scroll. If the browser is using visible scrollers,
the outer div's clientWidth will less than the offsetWidth, because
clientWidth does not include scrollbars, whereas offsetWidth does.
So if clientWidth === offsetWidth, the scrollers must be overlay.
Even IE gets this right.
*/
var outer = document.createElement('div'),
inner = document.createElement('p');
// position it absolute so it doesn't affect existing DOM elements
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner);
outer.style.overflow = "scroll";
document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2)
w2 = outer.clientWidth;
inner.style.width = "100%";
inner.style.height = "200px";
outer.appendChild(inner);
document.body.removeChild (outer);
document.body.appendChild(outer);
return (w1 - w2 == 0);
var usingOverlayScrollers = outer.clientWidth === outer.offsetWidth;
document.body.removeChild(outer);
return usingOverlayScrollers;
#else
return NO;
#endif
@@ -130,8 +140,8 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
var globalValue = [[CPBundle mainBundle] objectForInfoDictionaryKey:@"CPScrollersGlobalStyle"];
if (globalValue == nil || globalValue == -1)
CPScrollerStyleGlobal = _isSystemUsingOverlayScrollers() ? CPScrollerStyleOverlay : CPScrollerStyleLegacy
if (globalValue === nil || globalValue === -1)
CPScrollerStyleGlobal = _isBrowserUsingOverlayScrollers() ? CPScrollerStyleOverlay : CPScrollerStyleLegacy
else
CPScrollerStyleGlobal = globalValue;
}
+2 -1
View File
@@ -108,7 +108,7 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
return "scroller";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"scroller-width": 7.0,
@@ -182,6 +182,7 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
_allowFadingOut = YES;
_isMouseOver = NO;
_style = CPScrollerStyleOverlay;
var paramAnimFadeOut = @{
CPViewAnimationTargetKey: self,
CPViewAnimationEffectKey: CPViewAnimationFadeOutEffect,
+1 -1
View File
@@ -458,7 +458,7 @@ var RECENT_SEARCH_PREFIX = @" ";
[self sendAction:[self action] to:[self target]];
}
- (void)sendAction:(SEL)anAction to:(id)anObject
- (BOOL)sendAction:(SEL)anAction to:(id)anObject
{
[super sendAction:anAction to:anObject];
+1 -1
View File
@@ -56,7 +56,7 @@ CPSegmentSwitchTrackingMomentary = 2;
return "segmented-control";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"alignment": CPCenterTextAlignment,
+1 -1
View File
@@ -47,7 +47,7 @@ CPThemeStateShadowViewHeavy = CPThemeState("shadowview-style-heavy");
return "shadow-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"bezel-color": [CPNull null],
+1 -1
View File
@@ -49,7 +49,7 @@ CPCircularSlider = 1;
return "slider";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"knob-color": [CPNull null],
+12 -10
View File
@@ -55,7 +55,6 @@
CPTextField _hexLabel;
CPTextField _hexValue;
CPTextField _hexValue;
CPTextField _redValue;
CPTextField _greenValue;
CPTextField _blueValue;
@@ -146,7 +145,7 @@
[_hueLabel setTextColor:[CPColor blackColor]];
_hueSlider = [[CPSlider alloc] initWithFrame:CGRectMake(15, 143, aFrame.size.width - 70, 20)];
[_hueSlider setMaxValue:359.0];
[_hueSlider setMaxValue:0.999];
[_hueSlider setMinValue:0.0];
[_hueSlider setTarget:self];
[_hueSlider setAction:@selector(sliderChanged:)];
@@ -165,7 +164,7 @@
[_saturationLabel setTextColor:[CPColor blackColor]];
_saturationSlider = [[CPSlider alloc] initWithFrame:CGRectMake(15, 168, aFrame.size.width - 70, 20)];
[_saturationSlider setMaxValue:100.0];
[_saturationSlider setMaxValue:1.0];
[_saturationSlider setMinValue:0.0];
[_saturationSlider setTarget:self];
[_saturationSlider setAction:@selector(sliderChanged:)];
@@ -184,7 +183,7 @@
[_brightnessLabel setTextColor:[CPColor blackColor]];
_brightnessSlider = [[CPSlider alloc] initWithFrame:CGRectMake(15, 194, aFrame.size.width - 70, 20)];
[_brightnessSlider setMaxValue:100.0];
[_brightnessSlider setMaxValue:1.0];
[_brightnessSlider setMinValue:0.0];
[_brightnessSlider setTarget:self];
[_brightnessSlider setAction:@selector(sliderChanged:)];
@@ -282,6 +281,9 @@
- (void)setColor:(CPColor)aColor
{
if (!aColor)
[CPException raise:CPInvalidArgumentException reason:"aColor can't be nil"];
[self updateRGBSliders:aColor];
[self updateHSBSliders:aColor];
[self updateHex:aColor];
@@ -313,9 +315,9 @@
- (void)updateLabels
{
[_hueValue setStringValue:ROUND([_hueSlider floatValue])];
[_saturationValue setStringValue:ROUND([_saturationSlider floatValue])];
[_brightnessValue setStringValue:ROUND([_brightnessSlider floatValue])];
[_hueValue setStringValue:ROUND([_hueSlider floatValue] * 360.0)];
[_saturationValue setStringValue:ROUND([_saturationSlider floatValue] * 100.0)];
[_brightnessValue setStringValue:ROUND([_brightnessSlider floatValue] * 100.0)];
[_redValue setStringValue:ROUND([_redSlider floatValue] * 255)];
[_greenValue setStringValue:ROUND([_greenSlider floatValue] * 255)];
@@ -363,15 +365,15 @@
[self sliderChanged:_blueSlider];
break;
case _hueValue: [_hueSlider setFloatValue:MAX(MIN(ROUND(value), 360), 0)];
case _hueValue: [_hueSlider setFloatValue:MAX(MIN(ROUND(value), 360) / 360.0, 0)];
[self sliderChanged:_hueSlider];
break;
case _saturationValue: [_saturationSlider setFloatValue:MAX(MIN(ROUND(value), 100), 0)];
case _saturationValue: [_saturationSlider setFloatValue:MAX(MIN(ROUND(value), 100) / 100.0, 0)];
[self sliderChanged:_saturationSlider];
break;
case _brightnessValue: [_brightnessSlider setFloatValue:MAX(MIN(ROUND(value), 100), 0)];
case _brightnessValue: [_brightnessSlider setFloatValue:MAX(MIN(ROUND(value), 100) / 100.0, 0)];
[self sliderChanged:_brightnessSlider];
break;
}
+2 -2
View File
@@ -103,7 +103,7 @@ var ShouldSuppressResizeNotifications = 1,
return @"splitview";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"divider-thickness": 1.0,
@@ -995,7 +995,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
@param unsigned int - The divider index the button bar will be assigned to.
*/
// FIXME Should be renamed to setButtonBar:ofDividerAtIndex:.
- (void)setButtonBar:(CPButtonBar)aButtonBar forDividerAtIndex:(unsigned)dividerIndex
- (void)setButtonBar:(CPButtonBar)aButtonBar forDividerAtIndex:(CPUInteger)dividerIndex
{
if (!aButtonBar)
{
+2 -2
View File
@@ -213,7 +213,7 @@
Set the current value of the stepper.
@param aValue a float containing the value
*/
- (void)setDoubleValue:(float)aValue
- (void)setDoubleValue:(double)aValue
{
if (aValue > _maxValue)
[super setDoubleValue:_valueWraps ? _minValue : _maxValue];
@@ -267,7 +267,7 @@
return @"stepper";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"bezel-color-up-button": [CPNull null],
+28 -16
View File
@@ -33,10 +33,22 @@ CPNoTabsBezelBorder = 4; //Displays no tabs and has a bezeled border.
CPNoTabsLineBorder = 5; //Has no tabs and displays a line border.
CPNoTabsNoBorder = 6; //Displays no tabs and no border.
var CPTabViewDidSelectTabViewItemSelector = 1,
CPTabViewShouldSelectTabViewItemSelector = 2,
CPTabViewWillSelectTabViewItemSelector = 4,
CPTabViewDidChangeNumberOfTabViewItemsSelector = 8;
var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
CPTabViewShouldSelectTabViewItemSelector = 1 << 2,
CPTabViewWillSelectTabViewItemSelector = 1 << 3,
CPTabViewDidChangeNumberOfTabViewItemsSelector = 1 << 4;
@protocol CPTabViewDelegate <CPObject>
@optional
- (BOOL)tabView:(CPTabView)tabView shouldSelectTabViewItem:(CPTabViewItem)tabViewItem;
- (void)tabView:(CPTabView)tabView didSelectTabViewItem:(CPTabViewItem)tabViewItem;
- (void)tabView:(CPTabView)tabView willSelectTabViewItem:(CPTabViewItem)tabViewItem;
- (void)tabViewDidChangeNumberOfTabViewItems:(CPTabView)tabView;
@end
/*!
@ingroup appkit
@@ -48,18 +60,18 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
*/
@implementation CPTabView : CPView
{
CPArray _items;
CPArray _items;
CPSegmentedControl _tabs;
CPBox _box;
CPSegmentedControl _tabs;
CPBox _box;
CPNumber _selectedIndex;
CPNumber _selectedIndex;
CPTabViewType _type;
CPFont _font;
CPTabViewType _type;
CPFont _font;
id _delegate;
unsigned _delegateSelectors;
id <CPTabViewDelegate> _delegate;
unsigned _delegateSelectors;
}
- (id)initWithFrame:(CGRect)aFrame
@@ -107,7 +119,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
@param aTabViewItem the item to insert
@param anIndex the index for the item
*/
- (void)insertTabViewItem:(CPTabViewItem)aTabViewItem atIndex:(unsigned)anIndex
- (void)insertTabViewItem:(CPTabViewItem)aTabViewItem atIndex:(CPUInteger)anIndex
{
[_items insertObject:aTabViewItem atIndex:anIndex];
@@ -183,7 +195,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
Returns the CPTabViewItem at the specified index.
@return a tab view item, or nil
*/
- (CPTabViewItem)tabViewItemAtIndex:(unsigned)anIndex
- (CPTabViewItem)tabViewItemAtIndex:(CPUInteger)anIndex
{
return [_items objectAtIndex:anIndex];
}
@@ -270,7 +282,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
Selects the item at the specified index.
@param anIndex the index of the item to display.
*/
- (BOOL)selectTabViewItemAtIndex:(unsigned)anIndex
- (BOOL)selectTabViewItemAtIndex:(CPUInteger)anIndex
{
if (anIndex === _selectedIndex)
return;
@@ -405,7 +417,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
Sets the delegate for this tab view.
@param aDelegate the tab view's delegate
*/
- (void)setDelegate:(id)aDelegate
- (void)setDelegate:(id <CPTabViewDelegate>)aDelegate
{
if (_delegate == aDelegate)
return;
+3 -3
View File
@@ -416,7 +416,7 @@ CPTableColumnUserResizingMask = 1 << 1;
to be invoked with row equal to -1 in cases where no actual row is involved but the table
view needs to get some generic cell info.
*/
- (id)dataViewForRow:(int)aRowIndex
- (id)dataViewForRow:(CPInteger)aRowIndex
{
return [self dataView];
}
@@ -595,7 +595,7 @@ CPTableColumnUserResizingMask = 1 << 1;
@implementation CPTableColumn (Bindings)
+ (id)_binderClassForBinding:(CPString)aBinding
+ (Class)_binderClassForBinding:(CPString)aBinding
{
if (aBinding == CPValueBinding)
return [CPTableColumnValueBinder class];
@@ -828,7 +828,7 @@ var CPTableColumnIdentifierKey = @"CPTableColumnIdentifierKey",
/*!
@ignore
*/
- (id)dataCellForRow:(int)row
- (id)dataCellForRow:(CPInteger)row
{
[CPException raise:CPUnsupportedMethodException
reason:@"dataCellForRow: is not supported. Use -dataViewForRow:row instead."];
+44 -29
View File
@@ -43,7 +43,7 @@
return @"columnHeader";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"background-color": [CPNull null],
@@ -53,11 +53,11 @@
@"text-color": [CPNull null],
@"font": [CPNull null],
@"text-shadow-color": [CPNull null],
@"text-shadow-offset": CGSizeMakeZero(),
@"text-shadow-offset": CGSizeMakeZero()
};
}
- (void)initWithFrame:(CGRect)frame
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
@@ -229,6 +229,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
CGPoint _previousTrackingLocation;
int _activeColumn;
int _pressedColumn;
int _lastDragDestinationColumnIndex;
BOOL _isResizing;
BOOL _isDragging;
@@ -245,11 +246,12 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
return @"tableHeaderRow";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"background-color": [CPNull null],
@"divider-color": [CPColor grayColor],
@"divider-thickness": 1.0
};
}
@@ -285,7 +287,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
return [_tableView columnAtPoint:CGPointMake(aPoint.x, aPoint.y)];
}
- (CGRect)headerRectOfColumn:(int)aColumnIndex
- (CGRect)headerRectOfColumn:(CPInteger)aColumnIndex
{
var headerRect = CGRectMakeCopy([self bounds]),
columnRect = [_tableView rectOfColumn:aColumnIndex];
@@ -306,7 +308,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
return _drawsColumnLines;
}
- (CGRect)_cursorRectForColumn:(int)column
- (CGRect)_cursorRectForColumn:(CPInteger)column
{
if (column == -1 || !([_tableView._tableColumns[column] resizingMask] & CPTableColumnUserResizingMask))
return CGRectMakeZero();
@@ -332,7 +334,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
var headerView = [_tableView._tableColumns[column] headerView];
[headerView setThemeState:CPThemeStateHighlighted];
if (_tableView._editingColumn == column)
if (_tableView._editingCellIndex || _tableView._editingColumn == column)
[[self window] makeFirstResponder:_tableView];
}
@@ -381,7 +383,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
_mouseDownLocation = currentLocation;
_activeColumn = columnIndex;
[_tableView _sendDelegateDidMouseDownInHeader:columnIndex];
[_tableView _sendDelegateMouseDownInHeaderOfTableColumn:columnIndex];
if (shouldResize)
[self startResizingTableColumn:columnIndex at:currentLocation];
@@ -415,12 +417,13 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[CPApp setTarget:self selector:@selector(trackMouse:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
}
- (void)startTrackingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (void)startTrackingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
_lastDragDestinationColumnIndex = -1;
[self _setPressedColumn:aColumnIndex];
}
- (BOOL)continueTrackingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (BOOL)continueTrackingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
if ([self _shouldDragTableColumn:aColumnIndex at:aPoint])
{
@@ -441,21 +444,21 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
return YES;
}
- (BOOL)_shouldStopTrackingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (BOOL)_shouldStopTrackingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
return _isTrackingColumn && _activeColumn === aColumnIndex &&
CGRectContainsPoint([self headerRectOfColumn:aColumnIndex], aPoint);
}
- (void)stopTrackingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (void)stopTrackingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
[self _setPressedColumn:CPNotFound];
[self _updateResizeCursor:[CPApp currentEvent]];
}
- (BOOL)_shouldDragTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (BOOL)_shouldDragTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
return [_tableView allowsColumnReordering] && ABS(aPoint.x - _mouseDownLocation.x) >= 10.0;
return ABS(aPoint.x - _mouseDownLocation.x) >= 10.0 && [_tableView _sendDelegateShouldReorderColumn:aColumnIndex toColumn:-1];
}
- (CGRect)_headerRectOfLastVisibleColumn
@@ -501,11 +504,14 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[dragWindow setFrame:frame];
}
- (void)_moveColumn:(int)aFromIndex toColumn:(int)aToIndex
- (void)_moveColumn:(CPInteger)aFromIndex toColumn:(CPInteger)aToIndex
{
[_tableView moveColumn:aFromIndex toColumn:aToIndex];
_activeColumn = aToIndex;
_pressedColumn = _activeColumn;
if ([_tableView _sendDelegateShouldReorderColumn:aFromIndex toColumn:aToIndex])
{
[_tableView moveColumn:aFromIndex toColumn:aToIndex];
_activeColumn = aToIndex;
_pressedColumn = _activeColumn;
}
}
- (void)draggedView:(CPView)aView beganAt:(CGPoint)aPoint
@@ -541,14 +547,21 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
var hoveredColumn = [self columnAtPoint:hoverPoint];
if (hoveredColumn !== -1)
if (hoveredColumn !== _lastDragDestinationColumnIndex && hoveredColumn !== -1)
{
var columnRect = [self headerRectOfColumn:hoveredColumn],
columnCenterPoint = [self convertPoint:CGPointMake(CGRectGetMidX(columnRect), CGRectGetMidY(columnRect)) fromView:self];
if (hoveredColumn < _activeColumn && hoverPoint.x < columnCenterPoint.x)
{
[self _moveColumn:_activeColumn toColumn:hoveredColumn];
_lastDragDestinationColumnIndex = hoveredColumn;
}
else if (hoveredColumn > _activeColumn && hoverPoint.x > columnCenterPoint.x)
{
[self _moveColumn:_activeColumn toColumn:hoveredColumn];
_lastDragDestinationColumnIndex = hoveredColumn;
}
}
_previousTrackingLocation = aPoint;
@@ -568,7 +581,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[_tableView _enqueueDraggingViews];
}
- (BOOL)shouldResizeTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (BOOL)shouldResizeTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
if (_isResizing)
return YES;
@@ -579,7 +592,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
return [_tableView allowsColumnResizing] && CGRectContainsPoint([self _cursorRectForColumn:aColumnIndex], aPoint);
}
- (void)startResizingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (void)startResizingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
_isResizing = YES;
@@ -589,7 +602,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[_tableView setDisableAutomaticResizing:YES];
}
- (void)continueResizingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (void)continueResizingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
var tableColumn = [[_tableView tableColumns] objectAtIndex:aColumnIndex],
newWidth = [tableColumn width] + aPoint.x - _previousTrackingLocation.x;
@@ -609,7 +622,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
}
}
- (void)stopResizingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
- (void)stopResizingTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
{
var tableColumn = [[_tableView tableColumns] objectAtIndex:aColumnIndex];
[tableColumn _postDidResizeNotificationWithOldWidth:_columnOldWidth];
@@ -667,7 +680,8 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
- (void)layoutSubviews
{
var tableColumns = [_tableView tableColumns],
count = [tableColumns count];
count = [tableColumns count],
lineThickness = [self currentValueForThemeAttribute:@"divider-thickness"];
for (var i = 0; i < count; i++)
{
@@ -677,7 +691,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
// Make space for the gridline on the right.
frame.origin.x -= 0.5;
frame.size.width -= 1.0;
frame.size.width -= lineThickness;
frame.size.height -= 0.5;
// Note: we're not adding in intercell spacing here. This setting only affects the regular
// table cell data views, not the header. Verified in Cocoa on March 29th, 2011.
@@ -702,9 +716,10 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
tableColumns = [_tableView tableColumns],
exposedTableColumns = _tableView._exposedColumns,
firstIndex = [exposedTableColumns firstIndex],
exposedRange = CPMakeRange(firstIndex, [exposedTableColumns lastIndex] - firstIndex + 1);
exposedRange = CPMakeRange(firstIndex, [exposedTableColumns lastIndex] - firstIndex + 1),
lineThickness = [self currentValueForThemeAttribute:@"divider-thickness"];
CGContextSetLineWidth(context, 1);
CGContextSetLineWidth(context, lineThickness);
CGContextSetStrokeColor(context, [self currentValueForThemeAttribute:@"divider-color"]);
[exposedColumnIndexes getIndexes:columnsArray maxCount:-1 inIndexRange:exposedRange];
@@ -723,8 +738,8 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
columnMaxX = CGRectGetMaxX(columnToStroke);
CGContextMoveToPoint(context, FLOOR(columnMaxX) - 0.5, ROUND(CGRectGetMinY(columnToStroke)));
CGContextAddLineToPoint(context, FLOOR(columnMaxX) - 0.5, ROUND(CGRectGetMaxY(columnToStroke)) - 1.0);
CGContextMoveToPoint(context, FLOOR(columnMaxX) - 0.5 * lineThickness, ROUND(CGRectGetMinY(columnToStroke)));
CGContextAddLineToPoint(context, FLOOR(columnMaxX) - 0.5 * lineThickness, ROUND(CGRectGetMaxY(columnToStroke)) - 1.0);
}
CGContextClosePath(context);
+992 -465
View File
File diff suppressed because it is too large Load Diff
+11
View File
@@ -28,3 +28,14 @@ CPFormFeedCharacter = "\u000c";
CPCarriageReturnCharacter = "\u000d";
CPBackTabCharacter = "\u0019";
CPDeleteCharacter = "\u007f";
CPIllegalTextMovement = 0;
CPOtherTextMovement = 0;
CPReturnTextMovement = 16;
CPTabTextMovement = 17;
CPBacktabTextMovement = 18;
CPLeftTextMovement = 19;
CPRightTextMovement = 20;
CPUpTextMovement = 21;
CPDownTextMovement = 22;
CPCancelTextMovement = 23;
+316 -110
View File
@@ -209,7 +209,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
return "textfield";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"bezel-inset": CGInsetMakeZero(),
@@ -218,7 +218,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
};
}
/* @ignore */
#if PLATFORM(DOM)
- (DOMElement)_inputElement
{
@@ -352,8 +351,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
else
[self unsetThemeState:CPThemeStateEditable];
// We only allow first responder status if the field is editable and enabled.
if (!shouldBeEditable && [[self window] firstResponder] === self)
// We only allow first responder status if the field is enable, and editable or selectable.
if (!(shouldBeEditable && ![self isSelectable]) && [[self window] firstResponder] === self)
[[self window] makeFirstResponder:nil];
if (shouldBeEditable)
@@ -378,7 +377,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
{
[super setEnabled:shouldBeEnabled];
// We only allow first responder status if the field is editable and enabled.
// We only allow first responder status if the field is enabled.
if (!shouldBeEnabled && [[self window] firstResponder] === self)
[[self window] makeFirstResponder:nil];
}
@@ -529,30 +528,36 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
return _textFieldBackgroundColor;
}
/* @ignore */
/*! @ignore */
- (BOOL)acceptsFirstResponder
{
return [self isEditable] && [self isEnabled] && [self _isWithinUsablePlatformRect];
return [self isEnabled] && ([self isEditable] || [self isSelectable]) && [self _isWithinUsablePlatformRect];
}
/* @ignore */
/*! @ignore */
- (BOOL)becomeFirstResponder
{
if (![self isEnabled])
return NO;
// As long as we are the first responder we need to monitor the key status of our window.
[self _setObserveWindowKeyNotifications:YES];
_isEditing = NO;
if ([[self window] isKeyWindow])
if ([[self window] isKeyWindow] && [self isEditable])
return [self _becomeFirstKeyResponder];
return YES;
}
/*!
/*
A text field can be the first responder without necessarily being the focus of keyboard input. For example, it might be the first responder of window A but window B is the main and key window. It's important we don't put a focused input field into a text field in a non-key window, even if that field is the first responder, because the key window might also have a first responder text field which the user will expect to receive keyboard input.
Since a first responder but non-key window text field can't receive input it should not even look like an active text field (Cocoa has a "slightly active" text field look it uses when another window is the key window, but Cappuccino doesn't today.)
It's also possible for a text field to be non-editable but selectable in which case it can also become the first responder -
this is what allows text to be copied from it.
*/
- (BOOL)_becomeFirstKeyResponder
{
@@ -561,6 +566,11 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
if (![self _isWithinUsablePlatformRect])
return NO;
// A selectable but non-editable text field may be the first responder, but never the
// first key responder (first key responder indicating editability.)
if (![self isEditable])
return NO;
[self setThemeState:CPThemeStateEditing];
[self _updatePlaceholderState];
@@ -677,28 +687,30 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
return YES;
}
/* @ignore */
/*! @ignore */
- (BOOL)resignFirstResponder
{
#if PLATFORM(DOM)
var element = [self _inputElement],
newValue = element.value,
error = @"";
if (newValue !== _stringValue)
// We might have been the first responder without actually editing.
if (_isEditing && CPTextFieldInputOwner === self)
{
[self _setStringValue:newValue];
}
var element = [self _inputElement],
newValue = element.value,
error = @"";
// If there is a formatter, always give it a chance to reject the resignation,
// even if the value has not changed.
if ([self _valueIsValid:newValue] === NO)
{
element.focus();
return NO;
}
if (newValue !== _stringValue)
{
[self _setStringValue:newValue];
}
// If there is a formatter, always give it a chance to reject the resignation,
// even if the value has not changed.
if ([self _valueIsValid:newValue] === NO)
{
element.focus();
return NO;
}
}
#endif
// When we are no longer the first responder we don't worry about the key status of our window anymore.
@@ -707,10 +719,13 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
[self _resignFirstKeyResponder];
_isEditing = NO;
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]];
if ([self isEditable])
{
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:@{"CPTextMovement": [self _currentTextMovement]}]];
if ([self sendsActionOnEndEditing])
[self sendAction:[self action] to:[self target]];
if ([self sendsActionOnEndEditing])
[self sendAction:[self action] to:[self target]];
}
[self textDidBlur:[CPNotification notificationWithName:CPTextFieldDidBlurNotification object:self userInfo:nil]];
@@ -783,9 +798,14 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)_windowDidBecomeKey:(CPNotification)aNotification
{
if ([[self window] isKeyWindow] && [[self window] firstResponder] === self)
if (!([self isEnabled] && [self isEditable]))
return;
var wind = [self window];
if ([wind isKeyWindow] && [wind firstResponder] === self)
if (![self _becomeFirstKeyResponder])
[[self window] makeFirstResponder:nil];
[wind makeFirstResponder:nil];
}
- (BOOL)_valueIsValid:(CPString)aValue
@@ -820,13 +840,24 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
}
/*!
Only text fields that can become first responder accepts first mouse.
Only text fields that can become first responder accept first mouse.
*/
- (BOOL)acceptsFirstMouse:(CPEvent)anEvent
{
return [self acceptsFirstResponder];
}
- (void)_didEdit
{
if (!_isEditing)
{
_isEditing = YES;
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
}
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
}
- (void)mouseDown:(CPEvent)anEvent
{
// Don't track! (ever?)
@@ -853,7 +884,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)mouseUp:(CPEvent)anEvent
{
if (![self isSelectable] && (![self isEditable] || ![self isEnabled]))
if (![self isEnabled] || !([self isSelectable] || [self isEditable]))
[[self nextResponder] mouseUp:anEvent];
else if ([self isSelectable])
{
@@ -865,13 +896,22 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
CPTextFieldCachedSelectStartFunction = nil
CPTextFieldCachedDragFunction = nil;
}
// TODO clickCount === 2 should select the clicked word.
if ([[CPApp currentEvent] clickCount] === 3)
{
[self selectText:nil];
return;
}
return [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:YES];
}
}
- (void)mouseDragged:(CPEvent)anEvent
{
if (![self isSelectable] && (![self isEditable] || ![self isEnabled]))
if (![self isEnabled] || !([self isSelectable] || [self isEditable]))
[[self nextResponder] mouseDragged:anEvent];
else if ([self isSelectable])
return [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:YES];
@@ -879,26 +919,21 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)keyUp:(CPEvent)anEvent
{
#if PLATFORM(DOM)
if (!([self isEnabled] && [self isEditable]))
return;
#if PLATFORM(DOM)
var newValue = [self _inputElement].value;
if (newValue !== _stringValue)
{
[self _setStringValue:newValue];
if (!_isEditing)
{
_isEditing = YES;
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
}
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
[self _didEdit];
}
#endif
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
#endif
}
- (void)keyDown:(CPEvent)anEvent
@@ -931,11 +966,15 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)insertNewline:(id)sender
{
if (!([self isEnabled] && [self isEditable]))
return;
var newValue = [self _inputElement].value;
if (newValue !== _stringValue)
{
[self _setStringValue:newValue];
[self _didEdit];
}
if ([self _valueIsValid:_stringValue])
@@ -948,7 +987,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
if (_isEditing)
{
_isEditing = NO;
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]];
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:@{"CPTextMovement": [self _currentTextMovement]}]];
}
// If there is no target action, or the sendAction call returns
@@ -974,6 +1013,9 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)_insertCharacterIgnoringFieldEditor:(CPString)aCharacter
{
if (!([self isEnabled] && [self isEditable]))
return;
#if PLATFORM(DOM)
var oldValue = _stringValue,
@@ -986,13 +1028,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
// NOTE: _stringValue is now the current input element value
if (oldValue !== _stringValue)
{
if (!_isEditing)
{
_isEditing = YES;
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
}
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
[self _didEdit];
}
#endif
@@ -1035,7 +1071,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
}
/*
@ignore
Sets the internal string value without updating the value in the input element.
This should only be invoked when the underlying text element's value has changed.
*/
@@ -1044,8 +1079,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
return [self _setStringValue:aValue isNewValue:YES errorDescription:nil];
}
/*
@ignore
/*!
Sets the internal string value without updating the value in the input element.
If there is a formatter and formatting fails, returns NO. Otherwise returns YES.
*/
@@ -1104,10 +1138,13 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
value = undefined;
[super setObjectValue:value];
_stringValue = (value === nil || value === undefined) ? @"" : String(value);
}
else
_stringValue = formattedString;
}
_stringValue = [self stringValue];
else
_stringValue = [self stringValue];
#if PLATFORM(DOM)
@@ -1241,22 +1278,29 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)_selectText:(id)sender immediately:(BOOL)immediately
{
// Selecting the text in a field makes it the first responder
if (([self isEditable] || [self isSelectable]))
if ([self isEditable] || [self isSelectable])
{
var wind = [self window];
#if PLATFORM(DOM)
var element = [self _inputElement];
if ([wind firstResponder] === self)
if ([self isEditable])
{
if (immediately)
element.select();
else
window.setTimeout(function() { element.select(); }, 0);
var element = [self _inputElement];
if ([wind firstResponder] === self)
{
if (immediately)
element.select();
else
window.setTimeout(function() { element.select(); }, 0);
}
else if (wind !== nil && [wind makeFirstResponder:self])
[self _selectText:sender immediately:immediately];
}
else
{
[self setSelectedRange:CPMakeRange(0, _stringValue.length)];
}
else if (wind !== nil && [wind makeFirstResponder:self])
[self _selectText:sender immediately:immediately];
#else
// Even if we can't actually select the text we need to preserve the first
// responder side effect.
@@ -1269,36 +1313,70 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)copy:(id)sender
{
if (![CPPlatform isBrowser])
// First write to the Cappuccino clipboard.
var stringToCopy = nil;
if ([self isEditable])
{
var selectedRange = [self selectedRange];
if (selectedRange.length < 1)
return;
var pasteboard = [CPPasteboard generalPasteboard],
stringForPasting = [_stringValue substringWithRange:selectedRange];
stringToCopy = [_stringValue substringWithRange:selectedRange];
}
else
{
// selectedRange won't work if we're displaying our text using a <div>. Instead we have to ask the browser
// what's selected and hope it's right in a Cappuccino context as well.
#if PLATFORM(DOM)
stringToCopy = [[[self window] platformWindow] _selectedText];
#endif
}
[pasteboard declareTypes:[CPStringPboardType] owner:nil];
[pasteboard setString:stringForPasting forType:CPStringPboardType];
var pasteboard = [CPPasteboard generalPasteboard];
[pasteboard declareTypes:[CPStringPboardType] owner:nil];
[pasteboard setString:stringToCopy forType:CPStringPboardType];
if ([CPPlatform isBrowser])
{
// Then also allow the browser to capture the copied text into the system clipboard.
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
}
}
- (void)cut:(id)sender
{
if (![CPPlatform isBrowser])
if (![self isEnabled])
return;
[self copy:sender];
if (![self isEditable])
return;
if (![[CPApp currentEvent] _platformIsEffectingCutOrPaste])
{
[self copy:sender];
[self deleteBackward:sender];
}
// If we don't have an oninput listener, we won't detect the change made by the cut and need to fake a key up "soon".
else if (!CPFeatureIsCompatible(CPInputOnInputEventFeature))
[CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(keyUp:) userInfo:nil repeats:NO];
else
{
// Allow the browser's standard cut handling. This should also result in the deleteBackward: happening.
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
// If we don't have an oninput listener, we won't detect the change made by the cut and need to fake a key up "soon".
if (!CPFeatureIsCompatible(CPInputOnInputEventFeature))
[CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(keyUp:) userInfo:nil repeats:NO];
}
}
- (void)paste:(id)sender
{
if (![CPPlatform isBrowser])
if (!([self isEnabled] && [self isEditable]))
return;
if (![[CPApp currentEvent] _platformIsEffectingCutOrPaste])
{
var pasteboard = [CPPasteboard generalPasteboard];
@@ -1312,15 +1390,24 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:pasteString];
[self setStringValue:newValue];
[self _didEdit];
[self setSelectedRange:CPMakeRange(selectedRange.location + pasteString.length, 0)];
}
// If we don't have an oninput listener, we won't detect the change made by the cut and need to fake a key up "soon".
else if (!CPFeatureIsCompatible(CPInputOnInputEventFeature))
[CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(keyUp:) userInfo:nil repeats:NO];
else
{
// Allow the browser's standard paste handling.
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
if (!CPFeatureIsCompatible(CPInputOnInputEventFeature))
[CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(keyUp:) userInfo:nil repeats:NO];
}
}
- (CPRange)selectedRange
{
// TODO Need a way to figure out the selected range if we're not using an input. Need
// to get whole document selection and somehow see which part is inside of this text field.
if ([[self window] firstResponder] !== self)
return CPMakeRange(0, 0);
@@ -1364,35 +1451,48 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
#if PLATFORM(DOM)
var inputElement = [self _inputElement];
try
if (![self isEditable])
{
if ([inputElement.selectionStart isKindOfClass:CPNumber])
{
inputElement.selectionStart = aRange.location;
inputElement.selectionEnd = CPMaxRange(aRange);
}
else
{
// browsers which don't support selectionStart/selectionEnd (aka IE).
var theDocument = inputElement.ownerDocument || inputElement.document,
existingRange = theDocument.selection.createRange(),
range = inputElement.createTextRange();
// No input element - selectable text field only.
var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
if (range.inRange(existingRange))
if (contentView)
[contentView setSelectedRange:aRange];
}
else
{
// Input element
var inputElement = [self _inputElement];
try
{
if ([inputElement.selectionStart isKindOfClass:CPNumber])
{
range.collapse(true);
range.move('character', aRange.location);
range.moveEnd('character', aRange.length);
range.select();
inputElement.selectionStart = aRange.location;
inputElement.selectionEnd = CPMaxRange(aRange);
}
else
{
// browsers which don't support selectionStart/selectionEnd (aka IE).
var theDocument = inputElement.ownerDocument || inputElement.document,
existingRange = theDocument.selection.createRange(),
range = inputElement.createTextRange();
if (range.inRange(existingRange))
{
range.collapse(true);
range.move('character', aRange.location);
range.moveEnd('character', aRange.length);
range.select();
}
}
}
catch (e)
{
}
}
catch (e)
{
}
#endif
}
@@ -1403,18 +1503,84 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)deleteBackward:(id)sender
{
if (!([self isEnabled] && [self isEditable]))
return;
var selectedRange = [self selectedRange];
if (selectedRange.length < 2)
return;
if (selectedRange.length < 1)
{
if (selectedRange.location < 1)
return;
selectedRange.location += 1;
selectedRange.length -= 1;
// Delete a single element backward from the insertion point if there's no selection.
selectedRange.location -= 1;
selectedRange.length += 1;
}
var newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:""];
[self setStringValue:newValue];
[self setSelectedRange:CPMakeRange(selectedRange.location, 0)];
[self _didEdit];
#if PLATFORM(DOM)
// Since we just performed the deletion manually, we don't need the browser to do anything else.
// (Previously we would allow the event to propagate for the browser to delete 1 character only,
// and we'd delete the rest manually. But this meant that if deleteBackward: was called without
// it being a browser backspace event, 1 character would be left behind.)
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
#endif
}
- (void)delete:(id)sender
{
if (!([self isEnabled] && [self isEditable]))
return;
// delete: only works when there's a selection (as opposed to deleteForward: and deleteBackward:).
var selectedRange = [self selectedRange];
if (selectedRange.length < 1)
return;
var newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:""];
[self setStringValue:newValue];
[self setSelectedRange:CPMakeRange(selectedRange.location, 0)];
[self _didEdit];
#if PLATFORM(DOM)
// Since we just performed the deletion manually, we don't need the browser to do anything else.
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
#endif
}
- (void)deleteForward:(id)sender
{
if (!([self isEnabled] && [self isEditable]))
return;
var selectedRange = [self selectedRange];
if (selectedRange.length < 1)
{
if (selectedRange.location + 1 >= _stringValue.length)
return;
selectedRange.length += 1;
}
var newValue = [_stringValue stringByReplacingCharactersInRange:selectedRange withString:""];
[self setStringValue:newValue];
[self setSelectedRange:CPMakeRange(selectedRange.location, 0)];
[self _didEdit];
#if PLATFORM(DOM)
// Since we just performed the deletion manually, we don't need the browser to do anything else.
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
#endif
}
#pragma mark Setting the Delegate
@@ -1581,6 +1747,41 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
}
}
#pragma mark Overrides
- (void)viewDidHide
{
[super viewDidHide];
if ([[self window] firstResponder] === self)
[self _resignFirstKeyResponder];
}
- (void)viewDidUnhide
{
[super viewDidUnhide];
if ([self isEditable] && [[self window] firstResponder] === self)
[self _becomeFirstKeyResponder];
}
- (BOOL)validateUserInterfaceItem:(id /*<CPValidatedUserInterfaceItem>*/)anItem
{
var theAction = [anItem action];
if (![self isEditable] && (theAction == @selector(cut:) || theAction == @selector(paste:) || theAction == @selector(delete:)))
return NO;
// FIXME - [self selectedRange] is always empty if we're not an editable field, so we must assume yes here.
if (![self isEditable])
return YES;
if (theAction == @selector(copy:) || theAction == @selector(cut:) || theAction == @selector(delete:))
return [self selectedRange].length;
return YES;
}
#pragma mark Private
- (BOOL)_isWithinUsablePlatformRect
@@ -1588,8 +1789,13 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
// Make sure the text field is completely within the platform window
// so the browser will not scroll it into view.
var wind = [self window],
frame = [self convertRectToBase:[self bounds]],
var wind = [self window];
// If the field is not yet within a window, it can't be first responder
if (!wind)
return NO;
var frame = [self convertRectToBase:[self bounds]],
usableRect = [[wind platformWindow] usableContentFrame];
frame.origin = [wind convertBaseToGlobal:frame.origin];
@@ -1677,7 +1883,7 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
@implementation _CPTextFieldValueBinder : CPBinder
- (void)_updatePlaceholdersWithOptions:(CPDictionary)options forBinding:(CPBinder)aBinding
- (void)_updatePlaceholdersWithOptions:(CPDictionary)options forBinding:(CPString)aBinding
{
[super _updatePlaceholdersWithOptions:options];
Executable → Regular
+12 -6
View File
@@ -34,6 +34,8 @@
@import "CPWindow_Constants.j"
@global CPApp
@global CPTextFieldDidFocusNotification
@global CPTextFieldDidBlurNotification
#if PLATFORM(DOM)
@@ -96,7 +98,7 @@ CPTokenFieldDeleteButtonType = 1;
return "tokenfield";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{ @"editor-inset": CGInsetMakeZero() };
}
@@ -392,6 +394,8 @@ CPTokenFieldDeleteButtonType = 1;
element.focus();
CPTokenFieldInputOwner = self;
}, 0.0);
[self textDidFocus:[CPNotification notificationWithName:CPTextFieldDidFocusNotification object:self userInfo:nil]];
}, 0.0);
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
@@ -424,12 +428,14 @@ CPTokenFieldDeleteButtonType = 1;
if (_shouldNotifyTarget)
{
_shouldNotifyTarget = NO;
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]];
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:@{"CPTextMovement": [self _currentTextMovement]}]];
if ([self sendsActionOnEndEditing])
[self sendAction:[self action] to:[self target]];
}
[self textDidBlur:[CPNotification notificationWithName:CPTextFieldDidBlurNotification object:self userInfo:nil]];
return YES;
}
@@ -639,7 +645,7 @@ CPTokenFieldDeleteButtonType = 1;
[[self _tokens] makeObjectsPerformSelector:@selector(setEditable:) withObject:shouldBeEditable];
}
- (void)sendAction:(SEL)anAction to:(id)anObject
- (BOOL)sendAction:(SEL)anAction to:(id)anObject
{
_shouldNotifyTarget = NO;
[super sendAction:anAction to:anObject];
@@ -647,7 +653,7 @@ CPTokenFieldDeleteButtonType = 1;
// Incredible hack to disable supers implementation
// so it cannot change our object value and break the tokenfield
- (void)_setStringValue:(id)aValue
- (BOOL)_setStringValue:(CPString)aValue
{
}
@@ -1535,7 +1541,7 @@ CPTokenFieldDeleteButtonType = 1;
{
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
var attributes = [CPButton themeAttributes];
@@ -1565,7 +1571,7 @@ CPTokenFieldDeleteButtonType = 1;
{
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
var attributes = [CPButton themeAttributes];
+140 -20
View File
@@ -30,6 +30,13 @@
@global CPApp
var CPToolbarDelegate_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_ = 1 << 0,
CPToolbarDelegate_toolbarAllowedItemIdentifiers_ = 1 << 1,
CPToolbarDelegate_toolbarDefaultItemIdentifiers_ = 1 << 2,
CPToolbarDelegate_toolbarDidRemoveItem_ = 1 << 3,
CPToolbarDelegate_toolbarSelectableItemIdentifiers_ = 1 << 4,
CPToolbarDelegate_toolbarWillAddItem_ = 1 << 5;
/*
@global
@group CPToolbarDisplayMode
@@ -59,6 +66,20 @@ CPToolbarSizeModeSmall = 2;
var CPToolbarsByIdentifier = nil,
CPToolbarConfigurationsByIdentifier = nil;
@protocol CPToolbarDelegate <CPObject>
@optional
- (CPToolbarItem)toolbar:(CPToolbar)toolbar itemForItemIdentifier:(CPString)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)toolbar;
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)toolbar;
- (void)toolbarDidRemoveItem:(CPNotification)notification;
- (CPArray)toolbarSelectableItemIdentifiers:(CPToolbar)toolbar;
- (void)toolbarWillAddItem:(CPNotification)notification;
@end
/*!
@ingroup appkit
@class CPToolbar
@@ -89,14 +110,15 @@ var CPToolbarsByIdentifier = nil,
@implementation CPToolbar : CPObject
{
CPString _identifier;
CPToolbarDisplayMode _displayMode @accessors(property=displayMode);
CPToolbarDisplayMode _displayMode @accessors(property=displayMode);
BOOL _showsBaselineSeparator;
BOOL _allowsUserCustomization;
BOOL _isVisible;
int _sizeMode @accessors(property=sizeMode);
CPToolbarSizeMode _sizeMode @accessors(property=sizeMode);
int _desiredHeight;
id _delegate;
id <CPToolbarDelegate> _delegate;
unsigned _implementedDelegateMethods;
CPArray _itemIdentifiers;
@@ -165,15 +187,6 @@ var CPToolbarsByIdentifier = nil,
return self;
}
/*!
Sets the toolbar's display mode. NOT YET IMPLEMENTED.
*/
- (void)setDisplayMode:(CPToolbarDisplayMode)aDisplayMode
{
}
/*!
Returns the toolbar's identifier
*/
@@ -248,6 +261,25 @@ var CPToolbarsByIdentifier = nil,
return;
_delegate = aDelegate;
_implementedDelegateMethods = 0;
if ([_delegate respondsToSelector:@selector(toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:)])
_implementedDelegateMethods |= CPToolbarDelegate_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_;
if ([_delegate respondsToSelector:@selector(toolbarAllowedItemIdentifiers:)])
_implementedDelegateMethods |= CPToolbarDelegate_toolbarAllowedItemIdentifiers_;
if ([_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)])
_implementedDelegateMethods |= CPToolbarDelegate_toolbarDefaultItemIdentifiers_;
if ([_delegate respondsToSelector:@selector(toolbarDidRemoveItem:)])
_implementedDelegateMethods |= CPToolbarDelegate_toolbarDidRemoveItem_;
if ([_delegate respondsToSelector:@selector(toolbarSelectableItemIdentifiers:)])
_implementedDelegateMethods |= CPToolbarDelegate_toolbarSelectableItemIdentifiers_;
if ([_delegate respondsToSelector:@selector(toolbarWillAddItem:)])
_implementedDelegateMethods |= CPToolbarDelegate_toolbarWillAddItem_;
[self _reloadToolbarItems];
}
@@ -298,9 +330,9 @@ var CPToolbarsByIdentifier = nil,
// _defaultItems may have been loaded from Cib
_itemIdentifiers = [_defaultItems valueForKey:@"itemIdentifier"] || [];
if ([_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)])
if ([self _delegateRespondsToToolbarDefaultItemIdentifiers])
{
var itemIdentifiersFromDelegate = [_delegate toolbarDefaultItemIdentifiers:self];
var itemIdentifiersFromDelegate = [self _sendDelegateToolbarDefaultItemIdentifiers];
// If we get items both from the Cib and from the delegate method, put the delegate items before the
// Cib ones.
@@ -325,7 +357,7 @@ var CPToolbarsByIdentifier = nil,
item = [_identifiedItems objectForKey:identifier];
if (!item && _delegate)
item = [_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES];
item = [self _sendDelegateItemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES];
item = [item copy];
@@ -403,12 +435,14 @@ var CPToolbarsByIdentifier = nil,
- (id)_itemForItemIdentifier:(CPString)identifier willBeInsertedIntoToolbar:(BOOL)toolbar
{
var item = [_identifiedItems objectForKey:identifier];
if (!item)
{
item = [CPToolbarItem _standardItemWithItemIdentifier:identifier];
if (_delegate && !item)
{
item = [[_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:toolbar] copy];
item = [[self _sendDelegateItemForItemIdentifier:identifier willBeInsertedIntoToolbar:toolbar] copy];
if (!item)
[CPException raise:CPInvalidArgumentException
reason:@"Toolbar delegate " + _delegate + " returned nil toolbar item for identifier " + identifier];
@@ -433,11 +467,11 @@ var CPToolbarsByIdentifier = nil,
/* @ignore */
- (id)_defaultToolbarItems
{
if (!_defaultItems && [_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)])
if (!_defaultItems && [self _delegateRespondsToToolbarDefaultItemIdentifiers])
{
_defaultItems = [];
var identifiers = [_delegate toolbarDefaultItemIdentifiers:self],
var identifiers = [self _sendDelegateToolbarDefaultItemIdentifiers],
index = 0,
count = [identifiers count];
@@ -603,7 +637,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
return @"toolbar-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"item-margin": 10.0,
@@ -1225,7 +1259,7 @@ var LABEL_MARGIN = 2.0;
[_labelField setTextShadowColor:[self FIXME_labelShadowColor]];
}
- (void)sendAction:(SEL)anAction to:(id)aSender
- (BOOL)sendAction:(SEL)anAction to:(id)aSender
{
[CPApp sendAction:anAction to:aSender from:_toolbarItem];
}
@@ -1249,3 +1283,89 @@ var LABEL_MARGIN = 2.0;
}
@end
@implementation CPToolbar (CPToolbarDelegate)
/*
@ignore
Return YES if the delegate implements toolbarDefaultItemIdentifiers:
*/
- (BOOL)_delegateRespondsToToolbarDefaultItemIdentifiers
{
return _implementedDelegateMethods & CPToolbarDelegate_toolbarDefaultItemIdentifiers_;
}
/*!
@ignore
Call the delegate toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
*/
- (CPToolbarItem)_sendDelegateItemForItemIdentifier:(CPString)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
if (!(_implementedDelegateMethods & CPToolbarDelegate_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_))
return nil;
return [_delegate toolbar:self itemForItemIdentifier:itemIdentifier willBeInsertedIntoToolbar:flag];
}
/*!
@ignore
Call the delegate toolbarAllowedItemIdentifiers:
*/
- (CPArray)_sendDelegateToolbarAllowedItemIdentifiers
{
if (!(_implementedDelegateMethods & CPToolbarDelegate_toolbarAllowedItemIdentifiers_))
return [];
return [_delegate toolbarAllowedItemIdentifiers:self];
}
/*!
@ignore
Call the delegate toolbarDefaultItemIdentifiers:
*/
- (CPArray)_sendDelegateToolbarDefaultItemIdentifiers
{
if (!(_implementedDelegateMethods & CPToolbarDelegate_toolbarDefaultItemIdentifiers_))
return [];
return [_delegate toolbarDefaultItemIdentifiers:self];
}
/*!
@ignore
Call the delegate toolbarDidRemoveItem:
*/
- (void)_sendDelegateToolbarDidRemoveItem:(CPNotification)notification
{
if (!(_delegate & CPToolbarDelegate_toolbarDidRemoveItem_))
return;
[_delegate toolbarDidRemoveItem:notification];
}
/*!
@ignore
Call the delegate toolbarSelectableItemIdentifiers:
*/
- (CPArray)_sendDelegateToolbarSelectableItemIdentifiers
{
if (!(_implementedDelegateMethods & CPToolbarDelegate_toolbarSelectableItemIdentifiers_))
return [];
return [_delegate toolbarSelectableItemIdentifiers:self];
}
/*!
@ignore
Call the delegate toolbarWillAddItem:
*/
- (void)_sendDelegateToolbarWillAddItem:(CPNotification)notification
{
if (!(_delegate & CPToolbarDelegate_toolbarWillAddItem_))
return;
[_delegate toolbarWillAddItem:notification];
}
@end
+315 -50
View File
@@ -43,6 +43,26 @@
@global appkit_tag_dom_elements
#if PLATFORM(DOM)
if (typeof(appkit_tag_dom_elements) !== "undefined" && appkit_tag_dom_elements)
{
AppKitTagDOMElement = function(owner, element)
{
element.setAttribute("data-cappuccino-view", [owner className]);
element.setAttribute("data-cappuccino-uid", [owner UID]);
}
}
else
{
AppKitTagDOMElement = function(owner, element)
{
// By default, do nothing.
}
}
#endif
/*
@global
@group CPViewAutoresizingMasks
@@ -179,6 +199,11 @@ var CPViewFlags = { },
_CPViewFullScreenModeState _fullScreenModeState;
// Zoom Support
BOOL _isScaled;
CGSize _hierarchyScaleSize;
CGSize _scaleSize;
// Layout Support
BOOL _needsLayout;
JSObject _ephemeralSubviews;
@@ -317,15 +342,17 @@ var CPViewFlags = { },
_isHidden = NO;
_hitTests = YES;
_hierarchyScaleSize = CGSizeMake(1.0 , 1.0);
_scaleSize = CGSizeMake(1.0, 1.0);
_isScaled = NO;
#if PLATFORM(DOM)
_DOMElement = DOMElementPrototype.cloneNode(false);
AppKitTagDOMElement(self, _DOMElement);
CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(aFrame), CGRectGetMinY(aFrame));
CPDOMDisplayServerSetStyleSize(_DOMElement, width, height);
if (typeof(appkit_tag_dom_elements) !== "undefined" && !!appkit_tag_dom_elements)
_DOMElement.setAttribute("data-cappuccino-view", [self className]);
_DOMImageParts = [];
_DOMImageSizes = [];
#endif
@@ -379,9 +406,9 @@ var CPViewFlags = { },
#if PLATFORM(DOM)
if (_DOMElement.addEventListener)
{
_DOMElement.addEventListener("mouseover", _toolTipFunctionIn, NO);
_DOMElement.addEventListener("keypress", _toolTipFunctionOut, NO);
_DOMElement.addEventListener("mouseout", _toolTipFunctionOut, NO);
_DOMElement.addEventListener("mouseover", _toolTipFunctionIn, YES);
_DOMElement.addEventListener("keypress", _toolTipFunctionOut, YES);
_DOMElement.addEventListener("mouseout", _toolTipFunctionOut, YES);
}
else if (_DOMElement.attachEvent)
{
@@ -406,9 +433,9 @@ var CPViewFlags = { },
#if PLATFORM(DOM)
if (_DOMElement.removeEventListener)
{
_DOMElement.removeEventListener("mouseover", _toolTipFunctionIn, NO);
_DOMElement.removeEventListener("keypress", _toolTipFunctionOut, NO);
_DOMElement.removeEventListener("mouseout", _toolTipFunctionOut, NO);
_DOMElement.removeEventListener("mouseover", _toolTipFunctionIn, YES);
_DOMElement.removeEventListener("keypress", _toolTipFunctionOut, YES);
_DOMElement.removeEventListener("mouseout", _toolTipFunctionOut, YES);
}
else if (_DOMElement.detachEvent)
{
@@ -549,6 +576,13 @@ var CPViewFlags = { },
}
[aSubview setNextResponder:self];
[aSubview _scaleSizeUnitSquareToSize:[self _hierarchyScaleSize]];
// If the subview is not hidden and one of its ancestors is hidden,
// notify the subview that it is now hidden.
if (![aSubview isHidden] && [self isHiddenOrHasHiddenAncestor])
[aSubview _notifyViewDidHide];
[aSubview viewDidMoveToSuperview];
[self didAddSubview:aSubview];
@@ -581,6 +615,12 @@ var CPViewFlags = { },
#if PLATFORM(DOM)
CPDOMDisplayServerRemoveChild(_superview._DOMElement, _DOMElement);
#endif
// If the view is not hidden and one of its ancestors is hidden,
// notify the view that it is now unhidden.
if (!_isHidden && [_superview isHiddenOrHasHiddenAncestor])
[self _notifyViewDidUnhide];
_superview = nil;
[self _setWindow:nil];
@@ -936,8 +976,8 @@ var CPViewFlags = { },
if (YES)
{
_bounds.size.width = aSize.width;
_bounds.size.height = aSize.height;
_bounds.size.width = aSize.width * 1 / _scaleSize.width;
_bounds.size.height = aSize.height * 1 / _scaleSize.height;
}
if (_layer)
@@ -950,7 +990,7 @@ var CPViewFlags = { },
[self setNeedsDisplay:YES];
#if PLATFORM(DOM)
CPDOMDisplayServerSetStyleSize(_DOMElement, size.width, size.height);
[self _setDisplayServerSetStyleSize:size];
if (_DOMContentsElement)
{
@@ -1059,6 +1099,19 @@ var CPViewFlags = { },
[CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
}
/*!
This method is used to set the width and height of the _DOMElement. It cares about the scale of the view.
When scaling, for instance with a size (0.5, 0.5), the bounds of the view will be multiply by 2. It's why we multiply by the inverse of the scaling.
The view will finally keep the same proportion for the user on the screen.
*/
- (void)_setDisplayServerSetStyleSize:(CGSize)aSize
{
#if PLATFORM(DOM)
var scale = [self scaleSize];
CPDOMDisplayServerSetStyleSize(_DOMElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
#endif
}
/*!
Sets the receiver's bounds. The bounds define the size and location of the receiver inside it's frame. Posts a
CPViewBoundsDidChangeNotification to the default notification center if the receiver is configured to do so.
@@ -1359,6 +1412,7 @@ var CPViewFlags = { },
// FIXME: Should we return to visibility? This breaks in FireFox, Opera, and IE.
// _DOMElement.style.visibility = (_isHidden = aFlag) ? "hidden" : "visible";
_isHidden = aFlag;
#if PLATFORM(DOM)
_DOMElement.style.display = _isHidden ? "none" : "block";
#endif
@@ -1394,6 +1448,7 @@ var CPViewFlags = { },
[self viewDidHide];
var count = [_subviews count];
while (count--)
[_subviews[count] _notifyViewDidHide];
}
@@ -1403,6 +1458,7 @@ var CPViewFlags = { },
[self viewDidUnhide];
var count = [_subviews count];
while (count--)
[_subviews[count] _notifyViewDidUnhide];
}
@@ -1553,15 +1609,42 @@ var CPViewFlags = { },
*/
- (CPView)hitTest:(CGPoint)aPoint
{
if (_isHidden || !_hitTests || !CGRectContainsPoint(_frame, aPoint))
if (_isHidden || !_hitTests)
return nil;
var frame = _frame,
sizeScale = [self _hierarchyScaleSize];
if (_isScaled)
frame = CGRectApplyAffineTransform(_frame, CGAffineTransformMakeScale([_superview _hierarchyScaleSize].width, [_superview _hierarchyScaleSize].height));
else
frame = CGRectApplyAffineTransform(_frame, CGAffineTransformMakeScale(sizeScale.width, sizeScale.height));
if (!CGRectContainsPoint(frame, aPoint))
return nil;
var view = nil,
i = _subviews.length,
adjustedPoint = CGPointMake(aPoint.x - CGRectGetMinX(_frame), aPoint.y - CGRectGetMinY(_frame));
adjustedPoint = CGPointMake(aPoint.x - CGRectGetMinX(frame), aPoint.y - CGRectGetMinY(frame));
if (_inverseBoundsTransform)
adjustedPoint = CGPointApplyAffineTransform(adjustedPoint, _inverseBoundsTransform);
{
var affineTransform = CGAffineTransformMakeCopy(_inverseBoundsTransform);
if (_isScaled)
{
affineTransform.tx *= [_superview _hierarchyScaleSize].width;
affineTransform.ty *= [_superview _hierarchyScaleSize].height;
}
else
{
affineTransform.tx *= sizeScale.width;
affineTransform.ty *= sizeScale.height;
}
adjustedPoint = CGPointApplyAffineTransform(adjustedPoint, affineTransform);
}
while (i--)
if (view = [_subviews[i] hitTest:adjustedPoint])
@@ -1882,6 +1965,9 @@ var CPViewFlags = { },
*/
- (CGPoint)convertPoint:(CGPoint)aPoint fromView:(CPView)aView
{
if (aView === self)
return aPoint;
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(aView, self));
}
@@ -1892,7 +1978,7 @@ var CPViewFlags = { },
*/
- (CGPoint)convertPointFromBase:(CGPoint)aPoint
{
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(nil, self));
return [self convertPoint:aPoint fromView:nil];
}
/*!
@@ -1903,9 +1989,13 @@ var CPViewFlags = { },
*/
- (CGPoint)convertPoint:(CGPoint)aPoint toView:(CPView)aView
{
if (aView === self)
return aPoint;
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(self, aView));
}
/*!
Converts the point from the receivers coordinate system to the base coordinate system.
@param aPoint A point specifying a location in the coordinate system of the receiver
@@ -1913,7 +2003,7 @@ var CPViewFlags = { },
*/
- (CGPoint)convertPointToBase:(CGPoint)aPoint
{
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(self, nil));
return [self convertPoint:aPoint toView:nil];
}
/*!
@@ -1924,6 +2014,9 @@ var CPViewFlags = { },
*/
- (CGSize)convertSize:(CGSize)aSize fromView:(CPView)aView
{
if (aView === self)
return aSize;
return CGSizeApplyAffineTransform(aSize, _CPViewGetTransform(aView, self));
}
@@ -1935,6 +2028,9 @@ var CPViewFlags = { },
*/
- (CGSize)convertSize:(CGSize)aSize toView:(CPView)aView
{
if (aView === self)
return aSize;
return CGSizeApplyAffineTransform(aSize, _CPViewGetTransform(self, aView));
}
@@ -1946,6 +2042,9 @@ var CPViewFlags = { },
*/
- (CGRect)convertRect:(CGRect)aRect fromView:(CPView)aView
{
if (self === aView)
return aRect;
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(aView, self));
}
@@ -1956,7 +2055,7 @@ var CPViewFlags = { },
*/
- (CGRect)convertRectFromBase:(CGRect)aRect
{
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(nil, self));
return [self convertRect:aRect fromView:nil];
}
/*!
@@ -1967,6 +2066,9 @@ var CPViewFlags = { },
*/
- (CGRect)convertRect:(CGRect)aRect toView:(CPView)aView
{
if (self === aView)
return aRect;
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(self, aView));
}
@@ -1977,7 +2079,7 @@ var CPViewFlags = { },
*/
- (CGRect)convertRectToBase:(CGRect)aRect
{
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(self, nil));
return [self convertRect:aRect toView:nil];
}
/*!
@@ -2122,6 +2224,88 @@ setBoundsOrigin:
}
// Scaling
/*!
Scales the receivers coordinate system so that the unit square scales to the specified dimensions.
The bounds of the receiver will change, for instance if the given size is (0.5, 0.5) the width and height of the bounds will be multiply by 2.
You must call setNeedsDisplay: to redraw the view.
@param aSize, the size corresponding the new unit scales
*/
- (void)scaleUnitSquareToSize:(CGSize)aSize
{
if (!aSize)
return;
// Reset the bounds
var bounds = CGRectMakeCopy([self bounds]);
bounds.size.width *= _scaleSize.width;
bounds.size.height *= _scaleSize.height;
[self willChangeValueForKey:@"scaleSize"];
_scaleSize = CGSizeMakeCopy([self scaleSize]);
_scaleSize.height *= aSize.height;
_scaleSize.width *= aSize.width;
[self didChangeValueForKey:@"scaleSize"];
_isScaled = YES;
_hierarchyScaleSize = CGSizeMakeCopy([self _hierarchyScaleSize]);
_hierarchyScaleSize.height *= aSize.height;
_hierarchyScaleSize.width *= aSize.width;
var scaleAffine = CGAffineTransformMakeScale(1.0 / _scaleSize.width, 1.0 / _scaleSize.height),
newBounds = CGRectApplyAffineTransform(CGRectMakeCopy(bounds), scaleAffine);
[self setBounds:newBounds];
[_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
}
/*!
@ignore
Set the _hierarchyScaleSize and call all of the subviews to set their _hierarchyScaleSize
*/
- (void)_scaleSizeUnitSquareToSize:(CGSize)aSize
{
_hierarchyScaleSize = CGSizeMakeCopy([_superview _hierarchyScaleSize]);
if (_isScaled)
{
_hierarchyScaleSize.width *= _scaleSize.width;
_hierarchyScaleSize.height *= _scaleSize.height;
}
[_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
}
/*!
Return the _hierarchyScaleSize, this is a CGSize with the real zoom of the view (depending with his parents)
*/
- (CGSize)_hierarchyScaleSize
{
return _hierarchyScaleSize || CGSizeMake(1.0, 1.0);
}
/*!
Make a zoom in css
*/
- (void)_applyCSSScalingTranformations
{
#if PLATFORM(DOM)
if (_isScaled)
{
var scale = [self scaleSize],
browserPropertyTransform = CPBrowserStyleProperty(@"transform"),
browserPropertyTransformOrigin = CPBrowserStyleProperty(@"transformOrigin");
self._DOMElement.style[browserPropertyTransform] = 'scale(' + scale.width + ', ' + scale.height + ')';
self._DOMElement.style[browserPropertyTransformOrigin] = '0 0';
[self _setDisplayServerSetStyleSize:[self frameSize]];
}
#endif
}
// Displaying
/*!
@@ -2130,7 +2314,10 @@ setBoundsOrigin:
- (void)setNeedsDisplay:(BOOL)aFlag
{
if (aFlag)
{
[self _applyCSSScalingTranformations];
[self setNeedsDisplayInRect:[self bounds]];
}
}
/*!
@@ -2223,6 +2410,9 @@ setBoundsOrigin:
var graphicsPort = CGBitmapGraphicsContextCreate();
#if PLATFORM(DOM)
var width = CGRectGetWidth(_frame),
height = CGRectGetHeight(_frame);
_DOMContentsElement = graphicsPort.DOMElement;
_DOMContentsElement.style.zIndex = -100;
@@ -2231,13 +2421,10 @@ setBoundsOrigin:
_DOMContentsElement.style.position = "absolute";
_DOMContentsElement.style.visibility = "visible";
_DOMContentsElement.width = ROUND(CGRectGetWidth(_frame));
_DOMContentsElement.height = ROUND(CGRectGetHeight(_frame));
CPDOMDisplayServerSetSize(_DOMContentsElement, width, height);
_DOMContentsElement.style.top = "0px";
_DOMContentsElement.style.left = "0px";
_DOMContentsElement.style.width = ROUND(CGRectGetWidth(_frame)) + "px";
_DOMContentsElement.style.height = ROUND(CGRectGetHeight(_frame)) + "px";
CPDOMDisplayServerSetStyleLeftTop(_DOMContentsElement, NULL, 0.0, 0.0);
CPDOMDisplayServerSetStyleSize(_DOMContentsElement, width, height);
// The performance implications of this aren't clear, but without this subviews might not be redrawn when this
// view moves.
@@ -2527,14 +2714,18 @@ setBoundsOrigin:
- (CPView)nextValidKeyView
{
var result = [self nextKeyView],
firstResult = result;
resultUID = [result UID],
unsuitableResults = {};
while (result && ![result canBecomeKeyView])
{
unsuitableResults[resultUID] = 1;
result = [result nextKeyView];
// Cycled.
if (result === firstResult)
resultUID = [result UID];
// Did we get back to a key view we already ruled out due to ![result canBecomeKeyView]?
if (unsuitableResults[resultUID])
return nil;
}
@@ -2660,6 +2851,40 @@ setBoundsOrigin:
@end
@implementation CPView (Scaling)
/*!
Set the zoom of the view. This will call scaleUnitSquareToSize: and setNeedsDisplay:
This method doesn't care about the last zoom you set in the view
@param aSize, the size corresponding the new unit scales
*/
- (void)setScaleSize:(CGSize)aSize
{
if (CGSizeEqualToSize(_scaleSize, aSize))
return;
var size = CGSizeMakeZero(),
scale = CGSizeMakeCopy([self scaleSize]);
size.height = aSize.height / scale.height;
size.width = aSize.width / scale.width;
[self scaleUnitSquareToSize:size];
[self setNeedsDisplay:YES];
}
/*!
Return the scaleSize of the view, this scaleSize is used to scale in css
*/
- (CGSize)scaleSize
{
return _scaleSize || CGSizeMake(1.0, 1.0);
}
@end
@implementation CPView (Theming)
#pragma mark Theme States
@@ -3038,7 +3263,10 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
CPViewWindowKey = @"CPViewWindowKey",
CPViewNextKeyViewKey = @"CPViewNextKeyViewKey",
CPViewPreviousKeyViewKey = @"CPViewPreviousKeyViewKey",
CPReuseIdentifierKey = @"CPReuseIdentifierKey";
CPReuseIdentifierKey = @"CPReuseIdentifierKey",
CPViewScaleKey = @"CPViewScaleKey",
CPViewSizeScaleKey = @"CPViewSizeScaleKey",
CPViewIsScaledKey = @"CPViewIsScaledKey";
@implementation CPView (CPCoding)
@@ -3055,6 +3283,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
// a more "elegant" way to do this...?
#if PLATFORM(DOM)
_DOMElement = DOMElementPrototype.cloneNode(false);
AppKitTagDOMElement(self, _DOMElement);
#endif
// Also decode these "early".
@@ -3104,13 +3333,17 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
if (_toolTip)
[self _installToolTipEventHandlers];
_scaleSize = [aCoder containsValueForKey:CPViewScaleKey] ? [aCoder decodeSizeForKey:CPViewScaleKey] : CGSizeMake(1.0, 1.0);
_hierarchyScaleSize = [aCoder containsValueForKey:CPViewSizeScaleKey] ? [aCoder decodeSizeForKey:CPViewSizeScaleKey] : CGSizeMake(1.0, 1.0);
_isScaled = [aCoder containsValueForKey:CPViewIsScaledKey] ? [aCoder decodeBoolForKey:CPViewIsScaledKey] : NO;
// DOM SETUP
#if PLATFORM(DOM)
_DOMImageParts = [];
_DOMImageSizes = [];
CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
CPDOMDisplayServerSetStyleSize(_DOMElement, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
[self _setDisplayServerSetStyleSize:_frame.size];
var index = 0,
count = _subviews.length;
@@ -3233,6 +3466,10 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
if (_identifier)
[aCoder encodeObject:_identifier forKey:CPReuseIdentifierKey];
[aCoder encodeSize:[self scaleSize] forKey:CPViewScaleKey];
[aCoder encodeSize:[self _hierarchyScaleSize] forKey:CPViewSizeScaleKey];
[aCoder encodeBool:_isScaled forKey:CPViewIsScaledKey];
}
@end
@@ -3262,12 +3499,26 @@ var _CPViewGetTransform = function(/*CPView*/ fromView, /*CPView */ toView)
{
var frame = view._frame;
if (view._isScaled)
{
var affineZoom = CGAffineTransformMakeScale(view._scaleSize.width, view._scaleSize.height);
CGAffineTransformConcatTo(transform, affineZoom, transform);
}
transform.tx += CGRectGetMinX(frame);
transform.ty += CGRectGetMinY(frame);
if (view._boundsTransform)
{
CGAffineTransformConcatTo(transform, view._boundsTransform, transform);
var inverseBoundsTransform = CGAffineTransformMakeCopy(view._boundsTransform);
if (view._isScaled)
{
var affineZoom = CGAffineTransformMakeScale(view._scaleSize.width, view._scaleSize.height);
CGAffineTransformConcatTo(inverseBoundsTransform, affineZoom, inverseBoundsTransform);
}
CGAffineTransformConcatTo(transform, inverseBoundsTransform, transform);
}
view = view._superview;
@@ -3275,50 +3526,64 @@ var _CPViewGetTransform = function(/*CPView*/ fromView, /*CPView */ toView)
// If we hit toView, then we're done.
if (view === toView)
{
return transform;
}
else if (fromView && toView)
{
fromWindow = [fromView window];
toWindow = [toView window];
if (fromWindow && toWindow && fromWindow !== toWindow)
{
sameWindow = NO;
var frame = [fromWindow frame];
transform.tx += CGRectGetMinX(frame);
transform.ty += CGRectGetMinY(frame);
}
}
}
// FIXME: For now we can do things this way, but eventually we need to do them the "hard" way.
var view = toView;
var view = toView,
transform2 = CGAffineTransformMakeIdentity();
while (view)
while (view && view != fromView)
{
var frame = view._frame;
var frame = CGRectMakeCopy(view._frame);
transform.tx -= CGRectGetMinX(frame);
transform.ty -= CGRectGetMinY(frame);
// FIXME : For now we don't care about rotate transform and so on
if (view._isScaled)
{
transform2.a *= 1 / view._scaleSize.width;
transform2.d *= 1 / view._scaleSize.height;
}
transform2.tx += CGRectGetMinX(frame) * transform2.a;
transform2.ty += CGRectGetMinY(frame) * transform2.d;
if (view._boundsTransform)
{
CGAffineTransformConcatTo(transform, view._inverseBoundsTransform, transform);
var inverseBoundsTransform = CGAffineTransformMakeIdentity();
inverseBoundsTransform.tx -= view._inverseBoundsTransform.tx * transform2.a;
inverseBoundsTransform.ty -= view._inverseBoundsTransform.ty * transform2.d;
CGAffineTransformConcatTo(transform2, inverseBoundsTransform, transform2);
}
view = view._superview;
}
if (!sameWindow)
{
var frame = [toWindow frame];
transform2.tx = -transform2.tx;
transform2.ty = -transform2.ty;
transform.tx -= CGRectGetMinX(frame);
transform.ty -= CGRectGetMinY(frame);
if (view === fromView)
{
// toView is inside of fromView
return transform2;
}
CGAffineTransformConcatTo(transform, transform2, transform);
return transform;
/* var views = [],
view = toView;
+1 -1
View File
@@ -105,7 +105,7 @@ CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOutEffect";
[super startAnimation];
}
- (void)setCurrentProgress:(CPAnimationProgress)progress
- (void)setCurrentProgress:(float)progress
{
[super setCurrentProgress:progress];
+61 -16
View File
@@ -248,7 +248,7 @@ CPTexturedBackgroundWindowMask
@param aStyleMask a style mask
@return the initialized window
*/
- (id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask
- (id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask
{
self = [super init];
@@ -735,6 +735,10 @@ CPTexturedBackgroundWindowMask
}
}
/*
Constrain a frame so that the window remains at least partially visible on screen,
moving or resizing the frame as necessary.
*/
- (CGRect)_constrainFrame:(CGRect)aFrame toUsableScreenWidth:(BOOL)constrainWidth andHeight:(BOOL)constrainHeight
{
var frame = CGRectMakeCopy(aFrame);
@@ -759,7 +763,7 @@ CPTexturedBackgroundWindowMask
if (CGRectGetWidth(frame) > usableWidth)
{
frame.origin.x = CGRectGetMinX(usableRect);
frame.size.width = usableWidth;
frame.size.width = MAX(usableWidth, _minSize.width);
}
}
@@ -778,13 +782,20 @@ CPTexturedBackgroundWindowMask
if (CGRectGetHeight(frame) > usableHeight)
{
frame.origin.y = CGRectGetMinY(usableRect);
frame.size.height = usableHeight;
frame.size.height = MAX(usableHeight, _minSize.height);
}
}
return frame;
}
/*
Constrain the origin of a frame such that:
- The window view's minimum resize width is kept onscreen at the left/right of the window.
- The top of the window is kept below the top of the usable content.
- The top of the contentView + CPWindowMinVisibleVerticalMargin is kept above the bottom of the usable content.
*/
- (CGRect)_constrainOriginOfFrame:(CGRect)aFrame
{
var frame = CGRectMakeCopy(aFrame);
@@ -792,19 +803,20 @@ CPTexturedBackgroundWindowMask
if (!_constrainsToUsableScreen || !_isVisible)
return frame;
/*
- CPWindowMinVisibleHorizontalMargin is kept onscreen at the left/right of the window.
- The top of the window is kept below the top of the usable content.
- The top of the contentView + CPWindowMinVisibleVerticalMargin is kept above the bottom of the usable content.
*/
var usableRect = [_platformWindow usableContentFrame],
maxUsableY = CGRectGetMaxY(usableRect) - CGRectGetMinY([_contentView frame]) - CPWindowMinVisibleVerticalMargin;
minimumSize = [_windowView _minimumResizeSize];
frame.origin.x = MAX(frame.origin.x, CGRectGetMinX(usableRect) + CPWindowMinVisibleHorizontalMargin - CGRectGetWidth(frame));
frame.origin.x = MIN(frame.origin.x, CGRectGetMaxX(usableRect) - CPWindowMinVisibleHorizontalMargin);
// First constrain x so that at least CPWindowMinVisibleHorizontalMargin is visible on the right
frame.origin.x = MAX(frame.origin.x, CGRectGetMinX(usableRect) + minimumSize.width - CGRectGetWidth(frame));
// Now constrain x so that at least CPWindowMinVisibleHorizontalMargin is visible on the left
frame.origin.x = MIN(frame.origin.x, CGRectGetMaxX(usableRect) - minimumSize.width);
// Now constrain y so that it is below the top of the usable content
frame.origin.y = MAX(frame.origin.y, CGRectGetMinY(usableRect));
frame.origin.y = MIN(frame.origin.y, maxUsableY);
// Finally constrain y so that at least CPWindowMinVisibleHorizontalMargin is visible at the bottom
frame.origin.y = MIN(frame.origin.y, CGRectGetMaxY(usableRect) - CGRectGetMinY([_contentView frame]) - CPWindowMinVisibleVerticalMargin);
return frame;
}
@@ -985,6 +997,7 @@ CPTexturedBackgroundWindowMask
[_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel];
_level = aLevel;
[_childWindows makeObjectsPerformSelector:@selector(setLevel:) withObject:_level];
if ([self _sharesChromeWithPlatformWindow])
[_platformWindow setLevel:aLevel];
@@ -1020,6 +1033,23 @@ CPTexturedBackgroundWindowMask
[[CPNotificationCenter defaultCenter] postNotificationName:CPWindowResizeStyleGlobalChangeNotification object:nil];
}
/*!
If set to NO, platform window (virtual screen) resizes will not attempt to move/resize user windows.
to the usable area.
*/
+ (void)setConstrainWindowsToUsableScreen:(BOOL)shouldConstrain
{
CPWindowConstrainToScreen = shouldConstrain;
}
/*!
Return whether platform window (virtual screen) resizes constrain user windows to the usable area.
*/
+ (BOOL)constrainWindowsToUsableScreen
{
return CPWindowConstrainToScreen;
}
- (void)_didReceiveResizeStyleChange:(CPNotification)aNotification
{
[_windowView setShowsResizeIndicator:_styleMask & CPResizableWindowMask];
@@ -1669,11 +1699,17 @@ CPTexturedBackgroundWindowMask
switch (type)
{
case CPLeftMouseDown:
// This is needed when a doubleClick occurs when the sheet is closing or opening
if (!_parentWindow)
return;
[_windowView mouseDown:anEvent];
// -dw- if the window is clicked, the sheet should come to front, and become key,
// and the window should be immediately behind
[sheet makeKeyAndOrderFront:self];
return;
case CPMouseMoved:
@@ -2465,7 +2501,7 @@ CPTexturedBackgroundWindowMask
// If this has an owner, dump it!
[[aToolbar _window] setToolbar:nil];
// This is no longer out toolbar.
// This is no longer our toolbar.
[_toolbar _setWindow:nil];
_toolbar = aToolbar;
@@ -2530,6 +2566,7 @@ CPTexturedBackgroundWindowMask
[childWindow setParentWindow:self];
[childWindow _setChildOrdering:orderingMode];
[childWindow setLevel:[self level]];
if ([self isVisible] && ![childWindow isVisible])
[childWindow orderWindow:orderingMode relativeTo:_windowNumber];
@@ -2755,14 +2792,21 @@ CPTexturedBackgroundWindowMask
}
// The sheet starts hidden just above the top of a clip rect
// TODO : Make properly for the -1 in endY
var sheetFrame = [sheet frame],
sheetShadowFrame = sheet._hasShadow ? [sheet._shadowView frame] : sheetFrame,
frame = [self frame],
originX = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width) / 2),
startFrame = CGRectMake(originX, -sheetShadowFrame.size.height, sheetFrame.size.width, sheetFrame.size.height),
endY = [_windowView bodyOffset] - [[self contentView] frame].origin.y,
endY = -1 + [_windowView bodyOffset] - [[self contentView] frame].origin.y,
endFrame = CGRectMake(originX, endY, sheetFrame.size.width, sheetFrame.size.height);
if (_toolbar && [_windowView showsToolbar] && [self isFullPlatformWindow])
{
endY += [[_toolbar _toolbarView] frameSize].height;
endFrame = CGRectMake(originX, endY, sheetFrame.size.width, sheetFrame.size.height);
}
// Move the sheet offscreen before ordering front so it doesn't appear briefly
[sheet setFrameOrigin:CGPointMake(0, -13000)];
@@ -3260,7 +3304,8 @@ var keyViewComparator = function(lhs, rhs, context)
if ([self isFullPlatformWindow])
return [self setFrame:[_platformWindow visibleFrame]];
if (_autoresizingMask === CPWindowNotSizable)
// If this window is constrainable and we are globally ignoring constraining, ignore the platform resize
if ((_constrainsToUsableScreen && !CPWindowConstrainToScreen) || _autoresizingMask === CPWindowNotSizable)
return;
var frame = [_platformWindow contentBounds],
@@ -3282,7 +3327,7 @@ var keyViewComparator = function(lhs, rhs, context)
if (_autoresizingMask & CPWindowHeightSizable)
newFrame.size.height += dY;
[self setFrame:newFrame];
[self _setFrame:newFrame display:YES animate:NO constrainWidth:YES constrainHeight:YES];
}
/*
+2
View File
@@ -194,3 +194,5 @@ CPStandardWindowShadowStyle = 0;
CPMenuWindowShadowStyle = 1;
CPPanelWindowShadowStyle = 2;
CPCustomWindowShadowStyle = 3;
CPWindowConstrainToScreen = YES;
@@ -32,7 +32,7 @@
return @"bordeless-bridge-window-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"toolbar-background-color": [CPColor grayColor],
+1 -1
View File
@@ -33,7 +33,7 @@
return @"doc-modal-window-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"body-color": [CPColor whiteColor],
+10 -10
View File
@@ -28,11 +28,7 @@
@global CPPopoverAppearanceMinimal
var _CPPopoverWindowViewDefaultCursorSize = CGSizeMake(16, 10),
_CPPopoverWindowViewRadius = 5.0,
_CPPopoverWindowViewStrokeWidth = 1.0,
_CPPopoverWindowViewShadowSize = CGSizeMake(0, 6),
_CPPopoverWindowViewShadowBlur = 15.0;
var _CPPopoverWindowViewDefaultCursorSize = CGSizeMake(16, 10);
/*!
@ignore
@@ -54,13 +50,17 @@ var _CPPopoverWindowViewDefaultCursorSize = CGSizeMake(16, 10),
return @"popover-window-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"background-gradient": [CPNull null],
@"background-gradient-hud": [CPNull null],
@"stroke-color": [CPNull null],
@"stroke-color-hud": [CPNull null],
@"border-radius": 5.0,
@"stroke-width": 1.0,
@"shadow-size": CGSizeMake(0, 6),
@"shadow-blur": 15.0
};
}
@@ -156,15 +156,15 @@ var _CPPopoverWindowViewDefaultCursorSize = CGSizeMake(16, 10),
[super drawRect:aRect];
var context = [[CPGraphicsContext currentContext] graphicsPort],
radius = _CPPopoverWindowViewRadius,
radius = [self valueForThemeAttribute:@"border-radius"],
arrowWidth = _cursorSize.width,
arrowHeight = _cursorSize.height,
strokeWidth = _CPPopoverWindowViewStrokeWidth,
strokeWidth = [self valueForThemeAttribute:@"stroke-width"],
halfStrokeWidth = strokeWidth / 2.0,
strokeColor,
shadowColor = [[CPColor blackColor] colorWithAlphaComponent:.2],
shadowSize = _CPPopoverWindowViewShadowSize,
shadowBlur = _CPPopoverWindowViewShadowBlur,
shadowSize = [self valueForThemeAttribute:@"shadow-size"],
shadowBlur = [self valueForThemeAttribute:@"shadow-blur"],
gradient,
frame = [self bounds];
+1 -1
View File
@@ -41,7 +41,7 @@
return @"shadow-window-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{};
}
+37 -10
View File
@@ -29,6 +29,8 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
@implementation _CPTexturedWindowHeadView : CPView
{
BOOL _isSheet @accessors(setter=setSheet:);
_CPWindowView _parentView;
CPView _gradientView;
CPView _solidView;
@@ -39,7 +41,7 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
return @"textured-window-head-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{};
}
@@ -66,10 +68,11 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
[super layoutSubviews];
var gradientHeight = [[CPTheme defaultTheme] valueForAttributeWithName:@"gradient-height" forClass:_CPStandardWindowView],
bounds = [self bounds];
bounds = [self bounds],
bezelHeadColor = [[CPTheme defaultTheme] valueForAttributeWithName:_isSheet ? @"bezel-head-sheet-color" : @"bezel-head-color" inState:[_parentView themeState] forClass:_CPStandardWindowView];
[_gradientView setFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), gradientHeight)];
[_gradientView setBackgroundColor:[[CPTheme defaultTheme] valueForAttributeWithName:@"bezel-head-color" inState:[_parentView themeState] forClass:_CPStandardWindowView]];
[_gradientView setBackgroundColor:bezelHeadColor];
[_solidView setFrame:CGRectMake(0.0, gradientHeight, CGRectGetWidth(bounds), CGRectGetHeight(bounds) - gradientHeight)];
[_solidView setBackgroundColor:[[CPTheme defaultTheme] valueForAttributeWithName:@"solid-color" forClass:_CPStandardWindowView]];
@@ -97,6 +100,7 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
CPButton _minimizeButton;
BOOL _isDocumentEdited;
BOOL _isSheet;
}
+ (CPString)defaultThemeClass
@@ -104,12 +108,13 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
return @"standard-window-view";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"gradient-height": [CPNull null],
@"solid-color": [CPNull null],
@"bezel-head-color": [CPNull null],
@"bezel-head-sheet-color": [CPNull null],
@"divider-color": [CPColor blackColor],
@"body-color": [CPColor whiteColor],
@"title-bar-height": 32,
@@ -224,7 +229,14 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
width = CGRectGetWidth(bounds),
headHeight = [self toolbarMaxY];
if (_isSheet && _toolbarView && [self showsToolbar])
{
headHeight = [_toolbarView frameSize].height;
[_toolbarView setFrameOrigin:CGPointMake(0.0, 0.0)];
}
[_headView setFrameSize:CGSizeMake(width, headHeight)];
[_dividerView setFrame:CGRectMake(0.0, headHeight, width, _CPStandardWindowViewDividerViewHeight)];
var dividerMinY = 0,
@@ -312,12 +324,26 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
{
[super _enableSheet:enable inWindow:parentWindow];
[_headView setHidden:enable];
[_dividerView setHidden:enable];
_isSheet = enable;
[_headView setSheet:enable];
if (_toolbarView && [self showsToolbar])
{
[_headView setHidden:NO];
[_dividerView setHidden:NO];
}
else
{
[_headView setHidden:enable];
[_dividerView setHidden:enable];
}
[_closeButton setHidden:enable];
[_minimizeButton setHidden:enable];
[_titleField setHidden:enable];
[[self window] setMovable:!enable];
if (enable)
{
[_bodyView setBackgroundColor:[[CPTheme defaultTheme] valueForAttributeWithName:@"body-color" forClass:_CPDocModalWindowView]];
@@ -333,12 +359,13 @@ var _CPStandardWindowViewDividerViewHeight = 1.0;
var theWindow = [self window],
frame = [theWindow frame],
dividerHeight = [_dividerView frame].size.height,
dy;
dy = [self toolbarMaxY] + dividerHeight;
if (_toolbarView && [self showsToolbar])
dy = [[CPTheme defaultTheme] valueForAttributeWithName:@"gradient-height" forClass:_CPStandardWindowView];
if (enable)
dy = -[_headView frame].size.height;
else
dy = [self toolbarMaxY] + dividerHeight;
dy = -dy;
var newHeight = CGRectGetHeight(frame) + dy,
newWidth = CGRectGetWidth(frame);
+1 -1
View File
@@ -38,7 +38,7 @@
return @"tooltip";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"stroke-color": [CPColor colorWithHexString:@"E3E3E3"],
+39 -5
View File
@@ -81,7 +81,7 @@ _CPWindowViewResizeSlop = 3;
return "window";
}
+ (id)themeAttributes
+ (CPDictionary)themeAttributes
{
return @{
@"title-bar-height": 25,
@@ -631,7 +631,38 @@ _CPWindowViewResizeSlop = 3;
newHeight = startHeight;
}
[theWindow _setFrame:CGRectMake(newX, newY, newWidth, newHeight) display:YES animate:NO constrainWidth:NO constrainHeight:NO];
// When resizing, we always constrain to the usable screen.
frame = CGRectMake(newX, newY, newWidth, newHeight);
var constrainedFrame = [theWindow _constrainOriginOfFrame:frame],
dx = constrainedFrame.origin.x - frame.origin.x,
dy = constrainedFrame.origin.y - frame.origin.y;
// When resizing from the left or top, we adjust the origin and size.
switch (_resizeRegion)
{
case _CPWindowViewResizeRegionBottomLeft:
case _CPWindowViewResizeRegionLeft:
case _CPWindowViewResizeRegionTopLeft:
case _CPWindowViewResizeRegionTop:
case _CPWindowViewResizeRegionTopRight:
frame.origin = constrainedFrame.origin;
frame.size.width -= dx;
frame.size.height -= dy;
}
// When resizing from the right or bottom, we only adjust the size.
switch (_resizeRegion)
{
case _CPWindowViewResizeRegionTopRight:
case _CPWindowViewResizeRegionRight:
case _CPWindowViewResizeRegionBottomRight:
case _CPWindowViewResizeRegionBottom:
frame.size.width += dx;
frame.size.height += dy;
}
[theWindow _setFrame:frame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
[self setCursorForLocation:location resizing:YES];
}
@@ -683,7 +714,7 @@ _CPWindowViewResizeSlop = 3;
[theWindow _setAttachedSheetFrameOrigin];
[sheet._windowView _adjustShadowViewSize];
}
else if (theWindow._isSheet)
else if (theWindow && theWindow._isSheet)
[self _adjustShadowViewSize];
}
@@ -742,7 +773,9 @@ _CPWindowViewResizeSlop = 3;
- (BOOL)showsToolbar
{
return YES;
var styleMaskWindow = [[self window] styleMask];
return styleMaskWindow & CPBorderlessWindowMask || styleMaskWindow & CPTitledWindowMask || styleMaskWindow & CPHUDBackgroundWindowMask || styleMaskWindow & CPBorderlessBridgeWindowMask;
}
- (CGSize)toolbarOffset
@@ -926,7 +959,8 @@ _CPWindowViewResizeSlop = 3;
- (CGSize)_minimumResizeSize
{
return CGSizeMake(0, _CPWindowViewMinContentHeight);
// Leave at least 4px so there is something visible.
return CGSizeMake(4, _CPWindowViewMinContentHeight);
}
- (int)bodyOffset
+5 -5
View File
@@ -63,8 +63,8 @@ var CPCibOwner = @"CPCibOwner";
+ (CPCib)loadCibFile:(CPString)anAbsolutePath externalNameTable:(CPDictionary)aNameTable loadDelegate:aDelegate
{
return ([[CPCib alloc]
initWithContentsOfURL:anAbsolutePath
loadDelegate:[[_CPCibLoadDelegate alloc]
initWithContentsOfURL:anAbsolutePath
loadDelegate:[[_CPCibLoadDelegate alloc]
initWithLoadDelegate:aDelegate
externalNameTable:aNameTable]]);
}
@@ -84,9 +84,9 @@ var CPCibOwner = @"CPCibOwner";
- (CPCib)loadCibFile:(CPString)aFileName externalNameTable:(CPDictionary)aNameTable loadDelegate:(id)aDelegate
{
return ([[CPCib alloc]
initWithCibNamed:aFileName
bundle:self
loadDelegate:[[_CPCibLoadDelegate alloc]
initWithCibNamed:aFileName
bundle:self
loadDelegate:[[_CPCibLoadDelegate alloc]
initWithLoadDelegate:aDelegate
externalNameTable:aNameTable]]);
}
+24 -6
View File
@@ -35,7 +35,10 @@
var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
_CPCibCustomResourceResourceNameKey = @"_CPCibCustomResourceResourceNameKey",
_CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey";
_CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey",
_CPCibCustomResourceTemplateImageMap = nil;
@implementation _CPCibCustomResource : CPObject
{
@@ -45,6 +48,16 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
CPBundle _bundle;
}
+ (void)initialize
{
if (self !== [_CPCibCustomResource class])
return;
_CPCibCustomResourceTemplateImageMap = @{
"CPAddTemplate": "button-image-plus",
"CPRemoveTemplate": "button-image-minus"
};
}
+ (id)imageResourceWithName:(CPString)aResourceName size:(CGSize)aSize
{
return [[self alloc] initWithClassName:@"CPImage" resourceName:aResourceName properties:@{ @"size": aSize }];
@@ -98,12 +111,12 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
(![aCoder respondsToSelector:@selector(awakenCustomResources)] || [aCoder awakenCustomResources]))
if (_className === @"CPImage")
{
if (_resourceName == "CPAddTemplate")
return [[CPTheme defaultTheme] valueForAttributeWithName:@"button-image-plus" forClass:[CPButtonBar class]];
else if (_resourceName == "CPRemoveTemplate")
return [[CPTheme defaultTheme] valueForAttributeWithName:@"button-image-minus" forClass:[CPButtonBar class]];
var templateImage = [_CPCibCustomResourceTemplateImageMap objectForKey:_resourceName];
return [self imageFromCoder:aCoder];
if (templateImage)
return [[CPTheme defaultTheme] valueForAttributeWithName:templateImage forClass:[CPButtonBar class]];
else
return [self imageFromCoder:aCoder];
}
return self;
@@ -176,6 +189,11 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
return [_properties objectForKey:@"size"];
}
- (BOOL)isSingleImage
{
return YES;
}
- (BOOL)isThreePartImage
{
return NO;
+1 -1
View File
@@ -48,7 +48,7 @@
@end
var _CPCibCustomViewClassNameKey = @"_CPCibCustomViewClassNameKey";
var _CPCibCustomViewClassNameKey = @"_CPCibCustomViewClassNameKey";
@implementation _CPCibCustomView (CPCoding)
+13 -9
View File
@@ -87,12 +87,17 @@
- (id)_cibInstantiate
{
var windowClass = CPClassFromString([self windowClass]),
theWindow = [[windowClass alloc] initWithContentRect:_windowRect styleMask:_windowStyleMask];
var windowClass = CPClassFromString([self windowClass]);
/* if (!windowClass)
[NSException raise:NSInvalidArgumentException format:@"Unable to locate NSWindow class %@, using NSWindow",_windowClass];
class=[NSWindow class];*/
if (!windowClass)
{
#if DEBUG
CPLog.warn("Unknown class \"%@\" in cib file, using CPWindow instead.", [self windowClass]);
#endif
windowClass = [CPWindow class];
}
var theWindow = [[windowClass alloc] initWithContentRect:_windowRect styleMask:_windowStyleMask];
if (_minSize)
[theWindow setMinSize:_minSize];
@@ -103,12 +108,11 @@
//[result setHidesOnDeactivate:(_wtFlags&0x80000000)?YES:NO];
[theWindow setTitle:_windowTitle];
// FIXME: we can't autoresize yet...
var contentViewAutoresizesSubviews = [_windowView autoresizesSubviews];
[_windowView setAutoresizesSubviews:NO];
[theWindow setContentView:_windowView];
[_windowView setAutoresizesSubviews:YES];
[_windowView setAutoresizesSubviews:contentViewAutoresizesSubviews];
if ([_viewClass isKindOfClass:[CPToolbar class]])
[theWindow setToolbar:_viewClass];
+1 -1
View File
@@ -687,7 +687,7 @@ if (_DOMContentsElement && aLayer._zPosition > _DOMContentsElement.style.zIndex)
@param aLayer the layer to insert
@param anIndex the index to insert the layer at
*/
- (void)insertSublayer:(CALayer)aLayer atIndex:(unsigned)anIndex
- (void)insertSublayer:(CALayer)aLayer atIndex:(CPUInteger)anIndex
{
if (!aLayer)
return;
+1 -1
View File
@@ -75,7 +75,7 @@ var CAMediaNamedTimingFunctions = nil;
return self;
}
- (void)getControlPointAtIndex:(unsigned)anIndex values:(float/*[2]*/)reference
- (void)getControlPointAtIndex:(CPUInteger)anIndex values:(float/*[2]*/)reference
{
if (anIndex == 0)
{
+19 -6
View File
@@ -43,7 +43,7 @@ var CANVAS_LINECAP_TABLE = [ "butt", "round", "square" ],
#define _CGContextFillRectCanvas(aContext, aRect) aContext.fillRect(CGRectGetMinX(aRect), CGRectGetMinY(aRect), CGRectGetWidth(aRect), CGRectGetHeight(aRect))
#define _CGContextClipCanvas(aContext) aContext.clip()
// In Cocoa, all primitives excepts rects cannot be added to the context's path
// In Cocoa, all primitives excepts rects and arcs cannot be added to the context's path
// until a move to point has been done, because an empty path has no current point.
var hasPath = function(aContext, methodName)
{
@@ -113,12 +113,12 @@ function CGContextSetBlendMode(aContext, aBlendMode)
function CGContextAddArc(aContext, x, y, radius, startAngle, endAngle, clockwise)
{
if (!hasPath(aContext, "CGContextAddArc"))
return;
// Despite the documentation saying otherwise, the last parameter is anti-clockwise not clockwise.
// http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes#Arcs
_CGContextAddArcCanvas(aContext, x, y, radius, startAngle, endAngle, !clockwise);
// AddArc implicitly starts a path
aContext.hasPath = YES;
}
function CGContextAddArcToPoint(aContext, x1, y1, x2, y2, radius)
@@ -470,7 +470,7 @@ var scale_rotate = function(a, b, c, d)
var rotate_scale = function(a, b, c, d)
{
var sign = (a * d < 0.0 || b * c > 0.0) ? -1.0 : 1.0;
var sign = (a * d < 0.0 || b * c > 0.0) ? -1.0 : 1.0,
a1 = (ATAN2(sign * b, sign * a) + ATAN2(-c, d)) / 2.0,
cos = COS(a1),
sin = SIN(a1);
@@ -596,7 +596,6 @@ function CGContextDrawLinearGradient(aContext, aGradient, aStartPoint, anEndPoin
{
var colors = aGradient.colors,
count = colors.length,
linearGradient = aContext.createLinearGradient(aStartPoint.x, aStartPoint.y, anEndPoint.x, anEndPoint.y);
while (count--)
@@ -607,6 +606,20 @@ function CGContextDrawLinearGradient(aContext, aGradient, aStartPoint, anEndPoin
aContext.hasPath = NO;
}
function CGContextDrawRadialGradient(aContext, aGradient, aStartCenter, aStartRadius, anEndCenter, anEndRadius, options)
{
var colors = aGradient.colors,
count = colors.length,
linearGradient = aContext.createRadialGradient(aStartCenter.x, aStartCenter.y, aStartRadius, anEndCenter.x, anEndCenter.y, anEndRadius);
while (count--)
linearGradient.addColorStop(aGradient.locations[count], to_string(colors[count]));
aContext.fillStyle = linearGradient;
aContext.fill();
aContext.hasPath = NO;
}
function CGBitmapGraphicsContextCreate()
{
var DOMElement = document.createElement("canvas"),
+26 -8
View File
@@ -120,12 +120,14 @@ function CGPathAddArc(aPath, aTransform, x, y, aRadius, aStartAngle, anEndAngle,
The ending point of the arc becomes the new current point of the path.
*/
var arcEndX = x + aRadius * COS(anEndAngle),
arcEndY = y + aRadius * SIN(anEndAngle);
arcEndY = y + aRadius * SIN(anEndAngle),
arcStartX = x + aRadius * COS(aStartAngle),
arcStartY = y + aRadius * SIN(aStartAngle);
if (aPath.count)
{
if (aPath.current.x !== arcEndX || aPath.current.y !== arcEndY)
CGPathAddLineToPoint(aPath, aTransform, arcEndX, arcEndY);
if (aPath.current.x !== x || aPath.current.y !== y)
CGPathAddLineToPoint(aPath, aTransform, arcStartX, arcStartY);
}
else
{
@@ -136,7 +138,7 @@ function CGPathAddArc(aPath, aTransform, x, y, aRadius, aStartAngle, anEndAngle,
}
aPath.current = CGPointMake(arcEndX, arcEndY);
aPath.elements[aPath.count++] = { type:kCGPathElementAddArc, x:x, y:y, radius:aRadius, startAngle:aStartAngle, endAngle:anEndAngle, clockwise:isClockwise };
aPath.elements[aPath.count++] = { type:kCGPathElementAddArc, x:x, y:y, radius:aRadius, startAngle:aStartAngle, endAngle:anEndAngle, isClockwise:isClockwise };
}
function CGPathAddArcToPoint(aPath, aTransform, x1, y1, x2, y2, aRadius)
@@ -233,7 +235,7 @@ function CGPathAddPath(aPath, aTransform, anotherPath)
case kCGPathElementAddArc:
CGPathAddArc(aPath, aTransform, element.x, element.y,
element.radius, element.startAngle,
element.endAngle, element.clockwise);
element.endAngle, element.isClockwise);
break;
case kCGPathElementAddArcToPoint:
@@ -438,7 +440,7 @@ function CGPathEqualToPath(aPath, anotherPath)
element.radius !== anotherElement.radius ||
element.startAngle !== anotherElement.startAngle ||
element.endAngle !== anotherElement.endAngle ||
element.clockwise !== anotherElement.clockwise)
element.isClockwise !== anotherElement.isClockwise)
{
return NO;
}
@@ -608,7 +610,23 @@ function CGPathGetBoundingBox(aPath)
return CGRectMake(ox, oy, rx - ox, ry - oy);
}
function CGPathContainsPoint(aPath, aTransform, point, eoFill)
{
if (!aPath.count)
return NO;
if (aTransform)
point = CGPointApplyAffineTransform(point, aTransform);
var context = CGBitmapGraphicsContextCreate();
CGContextBeginPath(context);
CGContextAddPath(context, aPath);
CGContextClosePath(context);
return context.isPointInPath(point.x, point.y);
}
/*!
@}
*/
*/
+27 -30
View File
@@ -26,6 +26,7 @@
@import "CPPlatform.j"
@class CPMenu
@class CPPlatformPasteboard
@global CPApp
@@ -33,46 +34,42 @@ var PrimaryPlatformWindow = NULL;
@implementation CPPlatformWindow : CPObject
{
CGRect _contentRect;
CGRect _contentRect;
CPInteger _level;
BOOL _hasShadow;
unsigned _shadowStyle;
CPString _title;
CPInteger _level;
BOOL _hasShadow;
unsigned _shadowStyle;
CPString _title;
#if PLATFORM(DOM)
DOMWindow _DOMWindow;
DOMWindow _DOMWindow;
DOMElement _DOMBodyElement;
DOMElement _DOMFocusElement;
DOMElement _DOMEventGuard;
DOMElement _DOMScrollingElement;
id _hideDOMScrollingElementTimeout;
DOMElement _DOMBodyElement;
DOMElement _DOMFocusElement;
DOMElement _DOMEventGuard;
DOMElement _DOMScrollingElement;
id _hideDOMScrollingElementTimeout;
CPArray _windowLevels;
CPDictionary _windowLayers;
CPArray _windowLevels;
CPDictionary _windowLayers;
BOOL _mouseIsDown;
BOOL _mouseDownIsRightClick;
CGPoint _lastMouseEventLocation;
CPWindow _mouseDownWindow;
CPTimeInterval _lastMouseUp;
CPTimeInterval _lastMouseDown;
BOOL _mouseIsDown;
BOOL _mouseDownIsRightClick;
CGPoint _lastMouseEventLocation;
CPWindow _mouseDownWindow;
CPTimeInterval _lastMouseUp;
CPTimeInterval _lastMouseDown;
Object _charCodes;
unsigned _keyCode;
unsigned _lastKey;
BOOL _capsLockActive;
BOOL _ignoreNativeCopyOrCutEvent;
BOOL _ignoreNativePastePreparation;
Object _charCodes;
unsigned _keyCode;
unsigned _lastKey;
BOOL _capsLockActive;
BOOL _DOMEventMode;
BOOL _DOMEventMode;
// Native Pasteboard Support
DOMElement _DOMPasteboardElement;
CPEvent _pasteboardKeyDownEvent;
CPPlatformPasteboard _platformPasteboard;
CPString _overriddenEventType;
CPString _overriddenEventType;
#endif
}
+2 -1
View File
@@ -23,6 +23,7 @@
@import <Foundation/CPArray.j>
@import <Foundation/CPObject.j>
@import "CGGeometry.j"
@implementation CPDOMWindowLayer : CPObject
{
@@ -78,7 +79,7 @@
aWindow._isVisible = NO;
}
- (void)insertWindow:(CPWindow)aWindow atIndex:(unsigned)anIndex
- (void)insertWindow:(CPWindow)aWindow atIndex:(CPUInteger)anIndex
{
// We will have to adjust the z-index of all windows starting at this index.
var count = [_windows count],
+528
View File
@@ -0,0 +1,528 @@
/*
* CPPlatformPasteboard.j
* AppKit
*
* Created by Alexander Ljungberg.
* Copyright 2013, SlevenBits Ltd.
*
* 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/CPRunLoop.j>
@import "CPCompatibility.j"
@import "CPEvent.j"
@import "CPPasteboard.j"
@import "CPPlatform.j"
@import "CPPlatformWindow+DOMKeys.j"
@global CPApp
@global CPPlatformWindow
// From CPPlatformWindow+DOM.j
@global _CPDOMEventStop
#if PLATFORM(DOM)
#define SUPPRESS_CAPPUCCINO_CUT_FOR_EVENT(anEvent) anEvent._suppressCappuccinoCut = YES
#define SUPPRESS_CAPPUCCINO_PASTE_FOR_EVENT(anEvent) anEvent._suppressCappuccinoPaste = YES
var hasEditableTarget = function(aDOMEvent)
{
var target = aDOMEvent.target || aDOMEvent.srcElement;
if (!target)
return NO;
if (target.contentEditable == "true")
return YES;
var nodeName = target.nodeName.toUpperCase();
return nodeName === "INPUT" || nodeName == "TEXTAREA";
}
/*
* This class encapsulates copy and paste related functionality for the
* DOM environment. While originally all of this code was apread out in a
* dozen places in CPPlatformWindow+DOM.j, this class serves to collect
* and isolate that code for easier testing and maintenance.
*/
@implementation CPPlatformPasteboard : CPObject
{
DOMWindow _DOMWindow;
DOMElement _DOMPasteboardElement;
BOOL supportsNativeCopyAndPaste;
BOOL hasBugWhichPreventsNonEditablePaste;
BOOL hasBugWhichPreventsNonEditablePasteRedirect;
CPEvent _lastKeyDownEvent;
BOOL currentEventIsNativePasteEvent;
BOOL currentEventIsNativeCopyOrCutEvent;
BOOL currentEventShouldBeSuppressed;
BOOL currentEventShouldDefinitelyBubble;
BOOL currentEventShouldDefinitelyNotBubble;
BOOL _ignoreNativeCopyOrCutEvent;
BOOL _ignoreNativePastePreparation;
}
- (id)init
{
if (self = [super init])
{
supportsNativeCopyAndPaste = CPFeatureIsCompatible(CPJavaScriptClipboardEventsFeature);
hasBugWhichPreventsNonEditablePaste = CPPlatformHasBug(CPJavaScriptPasteRequiresEditableTarget);
hasBugWhichPreventsNonEditablePasteRedirect = CPPlatformHasBug(CPJavaScriptPasteCantRefocus);
}
return self;
}
- (void)setDOMWindow:(DOMWindow)aDOMWindow
{
if (_DOMWindow === aDOMWindow)
return;
if (_DOMWindow)
[self destroyDOMElements];
_DOMWindow = aDOMWindow;
if (_DOMWindow)
[self createDOMElements];
}
- (void)createDOMElements
{
var theDocument = _DOMWindow.document,
_DOMBodyElement = theDocument.getElementById("cappuccino-body") || theDocument.body;
// Create Native Pasteboard handler.
_DOMPasteboardElement = theDocument.createElement("textarea");
_DOMPasteboardElement.style.position = "absolute";
_DOMPasteboardElement.style.top = "-10000px";
_DOMPasteboardElement.style.zIndex = "999";
_DOMPasteboardElement.className = "cpdontremove";
_DOMBodyElement.appendChild(_DOMPasteboardElement);
_DOMPasteboardElement.blur();
var copyEventCallback = function (anEvent) { return [self beforeCopyEvent:anEvent]; },
nativeBeforeClipboardEventCallback = function (anEvent) { return [self nativeBeforeClipboardEvent:anEvent]; },
nativeCopyOrCutEventCallback = function (anEvent) { return [self nativeCopyOrCutEvent:anEvent]; },
pasteEventCallback = function (anEvent) { return [self beforePasteEvent:anEvent]; },
nativePasteEventCallback = function (anEvent) { return [self nativePasteEvent:anEvent]; };
if (theDocument.addEventListener)
{
if (supportsNativeCopyAndPaste)
{
_DOMWindow.addEventListener("beforecopy", nativeBeforeClipboardEventCallback, NO);
_DOMWindow.addEventListener("beforecut", nativeBeforeClipboardEventCallback, NO);
_DOMWindow.addEventListener("beforepaste", nativeBeforeClipboardEventCallback, NO);
_DOMWindow.addEventListener("copy", nativeCopyOrCutEventCallback, NO);
_DOMWindow.addEventListener("cut", nativeCopyOrCutEventCallback, NO);
_DOMWindow.addEventListener("paste", nativePasteEventCallback, NO);
}
else
{
theDocument.addEventListener("beforepaste", pasteEventCallback, NO);
theDocument.addEventListener("beforecopy", copyEventCallback, NO);
theDocument.addEventListener("beforecut", copyEventCallback, NO);
}
_DOMWindow.addEventListener("unload", function()
{
if (supportsNativeCopyAndPaste)
{
_DOMWindow.removeEventListener("beforecopy", nativeBeforeClipboardEventCallback, NO);
_DOMWindow.removeEventListener("beforecut", nativeBeforeClipboardEventCallback, NO);
_DOMWindow.removeEventListener("beforepaste", nativeBeforeClipboardEventCallback, NO);
_DOMWindow.removeEventListener("copy", nativeCopyOrCutEventCallback, NO);
_DOMWindow.removeEventListener("cut", nativeCopyOrCutEventCallback, NO);
_DOMWindow.removeEventListener("paste", nativePasteEventCallback, NO);
}
else
{
theDocument.removeEventListener("beforepaste", pasteEventCallback, NO);
theDocument.removeEventListener("beforecopy", copyEventCallback, NO);
theDocument.removeEventListener("beforecut", copyEventCallback, NO);
}
}, NO);
}
else
{
// TODO If we wanted IE 8 and lower copy and paste it'd go here.
}
}
- (void)destroyDOMElements
{
var theDocument = _DOMWindow.document,
_DOMBodyElement = theDocument.getElementById("cappuccino-body") || theDocument.body;
_DOMBodyElement.removeChild(_DOMPasteboardElement);
_DOMPasteboardElement = nil;
}
- (void)windowMaySendKeyEvent:(CPEvent)anEvent
{
// Reset our opinions.
currentEventIsNativePasteEvent = NO;
currentEventIsNativeCopyOrCutEvent = NO;
currentEventShouldBeSuppressed = NO;
currentEventShouldDefinitelyNotBubble = NO;
currentEventShouldDefinitelyBubble = NO;
if (!anEvent)
return;
if ([anEvent type] !== CPKeyDown)
{
// Reset these flags on key up.
_ignoreNativePastePreparation = NO;
_ignoreNativeCopyOrCutEvent = NO;
return;
}
var modifierFlags = [anEvent modifierFlags];
if (!(modifierFlags & (CPControlKeyMask | CPCommandKeyMask)))
return;
_lastKeyDownEvent = anEvent;
var aDOMEvent = anEvent._DOMEvent,
characters = [anEvent characters],
mayRequireDOMPasteboardElement = [self _mayRequireDOMPasteboardElementHack:aDOMEvent flags:modifierFlags];
if (characters === "v" && mayRequireDOMPasteboardElement)
{
if (supportsNativeCopyAndPaste && hasBugWhichPreventsNonEditablePaste && hasBugWhichPreventsNonEditablePasteRedirect && !hasEditableTarget(aDOMEvent))
{
// You can't paste from the system clipboard into a non-editable area in Safari, neither using native
// copy and paste nor our _DOMPasteboardElement hack. We will paste from the Cappuccino pasteboard only
// and allow Safari to "beep" to indicate something went wrong.
// The key down will not result in a paste event being sent by Safari, so it's not a paste event.
currentEventIsNativePasteEvent = NO;
// Yes to get the beep.
currentEventShouldDefinitelyBubble = YES;
}
else if (!(supportsNativeCopyAndPaste || hasBugWhichPreventsNonEditablePaste) && !_ignoreNativePastePreparation)
{
// We don't support native copy and paste so we must focus the _DOMPasteboardElement to receive the
// paste content. This needs to be done at keyDown time (or in the case of modern Safari, before the keyDown,
// which unfortunately isn't possible. See above.)
_DOMPasteboardElement.focus();
_DOMPasteboardElement.select();
_DOMPasteboardElement.value = "";
_DOMWindow.setNativeTimeout(function () { [self _checkDOMPasteboardElement]; }, 0);
currentEventIsNativePasteEvent = YES;
}
else if (supportsNativeCopyAndPaste)
currentEventIsNativePasteEvent = YES;
if (currentEventIsNativePasteEvent)
{
// We need the event to propagate or nothing will be pasted.
currentEventShouldDefinitelyBubble = YES;
// And we don't send the keydown because either our native paste envent handler will send it,
// or the _checkDOMPasteboardElement check will.
currentEventShouldBeSuppressed = YES;
}
}
else if ((characters == "c" || characters == "x") && mayRequireDOMPasteboardElement)
{
currentEventIsNativeCopyOrCutEvent = YES;
// If _ignoreNativeCopyOrCutEvent, we already handled the copy/cut in beforeCopyEvent:.
// If supportsNativeCopyAndPaste, we will be handling it in the nativebeforeCopyEvent: handler.
// In both of those cases we don't want to send the event on keydown too, or we'll get 2X copy/cut operations.
if (supportsNativeCopyAndPaste || _ignoreNativeCopyOrCutEvent)
currentEventShouldBeSuppressed = YES;
}
if (!currentEventShouldBeSuppressed)
{
if (characters === "v")
SUPPRESS_CAPPUCCINO_PASTE_FOR_EVENT(anEvent);
else if (characters === "x")
SUPPRESS_CAPPUCCINO_CUT_FOR_EVENT(anEvent);
}
}
- (BOOL)windowShouldSuppressKeyEvent
{
return currentEventShouldBeSuppressed;
}
- (void)windowDidSendKeyEvent:(CPEvent)anEvent
{
// Now that the copy event has been sent through the Cappuccino event stack, we can load any Cappuccino
// pasteboard string into our DOMPasteboardElement hack, if necessary.
if (!supportsNativeCopyAndPaste && currentEventIsNativeCopyOrCutEvent)
[self _primeDOMPasteboardElement];
}
- (BOOL)windowShouldStopPropagation
{
return currentEventShouldDefinitelyNotBubble;
}
- (BOOL)windowShouldNotStopPropagation
{
return currentEventShouldDefinitelyBubble;
}
- (CPEvent)_fakeClipboardEvent:(DOMEvent)aDOMEvent type:(CPString)aType
{
var keyCode = aType === "x" ? CPKeyCodes.X : (aType === "c" ? CPKeyCodes.C : CPKeyCodes.V),
characters = aType,
timestamp = [CPEvent currentTimestamp], // fake event, might as well use current timestamp
windowNumber = [[CPApp keyWindow] windowNumber],
modifierFlags = CPPlatformActionKeyMask,
location = [_lastKeyDownEvent locationInWindow],
anEvent = [CPEvent keyEventWithType:CPKeyDown location:location modifierFlags:modifierFlags
timestamp:timestamp windowNumber:windowNumber context:nil
characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode];
anEvent._data1 = @{ "simulated": YES };
anEvent._DOMEvent = aDOMEvent;
return anEvent;
}
- (void)beforeCopyEvent:(DOMEvent)aDOMEvent
{
if ([self _mayRequireDOMPasteboardElementHack:aDOMEvent flags:CPPlatformActionKeyMask] && !_ignoreNativeCopyOrCutEvent)
{
// we have to send out a fake copy or cut event so that we can force the copy/cut mechanisms to take place
var anEvent = [self _fakeClipboardEvent:aDOMEvent type:(aDOMEvent.type === "beforecut" ? "x" : "c")];
[CPApp sendEvent:anEvent];
// Once we've sent it, we can load the copy information into the pasteboard hack.
[self _primeDOMPasteboardElement];
//then we have to IGNORE the real keyboard event to prevent a double copy
//safari also sends the beforecopy event twice, so we additionally check here and prevent two events
_ignoreNativeCopyOrCutEvent = YES;
}
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
- (boolean)beforePasteEvent:(DOMEvent)aDOMEvent
{
// Set up to capture the paste in a temporary input field. We'll send the event after capture.
if ([self _mayRequireDOMPasteboardElementHack:aDOMEvent flags:CPPlatformActionKeyMask])
{
_DOMPasteboardElement.focus();
_DOMPasteboardElement.select();
_DOMPasteboardElement.value = "";
_ignoreNativePastePreparation = YES;
}
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
/*
Return true if the event may be a copy and paste event, but the target is not an input or text area.
*/
- (void)_mayRequireDOMPasteboardElementHack:(DOMEvent)aDOMEvent flags:(unsigned)modifierFlags
{
return !hasEditableTarget(aDOMEvent) && (modifierFlags & CPPlatformActionKeyMask);
}
- (void)_primeDOMPasteboardElement
{
var pasteboard = [CPPasteboard generalPasteboard],
types = [pasteboard types];
if (types.length)
{
if ([types indexOfObjectIdenticalTo:CPStringPboardType] !== CPNotFound)
_DOMPasteboardElement.value = [pasteboard stringForType:CPStringPboardType];
else
_DOMPasteboardElement.value = [pasteboard _generateStateUID];
_DOMPasteboardElement.focus();
_DOMPasteboardElement.select();
window.setNativeTimeout(function() { [self _clearDOMPasteboardElement]; }, 0);
}
}
- (void)_checkDOMPasteboardElement
{
if (supportsNativeCopyAndPaste)
{
[self _clearDOMPasteboardElement];
return;
}
var value = _DOMPasteboardElement.value;
if ([value length])
{
var pasteboard = [CPPasteboard generalPasteboard];
if ([pasteboard _stateUID] != value)
{
[pasteboard declareTypes:[CPStringPboardType] owner:self];
[pasteboard setString:value forType:CPStringPboardType];
}
}
[self _clearDOMPasteboardElement];
[CPApp sendEvent:[self _fakeClipboardEvent:nil type:@"v"]];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
- (void)_clearDOMPasteboardElement
{
_DOMPasteboardElement.value = "";
_DOMPasteboardElement.blur();
}
- (boolean)nativeBeforeClipboardEvent:(DOMEvent)aDOMEvent
{
// Our job here is to return "false" if the given clipboard operation should be enabled even in a situation where
// the browser might normally grey the option out.
// Allow these fields to do their own thing.
if (hasEditableTarget(aDOMEvent))
return true;
var returnValue = YES;
switch (aDOMEvent.type)
{
case "beforecopy":
returnValue = !([CPApp targetForAction:@selector(copy:)]);
break;
case "beforecut":
returnValue = !([CPApp targetForAction:@selector(cut:)]);
break;
case "beforepaste":
returnValue = !([CPApp targetForAction:@selector(paste:)]);
break;
}
if (!returnValue)
_CPDOMEventStop(aDOMEvent, self);
return returnValue;
}
- (boolean)nativePasteEvent:(DOMEvent)aDOMEvent
{
// This shouldn't happen.
if (!supportsNativeCopyAndPaste)
return;
var value;
if (aDOMEvent.clipboardData && aDOMEvent.clipboardData.setData)
value = aDOMEvent.clipboardData.getData('text/plain');
else
value = _DOMWindow.clipboardData.getData("Text");
if ([value length])
{
var pasteboard = [CPPasteboard generalPasteboard];
if ([pasteboard _stateUID] != value)
{
[pasteboard declareTypes:[CPStringPboardType] owner:self];
[pasteboard setString:value forType:CPStringPboardType];
}
}
var anEvent = [self _fakeClipboardEvent:aDOMEvent type:"v"],
platformWindow = [[anEvent window] platformWindow];
SUPPRESS_CAPPUCCINO_PASTE_FOR_EVENT(anEvent);
// By default we'll stop the native handling of the event since we're handling it ourselves. However, we need to
// stop it before we send the event so that the event can overrule our choice. CPTextField for instance wants the
// default handling when focused (which is to insert into the field).
[platformWindow _propagateCurrentDOMEvent:NO]
[CPApp sendEvent:anEvent];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
if (![platformWindow _willPropagateCurrentDOMEvent])
_CPDOMEventStop(aDOMEvent, self);
return false;
}
- (boolean)nativeCopyOrCutEvent:(DOMEvent)aDOMEvent
{
// This shouldn't happen.
if (!supportsNativeCopyAndPaste)
return;
var anEvent = [self _fakeClipboardEvent:aDOMEvent type:(aDOMEvent.type.indexOf("cut") != CPNotFound ? "x" : "c")],
platformWindow = [[anEvent window] platformWindow];
SUPPRESS_CAPPUCCINO_CUT_FOR_EVENT(anEvent);
[platformWindow _propagateCurrentDOMEvent:NO]
// Let the app react through copy: and cut: actions.
[CPApp sendEvent:anEvent];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
// If StopDOMEventPropagation was set to NO, we don't try to write to the system clipboard. The control that did this
// wants to use the default copy/cut functionality.
if (![platformWindow _willPropagateCurrentDOMEvent])
{
// Now the app should have written whatever it wants to have copied to the Cappuccino clipboard. So now we need
// to write it to the system board.
_CPDOMEventStop(aDOMEvent, self);
var pasteboard = [CPPasteboard generalPasteboard];
if ([[pasteboard types] containsObject:CPStringPboardType])
{
var stringValue = [pasteboard stringForType:CPStringPboardType];
if (aDOMEvent.clipboardData && aDOMEvent.clipboardData.setData)
aDOMEvent.clipboardData.setData('text/plain', stringValue);
else
_DOMWindow.clipboardData.setData('Text', stringValue);
}
}
return ![platformWindow _willPropagateCurrentDOMEvent];
}
@end
#endif
+2 -2
View File
@@ -53,7 +53,7 @@ var DOMFixedWidthSpanElement = nil,
style = DOMFlexibleWidthSpanElement.style;
style.position = "absolute";
style.left = "-100000px";
style.zIndex = -100000;
style.zIndex = -10000;
style.visibility = "visible";
style.padding = "0px";
style.margin = "0px";
@@ -99,7 +99,7 @@ var DOMFixedWidthSpanElement = nil,
DOMMetricsDivElement.className = "cpdontremove";
style = DOMMetricsDivElement.style;
style.position = "absolute";
style.left = "-10000px";
style.left = "-100000px";
style.zIndex = -10000;
style.width = "100000px";
style.whiteSpace = "nowrap";
+90 -190
View File
@@ -107,27 +107,29 @@
* P: undefined 80 undefined
*/
@import <Foundation/CPNotificationCenter.j>
@import <Foundation/CPObject.j>
@import <Foundation/CPRunLoop.j>
@import <Foundation/CPSet.j>
@import <Foundation/CPTimer.j>
@import "CPCursor.j"
@import "CPApplication_Constants.j"
@import "CPCompatibility.j"
@import "CPCursor.j"
@import "CPDOMWindowLayer.j"
@import "CPDragServer_Constants.j"
@import "CPEvent.j"
@import "CPPasteboard.j"
@import "CPPlatform.j"
@import "CPPlatformWindow.j"
@import "CPPlatformPasteboard.j"
@import "CPPlatformWindow+DOMKeys.j"
@import "CPPlatformWindow.j"
@import "CPText.j"
@import "CPWindow_Constants.j"
@class CPDragServer
@class _CPToolTip
@global CPApp
@global _CPRunModalLoop
// List of all open native windows
@@ -135,7 +137,6 @@ var PlatformWindows = [CPSet set];
// Define up here so compressor knows about them.
var CPDOMEventGetClickCount,
CPDOMEventStop,
StopDOMEventPropagation,
StopContextMenuDOMEventPropagation;
@@ -196,11 +197,13 @@ var ModifierKeyCodes = [
CPKeyCodes.ALT,
CPKeyCodes.SHIFT
],
supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
var resizeTimer = nil;
#if PLATFORM(DOM)
@implementation CPPlatformWindow (DOM)
- (id)_init
@@ -215,6 +218,8 @@ var resizeTimer = nil;
_windowLevels = [];
_windowLayers = @{};
_platformPasteboard = [CPPlatformPasteboard new];
[self registerDOMWindow];
[self updateFromNativeContentRect];
@@ -301,19 +306,6 @@ var resizeTimer = nil;
_DOMBodyElement.appendChild(_DOMFocusElement);
// Create Native Pasteboard handler.
_DOMPasteboardElement = theDocument.createElement("textarea");
_DOMPasteboardElement.style.position = "absolute";
_DOMPasteboardElement.style.top = "-10000px";
_DOMPasteboardElement.style.zIndex = "999";
_DOMPasteboardElement.className = "cpdontremove";
_DOMBodyElement.appendChild(_DOMPasteboardElement);
// Make sure the pastboard element is blurred.
_DOMPasteboardElement.blur();
// Create a full screen div to protect against iframes and other elements
// from consuming events during tracking
// FIXME: multiple windows
@@ -367,6 +359,8 @@ var resizeTimer = nil;
[self createDOMElements];
[self _addLayers];
[_platformPasteboard setDOMWindow:_DOMWindow];
var theClass = [self class],
dragEventImplementation = class_getMethodImplementation(theClass, @selector(dragEvent:)),
@@ -376,17 +370,9 @@ var resizeTimer = nil;
resizeEventImplementation = class_getMethodImplementation(theClass, resizeEventSelector),
resizeEventCallback = function (anEvent) { resizeEventImplementation(self, nil, anEvent); },
copyEventSelector = @selector(copyEvent:),
copyEventImplementation = class_getMethodImplementation(theClass, copyEventSelector),
copyEventCallback = function (anEvent) {copyEventImplementation(self, nil, anEvent); },
pasteEventSelector = @selector(pasteEvent:),
pasteEventImplementation = class_getMethodImplementation(theClass, pasteEventSelector),
pasteEventCallback = function (anEvent) {pasteEventImplementation(self, nil, anEvent); },
keyEventSelector = @selector(keyEvent:),
keyEventImplementation = class_getMethodImplementation(theClass, keyEventSelector),
keyEventCallback = function (anEvent) { keyEventImplementation(self, nil, anEvent); },
keyEventCallback = function (anEvent) { return keyEventImplementation(self, nil, anEvent); },
mouseEventSelector = @selector(mouseEvent:),
mouseEventImplementation = class_getMethodImplementation(theClass, mouseEventSelector),
@@ -421,10 +407,6 @@ var resizeTimer = nil;
theDocument.addEventListener("mousemove", mouseEventCallback, NO);
theDocument.addEventListener("contextmenu", contextMenuEventCallback, NO);
theDocument.addEventListener("beforecopy", copyEventCallback, NO);
theDocument.addEventListener("beforecut", copyEventCallback, NO);
theDocument.addEventListener("beforepaste", pasteEventCallback, NO);
theDocument.addEventListener("keyup", keyEventCallback, NO);
theDocument.addEventListener("keydown", keyEventCallback, NO);
theDocument.addEventListener("keypress", keyEventCallback, NO);
@@ -454,10 +436,6 @@ var resizeTimer = nil;
theDocument.removeEventListener("keydown", keyEventCallback, NO);
theDocument.removeEventListener("keypress", keyEventCallback, NO);
theDocument.removeEventListener("beforecopy", copyEventCallback, NO);
theDocument.removeEventListener("beforecut", copyEventCallback, NO);
theDocument.removeEventListener("beforepaste", pasteEventCallback, NO);
theDocument.removeEventListener("touchstart", touchEventCallback, NO);
theDocument.removeEventListener("touchend", touchEventCallback, NO);
theDocument.removeEventListener("touchmove", touchEventCallback, NO);
@@ -473,6 +451,8 @@ var resizeTimer = nil;
[PlatformWindows removeObject:self];
[_platformPasteboard setDOMWindow:nil];
self._DOMWindow = nil;
}, NO);
}
@@ -494,7 +474,7 @@ var resizeTimer = nil;
theDocument.onmousewheel = scrollEventCallback;
_DOMBodyElement.ondrag = function () { return NO; };
_DOMBodyElement.onselectstart = function () { return _DOMWindow.event.srcElement === _DOMPasteboardElement; };
_DOMBodyElement.onselectstart = function () { return _DOMWindow.event.srcElement === _platformPasteboard._DOMPasteboardElement; };
_DOMWindow.attachEvent("onunload", function()
{
@@ -523,6 +503,8 @@ var resizeTimer = nil;
[PlatformWindows removeObject:self];
[_platformPasteboard setDOMWindow:nil];
self._DOMWindow = nil;
}, NO);
}
@@ -709,9 +691,7 @@ var resizeTimer = nil;
StopDOMEventPropagation = NO;
}
var isNativePasteEvent = NO,
isNativeCopyOrCutEvent = NO,
overrideCharacters = nil,
var overrideCharacters = nil,
charactersIgnoringModifiers = @"";
switch (aDOMEvent.type)
@@ -753,31 +733,6 @@ var resizeTimer = nil;
//we are simply going to skip all keypress events that use cmd/ctrl key
//this lets us be consistent in all browsers and send on the keydown
//which means we can cancel the event early enough, but only if sendEvent needs to
var eligibleForCopyPaste = [self _validateCopyCutOrPasteEvent:aDOMEvent flags:modifierFlags];
// If this could be a native PASTE event, then we need to further examine it before
// sending a CPEvent. Select our element to see if anything gets pasted in it.
if (characters === "v" && eligibleForCopyPaste)
{
if (!_ignoreNativePastePreparation)
{
_DOMPasteboardElement.select();
_DOMPasteboardElement.value = "";
}
isNativePasteEvent = YES;
}
// However, of this could be a native COPY event, we need to let the normal event-process take place so it
// can capture our internal Cappuccino pasteboard.
else if ((characters == "c" || characters == "x") && eligibleForCopyPaste)
{
isNativeCopyOrCutEvent = YES;
if (_ignoreNativeCopyOrCutEvent)
break;
}
}
else if (CPKeyCodes.firesKeyPressEvent(_keyCode, _lastKey, aDOMEvent.shiftKey, aDOMEvent.ctrlKey, aDOMEvent.altKey))
{
@@ -823,12 +778,6 @@ var resizeTimer = nil;
timestamp:timestamp windowNumber:windowNumber context:nil
characters:characters charactersIgnoringModifiers:charactersIgnoringModifiers isARepeat:isARepeat keyCode:charCode];
if (isNativePasteEvent)
{
_pasteboardKeyDownEvent = event;
window.setNativeTimeout(function () { [self _checkPasteboardElement] }, 0);
}
break;
case "keyup":
@@ -838,8 +787,6 @@ var resizeTimer = nil;
_keyCode = -1;
_lastKey = -1;
_charCodes[keyCode] = nil;
_ignoreNativeCopyOrCutEvent = NO;
_ignoreNativePastePreparation = NO;
// check for caps lock state
if (keyCode === CPKeyCodes.CAPS_LOCK)
@@ -864,127 +811,33 @@ var resizeTimer = nil;
event = [CPEvent keyEventWithType:CPKeyUp location:location modifierFlags:modifierFlags
timestamp: timestamp windowNumber:windowNumber context:nil
characters:characters charactersIgnoringModifiers:charactersIgnoringModifiers isARepeat:NO keyCode:keyCode];
break;
}
if (event && !isNativePasteEvent)
{
if (event)
event._DOMEvent = aDOMEvent;
[_platformPasteboard windowMaySendKeyEvent:event];
if (event && ![_platformPasteboard windowShouldSuppressKeyEvent])
{
[CPApp sendEvent:event];
if (isNativeCopyOrCutEvent)
{
// If this is a native copy event, then check if the pasteboard has anything in it.
[self _primePasteboardElement];
}
[_platformPasteboard windowDidSendKeyEvent:event];
}
if (StopDOMEventPropagation)
CPDOMEventStop(aDOMEvent, self);
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
- (void)copyEvent:(DOMEvent)aDOMEvent
{
if ([self _validateCopyCutOrPasteEvent:aDOMEvent flags:CPPlatformActionKeyMask] && !_ignoreNativeCopyOrCutEvent)
var didStop = NO;
// Platform pasteboard can overrule the decision to stop propagation either way, or it might have no opinion.
if ([_platformPasteboard windowShouldStopPropagation] || (StopDOMEventPropagation && ![_platformPasteboard windowShouldNotStopPropagation]))
{
// we have to send out a fake copy or cut event so that we can force the copy/cut mechanisms to take place
var cut = aDOMEvent.type === "beforecut",
keyCode = cut ? CPKeyCodes.X : CPKeyCodes.C,
characters = cut ? "x" : "c",
timestamp = [CPEvent currentTimestamp], // fake event, might as well use current timestamp
windowNumber = [[CPApp keyWindow] windowNumber],
modifierFlags = CPPlatformActionKeyMask,
location = _lastMouseEventLocation || CGPointMakeZero(),
event = [CPEvent keyEventWithType:CPKeyDown location:location modifierFlags:modifierFlags
timestamp:timestamp windowNumber:windowNumber context:nil
characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode];
event._DOMEvent = aDOMEvent;
[CPApp sendEvent:event];
[self _primePasteboardElement];
//then we have to IGNORE the real keyboard event to prevent a double copy
//safari also sends the beforecopy event twice, so we additionally check here and prevent two events
_ignoreNativeCopyOrCutEvent = YES;
didStop = YES;
_CPDOMEventStop(aDOMEvent, self);
}
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
- (void)pasteEvent:(DOMEvent)aDOMEvent
{
if ([self _validateCopyCutOrPasteEvent:aDOMEvent flags:CPPlatformActionKeyMask])
{
_DOMPasteboardElement.focus();
_DOMPasteboardElement.select();
_DOMPasteboardElement.value = "";
_ignoreNativePastePreparation = YES;
}
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
- (void)_validateCopyCutOrPasteEvent:(DOMEvent)aDOMEvent flags:(unsigned)modifierFlags
{
return (
((aDOMEvent.target || aDOMEvent.srcElement).nodeName.toUpperCase() !== "INPUT" &&
(aDOMEvent.target || aDOMEvent.srcElement).nodeName.toUpperCase() !== "TEXTAREA"
) || aDOMEvent.target === _DOMPasteboardElement
) &&
(modifierFlags & CPPlatformActionKeyMask);
}
- (void)_primePasteboardElement
{
var pasteboard = [CPPasteboard generalPasteboard],
types = [pasteboard types];
if (types.length)
{
if ([types indexOfObjectIdenticalTo:CPStringPboardType] != CPNotFound)
_DOMPasteboardElement.value = [pasteboard stringForType:CPStringPboardType];
else
_DOMPasteboardElement.value = [pasteboard _generateStateUID];
_DOMPasteboardElement.focus();
_DOMPasteboardElement.select();
window.setNativeTimeout(function() { [self _clearPasteboardElement]; }, 0);
}
}
- (void)_checkPasteboardElement
{
var value = _DOMPasteboardElement.value;
if ([value length])
{
var pasteboard = [CPPasteboard generalPasteboard];
if ([pasteboard _stateUID] != value)
{
[pasteboard declareTypes:[CPStringPboardType] owner:self];
[pasteboard setString:value forType:CPStringPboardType];
}
}
[self _clearPasteboardElement];
[CPApp sendEvent:_pasteboardKeyDownEvent];
_pasteboardKeyDownEvent = nil;
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
- (void)_clearPasteboardElement
{
_DOMPasteboardElement.value = "";
_DOMPasteboardElement.blur();
return !didStop;
}
- (void)scrollEvent:(DOMEvent)aDOMEvent
@@ -1060,7 +913,7 @@ var resizeTimer = nil;
{
// Find the scroll delta
var deltaX = _DOMScrollingElement.scrollLeft - 150,
deltaY = (_DOMScrollingElement.scrollTop - 150) || (aDOMEvent.deltaY===undefined?0: aDOMEvent.deltaY);
deltaY = (_DOMScrollingElement.scrollTop - 150) || (aDOMEvent.deltaY === undefined ? 0 : aDOMEvent.deltaY);
// If we scroll super with momentum,
// there are so many events going off that
@@ -1081,7 +934,7 @@ var resizeTimer = nil;
// We set StopDOMEventPropagation = NO on line 1008
//if (StopDOMEventPropagation)
// CPDOMEventStop(aDOMEvent, self);
// _CPDOMEventStop(aDOMEvent, self);
// Reset the DOM elements scroll offset
_DOMScrollingElement.scrollLeft = 150;
@@ -1142,6 +995,10 @@ var resizeTimer = nil;
[windows[windowCount] resizeWithOldPlatformWindowSize:oldSize];
}
[[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationDidChangeScreenParametersNotification
object:CPApp
userInfo:nil];
//window.liveResize = NO;
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
@@ -1322,8 +1179,12 @@ var resizeTimer = nil;
[CPApp sendEvent:event];
}
var didStop = NO;
if (StopDOMEventPropagation && (!supportsNativeDragAndDrop || type !== "mousedown" && !isDragging))
CPDOMEventStop(aDOMEvent, self);
{
didStop = YES;
_CPDOMEventStop(aDOMEvent, self);
}
// If there are any tracking event listeners (listening for CPLeftMouseDraggedMask)
// then show the event guard so we don't lose events to iframes
@@ -1345,12 +1206,13 @@ var resizeTimer = nil;
_DOMEventGuard.style.display = hasTrackingEventListener ? "" : "none";
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
return !didStop;
}
- (void)contextMenuEvent:(DOMEvent)aDOMEvent
{
if (StopContextMenuDOMEventPropagation)
CPDOMEventStop(aDOMEvent, self);
_CPDOMEventStop(aDOMEvent, self);
return !StopContextMenuDOMEventPropagation;
}
@@ -1490,7 +1352,8 @@ var resizeTimer = nil;
// relative to it or the furthest parent.
var children = [aWindow childWindows],
count = [children count],
parent = aWindow;
parent = aWindow,
parentLevel = [parent level];
for (var i = 0; i < count; ++i)
{
@@ -1501,6 +1364,10 @@ var resizeTimer = nil;
if (!childWasVisible && ![child _hasBeenOrderedIn])
continue;
// If a user moved level of the child window, we should respect that
if ([child level] !== parentLevel)
continue;
var ordering = [child _childOrdering];
if ((ordering === CPWindowAbove && furthestParent._index > parent._index) ||
@@ -1641,6 +1508,44 @@ var resizeTimer = nil;
return theWindow;
}
/*! @ignore Return the selected text in the DOM window if known. */
- (CPString)_selectedText
{
if (_DOMWindow.getSelection)
return "" + _DOMWindow.getSelection();
else if (_DOMWindow.document.getSelection)
return "" + _DOMWindow.document.getSelection();
else if (_DOMWindow.selection)
return "" + _DOMWindow.selection.createRange().text;
else
return nil;
}
/*!
Set the text selection range to the given range within the given element, which must be a child of
this DOM window.
*/
- (void)setSelectedRange:(CPRange)aRange inElement:(DOMElement)anElement
{
if (_DOMWindow.getSelection())
{
var domRange = _DOMWindow.document.createRange();
domRange.setStart(anElement.childNodes[0], aRange.location);
domRange.setEnd(anElement.childNodes[0], CPMaxRange(aRange));
_DOMWindow.getSelection().removeAllRanges();
_DOMWindow.getSelection().addRange(domRange);
}
else if (_DOMWindow.document.selection)
{
var domRange = _DOMWindow.document.body.createTextRange();
domRange.moveToElementText(anElement);
domRange.collapse(true);
domRange.moveStart('character', aRange.location);
domRange.moveEnd('character', aRange.length);
domRange.select();
}
}
/*!
When using command (mac) or control (windows), keys are propagated to the browser by default.
To prevent a character key from propagating (to prevent its default action, and instead use it
@@ -1746,7 +1651,8 @@ var CPDOMEventGetClickCount = function(aComparisonEvent, aTimestamp, aLocation)
ABS(comparisonLocation.y - aLocation.y) < CLICK_SPACE_DELTA) ? [aComparisonEvent clickCount] + 1 : 1;
};
var CPDOMEventStop = function(aDOMEvent, aPlatformWindow)
// Global.
_CPDOMEventStop = function(aDOMEvent, aPlatformWindow)
{
// IE Model
aDOMEvent.cancelBubble = true;
@@ -1758,12 +1664,6 @@ var CPDOMEventStop = function(aDOMEvent, aPlatformWindow)
if (aDOMEvent.stopPropagation)
aDOMEvent.stopPropagation();
if (aDOMEvent.type === CPDOMEventMouseDown)
{
aPlatformWindow._DOMFocusElement.focus();
aPlatformWindow._DOMFocusElement.blur();
}
};
function CPWindowObjectList()
+70 -37
View File
@@ -375,7 +375,7 @@ var themedButtonValues = nil,
"themedMenuItemStandardView",
"themedMenuItemMenuBarView",
"themedToolbarView",
"themedBordelessBridgeWindowView",
"themedBorderlessBridgeWindowView",
"themedWindowView",
"themedBrowser",
"themedRuleEditor",
@@ -1097,7 +1097,7 @@ var themedButtonValues = nil,
+ (CPDatePicker)themedDatePicker
{
var datePicker = [[CPDatePicker alloc] initWithFrame:CGRectMake(40,140,300,29)],
var datePicker = [[CPDatePicker alloc] initWithFrame:CGRectMake(40.0, 40.0, 170.0, 29.0)],
bezelColor = PatternColor(
[
@@ -1166,6 +1166,7 @@ var themedButtonValues = nil,
[@"max-size", CGSizeMake(-1.0, 29.0)]
];
[datePicker setDatePickerStyle:CPTextFieldDatePickerStyle];
[self registerThemeValues:themeValues forView:datePicker];
return datePicker;
@@ -1173,7 +1174,7 @@ var themedButtonValues = nil,
+ (CPDatePicker)themedDatePickerCalendar
{
var datePicker = [[CPDatePicker alloc] initWithFrame:CGRectMake(40,140,300,29)],
var datePicker = [[CPDatePicker alloc] initWithFrame:CGRectMake(40.0, 140.0, 276.0, 148.0)],
arrowImageLeft = PatternImage("datepicker-calendar-arrow-left.png", 7.0, 10.0),
arrowImageRight = PatternImage("datepicker-calendar-arrow-right.png", 7.0, 10.0),
@@ -1183,17 +1184,26 @@ var themedButtonValues = nil,
arrowImageRightHighlighted = PatternImage("datepicker-calendar-arrow-right-highlighted.png", 7.0, 10.0),
circleImageHighlighted = PatternImage("datepicker-circle-image-highlighted.png", 9.0, 10.0),
secondHandColor = PatternColor("datepicker-clock-second-hand.png", 89.0, 89.0),
minuteHandColor = PatternColor("datepicker-clock-minute-hand.png", 85.0, 85.0),
hourHandColor = PatternColor("datepicker-clock-hour-hand.png", 47.0, 47.0),
middleHandColor = PatternColor("datepicker-clock-middle-hand.png", 13.0, 13.0),
clockImageColor = PatternColor("datepicker-clock.png", 122.0, 123.0),
secondHandSize = CGSizeMake(89.0, 89.0),
secondHandImage = PatternImage("datepicker-clock-second-hand.png", secondHandSize.width, secondHandSize.height),
secondHandColorDisabled = PatternColor("datepicker-clock-second-hand-disabled.png", 89.0, 89.0),
minuteHandColorDisabled = PatternColor("datepicker-clock-minute-hand-disabled.png", 85.0, 85.0),
hourHandColorDisabled = PatternColor("datepicker-clock-hour-hand-disabled.png", 47.0, 47.0),
middleHandColorDisabled = PatternColor("datepicker-clock-middle-hand-disabled.png", 13.0, 13.0),
clockImageColorDisabled = PatternColor("datepicker-clock-disabled.png", 122.0, 123.0),
minuteHandSize = CGSizeMake(85.0, 85.0),
minuteHandImage = PatternImage("datepicker-clock-minute-hand.png", minuteHandSize.width, minuteHandSize.height),
hourHandSize = CGSizeMake(47.0, 47.0),
hourHandImage = PatternImage("datepicker-clock-hour-hand.png", hourHandSize.width, hourHandSize.height),
middleHandSize = CGSizeMake(13.0, 13.0),
middleHandImage = PatternImage("datepicker-clock-middle-hand.png", middleHandSize.width, middleHandSize.height),
clockSize = CGSizeMake(122.0, 123.0),
clockImageColor = PatternColor("datepicker-clock.png", clockSize.width, clockSize.height),
secondHandImageDisabled = PatternImage("datepicker-clock-second-hand-disabled.png", secondHandSize.width, secondHandSize.height),
minuteHandImageDisabled = PatternImage("datepicker-clock-minute-hand-disabled.png", minuteHandSize.width, minuteHandSize.height),
hourHandImageDisabled = PatternImage("datepicker-clock-hour-hand-disabled.png", hourHandSize.width, hourHandSize.height),
middleHandImageDisabled = PatternImage("datepicker-clock-middle-hand-disabled.png", middleHandSize.width, middleHandSize.height),
clockImageColorDisabled = PatternColor("datepicker-clock-disabled.png", clockSize.width, clockSize.height),
themeValues =
[
@@ -1204,7 +1214,7 @@ var themedButtonValues = nil,
[@"bezel-color-calendar", [CPColor whiteColor]],
[@"bezel-color-calendar", [CPColor colorWithCalibratedRed:159.0 / 255.0 green:201.0 / 255.0 blue:225.0 / 255.0 alpha:1.0], CPThemeStateSelected],
[@"bezel-color-calendar", [CPColor colorWithCalibratedRed:159.0 / 255.0 green:201.0 / 255.0 blue:225.0 / 255.0 alpha:0.5], CPThemeStateSelected |CPThemeStateDisabled],
[@"bezel-color-calendar", [CPColor colorWithCalibratedRed:159.0 / 255.0 green:201.0 / 255.0 blue:225.0 / 255.0 alpha:0.5], CPThemeStateSelected | CPThemeStateDisabled],
[@"bezel-color-clock", clockImageColor],
[@"bezel-color-clock", clockImageColorDisabled, CPThemeStateDisabled],
@@ -1286,25 +1296,25 @@ var themedButtonValues = nil,
[@"circle-image-highlighted", circleImageHighlighted],
[@"arrow-inset", CGInsetMake(9.0, 4.0, 0.0, 0.0)],
[@"second-hand-color", secondHandColor],
[@"hour-hand-color", hourHandColor],
[@"middle-hand-color", middleHandColor],
[@"minute-hand-color", minuteHandColor],
[@"second-hand-image", secondHandImage],
[@"hour-hand-image", hourHandImage],
[@"middle-hand-image", middleHandImage],
[@"minute-hand-image", minuteHandImage],
[@"second-hand-color", secondHandColorDisabled, CPThemeStateDisabled],
[@"hour-hand-color", hourHandColorDisabled, CPThemeStateDisabled],
[@"middle-hand-color", middleHandColorDisabled, CPThemeStateDisabled],
[@"minute-hand-color", minuteHandColorDisabled, CPThemeStateDisabled],
[@"second-hand-image", secondHandImageDisabled, CPThemeStateDisabled],
[@"hour-hand-image", hourHandImageDisabled, CPThemeStateDisabled],
[@"middle-hand-image", middleHandImageDisabled, CPThemeStateDisabled],
[@"minute-hand-image", minuteHandImageDisabled, CPThemeStateDisabled],
[@"second-hand-size", CGSizeMake(89.0, 89.0)],
[@"hour-hand-size", CGSizeMake(47.0, 47.0)],
[@"middle-hand-size", CGSizeMake(13.0, 13.0)],
[@"minute-hand-size", CGSizeMake(85.0, 85.0)],
[@"second-hand-size", secondHandSize],
[@"hour-hand-size", hourHandSize],
[@"middle-hand-size", middleHandSize],
[@"minute-hand-size", minuteHandSize],
[@"border-width", 1.0],
[@"size-header", CGSizeMake(141.0, 39.0)],
[@"size-tile", CGSizeMake(20.0, 18.0)],
[@"size-clock", CGSizeMake(122.0, 123.0)],
[@"size-clock", clockSize],
[@"size-calendar", CGSizeMake(141.0, 109.0)],
[@"min-size-calendar", CGSizeMake(141.0, 148.0)],
[@"max-size-calendar", CGSizeMake(141.0, 148.0)]
@@ -1312,6 +1322,7 @@ var themedButtonValues = nil,
];
[datePicker setDatePickerStyle:CPClockAndCalendarDatePickerStyle];
[datePicker setBackgroundColor:[CPColor whiteColor]];
[self registerThemeValues:themeValues forView:datePicker];
return datePicker;
@@ -2071,15 +2082,32 @@ var themedButtonValues = nil,
themedTableViewValues =
[
[@"alternating-row-colors", alternatingRowColors],
[@"grid-color", gridColor],
[@"highlighted-grid-color", [CPColor whiteColor]],
[@"selection-color", selectionColor],
[@"sourcelist-selection-color", sourceListSelectionColor],
[@"sort-image", sortImage],
[@"sort-image-reversed", sortImageReversed],
[@"image-generic-file", imageGenericFile],
[@"default-row-height", 23.0],
[@"alternating-row-colors", alternatingRowColors],
[@"grid-color", gridColor],
[@"highlighted-grid-color", [CPColor whiteColor]],
[@"selection-color", selectionColor],
[@"sourcelist-selection-color", sourceListSelectionColor],
[@"sort-image", sortImage],
[@"sort-image-reversed", sortImageReversed],
[@"image-generic-file", imageGenericFile],
[@"default-row-height", 23.0],
[@"dropview-on-background-color", [CPColor colorWithRed:72 / 255 green:134 / 255 blue:202 / 255 alpha:0.25]],
[@"dropview-on-border-color", [CPColor colorWithHexString:@"4886ca"]],
[@"dropview-on-border-width", 3.0],
[@"dropview-on-border-radius", 8.0],
[@"dropview-on-selected-background-color", [CPColor clearColor]],
[@"dropview-on-selected-border-color", [CPColor whiteColor]],
[@"dropview-on-selected-border-width", 2.0],
[@"dropview-on-selected-border-radius", 8.0],
[@"dropview-above-border-color", [CPColor colorWithHexString:@"4886ca"]],
[@"dropview-above-border-width", 3.0],
[@"dropview-above-selected-border-color", [CPColor colorWithHexString:@"8BB6F0"]],
[@"dropview-above-selected-border-width", 2.0],
];
[self registerThemeValues:themedTableViewValues forView:tableview];
@@ -2687,6 +2715,7 @@ var themedButtonValues = nil,
[
[@"gradient-height", 31.0],
[@"bezel-head-color", bezelHeadColor],
[@"bezel-head-sheet-color", solidColor],
[@"solid-color", solidColor],
[@"title-font", [CPFont boldSystemFontOfSize:CPFontCurrentSystemSize]],
@@ -2750,7 +2779,7 @@ var themedButtonValues = nil,
return docModalWindowView;
}
+ (_CPBorderlessBridgeWindowView)themedBordelessBridgeWindowView
+ (_CPBorderlessBridgeWindowView)themedBorderlessBridgeWindowView
{
var bordelessBridgeWindowView = [[_CPBorderlessBridgeWindowView alloc] initWithFrame:CGRectMake(0,0,0,0)],
@@ -2968,6 +2997,10 @@ var themedButtonValues = nil,
themeValues =
[
[@"border-radius", 5.0],
[@"stroke-width", 1.0],
[@"shadow-size", CGSizeMake(0, 6)],
[@"shadow-blur", 15.0],
[@"background-gradient", gradient],
[@"background-gradient-hud", gradientHUD],
[@"stroke-color", strokeColor],
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 88 B

Some files were not shown because too many files have changed in this diff Show More