'=========================================================================== ' Subject: EDITOR WITH WORDWRAP Date: 01-18-99 (00:04) ' Author: Johannes Hansen Code: QB, QBasic, PDS ' Origin: 7yjohannes@horsensamts-gym.dk Packet: TEXT.ABC '=========================================================================== '------------------------------------------------------------------ ' Product: Editor with WordWrap (Freeware) ' Author: Johannes Hansen ' E-mail: 7yjohannes@horsensamts-gym.dk '------------------------------------------------------------------ ' The WordWrap procedure wraps the text$ so it fits the specified ' widht. The procedure can easiely be changed to print on a printer ' instead of the screen. ' I have already recieved comments on x% and y%, I admit they might ' be unlogical. x is the vertical position, y is the horizontal ' position. Please change the code to fit your needs. DECLARE SUB WordWrap (text$, x%, y%, bredde%, maxlin%, udtype$) DECLARE FUNCTION rette$ (x%, y%, strlenght%, maxlenght%, default$, ekstramark%) DIM SHARED maxlines% DIM SHARED maxwidht% maxlines% = 60 maxwidht% = 60 DIM SHARED linlen(0 TO maxlines% - 1) AS INTEGER CLS text$ = "Jeg gik mig over s› og land der m›dte jeg en gammel mand han sagde s† og spurgte s†" test$ = rette$(3, 3, 200, maxwidht%, text$, 0) DEFINT A-Z FUNCTION rette$ (x, y, strlenght, maxlenght, default$, ekstramark) markpos% = 1 + ekstramark linie = 0 insert = 0 text$ = default$ GOSUB vis DO DO inp$ = INKEY$ LOOP WHILE inp$ = "" SELECT CASE inp$ CASE CHR$(8) 'Backspace IF markpos% > 1 THEN text$ = MID$(text$, 1, markpos% - 2) + MID$(text$, markpos%) + " " markpos% = markpos% - 1 END IF GOSUB vis CASE CHR$(0) + CHR$(82) 'Insert IF insert = 0 THEN insert = 1 LOCATE , , , 1, 11 ELSE insert = 0 LOCATE , , , 13, 14 END IF CASE CHR$(0) + CHR$(83) 'Delete IF markpos% < strlenght THEN text$ = MID$(text$, 1, markpos% - 1) + MID$(text$, markpos% + 1) + " " END IF GOSUB vis CASE CHR$(0) + CHR$(71) 'Home markpos% = markpos% - (POS(0) - y) GOSUB position CASE CHR$(0) + CHR$(79) 'End markpos% = 0 FOR i = 0 TO linie markpos% = markpos% + linlen(i) NEXT i IF markpos% > strlenght THEN markpos% = strlenght GOSUB position CASE CHR$(0) + CHR$(75) 'Left <- IF markpos% > 1 THEN markpos% = markpos% - 1 GOSUB position END IF CASE CHR$(0) + CHR$(115) 'Ctrl + Left tmp$ = "" FOR i = markpos% TO 1 STEP -1 tmp$ = tmp$ + MID$(text$, i, 1) NEXT i markpos% = markpos% - INSTR(tmp$, " ") GOSUB position CASE CHR$(0) + CHR$(77) 'Right -> IF markpos% < strlenght THEN markpos% = markpos% + 1 GOSUB position END IF CASE CHR$(0) + CHR$(116) 'Ctrl + Right testpos% = INSTR(markpos%, text$, " ") + 1 SELECT CASE MID$(text$, testpos%, 1) CASE CHR$(33) TO CHR$(253) markpos% = testpos% GOSUB position END SELECT CASE CHR$(0) + CHR$(72) 'Up Œ IF NOT linie = 0 THEN IF POS(0) - y >= linlen(linie - 1) THEN markpos% = 0 FOR i = 0 TO linie - 1 markpos% = markpos% + linlen(i) NEXT i ELSE markpos% = markpos% - linlen(linie - 1) END IF GOSUB position END IF CASE CHR$(0) + CHR$(80) 'Down IF NOT markpos% + linlen(linie) > strlenght THEN IF POS(0) - y >= linlen(linie + 1) THEN markpos% = 0 FOR i = 0 TO linie + 1 markpos% = markpos% + linlen(i) NEXT i ELSE markpos% = markpos% + linlen(linie) END IF GOSUB position END IF CASE CHR$(27) 'Escape LOCATE 25, 3, , 13, 14: PRINT " "; text$ = default$ rette$ = default$ GOSUB vis EXIT FUNCTION CASE CHR$(13) 'enter LOCATE 25, 3, , 13, 14: PRINT " "; rette$ = text$ EXIT FUNCTION CASE CHR$(32) TO CHR$(253) 'En masse tegn text$ = MID$(text$, 1, markpos% - 1) + inp$ + MID$(text$, markpos% + insert) IF markpos% < strlenght THEN markpos% = markpos% + 1 GOSUB vis END SELECT LOOP vis: text$ = MID$(text$, 1, strlenght) IF LEN(default$) = beskrivelse THEN LOCATE 13, 16: PRINT SPACE$(32) END IF WordWrap text$, x, y, maxlenght, maxlines%, "screen" GOSUB position RETURN position: posx = 0: posy = markpos% FOR linie = 0 TO 4 posx = posx + linlen(linie) IF posx + 1 > markpos% THEN LOCATE x + linie, y + posy - 1, 1 EXIT FOR END IF posy = posy - linlen(linie) NEXT linie RETURN END FUNCTION SUB WordWrap (text$, x, y, bredde, maxlin, udtype$) omgang = 1 xpos = x ypos = y wrap$ = text$ IF LEN(wrap$) > bredde THEN FOR omgang = 1 TO maxlin IF LEN(wrap$) = 0 THEN EXIT FOR IF LEN(wrap$) > bredde THEN IF MID$(wrap$, bredde + 1, 1) = " " THEN ud$ = LEFT$(wrap$, bredde) GOSUB ud wrap$ = MID$(wrap$, bredde + 2) ELSE invert$ = "" FOR i = LEN(LEFT$(wrap$, bredde)) TO 1 STEP -1 invert$ = invert$ + MID$(wrap$, i, 1) NEXT i skift = INSTR(invert$, " ") ud$ = LEFT$(wrap$, bredde - skift) GOSUB ud wrap$ = MID$(wrap$, bredde + 2 - skift) END IF ELSE ud$ = wrap$ GOSUB ud EXIT FOR END IF NEXT omgang ELSE ud$ = wrap$ GOSUB ud END IF EXIT SUB ud: SELECT CASE udtype$ CASE "screen", "" LOCATE xpos, ypos, 0 PRINT ud$ + SPACE$(bredde - LEN(ud$)); xpos = xpos + 1 linlen(omgang - 1) = LEN(ud$) + 1 CASE "printer" END SELECT RETURN END SUB