views:

305

answers:

2

Hey All,

I'm completely stumped with this problem. I made a custom search control that uses a few different classes. For some reason, when an NSTextField is anywhere over these different pieces, it displays a solid black border around it, and the cursor doesn't blink.

If anyone has a couple minutes - I've put together my code on pastebin.

Here's a picture of the search control, and what it looks like in this particular case: http://imgur.com/6y8qx.png

The search control is sitting on top of a gradient view:
http://pastebin.com/m43fde2b6

The search control is pieced together with this code:
http://pastebin.com/m5be08c32

The actual graphical part of the search control is built from two classes:
http://pastebin.com/m5bfa9439
http://pastebin.com/m5e909a2f (extends above class)

I cannot find what the heck is wrong. The text works, but there's a black border, and the cursor doesn't blink. What am I doing wrong?

Arg, I've been pulling my hair out for days on this one.

+1  A: 

Putting one view over a sibling view has never been well-supported in Mac OS X. Try making it a subview instead. You may even want to make it a private component of a dedicated search-field view.

On that note, is there a reason you're not using NSSearchField?

Peter Hosey
I'm not using NSSearchControl because I have custom graphics.The NSSSearchControl does the same thing with the black border and not updating the cursor.Making the search field a subview doesn't do it either.
bl4th3rsk1t3
A: 

I got it figured out! Finally.

What I didn't realize was the the "drawRect:" method's parameter "dirtyRect", is the portion of the control that is "dirty", meaning it needs to be redrawn.

So, when an NSTextField is on top of a control, it will trigger that control's "drawRect:" to be called (3) different times - with different "dirtyRect" parameters.

1: the cursor - usually an NSMakeRect(textField.origin.x,textfield.origin.y,1,textfield.origin.height). 2: the text field frame 3: the size of the control the text field is sitting on.

So, the fix was simple, change my control's scale 9 drawing to always draw to [self frame]. You can see the change here: http://pastebin.com/m50a5b0ad (line 89).

Previously, it was drawing to the "rect" parameter (http://pastebin.com/m5e909a2f - line 88), but depending on where the drawRect call was coming from, the rect parameter was different sizes.

bl4th3rsk1t3