Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enumerate Controls and Find Overlapping Controls
!! Note: I have not tried to compile this code... so it might have bugs
qtFEQs QUEUE,TYPE
FEQ SIGNED
END
gtXYWH_Signed GROUP,TYPE
X SIGNED
Y SIGNED
W SIGNED
H SIGNED
END
MAP
EnumerateControls (*qtFEQs xOutQ, SIGNED xFEQ, SIGNED xLowFEQ=-MAX:FEQ, SIGNED xHiFEQ=MAX:FEQ)
GetPosition (*gtXYWH_Signed xOut, SIGNED xFEQ)
AreControlsOverlapping (SIGNED xFEQa, SIGNED xFEQb),BOOL
IsOverlapping (CONST *gtXYWH_Signed xA, CONST *gtXYWH_Signed xB),BOOL
_Min (? A, ? B),?
_Max (? A, ? B),?
OverlapAmount (REAL xLowA, REAL xHighA, REAL xLowB, SIGNED xHighB),REAL
FindControlsOverlappedBy (*qtFEQs xOutQ, SIGNED xFEQ, SIGNED xLowFEQ=-MAX:FEQ, SIGNED xHiFEQ=MAX:FEQ)
END
OMIT('***', MAX:FEQ > 0)
MAX:FEQ EQUATE(2147483647) !equivalent of CLEAR(Long,1) = 2^31 - 1 ! also appears in debuger.inc
!END-OMIT
EnumerateControls PROCEDURE(*qtFEQs xOutQ, SIGNED xFEQ, SIGNED xLowFEQ=-MAX:FEQ, SIGNED xHiFEQ=MAX:FEQ)
CurrFEQ SIGNED(0)
CODE
FREE(xOutQ)
LOOP
CurrFEQ = xWin{PROP:NextField, CurrFEQ}
IF ~CurrFEQ
BREAK
END
IF INRANGE( CurrFEQ, xLowFEQ, xHiFEQ)
xOutQ.FEQ = CurrFEQ
ADD(xOutQ)
END
END
!SORT(FEQs, FEQs.FEQ)
GetPosition PROCEDURE(*gtXYWH_Signed xOut, SIGNED xFEQ)
CODE
GETPOSITION(xFEQ, xOut.X, xOut.Y, xOut.W, xOut.H)
AreControlsOverlapping PROCEDURE(SIGNED xFEQa, SIGNED xFEQb)
CODE
IsOverlapping PROCEDURE(CONST *gtXYWH_Signed xA, CONST *gtXYWH_Signed xB)
CODE
RETURN CHOOSE( )
_Min PROCEDURE(? A, ? B)
CODE
IF A < B THEN RETURN A END
RETURN B
_Max PROCEDURE(? A, ? B)
CODE
IF A > B THEN RETURN A END
RETURN B
OverlapAmount PROCEDURE(REAL xLowA, REAL xHighA, REAL xLowB, SIGNED xHighB)
Answer REAL,AUTO
CODE
Answer = _Min(HighA, xHighB) - _Max(xLowA, xLowB)
RETURN _Max( Answer, 0)
FindControlsOverlappedBy PROCEDURE(*qtFEQs xOutQ, SIGNED xFEQ, SIGNED xLowFEQ=-MAX:FEQ, SIGNED xHiFEQ=MAX:FEQ)
QRec LONG,AUTO
CompareToXYWH LIKE(gtXYWH_Signed)
CurrXYWH LIKE(gtXYWH_Signed)
CODE
EnumerateControls(FEQsQ, xFEQ, xLowFEQ, xHiFEQ)
GetPosition(CompareToXYWH, xFEQ)
LOOP QRec = RECORD(FEQsQ) TO 1 BY -1
GET(FEQsQ, QRec)
GetPosition(CurrXYWH, FEQsQ.FEQ)
IF ~OverapAmount( CompareToXYWH.X, CompareToXYWH.X + CompareToXYWH.W, |
CurrXYWH.X, CurrXYWH.X + CurrXYWH.W ) |
OR ~OverapAmount( CompareToXYWH.Y, CompareToXYWH.Y + CompareToXYWH.H, |
CurrXYWH.Y, CurrXYWH.Y + CurrXYWH.H ) |
THEN
DELETE(FEQsQ)
END
END
! Example usage....
OverLappedControls QUEUE(qtFEQs)
WasDisabled BOOL
END
CODE
OPEN(Window)
....
FindControlsOverlappedBy(OverLappedControls, ?Browse1, 0) ! ignore negative FEQs (menus and toolbar)
DO DisableOverlappedControls
...
DO RestoreOverlappedControls
DisableOverlappedControls ROUTINE
DATA
QRec LONG,AUTO
CODE
LOOP QRec = 1 TO RECORDS(OverLappedControls)
GET(OverLappedControls, QRec)
OverLappedControls.WasDisabled = OverLappedControls.FEQ{PROP:Disabled}
PUT(OverLappedControls)
DISABLE(OverLappedControls.FEQ)
END
RestoreOverlappedControls ROUTINE
DATA
QRec LONG,AUTO
CODE
LOOP QRec = 1 TO RECORDS(OverLappedControls)
GET(OverLappedControls, QRec)
IF ~OverLappedControls.WasDisabled
ENABLE(OverLappedControls.FEQ)
END
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.