1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-15 11:59:34 +00:00

Saves and loads control bindings to/from .frm files.

This commit is contained in:
FellippeHeitor 2020-02-16 14:39:59 -03:00
parent bd01e48060
commit e926e788b0
4 changed files with 115 additions and 54 deletions

View file

@ -6953,11 +6953,11 @@ SUB __UI_CheckBinding(id AS LONG)
BindTarget = Control(id).BoundTo
IF BindTarget = 0 THEN EXIT SUB
IF Control(id).BoundProperty = Control(BindTarget).BoundProperty AND _
Control(id).BoundProperty = __UI_PropertyEnum&("Value", 0) THEN
Control(id).Min = Control(BindTarget).Min
Control(id).Max = Control(BindTarget).Max
END IF
'IF Control(id).BoundProperty = Control(BindTarget).BoundProperty AND _
' Control(id).BoundProperty = __UI_PropertyEnum&("Value", 0) THEN
' Control(id).Min = Control(BindTarget).Min
' Control(id).Max = Control(BindTarget).Max
'END IF
SELECT CASE Control(id).BoundProperty
CASE __UI_PropertyEnum&("Top", 0)

View file

@ -107,7 +107,7 @@ DIM SHARED SourceControlLB AS LONG
DIM SHARED SourceControlNameLB AS LONG
DIM SHARED TargetControlLB AS LONG
DIM SHARED TargetControlNameLB AS LONG
DIM SHARED SwapBT AS LONG
'DIM SHARED SwapBT AS LONG
DIM SHARED SourcePropertyLB AS LONG
DIM SHARED SourcePropertyList AS LONG
DIM SHARED TargetPropertyLB AS LONG
@ -189,6 +189,7 @@ REDIM SHARED PreviewControls(0) AS __UI_ControlTYPE
REDIM SHARED PreviewParentIDS(0) AS STRING
REDIM SHARED PreviewContextMenu(0) AS STRING
REDIM SHARED PreviewBoundTo(0) AS STRING
REDIM SHARED PreviewBoundProperty(0) AS STRING
REDIM SHARED PreviewKeyCombos(0) AS STRING
REDIM SHARED PreviewAnimatedGif(0) AS _BYTE
REDIM SHARED PreviewAutoPlayGif(0) AS _BYTE
@ -604,7 +605,7 @@ SUB __UI_Click (id AS LONG)
__UI_Focus = ControlList
ZOrderingDialogOpen = True
CASE EditMenuBindControls
'Get controls' names
'Get controls' names and bound properties
DIM CurrentSource$
j = 0
FOR i = 1 TO UBOUND(PreviewControls)
@ -613,17 +614,29 @@ SUB __UI_Click (id AS LONG)
IF j = 1 THEN
Caption(SourceControlNameLB) = RTRIM$(PreviewControls(i).Name)
CurrentSource$ = PreviewBoundTo(i)
IF LEN(PreviewBoundProperty(i)) = 0 THEN
Dummy = SelectItem(SourcePropertyList, "Value")
ELSE
Dummy = SelectItem(SourcePropertyList, PreviewBoundProperty(i))
END IF
END IF
IF j = 2 THEN
Caption(TargetControlNameLB) = RTRIM$(PreviewControls(i).Name)
IF LEN(PreviewBoundProperty(i)) = 0 THEN
Dummy = SelectItem(TargetPropertyList, "Value")
ELSE
Dummy = SelectItem(TargetPropertyList, PreviewBoundProperty(i))
END IF
EXIT FOR
END IF
END IF
NEXT
IF CurrentSource$ = Caption(TargetControlNameLB) THEN
Caption(BindBT) = "Rebind"
Caption(CancelBindBT) = "Unbind"
ELSE
Caption(BindBT) = "Bind"
Caption(CancelBindBT) = "Cancel"
END IF
@ -632,9 +645,9 @@ SUB __UI_Click (id AS LONG)
Control(SetControlBinding).Left = 83: Control(SetControlBinding).Top = 169
__UI_Focus = SourcePropertyList
SetBindingDialogOpen = True
CASE SwapBT
SWAP Caption(SourceControlNameLB), Caption(TargetControlNameLB)
SWAP Control(SourcePropertyList).Value, Control(TargetPropertyList).Value
'CASE SwapBT
' SWAP Caption(SourceControlNameLB), Caption(TargetControlNameLB)
' SWAP Control(SourcePropertyList).Value, Control(TargetPropertyList).Value
CASE BindBT
Control(DialogBG).Left = -600: Control(DialogBG).Top = -600
Control(SetControlBinding).Left = -600: Control(SetControlBinding).Top = -600
@ -1596,18 +1609,6 @@ SUB __UI_BeforeUpdateDisplay
__UI_ShowInvisibleControls = CVI(thisData$)
Control(ViewMenuShowInvisibleControls).Value = __UI_ShowInvisibleControls
CASE "SHOWBINDCONTROLDIALOG"
b$ = ReadSequential(thisData$, 4)
IF CVL(b$) = 0 THEN
j = SelectItem(SourcePropertyList, "Value")
ELSE
j = SelectItem(SourcePropertyList, ReadSequential(thisData$, CVL(b$)))
END IF
b$ = ReadSequential(thisData$, 4)
IF CVL(b$) = 0 THEN
j = SelectItem(TargetPropertyList, "Value")
ELSE
j = SelectItem(TargetPropertyList, ReadSequential(thisData$, CVL(b$)))
END IF
__UI_Click EditMenuBindControls
CASE "ORIGINALIMAGEWIDTH"
OriginalImageWidth = CVI(thisData$)
@ -3778,16 +3779,17 @@ SUB LoadPreview
b$ = ReadSequential$(FormData$, 4)
REDIM PreviewCaptions(1 TO CVL(b$)) AS STRING
REDIM PreviewTexts(1 TO CVL(b$)) AS STRING
REDIM PreviewMasks(1 TO CVL(b$)) AS STRING
REDIM PreviewTips(1 TO CVL(b$)) AS STRING
REDIM PreviewFonts(1 TO CVL(b$)) AS STRING
REDIM PreviewActualFonts(1 TO CVL(b$)) AS STRING
REDIM PreviewCaptions(0 TO CVL(b$)) AS STRING
REDIM PreviewTexts(0 TO CVL(b$)) AS STRING
REDIM PreviewMasks(0 TO CVL(b$)) AS STRING
REDIM PreviewTips(0 TO CVL(b$)) AS STRING
REDIM PreviewFonts(0 TO CVL(b$)) AS STRING
REDIM PreviewActualFonts(0 TO CVL(b$)) AS STRING
REDIM PreviewControls(0 TO CVL(b$)) AS __UI_ControlTYPE
REDIM PreviewParentIDS(0 TO CVL(b$)) AS STRING
REDIM PreviewContextMenu(0 TO CVL(b$)) AS STRING
REDIM PreviewBoundTo(0 TO CVL(b$)) AS STRING
REDIM PreviewBoundProperty(0 TO CVL(b$)) AS STRING
REDIM PreviewKeyCombos(0 TO CVL(b$)) AS STRING
REDIM PreviewAnimatedGif(0 TO CVL(b$)) AS _BYTE
REDIM PreviewAutoPlayGif(0 TO CVL(b$)) AS _BYTE
@ -3966,6 +3968,9 @@ SUB LoadPreview
b$ = ReadSequential$(FormData$, 2)
b$ = ReadSequential$(FormData$, CVI(b$))
PreviewBoundTo(Dummy) = b$
b$ = ReadSequential$(FormData$, 2)
b$ = ReadSequential$(FormData$, CVI(b$))
PreviewBoundProperty(Dummy) = b$
CASE -1 'new control
EXIT DO
CASE -1024
@ -4146,7 +4151,7 @@ SUB CheckPreview
END SUB
SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
DIM BaseOutputFileName AS STRING
DIM BaseOutputFileName AS STRING, j AS LONG
DIM TextFileNum AS INTEGER, Answer AS _BYTE, b$, i AS LONG
DIM a$, FontSetup$, FindSep AS INTEGER, NewFontFile AS STRING
DIM NewFontSize AS INTEGER, Dummy AS LONG, BackupFile$
@ -4485,6 +4490,31 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
NEXT
NEXT ThisPass
'Save control bindings
DIM BindingsSection AS _BYTE
DIM BindingDone(0 TO UBOUND(PreviewControls)) AS _BYTE
FOR i = 1 TO UBOUND(PreviewControls)
IF LEN(PreviewBoundTo(i)) > 0 AND BindingDone(i) = False THEN
IF BindingsSection = False THEN
PRINT #TextFileNum, " 'Control bindings:"
BindingsSection = True
END IF
BindingDone(i) = True
PRINT #TextFileNum, " __UI_Bind __UI_GetID(" + CHR$(34);
PRINT #TextFileNum, RTRIM$(__UI_TrimAt0$(PreviewControls(i).Name)) + CHR$(34) + "), ";
PRINT #TextFileNum, "__UI_GetID(" + CHR$(34);
PRINT #TextFileNum, PreviewBoundTo(i) + CHR$(34) + "), ";
PRINT #TextFileNum, CHR$(34) + PreviewBoundProperty(i) + CHR$(34) + ", ";
FOR j = 1 TO UBOUND(PreviewControls)
IF PreviewBoundTo(j) = RTRIM$(__UI_TrimAt0$(PreviewControls(i).Name)) THEN
BindingDone(j) = True
PRINT #TextFileNum, CHR$(34) + PreviewBoundProperty(j) + CHR$(34)
EXIT FOR
END IF
NEXT
END IF
NEXT
PRINT #TextFileNum, "END SUB"
PRINT #TextFileNum,
PRINT #TextFileNum, "SUB __UI_AssignIDs"

View file

@ -790,9 +790,9 @@ SUB __UI_LoadForm
SetCaption __UI_NewID, "TargetControlName"
Control(__UI_NewID).VAlign = __UI_Middle
__UI_NewID = __UI_NewControl(__UI_Type_Button, "SwapBT", 160, 23, 19, 220, __UI_GetID("SetControlBinding"))
SetCaption __UI_NewID, "Swap source and target"
Control(__UI_NewID).CanHaveFocus = True
'__UI_NewID = __UI_NewControl(__UI_Type_Button, "SwapBT", 160, 23, 19, 220, __UI_GetID("SetControlBinding"))
'SetCaption __UI_NewID, "Swap source and target"
'Control(__UI_NewID).CanHaveFocus = True
__UI_NewID = __UI_NewControl(__UI_Type_DropdownList, "SourcePropertyList", 380, 23, 35, 71, __UI_GetID("SetControlBinding"))
AddItem __UI_NewID, "Top"
@ -1018,7 +1018,7 @@ SUB __UI_AssignIDs
SourceControlNameLB = __UI_GetID("SourceControlNameLB")
TargetControlLB = __UI_GetID("TargetControlLB")
TargetControlNameLB = __UI_GetID("TargetControlNameLB")
SwapBT = __UI_GetID("SwapBT")
'SwapBT = __UI_GetID("SwapBT")
SourcePropertyLB = __UI_GetID("SourcePropertyLB")
SourcePropertyList = __UI_GetID("SourcePropertyList")
TargetPropertyLB = __UI_GetID("TargetPropertyLB")

View file

@ -1765,22 +1765,22 @@ SUB __UI_KeyPress (id AS LONG)
CASE 227 'Toggle __UI_ShowInvisibleControls
__UI_ShowInvisibleControls = NOT __UI_ShowInvisibleControls
CASE 228 'Bind/unbind controls
DIM a$, b$, c$, found AS _BYTE
DIM i AS LONG, j AS LONG
FOR i = 1 TO UBOUND(Control)
IF Control(i).ControlIsSelected THEN
j = j + 1
IF j = 1 THEN
found = __UI_PropertyEnum(a$, Control(i).BoundProperty)
IF __UI_TotalSelectedControls = 1 THEN EXIT FOR
ELSEIF j = 2 THEN
found = __UI_PropertyEnum(b$, Control(i).BoundProperty)
EXIT FOR
END IF
END IF
NEXT
c$ = MKL$(LEN(a$)) + a$ + MKL$(LEN(b$)) + b$
SendData c$, "SHOWBINDCONTROLDIALOG"
'DIM a$, b$, c$, found AS _BYTE
'DIM i AS LONG, j AS LONG
'FOR i = 1 TO UBOUND(Control)
' IF Control(i).ControlIsSelected THEN
' j = j + 1
' IF j = 1 THEN
' found = __UI_PropertyEnum(a$, Control(i).BoundProperty)
' IF __UI_TotalSelectedControls = 1 THEN EXIT FOR
' ELSEIF j = 2 THEN
' found = __UI_PropertyEnum(b$, Control(i).BoundProperty)
' EXIT FOR
' END IF
' END IF
'NEXT
'c$ = MKL$(LEN(a$)) + a$ + MKL$(LEN(b$)) + b$
SendData "", "SHOWBINDCONTROLDIALOG"
END SELECT
END SUB
@ -3075,6 +3075,30 @@ SUB LoadPreviewText
'New Control
IF LogFileLoad THEN PRINT #LogFileNum, "READ NEW CONTROL"
EXIT DO
ELSEIF LEFT$(b$, 10) = "__UI_Bind " THEN
ASC(b$, 10) = 40 'Changes first space into "(" for parsing
DIM SourceControl$, TargetControl$
DIM SourceProperty$, TargetProperty$
DIM SourceSet AS _BYTE, TargetSet AS _BYTE
SourceControl$ = nextParameter$(b$)
TargetControl$ = nextParameter$(b$)
SourceProperty$ = nextParameter$(b$)
TargetProperty$ = nextParameter$(b$)
SourceSet = False: TargetSet = False
FOR i = 1 TO UBOUND(Control)
IF RTRIM$(Control(i).Name) = SourceControl$ THEN
Control(i).BoundTo = __UI_GetID(TargetControl$)
Control(i).BoundProperty = __UI_PropertyEnum(SourceProperty$, 0)
SourceSet = True
ELSEIF RTRIM$(Control(i).Name) = TargetControl$ THEN
Control(i).BoundTo = __UI_GetID(SourceControl$)
Control(i).BoundProperty = __UI_PropertyEnum(TargetProperty$, 0)
TargetSet = True
END IF
IF SourceSet AND TargetSet THEN EXIT FOR
NEXT
ELSEIF b$ = "END SUB" THEN
IF LogFileLoad THEN PRINT #LogFileNum, "END OF FILE"
__UI_EOF = True
@ -3165,18 +3189,23 @@ FUNCTION nextParameter$ (__text$)
END FUNCTION
FUNCTION removeQuotation$ (__text$)
DIM text$
DIM text$, firstQ AS LONG, nextQ AS LONG
text$ = __text$
IF LEFT$(text$, 1) = CHR$(34) THEN text$ = MID$(text$, 2)
IF RIGHT$(text$, 1) = CHR$(34) THEN text$ = LEFT$(text$, LEN(text$) - 1)
removeQuotation$ = text$
firstQ = INSTR(text$, CHR$(34))
IF firstQ = 0 THEN removeQuotation$ = text$: EXIT FUNCTION
nextQ = INSTR(firstQ + 1, text$, CHR$(34))
IF nextQ = 0 THEN removeQuotation$ = MID$(text$, firstQ + 1): EXIT FUNCTION
removeQuotation$ = MID$(text$, firstQ + 1, nextQ - firstQ - 1)
END FUNCTION
SUB SavePreview (Destination AS _BYTE)
DIM b$, i AS LONG, a$, FontSetup$, TempValue AS LONG
DIM BinFileNum AS INTEGER, TxtFileNum AS INTEGER
DIM Clip$, Disk AS _BYTE, TCP AS _BYTE, UndoBuffer AS _BYTE
DIM PreviewData$
DIM PreviewData$, Dummy AS LONG
CONST Debug = False
@ -3545,6 +3574,8 @@ SUB SavePreview (Destination AS _BYTE)
END IF
IF Control(i).BoundTo > 0 THEN
b$ = MKI$(-48) + MKI$(LEN(RTRIM$(Control(Control(i).BoundTo).Name))) + RTRIM$(Control(Control(i).BoundTo).Name)
Dummy = __UI_PropertyEnum&(a$, Control(i).BoundProperty)
b$ = b$ + MKI$(LEN(a$)) + a$
IF Disk THEN PUT #BinFileNum, , b$ ELSE Clip$ = Clip$ + b$
END IF
END IF