Z-Order (again)

Hi folks,
I have an application, where the user can add multiple panels to the interface, these are ContainControls. They can be moved around and resized, but I have a problem and that when they overlap. Ideally I’d like it so that when the user clicks on one of these panels, it’s bought forwards to the top of the stack (or changing the z-Order).

If there an official Xojo way to do this?

Right now for the Mac, I’m using these declares (which I’m sure I’m going to get told off for), they work, however it requires the user click twice, once to bring it forwards and then a second time if they want to interact with the panel.

Dim superView as integer = NSViewSuperview( value.handle ) NSViewRemoveFromSuperViewWithoutNeedingDisplay( value.handle ) NSViewAddSubview( superView, value.handle )

With this project, I’d also like to port it to Windows (I look forward to using this application with a touch screen), which is also why I’m hoping for a Xojo official method.

Happy New Year.

Edit: I forgot to mention that I’ve already looked through the forum and saw that the following code from @Joost Rongen is supposed to work on Windows, but it doesn’t appear to do anything on the Mac.

self.trueWindow.focus = me.focus me.refresh

To move a control to the front of the zorder in windows do the following (for example inside MouseDown on the control you want to move):

Call SetWindowPos(Me.Handle, 0, 0, 0, 0, 0, 3) ' 2 + 1 for ignore position and size changes Me.Refresh(False)

Public Function SetWindowPos(hWnd As Integer, hWndInsertAfter As Integer, X as Int32, Y as Int32, cx As Int32, cy As Int32, uFlags As UInt32) as Integer 'https://blog./2017/01/22/windows-to-xojo-data-type-conversion/ 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx Declare Function SetWindowPos Lib "User32.dll" (hWnd As Integer, hWndInsertAfter As Integer, X as Int32, Y as Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Integer Return SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags) End Function

Just off the top of my head, have you tried setting the parent of the container to Nil and then re-embedding it?

Thanks for this, I look forward to testing it on Windows.

Thanks Greg; While that seemed like it should work, it goes horribly wrong on the Mac (at least in my app), I end up with it showing in two places, only one is movable and that one has no content, it also throws it down miles away from where it was. :frowning:

I’ve taken another look at the Apple docs, hoping there’s a simple property, I found one with CALayers… I might have to investigate some more.

@Sam Rowlands : Please keep us informed! I’m highly interested in your findings!

I was considering using a Canvas, but as the panels can be quite complex, I felt it was a better idea to use native controls where possible. Apart from this z-order issue, things are working quite well (so far).

In the end, I reversed how I went about it. Instead of ‘moving’ the container control I want forwards (which requires an additional click), I move all the others backwards. This works beautifully IMHO.

So my container controls are ‘groups’.

[code]Public Sub moveAllGroupsBehind(selectedGroup as projectGroup)
For each cGroup as projectGroup in groups
if cGroup = selectedGroup then continue

NSViewRemoveFromSuperViewWithoutNeedingDisplay( cGroup.handle )

Next

Dim superView as integer = NSViewSuperview( selectedGroup.handle )

For each cGroup as projectGroup in groups
NSViewAddSubviewPositionedRelativeTo( superView, cGroup.handle, -1, selectedGroup.handle )
Next
End Sub
[/code]