Author Topic: Working on the WP "Find" feature, or Fun with Parsing...  (Read 2944 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Working on the WP "Find" feature, or Fun with Parsing...
« on: January 26, 2021, 06:02:09 pm »
Code: QB64: [Select]
  1. DIM SHARED mx%, my%, margin.t AS INTEGER, margin.l AS INTEGER
  2. DIM SHARED action$
  3. DIM SHARED mb AS my_mb
  4. DIM scrb AS my_scrb
  5.  
  6. TYPE my_mb
  7.     l AS INTEGER
  8.     r AS INTEGER
  9.     m AS INTEGER
  10.     w AS INTEGER
  11.     drag AS INTEGER
  12.     dragon AS INTEGER
  13.  
  14. TYPE my_scrb
  15.     t AS INTEGER
  16.     b AS INTEGER
  17.     l AS INTEGER
  18.     x AS INTEGER
  19.     i AS INTEGER
  20.     d AS INTEGER
  21.     h AS INTEGER
  22.     s AS INTEGER
  23.     opt AS INTEGER
  24.     adjust AS INTEGER
  25.  
  26. DIM SHARED SMODE, passrightmargin%
  27. REDIM SHARED formbuttony%(3), formbuttonx%(3), formbutton$(3)
  28. REDIM button$(8)
  29. REDIM x$(10)
  30. margin.t = 7
  31. margin.l = 3
  32. dwidth = 72
  33. page.h = 1
  34. scr = 0
  35.  
  36. x$(1) = "This is a String Test. A way to string test the F3 find string function." + CHR$(10)
  37.  
  38. LOCATE margin.t + 1, margin.l + 1: PRINT x$(1);
  39.  
  40. msg$ = " Find:                                                  "
  41. button% = 4: button_index% = 4
  42. W1% = 0: W2% = 0: W3% = 0: W4% = 0
  43.  
  44. CALL popup(msg$, msg%, button$(), button%, button_index%, find$) ' Pass by ref text$ to find$
  45.  
  46. SELECT CASE action$
  47.     CASE "Whole Word"
  48.         whole_word% = 1
  49.         case_sensitive% = 0
  50.     CASE "Whole/Case"
  51.         whole_word% = 1
  52.         case_sensitive% = 1
  53.     CASE "Any Part"
  54.         whole_word% = 0
  55.         case_sensitive% = 0
  56.     CASE "Any/Case"
  57.         whole_word% = 0
  58.         case_sensitive% = 1
  59. action$ = ""
  60.  
  61. IF LEN(find$) THEN
  62.     i% = 1
  63.     FOR j% = 1 TO page.h
  64.         LOCATE margin.t + i%, margin.l + 1
  65.         a1$ = SPACE$(dwidth + 1)
  66.         x$ = RTRIM$(MID$(x$(scr + i%), 1, INSTR(x$(scr + i%), CHR$(10)) - 1))
  67.         MID$(a1$, 1, LEN(MID$(x$(scr + i%), 1, dwidth))) = x$
  68.  
  69.         SELECT CASE case_sensitive%
  70.             CASE 0
  71.                 SELECT CASE whole_word%
  72.                     CASE 0
  73.                         IF INSTR(LCASE$(a1$), find$) THEN
  74.                             seed% = 1
  75.                             PRINT MID$(a1$, 1, INSTR(LCASE$(a1$), find$) - 1);
  76.                             DO UNTIL INSTR(seed%, LCASE$(a1$), find$) = 0
  77.                                 COLOR 14, 4
  78.                                 PRINT MID$(a1$, INSTR(seed%, LCASE$(a1$), find$), LEN(find$));
  79.                                 seed% = INSTR(seed%, LCASE$(a1$), find$) + LEN(find$)
  80.                                 COLOR 7, 0
  81.                                 PRINT MID$(a1$, seed%, INSTR(seed%, LCASE$(a1$), find$) - seed%);
  82.                             LOOP
  83.                             PRINT MID$(x$(i%), seed%);
  84.                         ELSE
  85.                             PRINT a1$;
  86.                         END IF
  87.  
  88.                     CASE 1
  89.                         seed% = 0
  90.                         WHILE INSTR(seed%, LCASE$(a1$), LCASE$(find$))
  91.                             flag% = 0
  92.                             seed% = INSTR(seed%, LCASE$(a1$), LCASE$(find$))
  93.                             IF seed% - 1 = 0 OR MID$(LCASE$(a1$), seed% - 1, 1) = " " THEN flag% = 1
  94.  
  95.                             IF flag% THEN
  96.                                 IF INSTR(".,;:?!}]) ", MID$(LCASE$(a1$), seed% + LEN(find$), 1)) THEN flag% = 2
  97.                             END IF
  98.  
  99.                             IF flag% = 2 THEN
  100.                                 LOCATE , margin.l + seed%
  101.                                 COLOR 14, 4
  102.                                 PRINT MID$(a1$, seed%, LEN(find$));
  103.                             END IF
  104.                             seed% = seed% + LEN(find$)
  105.                         WEND
  106.                 END SELECT
  107.  
  108.             CASE 1
  109.                 SELECT CASE whole_word%
  110.                     CASE 0
  111.                         IF INSTR(a1$, find$) THEN
  112.                             seed% = 1
  113.                             PRINT MID$(a1$, 1, INSTR(a1$, find$) - 1);
  114.                             DO UNTIL INSTR(seed%, a1$, find$) = 0
  115.                                 COLOR 14, 4
  116.                                 PRINT MID$(a1$, INSTR(seed%, a1$, find$), LEN(find$));
  117.                                 seed% = INSTR(seed%, a1$, find$) + LEN(find$)
  118.                                 COLOR 7, 0
  119.                                 PRINT MID$(a1$, seed%, INSTR(seed%, a1$, find$) - seed%);
  120.                             LOOP
  121.                             PRINT MID$(x$(i%), seed%);
  122.                         ELSE
  123.                             PRINT a1$;
  124.                         END IF
  125.  
  126.                     CASE 1
  127.                         seed% = 0
  128.                         WHILE INSTR(seed%, a1$, find$)
  129.                             flag% = 0
  130.                             seed% = INSTR(seed%, a1$, find$)
  131.                             IF seed% - 1 = 0 OR MID$(a1$, seed% - 1, 1) = " " THEN flag% = 1
  132.  
  133.                             IF flag% THEN
  134.                                 IF INSTR(".,;:?!}]) ", MID$(a1$, seed% + LEN(find$), 1)) THEN flag% = 2
  135.                             END IF
  136.  
  137.                             IF flag% = 2 THEN
  138.                                 LOCATE , margin.l + seed%
  139.                                 COLOR 14, 4
  140.                                 PRINT MID$(a1$, seed%, LEN(find$));
  141.                             END IF
  142.                             seed% = seed% + LEN(find$)
  143.                         WEND
  144.                 END SELECT
  145.         END SELECT
  146.     NEXT
  147.  
  148.  
  149. SUB popup (msg$, msg%, button$(), button%, button_index%, text$)
  150.     DIM scrb AS my_scrb
  151.     STATIC doctype%
  152.     REDIM button$(8)
  153.     button$(1) = "Yes": button$(2) = "No!"
  154.     button$(3) = "Retry": button$(4) = "Cancel"
  155.     button$(5) = "Whole Word": button$(6) = "Whole/Case": button$(7) = "Any Part": button$(8) = "Any/Case"
  156.     iyy% = CSRLIN: ixx% = POS(0)
  157.     IF W3% = 0 THEN W3% = 5 ' Min.
  158.     IF W4% = 0 THEN W4% = LEN(msg$) + 4 ' Min
  159.  
  160.     IF W1% = 0 THEN
  161.         ' Auto-Center
  162.         W1% = _HEIGHT \ 2 - W3% \ 2 + .5
  163.         W2% = _WIDTH \ 2 - W4% \ 2 + .5
  164.     END IF
  165.  
  166.     SELECT CASE SMODE
  167.         CASE 0
  168.             oldsmode = SMODE: PCOPY 0, 1: SCREEN 0, 0, 1, 1: SMODE = 1
  169.         CASE 1
  170.             oldsmode = SMODE: PCOPY 1, 2: SCREEN 0, 0, 2, 2: SMODE = 2
  171.     END SELECT
  172.  
  173.     LOCATE W1%, W2%, 0 ' Cursor hide
  174.     FOR I = 1 TO W3%
  175.         A$ = ""
  176.         COLOR 15, 1
  177.         LOCATE , W2%
  178.         A$ = A$ + SPACE$(W4% - LEN(A$))
  179.         PRINT A$;
  180.         IF I <> 1 THEN
  181.             COLOR 1, 0: PRINT CHR$(176)
  182.         ELSE PRINT
  183.         END IF
  184.     NEXT I
  185.     LOCATE , W2% + 1
  186.     COLOR 1, 0: PRINT STRING$(W4%, CHR$(176));
  187.     COLOR 14, 1
  188.     LOCATE W1%, W2%
  189.     PRINT CHR$(218); STRING$(W4% - 2, CHR$(196)); CHR$(191);
  190.     LOCATE W1% + W3% - 1, W2%
  191.     PRINT CHR$(192); STRING$(W4% - 2, CHR$(196)); CHR$(217);
  192.     FOR I = 1 TO W3% - 2
  193.         LOCATE W1% + I, W2%: PRINT CHR$(179);: LOCATE W1% + I, W2% + W4% - 1: PRINT CHR$(179);
  194.     NEXT I
  195.     LOCATE W1%, W2% + W4% - 2: COLOR 15, 1: PRINT "x";
  196.  
  197.     IF LEN(msg$) THEN
  198.         SELECT CASE msg%
  199.             CASE -1
  200.                 LOCATE W1% + 1, W2% + W4% \ 2 - LEN(msg$) \ 2
  201.                 PRINT msg$;
  202.             CASE 0
  203.                 COLOR 15, 1
  204.                 IF button% THEN
  205.                     LOCATE W1% + W3% \ 2 - 1, W2% + W4% \ 2 - LEN(msg$) \ 2
  206.                     PRINT msg$;
  207.                     j% = 0
  208.                     FOR i% = 1 TO button%
  209.                         j% = j% + LEN(button$(button_index% + i%)) + 2
  210.                     NEXT
  211.                     LOCATE W1% + W3% \ 2 + 1, W2% + W4% \ 2 - j% \ 2 - 1
  212.                     COLOR 0, 7
  213.                     mouselocator$ = STRING$(_WIDTH, "0"): mouselocator% = W1% + W3% \ 2 + 1
  214.                     k% = 0
  215.                     FOR i% = button_index% + 1 TO button_index% + button%
  216.                         IF k% THEN LOCATE , POS(0) + 2
  217.                         k% = k% + 1
  218.                         MID$(mouselocator$, POS(0)) = STRING$(LEN(button$(i%)) + 2, LTRIM$(STR$(k%)))
  219.                         PRINT SPACE$(LEN(button$(i%)) + 2);
  220.                     NEXT
  221.                     LOCATE W1% + W3% \ 2 + 1, W2% + W4% \ 2 - j% \ 2
  222.                     COLOR 0, 7
  223.                     k% = 0
  224.                     FOR i% = button_index% + 1 TO button_index% + button%
  225.                         IF k% THEN LOCATE , POS(0) + 4
  226.                         PRINT button$(i%);
  227.                         k% = k% + 1
  228.                     NEXT
  229.  
  230.                     LOCATE 11, 18
  231.                     COLOR 8, 1: PRINT CHR$(222);
  232.                     COLOR c2%, c1%: PRINT SPACE$(48);
  233.                     passrightmargin% = POS(0) - 1: LOCATE 11, 19
  234.  
  235.  
  236.  
  237.  
  238.                     tabx% = 0: action$ = ""
  239.                     DO
  240.                         IF pete = 0 THEN
  241.                             IF xx1 THEN IF my% = 11 THEN LOCATE 11, xx1, 1 ELSE LOCATE 11, xx1, 0
  242.                             CALL textinput(text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb, noe, row, scr, config%, b$)
  243.                             xx1 = POS(0)
  244.                         ELSE
  245.                             CALL user(b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  246.                         END IF
  247.                         IF LEN(b$) THEN
  248.                             SELECT CASE b$
  249.                                 CASE CHR$(13)
  250.                                     IF pete = 0 THEN
  251.                                         SELECT CASE tabx%
  252.                                             CASE 1
  253.                                                 IF button_index% = 0 THEN action$ = "yes"
  254.                                                 IF button_index% = 2 THEN action$ = "retry"
  255.                                                 IF button_index% = 4 THEN action$ = "Whole Word" ' F3 Find option.
  256.                                             CASE 2
  257.                                                 IF button_index% = 0 THEN action$ = "no"
  258.                                                 IF button_index% = 2 THEN action$ = "abort"
  259.                                                 IF button_index% = 4 THEN action$ = "Whole/Case" ' F3 Find option.
  260.                                                 ' Find Function only.
  261.                                             CASE 0, 3
  262.                                                 IF button_index% = 4 THEN action$ = "Any Part" ' F3 Find option.
  263.                                             CASE 4
  264.                                                 IF button_index% = 4 THEN action$ = "Any/Case" ' F3 Find option.
  265.                                         END SELECT
  266.                                     ELSE
  267.                                         SELECT CASE tabx%
  268.                                             CASE 1
  269.                                                 IF button_index% = 0 THEN action$ = "yes"
  270.                                                 IF button_index% = 2 THEN action$ = "retry"
  271.                                             CASE 2
  272.                                                 IF button_index% = 0 THEN action$ = "no"
  273.                                                 IF button_index% = 2 THEN action$ = "abort"
  274.                                         END SELECT
  275.                                     END IF
  276.                                 CASE CHR$(27)
  277.                                     action$ = "close"
  278.                             END SELECT
  279.                         END IF
  280.  
  281.                         IF my% = W1% AND mx% = W2% + W4% - 2 THEN
  282.                             IF closex% = 0 THEN closex% = -1: LOCATE my%, mx%: COLOR 15, 4: PRINT "x";
  283.                         ELSE
  284.                             IF closex% THEN closex% = 0: LOCATE W1%, W2% + W4% - 2: COLOR 7, 1: PRINT "x";
  285.                         END IF
  286.  
  287.                         IF bhl% THEN IF bhl% = 1 AND my% <> mouselocator% OR bhl% = 1 AND MID$(mouselocator$, mx%, 1) = "0" THEN tabx% = 0: bhl% = 0
  288.                         IF b$ = CHR$(9) THEN tabx% = tabx% + 1: IF tabx% > button% THEN tabx% = 1
  289.                         IF oldmx% = mx% AND oldmy% = my% THEN i% = 0 ELSE i% = -1
  290.                         IF b$ = CHR$(9) OR my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" AND i% THEN
  291.                             IF b$ = CHR$(9) THEN k% = tabx%: bhl% = 9 ELSE k% = VAL(MID$(mouselocator$, mx%, 1)): tabx% = k%: bhl% = 1
  292.  
  293.                             IF h% AND h% <> tabx% THEN
  294.                                 COLOR 0, 7
  295.                                 LOCATE W1% + W3% \ 2 + 1, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  296.                                 PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  297.                             END IF
  298.  
  299.                             h% = k%: tabx% = h%
  300.  
  301.                             COLOR 0, 3
  302.                             LOCATE W1% + W3% \ 2 + 1, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  303.                             PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  304.                             _DELAY .15
  305.                         ELSE
  306.                             IF h% AND tabx% = 0 THEN
  307.                                 COLOR 0, 7
  308.                                 LOCATE W1% + W3% \ 2 + 1, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  309.                                 PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  310.                                 h% = 0: tabx% = 0
  311.                             END IF
  312.                         END IF
  313.  
  314.                         IF mb.l THEN
  315.                             IF closex% THEN SOUND 1000, .1: closex% = 0: action$ = "close"
  316.                             IF my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" THEN
  317.                                 SOUND 1000, .1
  318.                                 SELECT CASE VAL(MID$(mouselocator$, mx%, 1))
  319.                                     CASE 1
  320.                                         IF button_index% = 0 THEN action$ = "yes"
  321.                                         IF button_index% = 2 THEN action$ = "retry"
  322.                                         IF button_index% = 4 THEN action$ = "Whole Word" ' F3 Find option.
  323.                                     CASE 2
  324.                                         IF button_index% = 0 THEN action$ = "no"
  325.                                         IF button_index% = 2 THEN action$ = "abort"
  326.                                         IF button_index% = 4 THEN action$ = "Whole/Case" ' F3 Find option.
  327.                                         ' Find Function only.
  328.                                     CASE 3
  329.                                         IF button_index% = 4 THEN action$ = "Any Part" ' F3 Find option.
  330.                                     CASE 4
  331.                                         IF button_index% = 4 THEN action$ = "Any/Case" ' F3 Find option.
  332.                                 END SELECT
  333.                             END IF
  334.                         END IF
  335.  
  336.                         IF b$ = CHR$(9) THEN b$ = ""
  337.                         oldmy% = my%: oldmx% = mx%
  338.                     LOOP UNTIL LEN(action$)
  339.                     SMODE = oldsmode: SCREEN 0, 0, SMODE, SMODE
  340.                 ELSE
  341.                     LOCATE W1% + W3% \ 2, W2% + W4% \ 2 - LEN(msg$) \ 2
  342.                     PRINT msg$;
  343.                 END IF
  344.  
  345.         END SELECT
  346.     END IF
  347.     LOCATE iyy%, ixx%
  348.  
  349. SUB user (b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  350.  
  351.     '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  352.  
  353.     DEF SEG = 0
  354.     IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN shift% = -1 ELSE shift% = 0
  355.     IF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN ctrl% = -1 ELSE ctrl% = 0
  356.     IF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN ctrlshift% = -1 ELSE ctrlshift% = 0
  357.  
  358.     IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  359.         alt% = -1: con_panel% = -1
  360.     ELSE
  361.         IF alt% THEN alt% = 0: con_panel% = 1
  362.     END IF
  363.     DEF SEG
  364.  
  365.     b$ = INKEY$
  366.  
  367.     mb.w = 0
  368.         mb.w = mb.w + _MOUSEWHEEL
  369.     WEND
  370.  
  371.     mb.l% = _MOUSEBUTTON(1)
  372.     mb.r% = _MOUSEBUTTON(2)
  373.     mx% = _MOUSEX
  374.     my% = _MOUSEY
  375.  
  376. SUB textinput (text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb AS my_scrb, noe AS INTEGER, row, scr, config%, b$)
  377.     STATIC initiate%
  378.     STATIC hscrollon%, hscroll%, textfg%, textbk%, highlightfg%, highlightbk%, leftmargin%, rightmargin%, noleadingspace%, textmaxlength%, linecharacter%, click_l%, drag%, shiftclick%, tabx%
  379.     STATIC starthighlight%, highlight%, overwrite%, CurAdvance%
  380.     STATIC xx1
  381.     '''vartable% = 2: CALL setvariables(scrb, c1%, c2%, c1alt%, h1%, h2%, row, ins%, dwidth, dwidth2, menubar%)
  382.  
  383.     row = 1: tabx% = 2: thumb% = 0
  384.  
  385.     DO
  386.         IF NOT initiate% THEN ' Initiate textinput variables.
  387.             initiate% = -1
  388.             GOSUB initiate_variables
  389.         END IF
  390.  
  391.         ' --------------------POLL MOUSE--->
  392.         mb.w = 0
  393.         WHILE _MOUSEINPUT
  394.             mb.w = mb.w + _MOUSEWHEEL
  395.         WEND
  396.  
  397.         IF mb.w = 0 THEN
  398.             mx% = _MOUSEX ' Mouse column.
  399.             my% = _MOUSEY ' Mouse row.
  400.             mb.l = _MOUSEBUTTON(1)
  401.             mb.r = _MOUSEBUTTON(2)
  402.             mb.m = _MOUSEBUTTON(3)
  403.         END IF
  404.         '<----------------------------------
  405.  
  406.         IF noleadingspace% THEN ' Remove leading spaces of any text entry in form.
  407.             IF LEFT$(text$, 1) = " " THEN
  408.                 DO UNTIL LEFT$(text$, 1) <> " " OR text$ = ""
  409.                     text$ = MID$(text$, 2)
  410.                     LOCATE , leftmargin%
  411.                     GOSUB wash
  412.                 LOOP
  413.             END IF
  414.         END IF
  415.  
  416.         '-------------------------------------------------------------------------
  417.         mykey% = _KEYHIT
  418.  
  419.         '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  420.  
  421.         IF mykey% = 0 THEN
  422.             IF my% <> oldmy% OR mx% <> oldmx% OR mb.l OR mb.w THEN
  423.                 GOSUB mouseroutine
  424.                 IF LEN(action$) THEN EXIT DO
  425.             END IF
  426.         END IF
  427.  
  428.         ''''''IF mykey% = 0 THEN GOSUB file_display_keys
  429.  
  430.         IF mykey% > 0 THEN
  431.             GOSUB form_input_keyroutine
  432.             IF LEN(action$) THEN EXIT DO
  433.         END IF
  434.         '-------------------------------------------------------------------------
  435.         oldmy% = my%: oldmx% = mx%
  436.         IF pete = 0 THEN EXIT DO
  437.     LOOP
  438.     EXIT SUB
  439.  
  440.     '---------------------------GOSUB STATEMENTS-----------------------------
  441.     initiate_variables:
  442.     PageWidth1% = 80
  443.     PageWidth2% = 25
  444.     Topmargin% = 3
  445.     BottomMargin% = PageWidth2% - UpFromBottom%
  446.     UpFromBottom% = 2
  447.     BlockSize% = 0: REM -1 = variable.
  448.     Headers% = 0: REM On -1 or Off 0
  449.     TabElements% = 1: REM Number of input fields horizontally arranged. - 1 indicates variable.
  450.     ColorPrompt% = 0: REM 0 = COLOR 7, 0. Set all foreground/background by background * 16 + background.
  451.     ColorResponse% = 0: REM 0 will use textfg% and textbk% as defaults; otherwise set all foreground/background by background * 16 + background.
  452.     RestrictInput% = -1: REM On -1 or Off 0. (Uses 3 data fields)
  453.     InputFieldLength% = 0: REM Set to a number to allow variable length fields; otherwise filed input length will be determined by rightmargin% - (leftmargin% - 1).
  454.     PromptColumn% = 1: REM Column where prompt starts. Use 0 if no prompts. Use -1 for  multiple prompts on same row.
  455.     ResponseColumn% = 0: REM Set to a number if using Spacer%; otherwise 0 = input field follows response.
  456.  
  457.     TableStyle% = 0: REM 0 = Prompt/Space/Input, 1 = Prompt/Colon+Space/Response, 2 = Prompt/Spacers/Response
  458.     Spacer$ = ".": REM Type of spacer character if spacers are used (Table Style 2).
  459.  
  460.     textfg% = 7
  461.     textbk% = 0
  462.     highlightfg% = 0
  463.     highlightbk% = 7
  464.     leftmargin% = POS(0): iyy% = CSRLIN
  465.     rightmargin% = passrightmargin%
  466.     textmaxlength% = 250
  467.     noleadingspace% = -1
  468.     linecharacter% = 255: REM Blank space
  469.  
  470.     IF textmaxlength% > rightmargin% - (leftmargin% - 1) THEN hscrollon% = -1
  471.     IF rightmargin% < leftmargin% THEN CLS: PRINT "Rightmargin% cannot be smaller than leftmargin%. Redo.": END
  472.     IF leftmargin% < 1 OR leftmargin% > 80 THEN CLS: PRINT "Leftmargin% is not within 1 - 80 range. Redo.": END
  473.     REM no longer valid with hscroll.IF textmaxlength% > rightmargin% - leftmargin% + 1 THEN CLS: PRINT "textmaxlength% cannot exceed rightmargin% - leftmargin% + 1. Redo.:end"
  474.     IF LEN(text$) > textmaxlength% THEN CLS: PRINT "Text length cannot start out larger than textmaxlength%. Redo.": END
  475.  
  476.     IF rightmargin% = leftmargin% AND textmaxlength% = 1 THEN
  477.         CurAdvance% = 0
  478.     ELSE
  479.         CurAdvance% = 1
  480.     END IF
  481.  
  482.     COLOR textfg%, textbk%
  483.     LOCATE iyy%, leftmargin%, 1, 7, 7
  484.     RETURN '-----------------------------------------------------------------
  485.  
  486.     form_input_keyroutine:
  487.     DO ' Falk loop.
  488.         IF SMODE = 3 THEN ' Doctype dropdown is open.
  489.             SELECT CASE mykey%
  490.                 CASE 9, 27 ' Close doctype dropdown.
  491.                     GOSUB close_doctype_dropdown
  492.                 CASE 18432 ' Arrow up.
  493.                     IF CSRLIN = W1% + 17 THEN
  494.                         LOCATE W1% + 17, W2% + 15
  495.                         COLOR 7, 0: PRINT doctype$(2);
  496.                         LOCATE W1% + 16, W2% + 15
  497.                         COLOR 1, 3: PRINT doctype$(1);
  498.                     END IF
  499.                 CASE 20480 ' Arrow Down
  500.                     IF CSRLIN = W1% + 16 THEN
  501.                         LOCATE W1% + 16, W2% + 15
  502.                         COLOR 7, 0: PRINT doctype$(1);
  503.                         LOCATE W1% + 17, W2% + 15
  504.                         COLOR 1, 3: PRINT doctype$(2);
  505.                     END IF
  506.                 CASE 13 ' Enter
  507.                     IF pete = 0 THEN END: BEEP: b$ = CHR$(13): EXIT DO
  508.                     IF CSRLIN = W1% + 16 THEN i% = 1 ELSE i% = 2
  509.                     GOSUB close_doctype_dropdown
  510.                     GOSUB doctype_selected ' (Gosub parameter i%)
  511.             END SELECT
  512.             mykey% = 0
  513.             EXIT DO ' To REturn
  514.         END IF
  515.  
  516.         ' Process text if cursor is on form field text input line.
  517.         IF pete = 0 OR CSRLIN = W1% + W3% - 4 - 3 OR mykey% = 27 OR mykey% = 13 OR mykey% = 9 THEN ELSE EXIT DO
  518.  
  519.         IF _KEYDOWN(100303) = -1 OR _KEYDOWN(100304) = -1 THEN
  520.             SELECT CASE mykey%
  521.                 CASE 18176, 20224, 19200, 19712, 21248, 20992
  522.                     shift% = -1
  523.             END SELECT
  524.         ELSE
  525.             IF NOT drag% AND shift% THEN shift% = 0
  526.         END IF
  527.  
  528.         IF _KEYDOWN(100305) = -1 OR _KEYDOWN(100306) = -1 THEN
  529.             SELECT CASE mykey%
  530.                 CASE 86, 118
  531.                     control% = -2
  532.                 CASE ELSE
  533.                     control% = -1
  534.             END SELECT
  535.         ELSE
  536.             control% = 0
  537.         END IF
  538.  
  539.         REM Evaluate changes to highlighted text, excluding cut/copy/paste
  540.         IF highlight% AND shift% = 0 AND control% <> -1 AND mykey% <> 8 AND mykey% < 21248 THEN
  541.             IF mykey% > 31 AND mykey% < 256 THEN
  542.                 GOSUB cutcopy
  543.             ELSE
  544.                 GOSUB wash
  545.             END IF
  546.         END IF
  547.  
  548.         IF shift% = -1 AND control% = 0 THEN
  549.             SELECT CASE mykey%
  550.                 CASE 19200
  551.                     GOSUB HighlightLeft
  552.  
  553.                 CASE 19712
  554.                     IF control% THEN
  555.                         GOSUB ctrlrt
  556.                     ELSE
  557.                         GOSUB HighlightRight
  558.                     END IF
  559.  
  560.                 CASE 18176
  561.                     GOSUB SelectToHome
  562.  
  563.                 CASE 20224
  564.                     GOSUB SelectToEnd
  565.  
  566.                 CASE 21248
  567.                     mykey% = 88: REM Convert Delete to Cut
  568.                     GOSUB cutcopy
  569.  
  570.                 CASE 20992
  571.                     GOSUB PasteClipboard
  572.             END SELECT
  573.  
  574.         ELSE
  575.  
  576.             SELECT CASE control%
  577.                 CASE 0
  578.                     SELECT CASE mykey%
  579.                         CASE 18176
  580.                             IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  581.  
  582.                         CASE 20224
  583.                             IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  584.  
  585.                         CASE 8, 21248: REM Backspace and Delete
  586.                             GOSUB BackspaceDelete
  587.  
  588.                         CASE 9: REM Tab
  589.                             IF pete = 0 THEN b$ = CHR$(9): BEEP: EXIT DO ELSE GOSUB tabkey: mykey% = 0
  590.  
  591.                         CASE 13
  592.                             IF pete = 0 THEN b$ = CHR$(13): EXIT DO
  593.                             DO ' Single falks do/loop.
  594.                                 FOR i% = 1 TO UBOUND(formbutton$)
  595.                                     IF formbuttonx%(i%) < 0 THEN
  596.                                         SELECT CASE i%
  597.                                             CASE 1
  598.                                                 formbuttonx%(1) = ABS(formbuttonx%(1))
  599.                                                 GOSUB popfiletypes
  600.                                                 EXIT DO
  601.                                             CASE 2
  602.                                                 SELECT CASE config%
  603.                                                     CASE 1
  604.                                                         action$ = "open file"
  605.                                                     CASE 2
  606.                                                         action$ = "save as"
  607.                                                 END SELECT
  608.                                                 '''myfile$ = text$
  609.                                                 EXIT DO
  610.                                             CASE 3
  611.                                                 action$ = "cancel"
  612.                                                 EXIT DO
  613.                                         END SELECT
  614.                                     END IF
  615.                                 NEXT
  616.  
  617.                                 SELECT CASE tabx%
  618.                                     CASE 1 ' File selected from display window.
  619.                                         IF hlf% THEN
  620.                                             GOSUB fileselected
  621.                                             IF action$ = "change dir" THEN tabx% = 0: EXIT DO
  622.                                             tabx% = 2
  623.                                         ELSE
  624.                                             BEEP
  625.                                         END IF
  626.                                     CASE 2 ' Save or Open selected file.
  627.                                         IF LEN(text$) THEN
  628.                                             SELECT CASE config%
  629.                                                 CASE 1
  630.                                                     action$ = "open file"
  631.                                                 CASE 2
  632.                                                     action$ = "save as"
  633.                                             END SELECT
  634.                                             tabx% = 2
  635.                                             '''myfile$ = text$
  636.                                             EXIT DO
  637.                                         ELSE
  638.                                             BEEP
  639.                                         END IF
  640.                                     CASE 3 ' Open doctype dropdown menu.
  641.                                         GOSUB popfiletypes
  642.                                     CASE 4 ' Save or Open selected file. Only occurs when tab selected then mouse goes on another button and then goes to a neutral position. In this case the variable is no longer negative and the loop above misses it.
  643.                                         SELECT CASE config%
  644.                                             CASE 1
  645.                                                 action$ = "open file"
  646.                                             CASE 2
  647.                                                 action$ = "save as"
  648.                                         END SELECT
  649.                                         tabx% = 2
  650.                                         EXIT DO
  651.                                     CASE 5 ' Cancel
  652.                                         action$ = "cancel": tabx% = 2
  653.                                         EXIT DO
  654.                                 END SELECT
  655.                                 EXIT DO
  656.                             LOOP
  657.                             IF LEN(action$) THEN EXIT DO ' To Return
  658.  
  659.                         CASE 19200
  660.                             GOSUB CursorLeft
  661.  
  662.                         CASE 19712
  663.                             GOSUB CursorRight
  664.  
  665.                         CASE 18432
  666.                             GOSUB CursorUp
  667.  
  668.                         CASE 20480
  669.                             GOSUB CursorDown
  670.  
  671.                         CASE 18688
  672.                             GOSUB PageUp
  673.  
  674.                         CASE 20736
  675.                             GOSUB PageDown
  676.  
  677.                         CASE 27
  678.                             IF pete = 0 THEN b$ = CHR$(27): EXIT DO
  679.                             GOSUB wash
  680.                             EXIT DO
  681.  
  682.                         CASE 20992: REM Insert
  683.                             GOSUB InsertOverwrite
  684.  
  685.                         CASE ELSE
  686.                             GOSUB DisplayText
  687.                             IF flagtext% = -1 THEN flagtext% = 0: mykey% = 0
  688.                     END SELECT
  689.  
  690.                     REM Control% = -1 or -2
  691.                 CASE -1, -2
  692.  
  693.                     SELECT CASE mykey%
  694.  
  695.                         CASE 65, 97 ' A a
  696.                             GOSUB SelectAll
  697.  
  698.                         CASE 67, 99, 88, 120 ' C c X x
  699.                             GOSUB cutcopy
  700.  
  701.                         CASE 86, 118 ' V v
  702.                             REM Paste
  703.                             GOSUB PasteClipboard
  704.  
  705.                         CASE 19712
  706.                             REM Cursor and arrow right
  707.                             GOSUB ctrlrt
  708.  
  709.                         CASE 19200
  710.                             REM Cursor and arrow left
  711.                             GOSUB ctrllt
  712.  
  713.                         CASE 18176
  714.                             GOSUB CursorHome ' Ctrl + Home
  715.  
  716.                         CASE 20224
  717.                             GOSUB CursorEnd ' Ctrl + End
  718.  
  719.                         CASE ELSE
  720.                             ' Do nothing.
  721.  
  722.                     END SELECT
  723.             END SELECT
  724.         END IF
  725.         EXIT DO
  726.     LOOP
  727.     RETURN '-----------------------------------------------------------------
  728.  
  729.     ' Key Actions.
  730.     tabkey:
  731.     tabx% = tabx% + 1
  732.     IF tabx% > 5 THEN tabx% = 1: GOSUB clearbuttons
  733.  
  734.     SELECT CASE tabx%
  735.         CASE 1
  736.             IF hlf% THEN j% = -999: GOSUB highlightfile
  737.             i% = 0: GOSUB displaybutton
  738.             LOCATE , , 0: row = 1: j% = 0: GOSUB highlightfile
  739.         CASE 2
  740.             IF hlf% THEN j% = -999: GOSUB highlightfile
  741.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1
  742.         CASE 3
  743.             i% = -1: GOSUB displaybutton
  744.         CASE 4
  745.             i% = -2: GOSUB displaybutton
  746.         CASE 5
  747.             i% = -3: GOSUB displaybutton
  748.     END SELECT
  749.     b$ = "": mykey% = 0: null$ = INKEY$: k% = _KEYHIT ' Clear keyboard buffers
  750.     RETURN '------------------------------------------------------------------
  751.  
  752.     CursorLeft:
  753.     IF POS(0) > leftmargin% THEN
  754.         LOCATE , POS(0) - CurAdvance%
  755.     ELSE
  756.         IF hscroll% THEN hscroll% = hscroll% - 1: GOSUB wash
  757.     END IF
  758.     RETURN '------------------------------------------------------------------
  759.  
  760.     CursorRight:
  761.     IF POS(0) < rightmargin% THEN
  762.         IF POS(0) + CurAdvance% <= leftmargin% - 1 + LEN(text$) + 1 THEN
  763.             IF POS(0) < rightmargin% THEN LOCATE , POS(0) + CurAdvance%
  764.         END IF
  765.     ELSE
  766.         IF hscrollon% THEN
  767.             IF hscroll% + rightmargin% - (leftmargin% - 1) <= LEN(text$) THEN
  768.                 hscroll% = hscroll% + 1
  769.                 GOSUB wash
  770.             END IF
  771.         END IF
  772.     END IF
  773.  
  774.     RETURN '------------------------------------------------------------------
  775.  
  776.     ctrllt:
  777.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  778.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  779.     IF INSTR(texttemp$, " ") <> 0 THEN
  780.         FOR ictrllt% = POS(0) - leftmargin% + 1 + hscroll% TO 1 STEP -1
  781.             IF exitctrl% AND MID$(text$, ictrllt% - 1, 1) = " " THEN EXIT FOR
  782.             IF MID$(text$, ictrllt%, 1) <> " " THEN exitctrl% = -1
  783.             IF shift% THEN GOSUB HighlightLeft ELSE GOSUB CursorLeft
  784.         NEXT
  785.         exitctrl% = 0
  786.     ELSE
  787.         IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  788.     END IF
  789.     RETURN '---------------------------------------------------------------------
  790.  
  791.     ctrlrt:
  792.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  793.     texttemp$ = MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  794.     IF INSTR(texttemp$, " ") <> 0 THEN
  795.         FOR ictrlrt% = POS(0) - leftmargin% + 1 + hscroll% TO LEN(text$)
  796.             IF MID$(text$, ictrlrt%, 1) <> " " THEN
  797.                 IF exitctrl% THEN EXIT FOR
  798.                 jctrlrt% = -1
  799.             END IF
  800.             IF MID$(text$, ictrlrt%, 1) = " " AND jctrlrt% THEN exitctrl% = -1
  801.             IF shift% THEN GOSUB HighlightRight ELSE GOSUB CursorRight
  802.         NEXT
  803.         exitctrl% = 0: ictrlrt% = 0: jctrlrt% = 0
  804.     ELSE
  805.         IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  806.     END IF
  807.     RETURN '---------------------------------------------------------------------
  808.  
  809.     CursorHome:
  810.     IF hscroll% <> 0 THEN hscroll% = 0: GOSUB wash
  811.     LOCATE , leftmargin%
  812.     RETURN '---------------------------------------------------------------------
  813.  
  814.     CursorEnd:
  815.     IF hscrollon% THEN
  816.         IF LEN(text$) > rightmargin% - (leftmargin% - 1) THEN
  817.             hscroll% = LEN(text$) - (rightmargin% - (leftmargin% - 1)) + 1: REM + 1 allows for adding to end of text.
  818.             GOSUB wash
  819.         END IF
  820.     END IF
  821.     IF LEN(text$) + leftmargin% - 1 >= rightmargin% THEN
  822.         LOCATE , rightmargin%
  823.     ELSE
  824.         LOCATE , leftmargin% - 1 + LEN(text$) + CurAdvance%
  825.     END IF
  826.     RETURN '---------------------------------------------------------------------
  827.  
  828.     CursorUp:
  829.     REM PRINT "Cursor Up"
  830.     RETURN
  831.  
  832.     CursorDown:
  833.     REM PRINT "Cursor Down"
  834.     IF formbuttonx%(1) < 0 OR tabx% = 3 THEN ' Opens the doctype dropdown menu.
  835.         formbuttonx%(1) = ABS(formbuttonx%(1))
  836.         GOSUB popfiletypes
  837.     END IF
  838.     RETURN '---------------------------------------------------------------------
  839.  
  840.     PageUp:
  841.     REM PRINT "Page Up"
  842.     RETURN
  843.  
  844.     PageDown:
  845.     REM PRINT "Page Down"
  846.     RETURN
  847.  
  848.     REM Highlighting -----------------------------------------------------------
  849.     HighlightLeft:
  850.     iyy% = CSRLIN: ixx% = POS(0)
  851.     IF POS(0) > leftmargin% OR hscroll% THEN
  852.  
  853.         IF highlight% AND POS(0) >= highlight% - hscroll% THEN ' Unhighlighting left to right.
  854.             ' Move back first and then calculate POS(0) - 1, below.
  855.             IF highlight% = starthighlight% THEN
  856.                 starthighlight% = 0: highlight% = 0
  857.             ELSE
  858.                 highlight% = POS(0) - 1 + hscroll% ' Diminishing.
  859.             END IF
  860.         ELSE ' Highlighting left to right.
  861.             ' Calculate first and then move back. POS(0).
  862.             IF highlight% = 0 THEN highlight% = POS(0) + hscroll%
  863.             starthighlight% = POS(0) + hscroll%
  864.         END IF
  865.  
  866.         IF POS(0) = leftmargin% AND hscroll% THEN hscroll% = hscroll% - 1 ' hscroll% is reduced after the calculations above.
  867.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  868.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  869.  
  870.         LOCATE iyy%, leftmargin%
  871.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  872.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  873.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  874.  
  875.         IF ixx% - leftmargin% > 0 THEN ixx% = ixx% - 1 ' No moving cursor back when it is at left amrgin and scrolling text back.
  876.         LOCATE iyy%, ixx%
  877.         COLOR textfg%, textbk%
  878.     END IF
  879.     RETURN '---------------------------------------------------------------------
  880.  
  881.     HighlightRight:
  882.     iyy% = CSRLIN: ixx% = POS(0)
  883.     IF hscroll% + ixx% + 1 - leftmargin% <= LEN(text$) THEN
  884.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  885.  
  886.         IF POS(0) >= starthighlight% - hscroll% THEN
  887.             IF starthighlight% = 0 THEN starthighlight% = POS(0) + 1 + hscroll%
  888.             highlight% = POS(0) + 1 + hscroll%
  889.         ELSE
  890.             IF starthighlight% = highlight% THEN
  891.                 starthighlight% = 0: highlight% = 0
  892.             ELSE
  893.                 starthighlight% = POS(0) + 2 + hscroll%
  894.             END IF
  895.         END IF
  896.  
  897.         IF POS(0) = rightmargin% AND LEN(text$) - hscroll% > rightmargin% - leftmargin% THEN hscroll% = hscroll% + 1
  898.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  899.  
  900.         LOCATE iyy%, leftmargin%
  901.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  902.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  903.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  904.         IF POS(0) = rightmargin% THEN PRINT SPACE$(1); ' Only used when highlighting past last character to include one blank space.
  905.         IF ixx% < rightmargin% THEN ixx% = ixx% + 1
  906.         LOCATE iyy%, ixx%
  907.         COLOR textfg%, textbk%
  908.     END IF
  909.     RETURN '---------------------------------------------------------------------
  910.  
  911.     ClickhighLight:
  912.     j% = 0
  913.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  914.     FOR i% = LEN(texttemp$) TO 1 STEP -1
  915.         IF MID$(texttemp$, i%, 1) = " " AND j% THEN EXIT FOR ELSE j% = -1
  916.     NEXT
  917.     jClickhighLight% = LEN(texttemp$) - i% - 1
  918.     invokestarthighlight% = POS(0) + hscroll% - (LEN(texttemp$) - i%) + 1
  919.     FOR iClickhighLight% = 1 TO jClickhighLight%
  920.         IF POS(0) = leftmargin% THEN EXIT FOR
  921.         GOSUB CursorLeft
  922.     NEXT
  923.     shift% = -1
  924.     GOSUB ctrlrt
  925.     shift% = 0
  926.     invokestarthighlight% = 0: iClickhighLight% = 0: jClickhighLight% = 0
  927.     RETURN '---------------------------------------------------------------------
  928.  
  929.     SelectAll:
  930.     highlight% = 0: starthighlight% = 0: REM These are not zeroed as a ctrl keys bypass remove highlighting
  931.     GOSUB CursorHome
  932.     GOSUB SelectToEnd
  933.     RETURN '---------------------------------------------------------------------
  934.  
  935.     SelectToEnd:
  936.     IF mspan% = 0 THEN mspan% = POS(0) - leftmargin% + 1 + LEN(text$)
  937.     FOR iSelectToEnd% = 1 TO mspan%
  938.         GOSUB HighlightRight
  939.     NEXT
  940.     mspan% = 0: iSelectToEnd% = 0
  941.     RETURN '---------------------------------------------------------------------
  942.  
  943.     SelectToHome:
  944.     IF mspan% = 0 THEN
  945.         IF POS(0) = rightmargin% THEN
  946.             mspan% = rightmargin% - (leftmargin% - 1) + hscroll%
  947.         ELSE
  948.             mspan% = POS(0) - leftmargin% + 1 + hscroll%
  949.         END IF
  950.     END IF
  951.  
  952.     FOR iSelectToHome% = 1 TO mspan%
  953.         GOSUB HighlightLeft
  954.     NEXT
  955.     mspan% = 0: iSelectToHome% = 0
  956.     RETURN '---------------------------------------------------------------------
  957.  
  958.     DisplayText:
  959.     DO ' Falk loop.
  960.         IF mykey% > 31 AND mykey% < 256 THEN
  961.             COLOR 7, 0: LOCATE , , 1
  962.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  963.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 2)
  964.             ELSE
  965.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 1)
  966.             END IF
  967.  
  968.             positioncursor% = POS(0)
  969.  
  970.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  971.  
  972.                 IF POS(0) - leftmargin% + hscroll% < textmaxlength% THEN
  973.                     text$ = MID$(text$, 1, POS(0) + (hscroll%) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 2)
  974.                 ELSE
  975.                     flagtext% = -1: EXIT DO 'To Return
  976.                 END IF
  977.  
  978.                 REM Evaluate Horizontal Scroll
  979.                 IF POS(0) = rightmargin% THEN
  980.                     hscroll% = hscroll% + 1
  981.                 END IF
  982.             ELSE
  983.                 IF LEN(text$) < textmaxlength% THEN
  984.                     text$ = MID$(text$, 1, POS(0) + hscroll% - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 1)
  985.                     flagtext% = 0
  986.                 ELSE
  987.                     flagtext% = -1
  988.                 END IF
  989.  
  990.                 IF flagtext% = -1 THEN EXIT DO ' To Return REM flagtext% is set to zero upon return and exit.
  991.  
  992.                 REM Evaluate Horizontal Scroll
  993.                 IF hscrollon% AND POS(0) = rightmargin% THEN
  994.                     hscroll% = hscroll% + 1
  995.                 END IF
  996.             END IF
  997.  
  998.             ' Print to form input line.
  999.             LOCATE , leftmargin%: PRINT STRING$(rightmargin% - (leftmargin% - 1), linecharacter%);
  1000.             LOCATE , leftmargin%: PRINT MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1));
  1001.  
  1002.             IF CurAdvance% = 1 AND positioncursor% - leftmargin% + 1 < rightmargin% - leftmargin% + 1 THEN
  1003.                 LOCATE , positioncursor% + CurAdvance%
  1004.             ELSE
  1005.                 LOCATE , positioncursor%
  1006.             END IF
  1007.         END IF
  1008.         EXIT DO
  1009.     LOOP
  1010.     RETURN '---------------------------------------------------------------------
  1011.  
  1012.     BackspaceDelete:
  1013.     IF highlight% THEN GOSUB cutcopy
  1014.     IF POS(0) > leftmargin% OR mykey% = 21248 OR hscroll% > 0 THEN
  1015.         IF POS(0) <= leftmargin% + LEN(text$) THEN
  1016.             IF mykey% = 8 THEN
  1017.                 IF POS(0) <= leftmargin% + 2 AND hscroll% > 0 THEN
  1018.                     REM Adjust for horizontal scroll
  1019.                     holdcursor% = POS(0)
  1020.                     LOCATE , leftmargin%
  1021.                     countcolumnsmoved% = hscroll%
  1022.                     jBackspaceDelete% = (rightmargin% - (leftmargin% - 1)) * .33
  1023.                     IF jBackspaceDelete% < 3 AND rightmargin% - (leftmargin% - 1) > 3 THEN jBackspaceDelete% = 3: REM Set minimum scroll back.
  1024.                     FOR iBackspaceDelete% = 1 TO jBackspaceDelete%
  1025.                         GOSUB CursorLeft
  1026.                     NEXT
  1027.                     LOCATE , holdcursor% + countcolumnsmoved% - hscroll% - 1
  1028.                     countcolumnsmoved% = 0: iBackspaceDelete% = 0: jBackspaceDelete% = 0
  1029.                 ELSE
  1030.                     LOCATE , POS(0) - 1
  1031.                 END IF
  1032.             END IF
  1033.             iyy% = CSRLIN: ixx% = POS(0)
  1034.             text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + MID$(text$, POS(0) - leftmargin% + hscroll% + 2)
  1035.             texttemp$ = MID$(text$, hscroll% + 1, rightmargin% - (leftmargin% - 1))
  1036.             LOCATE iyy%, leftmargin%: PRINT texttemp$ + STRING$((rightmargin% - (leftmargin% - 1)) - LEN(texttemp$), linecharacter%);
  1037.             LOCATE iyy%, ixx%
  1038.         END IF
  1039.     END IF
  1040.     RETURN '---------------------------------------------------------------------
  1041.  
  1042.     cutcopy:
  1043.     IF highlight% THEN
  1044.         IF mykey% = 99 OR mykey% = 120 THEN
  1045.             _CLIPBOARD$ = MID$(text$, starthighlight% - leftmargin%, highlight% - starthighlight% + 1)
  1046.         END IF
  1047.  
  1048.         IF mykey% = 88 OR mykey% = 120 OR mykey% = 8 OR mykey% = 21248 THEN ' ctrl + x (cut), delete, backspace.
  1049.             positioncursor% = starthighlight% - 1 - hscroll%
  1050.             texttemp$ = MID$(text$, 1, starthighlight% - leftmargin% - 1) + MID$(text$, highlight% - leftmargin% + 1)
  1051.             text$ = texttemp$
  1052.             hscroll% = hscroll% - ABS(highlight% - starthighlight%)
  1053.             IF hscroll% < 0 THEN hscroll% = 0
  1054.             LOCATE , positioncursor%
  1055.             GOSUB wash
  1056.         END IF
  1057.     END IF
  1058.     RETURN '---------------------------------------------------------------------
  1059.  
  1060.     PasteClipboard:
  1061.     IF LEN(text$) + LEN(_CLIPBOARD$) <= textmaxlength% THEN
  1062.         text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + _CLIPBOARD$ + MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  1063.         i% = LEN(_CLIPBOARD$) - (rightmargin% - POS(0))
  1064.         positioncursor% = POS(0) + LEN(_CLIPBOARD$) - 1 + CurAdvance%
  1065.         IF positioncursor% > rightmargin% THEN
  1066.             hscroll% = hscroll% + positioncursor% - rightmargin%
  1067.             positioncursor% = rightmargin%
  1068.         END IF
  1069.         LOCATE , positioncursor%
  1070.         GOSUB wash
  1071.     ELSE
  1072.         BEEP
  1073.     END IF
  1074.     RETURN '---------------------------------------------------------------------
  1075.  
  1076.     InsertOverwrite:
  1077.     IF overwrite% = 0 THEN
  1078.         overwrite% = -1
  1079.         LOCATE , , 1, 7, 30
  1080.     ELSE
  1081.         overwrite% = 0
  1082.         LOCATE , , 1, 7, 7
  1083.     END IF
  1084.     RETURN
  1085.     ' End Key Controls-------------------------------------------------------
  1086.  
  1087.     mouseroutine:
  1088.     DO ' Falk loop
  1089.         IF shiftclick% THEN
  1090.             IF shiftclick% > 0 THEN mykey% = 19712: shiftclick% = shiftclick% - 1 ELSE mykey% = 19200: shiftclick% = shiftclick% + 1
  1091.             EXIT DO ' To Return
  1092.         END IF
  1093.  
  1094.         IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN shift% = -1 ELSE shift% = 0
  1095.  
  1096.         IF my% > margin.t + page.h OR my% <= margin.t THEN
  1097.             IF my% > margin.t + page.h + 2 AND hlf% THEN ' Unhighlight file in display window.
  1098.                 j% = -999: GOSUB highlightfile ' hlf% is in statement above
  1099.                 tabx% = 2
  1100.                 LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' Move to text input field.
  1101.             END IF
  1102.  
  1103.             GOTO 102
  1104.             IF NOT drag% THEN
  1105.                 IF my% = W1% AND mx% = W2% + W4% - 2 THEN
  1106.                     IF closepop% = 0 THEN
  1107.                         LOCATE , , 0
  1108.                         IF hlf% THEN j% = -999: GOSUB highlightfile
  1109.                         IF oldsmode2 THEN ' doctype dropdown menu is open.
  1110.                         ELSE
  1111.                             GOSUB clearbuttons: tabx% = 2
  1112.                         END IF
  1113.                         LOCATE W1% + W3% - 4 - 3, W2% + 15
  1114.                         GOSUB wash
  1115.                         COLOR 15, 4
  1116.                         LOCATE W1%, W2% + W4% - 2
  1117.                         PRINT "x";
  1118.                         closepop% = -1
  1119.                         LOCATE W1% + W3% - 4 - 3, W2% + 15, 1
  1120.                         COLOR textfg%, textbk%
  1121.                     END IF
  1122.                 ELSE
  1123.                     IF closepop% THEN
  1124.                         iyy% = CSRLIN: ixx% = POS(0)
  1125.                         closepop% = 0
  1126.                         COLOR 15, 1
  1127.                         LOCATE W1%, W2% + W4% - 2, 0
  1128.                         PRINT "x";
  1129.                         LOCATE iyy%, ixx%, 1
  1130.                         COLOR textfg%, textbk%
  1131.                     END IF
  1132.                 END IF
  1133.  
  1134.                 SELECT CASE SMODE
  1135.                     CASE 3 ' doctypedropdown menu open.
  1136.                         FOR i% = 1 TO UBOUND(doctype$)
  1137.                             IF my% = doctypey%(i%) AND mx% >= ABS(doctypex%(i%)) AND mx% < ABS(doctypex%(i%)) + LEN(doctype$(i%)) THEN
  1138.                                 IF doctypex%(i%) > 0 THEN
  1139.                                     COLOR 0, 3: LOCATE doctypey%(i%), doctypex%(i%), 0
  1140.                                     PRINT doctype$(i%);
  1141.                                     doctypex%(i%) = -doctypex%(i%)
  1142.                                     COLOR textfg%, textbk%
  1143.                                 END IF
  1144.                             ELSE
  1145.                                 IF doctypex%(i%) < 0 THEN
  1146.                                     doctypex%(i%) = ABS(doctypex%(i%))
  1147.                                     iyy% = CSRLIN: ixx% = POS(0)
  1148.                                     COLOR 7, 0: LOCATE doctypey%(i%), doctypex%(i%), 0
  1149.                                     PRINT doctype$(i%);
  1150.                                     LOCATE iyy%, ixx%, 0
  1151.                                     COLOR textfg%, textbk%
  1152.                                 END IF
  1153.                             END IF
  1154.                         NEXT
  1155.                     CASE ELSE
  1156.                         j% = 0
  1157.                         FOR i% = 1 TO UBOUND(formbutton$)
  1158.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% < ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1159.                                 IF formbuttonx%(i%) > 0 THEN
  1160.                                     iyy% = CSRLIN: ixx% = POS(0)
  1161.                                     COLOR 0, 3: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1162.                                     PRINT formbutton$(i%);
  1163.                                     formbuttonx%(i%) = -formbuttonx%(i%)
  1164.                                     j% = -1
  1165.                                     IF iyy% = W1% + W3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1166.                                     COLOR textfg%, textbk%
  1167.                                 END IF
  1168.                             ELSE
  1169.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1170.                                 iyy% = CSRLIN: ixx% = POS(0)
  1171.                                 COLOR 1, 7: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1172.                                 PRINT formbutton$(i%);
  1173.                                 IF iyy% = W1% + W3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1174.                                 COLOR textfg%, textbk%
  1175.                             END IF
  1176.                             IF formbuttonx%(i%) < 0 THEN j% = -1 ' Used below to designate a button is highlighted.
  1177.                         NEXT
  1178.  
  1179.                         IF tabx% >= 3 AND tabx% <= 5 AND j% = 0 THEN
  1180.                             COLOR 0, 3: LOCATE formbuttony%(tabx% - 2), ABS(formbuttonx%(tabx% - 2)), 0
  1181.                             PRINT formbutton$(tabx% - 2);
  1182.                         END IF
  1183.                 END SELECT
  1184.             END IF
  1185.  
  1186.             102
  1187.             IF mb.l THEN
  1188.                 IF closepop% THEN action$ = "close": EXIT DO ' To Return
  1189.  
  1190.                 IF NOT drag% THEN
  1191.                     IF oldsmode2 THEN ' Doctype dropdown menu is open.
  1192.                         FOR i% = 1 TO UBOUND(doctype$)
  1193.                             IF doctypex%(i%) < 0 THEN
  1194.                                 GOSUB close_doctype_dropdown
  1195.                                 GOSUB doctype_selected
  1196.                                 doctypex%(i%) = ABS(doctypex%(i%))
  1197.                             END IF
  1198.                         NEXT
  1199.                     END IF
  1200.  
  1201.                     FOR i% = 1 TO UBOUND(formbutton$) ' Check control buttons.
  1202.                         IF formbuttonx%(i%) < 0 THEN
  1203.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% <= ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1204.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1205.                                 SOUND 1000, .1
  1206.                                 LOCATE , , 0
  1207.                                 SELECT CASE i%
  1208.                                     CASE 1 ' Open doctype dropdown menu.
  1209.                                         GOSUB popfiletypes
  1210.                                     CASE 2 ' Open button.
  1211.                                         SELECT CASE config%
  1212.                                             CASE 1
  1213.                                                 action$ = "open file"
  1214.                                             CASE 2
  1215.                                                 action$ = "save as"
  1216.                                         END SELECT
  1217.                                         '''myfile$ = text$
  1218.                                         EXIT DO ' To Return.
  1219.                                     CASE 3 ' Cancel button.
  1220.                                         action$ = "cancel": EXIT DO ' To Return.
  1221.                                 END SELECT
  1222.                             END IF
  1223.                         END IF
  1224.                     NEXT
  1225.                 END IF
  1226.  
  1227.                 IF mx% > leftmargin% + LEN(text$) THEN EXIT DO ' To Return
  1228.  
  1229.                 IF click_l% >= 0 THEN
  1230.                     click_l% = -1
  1231.                     IF highlight% AND NOT shift% THEN GOSUB wash
  1232.                 END IF
  1233.  
  1234.                 IF shift% THEN
  1235.                     SELECT CASE mx%
  1236.                         CASE IS > POS(0): mykey% = 19712: shiftclick% = mx% - POS(0) - 1
  1237.                         CASE IS = POS(0): mykey% = 0
  1238.                         CASE IS < POS(0): mykey% = 19200: shiftclick% = mx% - POS(0) + 1
  1239.                     END SELECT
  1240.                     IF mykey% THEN EXIT DO ' To Return
  1241.                 END IF
  1242.             ELSE
  1243.                 IF click_l% = -1 THEN click_l% = 1: drag% = 0
  1244.             END IF
  1245.  
  1246.             IF click_l% = -1 THEN
  1247.                 IF mx% = POS(0) THEN
  1248.                     drag% = -1
  1249.                 ELSE
  1250.                     IF my% = CSRLIN AND drag% = 0 THEN
  1251.                         LOCATE my%, mx% ' Click in input field.
  1252.                     END IF
  1253.                 END IF
  1254.             END IF
  1255.  
  1256.             IF drag% THEN
  1257.                 shift% = -1
  1258.                 SELECT CASE mx%
  1259.                     CASE IS > POS(0): mykey% = 19712: IF mx% > rightmargin% THEN _DELAY .05
  1260.                     CASE IS = POS(0): mykey% = 0
  1261.                     CASE IS < POS(0): mykey% = 19200: IF mx% < leftmargin% THEN _DELAY .05
  1262.                 END SELECT
  1263.             END IF
  1264.  
  1265.             EXIT DO ' To Return
  1266.  
  1267.         ELSE
  1268.  
  1269.             DO
  1270.                 IF SMODE = 3 THEN EXIT DO
  1271.                 IF my% > margin.t AND my% - margin.t <= page.h AND mx% > margin.l AND mx% < margin.l + page.w THEN
  1272.                     tabx% = 1: GOSUB clearbuttons
  1273.                     IF mb.l AND NOT lbdown% THEN
  1274.                         IF my% = CSRLIN THEN ' File Selected
  1275.                             lbdown% = -1
  1276.                             GOSUB fileselected
  1277.                             EXIT DO
  1278.                         END IF
  1279.                     ELSE
  1280.                         IF mb.l = 0 THEN lbdown% = 0
  1281.                     END IF
  1282.  
  1283.                     IF hlf% = 0 THEN
  1284.                         row = my% - margin.t: j% = 0: GOSUB highlightfile
  1285.                     ELSEIF oldmy% > my% AND my% - margin.t <= page.h AND row > 1 THEN
  1286.                         i% = my%: IF i% - margin.t > 0 THEN
  1287.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1288.                             DO UNTIL CSRLIN <= i%
  1289.                                 row = row - 1: j% = 0: GOSUB highlightfile
  1290.                             LOOP
  1291.                         END IF
  1292.                     ELSEIF oldmy% AND oldmy% < my% AND row < page.h THEN
  1293.                         i% = my%: IF i% - margin.t <= page.h THEN
  1294.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1295.                             DO UNTIL CSRLIN >= i%
  1296.                                 row = row + 1: j% = 0: GOSUB highlightfile
  1297.                             LOOP
  1298.                         END IF
  1299.                     END IF
  1300.                 END IF
  1301.  
  1302.                 ' ------------------------------------Mouse----------------------------------
  1303.  
  1304.                 IF locked% < 0 THEN ' Mouse effects on mouse lock. key press effects are determined at inkey$ input, as key variable cannot be evaluated here, due to b$ = "" manipulations in the keypress routine.
  1305.                     IF mb.l OR mb.r OR mb.m THEN locked% = 0
  1306.                 END IF
  1307.  
  1308.                 IF mb.w THEN ' Determine if wheel is being used to scroll highlighted or unhighlighted text.
  1309.                     GOSUB clearbuttons
  1310.                     tabx% = 1 ' Reset tab index when mouse wheel is engaged.
  1311.                     locked% = 2 ' 2 is lock scrollbar, no highlighting permitted.
  1312.                 END IF
  1313.  
  1314.                 IF mb.l AND locked% <> 1 OR mb.w AND locked% <> -1 THEN
  1315.                     tabx% = 1
  1316.                     IF mb.l THEN GOSUB clearbuttons
  1317.                     ' Scrollbar routine.
  1318.                     IF mx% >= scrb.l - 1 AND mx% <= scrb.l + 1 AND my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 THEN draglock% = -1
  1319.  
  1320.                     IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR mx% = scrb.l AND scrb.s <> 0 AND my% >= scrb.t AND my% <= scrb.b AND mb.w = 0 OR scrbardrag% <> 0 AND my% > scrb.t AND my% < scrb.b AND mb.w = 0 OR mb.w > 0 AND scrb.x + scrb.s < scrb.h OR mb.w < 0 AND scrb.x > 0 THEN ' Mouse on scrollbar, doing a bar cursor drag or using the scroll wheel.
  1321.                         locked% = 2 ' Locked on scrollbar
  1322.                         IF my% = scrb.t AND scrb.x > 0 OR my% = scrb.b AND scrb.x + scrb.s < scrb.h OR mb.w <> 0 AND scr + page.h < noe THEN ' Mouse on a scrollbar arrow.
  1323.                             IF my% = scrb.t AND mb.w = 0 OR mb.w < 0 THEN scrb.x = scrb.x - 1: h% = -1 ELSE scrb.x = scrb.x + 1: h% = -2 ' Top or bottom arrow.
  1324.                             IF mb.w = 0 THEN delay.on! = .15
  1325.                             j% = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1326.  
  1327.                             IF j% >= 0 THEN ' Condition exists unless j% is negative such as doc is blank and mouse wheel is rolled downward.
  1328.                                 scrb.i = j%
  1329.  
  1330.                                 scr = scrb.i
  1331.  
  1332.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr) ' Positions scrollbar box.
  1333.  
  1334.                                 GOSUB scrollscrn
  1335.                             END IF
  1336.  
  1337.                         ELSEIF my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 AND scrbardrag% = 0 THEN ' Mouse on scrollbar block.
  1338.                             scrbardrag% = -1: scrb.adjust = (my% - (scrb.t + 1)) - scrb.x
  1339.                         ELSEIF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% > scrb.t AND my% < scrb.b THEN ' Mouse on scrollbar between scrollbar arrow and cursor.
  1340.                             IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% - (scrb.t + 1) - scrb.adjust >= 0 AND my% - (scrb.t + 1) + scrb.s - scrb.adjust <= scrb.h AND scrbardrag% <> -1 OR scrbardrag% = 0 THEN
  1341.                                 IF scrbardrag% = 0 THEN ' No drag, so adjust for cursor length for a click inside the scrollbar above or below the current scrollbar cursor position.
  1342.                                     IF my% - (scrb.t + 1) > scrb.x THEN
  1343.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x - 1: h% = -1
  1344.                                     ELSE
  1345.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x + 1: h% = -2
  1346.                                     END IF
  1347.                                 END IF
  1348.                                 scrb.x = my% - (scrb.t + 1) - scrb.adjust
  1349.                                 scrb.i = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1350.  
  1351.                                 scr = scrb.i
  1352.  
  1353.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1354.  
  1355.                                 GOSUB scrollscrn
  1356.  
  1357.                             ELSE ' Scrollbar is at top or bottom and mouse cursor is moving vertically along the scrollbar cursor. This allows the variable to readjust.
  1358.                                 IF mx% = scrb.l THEN scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1359.                             END IF
  1360.                         END IF
  1361.                         ' =======================================================
  1362.  
  1363.                     END IF
  1364.  
  1365.                     IF delay.on! THEN ' Scrollbar delay.
  1366.                         _DELAY delay.on!
  1367.                         delay.on! = 0 ' Toggle off.
  1368.                     END IF
  1369.  
  1370.                 ELSE
  1371.                     scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1372.                     IF locked% = 2 AND mb.l = 0 THEN locked% = 0
  1373.                 END IF
  1374.                 EXIT DO
  1375.             LOOP
  1376.         END IF
  1377.         EXIT DO
  1378.     LOOP
  1379.     RETURN '---------------------------------------------------------------------
  1380.  
  1381.     file_display_keys:
  1382.     DO '
  1383.         IF CSRLIN >= margin.t AND CSRLIN <= margin.t + page.h AND mb.l = 0 OR autokey% THEN
  1384.             ' Key commands for form input line.
  1385.             IF autokey% = 0 THEN b$ = INKEY$ ELSE b$ = MID$(b$, 3): IF LEN(b$) = 2 THEN autokey% = 0
  1386.             IF LEN(b$) THEN
  1387.                 IF b$ = CHR$(9) THEN GOSUB tabkey: b$ = "": null$ = INKEY$: EXIT DO ' tabx% assignment.
  1388.                 SELECT CASE MID$(b$, 1, 2) ' File directory window keys.
  1389.                     CASE CHR$(0) + "H"
  1390.                         IF row > 1 THEN
  1391.                             row = row - 1
  1392.                             LOCATE margin.t + row, margin.l + 1
  1393.                             j% = 0: GOSUB highlightfile
  1394.                         ELSE
  1395.                             IF scr > 0 THEN
  1396.                                 scr = scr - 1
  1397.                                 GOSUB scrollscrn
  1398.                                 j% = 0: GOSUB highlightfile
  1399.                             END IF
  1400.                         END IF
  1401.                     CASE CHR$(0) + "P"
  1402.                         IF tabx% <> 3 THEN
  1403.                             IF row < page.h THEN
  1404.                                 row = row + 1
  1405.                                 j% = 0: GOSUB highlightfile
  1406.                                 LOCATE margin.t + row, margin.l + 1
  1407.                             ELSE
  1408.                                 IF scr + page.h < noe THEN
  1409.                                     scr = scr + 1
  1410.                                     GOSUB scrollscrn
  1411.                                     j% = 0: GOSUB highlightfile
  1412.                                 END IF
  1413.                             END IF
  1414.                         ELSE
  1415.                             ' Arrow down key is highlighted by tabx%. Now open the doctype dropdown menu.
  1416.                             GOSUB popfiletypes
  1417.                         END IF
  1418.                     CASE CHR$(0) + "I"
  1419.                         autokey% = -1
  1420.                         LOCATE , margin.l + 1
  1421.                         k% = page.h - 1 + row - 2
  1422.                         FOR j% = 0 TO k%
  1423.                             b$ = b$ + CHR$(0) + "H"
  1424.                         NEXT
  1425.                         FOR j% = 1 TO row - 1
  1426.                             b$ = b$ + CHR$(0) + "P"
  1427.                         NEXT
  1428.                     CASE CHR$(0) + "Q"
  1429.                         autokey% = -1
  1430.                         LOCATE , margin.l + 1
  1431.                         k% = (page.h - 1) + (page.h - row) - 1
  1432.                         FOR j% = 0 TO k%
  1433.                             b$ = b$ + CHR$(0) + "P"
  1434.                         NEXT
  1435.                         FOR j% = 1 TO page.h - row
  1436.                             b$ = b$ + CHR$(0) + "H"
  1437.                         NEXT
  1438.                     CASE CHR$(0) + "w" ' Ctrl + Home
  1439.                         row = 1
  1440.                         IF scr > 0 THEN
  1441.                             scr = 0
  1442.                             h% = 0: GOSUB scrollscrn
  1443.                         END IF
  1444.                         LOCATE margin.t + 1, margin.l + 1
  1445.                         j% = 0: GOSUB highlightfile
  1446.                     CASE CHR$(0) + "u" ' Ctrl + End
  1447.                         IF noe > page.h THEN
  1448.                             row = page.h
  1449.                             scr = noe - row
  1450.                             LOCATE margin.t + 1, margin.l + 1
  1451.                             h% = 0: GOSUB scrollscrn
  1452.                             row = page.h
  1453.                             LOCATE margin.t + row, margin.l + 1
  1454.                             j% = 0: GOSUB highlightfile
  1455.                         ELSE
  1456.                             row = noe
  1457.                             LOCATE margin.t + row, margin.l + 1
  1458.                             j% = 0: GOSUB highlightfile
  1459.                         END IF
  1460.                     CASE CHR$(13)
  1461.                         GOSUB fileselected
  1462.                 END SELECT
  1463.             END IF
  1464.         ELSE
  1465.             null$ = INKEY$ ' Clear buffer
  1466.         END IF
  1467.         EXIT DO
  1468.     LOOP
  1469.  
  1470.     RETURN '---------------------------------------------------------------------
  1471.  
  1472.     '-------------------------------Nested Gosubs-----------------------------
  1473.  
  1474.     scrollscrn:
  1475.     FOR i% = 1 TO page.h
  1476.         LOCATE margin.t + i%, margin.l + 1
  1477.         PRINT x$(i% + scr);
  1478.     NEXT
  1479.     LOCATE row + margin.t, margin.l + 1
  1480.     IF hlf% AND LEN(b$) < 3 AND scrbardrag% = 0 THEN j% = 0: GOSUB highlightfile
  1481.  
  1482.     '''h% = 1: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1483.  
  1484.     RETURN '---------------------------------------------------------------------
  1485.  
  1486.     highlightfile:
  1487.     IF j% = -999 THEN ' Unhighlight text only.
  1488.         COLOR 7, 0
  1489.         LOCATE margin.t + hlf%, margin.l + 1, 0
  1490.         PRINT x$(hlf% + scr);
  1491.         hlf% = 0
  1492.     ELSE
  1493.         IF hlf% THEN
  1494.             LOCATE margin.t + hlf%, margin.l + 1, 0
  1495.             COLOR 7, 0: PRINT x$(hlf% + scr);
  1496.         END IF
  1497.         COLOR 1, 3
  1498.         LOCATE margin.t + row, margin.l + 1, 0
  1499.         PRINT x$(row + scr);
  1500.         hlf% = row
  1501.         COLOR c1%, c2%
  1502.     END IF
  1503.     RETURN '---------------------------------------------------------------------
  1504.  
  1505.     wash:
  1506.     starthighlight% = 0
  1507.     highlight% = 0
  1508.     iyy% = CSRLIN: ixx% = POS(0)
  1509.     COLOR textfg%, textbk%
  1510.     LOCATE , leftmargin%
  1511.     texttemp$ = MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1))
  1512.     PRINT texttemp$ + STRING$(rightmargin% - (leftmargin% - 1) - LEN(texttemp$), linecharacter%);
  1513.     LOCATE iyy%, ixx%
  1514.     RETURN '---------------------------------------------------------------------
  1515.  
  1516.     clearbuttons:
  1517.     iyy% = CSRLIN: ixx% = POS(0)
  1518.     FOR k% = 1 TO UBOUND(formbutton$)
  1519.         LOCATE formbuttony%(k%), ABS(formbuttonx%(k%)), 0
  1520.         COLOR 1, 7: PRINT formbutton$(k%);
  1521.         formbuttonx%(k%) = ABS(formbuttonx%(k%)) ' Remove button active (neg) designation.
  1522.     NEXT
  1523.     LOCATE iyy%, ixx%
  1524.     RETURN '---------------------------------------------------------------------
  1525.  
  1526.     displaybutton: ' Gosub parameters (i%)
  1527.     iyy% = CSRLIN: ixx% = POS(0)
  1528.     GOSUB clearbuttons ' Clear all buttons of highlighting first...
  1529.     IF i% < 0 THEN COLOR 0, 3 ELSE COLOR 1, 7
  1530.     IF tabx% THEN COLOR 0, 3
  1531.     IF i% <> 0 THEN
  1532.         LOCATE formbuttony%(ABS(i%)), ABS(formbuttonx%(ABS(i%))), 0
  1533.         PRINT formbutton$(ABS(i%));
  1534.         formbuttonx%(ABS(i%)) = -ABS(formbuttonx%(ABS(i%)))
  1535.     END IF
  1536.     LOCATE iyy%, ixx%
  1537.     RETURN '---------------------------------------------------------------------
  1538.  
  1539.     fileselected:
  1540.     IF noe THEN
  1541.         IF hlf% THEN j% = -999: GOSUB highlightfile
  1542.  
  1543.         text$ = xfull$(row + scr)
  1544.  
  1545.         IF LEFT$(text$, 2) = ".." OR LEFT$(text$, 1) = "[" THEN
  1546.             ' Ready to change diretories.
  1547.             IF LEFT$(text$, 2) = ".." THEN
  1548.                 CHDIR ".."
  1549.             ELSE
  1550.                 CHDIR MID$(text$, 2, LEN(text$) - 2)
  1551.             END IF
  1552.             action$ = "change dir"
  1553.         ELSE
  1554.             ' Text input line.
  1555.             COLOR 7, 0
  1556.             LOCATE W1% + W3% - 4 - 3, W2% + 15: PRINT SPACE$(W4% - 18); ' Blank it.
  1557.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1: PRINT MID$(text$, 1, W4% - 18); ' Display it.
  1558.             hlf% = 0
  1559.         END IF
  1560.     ELSE ' No files found in DIR to select.
  1561.         BEEP
  1562.     END IF
  1563.     RETURN '---------------------------------------------------------------------
  1564.  
  1565.     popfiletypes:
  1566.     LOCATE W1% + W3% - 4 - 3, W2% + 15, 0
  1567.     GOSUB wash
  1568.     oldsmode2 = SMODE
  1569.     SMODE = 3: PCOPY oldsmode2, SMODE: SCREEN 0, 0, SMODE, SMODE
  1570.     COLOR 8, 0: LOCATE W1% + 16, W2% + 15 - 1: PRINT CHR$(179);
  1571.     COLOR 1, 3: PRINT SPACE$(W4% - 21);
  1572.     LOCATE W1% + 16, W2% + 15
  1573.     COLOR 1, 3: PRINT doctype$(1);
  1574.     COLOR 8, 0: LOCATE W1% + 16, W2% + W4% - 4: PRINT CHR$(179);
  1575.     LOCATE W1% + 17, W2% + 14
  1576.     COLOR 8, 0: PRINT CHR$(179);
  1577.     COLOR 7, 0: PRINT SPACE$(W4% - 18);
  1578.     LOCATE W1% + 17, W2% + 15: PRINT doctype$(2);
  1579.     COLOR 8, 0: LOCATE , W2% + W4% - 4: PRINT CHR$(179);
  1580.     COLOR 8, 0: LOCATE W1% + 18, W2% + 14: PRINT CHR$(192); STRING$(W4% - 19, 196); CHR$(217);
  1581.     doctypey%(1) = W1% + 16: doctypex%(1) = W2% + 15
  1582.     doctypey%(2) = W1% + 17: doctypex%(2) = W2% + 15
  1583.     LOCATE W1% + 16, W2% + 15 ' Text input line.
  1584.     RETURN '---------------------------------------------------------------------
  1585.  
  1586.     doctype_selected:
  1587.     SELECT CASE i%
  1588.         CASE 1
  1589.             COLOR 7, 0: LOCATE W1% + 16, W2% + 15: PRINT SPACE$(W4% - 19); ' Leaves arrow down space.
  1590.             LOCATE W1% + 16, W2% + 15: PRINT doctype$(1);
  1591.  
  1592.             IF doctype$ <> doctype$(1) THEN
  1593.                 '''doctype$ = doctype$(1): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  1594.             END IF
  1595.  
  1596.             doctype$ = doctype$(1)
  1597.             IF doctype% = 2 THEN SWAP doctype$(1), doctype$(2)
  1598.             doctype% = 1
  1599.  
  1600.             LOCATE W1% + 16, w2 + W4% + 4 ' .txt or *.* all files arrow down button location.
  1601.             formbuttony%(1) = CSRLIN: formbuttonx%(1) = POS(0): formbutton$(1) = CHR$(25)
  1602.  
  1603.             i% = 1: GOSUB displaybutton
  1604.  
  1605.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' File name input field.
  1606.             COLOR textfg%, textbk%
  1607.         CASE 2
  1608.             COLOR 7, 0: LOCATE W1% + 16, W2% + 15: PRINT SPACE$(W4% - 19); ' Leaves arrow down space.
  1609.             LOCATE W1% + 16, W2% + 15: PRINT doctype$(2);
  1610.  
  1611.             IF doctype$ <> doctype$(2) THEN
  1612.                 '''doctype$ = doctype$(2): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  1613.             END IF
  1614.  
  1615.             doctype$ = doctype$(2)
  1616.             IF doctype% = 1 THEN SWAP doctype$(1), doctype$(2)
  1617.             doctype% = 2
  1618.  
  1619.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' File name input field.
  1620.             COLOR textfg%, textbk%
  1621.     END SELECT
  1622.  
  1623.     RETURN '---------------------------------------------------------------------
  1624.  
  1625.     close_doctype_dropdown:
  1626.     ' Note - Do not use i% in this routine. It would change a perviouly set value i one of the routines that calls this one.
  1627.     SMODE = oldsmode2: SCREEN 0, 0, SMODE, SMODE: oldsmode2 = 0
  1628.     LOCATE , , 0
  1629.     LOCATE W1% + 16, W2% + W4% - 4
  1630.     IF tabx% = 3 THEN COLOR 0, 3 ELSE COLOR 1, 7
  1631.     IF my% = CSRLIN AND mx% = POS(0) THEN COLOR 0, 3: formbuttonx%(1) = -formbuttonx%(1)
  1632.     PRINT formbutton$(1);
  1633.     LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' File name input field.
  1634.     COLOR textfg%, textbk%
  1635.     REDIM doctypex%(UBOUND(doctype$)), doctypey%(UBOUND(doctype$))
  1636.     RETURN '---------------------------------------------------------------------
  1637.  

It works, but it needs to have that GOTOremoved. For now, it knits it together just fine. I need to fiddle with a couple of the variables. Once that's done, it could be implemented, but...

A step beyond would be "Find" as a wrap around function. You know, when what you are searching for wraps in the document to another line. My idea for that would be to always add an extra text line to the find loop. So if two words were typed, which existed on line 5 and line 6, the routine would check lines 1 and 2, together, lines 2 and 3, together, lines 4 and 5, together, and finally, lines 5 and six together, which would display the results. Hopefully, not too much work to implement, but for another day.

Pete
« Last Edit: January 27, 2021, 11:48:44 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #1 on: January 27, 2021, 11:52:14 pm »
Well I edited the above code to include a popup for the search. The input line is fully functional for typing, cut/copy/past, highlighting, lateral scrolling to 250 characters. The buttons can be tabbed and entered or left clicked. After a search is completed, it sleeps, and runs again after a key is pressed. Click the program window "x" to end it.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #2 on: January 28, 2021, 12:16:56 am »
Oh I like that version much better! a couple more lines than last isn't it?

It'd be nice if you had bigger demo text to test scrollers. Do you plan tabs for paragraphs and things like that or just WYSIWYG?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #3 on: January 28, 2021, 12:16:43 pm »
In response to larger, more readable text, I just add the _FONT routine. I don't bother with that for this beta stuff.

In regard to a practical use, yes, I intend to apply and expand these routines so it can function with scrollable text.

Something like this...

Code: QB64: [Select]
  1. REDIM x$(20)
  2. margin.t = 5
  3. margin.l = 5
  4. dwidth = 68
  5. page.h = 6
  6. row = 1
  7. noe = 13
  8.  
  9. find$ = "and"
  10.  
  11. x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  12. x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  13. x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  14. x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  15. x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  16. x$(6) = "" + CHR$(255) + CHR$(10)
  17. x$(7) = "Article I" + CHR$(10)
  18. x$(8) = "" + CHR$(255) + CHR$(10)
  19. x$(9) = "Section 1: Congress" + CHR$(10)
  20. x$(10) = "" + CHR$(255) + CHR$(10)
  21. x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  22. x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  23. x$(13) = "Representatives." + CHR$(10)
  24.  
  25. GOSUB displaydoc: GOSUB finder
  26.  
  27.     DO
  28.         _LIMIT 30
  29.         b$ = INKEY$
  30.         IF LEN(b$) THEN
  31.             SELECT CASE b$
  32.                 CASE CHR$(27)
  33.                     SYSTEM
  34.                 CASE CHR$(0) + "H"
  35.                     IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  36.                 CASE CHR$(0) + "P"
  37.                     IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  38.             END SELECT
  39.         END IF
  40.     LOOP
  41.  
  42. displaydoc:
  43. COLOR 0, 7
  44. FOR i% = 1 TO page.h
  45.     a1$ = SPACE$(dwidth)
  46.     MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  47.     LOCATE margin.t + i%, margin.l + 1
  48.     PRINT a1$
  49.  
  50. finder:
  51. FOR i% = 1 TO page.h
  52.     a1$ = SPACE$(dwidth)
  53.     MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  54.  
  55.     IF INSTR(LCASE$(a1$), find$) THEN
  56.         COLOR 14, 4: seed% = 0
  57.         DO UNTIL INSTR(seed%, LCASE$(a1$), find$) = 0
  58.             seed% = INSTR(seed%, LCASE$(a1$), find$)
  59.             LOCATE margin.t + i%, margin.l + seed%
  60.             PRINT MID$(a1$, INSTR(seed%, LCASE$(a1$), find$), LEN(find$));
  61.             seed% = seed% + LEN(find$)
  62.         LOOP
  63.     END IF
  64. COLOR 0, 7
  65.  

Press arrow up or down to scroll doc. The demo only shows instances of "and" and does not have the case and whole word functions, present in the other post. It's just to show how I want to apply the search feature.

What's next? Well a replace feature, at some point, but before that, I'd like to try out my idea, mentioned in the original post above, to find wrapped text, too.

Thanks for taking it out for a spin,

Pete
« Last Edit: January 28, 2021, 12:28:02 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #4 on: January 28, 2021, 05:56:48 pm »
Well I need to recharge. Anyway, let me know if anyone sees any flaws in my approach. This now will find a search string that wraps to the next line. Note, it can only handle a limited amount of typed text. Too much will break it, and I still have to figure out the limits per page width. That's for another time. For now, I'm just curious what other conditions are needed, and if it's buggy. Oh, use arrow up and down to scroll the limited amount of text, and the Tab key to rerun.

Pete

Code: QB64: [Select]
  1. REDIM x$(20)
  2. margin.t = 5
  3. margin.l = 5
  4. dwidth = 68
  5. page.h = 6
  6. row = 1
  7. noe = 13
  8.  
  9. x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  10. x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  11. x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  12. x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  13. x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  14. x$(6) = "" + CHR$(255) + CHR$(10)
  15. x$(7) = "Article I" + CHR$(10)
  16. x$(8) = "" + CHR$(255) + CHR$(10)
  17. x$(9) = "Section 1: Congress" + CHR$(10)
  18. x$(10) = "" + CHR$(255) + CHR$(10)
  19. x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  20. x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  21. x$(13) = "Representatives." + CHR$(10)
  22.  
  23. COLOR 0, 7
  24. GOSUB displaydoc
  25. COLOR 7, 0: LOCATE 2, 2: LINE INPUT "Find: ", find$
  26.  
  27. GOSUB displaydoc: GOSUB finder
  28.  
  29.     DO
  30.         _LIMIT 30
  31.         b$ = INKEY$
  32.         IF LEN(b$) THEN
  33.             SELECT CASE b$
  34.                 CASE CHR$(9)
  35.                     COLOR 7, 0: CLS: RUN
  36.                 CASE CHR$(27)
  37.                     SYSTEM
  38.                 CASE CHR$(0) + "H"
  39.                     IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  40.                 CASE CHR$(0) + "P"
  41.                     IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  42.             END SELECT
  43.         END IF
  44.     LOOP
  45.  
  46. displaydoc:
  47. COLOR 0, 7
  48. FOR i% = 1 TO page.h
  49.     a1$ = SPACE$(dwidth)
  50.     MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  51.     LOCATE margin.t + i%, margin.l + 1
  52.     PRINT a1$
  53.  
  54. finder:
  55. findorig$ = find$
  56.  
  57. FOR i% = 1 TO page.h
  58.     a1$ = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  59.  
  60.     IF INSTR(find$, " ") THEN
  61.         IF RIGHT$(a1$, 1) <> " " THEN a2$ = a1$ + " " ELSE a2$ = a1$
  62.     ELSE
  63.         a2$ = a1$ ' No space for a solid line wrap around.
  64.     END IF
  65.  
  66.     IF INSTR(findorig$, " ") THEN
  67.         a2$ = a2$ + MID$(x$(i% + 1 + scr), 1, INSTR(x$(i% + 1 + scr), CHR$(10)) - 1)
  68.         a2% = -1
  69.     ELSE
  70.         a2% = 0
  71.     END IF
  72.  
  73.     IF INSTR(LCASE$(a2$), find$) THEN
  74.         COLOR 14, 4: seed% = 0
  75.         DO UNTIL INSTR(seed%, LCASE$(a2$), find$) = 0
  76.  
  77.             IF a2% THEN
  78.                 j% = INSTR(seed%, LCASE$(a2$), find$)
  79.                 IF j% + LEN(find$) >= LEN(a1$) AND j% <= LEN(a1$) THEN
  80.                     seed% = INSTR(seed%, LCASE$(a2$), find$)
  81.                     k% = 0
  82.                     find$ = MID$(findorig$, 1, LEN(a1$) - seed% - k%)
  83.                     flag% = 1
  84.                 ELSE
  85.                     seed% = INSTR(seed%, LCASE$(a2$), find$)
  86.                 END IF
  87.             ELSE
  88.                 seed% = INSTR(seed%, LCASE$(a2$), find$)
  89.             END IF
  90.  
  91.             IF seed% <= LEN(a1$) THEN
  92.                 LOCATE margin.t + i%, margin.l + seed%
  93.                 PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  94.                 seed% = seed% + LEN(find$)
  95.  
  96.                 IF flag% THEN
  97.                     SELECT CASE flag%
  98.                         CASE 2
  99.                             flag% = 0: find$ = findorig$
  100.                         CASE 1
  101.                             flag% = 2
  102.                             find$ = MID$(findorig$, LEN(find$) + 2)
  103.                             seed% = 0
  104.                             EXIT DO
  105.                     END SELECT
  106.                 END IF
  107.             ELSE
  108.                 EXIT DO
  109.             END IF
  110.         LOOP
  111.     END IF
  112. COLOR 0, 7
  113. flag% = 0
  114.  

« Last Edit: January 28, 2021, 07:52:06 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #5 on: January 29, 2021, 01:58:53 am »
Hi Pete

I took a look at the code(s) here - looks like you've got your head around what you're doing. Though I want to echo what bplus was saying above - can we please see a demo of the code that is proportional to its mass? Something that shows as many features being used at once. I ask this because I care about your question - it's kinda hard to see how one idea (like highlighting) fits into the whole. Maybe this is for lack of research on my part.

As for the most recent snippet, it looks pretty cool as-is. Scrolls as advertised, etc etc. So that inspired me to put highlighting into qXed, and was happy with the result (a few pics below). Works like an absolute charm. The part that does the highlighting *might* be able to work in your code, or at least an adaptation of the method. I start with an array called LineAsMapped(), which is exactly like your x$() array.  Here is the whole function (ignore some it, look for the Highlight part. In here, Highlight is a global):

Code: QB64: [Select]
  1. SUB PrintMainText
  2.     ' _ECHO "PrintMainText"
  3.     DIM i AS INTEGER
  4.     DIM j AS INTEGER
  5.     DIM k AS INTEGER
  6.     DIM k0 AS INTEGER
  7.     DIM k00 AS INTEGER
  8.     DIM c AS STRING
  9.     DIM d AS STRING
  10.     FOR i = 1 TO VisibleLines
  11.         c = LineAsMapped(i)
  12.         IF (TextFormatting = 1) THEN
  13.             FOR j = 1 TO TextWidth - LEN(c)
  14.                 c = c + "_"
  15.             NEXT
  16.         END IF
  17.         d = MID$(c, HScroll, TextWidth)
  18.         IF (Highlight <> "") THEN
  19.             k = INSTR(d, Highlight)
  20.         END IF
  21.         IF (k > 0) THEN
  22.             k0 = 0
  23.             DO WHILE (k > 0)
  24.                 k00 = k0 + k - 1
  25.                 COLOR 7, 1
  26.                 _PRINTSTRING (k0 + LeftIndent + 1, TopIndent + i), LEFT$(d, k - 1)
  27.                 COLOR 10, 1
  28.                 _PRINTSTRING (k0 + k - 1 + LeftIndent + 1, TopIndent + i), MID$(d, k, LEN(Highlight))
  29.                 d = RIGHT$(d, LEN(d) - k - LEN(Highlight) + 1)
  30.                 k0 = k0 + k - 1 + LEN(Highlight)
  31.                 k = INSTR(d, Highlight)
  32.             LOOP
  33.             COLOR 7, 1: _PRINTSTRING (k00 + LEN(Highlight) + LeftIndent + 1, TopIndent + i), d
  34.         ELSE
  35.             COLOR 7, 1: _PRINTSTRING (LeftIndent + 1, TopIndent + i), d
  36.         END IF
  37.     NEXT
  38.     ' _ECHO ")"

That prints every character visible at a given time, with the highlighting at full force. It's an ugly function, but it's not too complicated - maybe you want to hold it next to what you've got now, and see if there's space for optimization, making the code smaller, etc.

Anyway, good luck!
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #6 on: January 29, 2021, 02:31:54 am »
Hi @STxAxTIC (Bill),

Here's the FIND demo I've been building up to. I think this part of the WP project is complete, and after I redo some of the routing and fiddle a bit with a temporary variable I made to glue two routines together, I should be ready to add it tom my WP project.

In regard to highlighting text, I have another thread I poted, around a month or so back, with that routine. So highlighting the doc, cut, copy, paste, etc. is already a completed part of the WP project; but I do have a "cut" bug I have to work on before I forget the code that went into it.

I'm going to get some shut eye for now, but I'll have a look at your method, tomorrow, and commit.

I made this final post LARGER with _FONT routine.

For this word search Demo...

Use arrows up or down to scroll the testing text.

Tab to rerun.

F3 to bring up the search window. (4 search options for whole or partial word and case or not case sensitive).

Tab to buttons and Enter or just left click any button.

It can find multi-word search text, which appears wrapped from one line to the next in the doc.

The highlighted text will remain highlighted while scrolling up and down.

Code: QB64: [Select]
  1. enl% = 13: CALL windowscreen(enl%)
  2.  
  3.  
  4.     DIM SHARED mx%, my%, margin.t AS INTEGER, margin.l AS INTEGER
  5.     DIM SHARED action$
  6.     DIM SHARED mb AS my_mb
  7.     DIM scrb AS my_scrb
  8.  
  9.     TYPE my_mb
  10.         l AS INTEGER
  11.         r AS INTEGER
  12.         m AS INTEGER
  13.         w AS INTEGER
  14.         drag AS INTEGER
  15.         dragon AS INTEGER
  16.     END TYPE
  17.  
  18.     TYPE my_scrb
  19.         t AS INTEGER
  20.         b AS INTEGER
  21.         l AS INTEGER
  22.         x AS INTEGER
  23.         i AS INTEGER
  24.         d AS INTEGER
  25.         h AS INTEGER
  26.         s AS INTEGER
  27.         opt AS INTEGER
  28.         adjust AS INTEGER
  29.     END TYPE
  30.  
  31.     DIM SHARED SMODE, passrightmargin%
  32.     REDIM SHARED formbuttony%(3), formbuttonx%(3), formbutton$(3)
  33.     REDIM button$(8)
  34.     COLOR 0, 7: CLS
  35.  
  36.     REDIM x$(20)
  37.     margin.t = 2
  38.     margin.l = 5
  39.     dwidth = 68
  40.     page.h = 6
  41.     row = 1
  42.     noe = 13
  43.  
  44.     x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  45.     x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  46.     x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  47.     x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  48.     x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  49.     x$(6) = "" + CHR$(255) + CHR$(10)
  50.     x$(7) = "Article I" + CHR$(10)
  51.     x$(8) = "" + CHR$(255) + CHR$(10)
  52.     x$(9) = "Section 1: Congress" + CHR$(10)
  53.     x$(10) = "" + CHR$(255) + CHR$(10)
  54.     x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  55.     x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  56.     x$(13) = "Representatives." + CHR$(10)
  57.  
  58.     COLOR 0, 7
  59.     GOSUB displaydoc
  60.  
  61.     msg$ = " Find:                                                  "
  62.     button% = 4: button_index% = 4
  63.     W1% = 0: W2% = 0: W3% = 0: W4% = 0
  64.  
  65.     DO
  66.         _LIMIT 30
  67.         IF b$ = CHR$(0) + CHR$(61) THEN
  68.             scr = 0: GOSUB displaydoc
  69.             CALL popup(msg$, msg%, button$(), button%, button_index%, find$) ' Pass by ref text$ to find$
  70.             LOCATE , , 0
  71.         END IF
  72.  
  73.         IF LEN(action$) THEN
  74.             SELECT CASE action$
  75.                 CASE "Whole Word"
  76.                     whole_word% = 1
  77.                     case_sensitive% = 0
  78.                 CASE "Whole/Case"
  79.                     whole_word% = 1
  80.                     case_sensitive% = 1
  81.                 CASE "Any Part"
  82.                     whole_word% = 0
  83.                     case_sensitive% = 0
  84.                 CASE "Any/Case"
  85.                     whole_word% = 0
  86.                     case_sensitive% = 1
  87.             END SELECT
  88.             action$ = ""
  89.             GOSUB finder
  90.         END IF
  91.         b$ = INKEY$
  92.         IF LEN(b$) THEN
  93.             SELECT CASE b$
  94.                 CASE CHR$(9)
  95.                     COLOR 7, 0: CLS: CLEAR: EXIT DO
  96.                 CASE CHR$(27)
  97.                     SYSTEM
  98.                 CASE CHR$(0) + "H"
  99.                     IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  100.                 CASE CHR$(0) + "P"
  101.                     IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  102.             END SELECT
  103.         END IF
  104.     LOOP
  105.  
  106. displaydoc:
  107. COLOR 0, 7
  108. FOR i% = 1 TO page.h
  109.     a1$ = SPACE$(dwidth)
  110.     MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  111.     LOCATE margin.t + i%, margin.l + 1
  112.     PRINT a1$
  113.  
  114. finder:
  115. IF case_sensitive% = 0 THEN
  116.     find$ = LCASE$(find$): findorig$ = find$
  117.     findorig$ = find$
  118.  
  119. IF LEN(findorig$) THEN
  120.     flag% = 0
  121.     FOR i% = 1 TO page.h
  122.         LOCATE margin.t + i%, margin.l + 1
  123.         a1$ = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  124.  
  125.         IF INSTR(find$, " ") THEN
  126.             IF RIGHT$(a1$, 1) <> " " THEN a2$ = a1$ + " " ELSE a2$ = a1$
  127.         ELSE
  128.             a2$ = a1$ ' No space for a solid line wrap around.
  129.         END IF
  130.  
  131.         IF INSTR(findorig$, " ") THEN
  132.             a2$ = a2$ + MID$(x$(i% + 1 + scr), 1, INSTR(x$(i% + 1 + scr), CHR$(10)) - 1)
  133.             a2% = -1
  134.         ELSE
  135.             a2% = 0
  136.         END IF
  137.  
  138.         SELECT CASE case_sensitive%
  139.             CASE 0 ' Not case sensitive.
  140.                 SELECT CASE whole_word%
  141.                     CASE 0 ' Part word and not case sensitive.
  142.                         IF INSTR(LCASE$(a2$), find$) THEN
  143.                             COLOR 14, 4: seed% = 0
  144.                             DO UNTIL INSTR(seed%, LCASE$(a2$), find$) = 0
  145.  
  146.                                 IF a2% THEN
  147.                                     k% = INSTR(seed%, LCASE$(a2$), find$)
  148.                                     IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  149.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  150.                                         find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  151.                                         flag% = 1
  152.                                     ELSE
  153.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  154.                                     END IF
  155.                                 ELSE
  156.                                     seed% = INSTR(seed%, LCASE$(a2$), find$)
  157.                                 END IF
  158.  
  159.                                 IF seed% <= LEN(a1$) THEN
  160.                                     LOCATE margin.t + i%, margin.l + seed%
  161.                                     PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  162.                                     seed% = seed% + LEN(find$)
  163.  
  164.                                     IF flag% THEN
  165.                                         SELECT CASE flag%
  166.                                             CASE 2
  167.                                                 flag% = 0: find$ = findorig$
  168.                                             CASE 1
  169.                                                 flag% = 2
  170.                                                 find$ = MID$(findorig$, LEN(find$) + 2)
  171.                                                 seed% = 0
  172.                                                 EXIT DO
  173.                                         END SELECT
  174.                                     END IF
  175.                                 ELSE
  176.                                     EXIT DO
  177.                                 END IF
  178.                             LOOP
  179.                         END IF
  180.  
  181.                     CASE 1 ' Whole word and not case sensitive.
  182.                         seed% = 0: COLOR 14, 4
  183.                         WHILE INSTR(seed%, LCASE$(a2$), find$)
  184.                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  185.  
  186.                             IF seed% - 1 = 0 OR MID$(LCASE$(a2$), seed% - 1, 1) = " " THEN
  187.                                 IF INSTR(".,;:?!}]) ", MID$(LCASE$(a2$), seed% + LEN(find$), 1)) THEN
  188.  
  189.                                     IF a2% THEN
  190.                                         k% = INSTR(seed%, LCASE$(a2$), find$)
  191.                                         IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  192.                                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  193.                                             find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  194.                                             flag% = 1
  195.                                         ELSE
  196.                                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  197.                                         END IF
  198.                                     ELSE
  199.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  200.                                     END IF
  201.  
  202.                                     IF seed% <= LEN(a1$) THEN
  203.                                         LOCATE margin.t + i%, margin.l + seed%
  204.                                         PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  205.                                         seed% = seed% + LEN(find$)
  206.  
  207.                                         IF flag% THEN
  208.                                             SELECT CASE flag%
  209.                                                 CASE 2
  210.                                                     flag% = 0
  211.                                                     find$ = findorig$
  212.                                                 CASE 1
  213.                                                     flag% = 2
  214.                                                     find$ = MID$(findorig$, LEN(find$) + 2)
  215.                                                     seed% = 0
  216.                                                     EXIT WHILE
  217.                                             END SELECT
  218.                                         END IF
  219.                                     ELSE
  220.                                         EXIT WHILE
  221.                                     END IF
  222.  
  223.                                 END IF
  224.                             END IF
  225.  
  226.                             seed% = seed% + LEN(find$)
  227.  
  228.                         WEND
  229.  
  230.                 END SELECT
  231.  
  232.             CASE 1 ' Case sensitive
  233.                 SELECT CASE whole_word%
  234.                     CASE 0 ' Part word and case sensitive.
  235.                         seed% = 0: COLOR 14, 4
  236.                         WHILE INSTR(seed%, a2$, find$)
  237.                             seed% = INSTR(seed%, a2$, find$)
  238.  
  239.                             IF a2% THEN
  240.                                 k% = INSTR(seed%, a2$, find$)
  241.                                 IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  242.                                     seed% = INSTR(seed%, a2$, find$)
  243.                                     find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  244.                                     flag% = 1
  245.                                 ELSE
  246.                                     seed% = INSTR(seed%, a2$, find$)
  247.                                 END IF
  248.                             ELSE
  249.                                 seed% = INSTR(seed%, a2$, find$)
  250.                             END IF
  251.  
  252.                             IF seed% <= LEN(a1$) THEN
  253.                                 LOCATE margin.t + i%, margin.l + seed%
  254.                                 PRINT MID$(a2$, INSTR(seed%, a2$, find$), LEN(find$));
  255.                                 seed% = seed% + LEN(find$)
  256.  
  257.                                 IF flag% THEN
  258.                                     SELECT CASE flag%
  259.                                         CASE 2
  260.                                             flag% = 0: find$ = findorig$
  261.                                         CASE 1
  262.                                             flag% = 2
  263.                                             find$ = MID$(findorig$, LEN(find$) + 2)
  264.                                             seed% = 0
  265.                                             EXIT WHILE
  266.                                     END SELECT
  267.                                 END IF
  268.                             ELSE
  269.                                 EXIT WHILE
  270.                             END IF
  271.  
  272.                             seed% = seed% + LEN(find$)
  273.  
  274.                         WEND
  275.  
  276.                     CASE 1 ' Whole word and case sensitive.
  277.                         seed% = 0: COLOR 14, 4
  278.                         WHILE INSTR(seed%, a2$, find$)
  279.                             seed% = INSTR(seed%, a2$, find$)
  280.  
  281.                             IF seed% - 1 = 0 OR MID$(a2$, seed% - 1, 1) = " " THEN
  282.                                 IF INSTR(".,;:?!}]) ", MID$(a2$, seed% + LEN(find$), 1)) THEN
  283.  
  284.                                     IF a2% THEN
  285.                                         k% = INSTR(seed%, a2$, find$)
  286.                                         IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  287.                                             seed% = INSTR(seed%, a2$, find$)
  288.                                             find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  289.                                             flag% = 1
  290.                                         ELSE
  291.                                             seed% = INSTR(seed%, a2$, find$)
  292.                                         END IF
  293.                                     ELSE
  294.                                         seed% = INSTR(seed%, a2$, find$)
  295.                                     END IF
  296.  
  297.                                     IF seed% <= LEN(a1$) THEN
  298.                                         LOCATE margin.t + i%, margin.l + seed%
  299.                                         PRINT MID$(a2$, INSTR(seed%, a2$, find$), LEN(find$));
  300.                                         seed% = seed% + LEN(find$)
  301.  
  302.                                         IF flag% THEN
  303.                                             SELECT CASE flag%
  304.                                                 CASE 2
  305.                                                     flag% = 0: find$ = findorig$
  306.                                                 CASE 1
  307.                                                     flag% = 2
  308.                                                     find$ = MID$(findorig$, LEN(find$) + 2)
  309.                                                     seed% = 0
  310.                                                     EXIT WHILE
  311.                                             END SELECT
  312.                                         END IF
  313.                                     ELSE
  314.                                         EXIT WHILE
  315.                                     END IF
  316.  
  317.                                 END IF
  318.                             END IF
  319.  
  320.                             seed% = seed% + LEN(find$)
  321.  
  322.                         WEND
  323.  
  324.                 END SELECT
  325.         END SELECT
  326.     NEXT
  327.  
  328. SUB popup (msg$, msg%, button$(), button%, button_index%, text$)
  329.     DIM scrb AS my_scrb
  330.     STATIC doctype%
  331.     REDIM button$(8)
  332.     button$(1) = "Yes": button$(2) = "No!"
  333.     button$(3) = "Retry": button$(4) = "Cancel"
  334.     button$(5) = "Whole Word": button$(6) = "Whole/Case": button$(7) = "Any Part": button$(8) = "Any/Case"
  335.     iyy% = CSRLIN: ixx% = POS(0)
  336.     IF W3% = 0 THEN W3% = 5 ' Min.
  337.     IF W4% = 0 THEN W4% = LEN(msg$) + 4 ' Min
  338.  
  339.     IF W1% = 0 THEN
  340.         ' Auto-Center
  341.         W1% = _HEIGHT \ 2 - W3% \ 2 + .5
  342.         W2% = _WIDTH \ 2 - W4% \ 2 + .5
  343.     END IF
  344.  
  345.     SELECT CASE SMODE
  346.         CASE 0
  347.             oldsmode = SMODE: PCOPY 0, 1: SCREEN 0, 0, 1, 1: SMODE = 1
  348.         CASE 1
  349.             oldsmode = SMODE: PCOPY 1, 2: SCREEN 0, 0, 2, 2: SMODE = 2
  350.     END SELECT
  351.  
  352.     LOCATE W1%, W2%, 0 ' Cursor hide
  353.     FOR I = 1 TO W3%
  354.         A$ = ""
  355.         COLOR 15, 1
  356.         LOCATE , W2%
  357.         A$ = A$ + SPACE$(W4% - LEN(A$))
  358.         PRINT A$;
  359.         IF I <> 1 THEN
  360.             COLOR 1, 0: PRINT CHR$(176)
  361.         ELSE PRINT
  362.         END IF
  363.     NEXT I
  364.     LOCATE , W2% + 1
  365.     COLOR 1, 0: PRINT STRING$(W4%, CHR$(176));
  366.     COLOR 14, 1
  367.     LOCATE W1%, W2%
  368.     PRINT CHR$(218); STRING$(W4% - 2, CHR$(196)); CHR$(191);
  369.     LOCATE W1% + W3% - 1, W2%
  370.     PRINT CHR$(192); STRING$(W4% - 2, CHR$(196)); CHR$(217);
  371.     FOR I = 1 TO W3% - 2
  372.         LOCATE W1% + I, W2%: PRINT CHR$(179);: LOCATE W1% + I, W2% + W4% - 1: PRINT CHR$(179);
  373.     NEXT I
  374.     LOCATE W1%, W2% + W4% - 2: COLOR 15, 1: PRINT "x";
  375.  
  376.     IF LEN(msg$) THEN
  377.         SELECT CASE msg%
  378.             CASE -1
  379.                 LOCATE W1% + 1, W2% + W4% \ 2 - LEN(msg$) \ 2
  380.                 PRINT msg$;
  381.             CASE 0
  382.                 COLOR 15, 1
  383.                 IF button% THEN
  384.                     LOCATE W1% + W3% \ 2 - 1, W2% + W4% \ 2 - LEN(msg$) \ 2
  385.                     PRINT msg$;
  386.                     j% = 0
  387.                     FOR i% = 1 TO button%
  388.                         j% = j% + LEN(button$(button_index% + i%)) + 2
  389.                     NEXT
  390.                     LOCATE W1% + W3% \ 2 + 1, W2% + W4% \ 2 - j% \ 2 - 1
  391.                     COLOR 0, 7
  392.                     mouselocator$ = STRING$(_WIDTH, "0"): mouselocator% = W1% + W3% \ 2 + 1
  393.                     k% = 0
  394.                     FOR i% = button_index% + 1 TO button_index% + button%
  395.                         IF k% THEN LOCATE , POS(0) + 2
  396.                         k% = k% + 1
  397.                         MID$(mouselocator$, POS(0)) = STRING$(LEN(button$(i%)) + 2, LTRIM$(STR$(k%)))
  398.                         PRINT SPACE$(LEN(button$(i%)) + 2);
  399.                     NEXT
  400.                     LOCATE W1% + W3% \ 2 + 1, W2% + W4% \ 2 - j% \ 2
  401.                     COLOR 0, 7
  402.                     k% = 0
  403.                     FOR i% = button_index% + 1 TO button_index% + button%
  404.                         IF k% THEN LOCATE , POS(0) + 4
  405.                         PRINT button$(i%);
  406.                         k% = k% + 1
  407.                     NEXT
  408.  
  409.                     LOCATE 11, 18
  410.                     COLOR 8, 1: PRINT CHR$(222);
  411.                     COLOR c2%, c1%: PRINT SPACE$(48);
  412.                     passrightmargin% = POS(0) - 1: LOCATE 11, 19: xx2 = POS(0)
  413.                     tabx% = 0: action$ = ""
  414.                     _KEYCLEAR: text$ = ""
  415.  
  416.                     DO
  417.                         IF pete = 0 THEN
  418.                             LOCATE 11, xx2, 1
  419.                             CALL textinput(text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb, noe, row, scr, config%, b$)
  420.                             yy2 = CSRLIN: xx2 = POS(0)
  421.                         ELSE
  422.                             CALL user(b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  423.                         END IF
  424.                         IF LEN(b$) THEN
  425.                             SELECT CASE b$
  426.                                 CASE CHR$(13)
  427.                                     IF pete = 0 THEN
  428.                                         SELECT CASE tabx%
  429.                                             CASE 1
  430.                                                 IF button_index% = 0 THEN action$ = "yes"
  431.                                                 IF button_index% = 2 THEN action$ = "retry"
  432.                                                 IF button_index% = 4 THEN action$ = "Whole Word" ' F3 Find option.
  433.                                             CASE 2
  434.                                                 IF button_index% = 0 THEN action$ = "no"
  435.                                                 IF button_index% = 2 THEN action$ = "abort"
  436.                                                 IF button_index% = 4 THEN action$ = "Whole/Case" ' F3 Find option.
  437.                                                 ' Find Function only.
  438.                                             CASE 0, 3
  439.                                                 IF button_index% = 4 THEN action$ = "Any Part" ' F3 Find option.
  440.                                             CASE 4
  441.                                                 IF button_index% = 4 THEN action$ = "Any/Case" ' F3 Find option.
  442.                                         END SELECT
  443.                                     ELSE
  444.                                         SELECT CASE tabx%
  445.                                             CASE 1
  446.                                                 IF button_index% = 0 THEN action$ = "yes"
  447.                                                 IF button_index% = 2 THEN action$ = "retry"
  448.                                             CASE 2
  449.                                                 IF button_index% = 0 THEN action$ = "no"
  450.                                                 IF button_index% = 2 THEN action$ = "abort"
  451.                                         END SELECT
  452.                                     END IF
  453.                                 CASE CHR$(27)
  454.                                     action$ = "close"
  455.                             END SELECT
  456.                         END IF
  457.  
  458.                         IF my% = W1% AND mx% = W2% + W4% - 2 THEN
  459.                             IF closex% = 0 THEN closex% = -1: LOCATE my%, mx%: COLOR 15, 4: PRINT "x";
  460.                         ELSE
  461.                             IF closex% THEN closex% = 0: LOCATE W1%, W2% + W4% - 2: COLOR 7, 1: PRINT "x";
  462.                         END IF
  463.  
  464.                         IF bhl% THEN IF bhl% = 1 AND my% <> mouselocator% OR bhl% = 1 AND MID$(mouselocator$, mx%, 1) = "0" THEN tabx% = 0: bhl% = 0
  465.                         IF b$ = CHR$(9) THEN tabx% = tabx% + 1: IF tabx% > button% THEN tabx% = 1
  466.                         IF oldmx% = mx% AND oldmy% = my% THEN i% = 0 ELSE i% = -1
  467.                         IF b$ = CHR$(9) OR my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" AND i% THEN
  468.                             IF b$ = CHR$(9) THEN k% = tabx%: bhl% = 9 ELSE k% = VAL(MID$(mouselocator$, mx%, 1)): tabx% = k%: bhl% = 1
  469.                             IF pete = 0 THEN LOCATE , , 0 ' Hide cursor while making buttons.
  470.                             IF h% AND h% <> tabx% THEN
  471.                                 COLOR 0, 7
  472.                                 LOCATE W1% + W3% \ 2 + 1, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  473.                                 PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  474.                             END IF
  475.  
  476.                             h% = k%: tabx% = h%
  477.  
  478.                             COLOR 0, 3
  479.                             LOCATE W1% + W3% \ 2 + 1, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  480.                             PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  481.                             IF pete = 0 THEN LOCATE yy2, xx2, 1 ' Show cursor back in input field.
  482.                             _DELAY .15
  483.                         ELSE
  484.                             IF h% AND tabx% = 0 THEN
  485.                                 IF pete = 0 THEN LOCATE , , 0
  486.                                 COLOR 0, 7
  487.                                 LOCATE W1% + W3% \ 2 + 1, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  488.                                 PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  489.                                 h% = 0: tabx% = 0
  490.                                 IF pete = 0 THEN LOCATE yy2, xx2, 1
  491.                             END IF
  492.                         END IF
  493.  
  494.                         IF mb.l THEN
  495.                             IF closex% THEN SOUND 1000, .1: closex% = 0: action$ = "close"
  496.                             IF my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" THEN
  497.                                 SOUND 1000, .1
  498.                                 SELECT CASE VAL(MID$(mouselocator$, mx%, 1))
  499.                                     CASE 1
  500.                                         IF button_index% = 0 THEN action$ = "yes"
  501.                                         IF button_index% = 2 THEN action$ = "retry"
  502.                                         IF button_index% = 4 THEN action$ = "Whole Word" ' F3 Find option.
  503.                                     CASE 2
  504.                                         IF button_index% = 0 THEN action$ = "no"
  505.                                         IF button_index% = 2 THEN action$ = "abort"
  506.                                         IF button_index% = 4 THEN action$ = "Whole/Case" ' F3 Find option.
  507.                                         ' Find Function only.
  508.                                     CASE 3
  509.                                         IF button_index% = 4 THEN action$ = "Any Part" ' F3 Find option.
  510.                                     CASE 4
  511.                                         IF button_index% = 4 THEN action$ = "Any/Case" ' F3 Find option.
  512.                                 END SELECT
  513.                             END IF
  514.                         END IF
  515.  
  516.                         IF b$ = CHR$(9) THEN b$ = ""
  517.                         oldmy% = my%: oldmx% = mx%
  518.                     LOOP UNTIL LEN(action$)
  519.                     SMODE = oldsmode: SCREEN 0, 0, SMODE, SMODE
  520.                 ELSE
  521.                     LOCATE W1% + W3% \ 2, W2% + W4% \ 2 - LEN(msg$) \ 2
  522.                     PRINT msg$;
  523.                 END IF
  524.  
  525.         END SELECT
  526.     END IF
  527.     LOCATE iyy%, ixx%
  528.  
  529. SUB user (b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  530.  
  531.     '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  532.  
  533.     DEF SEG = 0
  534.     IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN shift% = -1 ELSE shift% = 0
  535.     IF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN ctrl% = -1 ELSE ctrl% = 0
  536.     IF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN ctrlshift% = -1 ELSE ctrlshift% = 0
  537.  
  538.     IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  539.         alt% = -1: con_panel% = -1
  540.     ELSE
  541.         IF alt% THEN alt% = 0: con_panel% = 1
  542.     END IF
  543.     DEF SEG
  544.  
  545.     b$ = INKEY$
  546.  
  547.     mb.w = 0
  548.         mb.w = mb.w + _MOUSEWHEEL
  549.     WEND
  550.  
  551.     mb.l% = _MOUSEBUTTON(1)
  552.     mb.r% = _MOUSEBUTTON(2)
  553.     mx% = _MOUSEX
  554.     my% = _MOUSEY
  555.  
  556. SUB textinput (text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb AS my_scrb, noe AS INTEGER, row, scr, config%, b$)
  557.     STATIC initiate%
  558.     STATIC hscrollon%, hscroll%, textfg%, textbk%, highlightfg%, highlightbk%, leftmargin%, rightmargin%, noleadingspace%, textmaxlength%, linecharacter%, click_l%, drag%, shiftclick%, tabx%
  559.     STATIC starthighlight%, highlight%, overwrite%, CurAdvance%
  560.     STATIC xx1
  561.     '''vartable% = 2: CALL setvariables(scrb, c1%, c2%, c1alt%, h1%, h2%, row, ins%, dwidth, dwidth2, menubar%)
  562.  
  563.     row = 1: tabx% = 2: thumb% = 0
  564.  
  565.     DO
  566.         IF NOT initiate% THEN ' Initiate textinput variables.
  567.             initiate% = -1
  568.             GOSUB initiate_variables
  569.         END IF
  570.  
  571.         ' --------------------POLL MOUSE--->
  572.         mb.w = 0
  573.         WHILE _MOUSEINPUT
  574.             mb.w = mb.w + _MOUSEWHEEL
  575.         WEND
  576.  
  577.         IF mb.w = 0 THEN
  578.             mx% = _MOUSEX ' Mouse column.
  579.             my% = _MOUSEY ' Mouse row.
  580.             mb.l = _MOUSEBUTTON(1)
  581.             mb.r = _MOUSEBUTTON(2)
  582.             mb.m = _MOUSEBUTTON(3)
  583.         END IF
  584.         '<----------------------------------
  585.  
  586.         IF noleadingspace% THEN ' Remove leading spaces of any text entry in form.
  587.             IF LEFT$(text$, 1) = " " THEN
  588.                 DO UNTIL LEFT$(text$, 1) <> " " OR text$ = ""
  589.                     text$ = MID$(text$, 2)
  590.                     LOCATE , leftmargin%
  591.                     GOSUB wash
  592.                 LOOP
  593.             END IF
  594.         END IF
  595.  
  596.         '-------------------------------------------------------------------------
  597.         mykey% = _KEYHIT
  598.  
  599.         '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  600.  
  601.         IF mykey% = 0 THEN
  602.             IF my% <> oldmy% OR mx% <> oldmx% OR mb.l OR mb.w THEN
  603.                 GOSUB mouseroutine
  604.                 IF LEN(action$) THEN EXIT DO
  605.             END IF
  606.         END IF
  607.  
  608.         ''''''IF mykey% = 0 THEN GOSUB file_display_keys
  609.  
  610.         IF mykey% > 0 THEN
  611.             GOSUB form_input_keyroutine
  612.             IF LEN(action$) THEN EXIT DO
  613.         END IF
  614.         '-------------------------------------------------------------------------
  615.         oldmy% = my%: oldmx% = mx%
  616.         IF pete = 0 THEN EXIT DO
  617.     LOOP
  618.     EXIT SUB
  619.  
  620.     '---------------------------GOSUB STATEMENTS-----------------------------
  621.     initiate_variables:
  622.     PageWidth1% = 80
  623.     PageWidth2% = 25
  624.     Topmargin% = 3
  625.     BottomMargin% = PageWidth2% - UpFromBottom%
  626.     UpFromBottom% = 2
  627.     BlockSize% = 0: REM -1 = variable.
  628.     Headers% = 0: REM On -1 or Off 0
  629.     TabElements% = 1: REM Number of input fields horizontally arranged. - 1 indicates variable.
  630.     ColorPrompt% = 0: REM 0 = COLOR 7, 0. Set all foreground/background by background * 16 + background.
  631.     ColorResponse% = 0: REM 0 will use textfg% and textbk% as defaults; otherwise set all foreground/background by background * 16 + background.
  632.     RestrictInput% = -1: REM On -1 or Off 0. (Uses 3 data fields)
  633.     InputFieldLength% = 0: REM Set to a number to allow variable length fields; otherwise filed input length will be determined by rightmargin% - (leftmargin% - 1).
  634.     PromptColumn% = 1: REM Column where prompt starts. Use 0 if no prompts. Use -1 for  multiple prompts on same row.
  635.     ResponseColumn% = 0: REM Set to a number if using Spacer%; otherwise 0 = input field follows response.
  636.  
  637.     TableStyle% = 0: REM 0 = Prompt/Space/Input, 1 = Prompt/Colon+Space/Response, 2 = Prompt/Spacers/Response
  638.     Spacer$ = ".": REM Type of spacer character if spacers are used (Table Style 2).
  639.  
  640.     textfg% = 7
  641.     textbk% = 0
  642.     highlightfg% = 0
  643.     highlightbk% = 7
  644.     leftmargin% = POS(0): iyy% = CSRLIN
  645.     rightmargin% = passrightmargin%
  646.     textmaxlength% = 250
  647.     noleadingspace% = -1
  648.     linecharacter% = 255: REM Blank space
  649.  
  650.     IF textmaxlength% > rightmargin% - (leftmargin% - 1) THEN hscrollon% = -1
  651.     IF rightmargin% < leftmargin% THEN CLS: PRINT "Rightmargin% cannot be smaller than leftmargin%. Redo.": END
  652.     IF leftmargin% < 1 OR leftmargin% > 80 THEN CLS: PRINT "Leftmargin% is not within 1 - 80 range. Redo.": END
  653.     REM no longer valid with hscroll.IF textmaxlength% > rightmargin% - leftmargin% + 1 THEN CLS: PRINT "textmaxlength% cannot exceed rightmargin% - leftmargin% + 1. Redo.:end"
  654.     IF LEN(text$) > textmaxlength% THEN CLS: PRINT "Text length cannot start out larger than textmaxlength%. Redo.": END
  655.  
  656.     IF rightmargin% = leftmargin% AND textmaxlength% = 1 THEN
  657.         CurAdvance% = 0
  658.     ELSE
  659.         CurAdvance% = 1
  660.     END IF
  661.  
  662.     COLOR textfg%, textbk%
  663.     LOCATE iyy%, leftmargin%, 1, 7, 7
  664.     RETURN '-----------------------------------------------------------------
  665.  
  666.     form_input_keyroutine:
  667.     DO ' Falk loop.
  668.         IF SMODE = 3 THEN ' Doctype dropdown is open.
  669.             SELECT CASE mykey%
  670.                 CASE 9, 27 ' Close doctype dropdown.
  671.                     GOSUB close_doctype_dropdown
  672.                 CASE 18432 ' Arrow up.
  673.                     IF CSRLIN = W1% + 17 THEN
  674.                         LOCATE W1% + 17, W2% + 15
  675.                         COLOR 7, 0: PRINT doctype$(2);
  676.                         LOCATE W1% + 16, W2% + 15
  677.                         COLOR 1, 3: PRINT doctype$(1);
  678.                     END IF
  679.                 CASE 20480 ' Arrow Down
  680.                     IF CSRLIN = W1% + 16 THEN
  681.                         LOCATE W1% + 16, W2% + 15
  682.                         COLOR 7, 0: PRINT doctype$(1);
  683.                         LOCATE W1% + 17, W2% + 15
  684.                         COLOR 1, 3: PRINT doctype$(2);
  685.                     END IF
  686.                 CASE 13 ' Enter
  687.                     b$ = CHR$(13): EXIT DO
  688.                     IF CSRLIN = W1% + 16 THEN i% = 1 ELSE i% = 2
  689.                     GOSUB close_doctype_dropdown
  690.                     GOSUB doctype_selected ' (Gosub parameter i%)
  691.             END SELECT
  692.             mykey% = 0
  693.             EXIT DO ' To REturn
  694.         END IF
  695.  
  696.         ' Process text if cursor is on form field text input line.
  697.         IF pete = 0 OR CSRLIN = W1% + W3% - 4 - 3 OR mykey% = 27 OR mykey% = 13 OR mykey% = 9 THEN ELSE EXIT DO
  698.  
  699.         IF _KEYDOWN(100303) = -1 OR _KEYDOWN(100304) = -1 THEN
  700.             SELECT CASE mykey%
  701.                 CASE 18176, 20224, 19200, 19712, 21248, 20992
  702.                     shift% = -1
  703.             END SELECT
  704.         ELSE
  705.             IF NOT drag% AND shift% THEN shift% = 0
  706.         END IF
  707.  
  708.         IF _KEYDOWN(100305) = -1 OR _KEYDOWN(100306) = -1 THEN
  709.             SELECT CASE mykey%
  710.                 CASE 86, 118
  711.                     control% = -2
  712.                 CASE ELSE
  713.                     control% = -1
  714.             END SELECT
  715.         ELSE
  716.             control% = 0
  717.         END IF
  718.  
  719.         REM Evaluate changes to highlighted text, excluding cut/copy/paste
  720.         IF highlight% AND shift% = 0 AND control% <> -1 AND mykey% <> 8 AND mykey% < 21248 THEN
  721.             IF mykey% > 31 AND mykey% < 256 THEN
  722.                 GOSUB cutcopy
  723.             ELSE
  724.                 GOSUB wash
  725.             END IF
  726.         END IF
  727.  
  728.         IF shift% = -1 AND control% = 0 THEN
  729.             SELECT CASE mykey%
  730.                 CASE 19200
  731.                     GOSUB HighlightLeft
  732.  
  733.                 CASE 19712
  734.                     IF control% THEN
  735.                         GOSUB ctrlrt
  736.                     ELSE
  737.                         GOSUB HighlightRight
  738.                     END IF
  739.  
  740.                 CASE 18176
  741.                     GOSUB SelectToHome
  742.  
  743.                 CASE 20224
  744.                     GOSUB SelectToEnd
  745.  
  746.                 CASE 21248
  747.                     mykey% = 88: REM Convert Delete to Cut
  748.                     GOSUB cutcopy
  749.  
  750.                 CASE 20992
  751.                     GOSUB PasteClipboard
  752.             END SELECT
  753.  
  754.         ELSE
  755.  
  756.             SELECT CASE control%
  757.                 CASE 0
  758.                     SELECT CASE mykey%
  759.                         CASE 18176
  760.                             IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  761.  
  762.                         CASE 20224
  763.                             IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  764.  
  765.                         CASE 8, 21248: REM Backspace and Delete
  766.                             GOSUB BackspaceDelete
  767.  
  768.                         CASE 9: REM Tab
  769.                             IF pete = 0 THEN b$ = CHR$(9): EXIT DO ELSE GOSUB tabkey: mykey% = 0
  770.  
  771.                         CASE 13
  772.                             IF pete = 0 THEN b$ = CHR$(13): EXIT DO
  773.                             DO ' Single falks do/loop.
  774.                                 FOR i% = 1 TO UBOUND(formbutton$)
  775.                                     IF formbuttonx%(i%) < 0 THEN
  776.                                         SELECT CASE i%
  777.                                             CASE 1
  778.                                                 formbuttonx%(1) = ABS(formbuttonx%(1))
  779.                                                 GOSUB popfiletypes
  780.                                                 EXIT DO
  781.                                             CASE 2
  782.                                                 SELECT CASE config%
  783.                                                     CASE 1
  784.                                                         action$ = "open file"
  785.                                                     CASE 2
  786.                                                         action$ = "save as"
  787.                                                 END SELECT
  788.                                                 '''myfile$ = text$
  789.                                                 EXIT DO
  790.                                             CASE 3
  791.                                                 action$ = "cancel"
  792.                                                 EXIT DO
  793.                                         END SELECT
  794.                                     END IF
  795.                                 NEXT
  796.  
  797.                                 SELECT CASE tabx%
  798.                                     CASE 1 ' File selected from display window.
  799.                                         IF hlf% THEN
  800.                                             GOSUB fileselected
  801.                                             IF action$ = "change dir" THEN tabx% = 0: EXIT DO
  802.                                             tabx% = 2
  803.                                         ELSE
  804.                                             BEEP
  805.                                         END IF
  806.                                     CASE 2 ' Save or Open selected file.
  807.                                         IF LEN(text$) THEN
  808.                                             SELECT CASE config%
  809.                                                 CASE 1
  810.                                                     action$ = "open file"
  811.                                                 CASE 2
  812.                                                     action$ = "save as"
  813.                                             END SELECT
  814.                                             tabx% = 2
  815.                                             '''myfile$ = text$
  816.                                             EXIT DO
  817.                                         ELSE
  818.                                             BEEP
  819.                                         END IF
  820.                                     CASE 3 ' Open doctype dropdown menu.
  821.                                         GOSUB popfiletypes
  822.                                     CASE 4 ' Save or Open selected file. Only occurs when tab selected then mouse goes on another button and then goes to a neutral position. In this case the variable is no longer negative and the loop above misses it.
  823.                                         SELECT CASE config%
  824.                                             CASE 1
  825.                                                 action$ = "open file"
  826.                                             CASE 2
  827.                                                 action$ = "save as"
  828.                                         END SELECT
  829.                                         tabx% = 2
  830.                                         EXIT DO
  831.                                     CASE 5 ' Cancel
  832.                                         action$ = "cancel": tabx% = 2
  833.                                         EXIT DO
  834.                                 END SELECT
  835.                                 EXIT DO
  836.                             LOOP
  837.                             IF LEN(action$) THEN EXIT DO ' To Return
  838.  
  839.                         CASE 19200
  840.                             GOSUB CursorLeft
  841.  
  842.                         CASE 19712
  843.                             GOSUB CursorRight
  844.  
  845.                         CASE 18432
  846.                             GOSUB CursorUp
  847.  
  848.                         CASE 20480
  849.                             GOSUB CursorDown
  850.  
  851.                         CASE 18688
  852.                             GOSUB PageUp
  853.  
  854.                         CASE 20736
  855.                             GOSUB PageDown
  856.  
  857.                         CASE 27
  858.                             IF pete = 0 THEN b$ = CHR$(27): EXIT DO
  859.                             GOSUB wash
  860.                             EXIT DO
  861.  
  862.                         CASE 20992: REM Insert
  863.                             GOSUB InsertOverwrite
  864.  
  865.                         CASE ELSE
  866.                             GOSUB DisplayText
  867.                             IF flagtext% = -1 THEN flagtext% = 0: mykey% = 0
  868.                     END SELECT
  869.  
  870.                     REM Control% = -1 or -2
  871.                 CASE -1, -2
  872.  
  873.                     SELECT CASE mykey%
  874.  
  875.                         CASE 65, 97 ' A a
  876.                             GOSUB SelectAll
  877.  
  878.                         CASE 67, 99, 88, 120 ' C c X x
  879.                             GOSUB cutcopy
  880.  
  881.                         CASE 86, 118 ' V v
  882.                             REM Paste
  883.                             GOSUB PasteClipboard
  884.  
  885.                         CASE 19712
  886.                             REM Cursor and arrow right
  887.                             GOSUB ctrlrt
  888.  
  889.                         CASE 19200
  890.                             REM Cursor and arrow left
  891.                             GOSUB ctrllt
  892.  
  893.                         CASE 18176
  894.                             GOSUB CursorHome ' Ctrl + Home
  895.  
  896.                         CASE 20224
  897.                             GOSUB CursorEnd ' Ctrl + End
  898.  
  899.                         CASE ELSE
  900.                             ' Do nothing.
  901.  
  902.                     END SELECT
  903.             END SELECT
  904.         END IF
  905.         EXIT DO
  906.     LOOP
  907.     RETURN '-----------------------------------------------------------------
  908.  
  909.     ' Key Actions.
  910.     tabkey:
  911.     tabx% = tabx% + 1
  912.     IF tabx% > 5 THEN tabx% = 1: GOSUB clearbuttons
  913.  
  914.     SELECT CASE tabx%
  915.         CASE 1
  916.             IF hlf% THEN j% = -999: GOSUB highlightfile
  917.             i% = 0: GOSUB displaybutton
  918.             LOCATE , , 0: row = 1: j% = 0: GOSUB highlightfile
  919.         CASE 2
  920.             IF hlf% THEN j% = -999: GOSUB highlightfile
  921.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1
  922.         CASE 3
  923.             i% = -1: GOSUB displaybutton
  924.         CASE 4
  925.             i% = -2: GOSUB displaybutton
  926.         CASE 5
  927.             i% = -3: GOSUB displaybutton
  928.     END SELECT
  929.     b$ = "": mykey% = 0: null$ = INKEY$: k% = _KEYHIT ' Clear keyboard buffers
  930.     RETURN '------------------------------------------------------------------
  931.  
  932.     CursorLeft:
  933.     IF POS(0) > leftmargin% THEN
  934.         LOCATE , POS(0) - CurAdvance%
  935.     ELSE
  936.         IF hscroll% THEN hscroll% = hscroll% - 1: GOSUB wash
  937.     END IF
  938.     RETURN '------------------------------------------------------------------
  939.  
  940.     CursorRight:
  941.     IF POS(0) < rightmargin% THEN
  942.         IF POS(0) + CurAdvance% <= leftmargin% - 1 + LEN(text$) + 1 THEN
  943.             IF POS(0) < rightmargin% THEN LOCATE , POS(0) + CurAdvance%
  944.         END IF
  945.     ELSE
  946.         IF hscrollon% THEN
  947.             IF hscroll% + rightmargin% - (leftmargin% - 1) <= LEN(text$) THEN
  948.                 hscroll% = hscroll% + 1
  949.                 GOSUB wash
  950.             END IF
  951.         END IF
  952.     END IF
  953.  
  954.     RETURN '------------------------------------------------------------------
  955.  
  956.     ctrllt:
  957.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  958.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  959.     IF INSTR(texttemp$, " ") <> 0 THEN
  960.         FOR ictrllt% = POS(0) - leftmargin% + 1 + hscroll% TO 1 STEP -1
  961.             IF exitctrl% AND MID$(text$, ictrllt% - 1, 1) = " " THEN EXIT FOR
  962.             IF MID$(text$, ictrllt%, 1) <> " " THEN exitctrl% = -1
  963.             IF shift% THEN GOSUB HighlightLeft ELSE GOSUB CursorLeft
  964.         NEXT
  965.         exitctrl% = 0
  966.     ELSE
  967.         IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  968.     END IF
  969.     RETURN '---------------------------------------------------------------------
  970.  
  971.     ctrlrt:
  972.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  973.     texttemp$ = MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  974.     IF INSTR(texttemp$, " ") <> 0 THEN
  975.         FOR ictrlrt% = POS(0) - leftmargin% + 1 + hscroll% TO LEN(text$)
  976.             IF MID$(text$, ictrlrt%, 1) <> " " THEN
  977.                 IF exitctrl% THEN EXIT FOR
  978.                 jctrlrt% = -1
  979.             END IF
  980.             IF MID$(text$, ictrlrt%, 1) = " " AND jctrlrt% THEN exitctrl% = -1
  981.             IF shift% THEN GOSUB HighlightRight ELSE GOSUB CursorRight
  982.         NEXT
  983.         exitctrl% = 0: ictrlrt% = 0: jctrlrt% = 0
  984.     ELSE
  985.         IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  986.     END IF
  987.     RETURN '---------------------------------------------------------------------
  988.  
  989.     CursorHome:
  990.     IF hscroll% <> 0 THEN hscroll% = 0: GOSUB wash
  991.     LOCATE , leftmargin%
  992.     RETURN '---------------------------------------------------------------------
  993.  
  994.     CursorEnd:
  995.     IF hscrollon% THEN
  996.         IF LEN(text$) > rightmargin% - (leftmargin% - 1) THEN
  997.             hscroll% = LEN(text$) - (rightmargin% - (leftmargin% - 1)) + 1: REM + 1 allows for adding to end of text.
  998.             GOSUB wash
  999.         END IF
  1000.     END IF
  1001.     IF LEN(text$) + leftmargin% - 1 >= rightmargin% THEN
  1002.         LOCATE , rightmargin%
  1003.     ELSE
  1004.         LOCATE , leftmargin% - 1 + LEN(text$) + CurAdvance%
  1005.     END IF
  1006.     RETURN '---------------------------------------------------------------------
  1007.  
  1008.     CursorUp:
  1009.     REM PRINT "Cursor Up"
  1010.     RETURN
  1011.  
  1012.     CursorDown:
  1013.     REM PRINT "Cursor Down"
  1014.     IF formbuttonx%(1) < 0 OR tabx% = 3 THEN ' Opens the doctype dropdown menu.
  1015.         formbuttonx%(1) = ABS(formbuttonx%(1))
  1016.         GOSUB popfiletypes
  1017.     END IF
  1018.     RETURN '---------------------------------------------------------------------
  1019.  
  1020.     PageUp:
  1021.     REM PRINT "Page Up"
  1022.     RETURN
  1023.  
  1024.     PageDown:
  1025.     REM PRINT "Page Down"
  1026.     RETURN
  1027.  
  1028.     REM Highlighting -----------------------------------------------------------
  1029.     HighlightLeft:
  1030.     iyy% = CSRLIN: ixx% = POS(0)
  1031.     IF POS(0) > leftmargin% OR hscroll% THEN
  1032.  
  1033.         IF highlight% AND POS(0) >= highlight% - hscroll% THEN ' Unhighlighting left to right.
  1034.             ' Move back first and then calculate POS(0) - 1, below.
  1035.             IF highlight% = starthighlight% THEN
  1036.                 starthighlight% = 0: highlight% = 0
  1037.             ELSE
  1038.                 highlight% = POS(0) - 1 + hscroll% ' Diminishing.
  1039.             END IF
  1040.         ELSE ' Highlighting left to right.
  1041.             ' Calculate first and then move back. POS(0).
  1042.             IF highlight% = 0 THEN highlight% = POS(0) + hscroll%
  1043.             starthighlight% = POS(0) + hscroll%
  1044.         END IF
  1045.  
  1046.         IF POS(0) = leftmargin% AND hscroll% THEN hscroll% = hscroll% - 1 ' hscroll% is reduced after the calculations above.
  1047.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  1048.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  1049.  
  1050.         LOCATE iyy%, leftmargin%
  1051.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  1052.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  1053.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  1054.  
  1055.         IF ixx% - leftmargin% > 0 THEN ixx% = ixx% - 1 ' No moving cursor back when it is at left amrgin and scrolling text back.
  1056.         LOCATE iyy%, ixx%
  1057.         COLOR textfg%, textbk%
  1058.     END IF
  1059.     RETURN '---------------------------------------------------------------------
  1060.  
  1061.     HighlightRight:
  1062.     iyy% = CSRLIN: ixx% = POS(0)
  1063.     IF hscroll% + ixx% + 1 - leftmargin% <= LEN(text$) THEN
  1064.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  1065.  
  1066.         IF POS(0) >= starthighlight% - hscroll% THEN
  1067.             IF starthighlight% = 0 THEN starthighlight% = POS(0) + 1 + hscroll%
  1068.             highlight% = POS(0) + 1 + hscroll%
  1069.         ELSE
  1070.             IF starthighlight% = highlight% THEN
  1071.                 starthighlight% = 0: highlight% = 0
  1072.             ELSE
  1073.                 starthighlight% = POS(0) + 2 + hscroll%
  1074.             END IF
  1075.         END IF
  1076.  
  1077.         IF POS(0) = rightmargin% AND LEN(text$) - hscroll% > rightmargin% - leftmargin% THEN hscroll% = hscroll% + 1
  1078.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  1079.  
  1080.         LOCATE iyy%, leftmargin%
  1081.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  1082.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  1083.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  1084.         IF POS(0) = rightmargin% THEN PRINT SPACE$(1); ' Only used when highlighting past last character to include one blank space.
  1085.         IF ixx% < rightmargin% THEN ixx% = ixx% + 1
  1086.         LOCATE iyy%, ixx%
  1087.         COLOR textfg%, textbk%
  1088.     END IF
  1089.     RETURN '---------------------------------------------------------------------
  1090.  
  1091.     ClickhighLight:
  1092.     j% = 0
  1093.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  1094.     FOR i% = LEN(texttemp$) TO 1 STEP -1
  1095.         IF MID$(texttemp$, i%, 1) = " " AND j% THEN EXIT FOR ELSE j% = -1
  1096.     NEXT
  1097.     jClickhighLight% = LEN(texttemp$) - i% - 1
  1098.     invokestarthighlight% = POS(0) + hscroll% - (LEN(texttemp$) - i%) + 1
  1099.     FOR iClickhighLight% = 1 TO jClickhighLight%
  1100.         IF POS(0) = leftmargin% THEN EXIT FOR
  1101.         GOSUB CursorLeft
  1102.     NEXT
  1103.     shift% = -1
  1104.     GOSUB ctrlrt
  1105.     shift% = 0
  1106.     invokestarthighlight% = 0: iClickhighLight% = 0: jClickhighLight% = 0
  1107.     RETURN '---------------------------------------------------------------------
  1108.  
  1109.     SelectAll:
  1110.     highlight% = 0: starthighlight% = 0: REM These are not zeroed as a ctrl keys bypass remove highlighting
  1111.     GOSUB CursorHome
  1112.     GOSUB SelectToEnd
  1113.     RETURN '---------------------------------------------------------------------
  1114.  
  1115.     SelectToEnd:
  1116.     IF mspan% = 0 THEN mspan% = POS(0) - leftmargin% + 1 + LEN(text$)
  1117.     FOR iSelectToEnd% = 1 TO mspan%
  1118.         GOSUB HighlightRight
  1119.     NEXT
  1120.     mspan% = 0: iSelectToEnd% = 0
  1121.     RETURN '---------------------------------------------------------------------
  1122.  
  1123.     SelectToHome:
  1124.     IF mspan% = 0 THEN
  1125.         IF POS(0) = rightmargin% THEN
  1126.             mspan% = rightmargin% - (leftmargin% - 1) + hscroll%
  1127.         ELSE
  1128.             mspan% = POS(0) - leftmargin% + 1 + hscroll%
  1129.         END IF
  1130.     END IF
  1131.  
  1132.     FOR iSelectToHome% = 1 TO mspan%
  1133.         GOSUB HighlightLeft
  1134.     NEXT
  1135.     mspan% = 0: iSelectToHome% = 0
  1136.     RETURN '---------------------------------------------------------------------
  1137.  
  1138.     DisplayText:
  1139.     DO ' Falk loop.
  1140.         IF mykey% > 31 AND mykey% < 256 THEN
  1141.             COLOR 7, 0: LOCATE , , 1
  1142.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  1143.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 2)
  1144.             ELSE
  1145.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 1)
  1146.             END IF
  1147.  
  1148.             positioncursor% = POS(0)
  1149.  
  1150.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  1151.  
  1152.                 IF POS(0) - leftmargin% + hscroll% < textmaxlength% THEN
  1153.                     text$ = MID$(text$, 1, POS(0) + (hscroll%) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 2)
  1154.                 ELSE
  1155.                     flagtext% = -1: EXIT DO 'To Return
  1156.                 END IF
  1157.  
  1158.                 REM Evaluate Horizontal Scroll
  1159.                 IF POS(0) = rightmargin% THEN
  1160.                     hscroll% = hscroll% + 1
  1161.                 END IF
  1162.             ELSE
  1163.                 IF LEN(text$) < textmaxlength% THEN
  1164.                     text$ = MID$(text$, 1, POS(0) + hscroll% - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 1)
  1165.                     flagtext% = 0
  1166.                 ELSE
  1167.                     flagtext% = -1
  1168.                 END IF
  1169.  
  1170.                 IF flagtext% = -1 THEN EXIT DO ' To Return REM flagtext% is set to zero upon return and exit.
  1171.  
  1172.                 REM Evaluate Horizontal Scroll
  1173.                 IF hscrollon% AND POS(0) = rightmargin% THEN
  1174.                     hscroll% = hscroll% + 1
  1175.                 END IF
  1176.             END IF
  1177.  
  1178.             ' Print to form input line.
  1179.             LOCATE , leftmargin%: PRINT STRING$(rightmargin% - (leftmargin% - 1), linecharacter%);
  1180.             LOCATE , leftmargin%: PRINT MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1));
  1181.  
  1182.             IF CurAdvance% = 1 AND positioncursor% - leftmargin% + 1 < rightmargin% - leftmargin% + 1 THEN
  1183.                 LOCATE , positioncursor% + CurAdvance%
  1184.             ELSE
  1185.                 LOCATE , positioncursor%
  1186.             END IF
  1187.         END IF
  1188.         EXIT DO
  1189.     LOOP
  1190.     RETURN '---------------------------------------------------------------------
  1191.  
  1192.     BackspaceDelete:
  1193.     IF highlight% THEN GOSUB cutcopy
  1194.     IF POS(0) > leftmargin% OR mykey% = 21248 OR hscroll% > 0 THEN
  1195.         IF POS(0) <= leftmargin% + LEN(text$) THEN
  1196.             IF mykey% = 8 THEN
  1197.                 IF POS(0) <= leftmargin% + 2 AND hscroll% > 0 THEN
  1198.                     REM Adjust for horizontal scroll
  1199.                     holdcursor% = POS(0)
  1200.                     LOCATE , leftmargin%
  1201.                     countcolumnsmoved% = hscroll%
  1202.                     jBackspaceDelete% = (rightmargin% - (leftmargin% - 1)) * .33
  1203.                     IF jBackspaceDelete% < 3 AND rightmargin% - (leftmargin% - 1) > 3 THEN jBackspaceDelete% = 3: REM Set minimum scroll back.
  1204.                     FOR iBackspaceDelete% = 1 TO jBackspaceDelete%
  1205.                         GOSUB CursorLeft
  1206.                     NEXT
  1207.                     LOCATE , holdcursor% + countcolumnsmoved% - hscroll% - 1
  1208.                     countcolumnsmoved% = 0: iBackspaceDelete% = 0: jBackspaceDelete% = 0
  1209.                 ELSE
  1210.                     LOCATE , POS(0) - 1
  1211.                 END IF
  1212.             END IF
  1213.             iyy% = CSRLIN: ixx% = POS(0)
  1214.             text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + MID$(text$, POS(0) - leftmargin% + hscroll% + 2)
  1215.             texttemp$ = MID$(text$, hscroll% + 1, rightmargin% - (leftmargin% - 1))
  1216.             LOCATE iyy%, leftmargin%: PRINT texttemp$ + STRING$((rightmargin% - (leftmargin% - 1)) - LEN(texttemp$), linecharacter%);
  1217.             LOCATE iyy%, ixx%
  1218.         END IF
  1219.     END IF
  1220.     RETURN '---------------------------------------------------------------------
  1221.  
  1222.     cutcopy:
  1223.     IF highlight% THEN
  1224.         IF mykey% = 99 OR mykey% = 120 THEN
  1225.             _CLIPBOARD$ = MID$(text$, starthighlight% - leftmargin%, highlight% - starthighlight% + 1)
  1226.         END IF
  1227.  
  1228.         IF mykey% = 88 OR mykey% = 120 OR mykey% = 8 OR mykey% = 21248 THEN ' ctrl + x (cut), delete, backspace.
  1229.             positioncursor% = starthighlight% - 1 - hscroll%
  1230.             texttemp$ = MID$(text$, 1, starthighlight% - leftmargin% - 1) + MID$(text$, highlight% - leftmargin% + 1)
  1231.             text$ = texttemp$
  1232.             hscroll% = hscroll% - ABS(highlight% - starthighlight%)
  1233.             IF hscroll% < 0 THEN hscroll% = 0
  1234.             LOCATE , positioncursor%
  1235.             GOSUB wash
  1236.         END IF
  1237.     END IF
  1238.     RETURN '---------------------------------------------------------------------
  1239.  
  1240.     PasteClipboard:
  1241.     IF LEN(text$) + LEN(_CLIPBOARD$) <= textmaxlength% THEN
  1242.         text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + _CLIPBOARD$ + MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  1243.         i% = LEN(_CLIPBOARD$) - (rightmargin% - POS(0))
  1244.         positioncursor% = POS(0) + LEN(_CLIPBOARD$) - 1 + CurAdvance%
  1245.         IF positioncursor% > rightmargin% THEN
  1246.             hscroll% = hscroll% + positioncursor% - rightmargin%
  1247.             positioncursor% = rightmargin%
  1248.         END IF
  1249.         LOCATE , positioncursor%
  1250.         GOSUB wash
  1251.     ELSE
  1252.         BEEP
  1253.     END IF
  1254.     RETURN '---------------------------------------------------------------------
  1255.  
  1256.     InsertOverwrite:
  1257.     IF overwrite% = 0 THEN
  1258.         overwrite% = -1
  1259.         LOCATE , , 1, 7, 30
  1260.     ELSE
  1261.         overwrite% = 0
  1262.         LOCATE , , 1, 7, 7
  1263.     END IF
  1264.     RETURN
  1265.     ' End Key Controls-------------------------------------------------------
  1266.  
  1267.     mouseroutine:
  1268.     DO ' Falk loop
  1269.         IF shiftclick% THEN
  1270.             IF shiftclick% > 0 THEN mykey% = 19712: shiftclick% = shiftclick% - 1 ELSE mykey% = 19200: shiftclick% = shiftclick% + 1
  1271.             EXIT DO ' To Return
  1272.         END IF
  1273.  
  1274.         IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN shift% = -1 ELSE shift% = 0
  1275.  
  1276.         IF my% > margin.t + page.h OR my% <= margin.t THEN
  1277.             IF my% > margin.t + page.h + 2 AND hlf% THEN ' Unhighlight file in display window.
  1278.                 j% = -999: GOSUB highlightfile ' hlf% is in statement above
  1279.                 tabx% = 2
  1280.                 LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' Move to text input field.
  1281.             END IF
  1282.  
  1283.             GOTO 102
  1284.             IF NOT drag% THEN
  1285.                 IF my% = W1% AND mx% = W2% + W4% - 2 THEN
  1286.                     IF closepop% = 0 THEN
  1287.                         LOCATE , , 0
  1288.                         IF hlf% THEN j% = -999: GOSUB highlightfile
  1289.                         IF oldsmode2 THEN ' doctype dropdown menu is open.
  1290.                         ELSE
  1291.                             GOSUB clearbuttons: tabx% = 2
  1292.                         END IF
  1293.                         LOCATE W1% + W3% - 4 - 3, W2% + 15
  1294.                         GOSUB wash
  1295.                         COLOR 15, 4
  1296.                         LOCATE W1%, W2% + W4% - 2
  1297.                         PRINT "x";
  1298.                         closepop% = -1
  1299.                         LOCATE W1% + W3% - 4 - 3, W2% + 15, 1
  1300.                         COLOR textfg%, textbk%
  1301.                     END IF
  1302.                 ELSE
  1303.                     IF closepop% THEN
  1304.                         iyy% = CSRLIN: ixx% = POS(0)
  1305.                         closepop% = 0
  1306.                         COLOR 15, 1
  1307.                         LOCATE W1%, W2% + W4% - 2, 0
  1308.                         PRINT "x";
  1309.                         LOCATE iyy%, ixx%, 1
  1310.                         COLOR textfg%, textbk%
  1311.                     END IF
  1312.                 END IF
  1313.  
  1314.                 SELECT CASE SMODE
  1315.                     CASE 3 ' doctypedropdown menu open.
  1316.                         FOR i% = 1 TO UBOUND(doctype$)
  1317.                             IF my% = doctypey%(i%) AND mx% >= ABS(doctypex%(i%)) AND mx% < ABS(doctypex%(i%)) + LEN(doctype$(i%)) THEN
  1318.                                 IF doctypex%(i%) > 0 THEN
  1319.                                     COLOR 0, 3: LOCATE doctypey%(i%), doctypex%(i%), 0
  1320.                                     PRINT doctype$(i%);
  1321.                                     doctypex%(i%) = -doctypex%(i%)
  1322.                                     COLOR textfg%, textbk%
  1323.                                 END IF
  1324.                             ELSE
  1325.                                 IF doctypex%(i%) < 0 THEN
  1326.                                     doctypex%(i%) = ABS(doctypex%(i%))
  1327.                                     iyy% = CSRLIN: ixx% = POS(0)
  1328.                                     COLOR 7, 0: LOCATE doctypey%(i%), doctypex%(i%), 0
  1329.                                     PRINT doctype$(i%);
  1330.                                     LOCATE iyy%, ixx%, 0
  1331.                                     COLOR textfg%, textbk%
  1332.                                 END IF
  1333.                             END IF
  1334.                         NEXT
  1335.                     CASE ELSE
  1336.                         j% = 0
  1337.                         FOR i% = 1 TO UBOUND(formbutton$)
  1338.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% < ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1339.                                 IF formbuttonx%(i%) > 0 THEN
  1340.                                     iyy% = CSRLIN: ixx% = POS(0)
  1341.                                     COLOR 0, 3: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1342.                                     PRINT formbutton$(i%);
  1343.                                     formbuttonx%(i%) = -formbuttonx%(i%)
  1344.                                     j% = -1
  1345.                                     IF iyy% = W1% + W3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1346.                                     COLOR textfg%, textbk%
  1347.                                 END IF
  1348.                             ELSE
  1349.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1350.                                 iyy% = CSRLIN: ixx% = POS(0)
  1351.                                 COLOR 1, 7: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1352.                                 PRINT formbutton$(i%);
  1353.                                 IF iyy% = W1% + W3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1354.                                 COLOR textfg%, textbk%
  1355.                             END IF
  1356.                             IF formbuttonx%(i%) < 0 THEN j% = -1 ' Used below to designate a button is highlighted.
  1357.                         NEXT
  1358.  
  1359.                         IF tabx% >= 3 AND tabx% <= 5 AND j% = 0 THEN
  1360.                             COLOR 0, 3: LOCATE formbuttony%(tabx% - 2), ABS(formbuttonx%(tabx% - 2)), 0
  1361.                             PRINT formbutton$(tabx% - 2);
  1362.                         END IF
  1363.                 END SELECT
  1364.             END IF
  1365.  
  1366.             102
  1367.             IF mb.l THEN
  1368.                 IF closepop% THEN action$ = "close": EXIT DO ' To Return
  1369.  
  1370.                 IF NOT drag% THEN
  1371.                     IF oldsmode2 THEN ' Doctype dropdown menu is open.
  1372.                         FOR i% = 1 TO UBOUND(doctype$)
  1373.                             IF doctypex%(i%) < 0 THEN
  1374.                                 GOSUB close_doctype_dropdown
  1375.                                 GOSUB doctype_selected
  1376.                                 doctypex%(i%) = ABS(doctypex%(i%))
  1377.                             END IF
  1378.                         NEXT
  1379.                     END IF
  1380.  
  1381.                     FOR i% = 1 TO UBOUND(formbutton$) ' Check control buttons.
  1382.                         IF formbuttonx%(i%) < 0 THEN
  1383.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% <= ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1384.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1385.                                 SOUND 1000, .1
  1386.                                 LOCATE , , 0
  1387.                                 SELECT CASE i%
  1388.                                     CASE 1 ' Open doctype dropdown menu.
  1389.                                         GOSUB popfiletypes
  1390.                                     CASE 2 ' Open button.
  1391.                                         SELECT CASE config%
  1392.                                             CASE 1
  1393.                                                 action$ = "open file"
  1394.                                             CASE 2
  1395.                                                 action$ = "save as"
  1396.                                         END SELECT
  1397.                                         '''myfile$ = text$
  1398.                                         EXIT DO ' To Return.
  1399.                                     CASE 3 ' Cancel button.
  1400.                                         action$ = "cancel": EXIT DO ' To Return.
  1401.                                 END SELECT
  1402.                             END IF
  1403.                         END IF
  1404.                     NEXT
  1405.                 END IF
  1406.  
  1407.                 IF mx% > leftmargin% + LEN(text$) THEN EXIT DO ' To Return
  1408.  
  1409.                 IF click_l% >= 0 THEN
  1410.                     click_l% = -1
  1411.                     IF highlight% AND NOT shift% THEN GOSUB wash
  1412.                 END IF
  1413.  
  1414.                 IF shift% THEN
  1415.                     SELECT CASE mx%
  1416.                         CASE IS > POS(0): mykey% = 19712: shiftclick% = mx% - POS(0) - 1
  1417.                         CASE IS = POS(0): mykey% = 0
  1418.                         CASE IS < POS(0): mykey% = 19200: shiftclick% = mx% - POS(0) + 1
  1419.                     END SELECT
  1420.                     IF mykey% THEN EXIT DO ' To Return
  1421.                 END IF
  1422.             ELSE
  1423.                 IF click_l% = -1 THEN click_l% = 1: drag% = 0
  1424.             END IF
  1425.  
  1426.             IF click_l% = -1 THEN
  1427.                 IF mx% = POS(0) THEN
  1428.                     drag% = -1
  1429.                 ELSE
  1430.                     IF my% = CSRLIN AND drag% = 0 THEN
  1431.                         LOCATE my%, mx% ' Click in input field.
  1432.                     END IF
  1433.                 END IF
  1434.             END IF
  1435.  
  1436.             IF drag% THEN
  1437.                 shift% = -1
  1438.                 SELECT CASE mx%
  1439.                     CASE IS > POS(0): mykey% = 19712: IF mx% > rightmargin% THEN _DELAY .05
  1440.                     CASE IS = POS(0): mykey% = 0
  1441.                     CASE IS < POS(0): mykey% = 19200: IF mx% < leftmargin% THEN _DELAY .05
  1442.                 END SELECT
  1443.             END IF
  1444.  
  1445.             EXIT DO ' To Return
  1446.  
  1447.         ELSE
  1448.  
  1449.             DO
  1450.                 IF SMODE = 3 THEN EXIT DO
  1451.                 IF my% > margin.t AND my% - margin.t <= page.h AND mx% > margin.l AND mx% < margin.l + page.w THEN
  1452.                     tabx% = 1: GOSUB clearbuttons
  1453.                     IF mb.l AND NOT lbdown% THEN
  1454.                         IF my% = CSRLIN THEN ' File Selected
  1455.                             lbdown% = -1
  1456.                             GOSUB fileselected
  1457.                             EXIT DO
  1458.                         END IF
  1459.                     ELSE
  1460.                         IF mb.l = 0 THEN lbdown% = 0
  1461.                     END IF
  1462.  
  1463.                     IF hlf% = 0 THEN
  1464.                         row = my% - margin.t: j% = 0: GOSUB highlightfile
  1465.                     ELSEIF oldmy% > my% AND my% - margin.t <= page.h AND row > 1 THEN
  1466.                         i% = my%: IF i% - margin.t > 0 THEN
  1467.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1468.                             DO UNTIL CSRLIN <= i%
  1469.                                 row = row - 1: j% = 0: GOSUB highlightfile
  1470.                             LOOP
  1471.                         END IF
  1472.                     ELSEIF oldmy% AND oldmy% < my% AND row < page.h THEN
  1473.                         i% = my%: IF i% - margin.t <= page.h THEN
  1474.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1475.                             DO UNTIL CSRLIN >= i%
  1476.                                 row = row + 1: j% = 0: GOSUB highlightfile
  1477.                             LOOP
  1478.                         END IF
  1479.                     END IF
  1480.                 END IF
  1481.  
  1482.                 ' ------------------------------------Mouse----------------------------------
  1483.  
  1484.                 IF locked% < 0 THEN ' Mouse effects on mouse lock. key press effects are determined at inkey$ input, as key variable cannot be evaluated here, due to b$ = "" manipulations in the keypress routine.
  1485.                     IF mb.l OR mb.r OR mb.m THEN locked% = 0
  1486.                 END IF
  1487.  
  1488.                 IF mb.w THEN ' Determine if wheel is being used to scroll highlighted or unhighlighted text.
  1489.                     GOSUB clearbuttons
  1490.                     tabx% = 1 ' Reset tab index when mouse wheel is engaged.
  1491.                     locked% = 2 ' 2 is lock scrollbar, no highlighting permitted.
  1492.                 END IF
  1493.  
  1494.                 IF mb.l AND locked% <> 1 OR mb.w AND locked% <> -1 THEN
  1495.                     tabx% = 1
  1496.                     IF mb.l THEN GOSUB clearbuttons
  1497.                     ' Scrollbar routine.
  1498.                     IF mx% >= scrb.l - 1 AND mx% <= scrb.l + 1 AND my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 THEN draglock% = -1
  1499.  
  1500.                     IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR mx% = scrb.l AND scrb.s <> 0 AND my% >= scrb.t AND my% <= scrb.b AND mb.w = 0 OR scrbardrag% <> 0 AND my% > scrb.t AND my% < scrb.b AND mb.w = 0 OR mb.w > 0 AND scrb.x + scrb.s < scrb.h OR mb.w < 0 AND scrb.x > 0 THEN ' Mouse on scrollbar, doing a bar cursor drag or using the scroll wheel.
  1501.                         locked% = 2 ' Locked on scrollbar
  1502.                         IF my% = scrb.t AND scrb.x > 0 OR my% = scrb.b AND scrb.x + scrb.s < scrb.h OR mb.w <> 0 AND scr + page.h < noe THEN ' Mouse on a scrollbar arrow.
  1503.                             IF my% = scrb.t AND mb.w = 0 OR mb.w < 0 THEN scrb.x = scrb.x - 1: h% = -1 ELSE scrb.x = scrb.x + 1: h% = -2 ' Top or bottom arrow.
  1504.                             IF mb.w = 0 THEN delay.on! = .15
  1505.                             j% = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1506.  
  1507.                             IF j% >= 0 THEN ' Condition exists unless j% is negative such as doc is blank and mouse wheel is rolled downward.
  1508.                                 scrb.i = j%
  1509.  
  1510.                                 scr = scrb.i
  1511.  
  1512.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr) ' Positions scrollbar box.
  1513.  
  1514.                                 GOSUB scrollscrn
  1515.                             END IF
  1516.  
  1517.                         ELSEIF my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 AND scrbardrag% = 0 THEN ' Mouse on scrollbar block.
  1518.                             scrbardrag% = -1: scrb.adjust = (my% - (scrb.t + 1)) - scrb.x
  1519.                         ELSEIF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% > scrb.t AND my% < scrb.b THEN ' Mouse on scrollbar between scrollbar arrow and cursor.
  1520.                             IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% - (scrb.t + 1) - scrb.adjust >= 0 AND my% - (scrb.t + 1) + scrb.s - scrb.adjust <= scrb.h AND scrbardrag% <> -1 OR scrbardrag% = 0 THEN
  1521.                                 IF scrbardrag% = 0 THEN ' No drag, so adjust for cursor length for a click inside the scrollbar above or below the current scrollbar cursor position.
  1522.                                     IF my% - (scrb.t + 1) > scrb.x THEN
  1523.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x - 1: h% = -1
  1524.                                     ELSE
  1525.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x + 1: h% = -2
  1526.                                     END IF
  1527.                                 END IF
  1528.                                 scrb.x = my% - (scrb.t + 1) - scrb.adjust
  1529.                                 scrb.i = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1530.  
  1531.                                 scr = scrb.i
  1532.  
  1533.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1534.  
  1535.                                 GOSUB scrollscrn
  1536.  
  1537.                             ELSE ' Scrollbar is at top or bottom and mouse cursor is moving vertically along the scrollbar cursor. This allows the variable to readjust.
  1538.                                 IF mx% = scrb.l THEN scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1539.                             END IF
  1540.                         END IF
  1541.                         ' =======================================================
  1542.  
  1543.                     END IF
  1544.  
  1545.                     IF delay.on! THEN ' Scrollbar delay.
  1546.                         _DELAY delay.on!
  1547.                         delay.on! = 0 ' Toggle off.
  1548.                     END IF
  1549.  
  1550.                 ELSE
  1551.                     scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1552.                     IF locked% = 2 AND mb.l = 0 THEN locked% = 0
  1553.                 END IF
  1554.                 EXIT DO
  1555.             LOOP
  1556.         END IF
  1557.         EXIT DO
  1558.     LOOP
  1559.     RETURN '---------------------------------------------------------------------
  1560.  
  1561.     file_display_keys:
  1562.     DO '
  1563.         IF CSRLIN >= margin.t AND CSRLIN <= margin.t + page.h AND mb.l = 0 OR autokey% THEN
  1564.             ' Key commands for form input line.
  1565.             IF autokey% = 0 THEN b$ = INKEY$ ELSE b$ = MID$(b$, 3): IF LEN(b$) = 2 THEN autokey% = 0
  1566.             IF LEN(b$) THEN
  1567.                 IF b$ = CHR$(9) THEN GOSUB tabkey: b$ = "": null$ = INKEY$: EXIT DO ' tabx% assignment.
  1568.                 SELECT CASE MID$(b$, 1, 2) ' File directory window keys.
  1569.                     CASE CHR$(0) + "H"
  1570.                         IF row > 1 THEN
  1571.                             row = row - 1
  1572.                             LOCATE margin.t + row, margin.l + 1
  1573.                             j% = 0: GOSUB highlightfile
  1574.                         ELSE
  1575.                             IF scr > 0 THEN
  1576.                                 scr = scr - 1
  1577.                                 GOSUB scrollscrn
  1578.                                 j% = 0: GOSUB highlightfile
  1579.                             END IF
  1580.                         END IF
  1581.                     CASE CHR$(0) + "P"
  1582.                         IF tabx% <> 3 THEN
  1583.                             IF row < page.h THEN
  1584.                                 row = row + 1
  1585.                                 j% = 0: GOSUB highlightfile
  1586.                                 LOCATE margin.t + row, margin.l + 1
  1587.                             ELSE
  1588.                                 IF scr + page.h < noe THEN
  1589.                                     scr = scr + 1
  1590.                                     GOSUB scrollscrn
  1591.                                     j% = 0: GOSUB highlightfile
  1592.                                 END IF
  1593.                             END IF
  1594.                         ELSE
  1595.                             ' Arrow down key is highlighted by tabx%. Now open the doctype dropdown menu.
  1596.                             GOSUB popfiletypes
  1597.                         END IF
  1598.                     CASE CHR$(0) + "I"
  1599.                         autokey% = -1
  1600.                         LOCATE , margin.l + 1
  1601.                         k% = page.h - 1 + row - 2
  1602.                         FOR j% = 0 TO k%
  1603.                             b$ = b$ + CHR$(0) + "H"
  1604.                         NEXT
  1605.                         FOR j% = 1 TO row - 1
  1606.                             b$ = b$ + CHR$(0) + "P"
  1607.                         NEXT
  1608.                     CASE CHR$(0) + "Q"
  1609.                         autokey% = -1
  1610.                         LOCATE , margin.l + 1
  1611.                         k% = (page.h - 1) + (page.h - row) - 1
  1612.                         FOR j% = 0 TO k%
  1613.                             b$ = b$ + CHR$(0) + "P"
  1614.                         NEXT
  1615.                         FOR j% = 1 TO page.h - row
  1616.                             b$ = b$ + CHR$(0) + "H"
  1617.                         NEXT
  1618.                     CASE CHR$(0) + "w" ' Ctrl + Home
  1619.                         row = 1
  1620.                         IF scr > 0 THEN
  1621.                             scr = 0
  1622.                             h% = 0: GOSUB scrollscrn
  1623.                         END IF
  1624.                         LOCATE margin.t + 1, margin.l + 1
  1625.                         j% = 0: GOSUB highlightfile
  1626.                     CASE CHR$(0) + "u" ' Ctrl + End
  1627.                         IF noe > page.h THEN
  1628.                             row = page.h
  1629.                             scr = noe - row
  1630.                             LOCATE margin.t + 1, margin.l + 1
  1631.                             h% = 0: GOSUB scrollscrn
  1632.                             row = page.h
  1633.                             LOCATE margin.t + row, margin.l + 1
  1634.                             j% = 0: GOSUB highlightfile
  1635.                         ELSE
  1636.                             row = noe
  1637.                             LOCATE margin.t + row, margin.l + 1
  1638.                             j% = 0: GOSUB highlightfile
  1639.                         END IF
  1640.                     CASE CHR$(13)
  1641.                         GOSUB fileselected
  1642.                 END SELECT
  1643.             END IF
  1644.         ELSE
  1645.             null$ = INKEY$ ' Clear buffer
  1646.         END IF
  1647.         EXIT DO
  1648.     LOOP
  1649.  
  1650.     RETURN '---------------------------------------------------------------------
  1651.  
  1652.     '-------------------------------Nested Gosubs-----------------------------
  1653.  
  1654.     scrollscrn:
  1655.     FOR i% = 1 TO page.h
  1656.         LOCATE margin.t + i%, margin.l + 1
  1657.         PRINT x$(i% + scr);
  1658.     NEXT
  1659.     LOCATE row + margin.t, margin.l + 1
  1660.     IF hlf% AND LEN(b$) < 3 AND scrbardrag% = 0 THEN j% = 0: GOSUB highlightfile
  1661.  
  1662.     '''h% = 1: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1663.  
  1664.     RETURN '---------------------------------------------------------------------
  1665.  
  1666.     highlightfile:
  1667.     IF j% = -999 THEN ' Unhighlight text only.
  1668.         COLOR 7, 0
  1669.         LOCATE margin.t + hlf%, margin.l + 1, 0
  1670.         PRINT x$(hlf% + scr);
  1671.         hlf% = 0
  1672.     ELSE
  1673.         IF hlf% THEN
  1674.             LOCATE margin.t + hlf%, margin.l + 1, 0
  1675.             COLOR 7, 0: PRINT x$(hlf% + scr);
  1676.         END IF
  1677.         COLOR 1, 3
  1678.         LOCATE margin.t + row, margin.l + 1, 0
  1679.         PRINT x$(row + scr);
  1680.         hlf% = row
  1681.         COLOR c1%, c2%
  1682.     END IF
  1683.     RETURN '---------------------------------------------------------------------
  1684.  
  1685.     wash:
  1686.     starthighlight% = 0
  1687.     highlight% = 0
  1688.     iyy% = CSRLIN: ixx% = POS(0)
  1689.     COLOR textfg%, textbk%
  1690.     LOCATE , leftmargin%
  1691.     texttemp$ = MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1))
  1692.     PRINT texttemp$ + STRING$(rightmargin% - (leftmargin% - 1) - LEN(texttemp$), linecharacter%);
  1693.     LOCATE iyy%, ixx%
  1694.     RETURN '---------------------------------------------------------------------
  1695.  
  1696.     clearbuttons:
  1697.     iyy% = CSRLIN: ixx% = POS(0)
  1698.     FOR k% = 1 TO UBOUND(formbutton$)
  1699.         LOCATE formbuttony%(k%), ABS(formbuttonx%(k%)), 0
  1700.         COLOR 1, 7: PRINT formbutton$(k%);
  1701.         formbuttonx%(k%) = ABS(formbuttonx%(k%)) ' Remove button active (neg) designation.
  1702.     NEXT
  1703.     LOCATE iyy%, ixx%
  1704.     RETURN '---------------------------------------------------------------------
  1705.  
  1706.     displaybutton: ' Gosub parameters (i%)
  1707.     iyy% = CSRLIN: ixx% = POS(0)
  1708.     GOSUB clearbuttons ' Clear all buttons of highlighting first...
  1709.     IF i% < 0 THEN COLOR 0, 3 ELSE COLOR 1, 7
  1710.     IF tabx% THEN COLOR 0, 3
  1711.     IF i% <> 0 THEN
  1712.         LOCATE formbuttony%(ABS(i%)), ABS(formbuttonx%(ABS(i%))), 0
  1713.         PRINT formbutton$(ABS(i%));
  1714.         formbuttonx%(ABS(i%)) = -ABS(formbuttonx%(ABS(i%)))
  1715.     END IF
  1716.     LOCATE iyy%, ixx%
  1717.     RETURN '---------------------------------------------------------------------
  1718.  
  1719.     fileselected:
  1720.     IF noe THEN
  1721.         IF hlf% THEN j% = -999: GOSUB highlightfile
  1722.  
  1723.         text$ = xfull$(row + scr)
  1724.  
  1725.         IF LEFT$(text$, 2) = ".." OR LEFT$(text$, 1) = "[" THEN
  1726.             ' Ready to change diretories.
  1727.             IF LEFT$(text$, 2) = ".." THEN
  1728.                 CHDIR ".."
  1729.             ELSE
  1730.                 CHDIR MID$(text$, 2, LEN(text$) - 2)
  1731.             END IF
  1732.             action$ = "change dir"
  1733.         ELSE
  1734.             ' Text input line.
  1735.             COLOR 7, 0
  1736.             LOCATE W1% + W3% - 4 - 3, W2% + 15: PRINT SPACE$(W4% - 18); ' Blank it.
  1737.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1: PRINT MID$(text$, 1, W4% - 18); ' Display it.
  1738.             hlf% = 0
  1739.         END IF
  1740.     ELSE ' No files found in DIR to select.
  1741.         BEEP
  1742.     END IF
  1743.     RETURN '---------------------------------------------------------------------
  1744.  
  1745.     popfiletypes:
  1746.     LOCATE W1% + W3% - 4 - 3, W2% + 15, 0
  1747.     GOSUB wash
  1748.     oldsmode2 = SMODE
  1749.     SMODE = 3: PCOPY oldsmode2, SMODE: SCREEN 0, 0, SMODE, SMODE
  1750.     COLOR 8, 0: LOCATE W1% + 16, W2% + 15 - 1: PRINT CHR$(179);
  1751.     COLOR 1, 3: PRINT SPACE$(W4% - 21);
  1752.     LOCATE W1% + 16, W2% + 15
  1753.     COLOR 1, 3: PRINT doctype$(1);
  1754.     COLOR 8, 0: LOCATE W1% + 16, W2% + W4% - 4: PRINT CHR$(179);
  1755.     LOCATE W1% + 17, W2% + 14
  1756.     COLOR 8, 0: PRINT CHR$(179);
  1757.     COLOR 7, 0: PRINT SPACE$(W4% - 18);
  1758.     LOCATE W1% + 17, W2% + 15: PRINT doctype$(2);
  1759.     COLOR 8, 0: LOCATE , W2% + W4% - 4: PRINT CHR$(179);
  1760.     COLOR 8, 0: LOCATE W1% + 18, W2% + 14: PRINT CHR$(192); STRING$(W4% - 19, 196); CHR$(217);
  1761.     doctypey%(1) = W1% + 16: doctypex%(1) = W2% + 15
  1762.     doctypey%(2) = W1% + 17: doctypex%(2) = W2% + 15
  1763.     LOCATE W1% + 16, W2% + 15 ' Text input line.
  1764.     RETURN '---------------------------------------------------------------------
  1765.  
  1766.     doctype_selected:
  1767.     SELECT CASE i%
  1768.         CASE 1
  1769.             COLOR 7, 0: LOCATE W1% + 16, W2% + 15: PRINT SPACE$(W4% - 19); ' Leaves arrow down space.
  1770.             LOCATE W1% + 16, W2% + 15: PRINT doctype$(1);
  1771.  
  1772.             IF doctype$ <> doctype$(1) THEN
  1773.                 '''doctype$ = doctype$(1): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  1774.             END IF
  1775.  
  1776.             doctype$ = doctype$(1)
  1777.             IF doctype% = 2 THEN SWAP doctype$(1), doctype$(2)
  1778.             doctype% = 1
  1779.  
  1780.             LOCATE W1% + 16, w2 + W4% + 4 ' .txt or *.* all files arrow down button location.
  1781.             formbuttony%(1) = CSRLIN: formbuttonx%(1) = POS(0): formbutton$(1) = CHR$(25)
  1782.  
  1783.             i% = 1: GOSUB displaybutton
  1784.  
  1785.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' File name input field.
  1786.             COLOR textfg%, textbk%
  1787.         CASE 2
  1788.             COLOR 7, 0: LOCATE W1% + 16, W2% + 15: PRINT SPACE$(W4% - 19); ' Leaves arrow down space.
  1789.             LOCATE W1% + 16, W2% + 15: PRINT doctype$(2);
  1790.  
  1791.             IF doctype$ <> doctype$(2) THEN
  1792.                 '''doctype$ = doctype$(2): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  1793.             END IF
  1794.  
  1795.             doctype$ = doctype$(2)
  1796.             IF doctype% = 1 THEN SWAP doctype$(1), doctype$(2)
  1797.             doctype% = 2
  1798.  
  1799.             LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' File name input field.
  1800.             COLOR textfg%, textbk%
  1801.     END SELECT
  1802.  
  1803.     RETURN '---------------------------------------------------------------------
  1804.  
  1805.     close_doctype_dropdown:
  1806.     ' Note - Do not use i% in this routine. It would change a perviouly set value i one of the routines that calls this one.
  1807.     SMODE = oldsmode2: SCREEN 0, 0, SMODE, SMODE: oldsmode2 = 0
  1808.     LOCATE , , 0
  1809.     LOCATE W1% + 16, W2% + W4% - 4
  1810.     IF tabx% = 3 THEN COLOR 0, 3 ELSE COLOR 1, 7
  1811.     IF my% = CSRLIN AND mx% = POS(0) THEN COLOR 0, 3: formbuttonx%(1) = -formbuttonx%(1)
  1812.     PRINT formbutton$(1);
  1813.     LOCATE W1% + W3% - 4 - 3, W2% + 15, 1 ' File name input field.
  1814.     COLOR textfg%, textbk%
  1815.     REDIM doctypex%(UBOUND(doctype$)), doctypey%(UBOUND(doctype$))
  1816.     RETURN '---------------------------------------------------------------------
  1817.  
  1818.  
  1819. SUB find_string
  1820.     REDIM x$(20)
  1821.     margin.t = 5
  1822.     margin.l = 5
  1823.     dwidth = 68
  1824.     page.h = 6
  1825.     row = 1
  1826.     noe = 13
  1827.  
  1828.     x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  1829.     x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  1830.     x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  1831.     x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  1832.     x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  1833.     x$(6) = "" + CHR$(255) + CHR$(10)
  1834.     x$(7) = "Article I" + CHR$(10)
  1835.     x$(8) = "" + CHR$(255) + CHR$(10)
  1836.     x$(9) = "Section 1: Congress" + CHR$(10)
  1837.     x$(10) = "" + CHR$(255) + CHR$(10)
  1838.     x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  1839.     x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  1840.     x$(13) = "Representatives." + CHR$(10)
  1841.  
  1842.     GOSUB displaydoc
  1843.  
  1844.     DO
  1845.         DO
  1846.             _LIMIT 30
  1847.             b$ = INKEY$
  1848.             IF LEN(b$) THEN
  1849.                 SELECT CASE b$
  1850.                     CASE CHR$(27)
  1851.                         SYSTEM
  1852.                     CASE CHR$(0) + "H"
  1853.                         IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  1854.                     CASE CHR$(0) + "P"
  1855.                         IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  1856.                 END SELECT
  1857.             END IF
  1858.         LOOP
  1859.     LOOP
  1860.  
  1861.     displaydoc:
  1862.     COLOR 0, 7
  1863.     FOR i% = 1 TO page.h
  1864.         a1$ = SPACE$(dwidth)
  1865.         MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  1866.         LOCATE margin.t + i%, margin.l + 1
  1867.         PRINT a1$
  1868.     NEXT
  1869.     RETURN
  1870.  
  1871.     finder:
  1872.     FOR i% = 1 TO page.h
  1873.         a1$ = SPACE$(dwidth)
  1874.         MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  1875.  
  1876.         IF INSTR(LCASE$(a1$), find$) THEN
  1877.             COLOR 14, 4: seed% = 0
  1878.             DO UNTIL INSTR(seed%, LCASE$(a1$), find$) = 0
  1879.                 seed% = INSTR(seed%, LCASE$(a1$), find$)
  1880.                 LOCATE margin.t + i%, margin.l + seed%
  1881.                 PRINT MID$(a1$, INSTR(seed%, LCASE$(a1$), find$), LEN(find$));
  1882.                 seed% = seed% + LEN(find$)
  1883.             LOOP
  1884.         END IF
  1885.     NEXT
  1886.     COLOR 0, 7
  1887.     RETURN
  1888.  
  1889. SUB windowscreen (ENL%)
  1890.     IF displayfullscreen% = -1 THEN EXIT SUB
  1891.     WINXX1% = CSRLIN: WINYY1% = POS(1)
  1892.     winmode$ = "2"
  1893.  
  1894.     IF ENL% <> 0 THEN
  1895.         full = _FULLSCREEN
  1896.         IF full = 0 THEN
  1897.             SELECT CASE ENL%
  1898.                 CASE -1: IF SCRNSIZE% > 0 THEN ELSE EXIT SUB
  1899.                 CASE 1: IF SCRNSIZE% < 14 THEN ELSE EXIT SUB
  1900.             END SELECT
  1901.         ELSE
  1902.             EXIT SUB
  1903.         END IF
  1904.     END IF
  1905.  
  1906.     SCRNSIZE% = SCRNSIZE% + ENL%
  1907.  
  1908.     SELECT CASE winmode$
  1909.         CASE "1"
  1910.             full = _FULLSCREEN
  1911.             IF full <> 0 THEN _FULLSCREEN _OFF
  1912.             GOSUB ChangeFont
  1913.         CASE "2"
  1914.             full = _FULLSCREEN
  1915.             IF full <> 0 THEN _FULLSCREEN _OFF
  1916.             style$ = "MONOSPACE"
  1917.             fontsize% = SCRNSIZE% + 13
  1918.             IF fontsize% < 14 THEN winmode$ = ""
  1919.             IF fontsize% < 18 THEN style$ = style$ + ", BOLD"
  1920.             fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
  1921.             GOSUB ChangeFont
  1922.         CASE "3"
  1923.             GOSUB ChangeFont
  1924.             _FULLSCREEN _SQUAREPIXELS
  1925.             full = _FULLSCREEN
  1926.             IF full = 0 THEN GOSUB nofull
  1927.         CASE "4"
  1928.             GOSUB ChangeFont
  1929.             _FULLSCREEN _STRETCH
  1930.             full = _FULLSCREEN
  1931.             IF full = 0 THEN GOSUB nofull
  1932.     END SELECT
  1933.  
  1934.     LOCATE WINXX1%, WINYY1%
  1935.     EXIT SUB
  1936.  
  1937.     nofull:
  1938.     RETURN
  1939.  
  1940.     ChangeFont:
  1941.     IF winmode$ <> "2" THEN
  1942.         _FONT 16 'select inbuilt 8x16 default font
  1943.         currentf& = _FONT
  1944.     ELSE
  1945.         currentf& = _LOADFONT(fontpath$, fontsize%, style$)
  1946.         _FONT currentf&
  1947.     END IF
  1948.  
  1949.     IF currentf& <> f& AND f& <> defaultf& THEN _FREEFONT f&
  1950.     f& = currentf&
  1951.     RETURN
  1952.  
  1953.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #7 on: January 29, 2021, 02:37:54 am »
Ah, that helps. Your highlighting is definitely more sophisticated. What I've got doesn't wrap around lines breaks as-is. (One would have to change window size or wrap mode to get around that).

You can probably toss what I posted but thanks for the inspiration! This wouldn't have gotten done otherwise.
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #8 on: January 31, 2021, 03:05:17 pm »
Okay, so I've added a replace feature. There is some more work and beta testing needed, but I think I might have found a bug, or some weird thing I don't understand. It works, but if you want to know what I found, look in a new thread for the bug report part...

F3 now displays a Find / Replace, instead of the Replace window. I'll marry the two, later, after I see what this possible QB64 bug situation is.

Pete

Safe to use. This routine does not add, kill, or overwrite any files.

Code: QB64: [Select]
  1. enl% = 13: CALL windowscreen(enl%)
  2.  
  3.  
  4.     DIM SHARED mx%, my%, margin.t AS INTEGER, margin.l AS INTEGER
  5.     DIM SHARED w1%, w2%, w3%, w4%
  6.     DIM SHARED action$
  7.     DIM SHARED mb AS my_mb
  8.     DIM scrb AS my_scrb
  9.  
  10.     TYPE my_mb
  11.         l AS INTEGER
  12.         r AS INTEGER
  13.         m AS INTEGER
  14.         w AS INTEGER
  15.         drag AS INTEGER
  16.         dragon AS INTEGER
  17.     END TYPE
  18.  
  19.     TYPE my_scrb
  20.         t AS INTEGER
  21.         b AS INTEGER
  22.         l AS INTEGER
  23.         x AS INTEGER
  24.         i AS INTEGER
  25.         d AS INTEGER
  26.         h AS INTEGER
  27.         s AS INTEGER
  28.         opt AS INTEGER
  29.         adjust AS INTEGER
  30.     END TYPE
  31.  
  32.     DIM SHARED SMODE, passrightmargin%
  33.     REDIM SHARED formbuttony%(3), formbuttonx%(3), formbutton$(3)
  34.     REDIM button$(8)
  35.     COLOR 0, 7: CLS
  36.  
  37.     REDIM x$(20)
  38.     margin.t = 2
  39.     margin.l = 5
  40.     dwidth = 68
  41.     page.h = 6
  42.     row = 1
  43.     noe = 13
  44.  
  45.     x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  46.     x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  47.     x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  48.     x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  49.     x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  50.     x$(6) = "" + CHR$(255) + CHR$(10)
  51.     x$(7) = "Article I" + CHR$(10)
  52.     x$(8) = "" + CHR$(255) + CHR$(10)
  53.     x$(9) = "Section 1: Congress" + CHR$(10)
  54.     x$(10) = "" + CHR$(255) + CHR$(10)
  55.     x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  56.     x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  57.     x$(13) = "Representatives." + CHR$(10)
  58.     DIM SHARED pete, ifield%, noif%, ifrow%, change_initiate%
  59.     REDIM SHARED entry$(10), ifield$(10)
  60.  
  61.     COLOR 0, 7
  62.     GOSUB displaydoc
  63.  
  64.     DO
  65.         _LIMIT 30
  66.         IF b$ = CHR$(0) + CHR$(61) OR b$ = CHR$(0) + CHR$(65) THEN
  67.             IF b$ = CHR$(0) + CHR$(61) THEN pete = 1: noif% = 1 ELSE scr = 0: pete = 2: noif% = 2
  68.             GOSUB displaydoc
  69.             change_initiate% = -1: CALL popup(msg$, msg%, button$(), button%, button_index%, find$, config%) ' Note: find$ is pass by ref find$ becomes text$ in popup sub and returns text$ back to find$ here.
  70.             LOCATE , , 0
  71.         END IF
  72.  
  73.         IF LEN(action$) THEN
  74.             IF action$ <> "close" THEN
  75.                 SELECT CASE action$
  76.                     CASE "Whole Word" ' Default selection if Enter is used instead of a button.
  77.                         whole_word% = 1
  78.                         case_sensitive% = 0
  79.                     CASE "Whole/Case"
  80.                         whole_word% = 1
  81.                         case_sensitive% = 1
  82.                     CASE "Any Part"
  83.                         whole_word% = 0
  84.                         case_sensitive% = 0
  85.                     CASE "Any/Case"
  86.                         whole_word% = 0
  87.                         case_sensitive% = 1
  88.                 END SELECT
  89.  
  90.                 SELECT CASE config%
  91.                     CASE 2
  92.                         GOSUB finder
  93.                     CASE 3
  94.                         GOSUB replacer
  95.                     CASE ELSE
  96.                         CLS: PRINT "No config% assigned to this case. "; config%: END '''
  97.                 END SELECT
  98.             END IF
  99.             action$ = ""
  100.         END IF
  101.  
  102.         b$ = INKEY$
  103.         IF LEN(b$) THEN
  104.             SELECT CASE b$
  105.                 CASE CHR$(9)
  106.                     COLOR 7, 0: CLS: CLEAR: EXIT DO
  107.                 CASE CHR$(27)
  108.                     SYSTEM
  109.                 CASE CHR$(0) + "H"
  110.                     IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  111.                 CASE CHR$(0) + "P"
  112.                     IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  113.             END SELECT
  114.         END IF
  115.     LOOP
  116.  
  117. displaydoc:
  118. COLOR 0, 7
  119. FOR i% = 1 TO page.h
  120.     a1$ = SPACE$(dwidth)
  121.     MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  122.     LOCATE margin.t + i%, margin.l + 1
  123.     PRINT a1$
  124.  
  125. finder:
  126. IF case_sensitive% = 0 THEN
  127.     find$ = LCASE$(find$): findorig$ = find$
  128.     findorig$ = find$
  129.  
  130. IF LEN(findorig$) THEN
  131.     flag% = 0
  132.     FOR i% = 1 TO page.h
  133.         LOCATE margin.t + i%, margin.l + 1
  134.         a1$ = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  135.  
  136.         IF INSTR(find$, " ") THEN
  137.             IF RIGHT$(a1$, 1) <> " " THEN a2$ = a1$ + " " ELSE a2$ = a1$
  138.         ELSE
  139.             a2$ = a1$ ' No space for a solid line wrap around.
  140.         END IF
  141.  
  142.         IF INSTR(findorig$, " ") THEN
  143.             a2$ = a2$ + MID$(x$(i% + 1 + scr), 1, INSTR(x$(i% + 1 + scr), CHR$(10)) - 1)
  144.             a2% = -1
  145.         ELSE
  146.             a2% = 0
  147.         END IF
  148.  
  149.         SELECT CASE case_sensitive%
  150.             CASE 0 ' Not case sensitive.
  151.                 SELECT CASE whole_word%
  152.                     CASE 0 ' Part word and not case sensitive.
  153.                         IF INSTR(LCASE$(a2$), find$) THEN
  154.                             COLOR 14, 4: seed% = 0
  155.                             DO UNTIL INSTR(seed%, LCASE$(a2$), find$) = 0
  156.  
  157.                                 IF a2% THEN
  158.                                     k% = INSTR(seed%, LCASE$(a2$), find$)
  159.                                     IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  160.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  161.                                         find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  162.                                         flag% = 1
  163.                                     ELSE
  164.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  165.                                     END IF
  166.                                 ELSE
  167.                                     seed% = INSTR(seed%, LCASE$(a2$), find$)
  168.                                 END IF
  169.  
  170.                                 IF seed% <= LEN(a1$) THEN
  171.                                     LOCATE margin.t + i%, margin.l + seed%
  172.                                     PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  173.                                     seed% = seed% + LEN(find$)
  174.  
  175.                                     IF flag% THEN
  176.                                         SELECT CASE flag%
  177.                                             CASE 2
  178.                                                 flag% = 0: find$ = findorig$
  179.                                             CASE 1
  180.                                                 flag% = 2
  181.                                                 find$ = MID$(findorig$, LEN(find$) + 2)
  182.                                                 seed% = 0
  183.                                                 EXIT DO
  184.                                         END SELECT
  185.                                     END IF
  186.                                 ELSE
  187.                                     EXIT DO
  188.                                 END IF
  189.                             LOOP
  190.                         END IF
  191.  
  192.                     CASE 1 ' Whole word and not case sensitive.
  193.                         seed% = 0: COLOR 14, 4
  194.                         WHILE INSTR(seed%, LCASE$(a2$), find$)
  195.                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  196.  
  197.                             IF seed% - 1 = 0 OR MID$(LCASE$(a2$), seed% - 1, 1) = " " THEN
  198.                                 IF INSTR(".,;:?!}]) ", MID$(LCASE$(a2$), seed% + LEN(find$), 1)) THEN
  199.  
  200.                                     IF a2% THEN
  201.                                         k% = INSTR(seed%, LCASE$(a2$), find$)
  202.                                         IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  203.                                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  204.                                             find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  205.                                             flag% = 1
  206.                                         ELSE
  207.                                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  208.                                         END IF
  209.                                     ELSE
  210.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  211.                                     END IF
  212.  
  213.                                     IF seed% <= LEN(a1$) THEN
  214.                                         LOCATE margin.t + i%, margin.l + seed%
  215.                                         PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  216.                                         seed% = seed% + LEN(find$)
  217.  
  218.                                         IF flag% THEN
  219.                                             SELECT CASE flag%
  220.                                                 CASE 2
  221.                                                     flag% = 0
  222.                                                     find$ = findorig$
  223.                                                 CASE 1
  224.                                                     flag% = 2
  225.                                                     find$ = MID$(findorig$, LEN(find$) + 2)
  226.                                                     seed% = 0
  227.                                                     EXIT WHILE
  228.                                             END SELECT
  229.                                         END IF
  230.                                     ELSE
  231.                                         EXIT WHILE
  232.                                     END IF
  233.  
  234.                                 END IF
  235.                             END IF
  236.  
  237.                             seed% = seed% + LEN(find$)
  238.  
  239.                         WEND
  240.  
  241.                 END SELECT
  242.  
  243.             CASE 1 ' Case sensitive
  244.                 SELECT CASE whole_word%
  245.                     CASE 0 ' Part word and case sensitive.
  246.                         seed% = 0: COLOR 14, 4
  247.                         WHILE INSTR(seed%, a2$, find$)
  248.                             seed% = INSTR(seed%, a2$, find$)
  249.  
  250.                             IF a2% THEN
  251.                                 k% = INSTR(seed%, a2$, find$)
  252.                                 IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  253.                                     seed% = INSTR(seed%, a2$, find$)
  254.                                     find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  255.                                     flag% = 1
  256.                                 ELSE
  257.                                     seed% = INSTR(seed%, a2$, find$)
  258.                                 END IF
  259.                             ELSE
  260.                                 seed% = INSTR(seed%, a2$, find$)
  261.                             END IF
  262.  
  263.                             IF seed% <= LEN(a1$) THEN
  264.                                 LOCATE margin.t + i%, margin.l + seed%
  265.                                 PRINT MID$(a2$, INSTR(seed%, a2$, find$), LEN(find$));
  266.                                 seed% = seed% + LEN(find$)
  267.  
  268.                                 IF flag% THEN
  269.                                     SELECT CASE flag%
  270.                                         CASE 2
  271.                                             flag% = 0: find$ = findorig$
  272.                                         CASE 1
  273.                                             flag% = 2
  274.                                             find$ = MID$(findorig$, LEN(find$) + 2)
  275.                                             seed% = 0
  276.                                             EXIT WHILE
  277.                                     END SELECT
  278.                                 END IF
  279.                             ELSE
  280.                                 EXIT WHILE
  281.                             END IF
  282.  
  283.                             seed% = seed% + LEN(find$)
  284.  
  285.                         WEND
  286.  
  287.                     CASE 1 ' Whole word and case sensitive.
  288.                         seed% = 0: COLOR 14, 4
  289.                         WHILE INSTR(seed%, a2$, find$)
  290.                             seed% = INSTR(seed%, a2$, find$)
  291.  
  292.                             IF seed% - 1 = 0 OR MID$(a2$, seed% - 1, 1) = " " THEN
  293.                                 IF INSTR(".,;:?!}]) ", MID$(a2$, seed% + LEN(find$), 1)) THEN
  294.  
  295.                                     IF a2% THEN
  296.                                         k% = INSTR(seed%, a2$, find$)
  297.                                         IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  298.                                             seed% = INSTR(seed%, a2$, find$)
  299.                                             find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  300.                                             flag% = 1
  301.                                         ELSE
  302.                                             seed% = INSTR(seed%, a2$, find$)
  303.                                         END IF
  304.                                     ELSE
  305.                                         seed% = INSTR(seed%, a2$, find$)
  306.                                     END IF
  307.  
  308.                                     IF seed% <= LEN(a1$) THEN
  309.                                         LOCATE margin.t + i%, margin.l + seed%
  310.                                         PRINT MID$(a2$, INSTR(seed%, a2$, find$), LEN(find$));
  311.                                         seed% = seed% + LEN(find$)
  312.  
  313.                                         IF flag% THEN
  314.                                             SELECT CASE flag%
  315.                                                 CASE 2
  316.                                                     flag% = 0: find$ = findorig$
  317.                                                 CASE 1
  318.                                                     flag% = 2
  319.                                                     find$ = MID$(findorig$, LEN(find$) + 2)
  320.                                                     seed% = 0
  321.                                                     EXIT WHILE
  322.                                             END SELECT
  323.                                         END IF
  324.                                     ELSE
  325.                                         EXIT WHILE
  326.                                     END IF
  327.  
  328.                                 END IF
  329.                             END IF
  330.  
  331.                             seed% = seed% + LEN(find$)
  332.  
  333.                         WEND
  334.  
  335.                 END SELECT
  336.         END SELECT
  337.     NEXT
  338.  
  339. replacer:
  340. find$ = entry$(1)
  341. r$ = entry$(2)
  342. REDIM entry$(UBOUND(ifield$))
  343. a$ = ""
  344. FOR i = 1 TO noe
  345.     a$ = a$ + MID$(x$(i), 1, INSTR(x$(i), CHR$(10)) - 1)
  346. a$ = " " + a$: a$ = a$ + " "
  347.  
  348. ' parse a$
  349. seed% = 0: j = 0
  350. DO UNTIL INSTR(seed%, a$, find$) = 0
  351.     a$ = MID$(a$, 1, INSTR(seed%, a$, find$) - 1) + r$ + MID$(a$, INSTR(seed%, a$, find$) + LEN(find$))
  352.     seed% = seed% + LEN(find$)
  353.  
  354. a$ = MID$(a$, 2): a$ = MID$(a$, 1, LEN(a$) - 1)
  355. REDIM x$(LEN(a$))
  356.  
  357. DO UNTIL a$ = ""
  358.     x$ = MID$(a$, 1, dwidth)
  359.     IF LEN(x$) < dwidth THEN
  360.         j = j + 1: x$(j) = x$
  361.         a$ = ""
  362.         x$(j) = x$(j) + CHR$(10)
  363.     ELSEIF INSTR(x$, CHR$(255)) THEN
  364.         j = j + 1
  365.         IF LEFT$(x$, 1) = CHR$(255) THEN
  366.             x$(j) = MID$(x$, 1, 1)
  367.             a$ = MID$(a$, 2)
  368.         ELSE
  369.             x$(j) = MID$(x$, 1, INSTR(x$, CHR$(255)) - 1)
  370.             a$ = MID$(a$, INSTR(x$, CHR$(255)))
  371.         END IF
  372.         x$(j) = x$(j) + CHR$(10)
  373.     ELSEIF INSTR(x$, " ") = 0 THEN
  374.         j = j + 1: x$(j) = x$
  375.         a$ = MID$(a$, LEN(x$(j)) + 1)
  376.         x$(j) = x$(j) + CHR$(10)
  377.     ELSE
  378.         j = j + 1: x$(j) = MID$(x$, 1, _INSTRREV(x$, " "))
  379.         a$ = MID$(a$, LEN(x$(j)) + 1)
  380.         x$(j) = x$(j) + CHR$(10)
  381.     END IF
  382. noe = j
  383.  
  384.  
  385. GOSUB displaydoc
  386.  
  387. SUB popup (msg$, msg%, button$(), button%, button_index%, text$, config%)
  388.     DIM scrb AS my_scrb
  389.     STATIC doctype%
  390.  
  391.     SELECT CASE pete
  392.         CASE 1
  393.             config% = 2 ' Find
  394.             REDIM ifield$(1)
  395.             msg$ = ""
  396.             ifield% = 48 ' Input field length.
  397.             ifield$(1) = "Find:"
  398.             button% = 4: button_index% = 4
  399.             w1% = 0: w2% = 0: w3% = 0: w4% = 0
  400.             noif% = 1
  401.  
  402.         CASE 2
  403.             config% = 3 ' Find / Replace
  404.             REDIM ifield$(2)
  405.             msg$ = ""
  406.             ifield% = 48
  407.             ifield$(1) = "   Find:"
  408.             ifield$(2) = "Replace:"
  409.             button% = 4: button_index% = 4
  410.             w1% = 0: w2% = 0: w3% = 7: w4% = 0
  411.             noif% = 2
  412.     END SELECT
  413.  
  414.     REDIM button$(8), ifieldyy%(noif%), ifieldxx%(noif%)
  415.     button$(1) = "Yes": button$(2) = "No!"
  416.     button$(3) = "Retry": button$(4) = "Cancel"
  417.     button$(5) = "Whole Word": button$(6) = "Whole/Case": button$(7) = "Any Part": button$(8) = "Any/Case"
  418.     iyy% = CSRLIN: ixx% = POS(0)
  419.     IF w3% = 0 THEN w3% = 5 ' Min.
  420.  
  421.     IF w4% = 0 THEN ' Calculate forn container width
  422.         w4% = LEN(msg$) + 4 ' Min
  423.         FOR i% = 1 TO UBOUND(ifield$)
  424.             IF LEN(ifield$(i%)) + ifield% > w4% THEN w4% = LEN(ifield$(i%)) + ifield% + 6
  425.         NEXT
  426.     END IF
  427.  
  428.     IF w1% = 0 THEN
  429.         ' Auto-Center
  430.         w1% = _HEIGHT \ 2 - w3% \ 2 + .5
  431.         w2% = _WIDTH \ 2 - w4% \ 2 + .5
  432.     END IF
  433.  
  434.     SELECT CASE SMODE
  435.         CASE 0
  436.             oldsmode = SMODE: PCOPY 0, 1: SCREEN 0, 0, 1, 1: SMODE = 1
  437.         CASE 1
  438.             oldsmode = SMODE: PCOPY 1, 2: SCREEN 0, 0, 2, 2: SMODE = 2
  439.     END SELECT
  440.  
  441.     LOCATE w1%, w2%, 0 ' Cursor hide
  442.     FOR i = 1 TO w3%
  443.         A$ = ""
  444.         COLOR 15, 1
  445.         LOCATE , w2%
  446.         A$ = A$ + SPACE$(w4% - LEN(A$))
  447.         PRINT A$;
  448.         IF i <> 1 THEN
  449.             COLOR 1, 0: PRINT CHR$(176)
  450.         ELSE PRINT
  451.         END IF
  452.     NEXT i
  453.     LOCATE , w2% + 1
  454.     COLOR 1, 0: PRINT STRING$(w4%, CHR$(176));
  455.     COLOR 14, 1
  456.     LOCATE w1%, w2%
  457.     PRINT CHR$(218); STRING$(w4% - 2, CHR$(196)); CHR$(191);
  458.     LOCATE w1% + w3% - 1, w2%
  459.     PRINT CHR$(192); STRING$(w4% - 2, CHR$(196)); CHR$(217);
  460.     FOR i = 1 TO w3% - 2
  461.         LOCATE w1% + i, w2%: PRINT CHR$(179);: LOCATE w1% + i, w2% + w4% - 1: PRINT CHR$(179);
  462.     NEXT i
  463.     LOCATE w1%, w2% + w4% - 2: COLOR 15, 1: PRINT "x";
  464.  
  465.     IF LEN(msg$) OR noif% THEN
  466.         SELECT CASE msg%
  467.             CASE -1 ' Message title.
  468.                 LOCATE w1% + 1, w2% + w4% \ 2 - LEN(msg$) \ 2
  469.                 PRINT msg$;
  470.             CASE 0 ' No message title. Usually used with input fields with limited vertical space.
  471.                 IF noif% THEN
  472.                     ifrow% = 1
  473.                     IF UBOUND(ifield$) > 1 THEN i% = 2: j% = UBOUND(ifield$) ELSE i% = 0: j% = 1 ' Where 2 is the spacing between input fields.
  474.                     FOR g% = 1 TO UBOUND(ifield$)
  475.                         LOCATE w1% + w3% \ 2 - j% + i% * (g% - 1), w2% + w4% \ 2 - (ifield% + LEN(ifield$(g%)) + 2) \ 2
  476.                         ifieldyy%(g%) = CSRLIN: ifieldxx%(g%) = POS(0) + LEN(ifield$(g%)) + 1 ' Start of text input line.
  477.                         COLOR 15, 1: PRINT ifield$(g%);
  478.                         COLOR 8, 1: PRINT CHR$(222);
  479.                         COLOR c2%, c1%: PRINT SPACE$(ifield%);
  480.                     NEXT
  481.                     passrightmargin% = POS(0) - 1 ' Sets right margin of the input field.
  482.                 END IF
  483.  
  484.                 IF button% THEN
  485.                     buttonyy% = CSRLIN + 2
  486.                     j% = 0
  487.                     FOR i% = 1 TO button%
  488.                         j% = j% + LEN(button$(button_index% + i%)) + 2
  489.                     NEXT
  490.                     LOCATE buttonyy%, w2% + w4% \ 2 - j% \ 2 - 1
  491.                     COLOR 0, 7
  492.                     mouselocator$ = STRING$(_WIDTH, "0"): mouselocator% = buttonyy%
  493.                     k% = 0
  494.  
  495.                     FOR i% = button_index% + 1 TO button_index% + button%
  496.                         IF k% THEN LOCATE , POS(0) + 2
  497.                         k% = k% + 1
  498.                         MID$(mouselocator$, POS(0)) = STRING$(LEN(button$(i%)) + 2, LTRIM$(STR$(k%)))
  499.                         PRINT SPACE$(LEN(button$(i%)) + 2);
  500.                     NEXT
  501.  
  502.                     LOCATE buttonyy%, w2% + w4% \ 2 - j% \ 2
  503.                     COLOR 0, 7
  504.                     k% = 0
  505.  
  506.                     ' Prints names on buttons.
  507.                     FOR i% = button_index% + 1 TO button_index% + button%
  508.                         IF k% THEN LOCATE buttonyy%, POS(0) + 4
  509.                         PRINT button$(i%);
  510.                         k% = k% + 1
  511.                     NEXT
  512.  
  513.                     IF pete THEN
  514.                         LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 1
  515.                         tabx% = 0: action$ = ""
  516.                         _KEYCLEAR: text$ = ""
  517.                     END IF
  518.  
  519.                     DO
  520.                         IF pete THEN
  521.                             inputfieldyy% = CSRLIN: inputfieldxx% = POS(0)
  522.  
  523.                             CALL textinput(text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb, noe, row, scr, config%, b$)
  524.  
  525.                         ELSE
  526.                             CALL user(b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  527.                         END IF
  528.  
  529.                         IF LEN(b$) THEN
  530.                             SELECT CASE b$
  531.                                 CASE CHR$(13)
  532.                                     IF pete THEN
  533.                                         action$ = "poll input lines": GOSUB tab_and_enter_fields: action$ = ""
  534.                                         IF LEN(b$) THEN ' b$ can be made null in the gosub above. This occurs when there are still more fields to fill in.
  535.                                             SELECT CASE tabx%
  536.                                                 CASE 1
  537.                                                     action$ = "Whole Word" ' F3 Find option.
  538.                                                 CASE 2
  539.                                                     action$ = "Whole/Case" ' F3 Find option.
  540.                                                     ' Find Function only.
  541.                                                 CASE 0, 3
  542.                                                     action$ = "Any Part" ' F3 Find option.
  543.                                                 CASE 4
  544.                                                     action$ = "Any/Case" ' F3 Find option.
  545.                                             END SELECT
  546.                                         END IF
  547.                                     ELSE
  548.                                         SELECT CASE tabx%
  549.                                             CASE 1
  550.                                                 IF button_index% = 0 THEN action$ = "yes"
  551.                                                 IF button_index% = 2 THEN action$ = "retry"
  552.                                             CASE 2
  553.                                                 IF button_index% = 0 THEN action$ = "no"
  554.                                                 IF button_index% = 2 THEN action$ = "abort"
  555.                                         END SELECT
  556.                                     END IF
  557.                                 CASE CHR$(27)
  558.                                     action$ = "close"
  559.                             END SELECT
  560.                         END IF
  561.  
  562.                         IF LEN(action$) THEN EXIT DO ''''' Newly added. Delete this if it causes problems.
  563.  
  564.                         IF my% = w1% AND mx% = w2% + w4% - 2 THEN
  565.                             IF closex% = 0 THEN closex% = -1: LOCATE my%, mx%: COLOR 15, 4: PRINT "x";
  566.                         ELSE
  567.                             IF closex% THEN closex% = 0: LOCATE w1%, w2% + w4% - 2: COLOR 7, 1: PRINT "x";
  568.                         END IF
  569.  
  570.                         IF bhl% THEN IF bhl% = 1 AND my% <> mouselocator% OR bhl% = 1 AND MID$(mouselocator$, mx%, 1) = "0" THEN tabx% = 0: bhl% = 0
  571.  
  572.                         IF b$ = CHR$(9) THEN GOSUB tab_and_enter_fields
  573.  
  574.                         IF oldmx% = mx% AND oldmy% = my% THEN i% = 0 ELSE i% = -1 ' Mouse has moved.
  575.                         IF b$ = CHR$(9) OR my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" AND i% THEN
  576.                             IF b$ = CHR$(9) THEN k% = tabx%: bhl% = 9 ELSE k% = VAL(MID$(mouselocator$, mx%, 1)): tabx% = k%: bhl% = 1
  577.                             IF pete THEN LOCATE , , 0 ' Hide cursor while making buttons.
  578.  
  579.                             IF h% AND h% <> tabx% THEN
  580.                                 entry$(ifrow%) = text$
  581.                                 GOSUB clear_button
  582.                             END IF
  583.  
  584.                             h% = k%: tabx% = h%
  585.  
  586.                             COLOR 0, 3
  587.                             LOCATE buttonyy%, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  588.                             PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  589.  
  590.                             IF pete THEN LOCATE inputfieldyy%, inputfieldxx%
  591.  
  592.                             _DELAY .15
  593.                         ELSE
  594.                             IF h% AND tabx% = 0 THEN
  595.                                 iyy% = CSRLIN: ixx% = POS(0)
  596.                                 IF pete THEN LOCATE , , 0
  597.                                 COLOR 0, 7
  598.                                 LOCATE buttonyy%, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  599.                                 PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  600.                                 LOCATE iyy%, ixx%
  601.                                 h% = 0: tabx% = 0
  602.                                 '''''''''''IF pete THEN LOCATE yy2, xx2, 1
  603.                             END IF
  604.                         END IF
  605.  
  606.                         ''' ss = CSRLIN: rr = POS(0): LOCATE 1, 41: PRINT mb.l, _MOUSEBUTTON(1): LOCATE ss, rr
  607.  
  608.                         IF mb.l THEN
  609.                             IF closex% THEN SOUND 1000, .1: closex% = 0: action$ = "close"
  610.                             IF my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" THEN
  611.                                 SOUND 1000, .1
  612.                                 SELECT CASE VAL(MID$(mouselocator$, mx%, 1))
  613.                                     CASE 1
  614.                                         IF button_index% = 0 THEN action$ = "yes"
  615.                                         IF button_index% = 2 THEN action$ = "retry"
  616.                                         IF button_index% = 4 THEN action$ = "Whole Word": GOSUB tab_and_enter_fields ' F3 Find option.
  617.                                     CASE 2
  618.                                         IF button_index% = 0 THEN action$ = "no"
  619.                                         IF button_index% = 2 THEN action$ = "abort"
  620.                                         IF button_index% = 4 THEN action$ = "Whole/Case": GOSUB tab_and_enter_fields ' F3 Find option.
  621.                                         ' Find Function only.
  622.                                     CASE 3
  623.                                         IF button_index% = 4 THEN action$ = "Any Part": GOSUB tab_and_enter_fields ' F3 Find option.
  624.                                     CASE 4
  625.                                         IF button_index% = 4 THEN action$ = "Any/Case": GOSUB tab_and_enter_fields ' F3 Find option.
  626.                                 END SELECT
  627.                             END IF
  628.  
  629.                             IF mb.l AND noif% > 1 THEN
  630.                                 IF mx% >= ifieldxx%(1) AND mx% <= ifieldxx%(1) + ifield% AND my% >= ifieldyy%(1) AND my% <= ifieldyy%(UBOUND(ifield$)) THEN
  631.                                     ''ss = CSRLIN: rr = POS(0): LOCATE 1, 1: PRINT i%; ifrow%; my%; ifieldyy%(ifrow%), ifieldxx%(1); mx%; ifieldxx%(1) + ifield%: LOCATE ss, rr
  632.                                     entry$(ifrow%) = text$
  633.                                     ifrow% = 0
  634.                                     FOR i% = 1 TO UBOUND(ifield$)
  635.                                         IF my% = ifieldyy%(i%) THEN ifrow% = i%: EXIT FOR
  636.                                     NEXT
  637.                                     IF ifrow% = 0 THEN CLS: PRINT "Error in ifrow%.": END '''
  638.                                     IF mx% <= ifieldxx%(ifrow%) + LEN(text$) THEN LOCATE my%, mx%, 1 ELSE LOCATE my%, ifieldxx%(ifrow%) + LEN(text$)
  639.                                     text$ = entry$(ifrow%)
  640.                                 END IF
  641.                             END IF
  642.  
  643.                         END IF
  644.  
  645.                         IF b$ = CHR$(9) THEN b$ = "" ''''''IS THIS EVEN NECESSARY ANYMORE???
  646.                         oldmy% = my%: oldmx% = mx%
  647.                     LOOP UNTIL LEN(action$) ''' An exit with len(action$) was added many lines up, so maybe this could be just loop?
  648.  
  649.                     SMODE = oldsmode: SCREEN 0, 0, SMODE, SMODE
  650.                 ELSE ' No buttons present.
  651.                     LOCATE w1% + w3% \ 2, w2% + w4% \ 2 - LEN(msg$) \ 2
  652.                     PRINT msg$;
  653.                 END IF
  654.  
  655.         END SELECT
  656.     END IF
  657.     LOCATE iyy%, ixx%
  658.     _KEYCLEAR
  659.     EXIT SUB
  660.  
  661.     clear_button:
  662.     COLOR 0, 7
  663.     LOCATE buttonyy%, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  664.     PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  665.     RETURN
  666.  
  667.     tab_and_enter_fields:
  668.     DO
  669.         IF tabx% = 0 AND ifrow% <= UBOUND(ifield$) OR tabx% = button% OR LEN(action$) THEN
  670.  
  671.             IF tabx% = button% THEN ' Last tab button is highlighted. Go back to input fields.
  672.                 h% = button%: GOSUB clear_button
  673.                 entry$(ifrow%) = text$
  674.                 tabx% = 0
  675.                 IF ifrow% = UBOUND(ifield$) THEN ifrow% = 1 ELSE ifrow% = ifrow% + 1
  676.                 text$ = entry$(ifrow%): _KEYCLEAR
  677.                 LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 1
  678.                 b$ = ""
  679.                 EXIT DO
  680.             END IF
  681.  
  682.             ' Remove any highlighting.
  683.             IF UBOUND(ifield$) >= 1 THEN
  684.                 LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 0
  685.                 COLOR 7, 0 '''''''''
  686.                 PRINT SPACE$(ifield%);
  687.                 LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%)
  688.                 COLOR 7, 0 ''''''''''''
  689.                 PRINT MID$(text$, 1, ifield%);
  690.                 entry$(ifrow%) = text$
  691.                 IF ifrow% + 1 > UBOUND(ifield$) THEN
  692.                     tabx% = 1 ' To reloop.
  693.                     entry$(ifrow%) = text$
  694.                 ELSE
  695.                     entry$(ifrow%) = text$
  696.                     ifrow% = ifrow% + 1
  697.                     text$ = entry$(ifrow%): _KEYCLEAR
  698.                     LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 1
  699.                     b$ = ""
  700.                     EXIT DO
  701.                 END IF
  702.             END IF
  703.             EXIT DO
  704.         ELSE
  705.             tabx% = tabx% + 1
  706.             EXIT DO
  707.         END IF
  708.     LOOP
  709.  
  710.     RETURN
  711.  
  712.  
  713. SUB user (b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  714.  
  715.     '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  716.  
  717.     DEF SEG = 0
  718.     IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN shift% = -1 ELSE shift% = 0
  719.     IF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN ctrl% = -1 ELSE ctrl% = 0
  720.     IF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN ctrlshift% = -1 ELSE ctrlshift% = 0
  721.  
  722.     IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  723.         alt% = -1: con_panel% = -1
  724.     ELSE
  725.         IF alt% THEN alt% = 0: con_panel% = 1
  726.     END IF
  727.     DEF SEG
  728.  
  729.     b$ = INKEY$
  730.  
  731.     mb.w = 0
  732.         mb.w = mb.w + _MOUSEWHEEL
  733.     WEND
  734.  
  735.     mb.l = _MOUSEBUTTON(1)
  736.     mb.r = _MOUSEBUTTON(2)
  737.     mx% = _MOUSEX
  738.     my% = _MOUSEY
  739.  
  740. SUB textinput (text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb AS my_scrb, noe AS INTEGER, row, scr, config%, b$)
  741.     STATIC initiate%
  742.     STATIC hscrollon%, hscroll%, textfg%, textbk%, highlightfg%, highlightbk%, leftmargin%, rightmargin%, noleadingspace%, textmaxlength%, linecharacter%, click_l%, drag%, shiftclick%, tabx%
  743.     STATIC starthighlight%, highlight%, overwrite%, CurAdvance%
  744.  
  745.     IF change_initiate% THEN change_initiate% = 0: initiate% = 0 ' Resets initiate%. Use when calling this sub to change settings like leftmargin% by zeroing static variable initiate%.
  746.     '''vartable% = 2: CALL setvariables(scrb, c1%, c2%, c1alt%, h1%, h2%, row, ins%, dwidth, dwidth2, menubar%)
  747.  
  748.     row = 1: tabx% = 2: thumb% = 0
  749.  
  750.     DO
  751.         IF NOT initiate% THEN ' Initiate textinput variables.
  752.             initiate% = -1
  753.             GOSUB initiate_variables
  754.         END IF
  755.  
  756.         ' --------------------POLL MOUSE--->
  757.         mb.w = 0
  758.         WHILE _MOUSEINPUT
  759.             mb.w = mb.w + _MOUSEWHEEL
  760.         WEND
  761.  
  762.         IF mb.w = 0 THEN
  763.             mx% = _MOUSEX ' Mouse column.
  764.             my% = _MOUSEY ' Mouse row.
  765.             mb.l = _MOUSEBUTTON(1)
  766.             mb.r = _MOUSEBUTTON(2)
  767.             mb.m = _MOUSEBUTTON(3)
  768.         END IF
  769.         '<----------------------------------
  770.         '''ss = CSRLIN: rr = POS(0): LOCATE 1, 1: PRINT mb.l, _MOUSEBUTTON(1): LOCATE ss, rr
  771.  
  772.         IF noleadingspace% THEN ' Remove leading spaces of any text entry in form.
  773.             IF LEFT$(text$, 1) = " " THEN
  774.                 DO UNTIL LEFT$(text$, 1) <> " " OR text$ = ""
  775.                     text$ = MID$(text$, 2)
  776.                     LOCATE , leftmargin%
  777.                     GOSUB wash
  778.                 LOOP
  779.             END IF
  780.         END IF
  781.  
  782.         '-------------------------------------------------------------------------
  783.         mykey% = _KEYHIT
  784.  
  785.         '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  786.  
  787.         IF mykey% = 0 THEN
  788.             IF my% <> oldmy% OR mx% <> oldmx% OR mb.l OR mb.w THEN
  789.                 GOSUB mouseroutine
  790.                 IF LEN(action$) THEN EXIT DO
  791.             END IF
  792.         END IF
  793.  
  794.         ''''''IF mykey% = 0 THEN GOSUB file_display_keys
  795.  
  796.         IF mykey% > 0 THEN
  797.             GOSUB form_input_keyroutine
  798.             IF LEN(action$) THEN EXIT DO
  799.         END IF
  800.         '-------------------------------------------------------------------------
  801.         oldmy% = my%: oldmx% = mx%
  802.         IF pete THEN EXIT DO
  803.     LOOP
  804.     EXIT SUB
  805.  
  806.     '---------------------------GOSUB STATEMENTS-----------------------------
  807.     initiate_variables:
  808.     PageWidth1% = 80
  809.     PageWidth2% = 25
  810.     Topmargin% = 3
  811.     BottomMargin% = PageWidth2% - UpFromBottom%
  812.     UpFromBottom% = 2
  813.     BlockSize% = 0: REM -1 = variable.
  814.     Headers% = 0: REM On -1 or Off 0
  815.     TabElements% = 1: REM Number of input fields horizontally arranged. - 1 indicates variable.
  816.     ColorPrompt% = 0: REM 0 = COLOR 7, 0. Set all foreground/background by background * 16 + background.
  817.     ColorResponse% = 0: REM 0 will use textfg% and textbk% as defaults; otherwise set all foreground/background by background * 16 + background.
  818.     RestrictInput% = -1: REM On -1 or Off 0. (Uses 3 data fields)
  819.     InputFieldLength% = 0: REM Set to a number to allow variable length fields; otherwise filed input length will be determined by rightmargin% - (leftmargin% - 1).
  820.     PromptColumn% = 1: REM Column where prompt starts. Use 0 if no prompts. Use -1 for  multiple prompts on same row.
  821.     ResponseColumn% = 0: REM Set to a number if using Spacer%; otherwise 0 = input field follows response.
  822.  
  823.     TableStyle% = 0: REM 0 = Prompt/Space/Input, 1 = Prompt/Colon+Space/Response, 2 = Prompt/Spacers/Response
  824.     Spacer$ = ".": REM Type of spacer character if spacers are used (Table Style 2).
  825.  
  826.     textfg% = 7
  827.     textbk% = 0
  828.     highlightfg% = 0
  829.     highlightbk% = 7
  830.     leftmargin% = POS(0): iyy% = CSRLIN
  831.     rightmargin% = passrightmargin%
  832.     textmaxlength% = 250
  833.     noleadingspace% = -1
  834.     linecharacter% = 255: REM Blank space
  835.  
  836.     IF textmaxlength% > rightmargin% - (leftmargin% - 1) THEN hscrollon% = -1
  837.     IF rightmargin% < leftmargin% THEN CLS: PRINT "Rightmargin% cannot be smaller than leftmargin%. Redo.": END
  838.     IF leftmargin% < 1 OR leftmargin% > 80 THEN CLS: PRINT "Leftmargin% is not within 1 - 80 range. Redo.": END
  839.     REM no longer valid with hscroll.IF textmaxlength% > rightmargin% - leftmargin% + 1 THEN CLS: PRINT "textmaxlength% cannot exceed rightmargin% - leftmargin% + 1. Redo.:end"
  840.     IF LEN(text$) > textmaxlength% THEN CLS: PRINT "Text length cannot start out larger than textmaxlength%. Redo.": END
  841.  
  842.     IF rightmargin% = leftmargin% AND textmaxlength% = 1 THEN
  843.         CurAdvance% = 0
  844.     ELSE
  845.         CurAdvance% = 1
  846.     END IF
  847.  
  848.     COLOR textfg%, textbk%
  849.     LOCATE iyy%, leftmargin%, 1, 7, 7
  850.     RETURN '-----------------------------------------------------------------
  851.  
  852.     form_input_keyroutine:
  853.     DO ' Falk loop.
  854.         IF SMODE = 3 THEN ' Doctype dropdown is open.
  855.             SELECT CASE mykey%
  856.                 CASE 9, 27 ' Close doctype dropdown.
  857.                     GOSUB close_doctype_dropdown
  858.                 CASE 18432 ' Arrow up.
  859.                     IF CSRLIN = w1% + 17 THEN
  860.                         LOCATE w1% + 17, w2% + 15
  861.                         COLOR 7, 0: PRINT doctype$(2);
  862.                         LOCATE w1% + 16, w2% + 15
  863.                         COLOR 1, 3: PRINT doctype$(1);
  864.                     END IF
  865.                 CASE 20480 ' Arrow Down
  866.                     IF CSRLIN = w1% + 16 THEN
  867.                         LOCATE w1% + 16, w2% + 15
  868.                         COLOR 7, 0: PRINT doctype$(1);
  869.                         LOCATE w1% + 17, w2% + 15
  870.                         COLOR 1, 3: PRINT doctype$(2);
  871.                     END IF
  872.                 CASE 13 ' Enter
  873.                     b$ = CHR$(13): EXIT DO
  874.                     IF CSRLIN = w1% + 16 THEN i% = 1 ELSE i% = 2
  875.                     GOSUB close_doctype_dropdown
  876.                     GOSUB doctype_selected ' (Gosub parameter i%)
  877.             END SELECT
  878.             mykey% = 0
  879.             EXIT DO ' To REturn
  880.         END IF
  881.  
  882.         ' Process text if cursor is on form field text input line.
  883.         IF pete OR CSRLIN = w1% + w3% - 4 - 3 OR mykey% = 27 OR mykey% = 13 OR mykey% = 9 THEN ELSE EXIT DO
  884.  
  885.         IF _KEYDOWN(100303) = -1 OR _KEYDOWN(100304) = -1 THEN
  886.             SELECT CASE mykey%
  887.                 CASE 18176, 20224, 19200, 19712, 21248, 20992
  888.                     shift% = -1
  889.             END SELECT
  890.         ELSE
  891.             IF NOT drag% AND shift% THEN shift% = 0
  892.         END IF
  893.  
  894.         IF _KEYDOWN(100305) = -1 OR _KEYDOWN(100306) = -1 THEN
  895.             SELECT CASE mykey%
  896.                 CASE 86, 118
  897.                     control% = -2
  898.                 CASE ELSE
  899.                     control% = -1
  900.             END SELECT
  901.         ELSE
  902.             control% = 0
  903.         END IF
  904.  
  905.         REM Evaluate changes to highlighted text, excluding cut/copy/paste
  906.         IF highlight% AND shift% = 0 AND control% <> -1 AND mykey% <> 8 AND mykey% < 21248 THEN
  907.             IF mykey% > 31 AND mykey% < 256 THEN
  908.                 GOSUB cutcopy
  909.             ELSE
  910.                 GOSUB wash
  911.             END IF
  912.         END IF
  913.  
  914.         IF shift% = -1 AND control% = 0 THEN
  915.             SELECT CASE mykey%
  916.                 CASE 19200
  917.                     GOSUB HighlightLeft
  918.  
  919.                 CASE 19712
  920.                     IF control% THEN
  921.                         GOSUB ctrlrt
  922.                     ELSE
  923.                         GOSUB HighlightRight
  924.                     END IF
  925.  
  926.                 CASE 18176
  927.                     GOSUB SelectToHome
  928.  
  929.                 CASE 20224
  930.                     GOSUB SelectToEnd
  931.  
  932.                 CASE 21248
  933.                     mykey% = 88: REM Convert Delete to Cut
  934.                     GOSUB cutcopy
  935.  
  936.                 CASE 20992
  937.                     GOSUB PasteClipboard
  938.             END SELECT
  939.  
  940.         ELSE
  941.  
  942.             SELECT CASE control%
  943.                 CASE 0
  944.                     SELECT CASE mykey%
  945.                         CASE 18176
  946.                             IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  947.  
  948.                         CASE 20224
  949.                             IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  950.  
  951.                         CASE 8, 21248: REM Backspace and Delete
  952.                             GOSUB BackspaceDelete
  953.  
  954.                         CASE 9: REM Tab
  955.                             IF pete THEN b$ = CHR$(9): EXIT DO ELSE GOSUB tabkey: mykey% = 0
  956.  
  957.                         CASE 13
  958.                             IF pete THEN b$ = CHR$(13): EXIT DO
  959.                             DO ' Single falks do/loop.
  960.                                 FOR i% = 1 TO UBOUND(formbutton$)
  961.                                     IF formbuttonx%(i%) < 0 THEN
  962.                                         SELECT CASE i%
  963.                                             CASE 1
  964.                                                 formbuttonx%(1) = ABS(formbuttonx%(1))
  965.                                                 GOSUB popfiletypes
  966.                                                 EXIT DO
  967.                                             CASE 2
  968.                                                 SELECT CASE config%
  969.                                                     CASE 1
  970.                                                         action$ = "open file"
  971.                                                     CASE 2
  972.                                                         action$ = "save as"
  973.                                                 END SELECT
  974.                                                 '''myfile$ = text$
  975.                                                 EXIT DO
  976.                                             CASE 3
  977.                                                 action$ = "cancel"
  978.                                                 EXIT DO
  979.                                         END SELECT
  980.                                     END IF
  981.                                 NEXT
  982.  
  983.                                 SELECT CASE tabx%
  984.                                     CASE 1 ' File selected from display window.
  985.                                         IF hlf% THEN
  986.                                             GOSUB fileselected
  987.                                             IF action$ = "change dir" THEN tabx% = 0: EXIT DO
  988.                                             tabx% = 2
  989.                                         ELSE
  990.                                             BEEP
  991.                                         END IF
  992.                                     CASE 2 ' Save or Open selected file.
  993.                                         IF LEN(text$) THEN
  994.                                             SELECT CASE config%
  995.                                                 CASE 1
  996.                                                     action$ = "open file"
  997.                                                 CASE 2
  998.                                                     action$ = "save as"
  999.                                             END SELECT
  1000.                                             tabx% = 2
  1001.                                             '''myfile$ = text$
  1002.                                             EXIT DO
  1003.                                         ELSE
  1004.                                             BEEP
  1005.                                         END IF
  1006.                                     CASE 3 ' Open doctype dropdown menu.
  1007.                                         GOSUB popfiletypes
  1008.                                     CASE 4 ' Save or Open selected file. Only occurs when tab selected then mouse goes on another button and then goes to a neutral position. In this case the variable is no longer negative and the loop above misses it.
  1009.                                         SELECT CASE config%
  1010.                                             CASE 1
  1011.                                                 action$ = "open file"
  1012.                                             CASE 2
  1013.                                                 action$ = "save as"
  1014.                                         END SELECT
  1015.                                         tabx% = 2
  1016.                                         EXIT DO
  1017.                                     CASE 5 ' Cancel
  1018.                                         action$ = "cancel": tabx% = 2
  1019.                                         EXIT DO
  1020.                                 END SELECT
  1021.                                 EXIT DO
  1022.                             LOOP
  1023.                             IF LEN(action$) THEN EXIT DO ' To Return
  1024.  
  1025.                         CASE 19200
  1026.                             GOSUB CursorLeft
  1027.  
  1028.                         CASE 19712
  1029.                             GOSUB CursorRight
  1030.  
  1031.                         CASE 18432
  1032.                             GOSUB CursorUp
  1033.  
  1034.                         CASE 20480
  1035.                             GOSUB CursorDown
  1036.  
  1037.                         CASE 18688
  1038.                             GOSUB PageUp
  1039.  
  1040.                         CASE 20736
  1041.                             GOSUB PageDown
  1042.  
  1043.                         CASE 27
  1044.                             IF pete THEN b$ = CHR$(27): EXIT DO
  1045.                             GOSUB wash
  1046.                             EXIT DO
  1047.  
  1048.                         CASE 20992: REM Insert
  1049.                             GOSUB InsertOverwrite
  1050.  
  1051.                         CASE ELSE
  1052.                             GOSUB DisplayText
  1053.                             IF flagtext% = -1 THEN flagtext% = 0: mykey% = 0
  1054.                     END SELECT
  1055.  
  1056.                     REM Control% = -1 or -2
  1057.                 CASE -1, -2
  1058.  
  1059.                     SELECT CASE mykey%
  1060.  
  1061.                         CASE 65, 97 ' A a
  1062.                             GOSUB SelectAll
  1063.  
  1064.                         CASE 67, 99, 88, 120 ' C c X x
  1065.                             GOSUB cutcopy
  1066.  
  1067.                         CASE 86, 118 ' V v
  1068.                             REM Paste
  1069.                             GOSUB PasteClipboard
  1070.  
  1071.                         CASE 19712
  1072.                             REM Cursor and arrow right
  1073.                             GOSUB ctrlrt
  1074.  
  1075.                         CASE 19200
  1076.                             REM Cursor and arrow left
  1077.                             GOSUB ctrllt
  1078.  
  1079.                         CASE 18176
  1080.                             GOSUB CursorHome ' Ctrl + Home
  1081.  
  1082.                         CASE 20224
  1083.                             GOSUB CursorEnd ' Ctrl + End
  1084.  
  1085.                         CASE ELSE
  1086.                             ' Do nothing.
  1087.  
  1088.                     END SELECT
  1089.             END SELECT
  1090.         END IF
  1091.         EXIT DO
  1092.     LOOP
  1093.     RETURN '-----------------------------------------------------------------
  1094.  
  1095.     ' Key Actions.
  1096.     tabkey:
  1097.     tabx% = tabx% + 1
  1098.     IF tabx% > 5 THEN tabx% = 1: GOSUB clearbuttons
  1099.  
  1100.     SELECT CASE tabx%
  1101.         CASE 1
  1102.             IF hlf% THEN j% = -999: GOSUB highlightfile
  1103.             i% = 0: GOSUB displaybutton
  1104.             LOCATE , , 0: row = 1: j% = 0: GOSUB highlightfile
  1105.         CASE 2
  1106.             IF hlf% THEN j% = -999: GOSUB highlightfile
  1107.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1
  1108.         CASE 3
  1109.             i% = -1: GOSUB displaybutton
  1110.         CASE 4
  1111.             i% = -2: GOSUB displaybutton
  1112.         CASE 5
  1113.             i% = -3: GOSUB displaybutton
  1114.     END SELECT
  1115.     b$ = "": mykey% = 0: null$ = INKEY$: k% = _KEYHIT ' Clear keyboard buffers
  1116.     RETURN '------------------------------------------------------------------
  1117.  
  1118.     CursorLeft:
  1119.     IF POS(0) > leftmargin% THEN
  1120.         LOCATE , POS(0) - CurAdvance%
  1121.     ELSE
  1122.         IF hscroll% THEN hscroll% = hscroll% - 1: GOSUB wash
  1123.     END IF
  1124.     RETURN '------------------------------------------------------------------
  1125.  
  1126.     CursorRight:
  1127.     IF POS(0) < rightmargin% THEN
  1128.         IF POS(0) + CurAdvance% <= leftmargin% - 1 + LEN(text$) + 1 THEN
  1129.             IF POS(0) < rightmargin% THEN LOCATE , POS(0) + CurAdvance%
  1130.         END IF
  1131.     ELSE
  1132.         IF hscrollon% THEN
  1133.             IF hscroll% + rightmargin% - (leftmargin% - 1) <= LEN(text$) THEN
  1134.                 hscroll% = hscroll% + 1
  1135.                 GOSUB wash
  1136.             END IF
  1137.         END IF
  1138.     END IF
  1139.  
  1140.     RETURN '------------------------------------------------------------------
  1141.  
  1142.     ctrllt:
  1143.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  1144.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  1145.     IF INSTR(texttemp$, " ") <> 0 THEN
  1146.         FOR ictrllt% = POS(0) - leftmargin% + 1 + hscroll% TO 1 STEP -1
  1147.             IF exitctrl% AND MID$(text$, ictrllt% - 1, 1) = " " THEN EXIT FOR
  1148.             IF MID$(text$, ictrllt%, 1) <> " " THEN exitctrl% = -1
  1149.             IF shift% THEN GOSUB HighlightLeft ELSE GOSUB CursorLeft
  1150.         NEXT
  1151.         exitctrl% = 0
  1152.     ELSE
  1153.         IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  1154.     END IF
  1155.     RETURN '---------------------------------------------------------------------
  1156.  
  1157.     ctrlrt:
  1158.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  1159.     texttemp$ = MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  1160.     IF INSTR(texttemp$, " ") <> 0 THEN
  1161.         FOR ictrlrt% = POS(0) - leftmargin% + 1 + hscroll% TO LEN(text$)
  1162.             IF MID$(text$, ictrlrt%, 1) <> " " THEN
  1163.                 IF exitctrl% THEN EXIT FOR
  1164.                 jctrlrt% = -1
  1165.             END IF
  1166.             IF MID$(text$, ictrlrt%, 1) = " " AND jctrlrt% THEN exitctrl% = -1
  1167.             IF shift% THEN GOSUB HighlightRight ELSE GOSUB CursorRight
  1168.         NEXT
  1169.         exitctrl% = 0: ictrlrt% = 0: jctrlrt% = 0
  1170.     ELSE
  1171.         IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  1172.     END IF
  1173.     RETURN '---------------------------------------------------------------------
  1174.  
  1175.     CursorHome:
  1176.     IF hscroll% <> 0 THEN hscroll% = 0: GOSUB wash
  1177.     LOCATE , leftmargin%
  1178.     RETURN '---------------------------------------------------------------------
  1179.  
  1180.     CursorEnd:
  1181.     IF hscrollon% THEN
  1182.         IF LEN(text$) > rightmargin% - (leftmargin% - 1) THEN
  1183.             hscroll% = LEN(text$) - (rightmargin% - (leftmargin% - 1)) + 1: REM + 1 allows for adding to end of text.
  1184.             GOSUB wash
  1185.         END IF
  1186.     END IF
  1187.     IF LEN(text$) + leftmargin% - 1 >= rightmargin% THEN
  1188.         LOCATE , rightmargin%
  1189.     ELSE
  1190.         LOCATE , leftmargin% - 1 + LEN(text$) + CurAdvance%
  1191.     END IF
  1192.     RETURN '---------------------------------------------------------------------
  1193.  
  1194.     CursorUp:
  1195.     REM PRINT "Cursor Up"
  1196.     RETURN
  1197.  
  1198.     CursorDown:
  1199.     REM PRINT "Cursor Down"
  1200.     IF formbuttonx%(1) < 0 OR tabx% = 3 THEN ' Opens the doctype dropdown menu.
  1201.         formbuttonx%(1) = ABS(formbuttonx%(1))
  1202.         GOSUB popfiletypes
  1203.     END IF
  1204.     RETURN '---------------------------------------------------------------------
  1205.  
  1206.     PageUp:
  1207.     REM PRINT "Page Up"
  1208.     RETURN
  1209.  
  1210.     PageDown:
  1211.     REM PRINT "Page Down"
  1212.     RETURN
  1213.  
  1214.     REM Highlighting -----------------------------------------------------------
  1215.     HighlightLeft:
  1216.     iyy% = CSRLIN: ixx% = POS(0)
  1217.     IF POS(0) > leftmargin% OR hscroll% THEN
  1218.  
  1219.         IF highlight% AND POS(0) >= highlight% - hscroll% THEN ' Unhighlighting left to right.
  1220.             ' Move back first and then calculate POS(0) - 1, below.
  1221.             IF highlight% = starthighlight% THEN
  1222.                 starthighlight% = 0: highlight% = 0
  1223.             ELSE
  1224.                 highlight% = POS(0) - 1 + hscroll% ' Diminishing.
  1225.             END IF
  1226.         ELSE ' Highlighting left to right.
  1227.             ' Calculate first and then move back. POS(0).
  1228.             IF highlight% = 0 THEN highlight% = POS(0) + hscroll%
  1229.             starthighlight% = POS(0) + hscroll%
  1230.         END IF
  1231.  
  1232.         IF POS(0) = leftmargin% AND hscroll% THEN hscroll% = hscroll% - 1 ' hscroll% is reduced after the calculations above.
  1233.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  1234.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  1235.  
  1236.         LOCATE iyy%, leftmargin%
  1237.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  1238.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  1239.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  1240.  
  1241.         IF ixx% - leftmargin% > 0 THEN ixx% = ixx% - 1 ' No moving cursor back when it is at left amrgin and scrolling text back.
  1242.         LOCATE iyy%, ixx%
  1243.         COLOR textfg%, textbk%
  1244.     END IF
  1245.     RETURN '---------------------------------------------------------------------
  1246.  
  1247.     HighlightRight:
  1248.     iyy% = CSRLIN: ixx% = POS(0)
  1249.     IF hscroll% + ixx% + 1 - leftmargin% <= LEN(text$) THEN
  1250.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  1251.  
  1252.         IF POS(0) >= starthighlight% - hscroll% THEN
  1253.             IF starthighlight% = 0 THEN starthighlight% = POS(0) + 1 + hscroll%
  1254.             highlight% = POS(0) + 1 + hscroll%
  1255.         ELSE
  1256.             IF starthighlight% = highlight% THEN
  1257.                 starthighlight% = 0: highlight% = 0
  1258.             ELSE
  1259.                 starthighlight% = POS(0) + 2 + hscroll%
  1260.             END IF
  1261.         END IF
  1262.  
  1263.         IF POS(0) = rightmargin% AND LEN(text$) - hscroll% > rightmargin% - leftmargin% THEN hscroll% = hscroll% + 1
  1264.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  1265.  
  1266.         LOCATE iyy%, leftmargin%
  1267.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  1268.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  1269.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  1270.         IF POS(0) = rightmargin% THEN PRINT SPACE$(1); ' Only used when highlighting past last character to include one blank space.
  1271.         IF ixx% < rightmargin% THEN ixx% = ixx% + 1
  1272.         LOCATE iyy%, ixx%
  1273.         COLOR textfg%, textbk%
  1274.     END IF
  1275.     RETURN '---------------------------------------------------------------------
  1276.  
  1277.     ClickhighLight:
  1278.     j% = 0
  1279.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  1280.     FOR i% = LEN(texttemp$) TO 1 STEP -1
  1281.         IF MID$(texttemp$, i%, 1) = " " AND j% THEN EXIT FOR ELSE j% = -1
  1282.     NEXT
  1283.     jClickhighLight% = LEN(texttemp$) - i% - 1
  1284.     invokestarthighlight% = POS(0) + hscroll% - (LEN(texttemp$) - i%) + 1
  1285.     FOR iClickhighLight% = 1 TO jClickhighLight%
  1286.         IF POS(0) = leftmargin% THEN EXIT FOR
  1287.         GOSUB CursorLeft
  1288.     NEXT
  1289.     shift% = -1
  1290.     GOSUB ctrlrt
  1291.     shift% = 0
  1292.     invokestarthighlight% = 0: iClickhighLight% = 0: jClickhighLight% = 0
  1293.     RETURN '---------------------------------------------------------------------
  1294.  
  1295.     SelectAll:
  1296.     highlight% = 0: starthighlight% = 0: REM These are not zeroed as a ctrl keys bypass remove highlighting
  1297.     GOSUB CursorHome
  1298.     GOSUB SelectToEnd
  1299.     RETURN '---------------------------------------------------------------------
  1300.  
  1301.     SelectToEnd:
  1302.     IF mspan% = 0 THEN mspan% = POS(0) - leftmargin% + 1 + LEN(text$)
  1303.     FOR iSelectToEnd% = 1 TO mspan%
  1304.         GOSUB HighlightRight
  1305.     NEXT
  1306.     mspan% = 0: iSelectToEnd% = 0
  1307.     RETURN '---------------------------------------------------------------------
  1308.  
  1309.     SelectToHome:
  1310.     IF mspan% = 0 THEN
  1311.         IF POS(0) = rightmargin% THEN
  1312.             mspan% = rightmargin% - (leftmargin% - 1) + hscroll%
  1313.         ELSE
  1314.             mspan% = POS(0) - leftmargin% + 1 + hscroll%
  1315.         END IF
  1316.     END IF
  1317.  
  1318.     FOR iSelectToHome% = 1 TO mspan%
  1319.         GOSUB HighlightLeft
  1320.     NEXT
  1321.     mspan% = 0: iSelectToHome% = 0
  1322.     RETURN '---------------------------------------------------------------------
  1323.  
  1324.     DisplayText:
  1325.     DO ' Falk loop.
  1326.         IF mykey% > 31 AND mykey% < 256 THEN
  1327.             COLOR 7, 0: LOCATE , , 1
  1328.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  1329.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 2)
  1330.             ELSE
  1331.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 1)
  1332.             END IF
  1333.  
  1334.             positioncursor% = POS(0)
  1335.  
  1336.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  1337.  
  1338.                 IF POS(0) - leftmargin% + hscroll% < textmaxlength% THEN
  1339.                     text$ = MID$(text$, 1, POS(0) + (hscroll%) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 2)
  1340.                 ELSE
  1341.                     flagtext% = -1: EXIT DO 'To Return
  1342.                 END IF
  1343.  
  1344.                 REM Evaluate Horizontal Scroll
  1345.                 IF POS(0) = rightmargin% THEN
  1346.                     hscroll% = hscroll% + 1
  1347.                 END IF
  1348.             ELSE
  1349.                 IF LEN(text$) < textmaxlength% THEN
  1350.                     text$ = MID$(text$, 1, POS(0) + hscroll% - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 1)
  1351.                     flagtext% = 0
  1352.                 ELSE
  1353.                     flagtext% = -1
  1354.                 END IF
  1355.  
  1356.                 IF flagtext% = -1 THEN EXIT DO ' To Return REM flagtext% is set to zero upon return and exit.
  1357.  
  1358.                 REM Evaluate Horizontal Scroll
  1359.                 IF hscrollon% AND POS(0) = rightmargin% THEN
  1360.                     hscroll% = hscroll% + 1
  1361.                 END IF
  1362.             END IF
  1363.  
  1364.             ' Print to form input line.-------------------------------------->
  1365.             LOCATE , leftmargin%: PRINT STRING$(rightmargin% - (leftmargin% - 1), linecharacter%);
  1366.             LOCATE , leftmargin%: PRINT MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1));
  1367.             ' <---------------------------------------------------------------
  1368.  
  1369.             IF CurAdvance% = 1 AND positioncursor% - leftmargin% + 1 < rightmargin% - leftmargin% + 1 THEN
  1370.                 LOCATE , positioncursor% + CurAdvance%
  1371.             ELSE
  1372.                 LOCATE , positioncursor%
  1373.             END IF
  1374.         END IF
  1375.         EXIT DO
  1376.     LOOP
  1377.     RETURN '---------------------------------------------------------------------
  1378.  
  1379.     BackspaceDelete:
  1380.     IF highlight% THEN GOSUB cutcopy
  1381.     IF POS(0) > leftmargin% OR mykey% = 21248 OR hscroll% > 0 THEN
  1382.         IF POS(0) <= leftmargin% + LEN(text$) THEN
  1383.             IF mykey% = 8 THEN
  1384.                 IF POS(0) <= leftmargin% + 2 AND hscroll% > 0 THEN
  1385.                     REM Adjust for horizontal scroll
  1386.                     holdcursor% = POS(0)
  1387.                     LOCATE , leftmargin%
  1388.                     countcolumnsmoved% = hscroll%
  1389.                     jBackspaceDelete% = (rightmargin% - (leftmargin% - 1)) * .33
  1390.                     IF jBackspaceDelete% < 3 AND rightmargin% - (leftmargin% - 1) > 3 THEN jBackspaceDelete% = 3: REM Set minimum scroll back.
  1391.                     FOR iBackspaceDelete% = 1 TO jBackspaceDelete%
  1392.                         GOSUB CursorLeft
  1393.                     NEXT
  1394.                     LOCATE , holdcursor% + countcolumnsmoved% - hscroll% - 1
  1395.                     countcolumnsmoved% = 0: iBackspaceDelete% = 0: jBackspaceDelete% = 0
  1396.                 ELSE
  1397.                     LOCATE , POS(0) - 1
  1398.                 END IF
  1399.             END IF
  1400.             iyy% = CSRLIN: ixx% = POS(0)
  1401.             text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + MID$(text$, POS(0) - leftmargin% + hscroll% + 2)
  1402.             texttemp$ = MID$(text$, hscroll% + 1, rightmargin% - (leftmargin% - 1))
  1403.             LOCATE iyy%, leftmargin%: PRINT texttemp$ + STRING$((rightmargin% - (leftmargin% - 1)) - LEN(texttemp$), linecharacter%);
  1404.             LOCATE iyy%, ixx%
  1405.         END IF
  1406.     END IF
  1407.     RETURN '---------------------------------------------------------------------
  1408.  
  1409.     cutcopy:
  1410.     IF highlight% THEN
  1411.         IF mykey% = 99 OR mykey% = 120 THEN
  1412.             _CLIPBOARD$ = MID$(text$, starthighlight% - leftmargin%, highlight% - starthighlight% + 1)
  1413.         END IF
  1414.  
  1415.         IF mykey% = 88 OR mykey% = 120 OR mykey% = 8 OR mykey% = 21248 THEN ' ctrl + x (cut), delete, backspace.
  1416.             positioncursor% = starthighlight% - 1 - hscroll%
  1417.             texttemp$ = MID$(text$, 1, starthighlight% - leftmargin% - 1) + MID$(text$, highlight% - leftmargin% + 1)
  1418.             text$ = texttemp$
  1419.             hscroll% = hscroll% - ABS(highlight% - starthighlight%)
  1420.             IF hscroll% < 0 THEN hscroll% = 0
  1421.             LOCATE , positioncursor%
  1422.             GOSUB wash
  1423.         END IF
  1424.     END IF
  1425.     RETURN '---------------------------------------------------------------------
  1426.  
  1427.     PasteClipboard:
  1428.     IF LEN(text$) + LEN(_CLIPBOARD$) <= textmaxlength% THEN
  1429.         text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + _CLIPBOARD$ + MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  1430.         i% = LEN(_CLIPBOARD$) - (rightmargin% - POS(0))
  1431.         positioncursor% = POS(0) + LEN(_CLIPBOARD$) - 1 + CurAdvance%
  1432.         IF positioncursor% > rightmargin% THEN
  1433.             hscroll% = hscroll% + positioncursor% - rightmargin%
  1434.             positioncursor% = rightmargin%
  1435.         END IF
  1436.         LOCATE , positioncursor%
  1437.         GOSUB wash
  1438.     ELSE
  1439.         BEEP
  1440.     END IF
  1441.     RETURN '---------------------------------------------------------------------
  1442.  
  1443.     InsertOverwrite:
  1444.     IF overwrite% = 0 THEN
  1445.         overwrite% = -1
  1446.         LOCATE , , 1, 7, 30
  1447.     ELSE
  1448.         overwrite% = 0
  1449.         LOCATE , , 1, 7, 7
  1450.     END IF
  1451.     RETURN
  1452.     ' End Key Controls-------------------------------------------------------
  1453.  
  1454.     mouseroutine:
  1455.     DO ' Falk loop
  1456.         IF shiftclick% THEN
  1457.             IF shiftclick% > 0 THEN mykey% = 19712: shiftclick% = shiftclick% - 1 ELSE mykey% = 19200: shiftclick% = shiftclick% + 1
  1458.             EXIT DO ' To Return
  1459.         END IF
  1460.  
  1461.         IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN shift% = -1 ELSE shift% = 0
  1462.  
  1463.         IF my% > margin.t + page.h OR my% <= margin.t THEN
  1464.             IF my% > margin.t + page.h + 2 AND hlf% THEN ' Unhighlight file in display window.
  1465.                 j% = -999: GOSUB highlightfile ' hlf% is in statement above
  1466.                 tabx% = 2
  1467.                 LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' Move to text input field.
  1468.             END IF
  1469.  
  1470.             GOTO 102
  1471.             IF NOT drag% THEN
  1472.                 IF my% = w1% AND mx% = w2% + w4% - 2 THEN
  1473.                     IF closepop% = 0 THEN
  1474.                         LOCATE , , 0
  1475.                         IF hlf% THEN j% = -999: GOSUB highlightfile
  1476.                         IF oldsmode2 THEN ' doctype dropdown menu is open.
  1477.                         ELSE
  1478.                             GOSUB clearbuttons: tabx% = 2
  1479.                         END IF
  1480.                         LOCATE w1% + w3% - 4 - 3, w2% + 15
  1481.                         GOSUB wash
  1482.                         COLOR 15, 4
  1483.                         LOCATE w1%, w2% + w4% - 2
  1484.                         PRINT "x";
  1485.                         closepop% = -1
  1486.                         LOCATE w1% + w3% - 4 - 3, w2% + 15, 1
  1487.                         COLOR textfg%, textbk%
  1488.                     END IF
  1489.                 ELSE
  1490.                     IF closepop% THEN
  1491.                         iyy% = CSRLIN: ixx% = POS(0)
  1492.                         closepop% = 0
  1493.                         COLOR 15, 1
  1494.                         LOCATE w1%, w2% + w4% - 2, 0
  1495.                         PRINT "x";
  1496.                         LOCATE iyy%, ixx%, 1
  1497.                         COLOR textfg%, textbk%
  1498.                     END IF
  1499.                 END IF
  1500.  
  1501.                 SELECT CASE SMODE
  1502.                     CASE 3 ' doctypedropdown menu open.
  1503.                         FOR i% = 1 TO UBOUND(doctype$)
  1504.                             IF my% = doctypey%(i%) AND mx% >= ABS(doctypex%(i%)) AND mx% < ABS(doctypex%(i%)) + LEN(doctype$(i%)) THEN
  1505.                                 IF doctypex%(i%) > 0 THEN
  1506.                                     COLOR 0, 3: LOCATE doctypey%(i%), doctypex%(i%), 0
  1507.                                     PRINT doctype$(i%);
  1508.                                     doctypex%(i%) = -doctypex%(i%)
  1509.                                     COLOR textfg%, textbk%
  1510.                                 END IF
  1511.                             ELSE
  1512.                                 IF doctypex%(i%) < 0 THEN
  1513.                                     doctypex%(i%) = ABS(doctypex%(i%))
  1514.                                     iyy% = CSRLIN: ixx% = POS(0)
  1515.                                     COLOR 7, 0: LOCATE doctypey%(i%), doctypex%(i%), 0
  1516.                                     PRINT doctype$(i%);
  1517.                                     LOCATE iyy%, ixx%, 0
  1518.                                     COLOR textfg%, textbk%
  1519.                                 END IF
  1520.                             END IF
  1521.                         NEXT
  1522.                     CASE ELSE
  1523.                         j% = 0
  1524.                         FOR i% = 1 TO UBOUND(formbutton$)
  1525.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% < ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1526.                                 IF formbuttonx%(i%) > 0 THEN
  1527.                                     iyy% = CSRLIN: ixx% = POS(0)
  1528.                                     COLOR 0, 3: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1529.                                     PRINT formbutton$(i%);
  1530.                                     formbuttonx%(i%) = -formbuttonx%(i%)
  1531.                                     j% = -1
  1532.                                     IF iyy% = w1% + w3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1533.                                     COLOR textfg%, textbk%
  1534.                                 END IF
  1535.                             ELSE
  1536.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1537.                                 iyy% = CSRLIN: ixx% = POS(0)
  1538.                                 COLOR 1, 7: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1539.                                 PRINT formbutton$(i%);
  1540.                                 IF iyy% = w1% + w3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1541.                                 COLOR textfg%, textbk%
  1542.                             END IF
  1543.                             IF formbuttonx%(i%) < 0 THEN j% = -1 ' Used below to designate a button is highlighted.
  1544.                         NEXT
  1545.  
  1546.                         IF tabx% >= 3 AND tabx% <= 5 AND j% = 0 THEN
  1547.                             COLOR 0, 3: LOCATE formbuttony%(tabx% - 2), ABS(formbuttonx%(tabx% - 2)), 0
  1548.                             PRINT formbutton$(tabx% - 2);
  1549.                         END IF
  1550.                 END SELECT
  1551.             END IF
  1552.  
  1553.             102
  1554.             IF mb.l THEN
  1555.                 IF closepop% THEN action$ = "close": EXIT DO ' To Return
  1556.  
  1557.                 IF NOT drag% THEN
  1558.                     IF oldsmode2 THEN ' Doctype dropdown menu is open.
  1559.                         FOR i% = 1 TO UBOUND(doctype$)
  1560.                             IF doctypex%(i%) < 0 THEN
  1561.                                 GOSUB close_doctype_dropdown
  1562.                                 GOSUB doctype_selected
  1563.                                 doctypex%(i%) = ABS(doctypex%(i%))
  1564.                             END IF
  1565.                         NEXT
  1566.                     END IF
  1567.  
  1568.                     FOR i% = 1 TO UBOUND(formbutton$) ' Check control buttons.
  1569.                         IF formbuttonx%(i%) < 0 THEN
  1570.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% <= ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1571.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1572.                                 SOUND 1000, .1
  1573.                                 LOCATE , , 0
  1574.                                 SELECT CASE i%
  1575.                                     CASE 1 ' Open doctype dropdown menu.
  1576.                                         GOSUB popfiletypes
  1577.                                     CASE 2 ' Open button.
  1578.                                         SELECT CASE config%
  1579.                                             CASE 1
  1580.                                                 action$ = "open file"
  1581.                                             CASE 2
  1582.                                                 action$ = "save as"
  1583.                                         END SELECT
  1584.                                         '''myfile$ = text$
  1585.                                         EXIT DO ' To Return.
  1586.                                     CASE 3 ' Cancel button.
  1587.                                         action$ = "cancel": EXIT DO ' To Return.
  1588.                                 END SELECT
  1589.                             END IF
  1590.                         END IF
  1591.                     NEXT
  1592.                 END IF
  1593.  
  1594.                 IF mx% > leftmargin% + LEN(text$) THEN EXIT DO ' To Return
  1595.  
  1596.                 IF click_l% >= 0 THEN
  1597.                     click_l% = -1
  1598.                     IF highlight% AND NOT shift% THEN GOSUB wash
  1599.                 END IF
  1600.  
  1601.                 IF shift% THEN
  1602.                     SELECT CASE mx%
  1603.                         CASE IS > POS(0): mykey% = 19712: shiftclick% = mx% - POS(0) - 1
  1604.                         CASE IS = POS(0): mykey% = 0
  1605.                         CASE IS < POS(0): mykey% = 19200: shiftclick% = mx% - POS(0) + 1
  1606.                     END SELECT
  1607.                     IF mykey% THEN EXIT DO ' To Return
  1608.                 END IF
  1609.             ELSE
  1610.                 IF click_l% = -1 THEN click_l% = 1: drag% = 0
  1611.             END IF
  1612.  
  1613.             IF click_l% = -1 THEN
  1614.                 IF mx% = POS(0) THEN
  1615.                     drag% = -1
  1616.                 ELSE
  1617.                     IF my% = CSRLIN AND drag% = 0 THEN
  1618.                         IF pete THEN
  1619.                             ' Cursor was already placed in popup sub.
  1620.                         ELSE
  1621.                             LOCATE my%, mx% ' Click in input field. '''''''' DOESN'T mx% NEED TO BE LIMITED IN OLD ROUTINE, TOO???
  1622.                         END IF
  1623.                     END IF
  1624.                 END IF
  1625.             END IF
  1626.  
  1627.             IF drag% THEN
  1628.                 shift% = -1
  1629.                 SELECT CASE mx%
  1630.                     CASE IS > POS(0): mykey% = 19712: IF mx% > rightmargin% THEN _DELAY .05
  1631.                     CASE IS = POS(0): mykey% = 0
  1632.                     CASE IS < POS(0): mykey% = 19200: IF mx% < leftmargin% THEN _DELAY .05
  1633.                 END SELECT
  1634.             END IF
  1635.  
  1636.             EXIT DO ' To Return
  1637.  
  1638.         ELSE
  1639.  
  1640.             DO
  1641.                 IF SMODE = 3 THEN EXIT DO
  1642.                 IF my% > margin.t AND my% - margin.t <= page.h AND mx% > margin.l AND mx% < margin.l + page.w THEN
  1643.                     tabx% = 1: GOSUB clearbuttons
  1644.                     IF mb.l AND NOT lbdown% THEN
  1645.                         IF my% = CSRLIN THEN ' File Selected
  1646.                             lbdown% = -1
  1647.                             GOSUB fileselected
  1648.                             EXIT DO
  1649.                         END IF
  1650.                     ELSE
  1651.                         IF mb.l = 0 THEN lbdown% = 0
  1652.                     END IF
  1653.  
  1654.                     IF hlf% = 0 THEN
  1655.                         row = my% - margin.t: j% = 0: GOSUB highlightfile
  1656.                     ELSEIF oldmy% > my% AND my% - margin.t <= page.h AND row > 1 THEN
  1657.                         i% = my%: IF i% - margin.t > 0 THEN
  1658.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1659.                             DO UNTIL CSRLIN <= i%
  1660.                                 row = row - 1: j% = 0: GOSUB highlightfile
  1661.                             LOOP
  1662.                         END IF
  1663.                     ELSEIF oldmy% AND oldmy% < my% AND row < page.h THEN
  1664.                         i% = my%: IF i% - margin.t <= page.h THEN
  1665.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1666.                             DO UNTIL CSRLIN >= i%
  1667.                                 row = row + 1: j% = 0: GOSUB highlightfile
  1668.                             LOOP
  1669.                         END IF
  1670.                     END IF
  1671.                 END IF
  1672.  
  1673.                 ' ------------------------------------Mouse----------------------------------
  1674.  
  1675.                 IF locked% < 0 THEN ' Mouse effects on mouse lock. key press effects are determined at inkey$ input, as key variable cannot be evaluated here, due to b$ = "" manipulations in the keypress routine.
  1676.                     IF mb.l OR mb.r OR mb.m THEN locked% = 0
  1677.                 END IF
  1678.  
  1679.                 IF mb.w THEN ' Determine if wheel is being used to scroll highlighted or unhighlighted text.
  1680.                     GOSUB clearbuttons
  1681.                     tabx% = 1 ' Reset tab index when mouse wheel is engaged.
  1682.                     locked% = 2 ' 2 is lock scrollbar, no highlighting permitted.
  1683.                 END IF
  1684.  
  1685.                 IF mb.l AND locked% <> 1 OR mb.w AND locked% <> -1 THEN
  1686.                     tabx% = 1
  1687.                     IF mb.l THEN GOSUB clearbuttons
  1688.                     ' Scrollbar routine.
  1689.                     IF mx% >= scrb.l - 1 AND mx% <= scrb.l + 1 AND my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 THEN draglock% = -1
  1690.  
  1691.                     IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR mx% = scrb.l AND scrb.s <> 0 AND my% >= scrb.t AND my% <= scrb.b AND mb.w = 0 OR scrbardrag% <> 0 AND my% > scrb.t AND my% < scrb.b AND mb.w = 0 OR mb.w > 0 AND scrb.x + scrb.s < scrb.h OR mb.w < 0 AND scrb.x > 0 THEN ' Mouse on scrollbar, doing a bar cursor drag or using the scroll wheel.
  1692.                         locked% = 2 ' Locked on scrollbar
  1693.                         IF my% = scrb.t AND scrb.x > 0 OR my% = scrb.b AND scrb.x + scrb.s < scrb.h OR mb.w <> 0 AND scr + page.h < noe THEN ' Mouse on a scrollbar arrow.
  1694.                             IF my% = scrb.t AND mb.w = 0 OR mb.w < 0 THEN scrb.x = scrb.x - 1: h% = -1 ELSE scrb.x = scrb.x + 1: h% = -2 ' Top or bottom arrow.
  1695.                             IF mb.w = 0 THEN delay.on! = .15
  1696.                             j% = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1697.  
  1698.                             IF j% >= 0 THEN ' Condition exists unless j% is negative such as doc is blank and mouse wheel is rolled downward.
  1699.                                 scrb.i = j%
  1700.  
  1701.                                 scr = scrb.i
  1702.  
  1703.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr) ' Positions scrollbar box.
  1704.  
  1705.                                 GOSUB scrollscrn
  1706.                             END IF
  1707.  
  1708.                         ELSEIF my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 AND scrbardrag% = 0 THEN ' Mouse on scrollbar block.
  1709.                             scrbardrag% = -1: scrb.adjust = (my% - (scrb.t + 1)) - scrb.x
  1710.                         ELSEIF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% > scrb.t AND my% < scrb.b THEN ' Mouse on scrollbar between scrollbar arrow and cursor.
  1711.                             IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% - (scrb.t + 1) - scrb.adjust >= 0 AND my% - (scrb.t + 1) + scrb.s - scrb.adjust <= scrb.h AND scrbardrag% <> -1 OR scrbardrag% = 0 THEN
  1712.                                 IF scrbardrag% = 0 THEN ' No drag, so adjust for cursor length for a click inside the scrollbar above or below the current scrollbar cursor position.
  1713.                                     IF my% - (scrb.t + 1) > scrb.x THEN
  1714.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x - 1: h% = -1
  1715.                                     ELSE
  1716.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x + 1: h% = -2
  1717.                                     END IF
  1718.                                 END IF
  1719.                                 scrb.x = my% - (scrb.t + 1) - scrb.adjust
  1720.                                 scrb.i = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1721.  
  1722.                                 scr = scrb.i
  1723.  
  1724.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1725.  
  1726.                                 GOSUB scrollscrn
  1727.  
  1728.                             ELSE ' Scrollbar is at top or bottom and mouse cursor is moving vertically along the scrollbar cursor. This allows the variable to readjust.
  1729.                                 IF mx% = scrb.l THEN scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1730.                             END IF
  1731.                         END IF
  1732.                         ' =======================================================
  1733.  
  1734.                     END IF
  1735.  
  1736.                     IF delay.on! THEN ' Scrollbar delay.
  1737.                         _DELAY delay.on!
  1738.                         delay.on! = 0 ' Toggle off.
  1739.                     END IF
  1740.  
  1741.                 ELSE
  1742.                     scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1743.                     IF locked% = 2 AND mb.l = 0 THEN locked% = 0
  1744.                 END IF
  1745.                 EXIT DO
  1746.             LOOP
  1747.         END IF
  1748.         EXIT DO
  1749.     LOOP
  1750.     RETURN '---------------------------------------------------------------------
  1751.  
  1752.     file_display_keys:
  1753.     DO '
  1754.         IF CSRLIN >= margin.t AND CSRLIN <= margin.t + page.h AND mb.l = 0 OR autokey% THEN
  1755.             ' Key commands for form input line.
  1756.             IF autokey% = 0 THEN b$ = INKEY$ ELSE b$ = MID$(b$, 3): IF LEN(b$) = 2 THEN autokey% = 0
  1757.             IF LEN(b$) THEN
  1758.                 IF b$ = CHR$(9) THEN GOSUB tabkey: b$ = "": null$ = INKEY$: EXIT DO ' tabx% assignment.
  1759.                 SELECT CASE MID$(b$, 1, 2) ' File directory window keys.
  1760.                     CASE CHR$(0) + "H"
  1761.                         IF row > 1 THEN
  1762.                             row = row - 1
  1763.                             LOCATE margin.t + row, margin.l + 1
  1764.                             j% = 0: GOSUB highlightfile
  1765.                         ELSE
  1766.                             IF scr > 0 THEN
  1767.                                 scr = scr - 1
  1768.                                 GOSUB scrollscrn
  1769.                                 j% = 0: GOSUB highlightfile
  1770.                             END IF
  1771.                         END IF
  1772.                     CASE CHR$(0) + "P"
  1773.                         IF tabx% <> 3 THEN
  1774.                             IF row < page.h THEN
  1775.                                 row = row + 1
  1776.                                 j% = 0: GOSUB highlightfile
  1777.                                 LOCATE margin.t + row, margin.l + 1
  1778.                             ELSE
  1779.                                 IF scr + page.h < noe THEN
  1780.                                     scr = scr + 1
  1781.                                     GOSUB scrollscrn
  1782.                                     j% = 0: GOSUB highlightfile
  1783.                                 END IF
  1784.                             END IF
  1785.                         ELSE
  1786.                             ' Arrow down key is highlighted by tabx%. Now open the doctype dropdown menu.
  1787.                             GOSUB popfiletypes
  1788.                         END IF
  1789.                     CASE CHR$(0) + "I"
  1790.                         autokey% = -1
  1791.                         LOCATE , margin.l + 1
  1792.                         k% = page.h - 1 + row - 2
  1793.                         FOR j% = 0 TO k%
  1794.                             b$ = b$ + CHR$(0) + "H"
  1795.                         NEXT
  1796.                         FOR j% = 1 TO row - 1
  1797.                             b$ = b$ + CHR$(0) + "P"
  1798.                         NEXT
  1799.                     CASE CHR$(0) + "Q"
  1800.                         autokey% = -1
  1801.                         LOCATE , margin.l + 1
  1802.                         k% = (page.h - 1) + (page.h - row) - 1
  1803.                         FOR j% = 0 TO k%
  1804.                             b$ = b$ + CHR$(0) + "P"
  1805.                         NEXT
  1806.                         FOR j% = 1 TO page.h - row
  1807.                             b$ = b$ + CHR$(0) + "H"
  1808.                         NEXT
  1809.                     CASE CHR$(0) + "w" ' Ctrl + Home
  1810.                         row = 1
  1811.                         IF scr > 0 THEN
  1812.                             scr = 0
  1813.                             h% = 0: GOSUB scrollscrn
  1814.                         END IF
  1815.                         LOCATE margin.t + 1, margin.l + 1
  1816.                         j% = 0: GOSUB highlightfile
  1817.                     CASE CHR$(0) + "u" ' Ctrl + End
  1818.                         IF noe > page.h THEN
  1819.                             row = page.h
  1820.                             scr = noe - row
  1821.                             LOCATE margin.t + 1, margin.l + 1
  1822.                             h% = 0: GOSUB scrollscrn
  1823.                             row = page.h
  1824.                             LOCATE margin.t + row, margin.l + 1
  1825.                             j% = 0: GOSUB highlightfile
  1826.                         ELSE
  1827.                             row = noe
  1828.                             LOCATE margin.t + row, margin.l + 1
  1829.                             j% = 0: GOSUB highlightfile
  1830.                         END IF
  1831.                     CASE CHR$(13)
  1832.                         GOSUB fileselected
  1833.                 END SELECT
  1834.             END IF
  1835.         ELSE
  1836.             null$ = INKEY$ ' Clear buffer
  1837.         END IF
  1838.         EXIT DO
  1839.     LOOP
  1840.  
  1841.     RETURN '---------------------------------------------------------------------
  1842.  
  1843.     '-------------------------------Nested Gosubs-----------------------------
  1844.  
  1845.     scrollscrn:
  1846.     FOR i% = 1 TO page.h
  1847.         LOCATE margin.t + i%, margin.l + 1
  1848.         PRINT x$(i% + scr);
  1849.     NEXT
  1850.     LOCATE row + margin.t, margin.l + 1
  1851.     IF hlf% AND LEN(b$) < 3 AND scrbardrag% = 0 THEN j% = 0: GOSUB highlightfile
  1852.  
  1853.     '''h% = 1: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1854.  
  1855.     RETURN '---------------------------------------------------------------------
  1856.  
  1857.     highlightfile:
  1858.     IF j% = -999 THEN ' Unhighlight text only.
  1859.         COLOR 7, 0
  1860.         LOCATE margin.t + hlf%, margin.l + 1, 0
  1861.         PRINT x$(hlf% + scr);
  1862.         hlf% = 0
  1863.     ELSE
  1864.         IF hlf% THEN
  1865.             LOCATE margin.t + hlf%, margin.l + 1, 0
  1866.             COLOR 7, 0: PRINT x$(hlf% + scr);
  1867.         END IF
  1868.         COLOR 1, 3
  1869.         LOCATE margin.t + row, margin.l + 1, 0
  1870.         PRINT x$(row + scr);
  1871.         hlf% = row
  1872.         COLOR c1%, c2%
  1873.     END IF
  1874.     RETURN '---------------------------------------------------------------------
  1875.  
  1876.     wash:
  1877.     starthighlight% = 0
  1878.     highlight% = 0
  1879.     iyy% = CSRLIN: ixx% = POS(0)
  1880.     COLOR textfg%, textbk%
  1881.     LOCATE , leftmargin%
  1882.     texttemp$ = MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1))
  1883.     PRINT texttemp$ + STRING$(rightmargin% - (leftmargin% - 1) - LEN(texttemp$), linecharacter%);
  1884.     LOCATE iyy%, ixx%
  1885.     RETURN '---------------------------------------------------------------------
  1886.  
  1887.     clearbuttons:
  1888.     iyy% = CSRLIN: ixx% = POS(0)
  1889.     FOR k% = 1 TO UBOUND(formbutton$)
  1890.         LOCATE formbuttony%(k%), ABS(formbuttonx%(k%)), 0
  1891.         COLOR 1, 7: PRINT formbutton$(k%);
  1892.         formbuttonx%(k%) = ABS(formbuttonx%(k%)) ' Remove button active (neg) designation.
  1893.     NEXT
  1894.     LOCATE iyy%, ixx%
  1895.     RETURN '---------------------------------------------------------------------
  1896.  
  1897.     displaybutton: ' Gosub parameters (i%)
  1898.     iyy% = CSRLIN: ixx% = POS(0)
  1899.     GOSUB clearbuttons ' Clear all buttons of highlighting first...
  1900.     IF i% < 0 THEN COLOR 0, 3 ELSE COLOR 1, 7
  1901.     IF tabx% THEN COLOR 0, 3
  1902.     IF i% <> 0 THEN
  1903.         LOCATE formbuttony%(ABS(i%)), ABS(formbuttonx%(ABS(i%))), 0
  1904.         PRINT formbutton$(ABS(i%));
  1905.         formbuttonx%(ABS(i%)) = -ABS(formbuttonx%(ABS(i%)))
  1906.     END IF
  1907.     LOCATE iyy%, ixx%
  1908.     RETURN '---------------------------------------------------------------------
  1909.  
  1910.     fileselected:
  1911.     IF noe THEN
  1912.         IF hlf% THEN j% = -999: GOSUB highlightfile
  1913.  
  1914.         text$ = xfull$(row + scr)
  1915.  
  1916.         IF LEFT$(text$, 2) = ".." OR LEFT$(text$, 1) = "[" THEN
  1917.             ' Ready to change diretories.
  1918.             IF LEFT$(text$, 2) = ".." THEN
  1919.                 CHDIR ".."
  1920.             ELSE
  1921.                 CHDIR MID$(text$, 2, LEN(text$) - 2)
  1922.             END IF
  1923.             action$ = "change dir"
  1924.         ELSE
  1925.             ' Text input line.
  1926.             COLOR 7, 0
  1927.             LOCATE w1% + w3% - 4 - 3, w2% + 15: PRINT SPACE$(w4% - 18); ' Blank it.
  1928.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1: PRINT MID$(text$, 1, w4% - 18); ' Display it.
  1929.             hlf% = 0
  1930.         END IF
  1931.     ELSE ' No files found in DIR to select.
  1932.         BEEP
  1933.     END IF
  1934.     RETURN '---------------------------------------------------------------------
  1935.  
  1936.     popfiletypes:
  1937.     LOCATE w1% + w3% - 4 - 3, w2% + 15, 0
  1938.     GOSUB wash
  1939.     oldsmode2 = SMODE
  1940.     SMODE = 3: PCOPY oldsmode2, SMODE: SCREEN 0, 0, SMODE, SMODE
  1941.     COLOR 8, 0: LOCATE w1% + 16, w2% + 15 - 1: PRINT CHR$(179);
  1942.     COLOR 1, 3: PRINT SPACE$(w4% - 21);
  1943.     LOCATE w1% + 16, w2% + 15
  1944.     COLOR 1, 3: PRINT doctype$(1);
  1945.     COLOR 8, 0: LOCATE w1% + 16, w2% + w4% - 4: PRINT CHR$(179);
  1946.     LOCATE w1% + 17, w2% + 14
  1947.     COLOR 8, 0: PRINT CHR$(179);
  1948.     COLOR 7, 0: PRINT SPACE$(w4% - 18);
  1949.     LOCATE w1% + 17, w2% + 15: PRINT doctype$(2);
  1950.     COLOR 8, 0: LOCATE , w2% + w4% - 4: PRINT CHR$(179);
  1951.     COLOR 8, 0: LOCATE w1% + 18, w2% + 14: PRINT CHR$(192); STRING$(w4% - 19, 196); CHR$(217);
  1952.     doctypey%(1) = w1% + 16: doctypex%(1) = w2% + 15
  1953.     doctypey%(2) = w1% + 17: doctypex%(2) = w2% + 15
  1954.     LOCATE w1% + 16, w2% + 15 ' Text input line.
  1955.     RETURN '---------------------------------------------------------------------
  1956.  
  1957.     doctype_selected:
  1958.     SELECT CASE i%
  1959.         CASE 1
  1960.             COLOR 7, 0: LOCATE w1% + 16, w2% + 15: PRINT SPACE$(w4% - 19); ' Leaves arrow down space.
  1961.             LOCATE w1% + 16, w2% + 15: PRINT doctype$(1);
  1962.  
  1963.             IF doctype$ <> doctype$(1) THEN
  1964.                 '''doctype$ = doctype$(1): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  1965.             END IF
  1966.  
  1967.             doctype$ = doctype$(1)
  1968.             IF doctype% = 2 THEN SWAP doctype$(1), doctype$(2)
  1969.             doctype% = 1
  1970.  
  1971.             LOCATE w1% + 16, w2 + w4% + 4 ' .txt or *.* all files arrow down button location.
  1972.             formbuttony%(1) = CSRLIN: formbuttonx%(1) = POS(0): formbutton$(1) = CHR$(25)
  1973.  
  1974.             i% = 1: GOSUB displaybutton
  1975.  
  1976.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' File name input field.
  1977.             COLOR textfg%, textbk%
  1978.         CASE 2
  1979.             COLOR 7, 0: LOCATE w1% + 16, w2% + 15: PRINT SPACE$(w4% - 19); ' Leaves arrow down space.
  1980.             LOCATE w1% + 16, w2% + 15: PRINT doctype$(2);
  1981.  
  1982.             IF doctype$ <> doctype$(2) THEN
  1983.                 '''doctype$ = doctype$(2): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  1984.             END IF
  1985.  
  1986.             doctype$ = doctype$(2)
  1987.             IF doctype% = 1 THEN SWAP doctype$(1), doctype$(2)
  1988.             doctype% = 2
  1989.  
  1990.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' File name input field.
  1991.             COLOR textfg%, textbk%
  1992.     END SELECT
  1993.  
  1994.     RETURN '---------------------------------------------------------------------
  1995.  
  1996.     close_doctype_dropdown:
  1997.     ' Note - Do not use i% in this routine. It would change a perviouly set value i one of the routines that calls this one.
  1998.     SMODE = oldsmode2: SCREEN 0, 0, SMODE, SMODE: oldsmode2 = 0
  1999.     LOCATE , , 0
  2000.     LOCATE w1% + 16, w2% + w4% - 4
  2001.     IF tabx% = 3 THEN COLOR 0, 3 ELSE COLOR 1, 7
  2002.     IF my% = CSRLIN AND mx% = POS(0) THEN COLOR 0, 3: formbuttonx%(1) = -formbuttonx%(1)
  2003.     PRINT formbutton$(1);
  2004.     LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' File name input field.
  2005.     COLOR textfg%, textbk%
  2006.     REDIM doctypex%(UBOUND(doctype$)), doctypey%(UBOUND(doctype$))
  2007.     RETURN '---------------------------------------------------------------------
  2008.  
  2009.  
  2010. SUB find_string
  2011.     REDIM x$(20)
  2012.     margin.t = 5
  2013.     margin.l = 5
  2014.     dwidth = 68
  2015.     page.h = 6
  2016.     row = 1
  2017.     noe = 13
  2018.  
  2019.     x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  2020.     x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  2021.     x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  2022.     x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  2023.     x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  2024.     x$(6) = "" + CHR$(255) + CHR$(10)
  2025.     x$(7) = "Article I" + CHR$(10)
  2026.     x$(8) = "" + CHR$(255) + CHR$(10)
  2027.     x$(9) = "Section 1: Congress" + CHR$(10)
  2028.     x$(10) = "" + CHR$(255) + CHR$(10)
  2029.     x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  2030.     x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  2031.     x$(13) = "Representatives." + CHR$(10)
  2032.  
  2033.     GOSUB displaydoc
  2034.  
  2035.     DO
  2036.         DO
  2037.             _LIMIT 30
  2038.             b$ = INKEY$
  2039.             IF LEN(b$) THEN
  2040.                 SELECT CASE b$
  2041.                     CASE CHR$(27)
  2042.                         SYSTEM
  2043.                     CASE CHR$(0) + "H"
  2044.                         IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  2045.                     CASE CHR$(0) + "P"
  2046.                         IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  2047.                 END SELECT
  2048.             END IF
  2049.         LOOP
  2050.     LOOP
  2051.  
  2052.     displaydoc:
  2053.     COLOR 0, 7
  2054.     FOR i% = 1 TO page.h
  2055.         a1$ = SPACE$(dwidth)
  2056.         MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  2057.         LOCATE margin.t + i%, margin.l + 1
  2058.         PRINT a1$
  2059.     NEXT
  2060.     RETURN
  2061.  
  2062.     finder:
  2063.     FOR i% = 1 TO page.h
  2064.         a1$ = SPACE$(dwidth)
  2065.         MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  2066.  
  2067.         IF INSTR(LCASE$(a1$), find$) THEN
  2068.             COLOR 14, 4: seed% = 0
  2069.             DO UNTIL INSTR(seed%, LCASE$(a1$), find$) = 0
  2070.                 seed% = INSTR(seed%, LCASE$(a1$), find$)
  2071.                 LOCATE margin.t + i%, margin.l + seed%
  2072.                 PRINT MID$(a1$, INSTR(seed%, LCASE$(a1$), find$), LEN(find$));
  2073.                 seed% = seed% + LEN(find$)
  2074.             LOOP
  2075.         END IF
  2076.     NEXT
  2077.     COLOR 0, 7
  2078.     RETURN
  2079.  
  2080. SUB windowscreen (ENL%)
  2081.     IF displayfullscreen% = -1 THEN EXIT SUB
  2082.     WINXX1% = CSRLIN: WINYY1% = POS(1)
  2083.     winmode$ = "2"
  2084.  
  2085.     IF ENL% <> 0 THEN
  2086.         full = _FULLSCREEN
  2087.         IF full = 0 THEN
  2088.             SELECT CASE ENL%
  2089.                 CASE -1: IF SCRNSIZE% > 0 THEN ELSE EXIT SUB
  2090.                 CASE 1: IF SCRNSIZE% < 14 THEN ELSE EXIT SUB
  2091.             END SELECT
  2092.         ELSE
  2093.             EXIT SUB
  2094.         END IF
  2095.     END IF
  2096.  
  2097.     SCRNSIZE% = SCRNSIZE% + ENL%
  2098.  
  2099.     SELECT CASE winmode$
  2100.         CASE "1"
  2101.             full = _FULLSCREEN
  2102.             IF full <> 0 THEN _FULLSCREEN _OFF
  2103.             GOSUB ChangeFont
  2104.         CASE "2"
  2105.             full = _FULLSCREEN
  2106.             IF full <> 0 THEN _FULLSCREEN _OFF
  2107.             style$ = "MONOSPACE"
  2108.             fontsize% = SCRNSIZE% + 13
  2109.             IF fontsize% < 14 THEN winmode$ = ""
  2110.             IF fontsize% < 18 THEN style$ = style$ + ", BOLD"
  2111.             fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
  2112.             GOSUB ChangeFont
  2113.         CASE "3"
  2114.             GOSUB ChangeFont
  2115.             _FULLSCREEN _SQUAREPIXELS
  2116.             full = _FULLSCREEN
  2117.             IF full = 0 THEN GOSUB nofull
  2118.         CASE "4"
  2119.             GOSUB ChangeFont
  2120.             _FULLSCREEN _STRETCH
  2121.             full = _FULLSCREEN
  2122.             IF full = 0 THEN GOSUB nofull
  2123.     END SELECT
  2124.  
  2125.     LOCATE WINXX1%, WINYY1%
  2126.     EXIT SUB
  2127.  
  2128.     nofull:
  2129.     RETURN
  2130.  
  2131.     ChangeFont:
  2132.     IF winmode$ <> "2" THEN
  2133.         _FONT 16 'select inbuilt 8x16 default font
  2134.         currentf& = _FONT
  2135.     ELSE
  2136.         currentf& = _LOADFONT(fontpath$, fontsize%, style$)
  2137.         _FONT currentf&
  2138.     END IF
  2139.  
  2140.     IF currentf& <> f& AND f& <> defaultf& THEN _FREEFONT f&
  2141.     f& = currentf&
  2142.     RETURN
  2143.  
  2144.  
« Last Edit: February 01, 2021, 04:48:48 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #9 on: January 31, 2021, 03:08:22 pm »
Hi Pete,

I made it as far as the screenshots show. Booted, pressed F3, began typing "promote":

  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #10 on: January 31, 2021, 03:19:54 pm »
I'll have a look. I posted a bit prematurely, as I wanted to bring attention to what I think may be a QB64 bug. I just posted that new thread.

Edit: I can't reproduce it, and I cut and pasted the code from here. What I do know is the position of the mouse pointer has to have some more conditions present to function properly. The error message is a catch for that. I'll continue debugging efforts and thanks for posting the screen shot in the other thread, showing the new version has the same issue at lines 350 and 351.

Pete
« Last Edit: January 31, 2021, 03:43:49 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #11 on: January 31, 2021, 08:41:05 pm »
Updated a few things in the code above, but I need to spend some time next week zeroing variables, cancel ,etc. Now it's put together just well enough to test get the find and replace stuff organized.

I added to the keys with F3 for Find and F7 for Find and Replace. Since I need to work on clearing variables next, I would recommend that if anyone tries it, just hit the Tab key after a find or find and replace is done. That engages the run command, for a fresh start.

Normally I wouldn't have posted at this stage, but I really wanted to find out what why the IDE accepted a REDIM with ubound only when the code included the  i% = ubound(ifield$). I discovered ifield$() array was local, in the old code, now changed to shared, and apparently QB64 made a 10 element array for ifield$() in the main. Previously, ifield$ was DIMmed in a SUB as a local array. So UBOUND can create an array, nice to know. My thanks to Bill and Fell for helping me work through that conundrum.

Edit: Fixed a couple of known issues and updated file. Now you don't have to rerun it with Tab to continue using. The next step will be to get more than one replace mode working. The test program only uses a case-sensitive any word part replace, no matter what button you click. More to come, next week.

Pete
« Last Edit: February 01, 2021, 04:53:44 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Working on the WP "Find" feature, or Fun with Parsing...
« Reply #12 on: February 01, 2021, 02:17:49 pm »
Finished the find / replace part.

Probably  needs lots of test drives to debug, before moving on and merging it into the WP. That in itself may demonstrate some initial conflicts, but due to compiling times, it is a lot easier to break this stuff up into test modules.

I will be looking into some of the find and replace functions when paragraphs are encountered. I'm not sure i have that all sorted out yet, so I may update this post if something else needs to be added for that to work properly.

So F3 for FIND and F7 for FIND / REPLACE

This routine will not alter any of yuor existing files, or write to your hard drive.

Code: QB64: [Select]
  1. enl% = 13: CALL windowscreen(enl%)
  2.  
  3.  
  4.     DIM SHARED mx%, my%, margin.t AS INTEGER, margin.l AS INTEGER
  5.     DIM SHARED w1%, w2%, w3%, w4%
  6.     DIM SHARED action$
  7.     DIM SHARED mb AS my_mb
  8.     DIM scrb AS my_scrb
  9.  
  10.     TYPE my_mb
  11.         l AS INTEGER
  12.         r AS INTEGER
  13.         m AS INTEGER
  14.         w AS INTEGER
  15.         drag AS INTEGER
  16.         dragon AS INTEGER
  17.     END TYPE
  18.  
  19.     TYPE my_scrb
  20.         t AS INTEGER
  21.         b AS INTEGER
  22.         l AS INTEGER
  23.         x AS INTEGER
  24.         i AS INTEGER
  25.         d AS INTEGER
  26.         h AS INTEGER
  27.         s AS INTEGER
  28.         opt AS INTEGER
  29.         adjust AS INTEGER
  30.     END TYPE
  31.  
  32.     DIM SHARED SMODE, passrightmargin%
  33.     REDIM SHARED formbuttony%(3), formbuttonx%(3), formbutton$(3)
  34.     REDIM button$(8)
  35.     COLOR 0, 7: CLS
  36.  
  37.     REDIM x$(20)
  38.     margin.t = 2
  39.     margin.l = 5
  40.     dwidth = 68
  41.     page.h = 6
  42.     row = 1
  43.     noe = 13
  44.  
  45.     x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  46.     x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  47.     x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  48.     x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  49.     x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  50.     x$(6) = "" + CHR$(255) + CHR$(10)
  51.     x$(7) = "Article I" + CHR$(10)
  52.     x$(8) = "" + CHR$(255) + CHR$(10)
  53.     x$(9) = "Section 1: Congress" + CHR$(10)
  54.     x$(10) = "" + CHR$(255) + CHR$(10)
  55.     x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  56.     x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  57.     x$(13) = "Representatives." + CHR$(10)
  58.     DIM SHARED pete, ifield%, noif%, ifrow%, change_initiate%
  59.     REDIM SHARED entry$(10), ifield$(10)
  60.  
  61.     COLOR 0, 7
  62.     GOSUB displaydoc
  63.  
  64.     DO
  65.         _LIMIT 30
  66.         IF b$ = CHR$(0) + CHR$(61) OR b$ = CHR$(0) + CHR$(65) THEN
  67.             IF b$ = CHR$(0) + CHR$(61) THEN pete = 1: noif% = 1 ELSE pete = 2: noif% = 2
  68.  
  69.             GOSUB displaydoc
  70.  
  71.             change_initiate% = -1: CALL popup(msg$, msg%, button$(), button%, button_index%, find$, config%) ' Note: find$ is pass by ref find$ becomes text$ in popup sub and returns text$ back to find$ here.
  72.             LOCATE , , 0
  73.         END IF
  74.  
  75.         IF LEN(action$) THEN
  76.             IF action$ <> "close" THEN
  77.                 SELECT CASE action$
  78.                     CASE "Whole Word" ' Default selection if Enter is used instead of a button.
  79.                         whole_word% = 1
  80.                         case_sensitive% = 0
  81.                     CASE "Whole/Case"
  82.                         whole_word% = 1
  83.                         case_sensitive% = 1
  84.                     CASE "Any Part"
  85.                         whole_word% = 0
  86.                         case_sensitive% = 0
  87.                     CASE "Any/Case"
  88.                         whole_word% = 0
  89.                         case_sensitive% = 1
  90.                 END SELECT
  91.  
  92.                 SELECT CASE config%
  93.                     CASE 2
  94.                         GOSUB finder
  95.                     CASE 3
  96.                         GOSUB replacer
  97.                     CASE ELSE
  98.                         CLS: PRINT "No config% assigned to this case. "; config%: END '''
  99.                 END SELECT
  100.             END IF
  101.             action$ = ""
  102.         END IF
  103.  
  104.         b$ = INKEY$
  105.         IF LEN(b$) THEN
  106.             SELECT CASE b$
  107.                 CASE CHR$(9)
  108.                     COLOR 7, 0: CLS: CLEAR: EXIT DO
  109.                 CASE CHR$(27)
  110.                     SYSTEM
  111.                 CASE CHR$(0) + "H"
  112.                     IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  113.                 CASE CHR$(0) + "P"
  114.                     IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  115.             END SELECT
  116.         END IF
  117.     LOOP
  118.  
  119. displaydoc:
  120. COLOR 0, 7
  121. FOR i% = 1 TO page.h
  122.     a1$ = SPACE$(dwidth)
  123.     MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  124.     LOCATE margin.t + i%, margin.l + 1
  125.     PRINT a1$
  126.  
  127. finder:
  128. IF case_sensitive% = 0 THEN
  129.     find$ = LCASE$(find$): findorig$ = find$
  130.     findorig$ = find$
  131.  
  132. IF LEN(findorig$) THEN
  133.     flag% = 0
  134.     FOR i% = 1 TO page.h
  135.         LOCATE margin.t + i%, margin.l + 1
  136.         a1$ = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  137.  
  138.         IF INSTR(find$, " ") THEN
  139.             IF RIGHT$(a1$, 1) <> " " THEN a2$ = a1$ + " " ELSE a2$ = a1$
  140.         ELSE
  141.             a2$ = a1$ ' No space for a solid line wrap around.
  142.         END IF
  143.  
  144.         IF INSTR(findorig$, " ") THEN
  145.             a2$ = a2$ + MID$(x$(i% + 1 + scr), 1, INSTR(x$(i% + 1 + scr), CHR$(10)) - 1)
  146.             a2% = -1
  147.         ELSE
  148.             a2% = 0
  149.         END IF
  150.  
  151.         SELECT CASE case_sensitive%
  152.             CASE 0 ' Not case sensitive.
  153.                 SELECT CASE whole_word%
  154.                     CASE 0 ' Part word and not case sensitive.
  155.                         IF INSTR(LCASE$(a2$), find$) THEN
  156.                             COLOR 14, 4: seed% = 0
  157.                             DO UNTIL INSTR(seed%, LCASE$(a2$), find$) = 0
  158.  
  159.                                 IF a2% THEN
  160.                                     k% = INSTR(seed%, LCASE$(a2$), find$)
  161.                                     IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  162.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  163.                                         find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  164.                                         flag% = 1
  165.                                     ELSE
  166.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  167.                                     END IF
  168.                                 ELSE
  169.                                     seed% = INSTR(seed%, LCASE$(a2$), find$)
  170.                                 END IF
  171.  
  172.                                 IF seed% <= LEN(a1$) THEN
  173.                                     LOCATE margin.t + i%, margin.l + seed%
  174.                                     PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  175.                                     seed% = seed% + LEN(find$)
  176.  
  177.                                     IF flag% THEN
  178.                                         SELECT CASE flag%
  179.                                             CASE 2
  180.                                                 flag% = 0: find$ = findorig$
  181.                                             CASE 1
  182.                                                 flag% = 2
  183.                                                 find$ = MID$(findorig$, LEN(find$) + 2)
  184.                                                 seed% = 0
  185.                                                 EXIT DO
  186.                                         END SELECT
  187.                                     END IF
  188.                                 ELSE
  189.                                     EXIT DO
  190.                                 END IF
  191.                             LOOP
  192.                         END IF
  193.  
  194.                     CASE 1 ' Whole word and not case sensitive.
  195.                         seed% = 0: COLOR 14, 4
  196.                         WHILE INSTR(seed%, LCASE$(a2$), find$)
  197.                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  198.  
  199.                             IF seed% - 1 = 0 OR MID$(LCASE$(a2$), seed% - 1, 1) = " " THEN
  200.                                 IF INSTR(".,;:?!}]) ", MID$(LCASE$(a2$), seed% + LEN(find$), 1)) THEN
  201.  
  202.                                     IF a2% THEN
  203.                                         k% = INSTR(seed%, LCASE$(a2$), find$)
  204.                                         IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  205.                                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  206.                                             find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  207.                                             flag% = 1
  208.                                         ELSE
  209.                                             seed% = INSTR(seed%, LCASE$(a2$), find$)
  210.                                         END IF
  211.                                     ELSE
  212.                                         seed% = INSTR(seed%, LCASE$(a2$), find$)
  213.                                     END IF
  214.  
  215.                                     IF seed% <= LEN(a1$) THEN
  216.                                         LOCATE margin.t + i%, margin.l + seed%
  217.                                         PRINT MID$(a2$, INSTR(seed%, LCASE$(a2$), find$), LEN(find$));
  218.                                         seed% = seed% + LEN(find$)
  219.  
  220.                                         IF flag% THEN
  221.                                             SELECT CASE flag%
  222.                                                 CASE 2
  223.                                                     flag% = 0
  224.                                                     find$ = findorig$
  225.                                                 CASE 1
  226.                                                     flag% = 2
  227.                                                     find$ = MID$(findorig$, LEN(find$) + 2)
  228.                                                     seed% = 0
  229.                                                     EXIT WHILE
  230.                                             END SELECT
  231.                                         END IF
  232.                                     ELSE
  233.                                         EXIT WHILE
  234.                                     END IF
  235.  
  236.                                 END IF
  237.                             END IF
  238.  
  239.                             seed% = seed% + LEN(find$)
  240.  
  241.                         WEND
  242.  
  243.                 END SELECT
  244.  
  245.             CASE 1 ' Case sensitive
  246.                 SELECT CASE whole_word%
  247.                     CASE 0 ' Part word and case sensitive.
  248.                         seed% = 0: COLOR 14, 4
  249.                         WHILE INSTR(seed%, a2$, find$)
  250.                             seed% = INSTR(seed%, a2$, find$)
  251.  
  252.                             IF a2% THEN
  253.                                 k% = INSTR(seed%, a2$, find$)
  254.                                 IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  255.                                     seed% = INSTR(seed%, a2$, find$)
  256.                                     find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  257.                                     flag% = 1
  258.                                 ELSE
  259.                                     seed% = INSTR(seed%, a2$, find$)
  260.                                 END IF
  261.                             ELSE
  262.                                 seed% = INSTR(seed%, a2$, find$)
  263.                             END IF
  264.  
  265.                             IF seed% <= LEN(a1$) THEN
  266.                                 LOCATE margin.t + i%, margin.l + seed%
  267.                                 PRINT MID$(a2$, INSTR(seed%, a2$, find$), LEN(find$));
  268.                                 seed% = seed% + LEN(find$)
  269.  
  270.                                 IF flag% THEN
  271.                                     SELECT CASE flag%
  272.                                         CASE 2
  273.                                             flag% = 0: find$ = findorig$
  274.                                         CASE 1
  275.                                             flag% = 2
  276.                                             find$ = MID$(findorig$, LEN(find$) + 2)
  277.                                             seed% = 0
  278.                                             EXIT WHILE
  279.                                     END SELECT
  280.                                 END IF
  281.                             ELSE
  282.                                 EXIT WHILE
  283.                             END IF
  284.  
  285.                             seed% = seed% + LEN(find$)
  286.  
  287.                         WEND
  288.  
  289.                     CASE 1 ' Whole word and case sensitive.
  290.                         seed% = 0: COLOR 14, 4
  291.                         WHILE INSTR(seed%, a2$, find$)
  292.                             seed% = INSTR(seed%, a2$, find$)
  293.  
  294.                             IF seed% - 1 = 0 OR MID$(a2$, seed% - 1, 1) = " " THEN
  295.                                 IF INSTR(".,;:?!}]) ", MID$(a2$, seed% + LEN(find$), 1)) THEN
  296.  
  297.                                     IF a2% THEN
  298.                                         k% = INSTR(seed%, a2$, find$)
  299.                                         IF k% + LEN(find$) >= LEN(a1$) AND k% <= LEN(a1$) THEN
  300.                                             seed% = INSTR(seed%, a2$, find$)
  301.                                             find$ = MID$(findorig$, 1, LEN(a1$) - seed%)
  302.                                             flag% = 1
  303.                                         ELSE
  304.                                             seed% = INSTR(seed%, a2$, find$)
  305.                                         END IF
  306.                                     ELSE
  307.                                         seed% = INSTR(seed%, a2$, find$)
  308.                                     END IF
  309.  
  310.                                     IF seed% <= LEN(a1$) THEN
  311.                                         LOCATE margin.t + i%, margin.l + seed%
  312.                                         PRINT MID$(a2$, INSTR(seed%, a2$, find$), LEN(find$));
  313.                                         seed% = seed% + LEN(find$)
  314.  
  315.                                         IF flag% THEN
  316.                                             SELECT CASE flag%
  317.                                                 CASE 2
  318.                                                     flag% = 0: find$ = findorig$
  319.                                                 CASE 1
  320.                                                     flag% = 2
  321.                                                     find$ = MID$(findorig$, LEN(find$) + 2)
  322.                                                     seed% = 0
  323.                                                     EXIT WHILE
  324.                                             END SELECT
  325.                                         END IF
  326.                                     ELSE
  327.                                         EXIT WHILE
  328.                                     END IF
  329.  
  330.                                 END IF
  331.                             END IF
  332.  
  333.                             seed% = seed% + LEN(find$)
  334.  
  335.                         WEND
  336.  
  337.                 END SELECT
  338.         END SELECT
  339.     NEXT
  340.  
  341. replacer:
  342. find$ = entry$(1)
  343. r$ = entry$(2)
  344. REDIM entry$(UBOUND(ifield$))
  345. a$ = ""
  346. FOR i = 1 TO noe
  347.     a$ = a$ + MID$(x$(i), 1, INSTR(x$(i), CHR$(10)) - 1)
  348. a$ = " " + a$: a$ = a$ + " "
  349.  
  350. ' parse a$
  351. seed% = 0: j = 0
  352.  
  353. SELECT CASE action$
  354.     CASE "Whole Word" ' Default selection.
  355.         find$ = LCASE$(find$)
  356.         flag% = 0: seed% = 2
  357.         DO UNTIL seed% = 0 OR INSTR(seed%, LCASE$(a$), find$) = 0
  358.             DO UNTIL seed% = 0
  359.                 IF flag% = 0 AND MID$(a$, seed% - 1, 1) = " " OR flag% = 0 AND MID$(a$, seed% - 1, 1) = CHR$(255) THEN
  360.                     flag% = 1
  361.                 ELSE
  362.                     x% = seed%
  363.                     seed% = INSTR(seed% + LEN(find$), LCASE$(a$), find$)
  364.                     IF seed% = 0 THEN EXIT DO
  365.                 END IF
  366.  
  367.                 IF flag% = 1 THEN
  368.                     IF INSTR(".,;:?!}] " + CHR$(255), MID$(a$, seed% + LEN(find$), 1)) THEN
  369.                         flag% = 0: EXIT DO
  370.                     ELSE
  371.                         flag% = 0: seed% = INSTR(seed% + LEN(find$), LCASE$(a$), find$)
  372.                     END IF
  373.                 END IF
  374.             LOOP
  375.  
  376.             IF seed% THEN
  377.                 a$ = MID$(a$, 1, INSTR(seed%, LCASE$(a$), find$) - 1) + r$ + MID$(a$, INSTR(seed%, LCASE$(a$), find$) + LEN(find$))
  378.                 seed% = seed% + LEN(r$) - LEN(find$) + LEN(find$)
  379.             END IF
  380.         LOOP
  381.  
  382.     CASE "Whole/Case"
  383.         flag% = 0: seed% = 2
  384.         DO UNTIL seed% = 0 OR INSTR(seed%, a$, find$) = 0
  385.             DO UNTIL seed% = 0
  386.                 IF flag% = 0 AND MID$(a$, seed% - 1, 1) = " " OR flag% = 0 AND MID$(a$, seed% - 1, 1) = CHR$(255) THEN
  387.                     flag% = 1
  388.                 ELSE
  389.                     x% = seed%
  390.                     seed% = INSTR(seed% + LEN(find$), a$, find$)
  391.                     IF seed% = 0 THEN EXIT DO
  392.                 END IF
  393.  
  394.                 IF flag% = 1 THEN
  395.                     IF INSTR(".,;:?!}] " + CHR$(255), MID$(a$, seed% + LEN(find$), 1)) THEN
  396.                         flag% = 0: EXIT DO
  397.                     ELSE
  398.                         flag% = 0: seed% = INSTR(seed% + LEN(find$), a$, find$)
  399.                     END IF
  400.                 END IF
  401.             LOOP
  402.  
  403.             IF seed% THEN
  404.                 a$ = MID$(a$, 1, INSTR(seed%, a$, find$) - 1) + r$ + MID$(a$, INSTR(seed%, a$, find$) + LEN(find$))
  405.                 seed% = seed% + LEN(r$) - LEN(find$) + LEN(find$)
  406.             END IF
  407.         LOOP
  408.  
  409.     CASE "Any Part"
  410.         find$ = LCASE$(find$)
  411.         DO UNTIL INSTR(seed%, a$, find$) = 0
  412.             a$ = MID$(a$, 1, INSTR(seed%, LCASE$(a$), find$) - 1) + r$ + MID$(a$, INSTR(seed%, LCASE$(a$), find$) + LEN(find$))
  413.             seed% = seed% + LEN(r$) - LEN(find$) + LEN(find$)
  414.         LOOP
  415.  
  416.     CASE "Any/Case"
  417.         DO UNTIL INSTR(seed%, a$, find$) = 0
  418.             a$ = MID$(a$, 1, INSTR(seed%, a$, find$) - 1) + r$ + MID$(a$, INSTR(seed%, a$, find$) + LEN(find$))
  419.             seed% = seed% + LEN(r$) - LEN(find$) + LEN(find$)
  420.         LOOP
  421.  
  422. a$ = MID$(a$, 2): a$ = MID$(a$, 1, LEN(a$) - 1)
  423. REDIM x$(LEN(a$))
  424.  
  425. DO UNTIL a$ = ""
  426.     x$ = MID$(a$, 1, dwidth)
  427.     IF LEN(x$) < dwidth THEN
  428.         j = j + 1: x$(j) = x$
  429.         a$ = ""
  430.         x$(j) = x$(j) + CHR$(10)
  431.     ELSEIF INSTR(x$, CHR$(255)) THEN
  432.         j = j + 1
  433.         IF LEFT$(x$, 1) = CHR$(255) THEN
  434.             x$(j) = MID$(x$, 1, 1)
  435.             a$ = MID$(a$, 2)
  436.         ELSE
  437.             x$(j) = MID$(x$, 1, INSTR(x$, CHR$(255)) - 1)
  438.             a$ = MID$(a$, INSTR(x$, CHR$(255)))
  439.         END IF
  440.         x$(j) = x$(j) + CHR$(10)
  441.     ELSEIF INSTR(x$, " ") = 0 THEN
  442.         j = j + 1: x$(j) = x$
  443.         a$ = MID$(a$, LEN(x$(j)) + 1)
  444.         x$(j) = x$(j) + CHR$(10)
  445.     ELSE
  446.         j = j + 1: x$(j) = MID$(x$, 1, _INSTRREV(x$, " "))
  447.         a$ = MID$(a$, LEN(x$(j)) + 1)
  448.         x$(j) = x$(j) + CHR$(10)
  449.     END IF
  450. noe = j
  451.  
  452. REDIM _PRESERVE x$(noe + 1)
  453.  
  454. row = 1: scr = 0: GOSUB displaydoc
  455.  
  456. SUB popup (msg$, msg%, button$(), button%, button_index%, text$, config%)
  457.     DIM scrb AS my_scrb
  458.     STATIC doctype%
  459.  
  460.     SELECT CASE pete
  461.         CASE 1
  462.             config% = 2 ' Find
  463.             REDIM ifield$(1)
  464.             msg$ = ""
  465.             ifield% = 48 ' Input field length.
  466.             ifield$(1) = "Find:"
  467.             button% = 4: button_index% = 4
  468.             w1% = 0: w2% = 0: w3% = 0: w4% = 0
  469.             noif% = 1
  470.  
  471.         CASE 2
  472.             config% = 3 ' Find / Replace
  473.             REDIM ifield$(2)
  474.             msg$ = ""
  475.             ifield% = 48
  476.             ifield$(1) = "   Find:"
  477.             ifield$(2) = "Replace:"
  478.             button% = 4: button_index% = 4
  479.             w1% = 0: w2% = 0: w3% = 7: w4% = 0
  480.             noif% = 2
  481.     END SELECT
  482.  
  483.     REDIM button$(8), ifieldyy%(noif%), ifieldxx%(noif%)
  484.     button$(1) = "Yes": button$(2) = "No!"
  485.     button$(3) = "Retry": button$(4) = "Cancel"
  486.     button$(5) = "Whole Word": button$(6) = "Whole/Case": button$(7) = "Any Part": button$(8) = "Any/Case"
  487.     iyy% = CSRLIN: ixx% = POS(0)
  488.     IF w3% = 0 THEN w3% = 5 ' Min.
  489.  
  490.     IF w4% = 0 THEN ' Calculate forn container width
  491.         w4% = LEN(msg$) + 4 ' Min
  492.         FOR i% = 1 TO UBOUND(ifield$)
  493.             IF LEN(ifield$(i%)) + ifield% > w4% THEN w4% = LEN(ifield$(i%)) + ifield% + 6
  494.         NEXT
  495.     END IF
  496.  
  497.     IF w1% = 0 THEN
  498.         ' Auto-Center
  499.         w1% = _HEIGHT \ 2 - w3% \ 2 + .5
  500.         w2% = _WIDTH \ 2 - w4% \ 2 + .5
  501.     END IF
  502.  
  503.     SELECT CASE SMODE
  504.         CASE 0
  505.             oldsmode = SMODE: PCOPY 0, 1: SCREEN 0, 0, 1, 1: SMODE = 1
  506.         CASE 1
  507.             oldsmode = SMODE: PCOPY 1, 2: SCREEN 0, 0, 2, 2: SMODE = 2
  508.     END SELECT
  509.  
  510.     LOCATE w1%, w2%, 0 ' Cursor hide
  511.     FOR i = 1 TO w3%
  512.         A$ = ""
  513.         COLOR 15, 1
  514.         LOCATE , w2%
  515.         A$ = A$ + SPACE$(w4% - LEN(A$))
  516.         PRINT A$;
  517.         IF i <> 1 THEN
  518.             COLOR 1, 0: PRINT CHR$(176)
  519.         ELSE PRINT
  520.         END IF
  521.     NEXT i
  522.     LOCATE , w2% + 1
  523.     COLOR 1, 0: PRINT STRING$(w4%, CHR$(176));
  524.     COLOR 14, 1
  525.     LOCATE w1%, w2%
  526.     PRINT CHR$(218); STRING$(w4% - 2, CHR$(196)); CHR$(191);
  527.     LOCATE w1% + w3% - 1, w2%
  528.     PRINT CHR$(192); STRING$(w4% - 2, CHR$(196)); CHR$(217);
  529.     FOR i = 1 TO w3% - 2
  530.         LOCATE w1% + i, w2%: PRINT CHR$(179);: LOCATE w1% + i, w2% + w4% - 1: PRINT CHR$(179);
  531.     NEXT i
  532.     LOCATE w1%, w2% + w4% - 2: COLOR 15, 1: PRINT "x";
  533.  
  534.     IF LEN(msg$) OR noif% THEN
  535.         SELECT CASE msg%
  536.             CASE -1 ' Message title.
  537.                 LOCATE w1% + 1, w2% + w4% \ 2 - LEN(msg$) \ 2
  538.                 PRINT msg$;
  539.             CASE 0 ' No message title. Usually used with input fields with limited vertical space.
  540.                 IF noif% THEN
  541.                     ifrow% = 1
  542.                     IF UBOUND(ifield$) > 1 THEN i% = 2: j% = UBOUND(ifield$) ELSE i% = 0: j% = 1 ' Where 2 is the spacing between input fields.
  543.                     FOR g% = 1 TO UBOUND(ifield$)
  544.                         LOCATE w1% + w3% \ 2 - j% + i% * (g% - 1), w2% + w4% \ 2 - (ifield% + LEN(ifield$(g%)) + 2) \ 2
  545.                         ifieldyy%(g%) = CSRLIN: ifieldxx%(g%) = POS(0) + LEN(ifield$(g%)) + 1 ' Start of text input line.
  546.                         COLOR 15, 1: PRINT ifield$(g%);
  547.                         COLOR 8, 1: PRINT CHR$(222);
  548.                         COLOR c2%, c1%: PRINT SPACE$(ifield%);
  549.                     NEXT
  550.                     passrightmargin% = POS(0) - 1 ' Sets right margin of the input field.
  551.                 END IF
  552.  
  553.                 IF button% THEN
  554.                     buttonyy% = CSRLIN + 2
  555.                     j% = 0
  556.                     FOR i% = 1 TO button%
  557.                         j% = j% + LEN(button$(button_index% + i%)) + 2
  558.                     NEXT
  559.                     LOCATE buttonyy%, w2% + w4% \ 2 - j% \ 2 - 1
  560.                     COLOR 0, 7
  561.                     mouselocator$ = STRING$(_WIDTH, "0"): mouselocator% = buttonyy%
  562.                     k% = 0
  563.  
  564.                     FOR i% = button_index% + 1 TO button_index% + button%
  565.                         IF k% THEN LOCATE , POS(0) + 2
  566.                         k% = k% + 1
  567.                         MID$(mouselocator$, POS(0)) = STRING$(LEN(button$(i%)) + 2, LTRIM$(STR$(k%)))
  568.                         PRINT SPACE$(LEN(button$(i%)) + 2);
  569.                     NEXT
  570.  
  571.                     LOCATE buttonyy%, w2% + w4% \ 2 - j% \ 2
  572.                     COLOR 0, 7
  573.                     k% = 0
  574.  
  575.                     ' Prints names on buttons.
  576.                     FOR i% = button_index% + 1 TO button_index% + button%
  577.                         IF k% THEN LOCATE buttonyy%, POS(0) + 4
  578.                         PRINT button$(i%);
  579.                         k% = k% + 1
  580.                     NEXT
  581.  
  582.                     IF pete THEN
  583.                         LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 1
  584.                         tabx% = 0: action$ = ""
  585.                         _KEYCLEAR: text$ = ""
  586.                     END IF
  587.  
  588.                     DO
  589.                         IF pete THEN
  590.                             inputfieldyy% = CSRLIN: inputfieldxx% = POS(0)
  591.  
  592.                             CALL textinput(text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb, noe, row, scr, config%, b$)
  593.  
  594.                         ELSE
  595.                             CALL user(b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  596.                         END IF
  597.  
  598.                         IF LEN(b$) THEN
  599.                             SELECT CASE b$
  600.                                 CASE CHR$(13)
  601.                                     IF pete THEN
  602.                                         action$ = "poll input lines": GOSUB tab_and_enter_fields: action$ = ""
  603.                                         IF LEN(b$) THEN ' b$ can be made null in the gosub above. This occurs when there are still more fields to fill in.
  604.                                             SELECT CASE tabx%
  605.                                                 CASE 1
  606.                                                     action$ = "Whole Word" ' F3 Find option.
  607.                                                 CASE 2
  608.                                                     action$ = "Whole/Case" ' F3 Find option.
  609.                                                     ' Find Function only.
  610.                                                 CASE 0, 3
  611.                                                     action$ = "Any Part" ' F3 Find option.
  612.                                                 CASE 4
  613.                                                     action$ = "Any/Case" ' F3 Find option.
  614.                                             END SELECT
  615.                                         END IF
  616.                                     ELSE
  617.                                         SELECT CASE tabx%
  618.                                             CASE 1
  619.                                                 IF button_index% = 0 THEN action$ = "yes"
  620.                                                 IF button_index% = 2 THEN action$ = "retry"
  621.                                             CASE 2
  622.                                                 IF button_index% = 0 THEN action$ = "no"
  623.                                                 IF button_index% = 2 THEN action$ = "abort"
  624.                                         END SELECT
  625.                                     END IF
  626.                                 CASE CHR$(27)
  627.                                     action$ = "close"
  628.                             END SELECT
  629.                         END IF
  630.  
  631.                         IF LEN(action$) THEN EXIT DO ''''' Newly added. Delete this if it causes problems.
  632.  
  633.                         IF my% = w1% AND mx% = w2% + w4% - 2 THEN
  634.                             IF closex% = 0 THEN closex% = -1: LOCATE my%, mx%: COLOR 15, 4: PRINT "x";
  635.                         ELSE
  636.                             IF closex% THEN closex% = 0: LOCATE w1%, w2% + w4% - 2: COLOR 7, 1: PRINT "x";
  637.                         END IF
  638.  
  639.                         IF bhl% THEN IF bhl% = 1 AND my% <> mouselocator% OR bhl% = 1 AND MID$(mouselocator$, mx%, 1) = "0" THEN tabx% = 0: bhl% = 0
  640.  
  641.                         IF b$ = CHR$(9) THEN GOSUB tab_and_enter_fields
  642.  
  643.                         IF oldmx% = mx% AND oldmy% = my% THEN i% = 0 ELSE i% = -1 ' Mouse has moved.
  644.                         IF b$ = CHR$(9) OR my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" AND i% THEN
  645.                             IF b$ = CHR$(9) THEN k% = tabx%: bhl% = 9 ELSE k% = VAL(MID$(mouselocator$, mx%, 1)): tabx% = k%: bhl% = 1
  646.                             IF pete THEN LOCATE , , 0 ' Hide cursor while making buttons.
  647.  
  648.                             IF h% AND h% <> tabx% THEN
  649.                                 entry$(ifrow%) = text$
  650.                                 GOSUB clear_button
  651.                             END IF
  652.  
  653.                             h% = k%: tabx% = h%
  654.  
  655.                             COLOR 0, 3
  656.                             LOCATE buttonyy%, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  657.                             PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  658.  
  659.                             IF pete THEN LOCATE inputfieldyy%, inputfieldxx%
  660.  
  661.                             _DELAY .15
  662.                         ELSE
  663.                             IF h% AND tabx% = 0 THEN
  664.                                 iyy% = CSRLIN: ixx% = POS(0)
  665.                                 IF pete THEN LOCATE , , 0
  666.                                 COLOR 0, 7
  667.                                 LOCATE buttonyy%, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  668.                                 PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  669.                                 LOCATE iyy%, ixx%
  670.                                 h% = 0: tabx% = 0
  671.                             END IF
  672.                         END IF
  673.  
  674.                         IF mb.l THEN
  675.                             IF closex% THEN SOUND 1000, .1: closex% = 0: action$ = "close"
  676.                             IF my% = mouselocator% AND MID$(mouselocator$, mx%, 1) <> "0" THEN
  677.                                 SOUND 1000, .1
  678.                                 SELECT CASE VAL(MID$(mouselocator$, mx%, 1))
  679.                                     CASE 1
  680.                                         IF button_index% = 0 THEN action$ = "yes"
  681.                                         IF button_index% = 2 THEN action$ = "retry"
  682.                                         IF button_index% = 4 THEN action$ = "Whole Word": GOSUB tab_and_enter_fields ' F3 Find option.
  683.                                     CASE 2
  684.                                         IF button_index% = 0 THEN action$ = "no"
  685.                                         IF button_index% = 2 THEN action$ = "abort"
  686.                                         IF button_index% = 4 THEN action$ = "Whole/Case": GOSUB tab_and_enter_fields ' F3 Find option.
  687.                                         ' Find Function only.
  688.                                     CASE 3
  689.                                         IF button_index% = 4 THEN action$ = "Any Part": GOSUB tab_and_enter_fields ' F3 Find option.
  690.                                     CASE 4
  691.                                         IF button_index% = 4 THEN action$ = "Any/Case": GOSUB tab_and_enter_fields ' F3 Find option.
  692.                                 END SELECT
  693.                             END IF
  694.  
  695.                             IF mb.l AND noif% > 1 THEN
  696.                                 IF mx% >= ifieldxx%(1) AND mx% <= ifieldxx%(1) + ifield% AND my% >= ifieldyy%(1) AND my% <= ifieldyy%(UBOUND(ifield$)) THEN
  697.                                     ''ss = CSRLIN: rr = POS(0): LOCATE 1, 1: PRINT i%; ifrow%; my%; ifieldyy%(ifrow%), ifieldxx%(1); mx%; ifieldxx%(1) + ifield%: LOCATE ss, rr
  698.                                     entry$(ifrow%) = text$
  699.                                     ifrow% = 0
  700.                                     FOR i% = 1 TO UBOUND(ifield$)
  701.                                         IF my% = ifieldyy%(i%) THEN ifrow% = i%: EXIT FOR
  702.                                     NEXT
  703.                                     IF ifrow% = 0 THEN CLS: PRINT "Error in ifrow%.": END '''
  704.                                     IF mx% <= ifieldxx%(ifrow%) + LEN(text$) THEN LOCATE my%, mx%, 1 ELSE LOCATE my%, ifieldxx%(ifrow%) + LEN(text$)
  705.                                     text$ = entry$(ifrow%)
  706.                                 END IF
  707.                             END IF
  708.  
  709.                         END IF
  710.  
  711.                         IF b$ = CHR$(9) THEN b$ = "" ''''''IS THIS EVEN NECESSARY ANYMORE???
  712.                         oldmy% = my%: oldmx% = mx%
  713.                     LOOP UNTIL LEN(action$) ''' An exit with len(action$) was added many lines up, so maybe this could be just loop?
  714.  
  715.                     SMODE = oldsmode: SCREEN 0, 0, SMODE, SMODE
  716.                 ELSE ' No buttons present.
  717.                     LOCATE w1% + w3% \ 2, w2% + w4% \ 2 - LEN(msg$) \ 2
  718.                     PRINT msg$;
  719.                 END IF
  720.  
  721.         END SELECT
  722.     END IF
  723.     LOCATE iyy%, ixx%
  724.     _KEYCLEAR
  725.     EXIT SUB
  726.  
  727.     clear_button:
  728.     COLOR 0, 7
  729.     LOCATE buttonyy%, INSTR(mouselocator$, LTRIM$(STR$(h%)))
  730.     PRINT SPACE$(1) + button$(h% + button_index%) + SPACE$(1);
  731.     RETURN
  732.  
  733.     tab_and_enter_fields:
  734.     DO
  735.         IF tabx% = 0 AND ifrow% <= UBOUND(ifield$) OR tabx% = button% OR LEN(action$) THEN
  736.  
  737.             IF tabx% = button% THEN ' Last tab button is highlighted. Go back to input fields.
  738.                 h% = button%: GOSUB clear_button
  739.                 entry$(ifrow%) = text$
  740.                 tabx% = 0
  741.                 IF ifrow% = UBOUND(ifield$) THEN ifrow% = 1 ELSE ifrow% = ifrow% + 1
  742.                 text$ = entry$(ifrow%): _KEYCLEAR
  743.                 LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 1
  744.                 b$ = ""
  745.                 EXIT DO
  746.             END IF
  747.  
  748.             ' Remove any highlighting.
  749.             IF UBOUND(ifield$) >= 1 THEN
  750.                 LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 0
  751.                 COLOR 7, 0 '''''''''
  752.                 PRINT SPACE$(ifield%);
  753.                 LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%)
  754.                 COLOR 7, 0 ''''''''''''
  755.                 PRINT MID$(text$, 1, ifield%);
  756.                 entry$(ifrow%) = text$
  757.                 IF ifrow% + 1 > UBOUND(ifield$) THEN
  758.                     tabx% = 1 ' To reloop.
  759.                     entry$(ifrow%) = text$
  760.                 ELSE
  761.                     entry$(ifrow%) = text$
  762.                     ifrow% = ifrow% + 1
  763.                     text$ = entry$(ifrow%): _KEYCLEAR
  764.                     LOCATE ifieldyy%(ifrow%), ifieldxx%(ifrow%), 1
  765.                     b$ = ""
  766.                     EXIT DO
  767.                 END IF
  768.             END IF
  769.             EXIT DO
  770.         ELSE
  771.             tabx% = tabx% + 1
  772.             EXIT DO
  773.         END IF
  774.     LOOP
  775.  
  776.     RETURN
  777.  
  778.  
  779. SUB user (b$, mx%, my%, alt%, shift%, ctrl%, ctrlshift%, con_panel%, doc_status_saved%)
  780.  
  781.     '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  782.  
  783.     DEF SEG = 0
  784.     IF PEEK(1047) MOD 16 = 1 OR PEEK(1047) MOD 16 = 2 THEN shift% = -1 ELSE shift% = 0
  785.     IF PEEK(1047) MOD 16 = 3 OR PEEK(1047) MOD 16 = 4 THEN ctrl% = -1 ELSE ctrl% = 0
  786.     IF PEEK(1047) MOD 16 = 5 OR PEEK(1047) MOD 16 = 6 THEN ctrlshift% = -1 ELSE ctrlshift% = 0
  787.  
  788.     IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  789.         alt% = -1: con_panel% = -1
  790.     ELSE
  791.         IF alt% THEN alt% = 0: con_panel% = 1
  792.     END IF
  793.     DEF SEG
  794.  
  795.     b$ = INKEY$
  796.  
  797.     mb.w = 0
  798.         mb.w = mb.w + _MOUSEWHEEL
  799.     WEND
  800.  
  801.     mb.l = _MOUSEBUTTON(1)
  802.     mb.r = _MOUSEBUTTON(2)
  803.     mx% = _MOUSEX
  804.     my% = _MOUSEY
  805.  
  806. SUB textinput (text$, passrightmargin%, mykey%, doctype$, doctype$(), doctype%, doctypey%(), doctypex%(), x$(), xfull$(), scrb AS my_scrb, noe AS INTEGER, row, scr, config%, b$)
  807.     STATIC initiate%
  808.     STATIC hscrollon%, hscroll%, textfg%, textbk%, highlightfg%, highlightbk%, leftmargin%, rightmargin%, noleadingspace%, textmaxlength%, linecharacter%, click_l%, drag%, shiftclick%, tabx%
  809.     STATIC starthighlight%, highlight%, overwrite%, CurAdvance%
  810.  
  811.     IF change_initiate% THEN change_initiate% = 0: initiate% = 0 ' Resets initiate%. Use when calling this sub to change settings like leftmargin% by zeroing static variable initiate%.
  812.     '''vartable% = 2: CALL setvariables(scrb, c1%, c2%, c1alt%, h1%, h2%, row, ins%, dwidth, dwidth2, menubar%)
  813.  
  814.     row = 1: tabx% = 2: thumb% = 0
  815.  
  816.     DO
  817.         IF NOT initiate% THEN ' Initiate textinput variables.
  818.             initiate% = -1
  819.             GOSUB initiate_variables
  820.         END IF
  821.  
  822.         ' --------------------POLL MOUSE--->
  823.         mb.w = 0
  824.         WHILE _MOUSEINPUT
  825.             mb.w = mb.w + _MOUSEWHEEL
  826.         WEND
  827.  
  828.         IF mb.w = 0 THEN
  829.             mx% = _MOUSEX ' Mouse column.
  830.             my% = _MOUSEY ' Mouse row.
  831.             mb.l = _MOUSEBUTTON(1)
  832.             mb.r = _MOUSEBUTTON(2)
  833.             mb.m = _MOUSEBUTTON(3)
  834.         END IF
  835.         '<----------------------------------
  836.         '''ss = CSRLIN: rr = POS(0): LOCATE 1, 1: PRINT mb.l, _MOUSEBUTTON(1): LOCATE ss, rr
  837.  
  838.         IF noleadingspace% THEN ' Remove leading spaces of any text entry in form.
  839.             IF LEFT$(text$, 1) = " " THEN
  840.                 DO UNTIL LEFT$(text$, 1) <> " " OR text$ = ""
  841.                     text$ = MID$(text$, 2)
  842.                     LOCATE , leftmargin%
  843.                     GOSUB wash
  844.                 LOOP
  845.             END IF
  846.         END IF
  847.  
  848.         '-------------------------------------------------------------------------
  849.         mykey% = _KEYHIT
  850.  
  851.         '''IF _EXIT THEN CALL exit_warning(doc_status_saved%)
  852.  
  853.         IF mykey% = 0 THEN
  854.             IF my% <> oldmy% OR mx% <> oldmx% OR mb.l OR mb.w THEN
  855.                 GOSUB mouseroutine
  856.                 IF LEN(action$) THEN EXIT DO
  857.             END IF
  858.         END IF
  859.  
  860.         ''''''IF mykey% = 0 THEN GOSUB file_display_keys
  861.  
  862.         IF mykey% > 0 THEN
  863.             GOSUB form_input_keyroutine
  864.             IF LEN(action$) THEN EXIT DO
  865.         END IF
  866.         '-------------------------------------------------------------------------
  867.         oldmy% = my%: oldmx% = mx%
  868.         IF pete THEN EXIT DO
  869.     LOOP
  870.     EXIT SUB
  871.  
  872.     '---------------------------GOSUB STATEMENTS-----------------------------
  873.     initiate_variables:
  874.     PageWidth1% = 80
  875.     PageWidth2% = 25
  876.     Topmargin% = 3
  877.     BottomMargin% = PageWidth2% - UpFromBottom%
  878.     UpFromBottom% = 2
  879.     BlockSize% = 0: REM -1 = variable.
  880.     Headers% = 0: REM On -1 or Off 0
  881.     TabElements% = 1: REM Number of input fields horizontally arranged. - 1 indicates variable.
  882.     ColorPrompt% = 0: REM 0 = COLOR 7, 0. Set all foreground/background by background * 16 + background.
  883.     ColorResponse% = 0: REM 0 will use textfg% and textbk% as defaults; otherwise set all foreground/background by background * 16 + background.
  884.     RestrictInput% = -1: REM On -1 or Off 0. (Uses 3 data fields)
  885.     InputFieldLength% = 0: REM Set to a number to allow variable length fields; otherwise filed input length will be determined by rightmargin% - (leftmargin% - 1).
  886.     PromptColumn% = 1: REM Column where prompt starts. Use 0 if no prompts. Use -1 for  multiple prompts on same row.
  887.     ResponseColumn% = 0: REM Set to a number if using Spacer%; otherwise 0 = input field follows response.
  888.  
  889.     TableStyle% = 0: REM 0 = Prompt/Space/Input, 1 = Prompt/Colon+Space/Response, 2 = Prompt/Spacers/Response
  890.     Spacer$ = ".": REM Type of spacer character if spacers are used (Table Style 2).
  891.  
  892.     textfg% = 7
  893.     textbk% = 0
  894.     highlightfg% = 0
  895.     highlightbk% = 7
  896.     leftmargin% = POS(0): iyy% = CSRLIN
  897.     rightmargin% = passrightmargin%
  898.     textmaxlength% = 250
  899.     noleadingspace% = -1
  900.     linecharacter% = 255: REM Blank space
  901.  
  902.     IF textmaxlength% > rightmargin% - (leftmargin% - 1) THEN hscrollon% = -1
  903.     IF rightmargin% < leftmargin% THEN CLS: PRINT "Rightmargin% cannot be smaller than leftmargin%. Redo.": END
  904.     IF leftmargin% < 1 OR leftmargin% > 80 THEN CLS: PRINT "Leftmargin% is not within 1 - 80 range. Redo.": END
  905.     REM no longer valid with hscroll.IF textmaxlength% > rightmargin% - leftmargin% + 1 THEN CLS: PRINT "textmaxlength% cannot exceed rightmargin% - leftmargin% + 1. Redo.:end"
  906.     IF LEN(text$) > textmaxlength% THEN CLS: PRINT "Text length cannot start out larger than textmaxlength%. Redo.": END
  907.  
  908.     IF rightmargin% = leftmargin% AND textmaxlength% = 1 THEN
  909.         CurAdvance% = 0
  910.     ELSE
  911.         CurAdvance% = 1
  912.     END IF
  913.  
  914.     COLOR textfg%, textbk%
  915.     LOCATE iyy%, leftmargin%, 1, 7, 7
  916.     RETURN '-----------------------------------------------------------------
  917.  
  918.     form_input_keyroutine:
  919.     DO ' Falk loop.
  920.         IF SMODE = 3 THEN ' Doctype dropdown is open.
  921.             SELECT CASE mykey%
  922.                 CASE 9, 27 ' Close doctype dropdown.
  923.                     GOSUB close_doctype_dropdown
  924.                 CASE 18432 ' Arrow up.
  925.                     IF CSRLIN = w1% + 17 THEN
  926.                         LOCATE w1% + 17, w2% + 15
  927.                         COLOR 7, 0: PRINT doctype$(2);
  928.                         LOCATE w1% + 16, w2% + 15
  929.                         COLOR 1, 3: PRINT doctype$(1);
  930.                     END IF
  931.                 CASE 20480 ' Arrow Down
  932.                     IF CSRLIN = w1% + 16 THEN
  933.                         LOCATE w1% + 16, w2% + 15
  934.                         COLOR 7, 0: PRINT doctype$(1);
  935.                         LOCATE w1% + 17, w2% + 15
  936.                         COLOR 1, 3: PRINT doctype$(2);
  937.                     END IF
  938.                 CASE 13 ' Enter
  939.                     b$ = CHR$(13): EXIT DO
  940.                     IF CSRLIN = w1% + 16 THEN i% = 1 ELSE i% = 2
  941.                     GOSUB close_doctype_dropdown
  942.                     GOSUB doctype_selected ' (Gosub parameter i%)
  943.             END SELECT
  944.             mykey% = 0
  945.             EXIT DO ' To REturn
  946.         END IF
  947.  
  948.         ' Process text if cursor is on form field text input line.
  949.         IF pete OR CSRLIN = w1% + w3% - 4 - 3 OR mykey% = 27 OR mykey% = 13 OR mykey% = 9 THEN ELSE EXIT DO
  950.  
  951.         IF _KEYDOWN(100303) = -1 OR _KEYDOWN(100304) = -1 THEN
  952.             SELECT CASE mykey%
  953.                 CASE 18176, 20224, 19200, 19712, 21248, 20992
  954.                     shift% = -1
  955.             END SELECT
  956.         ELSE
  957.             IF NOT drag% AND shift% THEN shift% = 0
  958.         END IF
  959.  
  960.         IF _KEYDOWN(100305) = -1 OR _KEYDOWN(100306) = -1 THEN
  961.             SELECT CASE mykey%
  962.                 CASE 86, 118
  963.                     control% = -2
  964.                 CASE ELSE
  965.                     control% = -1
  966.             END SELECT
  967.         ELSE
  968.             control% = 0
  969.         END IF
  970.  
  971.         REM Evaluate changes to highlighted text, excluding cut/copy/paste
  972.         IF highlight% AND shift% = 0 AND control% <> -1 AND mykey% <> 8 AND mykey% < 21248 THEN
  973.             IF mykey% > 31 AND mykey% < 256 THEN
  974.                 GOSUB cutcopy
  975.             ELSE
  976.                 GOSUB wash
  977.             END IF
  978.         END IF
  979.  
  980.         IF shift% = -1 AND control% = 0 THEN
  981.             SELECT CASE mykey%
  982.                 CASE 19200
  983.                     GOSUB HighlightLeft
  984.  
  985.                 CASE 19712
  986.                     IF control% THEN
  987.                         GOSUB ctrlrt
  988.                     ELSE
  989.                         GOSUB HighlightRight
  990.                     END IF
  991.  
  992.                 CASE 18176
  993.                     GOSUB SelectToHome
  994.  
  995.                 CASE 20224
  996.                     GOSUB SelectToEnd
  997.  
  998.                 CASE 21248
  999.                     mykey% = 88: REM Convert Delete to Cut
  1000.                     GOSUB cutcopy
  1001.  
  1002.                 CASE 20992
  1003.                     GOSUB PasteClipboard
  1004.             END SELECT
  1005.  
  1006.         ELSE
  1007.  
  1008.             SELECT CASE control%
  1009.                 CASE 0
  1010.                     SELECT CASE mykey%
  1011.                         CASE 18176
  1012.                             IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  1013.  
  1014.                         CASE 20224
  1015.                             IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  1016.  
  1017.                         CASE 8, 21248: REM Backspace and Delete
  1018.                             GOSUB BackspaceDelete
  1019.  
  1020.                         CASE 9: REM Tab
  1021.                             IF pete THEN b$ = CHR$(9): EXIT DO ELSE GOSUB tabkey: mykey% = 0
  1022.  
  1023.                         CASE 13
  1024.                             IF pete THEN b$ = CHR$(13): EXIT DO
  1025.                             DO ' Single falks do/loop.
  1026.                                 FOR i% = 1 TO UBOUND(formbutton$)
  1027.                                     IF formbuttonx%(i%) < 0 THEN
  1028.                                         SELECT CASE i%
  1029.                                             CASE 1
  1030.                                                 formbuttonx%(1) = ABS(formbuttonx%(1))
  1031.                                                 GOSUB popfiletypes
  1032.                                                 EXIT DO
  1033.                                             CASE 2
  1034.                                                 SELECT CASE config%
  1035.                                                     CASE 1
  1036.                                                         action$ = "open file"
  1037.                                                     CASE 2
  1038.                                                         action$ = "save as"
  1039.                                                 END SELECT
  1040.                                                 '''myfile$ = text$
  1041.                                                 EXIT DO
  1042.                                             CASE 3
  1043.                                                 action$ = "cancel"
  1044.                                                 EXIT DO
  1045.                                         END SELECT
  1046.                                     END IF
  1047.                                 NEXT
  1048.  
  1049.                                 SELECT CASE tabx%
  1050.                                     CASE 1 ' File selected from display window.
  1051.                                         IF hlf% THEN
  1052.                                             GOSUB fileselected
  1053.                                             IF action$ = "change dir" THEN tabx% = 0: EXIT DO
  1054.                                             tabx% = 2
  1055.                                         ELSE
  1056.                                             BEEP
  1057.                                         END IF
  1058.                                     CASE 2 ' Save or Open selected file.
  1059.                                         IF LEN(text$) THEN
  1060.                                             SELECT CASE config%
  1061.                                                 CASE 1
  1062.                                                     action$ = "open file"
  1063.                                                 CASE 2
  1064.                                                     action$ = "save as"
  1065.                                             END SELECT
  1066.                                             tabx% = 2
  1067.                                             '''myfile$ = text$
  1068.                                             EXIT DO
  1069.                                         ELSE
  1070.                                             BEEP
  1071.                                         END IF
  1072.                                     CASE 3 ' Open doctype dropdown menu.
  1073.                                         GOSUB popfiletypes
  1074.                                     CASE 4 ' Save or Open selected file. Only occurs when tab selected then mouse goes on another button and then goes to a neutral position. In this case the variable is no longer negative and the loop above misses it.
  1075.                                         SELECT CASE config%
  1076.                                             CASE 1
  1077.                                                 action$ = "open file"
  1078.                                             CASE 2
  1079.                                                 action$ = "save as"
  1080.                                         END SELECT
  1081.                                         tabx% = 2
  1082.                                         EXIT DO
  1083.                                     CASE 5 ' Cancel
  1084.                                         action$ = "cancel": tabx% = 2
  1085.                                         EXIT DO
  1086.                                 END SELECT
  1087.                                 EXIT DO
  1088.                             LOOP
  1089.                             IF LEN(action$) THEN EXIT DO ' To Return
  1090.  
  1091.                         CASE 19200
  1092.                             GOSUB CursorLeft
  1093.  
  1094.                         CASE 19712
  1095.                             GOSUB CursorRight
  1096.  
  1097.                         CASE 18432
  1098.                             GOSUB CursorUp
  1099.  
  1100.                         CASE 20480
  1101.                             GOSUB CursorDown
  1102.  
  1103.                         CASE 18688
  1104.                             GOSUB PageUp
  1105.  
  1106.                         CASE 20736
  1107.                             GOSUB PageDown
  1108.  
  1109.                         CASE 27
  1110.                             IF pete THEN b$ = CHR$(27): EXIT DO
  1111.                             GOSUB wash
  1112.                             EXIT DO
  1113.  
  1114.                         CASE 20992: REM Insert
  1115.                             GOSUB InsertOverwrite
  1116.  
  1117.                         CASE ELSE
  1118.                             GOSUB DisplayText
  1119.                             IF flagtext% = -1 THEN flagtext% = 0: mykey% = 0
  1120.                     END SELECT
  1121.  
  1122.                     REM Control% = -1 or -2
  1123.                 CASE -1, -2
  1124.  
  1125.                     SELECT CASE mykey%
  1126.  
  1127.                         CASE 65, 97 ' A a
  1128.                             GOSUB SelectAll
  1129.  
  1130.                         CASE 67, 99, 88, 120 ' C c X x
  1131.                             GOSUB cutcopy
  1132.  
  1133.                         CASE 86, 118 ' V v
  1134.                             REM Paste
  1135.                             GOSUB PasteClipboard
  1136.  
  1137.                         CASE 19712
  1138.                             REM Cursor and arrow right
  1139.                             GOSUB ctrlrt
  1140.  
  1141.                         CASE 19200
  1142.                             REM Cursor and arrow left
  1143.                             GOSUB ctrllt
  1144.  
  1145.                         CASE 18176
  1146.                             GOSUB CursorHome ' Ctrl + Home
  1147.  
  1148.                         CASE 20224
  1149.                             GOSUB CursorEnd ' Ctrl + End
  1150.  
  1151.                         CASE ELSE
  1152.                             ' Do nothing.
  1153.  
  1154.                     END SELECT
  1155.             END SELECT
  1156.         END IF
  1157.         EXIT DO
  1158.     LOOP
  1159.     RETURN '-----------------------------------------------------------------
  1160.  
  1161.     ' Key Actions.
  1162.     tabkey:
  1163.     tabx% = tabx% + 1
  1164.     IF tabx% > 5 THEN tabx% = 1: GOSUB clearbuttons
  1165.  
  1166.     SELECT CASE tabx%
  1167.         CASE 1
  1168.             IF hlf% THEN j% = -999: GOSUB highlightfile
  1169.             i% = 0: GOSUB displaybutton
  1170.             LOCATE , , 0: row = 1: j% = 0: GOSUB highlightfile
  1171.         CASE 2
  1172.             IF hlf% THEN j% = -999: GOSUB highlightfile
  1173.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1
  1174.         CASE 3
  1175.             i% = -1: GOSUB displaybutton
  1176.         CASE 4
  1177.             i% = -2: GOSUB displaybutton
  1178.         CASE 5
  1179.             i% = -3: GOSUB displaybutton
  1180.     END SELECT
  1181.     b$ = "": mykey% = 0: null$ = INKEY$: k% = _KEYHIT ' Clear keyboard buffers
  1182.     RETURN '------------------------------------------------------------------
  1183.  
  1184.     CursorLeft:
  1185.     IF POS(0) > leftmargin% THEN
  1186.         LOCATE , POS(0) - CurAdvance%
  1187.     ELSE
  1188.         IF hscroll% THEN hscroll% = hscroll% - 1: GOSUB wash
  1189.     END IF
  1190.     RETURN '------------------------------------------------------------------
  1191.  
  1192.     CursorRight:
  1193.     IF POS(0) < rightmargin% THEN
  1194.         IF POS(0) + CurAdvance% <= leftmargin% - 1 + LEN(text$) + 1 THEN
  1195.             IF POS(0) < rightmargin% THEN LOCATE , POS(0) + CurAdvance%
  1196.         END IF
  1197.     ELSE
  1198.         IF hscrollon% THEN
  1199.             IF hscroll% + rightmargin% - (leftmargin% - 1) <= LEN(text$) THEN
  1200.                 hscroll% = hscroll% + 1
  1201.                 GOSUB wash
  1202.             END IF
  1203.         END IF
  1204.     END IF
  1205.  
  1206.     RETURN '------------------------------------------------------------------
  1207.  
  1208.     ctrllt:
  1209.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  1210.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  1211.     IF INSTR(texttemp$, " ") <> 0 THEN
  1212.         FOR ictrllt% = POS(0) - leftmargin% + 1 + hscroll% TO 1 STEP -1
  1213.             IF exitctrl% AND MID$(text$, ictrllt% - 1, 1) = " " THEN EXIT FOR
  1214.             IF MID$(text$, ictrllt%, 1) <> " " THEN exitctrl% = -1
  1215.             IF shift% THEN GOSUB HighlightLeft ELSE GOSUB CursorLeft
  1216.         NEXT
  1217.         exitctrl% = 0
  1218.     ELSE
  1219.         IF shift% THEN GOSUB SelectToHome ELSE GOSUB CursorHome
  1220.     END IF
  1221.     RETURN '---------------------------------------------------------------------
  1222.  
  1223.     ctrlrt:
  1224.     IF highlight% <> 0 AND NOT shift% THEN GOSUB wash
  1225.     texttemp$ = MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  1226.     IF INSTR(texttemp$, " ") <> 0 THEN
  1227.         FOR ictrlrt% = POS(0) - leftmargin% + 1 + hscroll% TO LEN(text$)
  1228.             IF MID$(text$, ictrlrt%, 1) <> " " THEN
  1229.                 IF exitctrl% THEN EXIT FOR
  1230.                 jctrlrt% = -1
  1231.             END IF
  1232.             IF MID$(text$, ictrlrt%, 1) = " " AND jctrlrt% THEN exitctrl% = -1
  1233.             IF shift% THEN GOSUB HighlightRight ELSE GOSUB CursorRight
  1234.         NEXT
  1235.         exitctrl% = 0: ictrlrt% = 0: jctrlrt% = 0
  1236.     ELSE
  1237.         IF shift% THEN GOSUB SelectToEnd ELSE GOSUB CursorEnd
  1238.     END IF
  1239.     RETURN '---------------------------------------------------------------------
  1240.  
  1241.     CursorHome:
  1242.     IF hscroll% <> 0 THEN hscroll% = 0: GOSUB wash
  1243.     LOCATE , leftmargin%
  1244.     RETURN '---------------------------------------------------------------------
  1245.  
  1246.     CursorEnd:
  1247.     IF hscrollon% THEN
  1248.         IF LEN(text$) > rightmargin% - (leftmargin% - 1) THEN
  1249.             hscroll% = LEN(text$) - (rightmargin% - (leftmargin% - 1)) + 1: REM + 1 allows for adding to end of text.
  1250.             GOSUB wash
  1251.         END IF
  1252.     END IF
  1253.     IF LEN(text$) + leftmargin% - 1 >= rightmargin% THEN
  1254.         LOCATE , rightmargin%
  1255.     ELSE
  1256.         LOCATE , leftmargin% - 1 + LEN(text$) + CurAdvance%
  1257.     END IF
  1258.     RETURN '---------------------------------------------------------------------
  1259.  
  1260.     CursorUp:
  1261.     REM PRINT "Cursor Up"
  1262.     RETURN
  1263.  
  1264.     CursorDown:
  1265.     REM PRINT "Cursor Down"
  1266.     IF formbuttonx%(1) < 0 OR tabx% = 3 THEN ' Opens the doctype dropdown menu.
  1267.         formbuttonx%(1) = ABS(formbuttonx%(1))
  1268.         GOSUB popfiletypes
  1269.     END IF
  1270.     RETURN '---------------------------------------------------------------------
  1271.  
  1272.     PageUp:
  1273.     REM PRINT "Page Up"
  1274.     RETURN
  1275.  
  1276.     PageDown:
  1277.     REM PRINT "Page Down"
  1278.     RETURN
  1279.  
  1280.     REM Highlighting -----------------------------------------------------------
  1281.     HighlightLeft:
  1282.     iyy% = CSRLIN: ixx% = POS(0)
  1283.     IF POS(0) > leftmargin% OR hscroll% THEN
  1284.  
  1285.         IF highlight% AND POS(0) >= highlight% - hscroll% THEN ' Unhighlighting left to right.
  1286.             ' Move back first and then calculate POS(0) - 1, below.
  1287.             IF highlight% = starthighlight% THEN
  1288.                 starthighlight% = 0: highlight% = 0
  1289.             ELSE
  1290.                 highlight% = POS(0) - 1 + hscroll% ' Diminishing.
  1291.             END IF
  1292.         ELSE ' Highlighting left to right.
  1293.             ' Calculate first and then move back. POS(0).
  1294.             IF highlight% = 0 THEN highlight% = POS(0) + hscroll%
  1295.             starthighlight% = POS(0) + hscroll%
  1296.         END IF
  1297.  
  1298.         IF POS(0) = leftmargin% AND hscroll% THEN hscroll% = hscroll% - 1 ' hscroll% is reduced after the calculations above.
  1299.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  1300.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  1301.  
  1302.         LOCATE iyy%, leftmargin%
  1303.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  1304.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  1305.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  1306.  
  1307.         IF ixx% - leftmargin% > 0 THEN ixx% = ixx% - 1 ' No moving cursor back when it is at left amrgin and scrolling text back.
  1308.         LOCATE iyy%, ixx%
  1309.         COLOR textfg%, textbk%
  1310.     END IF
  1311.     RETURN '---------------------------------------------------------------------
  1312.  
  1313.     HighlightRight:
  1314.     iyy% = CSRLIN: ixx% = POS(0)
  1315.     IF hscroll% + ixx% + 1 - leftmargin% <= LEN(text$) THEN
  1316.         c1% = textfg%: c2% = textbk%: c3% = highlightfg%: c4% = highlightbk%
  1317.  
  1318.         IF POS(0) >= starthighlight% - hscroll% THEN
  1319.             IF starthighlight% = 0 THEN starthighlight% = POS(0) + 1 + hscroll%
  1320.             highlight% = POS(0) + 1 + hscroll%
  1321.         ELSE
  1322.             IF starthighlight% = highlight% THEN
  1323.                 starthighlight% = 0: highlight% = 0
  1324.             ELSE
  1325.                 starthighlight% = POS(0) + 2 + hscroll%
  1326.             END IF
  1327.         END IF
  1328.  
  1329.         IF POS(0) = rightmargin% AND LEN(text$) - hscroll% > rightmargin% - leftmargin% THEN hscroll% = hscroll% + 1
  1330.         texttemp$ = MID$(text$, 1 + hscroll%, rightmargin% - leftmargin% + 1)
  1331.  
  1332.         LOCATE iyy%, leftmargin%
  1333.         COLOR c1%, c2%: PRINT MID$(texttemp$, 1, starthighlight% - hscroll% - leftmargin% - 1);
  1334.         COLOR c3%, c4%: PRINT MID$(texttemp$, starthighlight% - hscroll% - leftmargin% + 0, ABS(highlight% - starthighlight%) + 1);
  1335.         COLOR c1%, c2%: PRINT MID$(texttemp$, highlight% - hscroll% - leftmargin% + 1);
  1336.         IF POS(0) = rightmargin% THEN PRINT SPACE$(1); ' Only used when highlighting past last character to include one blank space.
  1337.         IF ixx% < rightmargin% THEN ixx% = ixx% + 1
  1338.         LOCATE iyy%, ixx%
  1339.         COLOR textfg%, textbk%
  1340.     END IF
  1341.     RETURN '---------------------------------------------------------------------
  1342.  
  1343.     ClickhighLight:
  1344.     j% = 0
  1345.     texttemp$ = MID$(text$, 1, POS(0) - leftmargin% + 1 + hscroll%)
  1346.     FOR i% = LEN(texttemp$) TO 1 STEP -1
  1347.         IF MID$(texttemp$, i%, 1) = " " AND j% THEN EXIT FOR ELSE j% = -1
  1348.     NEXT
  1349.     jClickhighLight% = LEN(texttemp$) - i% - 1
  1350.     invokestarthighlight% = POS(0) + hscroll% - (LEN(texttemp$) - i%) + 1
  1351.     FOR iClickhighLight% = 1 TO jClickhighLight%
  1352.         IF POS(0) = leftmargin% THEN EXIT FOR
  1353.         GOSUB CursorLeft
  1354.     NEXT
  1355.     shift% = -1
  1356.     GOSUB ctrlrt
  1357.     shift% = 0
  1358.     invokestarthighlight% = 0: iClickhighLight% = 0: jClickhighLight% = 0
  1359.     RETURN '---------------------------------------------------------------------
  1360.  
  1361.     SelectAll:
  1362.     highlight% = 0: starthighlight% = 0: REM These are not zeroed as a ctrl keys bypass remove highlighting
  1363.     GOSUB CursorHome
  1364.     GOSUB SelectToEnd
  1365.     RETURN '---------------------------------------------------------------------
  1366.  
  1367.     SelectToEnd:
  1368.     IF mspan% = 0 THEN mspan% = POS(0) - leftmargin% + 1 + LEN(text$)
  1369.     FOR iSelectToEnd% = 1 TO mspan%
  1370.         GOSUB HighlightRight
  1371.     NEXT
  1372.     mspan% = 0: iSelectToEnd% = 0
  1373.     RETURN '---------------------------------------------------------------------
  1374.  
  1375.     SelectToHome:
  1376.     IF mspan% = 0 THEN
  1377.         IF POS(0) = rightmargin% THEN
  1378.             mspan% = rightmargin% - (leftmargin% - 1) + hscroll%
  1379.         ELSE
  1380.             mspan% = POS(0) - leftmargin% + 1 + hscroll%
  1381.         END IF
  1382.     END IF
  1383.  
  1384.     FOR iSelectToHome% = 1 TO mspan%
  1385.         GOSUB HighlightLeft
  1386.     NEXT
  1387.     mspan% = 0: iSelectToHome% = 0
  1388.     RETURN '---------------------------------------------------------------------
  1389.  
  1390.     DisplayText:
  1391.     DO ' Falk loop.
  1392.         IF mykey% > 31 AND mykey% < 256 THEN
  1393.             COLOR 7, 0: LOCATE , , 1
  1394.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  1395.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 2)
  1396.             ELSE
  1397.                 texttemp$ = MID$(text$, 1, POS(0) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) - leftmargin% + 1)
  1398.             END IF
  1399.  
  1400.             positioncursor% = POS(0)
  1401.  
  1402.             IF overwrite% = -1 OR CurAdvance% = 0 THEN
  1403.  
  1404.                 IF POS(0) - leftmargin% + hscroll% < textmaxlength% THEN
  1405.                     text$ = MID$(text$, 1, POS(0) + (hscroll%) - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 2)
  1406.                 ELSE
  1407.                     flagtext% = -1: EXIT DO 'To Return
  1408.                 END IF
  1409.  
  1410.                 REM Evaluate Horizontal Scroll
  1411.                 IF POS(0) = rightmargin% THEN
  1412.                     hscroll% = hscroll% + 1
  1413.                 END IF
  1414.             ELSE
  1415.                 IF LEN(text$) < textmaxlength% THEN
  1416.                     text$ = MID$(text$, 1, POS(0) + hscroll% - leftmargin%) + CHR$(mykey%) + MID$(text$, POS(0) + hscroll% - leftmargin% + 1)
  1417.                     flagtext% = 0
  1418.                 ELSE
  1419.                     flagtext% = -1
  1420.                 END IF
  1421.  
  1422.                 IF flagtext% = -1 THEN EXIT DO ' To Return REM flagtext% is set to zero upon return and exit.
  1423.  
  1424.                 REM Evaluate Horizontal Scroll
  1425.                 IF hscrollon% AND POS(0) = rightmargin% THEN
  1426.                     hscroll% = hscroll% + 1
  1427.                 END IF
  1428.             END IF
  1429.  
  1430.             ' Print to form input line.-------------------------------------->
  1431.             LOCATE , leftmargin%: PRINT STRING$(rightmargin% - (leftmargin% - 1), linecharacter%);
  1432.             LOCATE , leftmargin%: PRINT MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1));
  1433.             ' <---------------------------------------------------------------
  1434.  
  1435.             IF CurAdvance% = 1 AND positioncursor% - leftmargin% + 1 < rightmargin% - leftmargin% + 1 THEN
  1436.                 LOCATE , positioncursor% + CurAdvance%
  1437.             ELSE
  1438.                 LOCATE , positioncursor%
  1439.             END IF
  1440.         END IF
  1441.         EXIT DO
  1442.     LOOP
  1443.     RETURN '---------------------------------------------------------------------
  1444.  
  1445.     BackspaceDelete:
  1446.     IF highlight% THEN GOSUB cutcopy
  1447.     IF POS(0) > leftmargin% OR mykey% = 21248 OR hscroll% > 0 THEN
  1448.         IF POS(0) <= leftmargin% + LEN(text$) THEN
  1449.             IF mykey% = 8 THEN
  1450.                 IF POS(0) <= leftmargin% + 2 AND hscroll% > 0 THEN
  1451.                     REM Adjust for horizontal scroll
  1452.                     holdcursor% = POS(0)
  1453.                     LOCATE , leftmargin%
  1454.                     countcolumnsmoved% = hscroll%
  1455.                     jBackspaceDelete% = (rightmargin% - (leftmargin% - 1)) * .33
  1456.                     IF jBackspaceDelete% < 3 AND rightmargin% - (leftmargin% - 1) > 3 THEN jBackspaceDelete% = 3: REM Set minimum scroll back.
  1457.                     FOR iBackspaceDelete% = 1 TO jBackspaceDelete%
  1458.                         GOSUB CursorLeft
  1459.                     NEXT
  1460.                     LOCATE , holdcursor% + countcolumnsmoved% - hscroll% - 1
  1461.                     countcolumnsmoved% = 0: iBackspaceDelete% = 0: jBackspaceDelete% = 0
  1462.                 ELSE
  1463.                     LOCATE , POS(0) - 1
  1464.                 END IF
  1465.             END IF
  1466.             iyy% = CSRLIN: ixx% = POS(0)
  1467.             text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + MID$(text$, POS(0) - leftmargin% + hscroll% + 2)
  1468.             texttemp$ = MID$(text$, hscroll% + 1, rightmargin% - (leftmargin% - 1))
  1469.             LOCATE iyy%, leftmargin%: PRINT texttemp$ + STRING$((rightmargin% - (leftmargin% - 1)) - LEN(texttemp$), linecharacter%);
  1470.             LOCATE iyy%, ixx%
  1471.         END IF
  1472.     END IF
  1473.     RETURN '---------------------------------------------------------------------
  1474.  
  1475.     cutcopy:
  1476.     IF highlight% THEN
  1477.         IF mykey% = 99 OR mykey% = 120 THEN
  1478.             _CLIPBOARD$ = MID$(text$, starthighlight% - leftmargin%, highlight% - starthighlight% + 1)
  1479.         END IF
  1480.  
  1481.         IF mykey% = 88 OR mykey% = 120 OR mykey% = 8 OR mykey% = 21248 THEN ' ctrl + x (cut), delete, backspace.
  1482.             positioncursor% = starthighlight% - 1 - hscroll%
  1483.             texttemp$ = MID$(text$, 1, starthighlight% - leftmargin% - 1) + MID$(text$, highlight% - leftmargin% + 1)
  1484.             text$ = texttemp$
  1485.             hscroll% = hscroll% - ABS(highlight% - starthighlight%)
  1486.             IF hscroll% < 0 THEN hscroll% = 0
  1487.             LOCATE , positioncursor%
  1488.             GOSUB wash
  1489.         END IF
  1490.     END IF
  1491.     RETURN '---------------------------------------------------------------------
  1492.  
  1493.     PasteClipboard:
  1494.     IF LEN(text$) + LEN(_CLIPBOARD$) <= textmaxlength% THEN
  1495.         text$ = MID$(text$, 1, POS(0) - leftmargin% + hscroll%) + _CLIPBOARD$ + MID$(text$, POS(0) - leftmargin% + 1 + hscroll%)
  1496.         i% = LEN(_CLIPBOARD$) - (rightmargin% - POS(0))
  1497.         positioncursor% = POS(0) + LEN(_CLIPBOARD$) - 1 + CurAdvance%
  1498.         IF positioncursor% > rightmargin% THEN
  1499.             hscroll% = hscroll% + positioncursor% - rightmargin%
  1500.             positioncursor% = rightmargin%
  1501.         END IF
  1502.         LOCATE , positioncursor%
  1503.         GOSUB wash
  1504.     ELSE
  1505.         BEEP
  1506.     END IF
  1507.     RETURN '---------------------------------------------------------------------
  1508.  
  1509.     InsertOverwrite:
  1510.     IF overwrite% = 0 THEN
  1511.         overwrite% = -1
  1512.         LOCATE , , 1, 7, 30
  1513.     ELSE
  1514.         overwrite% = 0
  1515.         LOCATE , , 1, 7, 7
  1516.     END IF
  1517.     RETURN
  1518.     ' End Key Controls-------------------------------------------------------
  1519.  
  1520.     mouseroutine:
  1521.     DO ' Falk loop
  1522.         IF shiftclick% THEN
  1523.             IF shiftclick% > 0 THEN mykey% = 19712: shiftclick% = shiftclick% - 1 ELSE mykey% = 19200: shiftclick% = shiftclick% + 1
  1524.             EXIT DO ' To Return
  1525.         END IF
  1526.  
  1527.         IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN shift% = -1 ELSE shift% = 0
  1528.  
  1529.         IF my% > margin.t + page.h OR my% <= margin.t THEN
  1530.             IF my% > margin.t + page.h + 2 AND hlf% THEN ' Unhighlight file in display window.
  1531.                 j% = -999: GOSUB highlightfile ' hlf% is in statement above
  1532.                 tabx% = 2
  1533.                 LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' Move to text input field.
  1534.             END IF
  1535.  
  1536.             IF pete = 0 THEN ' Exclude this routine from find / find and replace functions.
  1537.                 IF NOT drag% THEN
  1538.                     IF my% = w1% AND mx% = w2% + w4% - 2 THEN
  1539.                         IF closepop% = 0 THEN
  1540.                             LOCATE , , 0
  1541.                             IF hlf% THEN j% = -999: GOSUB highlightfile
  1542.                             IF oldsmode2 THEN ' doctype dropdown menu is open.
  1543.                             ELSE
  1544.                                 GOSUB clearbuttons: tabx% = 2
  1545.                             END IF
  1546.                             LOCATE w1% + w3% - 4 - 3, w2% + 15
  1547.                             GOSUB wash
  1548.                             COLOR 15, 4
  1549.                             LOCATE w1%, w2% + w4% - 2
  1550.                             PRINT "x";
  1551.                             closepop% = -1
  1552.                             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1
  1553.                             COLOR textfg%, textbk%
  1554.                         END IF
  1555.                     ELSE
  1556.                         IF closepop% THEN
  1557.                             iyy% = CSRLIN: ixx% = POS(0)
  1558.                             closepop% = 0
  1559.                             COLOR 15, 1
  1560.                             LOCATE w1%, w2% + w4% - 2, 0
  1561.                             PRINT "x";
  1562.                             LOCATE iyy%, ixx%, 1
  1563.                             COLOR textfg%, textbk%
  1564.                         END IF
  1565.                     END IF
  1566.  
  1567.                     SELECT CASE SMODE
  1568.                         CASE 3 ' doctypedropdown menu open.
  1569.                             FOR i% = 1 TO UBOUND(doctype$)
  1570.                                 IF my% = doctypey%(i%) AND mx% >= ABS(doctypex%(i%)) AND mx% < ABS(doctypex%(i%)) + LEN(doctype$(i%)) THEN
  1571.                                     IF doctypex%(i%) > 0 THEN
  1572.                                         COLOR 0, 3: LOCATE doctypey%(i%), doctypex%(i%), 0
  1573.                                         PRINT doctype$(i%);
  1574.                                         doctypex%(i%) = -doctypex%(i%)
  1575.                                         COLOR textfg%, textbk%
  1576.                                     END IF
  1577.                                 ELSE
  1578.                                     IF doctypex%(i%) < 0 THEN
  1579.                                         doctypex%(i%) = ABS(doctypex%(i%))
  1580.                                         iyy% = CSRLIN: ixx% = POS(0)
  1581.                                         COLOR 7, 0: LOCATE doctypey%(i%), doctypex%(i%), 0
  1582.                                         PRINT doctype$(i%);
  1583.                                         LOCATE iyy%, ixx%, 0
  1584.                                         COLOR textfg%, textbk%
  1585.                                     END IF
  1586.                                 END IF
  1587.                             NEXT
  1588.                         CASE ELSE
  1589.                             j% = 0
  1590.                             FOR i% = 1 TO UBOUND(formbutton$)
  1591.                                 IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% < ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1592.                                     IF formbuttonx%(i%) > 0 THEN
  1593.                                         iyy% = CSRLIN: ixx% = POS(0)
  1594.                                         COLOR 0, 3: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1595.                                         PRINT formbutton$(i%);
  1596.                                         formbuttonx%(i%) = -formbuttonx%(i%)
  1597.                                         j% = -1
  1598.                                         IF iyy% = w1% + w3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1599.                                         COLOR textfg%, textbk%
  1600.                                     END IF
  1601.                                 ELSE
  1602.                                     formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1603.                                     iyy% = CSRLIN: ixx% = POS(0)
  1604.                                     COLOR 1, 7: LOCATE formbuttony%(i%), formbuttonx%(i%), 0
  1605.                                     PRINT formbutton$(i%);
  1606.                                     IF iyy% = w1% + w3% - 4 - 3 THEN LOCATE iyy%, ixx%, 1 ELSE LOCATE iyy%, ixx%, 0
  1607.                                     COLOR textfg%, textbk%
  1608.                                 END IF
  1609.                                 IF formbuttonx%(i%) < 0 THEN j% = -1 ' Used below to designate a button is highlighted.
  1610.                             NEXT
  1611.  
  1612.                             IF tabx% >= 3 AND tabx% <= 5 AND j% = 0 THEN
  1613.                                 COLOR 0, 3: LOCATE formbuttony%(tabx% - 2), ABS(formbuttonx%(tabx% - 2)), 0
  1614.                                 PRINT formbutton$(tabx% - 2);
  1615.                             END IF
  1616.                     END SELECT
  1617.                 END IF
  1618.             END IF
  1619.  
  1620.             IF mb.l THEN
  1621.                 IF closepop% THEN action$ = "close": EXIT DO ' To Return
  1622.  
  1623.                 IF NOT drag% THEN
  1624.                     IF oldsmode2 THEN ' Doctype dropdown menu is open.
  1625.                         FOR i% = 1 TO UBOUND(doctype$)
  1626.                             IF doctypex%(i%) < 0 THEN
  1627.                                 GOSUB close_doctype_dropdown
  1628.                                 GOSUB doctype_selected
  1629.                                 doctypex%(i%) = ABS(doctypex%(i%))
  1630.                             END IF
  1631.                         NEXT
  1632.                     END IF
  1633.  
  1634.                     FOR i% = 1 TO UBOUND(formbutton$) ' Check control buttons.
  1635.                         IF formbuttonx%(i%) < 0 THEN
  1636.                             IF my% = formbuttony%(i%) AND mx% >= ABS(formbuttonx%(i%)) AND mx% <= ABS(formbuttonx%(i%)) + LEN(formbutton$(i%)) THEN
  1637.                                 formbuttonx%(i%) = ABS(formbuttonx%(i%))
  1638.                                 SOUND 1000, .1
  1639.                                 LOCATE , , 0
  1640.                                 SELECT CASE i%
  1641.                                     CASE 1 ' Open doctype dropdown menu.
  1642.                                         GOSUB popfiletypes
  1643.                                     CASE 2 ' Open button.
  1644.                                         SELECT CASE config%
  1645.                                             CASE 1
  1646.                                                 action$ = "open file"
  1647.                                             CASE 2
  1648.                                                 action$ = "save as"
  1649.                                         END SELECT
  1650.                                         '''myfile$ = text$
  1651.                                         EXIT DO ' To Return.
  1652.                                     CASE 3 ' Cancel button.
  1653.                                         action$ = "cancel": EXIT DO ' To Return.
  1654.                                 END SELECT
  1655.                             END IF
  1656.                         END IF
  1657.                     NEXT
  1658.                 END IF
  1659.  
  1660.                 IF mx% > leftmargin% + LEN(text$) THEN EXIT DO ' To Return
  1661.  
  1662.                 IF click_l% >= 0 THEN
  1663.                     click_l% = -1
  1664.                     IF highlight% AND NOT shift% THEN GOSUB wash
  1665.                 END IF
  1666.  
  1667.                 IF shift% THEN
  1668.                     SELECT CASE mx%
  1669.                         CASE IS > POS(0): mykey% = 19712: shiftclick% = mx% - POS(0) - 1
  1670.                         CASE IS = POS(0): mykey% = 0
  1671.                         CASE IS < POS(0): mykey% = 19200: shiftclick% = mx% - POS(0) + 1
  1672.                     END SELECT
  1673.                     IF mykey% THEN EXIT DO ' To Return
  1674.                 END IF
  1675.             ELSE
  1676.                 IF click_l% = -1 THEN click_l% = 1: drag% = 0
  1677.             END IF
  1678.  
  1679.             IF click_l% = -1 THEN
  1680.                 IF mx% = POS(0) THEN
  1681.                     drag% = -1
  1682.                 ELSE
  1683.                     IF my% = CSRLIN AND drag% = 0 THEN
  1684.                         IF pete THEN
  1685.                             ' Cursor was already placed in popup sub.
  1686.                         ELSE
  1687.                             LOCATE my%, mx% ' Click in input field. '''''''' DOESN'T mx% NEED TO BE LIMITED IN OLD ROUTINE, TOO???
  1688.                         END IF
  1689.                     END IF
  1690.                 END IF
  1691.             END IF
  1692.  
  1693.             IF drag% THEN
  1694.                 shift% = -1
  1695.                 SELECT CASE mx%
  1696.                     CASE IS > POS(0): mykey% = 19712: IF mx% > rightmargin% THEN _DELAY .05
  1697.                     CASE IS = POS(0): mykey% = 0
  1698.                     CASE IS < POS(0): mykey% = 19200: IF mx% < leftmargin% THEN _DELAY .05
  1699.                 END SELECT
  1700.             END IF
  1701.  
  1702.             EXIT DO ' To Return
  1703.  
  1704.         ELSE
  1705.  
  1706.             DO
  1707.                 IF SMODE = 3 THEN EXIT DO
  1708.                 IF my% > margin.t AND my% - margin.t <= page.h AND mx% > margin.l AND mx% < margin.l + page.w THEN
  1709.                     tabx% = 1: GOSUB clearbuttons
  1710.                     IF mb.l AND NOT lbdown% THEN
  1711.                         IF my% = CSRLIN THEN ' File Selected
  1712.                             lbdown% = -1
  1713.                             GOSUB fileselected
  1714.                             EXIT DO
  1715.                         END IF
  1716.                     ELSE
  1717.                         IF mb.l = 0 THEN lbdown% = 0
  1718.                     END IF
  1719.  
  1720.                     IF hlf% = 0 THEN
  1721.                         row = my% - margin.t: j% = 0: GOSUB highlightfile
  1722.                     ELSEIF oldmy% > my% AND my% - margin.t <= page.h AND row > 1 THEN
  1723.                         i% = my%: IF i% - margin.t > 0 THEN
  1724.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1725.                             DO UNTIL CSRLIN <= i%
  1726.                                 row = row - 1: j% = 0: GOSUB highlightfile
  1727.                             LOOP
  1728.                         END IF
  1729.                     ELSEIF oldmy% AND oldmy% < my% AND row < page.h THEN
  1730.                         i% = my%: IF i% - margin.t <= page.h THEN
  1731.                             LOCATE oldmy%: row = CSRLIN - margin.t
  1732.                             DO UNTIL CSRLIN >= i%
  1733.                                 row = row + 1: j% = 0: GOSUB highlightfile
  1734.                             LOOP
  1735.                         END IF
  1736.                     END IF
  1737.                 END IF
  1738.  
  1739.                 ' ------------------------------------Mouse----------------------------------
  1740.  
  1741.                 IF locked% < 0 THEN ' Mouse effects on mouse lock. key press effects are determined at inkey$ input, as key variable cannot be evaluated here, due to b$ = "" manipulations in the keypress routine.
  1742.                     IF mb.l OR mb.r OR mb.m THEN locked% = 0
  1743.                 END IF
  1744.  
  1745.                 IF mb.w THEN ' Determine if wheel is being used to scroll highlighted or unhighlighted text.
  1746.                     GOSUB clearbuttons
  1747.                     tabx% = 1 ' Reset tab index when mouse wheel is engaged.
  1748.                     locked% = 2 ' 2 is lock scrollbar, no highlighting permitted.
  1749.                 END IF
  1750.  
  1751.                 IF mb.l AND locked% <> 1 OR mb.w AND locked% <> -1 THEN
  1752.                     tabx% = 1
  1753.                     IF mb.l THEN GOSUB clearbuttons
  1754.                     ' Scrollbar routine.
  1755.                     IF mx% >= scrb.l - 1 AND mx% <= scrb.l + 1 AND my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 THEN draglock% = -1
  1756.  
  1757.                     IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR mx% = scrb.l AND scrb.s <> 0 AND my% >= scrb.t AND my% <= scrb.b AND mb.w = 0 OR scrbardrag% <> 0 AND my% > scrb.t AND my% < scrb.b AND mb.w = 0 OR mb.w > 0 AND scrb.x + scrb.s < scrb.h OR mb.w < 0 AND scrb.x > 0 THEN ' Mouse on scrollbar, doing a bar cursor drag or using the scroll wheel.
  1758.                         locked% = 2 ' Locked on scrollbar
  1759.                         IF my% = scrb.t AND scrb.x > 0 OR my% = scrb.b AND scrb.x + scrb.s < scrb.h OR mb.w <> 0 AND scr + page.h < noe THEN ' Mouse on a scrollbar arrow.
  1760.                             IF my% = scrb.t AND mb.w = 0 OR mb.w < 0 THEN scrb.x = scrb.x - 1: h% = -1 ELSE scrb.x = scrb.x + 1: h% = -2 ' Top or bottom arrow.
  1761.                             IF mb.w = 0 THEN delay.on! = .15
  1762.                             j% = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1763.  
  1764.                             IF j% >= 0 THEN ' Condition exists unless j% is negative such as doc is blank and mouse wheel is rolled downward.
  1765.                                 scrb.i = j%
  1766.  
  1767.                                 scr = scrb.i
  1768.  
  1769.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr) ' Positions scrollbar box.
  1770.  
  1771.                                 GOSUB scrollscrn
  1772.                             END IF
  1773.  
  1774.                         ELSEIF my% - (scrb.t + 1) >= scrb.x AND my% - (scrb.t + 1) <= scrb.x + scrb.s - 1 AND scrbardrag% = 0 THEN ' Mouse on scrollbar block.
  1775.                             scrbardrag% = -1: scrb.adjust = (my% - (scrb.t + 1)) - scrb.x
  1776.                         ELSEIF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% > scrb.t AND my% < scrb.b THEN ' Mouse on scrollbar between scrollbar arrow and cursor.
  1777.                             IF draglock% = -1 AND my% > scrb.t AND my% < scrb.b OR my% - (scrb.t + 1) - scrb.adjust >= 0 AND my% - (scrb.t + 1) + scrb.s - scrb.adjust <= scrb.h AND scrbardrag% <> -1 OR scrbardrag% = 0 THEN
  1778.                                 IF scrbardrag% = 0 THEN ' No drag, so adjust for cursor length for a click inside the scrollbar above or below the current scrollbar cursor position.
  1779.                                     IF my% - (scrb.t + 1) > scrb.x THEN
  1780.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x - 1: h% = -1
  1781.                                     ELSE
  1782.                                         scrb.adjust = (my% - (scrb.t + 1)) - scrb.x + 1: h% = -2
  1783.                                     END IF
  1784.                                 END IF
  1785.                                 scrb.x = my% - (scrb.t + 1) - scrb.adjust
  1786.                                 scrb.i = INT(scrb.x * ((noe - scrb.d) / (scrb.h - scrb.s)))
  1787.  
  1788.                                 scr = scrb.i
  1789.  
  1790.                                 '''h% = 0: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1791.  
  1792.                                 GOSUB scrollscrn
  1793.  
  1794.                             ELSE ' Scrollbar is at top or bottom and mouse cursor is moving vertically along the scrollbar cursor. This allows the variable to readjust.
  1795.                                 IF mx% = scrb.l THEN scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1796.                             END IF
  1797.                         END IF
  1798.                         ' =======================================================
  1799.  
  1800.                     END IF
  1801.  
  1802.                     IF delay.on! THEN ' Scrollbar delay.
  1803.                         _DELAY delay.on!
  1804.                         delay.on! = 0 ' Toggle off.
  1805.                     END IF
  1806.  
  1807.                 ELSE
  1808.                     scrbardrag% = 0: scrb.adjust = 0: draglock% = 0
  1809.                     IF locked% = 2 AND mb.l = 0 THEN locked% = 0
  1810.                 END IF
  1811.                 EXIT DO
  1812.             LOOP
  1813.         END IF
  1814.         EXIT DO
  1815.     LOOP
  1816.     RETURN '---------------------------------------------------------------------
  1817.  
  1818.     file_display_keys:
  1819.     DO '
  1820.         IF CSRLIN >= margin.t AND CSRLIN <= margin.t + page.h AND mb.l = 0 OR autokey% THEN
  1821.             ' Key commands for form input line.
  1822.             IF autokey% = 0 THEN b$ = INKEY$ ELSE b$ = MID$(b$, 3): IF LEN(b$) = 2 THEN autokey% = 0
  1823.             IF LEN(b$) THEN
  1824.                 IF b$ = CHR$(9) THEN GOSUB tabkey: b$ = "": null$ = INKEY$: EXIT DO ' tabx% assignment.
  1825.                 SELECT CASE MID$(b$, 1, 2) ' File directory window keys.
  1826.                     CASE CHR$(0) + "H"
  1827.                         IF row > 1 THEN
  1828.                             row = row - 1
  1829.                             LOCATE margin.t + row, margin.l + 1
  1830.                             j% = 0: GOSUB highlightfile
  1831.                         ELSE
  1832.                             IF scr > 0 THEN
  1833.                                 scr = scr - 1
  1834.                                 GOSUB scrollscrn
  1835.                                 j% = 0: GOSUB highlightfile
  1836.                             END IF
  1837.                         END IF
  1838.                     CASE CHR$(0) + "P"
  1839.                         IF tabx% <> 3 THEN
  1840.                             IF row < page.h THEN
  1841.                                 row = row + 1
  1842.                                 j% = 0: GOSUB highlightfile
  1843.                                 LOCATE margin.t + row, margin.l + 1
  1844.                             ELSE
  1845.                                 IF scr + page.h < noe THEN
  1846.                                     scr = scr + 1
  1847.                                     GOSUB scrollscrn
  1848.                                     j% = 0: GOSUB highlightfile
  1849.                                 END IF
  1850.                             END IF
  1851.                         ELSE
  1852.                             ' Arrow down key is highlighted by tabx%. Now open the doctype dropdown menu.
  1853.                             GOSUB popfiletypes
  1854.                         END IF
  1855.                     CASE CHR$(0) + "I"
  1856.                         autokey% = -1
  1857.                         LOCATE , margin.l + 1
  1858.                         k% = page.h - 1 + row - 2
  1859.                         FOR j% = 0 TO k%
  1860.                             b$ = b$ + CHR$(0) + "H"
  1861.                         NEXT
  1862.                         FOR j% = 1 TO row - 1
  1863.                             b$ = b$ + CHR$(0) + "P"
  1864.                         NEXT
  1865.                     CASE CHR$(0) + "Q"
  1866.                         autokey% = -1
  1867.                         LOCATE , margin.l + 1
  1868.                         k% = (page.h - 1) + (page.h - row) - 1
  1869.                         FOR j% = 0 TO k%
  1870.                             b$ = b$ + CHR$(0) + "P"
  1871.                         NEXT
  1872.                         FOR j% = 1 TO page.h - row
  1873.                             b$ = b$ + CHR$(0) + "H"
  1874.                         NEXT
  1875.                     CASE CHR$(0) + "w" ' Ctrl + Home
  1876.                         row = 1
  1877.                         IF scr > 0 THEN
  1878.                             scr = 0
  1879.                             h% = 0: GOSUB scrollscrn
  1880.                         END IF
  1881.                         LOCATE margin.t + 1, margin.l + 1
  1882.                         j% = 0: GOSUB highlightfile
  1883.                     CASE CHR$(0) + "u" ' Ctrl + End
  1884.                         IF noe > page.h THEN
  1885.                             row = page.h
  1886.                             scr = noe - row
  1887.                             LOCATE margin.t + 1, margin.l + 1
  1888.                             h% = 0: GOSUB scrollscrn
  1889.                             row = page.h
  1890.                             LOCATE margin.t + row, margin.l + 1
  1891.                             j% = 0: GOSUB highlightfile
  1892.                         ELSE
  1893.                             row = noe
  1894.                             LOCATE margin.t + row, margin.l + 1
  1895.                             j% = 0: GOSUB highlightfile
  1896.                         END IF
  1897.                     CASE CHR$(13)
  1898.                         GOSUB fileselected
  1899.                 END SELECT
  1900.             END IF
  1901.         ELSE
  1902.             null$ = INKEY$ ' Clear buffer
  1903.         END IF
  1904.         EXIT DO
  1905.     LOOP
  1906.  
  1907.     RETURN '---------------------------------------------------------------------
  1908.  
  1909.     '-------------------------------Nested Gosubs-----------------------------
  1910.  
  1911.     scrollscrn:
  1912.     FOR i% = 1 TO page.h
  1913.         LOCATE margin.t + i%, margin.l + 1
  1914.         PRINT x$(i% + scr);
  1915.     NEXT
  1916.     LOCATE row + margin.t, margin.l + 1
  1917.     IF hlf% AND LEN(b$) < 3 AND scrbardrag% = 0 THEN j% = 0: GOSUB highlightfile
  1918.  
  1919.     '''h% = 1: CALL scrollbar_update(h%, scrb, noe, row, scr)
  1920.  
  1921.     RETURN '---------------------------------------------------------------------
  1922.  
  1923.     highlightfile:
  1924.     IF j% = -999 THEN ' Unhighlight text only.
  1925.         COLOR 7, 0
  1926.         LOCATE margin.t + hlf%, margin.l + 1, 0
  1927.         PRINT x$(hlf% + scr);
  1928.         hlf% = 0
  1929.     ELSE
  1930.         IF hlf% THEN
  1931.             LOCATE margin.t + hlf%, margin.l + 1, 0
  1932.             COLOR 7, 0: PRINT x$(hlf% + scr);
  1933.         END IF
  1934.         COLOR 1, 3
  1935.         LOCATE margin.t + row, margin.l + 1, 0
  1936.         PRINT x$(row + scr);
  1937.         hlf% = row
  1938.         COLOR c1%, c2%
  1939.     END IF
  1940.     RETURN '---------------------------------------------------------------------
  1941.  
  1942.     wash:
  1943.     starthighlight% = 0
  1944.     highlight% = 0
  1945.     iyy% = CSRLIN: ixx% = POS(0)
  1946.     COLOR textfg%, textbk%
  1947.     LOCATE , leftmargin%
  1948.     texttemp$ = MID$(text$, (hscroll% + 1), rightmargin% - (leftmargin% - 1))
  1949.     PRINT texttemp$ + STRING$(rightmargin% - (leftmargin% - 1) - LEN(texttemp$), linecharacter%);
  1950.     LOCATE iyy%, ixx%
  1951.     RETURN '---------------------------------------------------------------------
  1952.  
  1953.     clearbuttons:
  1954.     iyy% = CSRLIN: ixx% = POS(0)
  1955.     FOR k% = 1 TO UBOUND(formbutton$)
  1956.         LOCATE formbuttony%(k%), ABS(formbuttonx%(k%)), 0
  1957.         COLOR 1, 7: PRINT formbutton$(k%);
  1958.         formbuttonx%(k%) = ABS(formbuttonx%(k%)) ' Remove button active (neg) designation.
  1959.     NEXT
  1960.     LOCATE iyy%, ixx%
  1961.     RETURN '---------------------------------------------------------------------
  1962.  
  1963.     displaybutton: ' Gosub parameters (i%)
  1964.     iyy% = CSRLIN: ixx% = POS(0)
  1965.     GOSUB clearbuttons ' Clear all buttons of highlighting first...
  1966.     IF i% < 0 THEN COLOR 0, 3 ELSE COLOR 1, 7
  1967.     IF tabx% THEN COLOR 0, 3
  1968.     IF i% <> 0 THEN
  1969.         LOCATE formbuttony%(ABS(i%)), ABS(formbuttonx%(ABS(i%))), 0
  1970.         PRINT formbutton$(ABS(i%));
  1971.         formbuttonx%(ABS(i%)) = -ABS(formbuttonx%(ABS(i%)))
  1972.     END IF
  1973.     LOCATE iyy%, ixx%
  1974.     RETURN '---------------------------------------------------------------------
  1975.  
  1976.     fileselected:
  1977.     IF noe THEN
  1978.         IF hlf% THEN j% = -999: GOSUB highlightfile
  1979.  
  1980.         text$ = xfull$(row + scr)
  1981.  
  1982.         IF LEFT$(text$, 2) = ".." OR LEFT$(text$, 1) = "[" THEN
  1983.             ' Ready to change diretories.
  1984.             IF LEFT$(text$, 2) = ".." THEN
  1985.                 CHDIR ".."
  1986.             ELSE
  1987.                 CHDIR MID$(text$, 2, LEN(text$) - 2)
  1988.             END IF
  1989.             action$ = "change dir"
  1990.         ELSE
  1991.             ' Text input line.
  1992.             COLOR 7, 0
  1993.             LOCATE w1% + w3% - 4 - 3, w2% + 15: PRINT SPACE$(w4% - 18); ' Blank it.
  1994.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1: PRINT MID$(text$, 1, w4% - 18); ' Display it.
  1995.             hlf% = 0
  1996.         END IF
  1997.     ELSE ' No files found in DIR to select.
  1998.         BEEP
  1999.     END IF
  2000.     RETURN '---------------------------------------------------------------------
  2001.  
  2002.     popfiletypes:
  2003.     LOCATE w1% + w3% - 4 - 3, w2% + 15, 0
  2004.     GOSUB wash
  2005.     oldsmode2 = SMODE
  2006.     SMODE = 3: PCOPY oldsmode2, SMODE: SCREEN 0, 0, SMODE, SMODE
  2007.     COLOR 8, 0: LOCATE w1% + 16, w2% + 15 - 1: PRINT CHR$(179);
  2008.     COLOR 1, 3: PRINT SPACE$(w4% - 21);
  2009.     LOCATE w1% + 16, w2% + 15
  2010.     COLOR 1, 3: PRINT doctype$(1);
  2011.     COLOR 8, 0: LOCATE w1% + 16, w2% + w4% - 4: PRINT CHR$(179);
  2012.     LOCATE w1% + 17, w2% + 14
  2013.     COLOR 8, 0: PRINT CHR$(179);
  2014.     COLOR 7, 0: PRINT SPACE$(w4% - 18);
  2015.     LOCATE w1% + 17, w2% + 15: PRINT doctype$(2);
  2016.     COLOR 8, 0: LOCATE , w2% + w4% - 4: PRINT CHR$(179);
  2017.     COLOR 8, 0: LOCATE w1% + 18, w2% + 14: PRINT CHR$(192); STRING$(w4% - 19, 196); CHR$(217);
  2018.     doctypey%(1) = w1% + 16: doctypex%(1) = w2% + 15
  2019.     doctypey%(2) = w1% + 17: doctypex%(2) = w2% + 15
  2020.     LOCATE w1% + 16, w2% + 15 ' Text input line.
  2021.     RETURN '---------------------------------------------------------------------
  2022.  
  2023.     doctype_selected:
  2024.     SELECT CASE i%
  2025.         CASE 1
  2026.             COLOR 7, 0: LOCATE w1% + 16, w2% + 15: PRINT SPACE$(w4% - 19); ' Leaves arrow down space.
  2027.             LOCATE w1% + 16, w2% + 15: PRINT doctype$(1);
  2028.  
  2029.             IF doctype$ <> doctype$(1) THEN
  2030.                 '''doctype$ = doctype$(1): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  2031.             END IF
  2032.  
  2033.             doctype$ = doctype$(1)
  2034.             IF doctype% = 2 THEN SWAP doctype$(1), doctype$(2)
  2035.             doctype% = 1
  2036.  
  2037.             LOCATE w1% + 16, w2 + w4% + 4 ' .txt or *.* all files arrow down button location.
  2038.             formbuttony%(1) = CSRLIN: formbuttonx%(1) = POS(0): formbutton$(1) = CHR$(25)
  2039.  
  2040.             i% = 1: GOSUB displaybutton
  2041.  
  2042.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' File name input field.
  2043.             COLOR textfg%, textbk%
  2044.         CASE 2
  2045.             COLOR 7, 0: LOCATE w1% + 16, w2% + 15: PRINT SPACE$(w4% - 19); ' Leaves arrow down space.
  2046.             LOCATE w1% + 16, w2% + 15: PRINT doctype$(2);
  2047.  
  2048.             IF doctype$ <> doctype$(2) THEN
  2049.                 '''doctype$ = doctype$(2): CALL displayfiles(doctype$, x$(), xfull$(), scrb, noe, row, scr)
  2050.             END IF
  2051.  
  2052.             doctype$ = doctype$(2)
  2053.             IF doctype% = 1 THEN SWAP doctype$(1), doctype$(2)
  2054.             doctype% = 2
  2055.  
  2056.             LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' File name input field.
  2057.             COLOR textfg%, textbk%
  2058.     END SELECT
  2059.  
  2060.     RETURN '---------------------------------------------------------------------
  2061.  
  2062.     close_doctype_dropdown:
  2063.     ' Note - Do not use i% in this routine. It would change a perviouly set value i one of the routines that calls this one.
  2064.     SMODE = oldsmode2: SCREEN 0, 0, SMODE, SMODE: oldsmode2 = 0
  2065.     LOCATE , , 0
  2066.     LOCATE w1% + 16, w2% + w4% - 4
  2067.     IF tabx% = 3 THEN COLOR 0, 3 ELSE COLOR 1, 7
  2068.     IF my% = CSRLIN AND mx% = POS(0) THEN COLOR 0, 3: formbuttonx%(1) = -formbuttonx%(1)
  2069.     PRINT formbutton$(1);
  2070.     LOCATE w1% + w3% - 4 - 3, w2% + 15, 1 ' File name input field.
  2071.     COLOR textfg%, textbk%
  2072.     REDIM doctypex%(UBOUND(doctype$)), doctypey%(UBOUND(doctype$))
  2073.     RETURN '---------------------------------------------------------------------
  2074.  
  2075.  
  2076. SUB find_string
  2077.     REDIM x$(20)
  2078.     margin.t = 5
  2079.     margin.l = 5
  2080.     dwidth = 68
  2081.     page.h = 6
  2082.     row = 1
  2083.     noe = 13
  2084.  
  2085.     x$(1) = "We the People of the United States, in Order to form a more perfect " + CHR$(10)
  2086.     x$(2) = "Union, establish Justice, insure domestic Tranquility, provide for " + CHR$(10)
  2087.     x$(3) = "the common defence, promote the general Welfare, and secure the " + CHR$(10)
  2088.     x$(4) = "Blessings of Liberty to ourselves and our Posterity, do ordain and " + CHR$(10)
  2089.     x$(5) = "establish this Constitution for the United States of America." + CHR$(10)
  2090.     x$(6) = "" + CHR$(255) + CHR$(10)
  2091.     x$(7) = "Article I" + CHR$(10)
  2092.     x$(8) = "" + CHR$(255) + CHR$(10)
  2093.     x$(9) = "Section 1: Congress" + CHR$(10)
  2094.     x$(10) = "" + CHR$(255) + CHR$(10)
  2095.     x$(11) = "All legislative Powers herein granted shall be vested in a Congress " + CHR$(10)
  2096.     x$(12) = "of the United States, which shall consist of a Senate and House of " + CHR$(10)
  2097.     x$(13) = "Representatives." + CHR$(10)
  2098.  
  2099.     GOSUB displaydoc
  2100.  
  2101.     DO
  2102.         DO
  2103.             _LIMIT 30
  2104.             b$ = INKEY$
  2105.             IF LEN(b$) THEN
  2106.                 SELECT CASE b$
  2107.                     CASE CHR$(27)
  2108.                         SYSTEM
  2109.                     CASE CHR$(0) + "H"
  2110.                         IF scr THEN scr = scr - 1: row = 1: GOSUB displaydoc: GOSUB finder
  2111.                     CASE CHR$(0) + "P"
  2112.                         IF scr + page.h < noe THEN row = page.h: scr = scr + 1: GOSUB displaydoc: GOSUB finder
  2113.                 END SELECT
  2114.             END IF
  2115.         LOOP
  2116.     LOOP
  2117.  
  2118.     displaydoc:
  2119.     COLOR 0, 7
  2120.     FOR i% = 1 TO page.h
  2121.         a1$ = SPACE$(dwidth)
  2122.         MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  2123.         LOCATE margin.t + i%, margin.l + 1
  2124.         PRINT a1$
  2125.     NEXT
  2126.     RETURN
  2127.  
  2128.     finder:
  2129.     FOR i% = 1 TO page.h
  2130.         a1$ = SPACE$(dwidth)
  2131.         MID$(a1$, 1) = MID$(x$(i% + scr), 1, INSTR(x$(i% + scr), CHR$(10)) - 1)
  2132.  
  2133.         IF INSTR(LCASE$(a1$), find$) THEN
  2134.             COLOR 14, 4: seed% = 0
  2135.             DO UNTIL INSTR(seed%, LCASE$(a1$), find$) = 0
  2136.                 seed% = INSTR(seed%, LCASE$(a1$), find$)
  2137.                 LOCATE margin.t + i%, margin.l + seed%
  2138.                 PRINT MID$(a1$, INSTR(seed%, LCASE$(a1$), find$), LEN(find$));
  2139.                 seed% = seed% + LEN(find$)
  2140.             LOOP
  2141.         END IF
  2142.     NEXT
  2143.     COLOR 0, 7
  2144.     RETURN
  2145.  
  2146. SUB windowscreen (ENL%)
  2147.     IF displayfullscreen% = -1 THEN EXIT SUB
  2148.     WINXX1% = CSRLIN: WINYY1% = POS(1)
  2149.     winmode$ = "2"
  2150.  
  2151.     IF ENL% <> 0 THEN
  2152.         full = _FULLSCREEN
  2153.         IF full = 0 THEN
  2154.             SELECT CASE ENL%
  2155.                 CASE -1: IF SCRNSIZE% > 0 THEN ELSE EXIT SUB
  2156.                 CASE 1: IF SCRNSIZE% < 14 THEN ELSE EXIT SUB
  2157.             END SELECT
  2158.         ELSE
  2159.             EXIT SUB
  2160.         END IF
  2161.     END IF
  2162.  
  2163.     SCRNSIZE% = SCRNSIZE% + ENL%
  2164.  
  2165.     SELECT CASE winmode$
  2166.         CASE "1"
  2167.             full = _FULLSCREEN
  2168.             IF full <> 0 THEN _FULLSCREEN _OFF
  2169.             GOSUB ChangeFont
  2170.         CASE "2"
  2171.             full = _FULLSCREEN
  2172.             IF full <> 0 THEN _FULLSCREEN _OFF
  2173.             style$ = "MONOSPACE"
  2174.             fontsize% = SCRNSIZE% + 13
  2175.             IF fontsize% < 14 THEN winmode$ = ""
  2176.             IF fontsize% < 18 THEN style$ = style$ + ", BOLD"
  2177.             fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
  2178.             GOSUB ChangeFont
  2179.         CASE "3"
  2180.             GOSUB ChangeFont
  2181.             _FULLSCREEN _SQUAREPIXELS
  2182.             full = _FULLSCREEN
  2183.             IF full = 0 THEN GOSUB nofull
  2184.         CASE "4"
  2185.             GOSUB ChangeFont
  2186.             _FULLSCREEN _STRETCH
  2187.             full = _FULLSCREEN
  2188.             IF full = 0 THEN GOSUB nofull
  2189.     END SELECT
  2190.  
  2191.     LOCATE WINXX1%, WINYY1%
  2192.     EXIT SUB
  2193.  
  2194.     nofull:
  2195.     RETURN
  2196.  
  2197.     ChangeFont:
  2198.     IF winmode$ <> "2" THEN
  2199.         _FONT 16 ' Inbuilt 8x16 default font.
  2200.         currentf& = _FONT
  2201.     ELSE
  2202.         currentf& = _LOADFONT(fontpath$, fontsize%, style$)
  2203.         _FONT currentf&
  2204.     END IF
  2205.  
  2206.     IF currentf& <> f& AND f& <> defaultf& THEN _FREEFONT f&
  2207.     f& = currentf&
  2208.     RETURN
  2209.  
  2210.  

Edit: Woohoo, it did fit back into the WP, without any immediate conflicts found. Fingers crossed I can get the two new features displayed and activated just as easily.

Pete
« Last Edit: February 01, 2021, 04:13:29 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/