CocoaDev

Edit AllPages

This is just a prettied up version of what’s in NSTableViewRollover. (Moved from CCDSourceTable.)

Never mind the inaccurate description, see the example: http://homepage.mac.com/ryanstevens/SourceList.zip

// Copyright (c) 2005 Ryan Stevens. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the “Software”), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software. // // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. //

#import <Cocoa/Cocoa.h>

@interface CCDGradientSelectionTableCell : NSTextFieldCell {} @end

@interface CCDGradientHeaderView : NSTableHeaderView { NSImage *headerGradient; NSString *headerTitle; }

@interface CCDGradientSelectionTableView : NSTableView { NSImage *blueGradient; NSImage *grayGradient; NSRect iRect;

	int mouseOverRow;
	int lastOverRow;
	NSTrackingRectTag trackingTag;
            BOOL mouseInView; }

#import “CCDGradientSelectionTableView.h”

// You’ll want to do something like this in the class you use as your dataCell. @implementation CCDGradientSelectionTableCell

// This keeps the fieldEditor in check.

@end

@implementation CCDGradientHeaderView

static NSString *headerImageData = @”<4d4d002a 00000074 fe6afe97 fed2fee8 00e6ffe5 00e4ffe3 fee1fede 02dcdbdc 02d9d8d9 02d6d5d6 02d2d1d2 02cfcecf fecbfec8 fec4fec0 febdfeb9 feb5feb2 00afffae 00abffaa 00a8ffa7 fea402a1 a0a1029e 9d9e029b 9a9b0298 97980295 9495fe92 fe90008e ff8d008c ff8b007c ff7bfe6b 000c0100 00030000 00010001 00000101 00030000 00010024 00000102 00030000 00030000 010a0103 00030000 00018005 00000106 00030000 00010002 00000111 00040000 00010000 00080115 00030000 00010003 00000117 00040000 00010000 006c011a 00050000 00010000 0110011b 00050000 00010000 0118011c 00030000 00010001 00000128 00030000 00010002 00000000 00000008 00080008 000afc80 00002710 000afc80 00002710 >”;

-(void)mouseDown:(NSEvent *)event { self window] makeFirstResponder:[self tableView; } @end

@implementation CCDGradientSelectionTableView

static NSString *blueImageData = @”<4d4d002a 00000048 800f4f6d a2ca65ca 564b390a 69371941 1ee22622 dc04743b 7c86826e 900fcdb1 d9e5b237 3ab60647 06b0b8d8 d5151a1a 82732348 46616888 4bcd00f9 719f0100 000d0100 00030000 00010001 00000101 00030000 00010012 00000102 00030000 00030000 00ea0103 00030000 00010005 00000106 00030000 00010002 00000111 00040000 00010000 00080115 00030000 00010003 00000116 00040000 00010000 2aaa0117 00040000 00010000 003f011a 00050000 00010000 00f0011b 00050000 00010000 00f8011c 00030000 00010001 00000128 00030000 00010002 00000000 00000008 00080008 000afc80 00002710 000afc80 00002710 >”; static NSString *grayImageData = @”<4d4d002a 0000006c 808080e5 7e7e7ee5 7d7d7de5 7c7c7ce5 7a7a7be5 787778e5 777676e5 747474e5 737373e5 727171e5 706f6fe5 6d6d6ce5 6c6c6be5 6a6a6ae5 696969e5 676767e5 656565e5 636464e5 616161e5 616161e5 606161e5 5f5e5fe5 5e5e5ee5 5d5d5de5 5c5c5ce5 000d0100 00030000 00010001 00000101 00030000 00010019 00000102 00030000 00040000 010e0103 00030000 00010001 00000106 00030000 00010002 00000111 00040000 00010000 00080115 00030000 00010004 00000117 00040000 00010000 0064011a 00050000 00010000 0116011b 00050000 00010000 011e011c 00030000 00010001 00000128 00030000 00010002 00000152 00030000 00010001 00000000 00000008 00080008 0008000a fc800000 2710000a fc800000 2710>”;

// You’ll want to remove this if you use a custom dataCell

Your delegate should look something like this…


Without a custom fieldEditor editing isn’t going to work exactly like it does in iTunes but I think I’ve got it pretty close here.

Fixed a glitch. My bad.

—-Discussion—-

Looks great! However theres a pretty decent bug at least on Mac OS X 10.4.2 where when you load the Sample app with the iTunes like table and everything looks good, then you switch to another window or app and take the focus away from the app with the table and the Header title disappears, when you bring focus back to the app it works just like before except the title is gone. Anybody else get this? I’ve tried this in my app and in the sample app and it’s reproducable 100% of the time for me so far.


I, too, am getting that bug, but for my uses, I didn’t really like the whole textured header thing anyway, so I just used the regular Aqua header. I never really attempted to chase down the cause. I suspect that if you were to use needsDisplay: on it, when it becomes firstResponder, then that would force it to redraw, and get around the issue, but it may not help figure out the original cause. Someone, please correct me if I’m wrong. – JasonTerhorst


Sounds like the header view isn’t getting its notifications. shrug