• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why do all subcell buttons highlite for custom cell in NSTableView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why do all subcell buttons highlite for custom cell in NSTableView?


  • Subject: Why do all subcell buttons highlite for custom cell in NSTableView?
  • From: Guy Umbright <email@hidden>
  • Date: Tue, 10 Jan 2006 10:34:38 -0600

I have a custom cell (CustomCell.m source below) that consists of two subcells, a button end edit cell.
When used in an NSTableView with multiple rows, when I press the button, ALL instances of the button
subcell hilight, rather than just the one I am pressing.


I suppose I am missing something here. I know that the same cell instance is used for all the cells
in the NSTable so I guess that is why the all highlight, but what then can I do to prevent this?


Guy

Code follows:
======================================================================== ==


//
//  CustomCell.m


@implementation CustomCell

///////////////////////////////////
//
///////////////////////////////////
- (id) init
{
return [self initWithString:@""];
}

///////////////////////////////////
//
///////////////////////////////////
- (id) initImageCell:(NSImage*) image
{
return [self initWithString:@""];
}

///////////////////////////////////
//
///////////////////////////////////
- (id) initTextCell:(NSString*) string
{
return [self initWithString:string];
}

///////////////////////////////////
//
///////////////////////////////////
- (id) initWithString:(NSString*) string
{
if (self = [super init])
    {
     m_buttonCell = [[NSButtonCell alloc] initImageCell: nil];
     [m_buttonCell setBezelStyle:NSRegularSquareBezelStyle];
     [m_buttonCell setButtonType:NSMomentaryPushInButton];
     [m_buttonCell setControlSize:NSSmallControlSize];

     m_editCell = [[NSTextFieldCell alloc] initTextCell:string];
     [m_editCell setEditable:YES];
     [m_editCell setDrawsBackground:NO];
     [m_editCell setWraps: YES];
    }

return self;
}

///////////////////////////////////
//
///////////////////////////////////
- (void) _CalcSubCellFrames:(NSRect) frame
{
int n;
m_buttonFrame = frame;

n = frame.size.height - 1;

m_buttonFrame.size.width = n;
m_buttonFrame.size.height = n;
m_buttonFrame.origin.x += (frame.size.width - (m_buttonFrame.size.width + 2));
//m_buttonFrame.origin.y = (frame.size.height - m_buttonFrame.size.height) / 2;


m_editFrame = frame;
m_editFrame.size.width -= m_buttonFrame.size.width;
}

///////////////////////////////////
//
///////////////////////////////////
- (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView
{
[super resetCursorRect:m_editFrame inView:controlView];
}

///////////////////////////////////
//
///////////////////////////////////
- (void) drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *) controlView
{
[self _CalcSubCellFrames:cellFrame];
[m_editCell drawWithFrame:m_editFrame inView:controlView];
[m_buttonCell drawWithFrame:m_buttonFrame inView:controlView];
}


///////////////////////////////////
//
///////////////////////////////////
- (BOOL)trackMouse:(NSEvent *)theEvent
        inRect:(NSRect)cellFrame
        ofView:(NSView *)controlView
        untilMouseUp:(BOOL)untilMouseUp
{
[self _CalcSubCellFrames:cellFrame];
return [super trackMouse: theEvent
               inRect: cellFrame
               ofView: controlView
               untilMouseUp:untilMouseUp];
}

- (BOOL) startTrackingAt: (NSPoint) startPoint inView:(NSView*) controlView
{
if (NSMouseInRect(startPoint, m_buttonFrame,NO) == YES)
{
[m_buttonCell highlight:YES withFrame:m_buttonFrame inView:controlView];
[self _RunPanel];
[m_buttonCell highlight:NO withFrame:m_buttonFrame inView:controlView];
}
else if (NSMouseInRect(startPoint, m_editFrame,NO) == YES)
{
NSText* editor = [[controlView window] fieldEditor:YES forObject:self];
NSText* object;
int l;


     l = [[m_editCell stringValue] length];
     object = [m_editCell setUpFieldEditorAttributes:editor];
     [m_editCell selectWithFrame: m_editFrame
                 inView:controlView
                 editor: object
                 delegate: self
                 start:0
                 length: l];

	}
return NO;
}


/////////////////////////////////// // /////////////////////////////////// - (NSString*) stringValue { return [m_editCell stringValue]; }

///////////////////////////////////
//
///////////////////////////////////
- (void) setStringValue:(NSString*) string
{
[m_editCell setStringValue:string];
}

///////////////////////////////////
//
///////////////////////////////////
- (void) _ButtonPressed:(id) sender
{
[self _RunPanel];
}

///////////////////////////////////
//
///////////////////////////////////
- (void) _RunPanel
{
NSOpenPanel* panel = [NSOpenPanel openPanel];
BOOL isDir,result;
NSString* s = [m_editCell stringValue];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
[panel setAllowsMultipleSelection:NO];
//???check for tilde to expand first?
if ([s length])
{
result = [[NSFileManager defaultManager] fileExistsAtPath:s isDirectory:&isDir];
}

[panel setLevel:NSModalPanelWindowLevel];
//id del = [panel delegate];
//NSLog(@"del=%@",del);
//[panel setDelegate: self];
int panelResult = [panel runModal];
if (panelResult == NSFileHandlingPanelOKButton)
{
NSArray* dir = [panel filenames];
[m_editCell setStringValue:[dir objectAtIndex:0]];
//[self setToolTip:[dir objectAtIndex:0]];
//NSLog([m_editCell stringValue]);
//NSLog(dir);
}
}


///////////////////////////////
//
///////////////////////////////
- (id) objectValue
{
return nil;
}

///////////////////////////////
//
///////////////////////////////
- (void) setObjectValue:(id) obj;
{
[self setStringValue:obj];
}

///////////////////////////////
//
///////////////////////////////
- (void) windowDidExpose:(NSNotification*) aNotification
{
NSLog(@"dummy");
}

@end


================================= code from window containing the NSTableView


- (void) awakeFromNib { NSArray* cols;

CustomCell* cell2 = [[[CustomCell alloc] init] retain];

cols = [o_table tableColumns];

[[cols objectAtIndex:1] setDataCell: cell2];
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40kickstandsoft.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Why do all subcell buttons highlite for custom cell in NSTableView?
      • From: Corbin Dunn <email@hidden>
  • Prev by Date: RE: Getting started with WebKit plugins
  • Next by Date: Re: Unable to Load Window NIB
  • Previous by thread: Re: Why do all subcell buttons highlite for custom cell in NSTableView?
  • Next by thread: Re: Why do all subcell buttons highlite for custom cell in NSTableView?
  • Index(es):
    • Date
    • Thread