aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/BWToolkitFramework.framework/BWCustomView.m
diff options
context:
space:
mode:
authoravenjamin <avenjamin@gmail.com>2009-06-24 15:46:27 +0000
committeravenjamin <avenjamin@gmail.com>2009-06-24 15:46:27 +0000
commit5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40 (patch)
treef0eaf423f2c13f2091fe9cfceaa2e0a6f2169723 /Frameworks/BWToolkitFramework.framework/BWCustomView.m
parent37bd86b2879c107ebb026954693540979cf25e2a (diff)
downloadsequelpro-5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40.tar.gz
sequelpro-5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40.tar.bz2
sequelpro-5b05f3f15aa0676f91bc1d127d31f4fd95ef9f40.zip
- Changed the way the BWToolkit framework was included to allow modifications to be made easily.
- Fixed show/hide info pane toggle button image states to now show correctly
Diffstat (limited to 'Frameworks/BWToolkitFramework.framework/BWCustomView.m')
-rw-r--r--Frameworks/BWToolkitFramework.framework/BWCustomView.m186
1 files changed, 186 insertions, 0 deletions
diff --git a/Frameworks/BWToolkitFramework.framework/BWCustomView.m b/Frameworks/BWToolkitFramework.framework/BWCustomView.m
new file mode 100644
index 00000000..dff80f57
--- /dev/null
+++ b/Frameworks/BWToolkitFramework.framework/BWCustomView.m
@@ -0,0 +1,186 @@
+//
+// BWGradientSplitViewSubview.m
+// BWToolkit
+//
+// Created by Brandon Walkin (www.brandonwalkin.com)
+// All code is provided under the New BSD license.
+//
+
+#import "BWCustomView.h"
+#import "NSColor+BWAdditions.h"
+#import "NSWindow+BWAdditions.h"
+#import "NSApplication+BWAdditions.h"
+#import "IBColor.h"
+
+@interface BWCustomView (BWCVPrivate)
+- (void)drawTextInRect:(NSRect)rect;
+- (NSColor *)containerCustomViewBackgroundColor;
+- (NSColor *)childlessCustomViewBackgroundColor;
+- (NSColor *)customViewDarkTexturedBorderColor;
+- (NSColor *)customViewDarkBorderColor;
+- (NSColor *)customViewLightBorderColor;
+@end
+
+@implementation BWCustomView
+
+- (void)drawRect:(NSRect)rect
+{
+ rect = self.bounds;
+
+ NSColor *insetColor = [self customViewLightBorderColor];
+ NSColor *borderColor;
+
+ if ([[self window] isTextured])
+ borderColor = [self customViewDarkTexturedBorderColor];
+ else
+ borderColor = [self customViewDarkBorderColor];
+
+ // Note: These two colors are reversed in IBColor in 10.5
+ if (self.subviews.count == 0)
+ {
+ if ([NSApplication isOnLeopard])
+ [[self containerCustomViewBackgroundColor] set];
+ else
+ [[self childlessCustomViewBackgroundColor] set];
+ NSRectFillUsingOperation(rect,NSCompositeSourceOver);
+ }
+ else
+ {
+ if ([NSApplication isOnLeopard])
+ [[self childlessCustomViewBackgroundColor] set];
+ else
+ [[self containerCustomViewBackgroundColor] set];
+ NSRectFillUsingOperation(rect,NSCompositeSourceOver);
+ }
+
+ if ([[self superview] isKindOfClass:NSClassFromString(@"BWSplitView")] && [[self superview] subviews].count > 1)
+ {
+ isOnItsOwn = NO;
+ NSArray *subviews = [[self superview] subviews];
+
+ if ([subviews objectAtIndex:0] == self)
+ {
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+
+ if ([(NSSplitView *)[self superview] isVertical])
+ {
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ }
+ else
+ {
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ }
+
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ }
+ else if ([subviews lastObject] == self)
+ {
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+
+ if ([(NSSplitView *)[self superview] isVertical])
+ {
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ }
+ else
+ {
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ }
+
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ }
+ else
+ {
+ if ([(NSSplitView *)[self superview] isVertical])
+ {
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ }
+ else
+ {
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [insetColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ }
+ }
+ }
+ else
+ {
+ isOnItsOwn = YES;
+
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [insetColor drawPixelThickLineAtPosition:1 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:NO];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:NO flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:YES];
+ [borderColor drawPixelThickLineAtPosition:0 withInset:0 inRect:rect inView:self horizontal:YES flip:NO];
+ }
+
+ if (rect.size.height > 16)
+ [self drawTextInRect:rect];
+}
+
+- (void)drawTextInRect:(NSRect)rect
+{
+ NSString *text;
+
+ if (isOnItsOwn)
+ text = [NSString stringWithFormat:@"%d x %d pt",(int)rect.size.width,(int)rect.size.height];
+ else if ([(NSSplitView *)[self superview] isVertical])
+ text = [NSString stringWithFormat:@"%d pt",(int)rect.size.width];
+ else
+ text = [NSString stringWithFormat:@"%d pt",(int)rect.size.height];
+
+ if (![self.className isEqualToString:@"NSView"])
+ text = self.className;
+
+ NSMutableDictionary *attributes = [[[NSMutableDictionary alloc] init] autorelease];
+ [attributes setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
+ [attributes setObject:[NSFont boldSystemFontOfSize:12] forKey:NSFontAttributeName];
+
+ NSShadow *shadow = [[[NSShadow alloc] init] autorelease];
+ [shadow setShadowOffset:NSMakeSize(0,-1)];
+ [shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:0.4]];
+ [attributes setObject:shadow forKey:NSShadowAttributeName];
+
+ NSMutableAttributedString *string = [[[NSMutableAttributedString alloc] initWithString:text attributes:attributes] autorelease];
+
+ NSRect boundingRect = [string boundingRectWithSize:rect.size options:0];
+
+ NSPoint rectCenter;
+ rectCenter.x = rect.size.width / 2;
+ rectCenter.y = rect.size.height / 2;
+
+ NSPoint drawPoint = rectCenter;
+ drawPoint.x -= boundingRect.size.width / 2;
+ drawPoint.y -= boundingRect.size.height / 2;
+
+ drawPoint.x = roundf(drawPoint.x);
+ drawPoint.y = roundf(drawPoint.y);
+
+ [string drawAtPoint:drawPoint];
+}
+
+@end \ No newline at end of file