1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/* CynthiuneHeaderCell.m - this file is part of Cynthiune
*
* Copyright (C) 2005 Wolfgang Sourdeau
*
* Author: Wolfgang Sourdeau <Wolfgang@Contre.COM>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <math.h>
#import <AppKit/NSBezierPath.h>
#import <AppKit/NSColor.h>
#import <Foundation/NSGeometry.h>
#import <Foundation/NSString.h>
#import "CynthiuneHeaderCell.h"
@implementation CynthiuneHeaderCell : NSTableHeaderCell
- (id) init
{
if ((self = [super init]))
{
comparisonResult = NSOrderedSame;
}
return self;
}
static inline NSPoint
RelativePoint (NSPoint point, NSPoint refPoint)
{
return NSMakePoint (refPoint.x + point.x, refPoint.y + point.y);
}
- (void) _drawArrowOfSize: (NSSize) arrowSize
flipped: (BOOL) flipped
atReferencePoint: (NSPoint) refPoint
{
NSBezierPath *bezier;
float pointA, pointB;
bezier = [NSBezierPath bezierPath];
[bezier setLineWidth: 0.0];
[[self textColor] set];
if ((!flipped && comparisonResult == NSOrderedAscending)
|| (flipped && comparisonResult == NSOrderedDescending)) {
pointA = arrowSize.height;
pointB = 0.0;
} else {
pointA = 0.0;
pointB = arrowSize.height;
}
[bezier moveToPoint: RelativePoint (NSMakePoint(0, pointA), refPoint)];
[bezier lineToPoint: RelativePoint (NSMakePoint(arrowSize.width / 2, pointB), refPoint)];
[bezier lineToPoint: RelativePoint (NSMakePoint(arrowSize.width, pointA), refPoint)];
[bezier lineToPoint: RelativePoint (NSMakePoint(0, pointA), refPoint)];
[bezier closePath];
[bezier fill];
}
- (void) drawInteriorWithFrame: (NSRect) cellFrame
inView: (NSView *) controlView
{
NSRect arrowFrame, remainingFrame;
NSPoint refPoint;
float arrowHeight, arrowWidth;
[super drawInteriorWithFrame: cellFrame
inView: controlView];
arrowHeight = cellFrame.size.height / 3.0;
arrowWidth = ceil (arrowHeight * 1.3);
if (comparisonResult != NSOrderedSame)
{
NSDivideRect (cellFrame, &arrowFrame, &remainingFrame,
arrowWidth + arrowOffset, NSMaxXEdge);
refPoint = RelativePoint (NSMakePoint (0, (cellFrame.size.height
- arrowHeight) / 2),
arrowFrame.origin);
[self _drawArrowOfSize: NSMakeSize (arrowWidth, arrowHeight)
flipped: [controlView isFlipped]
atReferencePoint: refPoint];
}
}
- (void) setComparisonResult: (NSComparisonResult) result
{
comparisonResult = result;
}
- (NSSize) cellSize
{
NSSize size;
size = [super cellSize];
size.width += ceil ((size.height * 1.3) / 3.0) + arrowOffset;
return size;
}
- (float) widthOfText: (NSString *) text
{
NSSize size;
size = [self cellSize];
return ([self widthOfText: text]
+ ceil ((size.height * 1.3) / 3.0)
+ arrowOffset );
}
@end
|