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.
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]
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.
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?
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?
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