зеркало из https://github.com/mozilla/pjs.git
Fixing bug 357530 Remove dead code from DraggableImageAndTextCell. Patch by smorgan <stuart.morgan@alumni.case.edu>, sr=smfr. Camino only.
This commit is contained in:
Родитель
f4a830b6b5
Коммит
af9ac58b4b
|
@ -39,15 +39,8 @@
|
|||
|
||||
@interface DraggableImageAndTextCell : NSButtonCell
|
||||
{
|
||||
NSImage *mImage;
|
||||
NSMutableString *mTruncLabelString;
|
||||
NSPoint mTrackingStart;
|
||||
int mLabelStringWidth; // -1 if not known
|
||||
float mImagePadding;
|
||||
float mImageSpace;
|
||||
float mImageAlpha;
|
||||
float mClickHoldTimeoutSeconds;
|
||||
BOOL mTruncateLabel;
|
||||
BOOL mIsDraggable;
|
||||
BOOL mLastClickHoldTimedOut;
|
||||
|
||||
|
@ -56,16 +49,6 @@
|
|||
|
||||
- (id)initTextCell:(NSString*)aString;
|
||||
|
||||
- (void)setImagePadding:(float)padding;
|
||||
- (void)setImageSpace:(float)space;
|
||||
- (void)setImageAlpha:(float)alpha;
|
||||
|
||||
//- (void)setImage:(NSImage *)anImage;
|
||||
//- (NSImage *)image;
|
||||
|
||||
- (BOOL)labelTruncates;
|
||||
- (void)setLabelTruncates:(BOOL)inTruncates;
|
||||
|
||||
- (BOOL)isDraggable;
|
||||
- (void)setDraggable:(BOOL)inDraggable;
|
||||
|
||||
|
|
|
@ -40,12 +40,6 @@
|
|||
#import "DraggableImageAndTextCell.h"
|
||||
|
||||
|
||||
@interface DraggableImageAndTextCell(Private)
|
||||
|
||||
- (void)clearCachedTruncatedLabel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation DraggableImageAndTextCell
|
||||
|
||||
+ (BOOL)prefersTrackingUntilMouseUp
|
||||
|
@ -55,12 +49,7 @@
|
|||
|
||||
- (id)initTextCell:(NSString*)aString
|
||||
{
|
||||
if ((self = [super initTextCell:aString]))
|
||||
{
|
||||
mLabelStringWidth = -1;
|
||||
mImagePadding = 0;
|
||||
mImageSpace = 2;
|
||||
mImageAlpha = 1.0;
|
||||
if ((self = [super initTextCell:aString])) {
|
||||
mIsDraggable = NO;
|
||||
mClickHoldTimeoutSeconds = 60.0 * 60.0 * 24.0;
|
||||
mLastClickHoldTimedOut = NO;
|
||||
|
@ -68,134 +57,6 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[mImage release];
|
||||
[mTruncLabelString release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
DraggableImageAndTextCell *cell = (DraggableImageAndTextCell *)[super copyWithZone:zone];
|
||||
cell->mImage = [mImage retain];
|
||||
cell->mTruncLabelString = nil;
|
||||
cell->mLabelStringWidth = -1;
|
||||
return cell;
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
|
||||
{
|
||||
NSRect textRect = cellFrame;
|
||||
NSRect imageRect;
|
||||
|
||||
// we always reserve space for the image, even if there isn't one
|
||||
// assume the image rect is always square
|
||||
float imageWidth = NSHeight(cellFrame) - 2 * mImagePadding;
|
||||
NSDivideRect(cellFrame, &imageRect, &textRect, imageWidth, NSMinXEdge);
|
||||
|
||||
if (mImage)
|
||||
{
|
||||
NSRect imageSrcRect = NSZeroRect;
|
||||
imageSrcRect.size = [mImage size];
|
||||
[mImage drawInRect:NSInsetRect(imageRect, mImagePadding, mImagePadding)
|
||||
fromRect:imageSrcRect operation:NSCompositeSourceOver fraction:mImageAlpha];
|
||||
}
|
||||
|
||||
// remove image space
|
||||
NSDivideRect(textRect, &imageRect, &textRect, mImageSpace, NSMinXEdge);
|
||||
|
||||
int cellWidth = (int)NSWidth(textRect);
|
||||
NSDictionary *cellAttributes = [[self attributedTitle] attributesAtIndex:0 effectiveRange:nil];
|
||||
|
||||
if (mLabelStringWidth != cellWidth || !mTruncLabelString)
|
||||
{
|
||||
[mTruncLabelString release];
|
||||
mTruncLabelString = [[NSMutableString alloc] initWithString:[self title]];
|
||||
[mTruncLabelString truncateToWidth:cellWidth at:kTruncateAtEnd withAttributes:cellAttributes];
|
||||
mLabelStringWidth = cellWidth;
|
||||
}
|
||||
|
||||
[mTruncLabelString drawInRect:textRect withAttributes:cellAttributes];
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)setStringValue:(NSString *)aString
|
||||
{
|
||||
if (![aString isEqualToString:[self stringValue]])
|
||||
[self clearCachedTruncatedLabel];
|
||||
|
||||
[super setStringValue:aString];
|
||||
}
|
||||
|
||||
- (void)setAttributedStringValue:(NSAttributedString *)attribStr
|
||||
{
|
||||
if (![attribStr isEqualToAttributedString:[self attributedStringValue]])
|
||||
[self clearCachedTruncatedLabel];
|
||||
|
||||
[super setAttributedStringValue:attribStr];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)aString
|
||||
{
|
||||
if (![aString isEqualToString:[self stringValue]])
|
||||
[self clearCachedTruncatedLabel];
|
||||
|
||||
[super setTitle:aString];
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)setImage:(NSImage *)anImage
|
||||
{
|
||||
if (anImage != mImage)
|
||||
{
|
||||
[mImage release];
|
||||
mImage = [anImage retain];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSImage *)image
|
||||
{
|
||||
return mImage;
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)setImagePadding:(float)padding
|
||||
{
|
||||
mImagePadding = padding;
|
||||
}
|
||||
|
||||
- (void)setImageSpace:(float)space
|
||||
{
|
||||
mImageSpace = space;
|
||||
}
|
||||
|
||||
- (void)setImageAlpha:(float)alpha
|
||||
{
|
||||
mImageAlpha = alpha;
|
||||
}
|
||||
|
||||
- (BOOL)labelTruncates
|
||||
{
|
||||
return mTruncateLabel;
|
||||
}
|
||||
|
||||
- (void)setLabelTruncates:(BOOL)inTruncates
|
||||
{
|
||||
if (mTruncateLabel != inTruncates)
|
||||
[self clearCachedTruncatedLabel];
|
||||
|
||||
mTruncateLabel = inTruncates;
|
||||
}
|
||||
|
||||
|
||||
- (void)clearCachedTruncatedLabel
|
||||
{
|
||||
[mTruncLabelString release];
|
||||
mTruncLabelString = nil;
|
||||
}
|
||||
|
||||
- (void)setClickHoldTimeout:(float)timeoutSeconds
|
||||
{
|
||||
mClickHoldTimeoutSeconds = timeoutSeconds;
|
||||
|
@ -223,7 +84,7 @@
|
|||
mIsDraggable = inDraggable;
|
||||
}
|
||||
|
||||
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
|
||||
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView*)controlView
|
||||
{
|
||||
if (!mIsDraggable)
|
||||
return [super startTrackingAt:startPoint inView:controlView];
|
||||
|
@ -232,23 +93,23 @@
|
|||
return YES; //[super startTrackingAt:startPoint inView:controlView];
|
||||
}
|
||||
|
||||
- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
|
||||
- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView*)controlView
|
||||
{
|
||||
if (!mIsDraggable)
|
||||
return [super continueTracking:lastPoint at:currentPoint inView:controlView];
|
||||
|
||||
return [DraggableImageAndTextCell prefersTrackingUntilMouseUp]; // XXX fix me?
|
||||
return [DraggableImageAndTextCell prefersTrackingUntilMouseUp]; // XXX fix me?
|
||||
}
|
||||
|
||||
// called when the mouse leaves the cell, or the mouse button was released
|
||||
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
|
||||
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView*)controlView mouseIsUp:(BOOL)flag
|
||||
{
|
||||
[super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
|
||||
}
|
||||
|
||||
#define kDragThreshold 4.0
|
||||
|
||||
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp
|
||||
- (BOOL)trackMouse:(NSEvent*)theEvent inRect:(NSRect)cellFrame ofView:(NSView*)controlView untilMouseUp:(BOOL)untilMouseUp
|
||||
{
|
||||
mLastClickHoldTimedOut = NO;
|
||||
|
||||
|
@ -263,26 +124,23 @@
|
|||
|
||||
if (![self startTrackingAt:curWindowLocation inView:controlView])
|
||||
return NO;
|
||||
|
||||
while(1)
|
||||
{
|
||||
NSEvent* event = [NSApp nextEventMatchingMask:
|
||||
(NSLeftMouseDraggedMask | NSLeftMouseUpMask)
|
||||
untilDate:clickHoldBailTime
|
||||
inMode:NSEventTrackingRunLoopMode
|
||||
dequeue:YES];
|
||||
if (!event)
|
||||
{
|
||||
|
||||
while(1) {
|
||||
NSEvent* event = [NSApp nextEventMatchingMask:(NSLeftMouseDraggedMask | NSLeftMouseUpMask)
|
||||
untilDate:clickHoldBailTime
|
||||
inMode:NSEventTrackingRunLoopMode
|
||||
dequeue:YES];
|
||||
if (!event) {
|
||||
mLastClickHoldTimedOut = YES;
|
||||
break;
|
||||
}
|
||||
|
||||
curWindowLocation = [event locationInWindow];
|
||||
lastEvent = [event type];
|
||||
|
||||
|
||||
if (![self continueTracking:lastWindowLocation at:curWindowLocation inView:controlView])
|
||||
return NO;
|
||||
|
||||
|
||||
// Tracking process
|
||||
if (([event type] == NSLeftMouseDragged) &&
|
||||
(fabs(firstWindowLocation.x - curWindowLocation.x) > kDragThreshold ||
|
||||
|
@ -290,10 +148,10 @@
|
|||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ([event type] == NSLeftMouseUp)
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
lastWindowLocation = curWindowLocation;
|
||||
}
|
||||
|
||||
|
@ -304,9 +162,9 @@
|
|||
[(NSControl*)controlView sendAction:mClickHoldAction to:[self target]];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
[self stopTracking:lastWindowLocation at:curWindowLocation inView:controlView mouseIsUp:(lastEvent == NSLeftMouseUp)];
|
||||
return YES; // XXX fix me
|
||||
return YES; // XXX fix me
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Загрузка…
Ссылка в новой задаче