1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-15 03:49:56 +00:00

Properly stores and retrieves special characters from .frm; Closes #67.

Special characters are now saved using escape codes which are interpreted at load time. Instead of storing CHR$(10), we store \10; inside the string being saved and so forth for every character below ASC(32), for CHR(34) and for ASC("\").
This commit is contained in:
FellippeHeitor 2018-06-24 22:26:56 -03:00
parent 5a396f0143
commit 5ddeaf6c59
3 changed files with 59 additions and 24 deletions

View file

@ -4618,21 +4618,6 @@ FUNCTION __UI_LoadThemeImage& (FileName$)
__UI_LoadThemeImage& = TempImage
END FUNCTION
'---------------------------------------------------------------------------------
FUNCTION __UI_SpecialCharsToCHR$ (Text$)
DIM i AS LONG, Temp$
Temp$ = CHR$(34)
FOR i = 1 TO LEN(Text$)
IF ASC(Text$, i) < 32 OR ASC(Text$, i) = 34 THEN
Temp$ = Temp$ + CHR$(34) + " + CHR$(" + LTRIM$(STR$(ASC(Text$, i))) + ") + " + CHR$(34)
ELSE
Temp$ = Temp$ + MID$(Text$, i, 1)
END IF
NEXT
__UI_SpecialCharsToCHR$ = Temp$ + CHR$(34)
END FUNCTION
'---------------------------------------------------------------------------------
SUB SetRadioButtonValue (id AS LONG)
'Radio buttons will change value of others in the same group

View file

@ -3398,12 +3398,12 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
'ELSE
' a$ = PreviewCaptions(i)
'END IF
a$ = " SetCaption __UI_NewID, " + __UI_SpecialCharsToCHR$(PreviewCaptions(i))
a$ = " SetCaption __UI_NewID, " + SpecialCharsToEscapeCode$(PreviewCaptions(i))
PRINT #TextFileNum, a$
END IF
IF LEN(PreviewTips(i)) > 0 THEN
a$ = " ToolTip(__UI_NewID) = " + __UI_SpecialCharsToCHR$(PreviewTips(i))
a$ = " ToolTip(__UI_NewID) = " + SpecialCharsToEscapeCode$(PreviewTips(i))
PRINT #TextFileNum, a$
END IF
@ -3432,12 +3432,12 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
a$ = " LoadImage Control(__UI_NewID), " + CHR$(34) + PreviewTexts(i) + CHR$(34)
PRINT #TextFileNum, a$
CASE ELSE
a$ = " Text(__UI_NewID) = " + __UI_SpecialCharsToCHR$(PreviewTexts(i))
a$ = " Text(__UI_NewID) = " + SpecialCharsToEscapeCode$(PreviewTexts(i))
PRINT #TextFileNum, a$
END SELECT
END IF
IF LEN(PreviewMasks(i)) > 0 THEN
a$ = " Mask(__UI_NewID) = " + __UI_SpecialCharsToCHR$(PreviewMasks(i))
a$ = " Mask(__UI_NewID) = " + SpecialCharsToEscapeCode$(PreviewMasks(i))
PRINT #TextFileNum, a$
END IF
IF PreviewControls(i).TransparentColor > 0 THEN
@ -4265,3 +4265,18 @@ FUNCTION Download$ (url$, file$, timelimit) STATIC
Download = MKI$(0) 'still working
END FUNCTION
'---------------------------------------------------------------------------------
FUNCTION SpecialCharsToEscapeCode$ (Text$)
DIM i AS LONG, Temp$
Temp$ = CHR$(34)
FOR i = 1 TO LEN(Text$)
IF ASC(Text$, i) < 32 OR ASC(Text$, i) = 34 OR ASC(Text$, i) = 92 THEN
Temp$ = Temp$ + "\" + LTRIM$(STR$(ASC(Text$, i))) + ";"
ELSE
Temp$ = Temp$ + MID$(Text$, i, 1)
END IF
NEXT
SpecialCharsToEscapeCode$ = Temp$ + CHR$(34)
END FUNCTION

View file

@ -2233,13 +2233,12 @@ SUB LoadPreviewText
'Caption
DummyText$ = nextParameter(b$) 'discard first parameter
DummyText$ = nextParameter(b$)
'Replace CHR$(10) with \n:
DummyText$ = Replace$(DummyText$, CHR$(34) + " + CHR$(10) + " + CHR$(34), "\n", False, 0)
DummyText$ = RestoreCHRfromEscapeCode$(DummyText$)
SetCaption TempValue, DummyText$
ELSEIF LEFT$(b$, 8) = "AddItem " THEN
'Caption
DummyText$ = nextParameter(b$) 'discard first parameter
DummyText$ = nextParameter(b$)
DummyText$ = RestoreCHRfromEscapeCode(nextParameter(b$))
AddItem TempValue, DummyText$
ELSEIF LEFT$(b$, 10) = "LoadImage " THEN
'Image
@ -2249,12 +2248,12 @@ SUB LoadPreviewText
ELSEIF LEFT$(b$, 22) = "ToolTip(__UI_NewID) = " THEN
'Tooltip
DummyText$ = MID$(b$, INSTR(b$, " = ") + 3)
DummyText$ = Replace$(DummyText$, CHR$(34) + " + CHR$(10) + " + CHR$(34), CHR$(10), False, 0)
DummyText$ = RestoreCHRfromEscapeCode$(DummyText$)
ToolTip(TempValue) = removeQuotation$(DummyText$)
ELSEIF LEFT$(b$, 19) = "Text(__UI_NewID) = " THEN
'Text
DummyText$ = MID$(b$, INSTR(b$, " = ") + 3)
DummyText$ = Replace$(DummyText$, CHR$(34) + " + CHR$(10) + " + CHR$(34), CHR$(10), False, 0)
DummyText$ = RestoreCHRfromEscapeCode$(DummyText$)
Text(TempValue) = removeQuotation$(DummyText$)
IF Control(TempValue).Type = __UI_Type_PictureBox OR Control(TempValue).Type = __UI_Type_Button THEN
@ -2269,6 +2268,7 @@ SUB LoadPreviewText
ELSEIF LEFT$(b$, 19) = "Mask(__UI_NewID) = " THEN
'Mask
DummyText$ = MID$(b$, INSTR(b$, " = ") + 3)
DummyText$ = RestoreCHRfromEscapeCode$(DummyText$)
Mask(TempValue) = removeQuotation$(DummyText$)
ELSEIF INSTR(b$, "__UI_NewControl") > 0 THEN
'New Control
@ -2942,3 +2942,38 @@ SUB LoadDefaultFonts
Control(__UI_FormID).Font = SetFont("InForm/resources/NotoMono-Regular.ttf", 12)
END IF
END SUB
FUNCTION RestoreCHRfromEscapeCode$ (__Text$)
DIM Text$, i AS LONG, BackSlash AS LONG, SemiColon AS LONG
DIM j AS LONG, tempNum$
Text$ = __Text$
IF INSTR(Text$, "\") = 0 THEN
RestoreCHRfromEscapeCode$ = Text$
EXIT FUNCTION
END IF
DO
BackSlash = INSTR(BackSlash + 1, Text$, "\")
IF BackSlash = 0 THEN EXIT DO
SemiColon = INSTR(BackSlash + 1, Text$, ";")
IF SemiColon = 0 THEN _CONTINUE
tempNum$ = ""
FOR j = BackSlash + 1 TO SemiColon - 1
IF ASC(Text$, j) < 48 OR ASC(Text$, j) > 57 THEN tempNum$ = "": EXIT FOR
tempNum$ = tempNum$ + MID$(Text$, j, 1)
NEXT
IF LEN(tempNum$) THEN
Text$ = LEFT$(Text$, BackSlash - 1) + CHR$(VAL(tempNum$)) + MID$(Text$, SemiColon + 1)
END IF
BackSlash = 0
LOOP
RestoreCHRfromEscapeCode$ = Text$
END FUNCTION