Wednesday, October 04, 2006

Managing Z-Order of windows on OSX with groups

I was recently working on an application in OSX that required me to use multiple WebViews in an overlay configuration. This problem ended up being more difficult than I first anticipated because of the way OSX manages windows. After unsuccessfully trying to order multiple views in the same window, I decided to approach the problem using window groups. After searching the web for a while, I hit upon the following combination of commands that allows you to group multiple windows together and have them retain their Z-order


WindowGroupRef parentWindowGroup = GetWindowGroup (hostWindowRef);
CreateWindowGroup (kWindowGroupAttrSelectAsLayer | kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse, &windowGroup);
SetWindowGroupParent (windowGroup, parentWindowGroup);
SetWindowGroup (hostWindowRef, windowGroup);
SetWindowGroup (childWindow1Ref, windowGroup);
SetWindowGroup (childWindow2Ref, windowGroup);

It is important is that you create your childWindows with the following attributes:
kWindowNoActivatesAttribute | kWindowDoesNotCycleAttribute
and that you set the ActivationScope :
SetWindowActivationScope (childWindowRef, kWindowActivationScopeAll);
Also using the kOverlayWindowClass for the "child" windows seems to help.

The full text of this post can be found at:
http://www.kvraudio.com/forum/viewtopic.php?p=1057433