Some cleanup.

Reviewed by me.
This commit is contained in:
Francisco Tolmasky committed 2009-02-18 23:28:13 -08:00
1 parent 2c335e37b0
commit 1f54d5de0e
5 files changed
+41 -102

No files matched your search

+4 -63
View File
@@ -73,18 +73,11 @@ CPTextFieldSquareBezel = 0;
*/
CPTextFieldRoundedBezel = 1;
var TOP_PADDING = 4.0,
BOTTOM_PADDING = 3.0;
HORIZONTAL_PADDING = 3.0;
ROUNDEDBEZEL_HORIZONTAL_PADDING = 8.0;
#if PLATFORM(DOM)
var CPTextFieldDOMInputElement = nil;
#endif
var _CPTextFieldSquareBezelColor = nil,
_CPTextFieldRoundedBezelColor = nil;
@implementation CPString (CPTextFieldAdditions)
/*!
@@ -325,7 +318,8 @@ CPTextFieldStateRounded = 1 << 12;
_drawsBackground = shouldDrawBackground;
[self _updateBackground];
[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
/*!
@@ -347,7 +341,8 @@ CPTextFieldStateRounded = 1 << 12;
_textFieldBackgroundColor = aColor;
[self _updateBackground];
[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
/*!
@@ -358,60 +353,6 @@ CPTextFieldStateRounded = 1 << 12;
return _textFieldBackgroundColor;
}
/* @ignore */
- (void)_updateBackground
{
if (_isBezeled)
{
if (_bezelStyle == CPTextFieldSquareBezel)
{
if (!_CPTextFieldSquareBezelColor)
{
var bundle = [CPBundle bundleForClass:[CPTextField class]];
_CPTextFieldSquareBezelColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare0.png"] size:CGSizeMake(2.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare1.png"] size:CGSizeMake(1.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare2.png"] size:CGSizeMake(2.0, 3.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare3.png"] size:CGSizeMake(2.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare5.png"] size:CGSizeMake(2.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare6.png"] size:CGSizeMake(2.0, 2.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare7.png"] size:CGSizeMake(1.0, 2.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelSquare8.png"] size:CGSizeMake(2.0, 2.0)]
]]];
}
[self setBackgroundColor:_CPTextFieldSquareBezelColor];
}
else if (_bezelStyle == CPTextFieldRoundedBezel)
{
if (!_CPTextFieldRoundedBezelColor)
{
var bundle = [CPBundle bundleForClass:[CPTextField class]];
_CPTextFieldRoundedBezelColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelRounded0.png"] size:CGSizeMake(12.0, 22.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelRounded1.png"] size:CGSizeMake(16.0, 22.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CPTextField/CPTextFieldBezelRounded2.png"] size:CGSizeMake(12.0, 22.0)]
] isVertical:NO]];
}
[self setBackgroundColor:_CPTextFieldRoundedBezelColor];
}
}
else
{
if (_drawsBackground)
[self setBackgroundColor:_textFieldBackgroundColor];
else
[self setBackgroundColor:nil];
// FIXME: do something for bordered textfields
//if (_isBordered)
}
}
/* @ignore */
- (BOOL)acceptsFirstResponder
{
@@ -42,12 +42,12 @@ var _CPToolbarViewBackgroundColor = nil;
{
[super tile];
var owningWindow = [self owningWindow],
var theWindow = [self window],
bounds = [self bounds];
[[owningWindow contentView] setFrame:CGRectMake(0.0, [self toolbarMaxY], CGRectGetWidth(bounds), CGRectGetHeight(bounds) - [self toolbarMaxY])];
[[theWindow contentView] setFrame:CGRectMake(0.0, [self toolbarMaxY], CGRectGetWidth(bounds), CGRectGetHeight(bounds) - [self toolbarMaxY])];
if (![[owningWindow toolbar] isVisible])
if (![[theWindow toolbar] isVisible])
{
[_toolbarBackgroundView removeFromSuperview];
+12 -9
View File
@@ -86,7 +86,7 @@ var HUD_TITLEBAR_HEIGHT = 26.0;
{
var contentRect = [[self class] contentRectForFrameRect:aFrameRect];
if ([[[self owningWindow] toolbar] isVisible])
if ([[[self window] toolbar] isVisible])
{
toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
@@ -101,7 +101,7 @@ var HUD_TITLEBAR_HEIGHT = 26.0;
{
var frameRect = [[self class] frameRectForContentRect:aContentRect];
if ([[[self owningWindow] toolbar] isVisible])
if ([[[self window] toolbar] isVisible])
{
toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
@@ -112,9 +112,9 @@ var HUD_TITLEBAR_HEIGHT = 26.0;
return frameRect;
}
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask owningWindow:(CPWindow)aWindow
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
{
self = [super initWithFrame:aFrame styleMask:aStyleMask owningWindow:aWindow];
self = [super initWithFrame:aFrame styleMask:aStyleMask];
if (self)
{
@@ -155,9 +155,6 @@ var HUD_TITLEBAR_HEIGHT = 26.0;
[_closeButton setImage:_CPHUDWindowViewCloseImage];
[_closeButton setAlternateImage:_CPHUDWindowViewCloseActiveImage];
[_closeButton setTarget:aWindow];
[_closeButton setAction:@selector(performClose:)];
[self addSubview:_closeButton];
}
@@ -167,6 +164,12 @@ var HUD_TITLEBAR_HEIGHT = 26.0;
return self;
}
- (void)viewDidMoveToWindow
{
[_closeButton setTarget:[self window]];
[_closeButton setAction:@selector(performClose:)];
}
- (void)setTitle:(CPString)aTitle
{
[_titleField setStringValue:aTitle];
@@ -191,9 +194,9 @@ var HUD_TITLEBAR_HEIGHT = 26.0;
{
[super tile];
var owningWindow = [self owningWindow];
var theWindow = [self window];
[[owningWindow contentView] setFrameOrigin:CGPointMake(0.0, [self toolbarMaxY])];//HUD_TITLEBAR_HEIGHT + toolbarHeight)];
[[theWindow contentView] setFrameOrigin:CGPointMake(0.0, [self toolbarMaxY])];//HUD_TITLEBAR_HEIGHT + toolbarHeight)];
}
@end
+12 -9
View File
@@ -164,7 +164,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
{
var contentRect = [[self class] contentRectForFrameRect:aFrameRect];
if ([[[self owningWindow] toolbar] isVisible])
if ([[[self window] toolbar] isVisible])
{
toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
@@ -179,7 +179,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
{
var frameRect = [[self class] frameRectForContentRect:aContentRect];
if ([[[self owningWindow] toolbar] isVisible])
if ([[[self window] toolbar] isVisible])
{
toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
@@ -190,9 +190,9 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
return frameRect;
}
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask owningWindow:(CPWindow)aWindow
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
{
self = [super initWithFrame:aFrame styleMask:aStyleMask owningWindow:aWindow];
self = [super initWithFrame:aFrame styleMask:aStyleMask];
if (self)
{
@@ -261,9 +261,6 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
[_closeButton setImage:_CPStandardWindowViewCloseButtonImage];
[_closeButton setAlternateImage:_CPStandardWindowViewCloseButtonHighlightedImage];
[_closeButton setTarget:aWindow];
[_closeButton setAction:@selector(performClose:)];
[self addSubview:_closeButton];
}
@@ -274,6 +271,12 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
return self;
}
- (void)viewDidMoveToWindow
{
[_closeButton setTarget:[self window]];
[_closeButton setAction:@selector(performClose:)];
}
- (CGSize)toolbarOffset
{
return CGSizeMake(0.0, STANDARD_TITLEBAR_HEIGHT);
@@ -283,7 +286,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
{
[super tile];
var owningWindow = [self owningWindow],
var theWindow = [self window],
width = CGRectGetWidth([self bounds]);
[_headView setFrameSize:CGSizeMake(width, [self toolbarMaxY])];
@@ -292,7 +295,7 @@ var STANDARD_GRADIENT_HEIGHT = 41.0;
[_titleField setFrame:CGRectMake(10.0, 3.0, width - 20.0, CGRectGetHeight([_titleField frame]))];
[[owningWindow contentView] setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_dividerView frame]))];
[[theWindow contentView] setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_dividerView frame]))];
}
- (void)setTitle:(CPString)aTitle
+10 -18
View File
@@ -37,8 +37,6 @@ var _CPWindowViewResizeIndicatorImage = nil;
CPView _toolbarView;
CPWindow _owningWindow;
CGRect _resizeFrame;
CGPoint _mouseDraggedPoint;
}
@@ -71,14 +69,13 @@ var _CPWindowViewResizeIndicatorImage = nil;
return [[self class] frameRectForContentRect:aContentRect];
}
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask owningWindow:(CPWindow)aWindow
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
{
self = [super initWithFrame:aFrame];
if (self)
{
_styleMask = aStyleMask;
_owningWindow = aWindow;
_resizeIndicatorOffset = CGSizeMake(0.0, 0.0);
_toolbarOffset = CGSizeMake(0.0, 0.0);
@@ -88,11 +85,6 @@ var _CPWindowViewResizeIndicatorImage = nil;
return self;
}
- (CPWindow)owningWindow
{
return _owningWindow;
}
- (void)setTitle:(CPString)aTitle
{
}
@@ -104,7 +96,7 @@ var _CPWindowViewResizeIndicatorImage = nil;
- (void)mouseDown:(CPEvent)anEvent
{
var theWindow = [self owningWindow];
var theWindow = [self window];
if ((_styleMask & CPResizableWindowMask) && _resizeIndicator)
{
@@ -130,7 +122,7 @@ var _CPWindowViewResizeIndicatorImage = nil;
if (type === CPLeftMouseUp)
return;
var theWindow = [self owningWindow];
var theWindow = [self window];
if (type === CPLeftMouseDown)
{
@@ -153,11 +145,11 @@ var _CPWindowViewResizeIndicatorImage = nil;
return;
else if (type === CPLeftMouseDown)
_mouseDraggedPoint = [[self owningWindow] convertBaseToBridge:[anEvent locationInWindow]];
_mouseDraggedPoint = [[self window] convertBaseToBridge:[anEvent locationInWindow]];
else if (type === CPLeftMouseDragged)
{
var theWindow = [self owningWindow],
var theWindow = [self window],
location = [theWindow convertBaseToBridge:[anEvent locationInWindow]],
frame = [theWindow frame];
@@ -256,11 +248,11 @@ var _CPWindowViewResizeIndicatorImage = nil;
- (void)tile
{
var owningWindow = [self owningWindow],
var theWindow = [self window],
bounds = [self bounds],
width = CGRectGetWidth(bounds);
if ([[owningWindow toolbar] isVisible])
if ([[theWindow toolbar] isVisible])
{
var toolbarView = [self toolbarView],
toolbarOffset = [self toolbarOffset];
@@ -279,8 +271,8 @@ var _CPWindowViewResizeIndicatorImage = nil;
- (void)noteToolbarChanged
{
var owningWindow = [self owningWindow],
toolbar = [owningWindow toolbar],
var theWindow = [self window],
toolbar = [theWindow toolbar],
toolbarView = [toolbar _toolbarView];
if (_toolbarView !== toolbarView)
@@ -302,7 +294,7 @@ var _CPWindowViewResizeIndicatorImage = nil;
[toolbarView setHidden:![self showsToolbar] || ![toolbar isVisible]];
[self setAutoresizesSubviews:NO];
[owningWindow setFrameSize:[self frameRectForContentRect:[[owningWindow contentView] frame]].size];
[theWindow setFrameSize:[self frameRectForContentRect:[[theWindow contentView] frame]].size];
[self setAutoresizesSubviews:YES];
[self tile];