• 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
Re: Setting a shadow in -willDisplayCell causes CGContextSetStyle error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting a shadow in -willDisplayCell causes CGContextSetStyle error?


  • Subject: Re: Setting a shadow in -willDisplayCell causes CGContextSetStyle error?
  • From: "Julien Jalon" <email@hidden>
  • Date: Thu, 11 Oct 2007 13:40:42 +0200

You never can't assume willDisplayCell: will be called inside a drawing
context (it's "willDisplay:", not "willDraw:" method, after all ;-) ).
If you want to add niceties to your cells, you should:

1) subclass the NSCell classes you use and use them as your cell class
prototype:

@interface KBShadowyTextFieldCell : NSTextFieldCell
{
    NSShadow* cellShadow;
}

- (void)setShadow:(NSShadow *)aShadow;
- (NSShadow *)shadow;

@end


@implementation KBShadowyTextFieldCell

- (void)dealloc
{
    [shadow release];
    [super dealloc];
}

- (void)setShadow:(NSShadow *)aShadow
{
    if(aShadow != shadow) {
       [aShadow retain];
       [shadow release];
       shadow = aShadow;
    }
}

- (NSShadow *)shadow
{
    return shadow;
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
    [NSGraphicsContext saveGraphicsState];
    [shadow set];
    [super drawWithFrame:cellFrame inView:controlView];
    [NSGraphicsContext restoreGraphicsState];
}


@end

[... and in your delegate method ...]

- (void)outlineView:(NSOutlineView *)olv
willDisplayCell:(id)cell
        forTableColumn:(NSTableColumn *)tableColumn
item:(id)item
{
       NSShadow *shadow = [[NSShadow alloc] init];
       [shadow setShadowOffset:NSMakeSize(0, -1.1)];
       [shadow setShadowColor:[NSColor grayColor]];
       [(KBShadowyTextFieldCell *)cell ];
       [shadow release];
}


On 10/11/07, Keith Blount <email@hidden> wrote:
>
> Hi,
>
> A couple of months ago, I posted about an apparently
> benign error my app was generating on the console:
>
> CGContextSetStyle: invalid context
>
> (The original thread can be found here:
> http://www.cocoabuilder.com/archive/message/cocoa/2007/8/24/188258)
>
> It has had me stumped ever since, but today I *think*
> I have finally found the cause. (The strange thing was
> that this error only ever appeared if projects were
> opened via File > Open; my app automatically opens the
> last project when it is launched, and the error never
> seems to occur in this circumstance so I kept missing
> it - weird.)
>
> It seems to come from the fact that I add a shadow to
> the text of my NSOutlineView source list using
> -outlineView:willDisplayCell:forTableColumn:item: as
> follows:
>
> - (void)outlineView:(NSOutlineView *)olv
> willDisplayCell:(id)cell
>          forTableColumn:(NSTableColumn *)tableColumn
> item:(id)item
> {
>         NSShadow *shadow = [[NSShadow alloc] init];
>         [shadow setShadowOffset:NSMakeSize(0, -1.1)];
>         [shadow setShadowColor:[NSColor grayColor]];
>         [shadow set];
>         [shadow autorelease];
> }
>
> The above code seems to cause a "CGContextSetStyle:
> invalid context" console error whenever it is called
> if the item is selected (which, unfortunately, is the
> exact case in which I want to add a shadow in my code
> - for selected items).
>
> Can anyone see what I am doing wrong here, or why this
> might be generating such an error? Is there a better
> way of setting the shadow that will avoid this console
> error?
>
> Many thanks in advance,
> Keith
>
>
>       ____________________________________________________________
> ________________________
> Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get
> listings, and more!
> http://tv.yahoo.com/collections/3658
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Setting a shadow in -willDisplayCell causes CGContextSetStyle error? (From: Keith Blount <email@hidden>)

  • Prev by Date: Setting a shadow in -willDisplayCell causes CGContextSetStyle error?
  • Next by Date: Re: NSOpenPanel & NSFileTypeForHFSTypeCode
  • Previous by thread: Setting a shadow in -willDisplayCell causes CGContextSetStyle error?
  • Next by thread: selectable text field
  • Index(es):
    • Date
    • Thread