• 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: The fieldEditor and a focus ring
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The fieldEditor and a focus ring


  • Subject: Re: The fieldEditor and a focus ring
  • From: Eric Gorr <email@hidden>
  • Date: Mon, 2 Mar 2009 10:30:29 -0500


On Feb 27, 2009, at 6:29 PM, Graham Cox wrote:


On 28/02/2009, at 7:07 AM, Eric Gorr wrote:

If I check the value of focusRingType for the fieldEditor which is currently handling the text input, I get a value back of NSFocusRingTypeDefault. But, even if I set the value to NSFocusRingTypeExterior, no focus ring is drawn.

Is this focus ring something I need to draw myself or is there some way to get the fieldEditor to draw it?


I could be wrong (check the documentation), but my understanding is that the field editor isn't responsible for this.

The documentation for the field editor doesn't mention the focus ring.

However, I suspect you are correctly, that the field editor isn't responsible for this - especially since it doesn't draw one.


If you are using the field editor with something other than a standard NSTextField, you are going to have to draw the focus ring yourself but based on the actual view or part of the view that is visible, not the field editor.


I tried following the comments found here:

http://www.cocoadev.com/index.pl?DrawingAFocusRingAlongAnArbitraryPath

So, this is what I have tried to which should be drawing the focus ring but doesn't:

[self lockFocus];
[NSGraphicsContext saveGraphicsState];
NSRect focusRingBounds = [self bounds];
NSSetFocusRingStyle( NSFocusRingOnly );
NSBezierPath *path = [NSBezierPath bezierPathWithRect:focusRingBounds];
[path setClip];
[path fill];
[NSGraphicsContext restoreGraphicsState];
[self unlockFocus];



I have checked [self lockFocusIfCanDraw] as well and this returns true.



Here is what the code is surrounded by:
(Taken from the /Developer/Examples/Accessibility/AXCanvas sample code)

// Create a field editor.
fieldEditor = (NSTextView *)[[self window] fieldEditor:YES forObject:self];
[fieldEditor setDelegate:self];
[fieldEditor setFrame:[self bounds]];
[fieldEditor setMinSize:[self bounds].size];
[fieldEditor setMaxSize:[self bounds].size];
[[fieldEditor textContainer] setContainerSize:NSMakeSize( NSWidth( [self bounds] ), CGFLOAT_MAX ) ];


[fieldEditor setSelectedRange:NSMakeRange(0, [[(ResourceItemData*) [controller representedObject] textContent] length])];
[fieldEditor setTextContainerInset:NSZeroSize];


[[fieldEditor textStorage] setAttributedString:[(ResourceItemData*) [controller representedObject] storage]];
[fieldEditor setRichText:NO];
[fieldEditor setAllowsDocumentBackgroundColorChange:NO];
[fieldEditor setBackgroundColor:[NSColor whiteColor]];
[fieldEditor setTypingAttributes:[(ResourceItemData*)[controller representedObject] textAttributes]];


[[fieldEditor textContainer] setWidthTracksTextView:NO];
[[fieldEditor textContainer] setHeightTracksTextView:NO];
[fieldEditor setHorizontallyResizable:NO];
[fieldEditor setVerticallyResizable:YES];

NSLayoutManager *layoutManager = [ResourceItemLabel sharedLayoutManager];
NSTextContainer *container = [[layoutManager textContainers] objectAtIndex:0];


[container setContainerSize:NSMakeSize( [self bounds].size.width, CGFLOAT_MAX )];

NSTextStorage *storage = [[controller representedObject] storage];
[storage addLayoutManager:layoutManager];

NSPoint location = [self convertPoint:[anEvent locationInWindow] fromView:nil];
CGFloat partialDistance;
NSUInteger glyphIndex;


glyphIndex = [layoutManager glyphIndexForPoint:location
                               inTextContainer:container
                fractionOfDistanceThroughGlyph:&partialDistance];

if ( partialDistance > .5 )
    glyphIndex++;

NSRange indicatorPosition = NSMakeRange( glyphIndex, 0 );
[fieldEditor setSelectedRange:indicatorPosition];
[storage removeLayoutManager:layoutManager];

[self lockFocus];
[NSGraphicsContext saveGraphicsState];
NSRect focusRingBounds = [self bounds];
NSSetFocusRingStyle( NSFocusRingOnly );
NSBezierPath *path = [NSBezierPath bezierPathWithRect:focusRingBounds];
[path setClip];
[path fill];
[NSGraphicsContext restoreGraphicsState];
[self unlockFocus];

// Activate the field editor.
[self addSubview:fieldEditor];
[[self window] makeFirstResponder:fieldEditor];
NSLog( @"ResourceItemLabel: START EDITING" );


_______________________________________________

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


  • Follow-Ups:
    • Re: The fieldEditor and a focus ring
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Terminating a thread...
  • Next by Date: Re: Animate the way a HUD panel appears.
  • Previous by thread: Re: Terminating a thread...
  • Next by thread: Re: The fieldEditor and a focus ring
  • Index(es):
    • Date
    • Thread