Window.Locations (what for?)

Mojave/2019 r3.1

Window.Locations are enumerations that allow you to specify the Window.DefaultLocation property of a window. I was trying to set up a situation where I was alternating between two equal-sized Document windows. The smoothest transition visually was to open the next window first and then immediately close the prior window which was now behind what was just opened.

However, the newly opened window opened a little offset from the one that immediately proceeded it. So as you go back and forth, the visible window marches down and to the right across the screen.

To stop this, I assigned the two (in my case actually many more than that) windows the Window.Locations.ParentWindow value.

The documentation: [quote]Over the parent window if it opens another window.[/quote]

As far as I can see, this had no effect whatever. The newly opened window just opened a little down and to the right from the previous window.

Eventually, I could solve the problem by storing the Left and Top values of the current window and applying it to the window coming into existence.

But now I am curious. Just what is assigning the Window.DefaultLocation the ParentWindow value supposed to actually do? The documentation that I could find seemed pretty sparse.

i use ParentWindow for dialogs that they appear inside/over the main window.
i not tested this behavior on mac.
at ms windows the windows of same size looks stacked vertical.
smaller windows appear inside at top.
i would expect centered but it is not.

this opens the new window with same size (if both have a menu)

[code]Var w As New Window2

If 1=1 Then
w.Left = Self.Left
w.Top = Self.Top
w.Width = Self.Width
w.Height = Self.Height
End If



What I consider “correct” for macOS is to set every window to “Parent Window Screen”

This will make the window appear on the currently active screen as macOS sees it. Unfortunately, I haven’t found a way to get a Xojo app to respect the active screen at launch.

I see your concerns about the offset, but it’s supposed to happen. You’ll see this with ShowModal, which is why it’s offset, so that the user can see the piling up notifications. A regular Document window with Show will show in exactly the same position each time (try cmd-N in ExeWrapper).

You can use a NSScreen object for that (either using declares or with the MBS plugin).

Knowing your window always default to screen(0), keep the window hidden while it gets inited and use the NSScreen’s MainScreen function to get the screen the user is working on (the one having the front/focused window). Just do some maths to move your window from one screen to another (e.g. centred, relative, proportional, etc.). Finally, show the window.