textfield under NSStatusItem?

Hi,
Does anyone know if it is possible to have either a NSSearchField, or a simple textfield appear directly under a clicked NSStatusItem?

Basically, the same as spotlight does?
Any pointers will be greatly appreciated.

Thank you all in advance.

of course it’s possible.
Put a little window below and put the textfield inside.

I already thought of that Christian, but I will not know how far left or right my NSStatusItem appears in the user’s OS X menubar.
Therefore, I do not know what x and y coordinates to place my window containing the NSSearchField?

Is there any way of finding out where the NSStatusItem is in the menubar?

Thanks.

NSStatusItem.View.Bounds will return an NSRect of the bounds of the StatusItem.

Jason,
is it possible you could expand on that a little, as I can never understand Xcode or Apple’s documentation :frowning:

Do you mean that NSRect will tell me how many pixels from the top right edge of the screen my NSStatusItem is?
Or would NSRect automatically place my window at the correct coordinates, in order to prevent part of my window being off-screen, so to speak?

Thanks Jason.

Well, Apple does probably some clever things which we may not be able to do.
But it may be simply a window.

And yes, you can query the area of the NSStatusItem which gives coordinates on screen.
My plugin has Left, Top, Width and Height properties for that.

Sure Richard,
Actually what I has said before only works if you have set the view of the NSStatusItem. Since I don’t think you have done this, the following will return the bounds of the NSStatusItem:

[code] soft declare function frame lib CocoaLib Selector “frame” (obj_id as ptr) as Cocoa.NSRect
soft declare function valueForKey lib CocoaLib selector “valueForKey:” (obj_id as ptr, key as CFStringRef) as ptr

dim rect as Cocoa.NSRect = frame(valueForKey(NSSTATUSITEM,“window”))[/code]

Then if you set the left of the window to rect.x the left edge of the window will be aligned with the left edge of the NSStatusItem.

Hopefully this helps.

Hmm, can’t edit. Anyway you will just have to change NSSTATUSITEM to the name of the NSStatusItem variable.

So your code above works out where my NSStatusItem is in the OS X menubar, and then defines a rectangle as wide as my NSStatusItem’s icon.

And then I can say:

Window1.left = rect x

Which will position my window’s left edge to the NSStausItem’s left edge?

And the following code:

Window1.right = rect x

Which will position my window’s right edge to the NSStausItem’s right edge?

Left window edge at left edge of StatusItem:

window.left = rect.x
Right window edge as right edge of StatusItem:

window.left = rect.x+rect.w-window.width

Bit lost on that last statement?
What does rect.w-window.width refer to?

Or should that be:

Window1.left = (rect.x + rect.w) - Window1.width

It could be, addition and subtraction are associative however, so you don’t need any parentheses. Either way will work.

Thanks Jason.

I presume I just need to work out how many pixels high the menubar is, and then add 1 to it, in order to position the Window1.top co-ordinate?

The only part I don’t understand now is your quote below:

A bit lost on that part? :frowning:

In the code above to get the rect of the NSStatusItem, you need to replace NSSTATUSITEM with the name of the variable. I didn’t know what you called your variable so I put the class name in caps for you to replace with the variable name.

Ok,
I am new to this NSStatusItem stuff, so please excuse my ignorance.
I am presuming that judging from my code below (which creates the actual StatusItem), that I have to change NSSTATUSITEM to item1? :

// DISPLAY THE NSSTATUSITEM IN THE OS X MENUBAR dim bar as NSStatusBar = NSStatusBar.SystemStatusBar item1 = bar.CreateStatusItem(NSStatusBar.NSVariableStatusItemLength, AddressOf StatusItemHandler) item1.highlightMode = true item1.Image = NSStatusItemImage item1.AlternateImage = NSStatusItemImage

Correct

I can’t believe that this developing stuff is starting to make sense :slight_smile:

Thank you so much Jason - I really appreciate it when someone spends time to answer fully all of my sometimes stupid sounding questions!

I am just extremely inquisitive, am a perfectionist, and also have OCD - so I always ask a lot of questions so that I can sit back and fully study and learn from all of the info people such as yourself provide me with.

THANK YOU !

You’re welcome. Glad I could help.

Could you make a sample code to download :wink: ?

Me, or Jason??