Getting the view of a Window's controls?

I am currently stuck with a problem that’s probably only caused by some wrong thinking on my side.
But anyway: Hope you can help.
I am currently experimenting with the NSDrawer Class and can instantiate and open one. So far, so nice.

In order to make it easy to set up this class, I take a Xojo Window (could even be ContainerControl or anything else) and take its boundaries, create the Drawer independently and disregard the window. As a next step I want to take the controls placed on my template window and transfer them to the Drawer.
For this, I can iterate through the window.control array and get the handles of the placed objects.

But in order to transfer them, I have to get their views to call an addSubview method for each. And this is where I fail.
A control (or rectcontrol) extension doesn’t work – the base class doesn’t know this method:

Function view(extends c as rectcontrol) As ptr #if targetmacos declare function view lib CocoaLib Selector "view" (id as integer) as ptr return view (c.Handle) #endif End Function

Any hints on how I can make this work?
Thanks a lot!

Try this (untested) code:

declare sub setSubviews lib "Cocoa" selector "setSubviews:" (subviewArray as ptr) declare function subviews lib "Cocoa" selector "subviews" (parentView as ptr) as Ptr declare function contentView lib "Cocoa" selector "contentView" (windHandle as integer) declare function contentView lib "Cocoa" selector "contentView" (drawerRef as ptr) //nsdrawerref is the nsdrawer, self is the window setSubviews(contentView(nsdrawerref),subviews(contentView(self.Handle)))
It gets the NSArray of the subviews of the window’s content view and adds the views to the NSDrawer content view. I think it will work, but I haven’t tested it.

Anyway, that’s a great idea! Thanks a lot, will tell you if it worked very soon :wink:

handle is already the NSView pointer.

It is? Oh, that would make things quite easy. Thanks a lot, Christian!

Yes! How easy!
So for future reference, this is how it works:
declare sub addSubView lib CocoaLib selector "addSubview:" (id as ptr, view as ptr) for q as integer = 0 to self.ControlCount -1 addSubView ContentView, ptr(self.control(q).Handle) next