Re: Mouse events inside a cell
Re: Mouse events inside a cell
- Subject: Re: Mouse events inside a cell
- From: Anthony Arthur <email@hidden>
- Date: Mon, 3 Jun 2002 16:22:42 -0400
If you want to customize the way a UI object responds to events, such as
keyboard or mouse events, then subclassing is probably the best and/or
only way to achieve this. For example (an easy one), say you wanted to
customize a button to do something special when the event is a
double-click and the button is disabled ( normally a disabled control
will ignore mouse clicks, no matter how many )..., imagine the user is
furiously clicking like crazy as though they could will it back life,
and the button suddenly appears smart enough to respond. So you would
probably design the subclassed button to intercept mouseDown: messages
(by overriding it in your subclass) and look for the magic condition, if
it exists then post a notification, otherwise let the superclass
respond. Your custom drawing example would also fit into some custom
behavior of the UI object. The cell to subclass would be the default
cell class for that control..., so for tableView it would be
NSTableViewCell, and for matrix it would NSButtonCell..., see the docs.
Then you would need to set the prototype cell on the control to be your
custom cell class, very early.
Then there is the case that you want the UI object to send an action
( selector or message ) to a target ( an object that responds to that
action ). Here the UI object handles the mouseDown: for you, no
customization needed on your part, and somewhere down in the guts
translates this event into another message being sent to which ever
target specified, normally an application controller but it could even
be another UI object.
Finally, there is the case of delegation. There are hooks built into
the UI objects, that your controller can use to monitor certain events.
By registering the object of your choice, normally an application
controller, as the delegate of another object, most every class in
AppKit offers delegation, you may be able to bypass the need to
subclass. You can register for either delegation or notification
messages, and the API docs are typically found at the bottom for each
class that supports it. Remember, sometimes the delegation hooks you
need are handled in the superclass.
cheers,
--Brian
On Monday, June 3, 2002, at 12:44 PM, Jay Vaughan wrote:
Are you sure you want the cell object to perform some task, or do
you need another object to respond to the mouse click? It appears a
lot of you out there are getting confused between intercepting mouse
clicks, which typically is rarely needed, and having the mouse click
send an action, as when clicking a button or even a cell.
I made the same observation as you, while lurking on this list - there
has been a recurring thread on this issue - I'm just wondering if the
reason for this is because TableView's are being used as the basis for
some of the game editors people have also mentioned on this list?
For custom drawing in the cell, wouldn't receiving the mouse events
directly be necessary?
As a relative newcomer to Obj-C/OSX controls, I'm quite curious about
subclassing NSCell's for custom GUI elements (-*).
If I'm using NSCell's as the basis for new custom controls which are
inherently, 'griddable' controls, wouldn't it be better to get the
events directly, rather than going through the whole Action chain?
(*- if anyone has any pointers to custom control code, projects,
articles, or books, which detail ways to make standard custom GUI
controls using Aqua, please post details. I ditched a *lot* of custom
controls in my old Delphi work, I'd like to get up to speed on how its
done under ObjC/OSX as quickly as possible...)
-- j.
--
Jay Vaughan
Systems Engineer
Access Music http://www.access-music.de/
>> music technology ...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.