• 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: [Q] How can one programatically begin a text editing session in a NSTextField?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Q] How can one programatically begin a text editing session in a NSTextField?


  • Subject: Re: [Q] How can one programatically begin a text editing session in a NSTextField?
  • From: Eric Gorr <email@hidden>
  • Date: Thu, 5 Feb 2009 11:29:10 -0500


On Feb 5, 2009, at 10:54 AM, Eric Gorr wrote:

The documentation at:

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/TextEditing/Tasks/SetFocus.html#/ /apple_ref/doc/uid/20000933

seems to indicate that one just needs to do:

[theWindow makeFirstResponder: theTextView];
[theTextView setSelectedRange:NSMakeRange(0,0)];

However, upon closer inspection, this seems to only apply to a NSTextView, not a NSTextField.
For example, NSTextField does not respond to the setSelectedRange message.


But, when I call makeFirstResponder on my NSTextField, it does return true, but an edit session is not started - I cannot type anything which changes the text in the field.

Thank you.


In case it matters and in case someone can suggest something better, the reason why I need to do this is because I have a NSView (ResourceItem) which contains both a NSImageView and a NSTextField. You can see a picture here:

http://ericgorr.net/cocoadev/outlinetable/item.png

Now, what I will need to do eventually is be able to click and drag in this ResourceItem and drag the entire item elsewhere. What I noticed is that if I clicked in the NSTextField and started dragging, it would drag the text which is not the behavior I want.

So, to change this behavior, I have modified the hitTest method of ResourceItem to be the following:

- (NSView *) hitTest:(NSPoint)aPoint
{
    NSView          *result;
    NSRect          bounds      = [self bounds];

    aPoint = [[self superview] convertPoint:aPoint toView:self];

    result = ( NSPointInRect( aPoint, bounds ) ) ? self : nil;

    return result;
}

Of course, when I do this, I can no longer click in the NSTextField and start typing, which is a problem.

However, the mouseDown, mouseDragged, and mouseUp methods of ResourceItem will get called. I figured that I could see where the mouse went up and if there was also a mouseDown and not a mouseDragged in the text field, programatically begin a text editing session in the NSTextField. Unfortunately, I cannot determine how do this.

But, perhaps, I need to actually use a NSTextView instead...?

Eventually, this view will be used in an entirely custom implementation of an outline view as pictured here:

http://ericgorr.net/cocoadev/outlinetable/outlineview.png

Sadly, it is impossible to subclass a NSTableView and NSOutlineView and get all of the functionality I need. It is also not possible to use a NSCollectionView in this situation without unacceptable behaviors.





_______________________________________________

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


  • Follow-Ups:
    • Re: [Q] How can one programatically begin a text editing session in a NSTextField?
      • From: Kyle Sluder <email@hidden>
References: 
 >[Q] How can one programatically begin a text editing session in a NSTextField? (From: Eric Gorr <email@hidden>)

  • Prev by Date: Re: [Q] How can one programatically begin a text editing session in a NSTextField?
  • Next by Date: Re: [Q] How can one programatically begin a text editing session in a NSTextField?
  • Previous by thread: Re: [Q] How can one programatically begin a text editing session in a NSTextField?
  • Next by thread: Re: [Q] How can one programatically begin a text editing session in a NSTextField?
  • Index(es):
    • Date
    • Thread