• 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
Using NSTextCell to act like the Address Book in custom NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using NSTextCell to act like the Address Book in custom NSTextView


  • Subject: Using NSTextCell to act like the Address Book in custom NSTextView
  • From: Kevin Brown <email@hidden>
  • Date: Thu, 16 Nov 2006 08:23:06 -0800

I'm writing a music notation program, and I'd like to have the program essentially act like the address book for the user to be able to input the title of the tune, composer, etc. I assume they're going about this with NSTextCells.

Currently, I'm drawing an NSTextCell as part of my drawRect: method. The only problem I'm having is some strangeness when they edit. So, here's my current mouseDown: method:

- (void)mouseDown:(NSEvent*)theEvent
{
	NSPoint clickLocation;

	clickLocation = [self convertPoint:[theEvent locationInWindow]
							  fromView:nil];

	// Go through my various cells and see if the click happened
	// in them.  If so, start editing them.  Else, click was in
	// the text view and we'll let it handle that.
	if (NSPointInRect(clickLocation, TITLE_RECT))
	{
		[titleCell editWithFrame:TITLE_RECT
					 inView:self
					 editor:[[self window] fieldEditor:YES forObject:self]
				   delegate:self
					  event:theEvent];

		return;
	}
	else
	{
		[titleCell endEditing:[[self window] fieldEditor:YES forObject:self]];
		[self setNeedsDisplay:YES];
	}

	[super mouseDown:theEvent];
}

TITLE_RECT is #defined to the same NSMakeRect call that we use to draw the cell.

Essentially, the placeholder text stays there when they start editing (so they're typing over grey text). Then, once they finish editing, the view simply reverts to being empty and doesn't seem to hold its text.

Can anyone shed some light on what I'm missing? I haven't implemented any delegate methods for NSCell or anything, so if I need to, where are those documented?

For the record, here's how I instantiate the NSTextCell and how I draw it.

// In initWithFrame:
		titleCell = [[NSTextFieldCell alloc] initTextCell:@""];
		[titleCell setPlaceholderString:@"Title"];
		[titleCell setEditable:YES];
		[titleCell setBordered:YES];
		[titleCell setFocusRingType:NSFocusRingTypeExterior];
		[titleCell setAlignment:NSCenterTextAlignment];

// In drawRect:
	[titleCell drawWithFrame:TITLE_RECT inView:self];

_______________________________________________
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


  • Prev by Date: Re: Why doesn't CFDictionaryContainsKey() work?
  • Next by Date: Re: Why doesn't CFDictionaryContainsKey() work?
  • Previous by thread: Re: Re: [SOLVED] Why doesn't CFDictionaryContainsKey() work?
  • Next by thread: Tooltips for hidden applications
  • Index(es):
    • Date
    • Thread