Toolbar on/off

Just discovered a cool trick :

Place a Toolbar on a ContainerControl. When you embed it in a document window, it gets the toolbar. When the CC is closed, the toolbar goes away :slight_smile:

about the toolbar… does anybody know if you can reduce the size of the toolbar
and also the icons inside, they are pretty big for me
is there a way to adjust the toolbar height ?
like on lots of apps where you can personalize the toolbar, you often have “text only”, “small icons” or “large icons”

The only way I can think of is to use a custom toolbar.

Here is what I use, derived from a method I believe used by Jim MvKay in a project of the Black Window thread :

[code]Sub NewTitleBar(mycontrol as Control)

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)
dim themeFrame As Ptr = superView(cv)
dim firstSubView As Ptr = objAtIdx(subViews(themeFrame), 0)
addSubView(themeFrame, mycontrol.Handle, 0, firstSubView)
End Sub[/code]

Place a canvas over the window bar and go

NewTitleBar(Canvas1)

Since a canvas can be used as container, you can put most anything on top of it. Or use its paint event.

Using a Canvas with the above code works great.
To get the different colors and divider, I guess the best thing to do is placing the Canvas on an (empty) regular Toolbar.

However, a Toolbar with nothing on it is just too small to add a Canvas with controls.
Adding a fake spacer/button to the Toolbar makes the Toolbar huge again. Ideally, it would be something in the middle.
Too bad that (although the documentation says so) the ToolBar.Height property doesn’t seem to do anything.

[quote=274260:@Marco Hof]Using a Canvas with the above code works great.
To get the different colors and divider, I guess the best thing to do is placing the Canvas on an (empty) regular Toolbar.

However, a Toolbar with nothing on it is just too small to add a Canvas with controls.
Adding a fake spacer/button to the Toolbar makes the Toolbar huge again. Ideally, it would be something in the middle.
Too bad that (although the documentation says so) the ToolBar.Height property doesn’t seem to do anything.[/quote]

You don’t have to make the canvas the size of the bar. It can be taller. Something in between the regular bar and the toolbar height, which is apparently what Jean-Yves is after. Of course this then means moving controls lower.

I don’t think that will work very nice. Apart from the handling of the dragging and gestures yourself, you’ll always see the Title Bar’s divider line coming through.

In the open event of a toolbar put:

Declare Sub setAllowsUserCustomization Lib "Cocoa" Selector "setAllowsUserCustomization:" (NSToolbar As Ptr, allowsUserCustomization As Boolean) Dim toolbarPtr As Ptr = toolbar(Ptr(Self.Handle)) setAllowsUserCustomization(toolbarPtr, True)

thanks, Eli.
is there any method for windows and linux ?
although it’s not a necessity, I would like to stay multi-platform on this.

@Michel Bujardet : Yes, but only if you do this with one Container Control (even if they have the same toolbar)

I discovered later that hiding the ToolBar that is on the window also makes it appear and disappear.

Also, today, I used the declare I posted to place a label on the toolbar to show the number of items in the print queue. It is really convenient to attach really any control.

[quote=274269:@Eli Ott]In the open event of a toolbar put:

Declare Sub setAllowsUserCustomization Lib "Cocoa" Selector "setAllowsUserCustomization:" (NSToolbar As Ptr, allowsUserCustomization As Boolean) Dim toolbarPtr As Ptr = toolbar(Ptr(Self.Handle)) setAllowsUserCustomization(toolbarPtr, True)[/quote]

I get this error: Type mismatch error. Expected class Toolbar, but got Ptr

I forgot a declare in my post:

Declare Function toolbar Lib "Cocoa" Selector "toolbar" (NSWindow As Ptr) As Ptr

Works great, thanks

Eli, here is what I have now, that does not create an error :

Sub Open() Declare Function toolbar Lib "Cocoa" Selector "toolbar" (NSWindow As Ptr) As Ptr Declare Sub setAllowsUserCustomization Lib "Cocoa" Selector "setAllowsUserCustomization:" (NSToolbar As Ptr, allowsUserCustomization As Boolean) Dim toolbarPtr As Ptr = toolbar(Ptr(Self.Handle)) setAllowsUserCustomization(toolbarPtr, True) End Sub

But… As it stands, it does not customize anything, right ? What are the missing pieces to do text only or small icons ?

Correct. It allows to show the popup menu when you right click with the mouse.

More declares:

Declare Sub setShowsBaselineSeparator Lib "Cocoa" Selector "setShowsBaselineSeparator:" (NSToolbar As Ptr, flag As Boolean) setShowsBaselineSeparator(toolbarPtr, false)

Declare Sub setDisplayMode Lib "Cocoa" Selector "setDisplayMode:" (NSToolbar As Ptr, NSToolbarDisplayMode As UInteger) Const ToolbarDisplayModeDefault = 0 Const ToolbarDisplayModeIconAndLabel = 1 Const ToolbarDisplayModeIconOnly = 2 Const ToolbarDisplayModeLabelOnly = 3 setDisplayMode(toolbarPtr, ToolbarDisplayModeIconOnly)

Declare Sub setSizeMode Lib "Cocoa" Selector "setSizeMode:" (NSToolbar As Ptr, NSToolbarSizeMode As UInteger) Const NSToolbarSizeModeDefault = 0 Const NSToolbarSizeModeRegular = 1 Const NSToolbarSizeModeSmall = 2 setSizeMode(toolbarPtr, NSToolbarSizeModeSmall)
Unfortunately I haven’t found a way to auto save the user settings without completely replacing the Xojo Toolbar with a true NSToolbar class instance.

Super, Eli. Thank you :slight_smile:

Still in my list of readings: NSToolbar .

[quote=274271:@Jean-Yves Pochez]is there any method for windows and linux ?
although it’s not a necessity, I would like to stay multi-platform on this.[/quote]

Any taker ?

Also:

from the Human Interface Guidelines Toolbars .