Relayering a Grouped Control to the Top of Its Group
Mac OS 9 Mac OS X Windows Linux

Here's a handler that brings a control as close to the front as possible without affecting its owner.

No control has its owner changed. All controls other than the one that moves keep their original sequence within their owners. No controls are copied or deleted, so no system messages like newGroup and deleteGroup get sent. There's no "start editing" command, so stepping through the handler doesn't cause unexpected results (see the dictionary entry for "start editing"). The previous value of the relayerGroupedControls is restored at the end.

The optional input parameter identifies the control to bring to the front. With no input the handler operates on the target.

on bringToFrontWithinOwner pControl
  if pControl is empty then
    put abbr id of the target into tTarget
    put abbr id of pControl into tTarget
  end if
  put long owner of tTarget into tOwner
  if word 1 of tOwner is "card" then
    put 1 into tLayer
    put the layer of tOwner + 1 into tLayer
  end if
  repeat with i = number of controls down to 1
    if long owner of control i is tOwner then
      if abbr id of control i is not tTarget then
        put abbr id of control i & cr after tPeers
        -- note: peers share the same owner
      end if
    end if
  end repeat
  lock screen
  put the relayerGroupedControls into tRelayerGroupedControls
  set the relayerGroupedControls to "true"
  repeat for each line tPeer in tPeers
    set the layer of tPeer to tLayer
  end repeat
  set the relayerGroupedControls to tRelayerGroupedControls
  unlock screen
end bringToFrontWithinOwner
The handler passed my tests. If you find a problem with it, please let me know.

-- Dick

Posted 2/3/2006 by Dick Kriesel to the Use-Revolution List