Focus Ring in field editor for NSTextFieldCell in an NSTableView

273 Views Asked by At

I have a cell-based NSTableView with a text cell in a particular column. I want to provide a custom field editor so that I can do auto completion without the user pressing F5.

@implementation AutoCompleteFieldEditorTextView

-(id)init
{
    self = [super init];
    if (self)
    {
        self.focusRingType = NSFocusRingTypeDefault;
        self.fieldEditor = YES;
    }
    return self;
}

@end

This works ok except the focus ring does not exist. Even if I add:

-(void)drawFocusRingMask
{
    NSRectFill([self bounds]);
}

-(NSRect)focusRingMaskBounds
{
    return [self bounds];
}

it still does not work. How can I get the exact focus ring that appears with the default NSTextView used as a field editor in an NSTableView?

1

There are 1 best solutions below

0
vtukhtarov On

Have same problem and for solving I'm using next approach. This method overloaded in custom NSTextFieldCell which creates and return your custom NSTextView:

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
      [super drawInteriorWithFrame:cellFrame inView:controlView];

      if([controlView.window firstResponder] == self.maskTextField)
      {
         [super drawFocusRingMaskWithFrame:cellFrame
                                    inView:controlView];
      }
}

Hope this help someone in future.