fieldlength% = 36
CALL textinput
(text$
, fieldlength%
)
SUB textinput
(text$
, fieldlength%
) STATIC initiate%
, hscrollon%
, hscroll%
, textfg%
, textbk%
, highlightfg%
STATIC highlightbk%
, leftmargin%
, rightmargin%
, textmaxlength%
, linecharacter%
STATIC click_l%
, drag%
, shiftclick%
, starthighlight%
, highlight%
, overwrite%
, CurAdvance%
IF NOT initiate%
THEN ' Initiate textinput variables. initiate% = -1
' --------------------POLL MOUSE--->
mb.w = 0
'<----------------------------------
GOSUB form_input_keyroutine
'-------------------------------------------------------------------------
oldmy% = my%: oldmx% = mx%
'---------------------------GOSUB STATEMENTS-----------------------------
initiate_variables:
textfg% = 0
textbk% = 7
highlightfg% = 15
highlightbk% = 1
rightmargin% = leftmargin% + fieldlength%
textmaxlength% = 100
linecharacter%
= 255:
REM Blank space
IF textmaxlength%
> rightmargin%
- (leftmargin%
- 1) THEN hscrollon%
= -1 IF rightmargin%
< leftmargin%
THEN CLS:
PRINT "Rightmargin% cannot be smaller than leftmargin%. Redo.":
END IF leftmargin%
< 1 OR leftmargin%
> 80 THEN CLS:
PRINT "Leftmargin% is not within 1 - 80 range. Redo.":
END IF LEN(text$
) > textmaxlength%
THEN CLS:
PRINT "Text length cannot start out larger than textmaxlength%. Redo.":
END
IF rightmargin%
= leftmargin%
AND textmaxlength%
= 1 THEN CurAdvance% = 0
CurAdvance% = 1
LOCATE iyy%
, leftmargin%
, 1, 7, 7 RETURN '-----------------------------------------------------------------
form_input_keyroutine:
CASE 18176, 20224, 19200, 19712, 21248, 20992 shift% = -1
control% = -2
control% = -1
control% = 0
REM Evaluate changes
to highlighted text
, excluding cut
/copy
/paste
mykey%
= 88:
REM Convert Delete
to Cut
action$ = "enter"
action$ = "exit"
IF flagtext%
= -1 THEN flagtext%
= 0: mykey%
= 0
CASE 67, 99, 88, 120 ' C c X x
GOSUB CursorHome
' Ctrl + Home
GOSUB CursorEnd
' Ctrl + End
' Do nothing.
RETURN '-----------------------------------------------------------------
' Key Actions.
CursorLeft:
RETURN '------------------------------------------------------------------
CursorRight:
IF POS(0) + CurAdvance%
<= leftmargin%
- 1 + LEN(text$
) + 1 THEN IF hscroll%
+ rightmargin%
- (leftmargin%
- 1) <= LEN(text$
) THEN hscroll% = hscroll% + 1
RETURN '------------------------------------------------------------------
ctrllt:
texttemp$
= MID$(text$
, 1, POS(0) - leftmargin%
+ 1 + hscroll%
) FOR ictrllt%
= POS(0) - leftmargin%
+ 1 + hscroll%
TO 1 STEP -1 IF MID$(text$
, ictrllt%
, 1) <> " " THEN exitctrl%
= -1 exitctrl% = 0
RETURN '---------------------------------------------------------------------
ctrlrt:
texttemp$
= MID$(text$
, POS(0) - leftmargin%
+ 1 + hscroll%
) FOR ictrlrt%
= POS(0) - leftmargin%
+ 1 + hscroll%
TO LEN(text$
) jctrlrt% = -1
IF MID$(text$
, ictrlrt%
, 1) = " " AND jctrlrt%
THEN exitctrl%
= -1 exitctrl% = 0: ictrlrt% = 0: jctrlrt% = 0
RETURN '---------------------------------------------------------------------
CursorHome:
RETURN '---------------------------------------------------------------------
CursorEnd:
IF LEN(text$
) > rightmargin%
- (leftmargin%
- 1) THEN hscroll%
= LEN(text$
) - (rightmargin%
- (leftmargin%
- 1)) + 1:
REM + 1 allows
for adding
to end of text.
IF LEN(text$
) + leftmargin%
- 1 >= rightmargin%
THEN LOCATE , leftmargin%
- 1 + LEN(text$
) + CurAdvance%
RETURN '---------------------------------------------------------------------
CursorUp:
CursorDown:
RETURN '---------------------------------------------------------------------
PageUp:
PageDown:
REM Highlighting
----------------------------------------------------------- HighlightLeft:
IF highlight%
AND POS(0) >= highlight%
- hscroll%
THEN ' Unhighlighting left to right. ' Move back first and then calculate POS(0) - 1, below.
IF highlight%
= starthighlight%
THEN starthighlight% = 0: highlight% = 0
highlight%
= POS(0) - 1 + hscroll%
' Diminishing. ELSE ' Highlighting left to right. ' Calculate first and then move back. POS(0).
IF highlight%
= 0 THEN highlight%
= POS(0) + hscroll%
starthighlight%
= POS(0) + hscroll%
IF POS(0) = leftmargin%
AND hscroll%
THEN hscroll%
= hscroll%
- 1 ' hscroll% is reduced after the calculations above. c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
texttemp$
= MID$(text$
, 1 + hscroll%
, rightmargin%
- leftmargin%
+ 1)
COLOR c1%
, c2%:
PRINT MID$(texttemp$
, 1, starthighlight%
- hscroll%
- leftmargin%
- 1);
COLOR c3%
, c4%:
PRINT MID$(texttemp$
, starthighlight%
- hscroll%
- leftmargin%
+ 0, ABS(highlight%
- starthighlight%
) + 1);
COLOR c1%
, c2%:
PRINT MID$(texttemp$
, highlight%
- hscroll%
- leftmargin%
+ 1);
IF ixx%
- leftmargin%
> 0 THEN ixx%
= ixx%
- 1 ' No moving cursor back when it is at left amrgin and scrolling text back. RETURN '---------------------------------------------------------------------
HighlightRight:
IF hscroll%
+ ixx%
+ 1 - leftmargin%
<= LEN(text$
) THEN c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
IF starthighlight%
= 0 THEN starthighlight%
= POS(0) + 1 + hscroll%
highlight%
= POS(0) + 1 + hscroll%
IF starthighlight%
= highlight%
THEN starthighlight% = 0: highlight% = 0
starthighlight%
= POS(0) + 2 + hscroll%
IF POS(0) = rightmargin%
AND LEN(text$
) - hscroll%
> rightmargin%
- leftmargin%
THEN hscroll%
= hscroll%
+ 1 texttemp$
= MID$(text$
, 1 + hscroll%
, rightmargin%
- leftmargin%
+ 1)
COLOR c1%
, c2%:
PRINT MID$(texttemp$
, 1, starthighlight%
- hscroll%
- leftmargin%
- 1);
COLOR c3%
, c4%:
PRINT MID$(texttemp$
, starthighlight%
- hscroll%
- leftmargin%
+ 0, ABS(highlight%
- starthighlight%
) + 1);
COLOR c1%
, c2%:
PRINT MID$(texttemp$
, highlight%
- hscroll%
- leftmargin%
+ 1);
IF POS(0) = rightmargin%
THEN PRINT SPACE$(1);
' Only used when highlighting past last character to include one blank space. IF ixx%
< rightmargin%
THEN ixx%
= ixx%
+ 1 RETURN '---------------------------------------------------------------------
ClickhighLight:
j% = 0
texttemp$
= MID$(text$
, 1, POS(0) - leftmargin%
+ 1 + hscroll%
) jClickhighLight%
= LEN(texttemp$
) - i%
- 1 invokestarthighlight%
= POS(0) + hscroll%
- (LEN(texttemp$
) - i%
) + 1 FOR iClickhighLight%
= 1 TO jClickhighLight%
shift% = -1
shift% = 0
invokestarthighlight% = 0: iClickhighLight% = 0: jClickhighLight% = 0
RETURN '---------------------------------------------------------------------
SelectAll:
highlight%
= 0: starthighlight%
= 0:
REM These are
not zeroed
as a ctrl keys bypass remove highlighting
RETURN '---------------------------------------------------------------------
SelectToEnd:
IF mspan%
= 0 THEN mspan%
= POS(0) - leftmargin%
+ 1 + LEN(text$
) FOR iSelectToEnd%
= 1 TO mspan%
mspan% = 0: iSelectToEnd% = 0
RETURN '---------------------------------------------------------------------
SelectToHome:
mspan% = rightmargin% - (leftmargin% - 1) + hscroll%
mspan%
= POS(0) - leftmargin%
+ 1 + hscroll%
FOR iSelectToHome%
= 1 TO mspan%
mspan% = 0: iSelectToHome% = 0
RETURN '---------------------------------------------------------------------
DisplayText:
IF overwrite%
= -1 OR CurAdvance%
= 0 THEN texttemp$
= MID$(text$
, 1, POS(0) - leftmargin%
) + CHR$(mykey%
) + MID$(text$
, POS(0) - leftmargin%
+ 2) texttemp$
= MID$(text$
, 1, POS(0) - leftmargin%
) + CHR$(mykey%
) + MID$(text$
, POS(0) - leftmargin%
+ 1)
IF overwrite%
= -1 OR CurAdvance%
= 0 THEN
IF POS(0) - leftmargin%
+ hscroll%
< textmaxlength%
THEN text$
= MID$(text$
, 1, POS(0) + (hscroll%
) - leftmargin%
) + CHR$(mykey%
) + MID$(text$
, POS(0) + hscroll%
- leftmargin%
+ 2) flagtext%
= -1:
EXIT DO 'To Return
REM Evaluate Horizontal Scroll
hscroll% = hscroll% + 1
text$
= MID$(text$
, 1, POS(0) + hscroll%
- leftmargin%
) + CHR$(mykey%
) + MID$(text$
, POS(0) + hscroll%
- leftmargin%
+ 1) flagtext% = 0
flagtext% = -1
IF flagtext%
= -1 THEN EXIT DO ' To Return REM flagtext% is set to zero upon return and exit.
REM Evaluate Horizontal Scroll
hscroll% = hscroll% + 1
' Print to form input line.
LOCATE , leftmargin%:
PRINT MID$(text$
, (hscroll%
+ 1), rightmargin%
- (leftmargin%
- 1));
IF CurAdvance%
= 1 AND positioncursor%
- leftmargin%
+ 1 < rightmargin%
- leftmargin%
+ 1 THEN LOCATE , positioncursor%
+ CurAdvance%
RETURN '---------------------------------------------------------------------
BackspaceDelete:
REM Adjust
for horizontal scroll
countcolumnsmoved% = hscroll%
jBackspaceDelete% = (rightmargin% - (leftmargin% - 1)) * .33
IF jBackspaceDelete%
< 3 AND rightmargin%
- (leftmargin%
- 1) > 3 THEN jBackspaceDelete%
= 3:
REM Set minimum scroll back.
FOR iBackspaceDelete%
= 1 TO jBackspaceDelete%
LOCATE , holdcursor%
+ countcolumnsmoved%
- hscroll%
- 1 countcolumnsmoved% = 0: iBackspaceDelete% = 0: jBackspaceDelete% = 0
text$
= MID$(text$
, 1, POS(0) - leftmargin%
+ hscroll%
) + MID$(text$
, POS(0) - leftmargin%
+ hscroll%
+ 2) texttemp$
= MID$(text$
, hscroll%
+ 1, rightmargin%
- (leftmargin%
- 1)) LOCATE iyy%
, leftmargin%:
PRINT texttemp$
+ STRING$((rightmargin%
- (leftmargin%
- 1)) - LEN(texttemp$
), linecharacter%
);
RETURN '---------------------------------------------------------------------
cutcopy:
_CLIPBOARD$ = MID$(text$
, starthighlight%
- leftmargin%
, highlight%
- starthighlight%
+ 1)
IF mykey%
= 88 OR mykey%
= 120 OR mykey%
= 8 OR mykey%
= 21248 THEN ' ctrl + x (cut), delete, backspace. positioncursor% = starthighlight% - 1 - hscroll%
texttemp$
= MID$(text$
, 1, starthighlight%
- leftmargin%
- 1) + MID$(text$
, highlight%
- leftmargin%
+ 1) text$ = texttemp$
hscroll%
= hscroll%
- ABS(highlight%
- starthighlight%
) IF hscroll%
< 0 THEN hscroll%
= 0 RETURN '---------------------------------------------------------------------
PasteClipboard:
IF positioncursor%
> rightmargin%
THEN hscroll% = hscroll% + positioncursor% - rightmargin%
positioncursor% = rightmargin%
RETURN '---------------------------------------------------------------------
InsertOverwrite:
overwrite% = -1
overwrite% = 0
' End Key Controls-------------------------------------------------------
mouseroutine:
IF shiftclick%
> 0 THEN mykey%
= 19712: shiftclick%
= shiftclick%
- 1 ELSE mykey%
= 19200: shiftclick%
= shiftclick%
+ 1
click_l% = -1
CASE IS > POS(0): mykey%
= 19712: shiftclick%
= mx%
- POS(0) - 1 CASE IS < POS(0): mykey%
= 19200: shiftclick%
= mx%
- POS(0) + 1 IF click_l%
= -1 THEN click_l%
= 1: drag%
= 0
drag% = -1
LOCATE my%
, mx%
' Click in input field.
shift% = -1
'-------------------------------Nested Gosubs-----------------------------
wash:
starthighlight% = 0
highlight% = 0
texttemp$
= MID$(text$
, (hscroll%
+ 1), rightmargin%
- (leftmargin%
- 1)) PRINT texttemp$
+ STRING$(rightmargin%
- (leftmargin%
- 1) - LEN(texttemp$
), linecharacter%
);
RETURN '---------------------------------------------------------------------
selection_made:
RETURN '---------------------------------------------------------------------