Mac NSSearchField confusion

ranguvar

macrumors 6502
Original poster
Sep 18, 2009
318
1
Hi,

I'm drawing inside a custom NSSearchFieldCell subclass, but while the NSSearchField that the cell is in is active, the text gets drawn twice (once by my subclass and once somehow by the NSSearchField, I suppose).
As soon as I unselect the NSSearchField, e.g. by clicking inside a table view, the text gets drawn correctly (only once, by the cell).

A simple fix for this would of course be to let the cell only draw the text when the search field is inactive.
I tried to implement this, but I got stuck:

Is there nothing such as a - (BOOL)isSelected method for text fields or their cells?!

There must surely be some way to check if a text field is selected by the user!
Or do I miss a key concept of Cocoa?

Thanks for any input, I'm totally lost.

-ranguvar
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
5
Sounds like something in your drawing code isn't being done right. Maybe post some of it?

The selected control is the firstResponder, so you can check for this via:
Code:
if ([[control window] firstResponder] == control)
    ...
 

ranguvar

macrumors 6502
Original poster
Sep 18, 2009
318
1
Sounds like something in your drawing code isn't being done right. Maybe post some of it?

The selected control is the firstResponder, so you can check for this via:
Code:
if ([[control window] firstResponder] == control)
    ...
I had tried that, it didn't work though (dunno why). In the end, I used this method.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.