• 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: Custom button cells for NSMatrix
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom button cells for NSMatrix


  • Subject: Re: Custom button cells for NSMatrix
  • From: Ricky Sharp <email@hidden>
  • Date: Mon, 20 Oct 2008 15:38:23 -0500


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@hidden
Instant Interactive(tm)   http://www.instantinteractive.com



_______________________________________________

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


References: 
 >Custom button cells for NSMatrix (From: norio <email@hidden>)
 >Re: Custom button cells for NSMatrix (From: Ricky Sharp <email@hidden>)

  • Prev by Date: RE: Launchd timeout messages
  • Next by Date: Re: Launchd timeout messages
  • Previous by thread: Re: Custom button cells for NSMatrix
  • Next by thread: Re: Custom button cells for NSMatrix
  • Index(es):
    • Date
    • Thread