FS Browser Cell

Dieses Thema im Forum "Mac OS Entwickler, Programmierer" wurde erstellt von Macisiert, 18.07.2005.

  1. Macisiert

    Macisiert Thread Starter MacUser Mitglied

    Mitglied seit:
    hi leute
    zu diesem code würde mich interessieren ( eines der apple examples)
    wie ich ein stammverzeichnis festlege. zb das ich eine zeile im code habe wo er gleich automatisch zu meinen fotos springt und ich mich nicht erst bis dort hin durchklicken muss

    #import "FSNodeInfo.h"
    #import "FSBrowserCell.h"
    #define ICON_INSET_VERT		2.0	/* The size of empty space between the icon end the top/bottom of the cell */ 
    #define ICON_SIZE 		16.0	/* Our Icons are ICON_SIZE x ICON_SIZE */
    #define ICON_INSET_HORIZ	4.0	/* Distance to inset the icon from the left edge. */
    #define ICON_TEXT_SPACING	2.0	/* Distance between the end of the icon and the text part */
    @interface FSBrowserCell (PrivateUtilities)
    	// This is a category in FSBrowserCell since it somewhat UI related and its a good idea to keep the UI part separate from the low level parts.
    		+ (NSDictionary*)stringAttributesForNode:(FSNodeInfo*)node;
    @implementation FSBrowserCell
    	- (void)dealloc 
    		[iconImage release];
    		iconImage = nil;
    		[super dealloc];
    	- (void)setAttributedStringValueFromFSNodeInfo:(FSNodeInfo*)node 
    		// Given a particular FSNodeInfo object set up our display properties.
    			NSString *stringValue = [node lastPathComponent];
    		// Set the text part.   FSNode will format the string (underline, bold, etc...) based on various properties of the file.
    			[self setAttributedStringValue: [[[NSAttributedString alloc] initWithString:stringValue attributes:[FSBrowserCell stringAttributesForNode:node]] autorelease]];
    		// Set the image part.  FSNodeInfo knows how to look up the proper icon to use for a give file/directory.
    			[self setIconImage: [node iconImageOfSize:NSMakeSize(ICON_SIZE,ICON_SIZE)]];
    		// If we don't have access to the file, make sure the user can't select it!
    			[self setEnabled: [node isReadable]];
    		// Make sure the cell knows if it has children or not.
    			[self setLeaf:![node isDirectory]];
    	- (NSSize)cellSizeForBounds:(NSRect)aRect 
    		// Make our cells a bit higher than normal to give some additional space for the icon to fit.
    			NSSize theSize = [super cellSizeForBounds:aRect];
    			theSize.width += [[self iconImage] size].width + ICON_INSET_HORIZ + ICON_INSET_HORIZ;
    			theSize.height = ICON_SIZE + ICON_INSET_VERT * 2.0;
    			return theSize;
    	- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
        if (iconImage != nil) 
    			NSSize	imageSize = [iconImage size];
    			NSRect	imageFrame, highlightRect, textFrame;
    		// Divide the cell into 2 parts, the image part (on the left) and the text part.
    			NSDivideRect(cellFrame, &imageFrame, &textFrame, ICON_INSET_HORIZ + ICON_TEXT_SPACING + imageSize.width, NSMinXEdge);
    			imageFrame.origin.x += ICON_INSET_HORIZ;
    			imageFrame.size = imageSize;
    		// Adjust the image frame top account for the fact that we may or may not be in a flipped control view, since when compositing
    		// the online documentation states: "The image will have the orientation of the base coordinate system, regardless of the destination coordinates".
    			if ([controlView isFlipped]) imageFrame.origin.y += ceil((textFrame.size.height + imageFrame.size.height) / 2);
    			else imageFrame.origin.y += ceil((textFrame.size.height - imageFrame.size.height) / 2);
    		// Depending on the current state, set the color we will highlight with.
    			if ([self isHighlighted]) 
    					// use highlightColorInView instead of [NSColor selectedControlColor] since NSBrowserCell slightly dims all cells except those in the right most column.
    					// The return value from highlightColorInView will return the appropriate one for you. 
    						[[self highlightColorInView: controlView] set];
    						[[NSColor controlBackgroundColor] set];
    		// Draw the highlight, but only the portion that won't be caught by the call to [super drawInteriorWithFrame:...] below.  No need to draw parts 2 times!
    			highlightRect = NSMakeRect(NSMinX(cellFrame), NSMinY(cellFrame), NSWidth(cellFrame) - NSWidth(textFrame), NSHeight(cellFrame));
    		// Blit the image.
    			[iconImage compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
    		// Have NSBrowser kindly draw the text part, since it knows how to do that for us, no need to re-invent what it knows how to do.
    			[super drawInteriorWithFrame:textFrame inView:controlView];
    			// At least draw something if we couldn't find an icon. show another icon
    			[super drawInteriorWithFrame:cellFrame inView:controlView];
    @implementation FSBrowserCell (PrivateUtilities)
    	+ (NSDictionary*)stringAttributesForNode:(FSNodeInfo*)node
    		NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    		[attrs setObject: [NSFont systemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
    			// Just for fun,let's underline the text of things that are links.
    		if ([node isLink]) 
    			[attrs setObject:[NSNumber numberWithInt:NSSingleUnderlineStyle] forKey:NSUnderlineStyleAttributeName];
    		return attrs;

    mfg bernhard
Die Seite wird geladen...