Re: Re: redrawing an NSPopUpButtonCell, and ghost effect
Re: Re: redrawing an NSPopUpButtonCell, and ghost effect
- Subject: Re: Re: redrawing an NSPopUpButtonCell, and ghost effect
- From: "Ender Wiggins" <email@hidden>
- Date: Sat, 12 Aug 2006 20:36:37 -0500
Thanks Pat, I see what you mean, I'll work on this as soon as I get
another problem out of the way, this is helpful.
On 8/11/06, PGM <email@hidden> wrote:
For my own tableView headerCell troubles, I worked around the "ghost
column" problem by using the following code in a subclass of
NSTableHeaderCell:
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)
controlView
{
//this method is also called for the headerCell of the ghost column
[super drawInteriorWithFrame:cellFrame inView:controlView];
//don't draw any additional stuff if value is not set
(otherwise empty column at end is also drawn)
if([[self title] length]){
//some custom drawing for my headerCell that I do not want in the
ghost column
}
}
You can subclass NSpopUpButtonCell to achieve more or less the same,
something like:
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)
controlView
{
if(someFlag){
//if not last column, draw the popUp
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
else{
//draw some background
}
}
Then you have to initialise the instance variable "someFlag" to NO,
and make an accessor so that you can set it to YES for every column
you create. Alternatively there may be some property of the cell that
the ghost column does not have, but all others do, and test for that.
Best, Patrick
On 10-Aug-06, at 22:01 PM, Ender Wiggins wrote:
> I have a new problem by putting an NSPopUpButtonCell within my tables
> headers by subclassing NSTableHeaderView.
>
> #1 If I setBordered:NO on the NSPopUpButtonCell, then once I select
> the button by pressing mouse down, the cell seems to draw the newly
> selected item text on top of the previous item text without clearing
> it first. If I set it to YES, then it displays the new selection
> within the cell just fine, but of course, shows the border that I
> don't want.
>
> One thing to note here is that, if I tab over to another NSView, and
> then click on a tab which brings this tabbed pane back up, the
> NSTableView headers are redisplayed correctly and cleanly. I tried
> setNeedsDisplay, but that didn't do anything to it.
>
> #2 The other problem is that the NSTableHeaderView has 4 columns, but
> shows a 5th column as well, like a ghost effect of what's in the 4th.
> If I select the mouseDown on the 5th column, my mouseDown debug output
> displays a -1 for that column (like it doesn't exist, but it shows
> up), but clicking on the other 4 columns show output correctly from 0
> to 3. Clicking on other tab buttons and coming back to this
> NSTableView screen don't clear out the 5th column problem.
>
> Here is how my popup button cells are created in the columns.
> [code]
> NSString *col = [columnItems objectAtIndex:i];
>
> headerCell = [[NSPopUpButtonCell alloc] initTextCell:col];
> [headerCell setPullsDown:NO];
> [headerCell setControlSize:NSMiniControlSize];
> [headerCell setBordered:YES];
> [headerCell setEditable:YES];
> [headerCell setControlView:[tableView headerView]];
> [headerCell setFont:[NSFont labelFontOfSize:
> [NSFont smallSystemFontSize]]];
>
> [headerCell addItemWithTitle:@"Item A"];
> [headerCell addItemWithTitle:@"Item B"];
> [headerCell addItemWithTitle:@"Item C"];
>
> column = [[NSTableColumn alloc]
> initWithIdentifier:[NSNumber numberWithInt:i]];
>
> [column setHeaderCell:headerCell];
> [headerCell release];
>
> [tableView addTableColumn:column];
> [column release];
> [/code]
>
> This is my class subclassed from NSTableHeaderView, mouseDown method.
> [code]
> - (void)mouseDown:(NSEvent *)event
> {
> NSPoint point = [event locationInWindow];
>
> int column = [self columnAtPoint:[self convertPoint:point
> fromView:nil]];
> NSLog(@"column: %d", column);
>
> if (column >= 0) {
> NSTableColumn *col = [[[self tableView] tableColumns]
> objectAtIndex:column];
>
> [[col headerCell] trackMouse:event
> inRect:[self headerRectOfColumn:column]
> ofView:self untilMouseUp:NO];
>
> NSLog(@"selected %@", [[[col headerCell] selectedItem] title]);
> [[col headerCell] setTitle:[[[col headerCell] selectedItem] title]];
>
> [self setNeedsDisplay:YES];
> } else {
> [super mouseDown:event];
> }
> }
>
> [/code]
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> 40sympatico.ca
>
> 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