NSThemeFrame/custom theme

Hey guys,

I have followed a thread in the OSX section how to add controls to the NSThemeFrame
or even to customize the window title. Unfortunately I have little issue that I need to solve too. :slight_smile:

As the screen dump shows, I have a small area of 5 pixel where the I cannot drag the window but I like to do that over the full custom frame height.

(subclassed Canvas)

[code]Sub Open()
declare function frame lib CocoaLib selector “frame” (id As ptr) as NSRect
declare function contentView lib CocoaLib selector “contentView” (id As integer) as ptr
declare function superView lib CocoaLib selector “superview” (id As Ptr) As Ptr
declare function subviews lib CocoaLib selector “subviews” (id As Ptr) As Ptr
declare function firstObject lib CocoaLib selector “firstObject” (id As Ptr) as ptr
declare sub addSubView lib CocoaLib selector “addSubview:positioned:relativeTo:” _
(id As Ptr, aView As integer, order As integer, rel As Ptr)

// get the NSThemeFrame
dim cv as ptr = contentView(me.TrueWindow.Handle)
dim themeView As Ptr = superView(cv)
dim firstSubView As Ptr = firstObject(subViews(themeView))
// add our view
addSubView(themeView, me.Handle, 0, firstSubView)

// adjust our view correctly we’ve placed in the IDE somewhere
dim barHeight as integer=frame(themeView).h-frame(cv).h
me.Left=0
me.Top=0-barHeight
me.Width=TrueWindow.Width
//
me.LockLeft=true
me.LockRight=true
End Sub[/code]

You shouldn’t do this for OS X 10.10 Yosemite or newer. It was never an ‘approved’ method, but with Yosemite, Apple have added some API which will enable you to do this.

I wrote the declares in issue 12.5 of xDev Magazine.

me.wantsLayer = true me.titleVisibility = NSWindowTitle.hidden me.titleBarAppearsTransparent = true me.styleMask = me.styleMask + NSFullSizeContentViewWindowMask

You can also find them as part of the Retina Kit http://www.ohanaware.com/retinakit/

[quote=265523:@Sam Rowlands]You shouldn’t do this for OS X 10.10 Yosemite or newer. It was never an ‘approved’ method, but with Yosemite, Apple have added some API which will enable you to do this.

I wrote the declares in issue 12.5 of xDev Magazine.

me.wantsLayer = true me.titleVisibility = NSWindowTitle.hidden me.titleBarAppearsTransparent = true me.styleMask = me.styleMask + NSFullSizeContentViewWindowMask

You can also find them as part of the Retina Kit http://www.ohanaware.com/retinakit/
[/quote]

Well, I remember having seen other approaches but couldn’t recall. Thanks for the hint to the xdev. Gosh, I own it already. :slight_smile:

Yeah, we all got into using the NSThemeFrame in 10.8/10.9 to make interfaces, then Apple change it. I do recall hearing that modifying the NSThemeFrame wasn’t entirely stable.

The great thing about the new declares is that you simply layout the window, then with the functions in place, it simply moves it up by the titlebar height. Or if you can, use a toolbar.

The downside is that it doesn’t work on 10.9 and lower, so you may want to think about how you’ll handle legacy OS versions. With 10.12 or whatever it’s going to be approaching we’ve decided to not support 10.9 in our new apps.

just to point that out : setting the mask to NSFullSizeContentViewWindowMask will enabled the window to be layer-backed which
means some drawbacks for labels ect (not crisp anymore).

I can see you’ve subclassed the xojo label (NSLabel) for that reason is this true ?

Correct, I originally did it so get a label with vibrancy, so imagine my surprise when it displays better than a Xojo label on a Layer-Backed Window.

I couldn’t find a note in the documentation but this seems like bug ? I was kind of surprised.