• 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
NSStatusItem hack (free code!!)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSStatusItem hack (free code!!)


  • Subject: NSStatusItem hack (free code!!)
  • From: Steve Gehrman <email@hidden>
  • Date: Fri, 14 Feb 2003 02:29:16 -0800

NSStatusItems are drawn in the menuBar with this super annoying and
ugly shadow.

I finally got sick of it and wrote a hack.... This takes away the
shadow. In this example I'm checking for an image, you can change this
if you have a text status item. I've been leaching off this list for
so long, I thought I would give something back.

(if someone has a better hack, let me know)

// call this early in the code....

[NSStatusBarButtonCell_HACK install];

// ====================================================
// header file

#import <Cocoa/Cocoa.h>

// this is undocumented, just put this phony interface so it will
compile. Linker should see it
@interface NSStatusBarButtonCell : NSButtonCell
{
}

@end

@interface NSStatusBarButtonCell_HACK : NSStatusBarButtonCell // a
type of NSButtonCell
{
}

+ (void)install;
@end

// ====================================================
// code file

#import "NSStatusBarButtonCell_HACK.h"

@implementation NSStatusBarButtonCell_HACK

+ (void)install;
{
[NSStatusBarButtonCell_HACK poseAsClass:[NSStatusBarButtonCell
class]];
}

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView
{
NSImage *image = [self image];

if (image)
{
NSImage *drawImage = [[[NSImage alloc]
initWithSize:cellFrame.size] autorelease];
NSPoint origin;

// to avoid the crazy shadow effect, make the whole thing an
image
[drawImage lockFocus];
{
int controlHeight = cellFrame.size.height;
int imageHeight = [image size].height;
int controlWidth = cellFrame.size.width;
int imageWidth = [image size].width;

origin = NSMakePoint(0,0);
origin.y += ((controlHeight - imageHeight) /2);

[image compositeToPoint:origin
operation:NSCompositeSourceOver];
}
[drawImage unlockFocus];

// now draw the image
origin = cellFrame.origin;
origin.y += cellFrame.size.height;

if ([self isHighlighted])
[drawImage compositeToPoint:origin
operation:NSCompositeSourceOver];
else
[drawImage compositeToPoint:origin
operation:NSCompositeCopy];
}
else
[super drawInteriorWithFrame:cellFrame inView:controlView];
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: pdf forms without Adobe Acrobat -also posted on macosxdev
  • Next by Date: How to know that a NSDocument is new or open from a file ?
  • Previous by thread: Re: loading nib from jnilib - now java from cocoa!
  • Next by thread: Re: NSStatusItem hack (free code!!)
  • Index(es):
    • Date
    • Thread