• 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: Temporary text display over NSTableView (was NSTextField over NSImageView?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Temporary text display over NSTableView (was NSTextField over NSImageView?)


  • Subject: Re: Temporary text display over NSTableView (was NSTextField over NSImageView?)
  • From: Ricky Sharp <email@hidden>
  • Date: Sun, 23 Apr 2006 16:09:29 -0500


On Apr 23, 2006, at 10:20 AM, James Bucanek wrote:

When a user opens a new document window they get an empty NSTableView -- this is not very informative. I'd like to superimpose some subtle text (light grey or semi-transparent) over the center of the table to the effect of "To add items to the table, drag and drop them here." This text would go away as soon as the table was no longer empty.

What would be the sane+Cocoa way of accomplishing this?

- I know that I could simply override the NSTableView's drawing routine and draw my text directly into the view after the table is finished drawing. I've been putting this off because it just seems like a lot of work (get a font, measure it, calculate a centering rectangle, ...).

- Using NSTextField would make less work for me because it would handle all of the centering, clipping, wrapping, etc. of the text (and I could localize the message in the NIB). But where do I stick it in the NSView hierarchy and how to I keep it centered over the table? From the earlier thread, it appears that just cramming it into the same NSView that the NSTableView is in is a bad idea. On the other hand, making an NSTextField a subview of an NSTableView just seems bizarre and I'm afraid of messing up the NSTableView's subview(s).

I would look into using an overlay window. Basically you:

(a) subclass NSWindow and set appropriate attributes. Here's how I set things up for a "watermark" window:

	if ((self = [super initWithContentRect:theContentRect
		styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
		defer:NO]) != nil)
		{
		[self setLevel:NSFloatingWindowLevel];
		[self setBackgroundColor:[NSColor clearColor]];
		[self setIgnoresMouseEvents:YES];
		[self setHidesOnDeactivate:YES];
		[self setReleasedWhenClosed:NO];
		[self setMovableByWindowBackground:NO];
		[self setHasShadow:NO];
		[self useOptimizedDrawing:YES];

		[self setOpaque:NO];
		[self setAlphaValue:1.0];
		}

(b) create and add the window as a child to your table-view's window:

MyOverlayWindow* theOverlayWindow = ...

[theOverlayWindow orderFront:nil];
[theTableViewWindow addChildWindow:theOverlayWindow ordered:NSWindowAbove];


(c) Add a text control as a subview of the overlay window's content view

NSControl* theTextMessage] = ...

[[theOverlayWindow contentView] addSubview:theTextMessage];


(d) add logic to show/hide the overlay as needed.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
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: Temporary text display over NSTableView (was NSTextField over NSImageView?)
      • From: Andy Lee <email@hidden>
References: 
 >Temporary text display over NSTableView (was NSTextField over NSImageView?) (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Superimpose a NSTextField over NSImageView?
  • Next by Date: Re: Temporary text display over NSTableView (was NSTextField over NSImageView?)
  • Previous by thread: Re: Temporary text display over NSTableView (was NSTextField over NSImageView?)
  • Next by thread: Re: Temporary text display over NSTableView (was NSTextField over NSImageView?)
  • Index(es):
    • Date
    • Thread