How can I retrieve the control's message?
-
I'm a Windows programmer, and have been written program for Linux some
times, now, I try to learn programming under Mac.
But, as you know, in Windows, there are many System-Defined custom messages,
such like WM_KEYDOWN, or, WM_NOTIFY, with these I can retrieve many
information or actions occurred on controls, such like the TreeView.
But in Mac, in cocoa, I can't find anything like them, I even don't know how
to hook the action when user input some text into the TextBox or when user
have select some node in TreeView, who can tell me, how to do this?
Thanks again. -
On Jan 28, 2008 AD, at 6:58 PM, ÃõÃÃÃ÷ wrote:> But, as you know, in Windows, there are many System-Defined custom
> messages,
> such like WM_KEYDOWN, or, WM_NOTIFY, with these I can retrieve many
> information or actions occurred on controls, such like the TreeView.
>
> But in Mac, in cocoa, I can't find anything like them, I even don't
> know how
> to hook the action when user input some text into the TextBox or
> when user
> have select some node in TreeView, who can tell me, how to do this?
The Mac OS X equivalent is to subclass the view and override the
method that handles the event, such as -keyDown:, -mouseDown:, etc.
But many classes, such as NSTextField, have either an action or
delegate API that gets called when something happens, such as -
controlTextDidChange:. If either a target/action or a delegate did-
change method is present in the class (or superclass), then you should
use them instead unless you really know what you're doing.
Nick Zitzmann
<http://www.chronosnet.com/> -
In Cocoa, you don't run the event loop yourself, so there aren't events
like this. Instead, most things like this happen via delegates, and in
some rare cases, subclassing.
For instance, when the user types into an NSTextField, the delegate
method "textDidChange:" is invoked. You need to set a delegate on the
NSTextField and implement textDidChange: in your delegate class.
çŽâ¹Ã¥â¦â æËŽ wrote:> I'm a Windows programmer, and have been written program for Linux some
> times, now, I try to learn programming under Mac.
>
> But, as you know, in Windows, there are many System-Defined custom messages,
> such like WM_KEYDOWN, or, WM_NOTIFY, with these I can retrieve many
> information or actions occurred on controls, such like the TreeView.
>
> But in Mac, in cocoa, I can't find anything like them, I even don't know how
> to hook the action when user input some text into the TextBox or when user
> have select some node in TreeView, who can tell me, how to do this?
>
> Thanks again.
> -
On Jan 28, 2008, at 6:05 PM, Nick Zitzmann wrote:> The Mac OS X equivalent is to subclass the view and override the
> method that handles the event, such as -keyDown:, -mouseDown:, etc.
>
> But many classes, such as NSTextField, have either an action or
> delegate API that gets called when something happens, such as -
> controlTextDidChange:. If either a target/action or a delegate did-
> change method is present in the class (or superclass), then you
> should use them instead unless you really know what you're doing.
I would put the second paragraph here first, for emphasis. If you're
dealing with anything that handles real text input--NSTextField, for
example--then you definitely do not want to be overriding -keyDown:.
The real solution to the OP's question is to start with some
tutorials; any introductory set of Cocoa examples would answer these
sorts of very basic questions, for which the answer is usually going
to be "hook it up in IB".
Douglas Davidson -
The following sample may help you:
http://developer.apple.com/samplecode/TextLinks/listing2.html
In file: Controller.m, there are some NSTextView delegate methods such as:
- (BOOL) textView: (NSTextView *) textView
clickedOnLink: (id) link
atIndex: (unsigned) charIndex
To make the given object the receiverââ¬â¢s delegate, you can use Interface
Builder or NSApplication's setDelegate:" method.
Also, NSNotificationCenter's "addObserver:selector:name:object:" can be used
to observe some notifications.
=============================================
Qi Liu
E-Mail: <qliu...>
--Stay Hungry. Stay Foolish.
--You've got to find what you love.
=============================================
----- Original Message -----
From: "Douglas Davidson" <ddavidso...>
To: "Nick Zitzmann" <nick...>
Cc: "çŽâ¹Ã¥â¦â æËŽ" <unalone...>; <cocoa-dev...>
Sent: Tuesday, January 29, 2008 11:12 AM
Subject: Re: How can I retrieve the control's message?>
> On Jan 28, 2008, at 6:05 PM, Nick Zitzmann wrote:
>
>> The Mac OS X equivalent is to subclass the view and override the method
>> that handles the event, such as -keyDown:, -mouseDown:, etc.
>>
>> But many classes, such as NSTextField, have either an action or delegate
>> API that gets called when something happens, such as -
>> controlTextDidChange:. If either a target/action or a delegate did-
>> change method is present in the class (or superclass), then you should
>> use them instead unless you really know what you're doing.
>
> I would put the second paragraph here first, for emphasis. If you're
> dealing with anything that handles real text input--NSTextField, for
> example--then you definitely do not want to be overriding -keyDown:. The
> real solution to the OP's question is to start with some tutorials; any
> introductory set of Cocoa examples would answer these sorts of very basic
> questions, for which the answer is usually going to be "hook it up in
> IB".
>
> Douglas Davidson
>


