On Oct 20, 2008, at 6:23 AM, Ricky Sharp wrote:

This is actually quite difficult. I can send you details later today. In my case, I needed accessibility and mimic the Aqua radio buttons in terms of all their behaviors.

I ended up subclassing NSMatrix and NSActionCell. I could not get a subclass of NSButtonCell in an NSMatrix to work completely.


I originally attempted to create a custom radio button control around Nov 2004. You can search the archives for a thread back then titled "Tracking behavior of cells in NSMatrix".

There seemed to be some special code going on between NSMatrix and NSButtonCell that I could not duplicate. There are probably many private methods at work.

Anyhow, my final solution was to do this:

subclass NSMatrix (this will be your "radio button group")

In that subclass, I implemented mouseDown: to do the following:

- call convertPoint:fromView: to get the view's point that was clicked
- call getRow:column:forPoint: to see if point clicked any cells
- if it did, call cellAtRow:column: to get the cell instance.

Then it got tricky...

if the matrix didn't yet have a keyCell, I set the key cell to the one just clicked

I then fell into a local tracking loop by sending trackMouse:inRect:ofView:untilMouseUp: to the cell.

If the mouse was released inside the bounds of the cell being tracked...
- set the state of the original cell to NSOffsate and set the state of the tracked cell to NSOnState.

else...
- set the key cell to the original key cell before tracking was started.


Then, in a subclass of NSActionCell, I implemented:

trackMouse:inRect:ofView:untilMouseUp:

I maintained a flag in that class so I could query if the mouse was released in its bounds or not (used by the matrix's mouseDown: code above).

The subclass of NSActionCell of course handled all custom drawing too depending on state.


This implementation (plus more code not shown) gave me:

- custom drawing
- exact Aqua behaviors when dealing with mouse or full keyboard access
- bindings integration (e.g. selectedRadioTag)
- accessibility hooks

___________________________________________________________
Ricky A. Sharp         mailto:[EMAIL PROTECTED]
Instant Interactive(tm)   http://www.instantinteractive.com



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to