File: programming/cocoa/UKDistributedView.zip/UKDistributedView/UKFinderIconCell/UKFinderIconCell.m


/* =============================================================================
	FILE:		UKFinderIconCell.m
	PROJECT:	UKDistributedView
 
    COPYRIGHT:  (c) 2003 M. Uli Kusterer, all rights reserved.
    
	AUTHORS:	M. Uli Kusterer - UK
    
    LICENSES:   GPL, Commercial (ask for pricing)
 
	REVISIONS:
		2003-12-19	UK	Created.
   ========================================================================== */
 
// -----------------------------------------------------------------------------
//  Headers:
// -----------------------------------------------------------------------------
 
#import "UKFinderIconCell.h"
#import "NSBezierPathCappedBoxes.h"
#import "NSImage+NiceScaling.h"
 
 
// -----------------------------------------------------------------------------
//  Private Methods:
// -----------------------------------------------------------------------------
// Is reset each time cell is drawn in a view.
// -----------------------------------------------------------------------------
//  Designated initializer:
// -----------------------------------------------------------------------------
"NSApplicationIcon""UKDVUKDT"/* -----------------------------------------------------------------------------
	initWithCoder:
		Persistence constructor needed for IB palette.
	
	REVISIONS:
        2004-12-03	UK	Created.
   -------------------------------------------------------------------------- */"UKFICimage""UKFICnameColor""UKFICboxColor""UKFICselectionColor""UKFICbgColor""UKFICimagePosition""UKFICtruncateMode""UKFICalpha""NSApplicationIcon"/* -----------------------------------------------------------------------------
	encodeWithCoder:
		Save this cell to a file. Used by IB.
	
	REVISIONS:
        2004-12-03	UK	Created.
   -------------------------------------------------------------------------- */"UKFICimage""UKFICnameColor""UKFICboxColor""UKFICimagePosition""UKFICselectionColor""UKFICbgColor""UKFICtruncateMode""UKFICalpha"// -----------------------------------------------------------------------------
//  Initializer for us lazy ones:
// -----------------------------------------------------------------------------
"UKDVUliDaniel"];
}
 
 
// -----------------------------------------------------------------------------
//  Destructor:
// -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
	copyWithZone:
		Implement the NSCopying protocol (IB requires this, and some cell-based
        classes may, as well).
	
	REVISIONS:
        2004-12-23	UK	Documented.
   -------------------------------------------------------------------------- */// -----------------------------------------------------------------------------
//  Reset boxColor, nameColor and selectionColor to the defaults:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for cell selection state:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Accessor for cell flipped state (cached from last drawing):
//      Mutator is in private methods.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for separator at top of cell:
// -----------------------------------------------------------------------------
/*-(void) drawWithFrame: (NSRect)box inView: (NSView*)aView
{
    [self drawInteriorWithFrame: box inView: aView];
}*/// Just to shut up compiler warnings.
// -----------------------------------------------------------------------------
//  Draws everything you see of the cell:
// -----------------------------------------------------------------------------
//NSLog(@"drawing %@", UKDebugNameFor(self));
	
    /*
    attrs = [NSDictionary dictionaryWithObjectsAndKeys:
                    [NSFont systemFontOfSize: 12], NSFontAttributeName,
                    [[NSColor alternateSelectedControlTextColor] colorWithAlphaComponent: alpha], NSForegroundColorAttributeName,
                    nil];*/// Just to shut up compiler warnings.
// Make sure we don't draw outside our cell.
	
	// Set up text attributes for title:
// Calculate area left for title beside image:
// How much to make title narrower to allow for icon next to it.
// Truncate string if needed:
// Removed - - here.
 
	// Calculate rectangle for text:
// Finder icon view (big, title below image).
// Title *above* image.
// Center our text at cell's bottom.
// Give us some room around our text.
// Center our text vertically in cell.
/*-truncf(txSize.height /2)*/ );		// Give us some room around our text.
	}
		
	// Prepare image and image highlight rect:
// TODO: Sidewards titles are broken.
"UKFinderIconCell - Unsupported image position mode."// Make sure icon box is pretty and square:
// Force width to be same as height.
// Center narrower box in cell.
// Draw text background either with white, or with "selected" color:
// draw text bg.
	
	// Draw actual text:
// If selected, draw image highlight rect:
// Set up line for selection outline:
// Draw selection outline:
// Slightly transparent body first.
// Opaque rounded boundaries next.
// Clean up:
// Calculate box for icon:
/*imgBox.origin.x += (imgBox.size.width -actualSize.width) /2;	// Center icon image in icon box.
	imgBox.origin.y += (imgBox.size.height -actualSize.height) /2;*/
 
        // Make sure we're drawing on whole pixels, not between them:
    imgBox.origin.x = truncf(imgBox.origin.x);
    imgBox.origin.y = truncf(imgBox.origin.y);
	//imgBox.size.width = actualSize.width;
	//imgBox.size.height = actualSize.height;
// Draw it!
/*if( [aView isKindOfClass: [NSMatrix class]] )
        drawUpsideDown = !drawUpsideDown;*//*if( flags.flipped )
		[image compositeToPoint: NSMakePoint(imgBox.origin.x,imgBox.origin.y +actualSize.height) operation: NSCompositeSourceOver fraction: alpha];
	else
		[image compositeToPoint: imgBox.origin operation: NSCompositeSourceOver fraction: alpha];*/// -----------------------------------------------------------------------------
//  Accessor for cell icon:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for cell icon:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for name background color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Accessor for name background color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for icon highlight box color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Accessor for icon highlight box color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for cell background color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Accessor for cell background color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Mutator for name highlight color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Accessor for name highlight color:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Accessors/Mutators for image positioning relative to title:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  Size we'd want for cell:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	editWithFrame:inView:editor:delegate:event:
//		Start inline-editing.
//	
//	REVISIONS:
//        2004-12-23	UK	Documented.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	endEditing:
//		Finish inline-editing.
//	
//	REVISIONS:
//        2004-12-23	UK	Documented.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	selectWithFrame:inView:editor:delegate:start:length:
//		Alternate way to start inline-editing.
//	
//	REVISIONS:
//        2004-12-23	UK	Documented.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	Accessor/Mutator for how to truncate title string:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	Accessor/Mutator for opacity of cell drawing:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	Querying where the title is displayed:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	Adjust text alignment for drawing so it goes nicely with the image display
//      position:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	Mutator for flipped drawing:
// -----------------------------------------------------------------------------
// Is reset every time you draw this into a view.
// -----------------------------------------------------------------------------
//  Returns a truncated version of the specified string that fits a width:
//		Appends/Inserts three periods as an "ellipsis" to/in the string to
//      indicate when and where it was truncated.
// -----------------------------------------------------------------------------
// Don't do anything if it fits.
// NSLineBreakByTruncatingMiddle
"...""..."// No need to fix location, stays at start.
// Fix location so range that's one longer still lies inside our string at end.
// even? NSLineBreakByTruncatingMiddle
            rangeToCut.location--;  // Move location left every other time, so it grows to right and left and stays centered.
"..."

This code uses the PclZip Zip File reading code, which is subject to the GNU LGPL. It also uses the GeSHi syntax highlighter, subject to the GPL. Ask if you want this for your own web site, it's free.