/*------------------------------------------------------------------------------
  test-11180-g-teardown-mouse.p                          (mouse/keyboard path)

  DRAFT probe for #11180 review finding 2 - the mouse/keyboard twin of
  test-11180-g-teardown-apply.p.  Same window-teardown-without-APPLY topology,
  but the focus transfer is driven by a physical CLICK rather than APPLY 'ENTRY',
  so it exercises FocusManager.handleFocusChange (the mouse/keyboard path) rather
  than ThinClient.processProgressEvent's SE_ENTRY branch.

  This probe is NOT head-less: the mouse path only runs under a real GUI driver
  (web or Swing), exactly like test-11180-e-mouse-dest-browse-leave.p.  Run it in
  the GUI, perform the single click described below, then compare the event log
  to a native-OpenEdge run.

  Steps to drive (GUI):
    1. Focus starts in fO (secondary window W2).
    2. CLICK fT in the default window's frame frmT.
    3. fO's frame LEAVE (fired by the click-driven focus change) DELETEs window
       W2 with NO APPLY - a bare-refocus fallback, not a nested steal.

  OPEN QUESTION (unmeasured by any existing probe): after the click, does
  OpenEdge honour the click into fT (fT : ENTRY, focus fT) or does it treat the
  window-teardown fallback as a steal (keep the fallback focus, drop the click)?

  Expected (native OpenEdge): <to be recorded from the OE run>
  FWD 11180b (post-review):   FocusManager.handleFocusChange returns true on the
                              teardown fallback -> the clicked fT gets neither
                              ENTRY nor focus (candidate finding 2).

  Log to test-11180-g-mouse.log; leave the window open for inspection (WAIT-FOR).
------------------------------------------------------------------------------*/

DEFINE VARIABLE seq AS INTEGER NO-UNDO.

DEFINE VARIABLE hWin2 AS HANDLE NO-UNDO.
DEFINE VARIABLE hFrmO AS HANDLE NO-UNDO.
DEFINE VARIABLE hFO   AS HANDLE NO-UNDO.

DEFINE VARIABLE fT AS CHARACTER NO-UNDO FORMAT "x(8)" INITIAL "ttt".

DEFINE FRAME frmT fT WITH TITLE "FRAME-T (click target, default window)"
   AT ROW 3 COLUMN 2 SIZE 44 BY 4.

PROCEDURE logit:
   DEFINE INPUT PARAMETER m AS CHARACTER NO-UNDO.
   seq = seq + 1.
   OUTPUT TO "test-11180-g-mouse.log" APPEND.
   PUT UNFORMATTED STRING(seq, "99") " " m SKIP.
   OUTPUT CLOSE.
END PROCEDURE.

/* fO's frame LEAVE (driven by the click): tear down window W2, NO APPLY */
PROCEDURE oLeave:
   RUN logit("frmO  LEAVE  (begin - delete secondary WINDOW W2, NO APPLY)").
   IF VALID-HANDLE(hWin2) THEN DELETE WIDGET hWin2.
   RUN logit("frmO  LEAVE  (end - no APPLY performed)").
END PROCEDURE.

ON ENTRY OF FRAME frmT
   RUN logit("frmT  ENTRY  <== target FRAME ENTRY (click honoured?)").
ON ENTRY OF fT IN FRAME frmT
   RUN logit("fT    ENTRY  <== clicked target ENTRY (dropped by candidate bug?)").
ON LEAVE OF fT IN FRAME frmT
   RUN logit("fT    LEAVE").

/* ---- main ---- */
OUTPUT TO "test-11180-g-mouse.log".
PUT UNFORMATTED "=== test-11180-g-teardown-mouse start ===" SKIP.
OUTPUT CLOSE.

ENABLE fT WITH FRAME frmT.
VIEW FRAME frmT.

CREATE WINDOW hWin2
   ASSIGN TITLE = "WINDOW-2 (torn down in its own LEAVE)"
          WIDTH = 40 HEIGHT = 6 VISIBLE = FALSE.
CREATE FRAME hFrmO
   ASSIGN TITLE = "FRAME-O (source, in window 2)"
          PARENT = hWin2
          ROW = 2 COLUMN = 2 WIDTH = 34 HEIGHT = 4
          BOX = TRUE VISIBLE = FALSE.
CREATE FILL-IN hFO
   ASSIGN FRAME = hFrmO
          NAME = "fO" FORMAT = "x(8)" SCREEN-VALUE = "ooo"
          X = 4 Y = 4 WIDTH = 20
          SENSITIVE = TRUE VISIBLE = TRUE.
ON "LEAVE":U OF hFrmO PERSISTENT RUN oLeave.

hWin2:VISIBLE  = TRUE.
hFrmO:VISIBLE = TRUE.

CURRENT-WINDOW = hWin2.

RUN logit("--- APPLY ENTRY to fO (park focus in secondary window W2) ---").
APPLY "ENTRY" TO hFO.
RUN logit("--- now CLICK fT in the default window (drives the mouse path) ---").
PAUSE 0.
/* Keep the session alive so the tester can click fT; the LEAVE fires from the
   click, not from an APPLY.  Close the window to end. */
WAIT-FOR CLOSE OF THIS-PROCEDURE.

RUN logit("--- done; FOCUS is now: "
          + (IF VALID-HANDLE(FOCUS) THEN STRING(FOCUS:TYPE) + "/" + FOCUS:NAME
             ELSE "<none/invalid>") + " ---").
RUN logit("--- OPEN QUESTION: OE = is the click honoured (fT ENTRY) or dropped? ---").
