Files
MBS/TEST/MultipleDialogs/ThreeLists.4gl
T

157 lines
4.7 KiB
Plaintext

# Property of Four Js*
# (c) Copyright Four Js 1995, 2019. All Rights Reserved.
# * Trademark of Four Js Development Tools Europe Ltd
# in the United States and elsewhere
#
# Four Js and its suppliers do not warrant or guarantee that these
# samples are accurate and suitable for your purposes. Their inclusion is
# purely for information purposes only.
DEFINE arr1 DYNAMIC ARRAY OF RECORD name STRING END RECORD
DEFINE arr2 DYNAMIC ARRAY OF RECORD name STRING END RECORD
DEFINE arr3 DYNAMIC ARRAY OF RECORD name STRING END RECORD
DEFINE att1 DYNAMIC ARRAY OF RECORD color STRING END RECORD
DEFINE att2 DYNAMIC ARRAY OF RECORD color STRING END RECORD
DEFINE att3 DYNAMIC ARRAY OF RECORD color STRING END RECORD
MAIN
OPTIONS INPUT WRAP
OPEN FORM f1 FROM "ThreeLists"
DISPLAY FORM f1
CALL fillarr(arr1, att1, "First List ", 5, "blue reverse")
CALL fillarr(arr2, att2, "Second List ", 7, "red reverse")
CALL fillarr(arr3, att3, "Third List ", 4, "green reverse")
DIALOG ATTRIBUTES(FIELD ORDER FORM, UNBUFFERED)
DISPLAY ARRAY arr1 TO sr1.*
BEFORE ROW
CALL setup(DIALOG)
END DISPLAY
DISPLAY ARRAY arr2 TO sr2.*
BEFORE ROW
CALL setup(DIALOG)
END DISPLAY
DISPLAY ARRAY arr3 TO sr3.*
BEFORE ROW
CALL setup(DIALOG)
END DISPLAY
BEFORE DIALOG
CALL DIALOG.setArrayAttributes("sr1", att1)
CALL DIALOG.setArrayAttributes("sr2", att2)
CALL DIALOG.setArrayAttributes("sr3", att3)
ON ACTION move_1_to_2 CALL move_row(DIALOG, "sr1", "sr2", arr1, arr2, att1, att2)
ON ACTION move_2_to_1 CALL move_row(DIALOG, "sr2", "sr1", arr2, arr1, att2, att1)
ON ACTION move_1_to_3 CALL move_row(DIALOG, "sr1", "sr3", arr1, arr3, att1, att3)
ON ACTION move_2_to_3 CALL move_row(DIALOG, "sr2", "sr3", arr2, arr3, att2, att3)
ON ACTION move_3_to_12 CALL move_3_to_12(DIALOG)
ON ACTION clear_current
CALL clear_current(DIALOG)
ON ACTION quit ATTRIBUTES(TEXT="Quit")
EXIT DIALOG
ON ACTION CLOSE
EXIT DIALOG
END DIALOG
END MAIN
FUNCTION setup(d)
DEFINE d ui.Dialog
-- can't user ui.Dialog.getArrayLength() because it's not synchronized for now.
CALL d.setActionActive("move_1_to_2", arr1.getLength()>0)
CALL d.setActionActive("move_2_to_1", arr2.getLength()>0)
CALL d.setActionActive("move_1_to_3", arr1.getLength()>0)
CALL d.setActionActive("move_2_to_3", arr2.getLength()>0)
CALL d.setActionActive("move_3_to_12", arr3.getLength()>0)
END FUNCTION
FUNCTION clear_current(d)
DEFINE d ui.Dialog
CALL d.deleteAllRows( d.getCurrentItem() )
CALL setup(d)
END FUNCTION
FUNCTION move_row(d, sa, sb, arra, arrb, atta, attb)
DEFINE d ui.Dialog
DEFINE sa, sb STRING
DEFINE arra DYNAMIC ARRAY OF RECORD name STRING END RECORD
DEFINE arrb DYNAMIC ARRAY OF RECORD name STRING END RECORD
DEFINE atta DYNAMIC ARRAY OF RECORD color STRING END RECORD
DEFINE attb DYNAMIC ARRAY OF RECORD color STRING END RECORD
DEFINE ra, rb INTEGER
LET ra = d.getCurrentRow(sa)
IF ra == 0 THEN RETURN END IF
LET rb = d.getCurrentRow(sb)
IF rb == 0 THEN
CALL d.appendRow(sb)
LET rb = 1
ELSE
CALL d.insertRow(sb, rb)
END IF
CALL d.setCurrentRow(sb, rb)
LET arrb[rb].name = arra[ra].name
LET attb[rb].color = atta[ra].color
CALL d.deleteRow(sa, ra)
CALL setup(d)
END FUNCTION
FUNCTION move_3_to_12(d)
DEFINE d ui.Dialog
DEFINE r1, r2, r3 INTEGER
LET r3 = d.getCurrentRow("sr3")
IF r3 == 0 THEN RETURN END IF
LET r1 = d.getCurrentRow("sr1")
LET r2 = d.getCurrentRow("sr2")
IF r1 == 0 THEN
CALL d.appendRow("sr1")
LET r1 = 1
ELSE
CALL d.insertRow("sr1", r1)
END IF
LET arr1[r1].name = arr3[r3].name
LET att1[r1].color = att3[r3].color
CALL d.setCurrentRow("sr1", r1)
IF r2 == 0 THEN
CALL d.appendRow("sr2")
LET r2 = 1
ELSE
CALL d.insertRow("sr2", r2)
END IF
LET arr2[r2].name = arr3[r3].name
LET att2[r2].color = att3[r3].color
CALL d.setCurrentRow("sr2", r2)
CALL d.deleteRow("sr3", r3)
CALL setup(d)
END FUNCTION
FUNCTION fillarr(a, c, p, m, d)
DEFINE a DYNAMIC ARRAY OF RECORD name STRING END RECORD
DEFINE c DYNAMIC ARRAY OF RECORD color STRING END RECORD
DEFINE p, d STRING
DEFINE m, i INTEGER
CALL a.clear()
CALL c.clear()
FOR i = 1 TO m
LET a[i].name = p || "-" || i
LET c[i].color = d
END FOR
END FUNCTION