• 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: AddressBook-like TextFields?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AddressBook-like TextFields?


  • Subject: Re: AddressBook-like TextFields?
  • From: Corbin Dunn <email@hidden>
  • Date: Fri, 20 May 2005 15:40:13 -0700

AddressBook is probably using NSLayoutManager directly and some custom subclass of NSView to layout and display the text. The text field for editing appears on-demand only. It has been discussed some time ago, so search the archives.

AB does use a custom subclass of NSView. Instead of laying out the text, it might be easiest to draw the text in the desired locations using an NSCell (like what the TableView does), and manually begin editing the text in a single/double click (using: [NSCell selectWithFrame:inView:editor:delegate:start:length]. A snippet of how this is done would be:


- (void)mouseDown:(NSEvent *)theEvent {
    if ([theEvent clickCount] == 2) {
        [[self window] makeFirstResponder:self];

NSRect textRect = [self currentTextRect]; // this returns the rect of our text
NSText *textEditor = [[self window] fieldEditor:YES forObject:self];
[_editingCell release];
_editingCell = [_textCell copyWithZone:NULL]; // this copies an NSTextFieldCell used for drawing
// If we don't draw the background, we will see what is underneath the cell -- which will be our text that we last had drawn.
[_editingCell setDrawsBackground:YES];
// Begin editing of the cell by selecting all the text in it. We are set as the delegate for the text operations. editWithFrame could be called instead, but it does not immdediatly select all the text in the fieldEditor.
[_editingCell selectWithFrame:textRect inView:self editor:textEditor delegate:self start:0 length:32000];
}
}



I'll send you a demo app that I have which does this. If anyone else is interested in having it, drop me an email.


--corbin
_______________________________________________
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: AddressBook-like TextFields?
      • From: Jiri Volejnik <email@hidden>
References: 
 >Re: AddressBook-like TextFields? (From: Jiri Volejnik <email@hidden>)

  • Prev by Date: Re: Creating an Offscreen NSView
  • Next by Date: Re: "Selector not recognized" for existing selector : how is this possible??
  • Previous by thread: Re: AddressBook-like TextFields?
  • Next by thread: Re: AddressBook-like TextFields?
  • Index(es):
    • Date
    • Thread