moligaloo
moligaloo

Reputation: 1101

How to prevent focus window when its view is clicked by mouse on OSX?

I am writing a Cocoa app and do not want it focus on mouse click it, but I found no way to implement yet. Any one can give me suggestions ?

Upvotes: 2

Views: 1575

Answers (3)

moligaloo
moligaloo

Reputation: 1101

I've finally found a solution!

Create a subclass of NSView, and reimplement the following methods:

-(BOOL) shouldDelayWindowOrderingForEvent:(NSEvent *)theEvent
{
    return YES;
}

-(void) mouseDown:(NSEvent *)theEvent
{
    [NSApp preventWindowOrdering];
}

and set the contentView property of the created NSWindow, and set the window style mask to NSBorderlessWindowMask , and it works.

Upvotes: 5

kilik52
kilik52

Reputation: 664

Select the Table View in Interface Builder. There is a "Focus Ring" Attribute, change it to "None". I set all these attributes in Scroll View, Clip View, and Table View.

Hope it help.

Upvotes: 0

vasylz
vasylz

Reputation: 177

There is method(s) you may override in your subclass with returning NO

-(BOOL)acceptsFirstResponder
-(BOOL)becomeFirstResponder

Upvotes: 1

Related Questions