macoslib toolbar search field

Hi,
Does anyone know the steps necessary to add an NSSearchField to my already existing toolbar?
I have looked at the corresponding window in the macoslib examples folder, but cannot work out how to add a search field into my already existing toolbar.

Thank you.

I’m looking for that too … bumping the conversation !

I lifted this from an example project Jim McKay posted in the black window thread. If you place it in the Open event of the window, it will enable you to place regular controls over the toolbar :

[code] declare function contentView lib “Cocoa” selector “contentView” (id As integer) As Ptr
declare function superView lib “Cocoa” selector “superview” (id As Ptr) As Ptr
declare function subviews lib “Cocoa” selector “subviews” (id As Ptr) As Ptr
declare function objAtIdx lib “Cocoa” selector “objectAtIndex:” (id As Ptr, idx As UInt32) As Ptr
declare sub addSubView lib “Cocoa” selector “addSubview:positioned:relativeTo:” _
(id As Ptr, aView As integer, order As integer, rel As Ptr)

dim cv As Ptr = contentView(self.Handle)
cv.Integer = cv.integer
dim themeFrame As Ptr = superView(cv)
dim firstSubView As Ptr = objAtIdx(subViews(themeFrame), 0)
addSubView(themeFrame, CanvasBar.Handle, 0, firstSubView)[/code]

I have used that to create this example :

Note that the two first buttons are toolbar buttons, after which they all are regular controls.

Download Example

Hi Michel,
I would not recommend using this code for this purpose. This code inserts the control into the window frame, what you want is code that inserts the control into the toolbar. This way it’ll work on both Mavericks and Yosemite (with the different visual styles).

I included that code at part of the Yosemite article in the latest xDev magazine, it also comes with the retina kit.

Hi @Sam Rowlands,

I use your Code from the xDevMag Article where I can add different Controls in to a macOS Toolbar. I added a PushButton. After click on it, the Button should show a PopUp-Menu. I use this sample code, but it opens at the wrong coordinates, not at the coordinates, where the PushButton is placed into the Toolbar Me.setItemControl( 0, PushButton1 ). How to fix it?

[code]Dim base As New MenuItem

base.append(New MenuItem(“Import”))
base.append(New MenuItem(“Export”))
base.append(New MenuItem(MenuItem.TextSeparator))

base.append(New MenuItem(“Cut”))
base.append(New MenuItem(“Copy”))
base.append(New MenuItem(“Paste”))

Dim selectedMenu As MenuItem
selectedMenu = base.Popup(me.Left, PushButton1.Left, pushButton1.Top + PushButton1.Height) ’ PushButtons original Coordinates
[/code]

  1. Don’t use a PushButton when you want a drop down menu, see the latest xDev for code on how to make one.
  2. Most of the stuff I do, messes with the Xojo view hierarchy.
  3. You could grab the X and Y co-ordinates from the MouseDown event and subtract them from the system mouse location.
base.popup( system.mouseX - X, system.mouseY - Y )

Thanks Sam.

Have a look to Apple Pages. If you click the View Toolbutton, you see a Popupmenu. Is this the same you describe in the current xDevMag?

[quote=326963:@Martin Trippensee]Thanks Sam.

Have a look to Apple Pages. If you click the View Toolbutton, you see a Popupmenu. Is this the same you describe in the current xDevMag?[/quote]
Yup.

And how can I style the Popupmenu like a PushButton/SegmentedControl? And how to set a image to this?

The article explains how to use the Retina Kit to add images/icons to the popup menu.

As for the style; once you have the Retina Kit installed in your project you can call.

me.setBezelStyle NSBezelStyle.texturedRounded

In the open event of the PopupMenu.

Hi,

I built a small Sample-Project with Sam’s Code for xDevMag on macOS Sierra 10.12.4. I added a PopupMenu to the Toolbar (Zoom). If I open the App, there is a big distance between the PopupMenu und the ToolButtons Text. After resizing the Window to Fullscreen-Mode, the PopupMenu and Text placed well. How to fix it?

After App opened

After App resized to Fullscreen-Mode

Sample-Project

Without testing (but it will work). Change the height of popupmenu to 34 or more. That should take care of the alignment.
Not sure if this is a Xojo bug, but it fixes such issues.

[quote=327261:@Christoph De Vocht]Without testing (but it will work). Change the height of popupmenu to 34 or more. That should take care of the alignment.
Not sure if this is a Xojo bug, but it fixes such issues.[/quote]
Simple solution. It works fine! Thank you Christoph