I have a NSToolbarItem
that uses a view similar to the Xcode status view. It currently has no label, but I can't figure out a way to draw into the area where the item label would normally be drawn. I would like the view to extend into that area just as the Xcode status view does. I know the very bottom portion of pixels of NSToolbar
is out of bounds, but I have seen other applications draw into the label area. Any ideas?
Edit: For clarification, this is the status view I'm referring to in Xcode:
I want the bounds of my view to extend past the label area of the toolbar just as the view in Xcode does.
The Xcode status view is not an NSToolbarItem
is a custom NSView
inserted in the NSToolbar
.
If you log
NSLog(@" %@", [[self.window.contentView superview] subviews]);
You will get
NSToolbarView doesn't autoresize it's subviews so you have issues with centering it.
And [self.window.contentView superview]
doesn't contain the toolbarview when full screen.
You can add the view you want in the center of the toolbar to the [self.window.contentView superview]
when not in fullscreen and position it properly. It will autoresize and stay centered.
When switching to full screen remove it from [self.window.contentView superview]
and add it to NSToolbarView in the center that way it stays in the toolbar and it also moves down with the toolbar when you reveal the status bar.
You can get the toolbar view by iterating thru the subviews or with a private method
[[self.window toolbar] performSelector:@selector(_toolbarView)];
Update: I did a little more digging with the debugger and I found out that this is what Xcode does. At least while not in full screen.
thealch3m1st$ sudo lldb
(lldb) process attach -p 11478
Process 11478 stopped
Executable module set to "/Applications/Xcode.app/Contents/MacOS/Xcode".
Architecture set to: x86_64.
(lldb) po [NSApplication sharedApplication]
(id) $0 = 0x000000040013f5e0 <IDEApplication: 0x40013f5e0>
(lldb) po [$0 mainWindow]
(id) $1 = 0x0000000000000000 <nil>
(lldb) po [$0 windows]
(id) $2 = 0x0000000408278460 <__NSArrayM 0x408278460>(
<IDEWelcomeWindow: 0x40141c1e0>,
<IDEWorkspaceWindow: 0x401ef2780>,
<NSComboBoxWindow: 0x402019be0>,
<NSWindow: 0x4022adc60>,
<IDEOrganizerWindow: 0x402951b20>
)
(lldb) po [$0 windows]
(id) $3 = 0x0000000408820300 <__NSArrayM 0x408820300>(
<IDEWelcomeWindow: 0x40141c1e0>,
<IDEWorkspaceWindow: 0x401ef2780>,
<NSComboBoxWindow: 0x402019be0>,
<NSWindow: 0x4022adc60>,
<IDEOrganizerWindow: 0x402951b20>
)
(lldb) [$3 objectAtIndex:1]
error: '[$3' is not a valid command.
(lldb) po [$3 objectAtIndex:1]
(id) $4 = 0x0000000401ef2780 <IDEWorkspaceWindow: 0x401ef2780>
(lldb) po [$4 contentView]
(id) $5 = 0x0000000401ef0920 <NSView: 0x401ef0920>
(lldb) po [$5 superview]
(id) $6 = 0x0000000401ef2e20 <NSThemeFrame: 0x401ef2e20>
(lldb) po [$6 subviews]
(id) $7 = 0x0000000401ef3800 <__NSArrayM 0x401ef3800>(
<_NSThemeCloseWidget: 0x401ef3120>,
<_NSThemeWidget: 0x401ef3b80>,
<_NSThemeWidget: 0x401ef40e0>,
<NSView: 0x401ef0920>,
<IDEActivityView: 0x4020cd700>,
<_NSThemeFullScreenButton: 0x402017b20>,
(<NSToolbarView: 0x4020192e0>: Xcode.IDEKit.ToolbarDefinition.Workspace),
<DVTDualProxyWindowTitleView: 0x40225e0a0>,
<NSThemeDocumentButton: 0x402698020>
)
(lldb) po [$7 objectAtIndex:4]
(id) $8 = 0x00000004020cd700 <IDEActivityView: 0x4020cd700>
(lldb) [$8 setHidden:YES]
error: '[$8' is not a valid command.
(lldb) po [$8 setHidden:YES]
(id) $9 = 0x0000000000000000 <nil>
(lldb) continue
Process 11478 resuming
(lldb)
And the activity view is gone :)
While in full screen however. It doesn't add it to NSToolbarView it adds it to NSNextStepFrame which is NSToolbarView's superview. The toolbar is not contained in the window's contentview superview when in full screen. I think it has something to do with full screen behavior and spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With