Re: [Q] How can one programatically begin a text editing session in a NSTextField?
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: Michael Ash <email@hidden>
- Date: Thu, 5 Feb 2009 15:39:42 -0500
On Thu, Feb 5, 2009 at 12:39 PM, Eric Gorr <email@hidden> wrote:
>
> On Feb 5, 2009, at 12:33 PM, Andy Lee wrote:
>
>> On Feb 5, 2009, at 12:17 PM, Eric Gorr wrote:
>>>
>>> I wasn't sure what _textField2 was supposed to refer to exactly,
>>
>> Oops, copy-paste error. :)
>>
>>> so I tried this instead:
>>>
>>> [[textField currentEditor] setSelectedRange:NSMakeRange(0, 0)];
>>
>> Bah, currentEditor is what I was trying to remember.
>
> :-)
>
> So, if you know of an easy way to determine the location in the string of a
> NSTextField where a click occurred, I am interested.
>
> Or a better way, which works around this whole mess, to accomplish what I
> described in:
>
> http://lists.apple.com/archives/cocoa-dev/2009/Feb/msg00341.html
>
> I would be interested in that as well.
Let me see if I understand this correctly. You have a text field in a
view. You want to be able to drag the mouse anywhere in the view
without editing the text field, but you want to be able to click on
the text field to edit it, right?
Seems to me that the simplest solution would be to just selectively
forward events to the text field. Something like this in your view:
- (void)mouseDown:(NSEvent *)event {
[self setLastMouseDownEvent:event]; // this is just a setter for an ivar
}
- (void)mouseDragged:(NSEvent *)event {
[self setLastMouseDownEvent:nil];
/* do whatever it is that you do here */
}
- (void)mouseUp:(NSEvent *)event {
NSEvent *mouseDown = [self lastMouseDownEvent];
if(mouseDown) {
[NSApp postEvent:event atStart:YES];
[_textField mouseDown:mouseDown];
}
}
Mike
_______________________________________________
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