• 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 focus ring ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: custom focus ring ?


  • Subject: Re: custom focus ring ?
  • From: Ricky Sharp <email@hidden>
  • Date: Tue, 11 Jan 2005 18:38:35 -0600

On Jan 11, 2005, at 4:20 PM, Bob Miller wrote:

Can anyone tell me if there is a way to draw a custom focus ring on an NSCell. Specifically a raised editor type border. I have a custom subclass of NSTextField that does automatic resizing to fit the text it contains. I want the text field to act like a field as far as the responder chain is concerned but behave like a resizable text view. When I try to draw outside the text field's bounds I see I am being clipped by an _NSKeyboardFocusClipview class. Which seems to control the clip area so that the current graphics context cannot draw outside of that area. Is there something I'm missing (other than a few cards ffroma full deck) Why is it so difficult to try and draw a border around a text field ? Any help is greay appreciated.

If you want to use the default focus ring, that will definitely work. See the following example for a custom control that uses the system focus ring style:


/Developer/Examples/AppKit/ClockControl/

To draw your own focus ring, the only thing I've done is to "cheat" a bit. The size of my custom controls always includs within its bounds the area to draw the focus ring. Then, in my drawInteriorWithFrame:inView: method, I draw the control, then draw the focus ring if showsFirstResponder returns YES.

What I haven't yet done is to draw a custom focus ring outside the bounds of the control. From reading your description above, it appears you want to go this route. The following may work:

In your cell, set up its focus ring type by calling setFocusRingType with a parameter of NSFocusRingTypeNone. There are only two other options, but both will give you the Aqua style.

Then, in response to becomeFirstResponder, resignFirstResponder, etc. in your custom control (view), call setKeyboardFocusRingNeedsDisplayInRect:. The docs say that the NSRect parameter is "expanded to include to focus ring for invalidation". It doesn't mention what to do when your focus ring type is "none". But I'd imagine that you'd need to set the NSRect to the appropriate size yourself. You should then get the right clipping to occur and can draw your focus ring.

See the ClockControl example for the methods to override that should call setKeyboardFocusRingNeedsDisplayInRect:.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >custom focus ring ? (From: Bob Miller <email@hidden>)

  • Prev by Date: NSTableView cornerView
  • Next by Date: Re: NSTableView cornerView
  • Previous by thread: custom focus ring ?
  • Next by thread: Saving, file types, and non-document-based apps
  • Index(es):
    • Date
    • Thread