CEdit: optimization; small font (6x9) support

git-svn-id: svn://kolibrios.org@9668 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-24 22:03:13 +00:00
parent 756a832e4e
commit 254d30c075
11 changed files with 374 additions and 157 deletions

Binary file not shown.

View File

@ -28,14 +28,13 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar; RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST CONST
HEADER = "CEdit (20-jan-2022)"; HEADER = "CEdit (25-jan-2022)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
fontWidth = K.fontWidth; fontWidth = K.fontWidth;
fontHeight = K.fontHeight; fontHeight = K.fontHeight;
scrollWidth = 22;
btnClose = 1; btnClose = 1;
@ -67,8 +66,6 @@ CONST
toolbarTop = Menu.MainMenuHeight + 3; toolbarTop = Menu.MainMenuHeight + 3;
TOP = toolbarTop + Toolbar.BtnSize + 10 + Tabs.tabHeight; TOP = toolbarTop + Toolbar.BtnSize + 10 + Tabs.tabHeight;
RIGHT = scrollWidth - 2;
BOTTOM = scrollWidth + 18;
minWinWidth = 635; minWinHeight = 550; minWinWidth = 635; minWinHeight = 550;
@ -111,7 +108,9 @@ CONST
menuExit = 17; menuExit = 17;
menuNumbers = 20; menuNumbers = 20;
menuFontSize = 21; menuFontSmall = 21;
menuFontMedium = 22;
menuFontBig = 23;
menuColors = 1000; menuColors = 1000;
menuMaxColors = menuColors + Ini.MAX_SECTIONS - 1; menuMaxColors = menuColors + Ini.MAX_SECTIONS - 1;
@ -176,7 +175,7 @@ CONST
VAR VAR
header: RW.tFileName; header: RW.tFileName;
canvas: G.tCanvas; canvas: G.tCanvas;
font, font1, font2: G.tFont; font: G.tFont;
tabs: Tabs.tTabs; tabs: Tabs.tTabs;
text: T.tText; text: T.tText;
@ -184,14 +183,14 @@ VAR
textsCount, curText: INTEGER; textsCount, curText: INTEGER;
winWidth, winHeight: INTEGER; winWidth, winHeight: INTEGER;
SkinHeight: INTEGER; SkinHeight, scrollWidth: INTEGER;
AppPath, runScript, buildScript, debugScript, CurFolder: RW.tFileName; AppPath, runScript, buildScript, debugScript, CurFolder: RW.tFileName;
OD: OpenDlg.Dialog; OD: OpenDlg.Dialog;
confirm, notFound, menuFindClicked, search, searchOpened: BOOLEAN; confirm, notFound, menuFindClicked, search, searchOpened: BOOLEAN;
switch, closing: BOOLEAN; switch, closing: BOOLEAN;
leftButton: BOOLEAN; leftButton: BOOLEAN;
LEFT: INTEGER; LEFT, RIGHT, BOTTOM: INTEGER;
FindEdit, ReplaceEdit, GotoEdit: EB.tEditBox; FindEdit, ReplaceEdit, GotoEdit: EB.tEditBox;
hScroll, vScroll: Scroll.tScroll; hScroll, vScroll: Scroll.tScroll;
@ -370,6 +369,14 @@ BEGIN
END DrawScroll; END DrawScroll;
PROCEDURE drawText;
BEGIN
G.SetColor(canvas, K.colors.line);
G.VLine(canvas, 0, 0, canvas.height - 1);
G.DrawCanvas(canvas, LEFT, TOP)
END drawText;
PROCEDURE repaint; PROCEDURE repaint;
VAR VAR
width, height, scrollX, scrollY: INTEGER; width, height, scrollX, scrollY: INTEGER;
@ -403,10 +410,7 @@ BEGIN
CheckBox.draw(CS); CheckBox.draw(CS);
CheckBox.draw(WH); CheckBox.draw(WH);
END; END;
drawText;
G.SetColor(canvas, K.colors.line);
G.VLine(canvas, 0, 0, canvas.height - 1);
G.DrawCanvas(canvas, LEFT, TOP);
NotFound; NotFound;
Replaced; Replaced;
Toolbar.enable(toolbar, btnSave, text.modified); Toolbar.enable(toolbar, btnSave, text.modified);
@ -435,6 +439,12 @@ BEGIN
K.SetWinSize(winWidth, winHeight); K.SetWinSize(winWidth, winHeight);
K.WinSize(winWidth, winHeight); K.WinSize(winWidth, winHeight);
K.ClientSize(cliWidth, cliHeight); K.ClientSize(cliWidth, cliHeight);
IF font # G.font2 THEN
SB.SetFont(font)
ELSE
SB.SetFont(G.font1)
END;
BOTTOM := SB.height() + scrollWidth - 1;
G.destroy(canvas); G.destroy(canvas);
canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 2 + RIGHT_PADDING), cliHeight - (TOP + BOTTOM + 1)); canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 2 + RIGHT_PADDING), cliHeight - (TOP + BOTTOM + 1));
Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, cliWidth - (LEFT + RIGHT + 2 + RIGHT_PADDING), Tabs.tabHeight); Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, cliWidth - (LEFT + RIGHT + 2 + RIGHT_PADDING), Tabs.tabHeight);
@ -1041,7 +1051,9 @@ BEGIN
INC(x, menuEncodingX) INC(x, menuEncodingX)
ELSIF menu = menuView THEN ELSIF menu = menuView THEN
Menu.check(menu, menuNumbers, text.numbers); Menu.check(menu, menuNumbers, text.numbers);
Menu.check(menu, menuFontSize, font = font2); Menu.option(menu, menuFontSmall, font = G.font0);
Menu.option(menu, menuFontMedium, font = G.font1);
Menu.option(menu, menuFontBig, font = G.font2);
FOR i := 0 TO Ini.sections.count - 1 DO FOR i := 0 TO Ini.sections.count - 1 DO
Menu.option(menu, menuColors + i, Ini.curSectionNum = i) Menu.option(menu, menuColors + i, Ini.curSectionNum = i)
END; END;
@ -1165,12 +1177,14 @@ BEGIN
T.gotoLabel(text, FALSE) T.gotoLabel(text, FALSE)
|menuNumbers: |menuNumbers:
T.toggleNumbers(text) T.toggleNumbers(text)
|menuFontSize: |menuFontSmall:
IF font = font1 THEN font := G.font0;
font := font2 resize
ELSE |menuFontMedium:
font := font1 font := G.font1;
END; resize
|menuFontBig:
font := G.font2;
resize resize
|menuText: |menuText:
T.setLang(text, Languages.langText) T.setLang(text, Languages.langText)
@ -1359,7 +1373,10 @@ VAR
BEGIN BEGIN
menu := List.create(NIL); menu := List.create(NIL);
Menu.AddMenuItem(menu, menuNumbers, "line numbers"); Menu.AddMenuItem(menu, menuNumbers, "line numbers");
Menu.AddMenuItem(menu, menuFontSize, "x2"); Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuFontSmall, "small");
Menu.AddMenuItem(menu, menuFontMedium, "medium");
Menu.AddMenuItem(menu, menuFontBig, "big");
Menu.delimiter(menu); Menu.delimiter(menu);
colors := Ini.sections.first(Ini.tSection); colors := Ini.sections.first(Ini.tSection);
@ -1763,11 +1780,13 @@ BEGIN
goto goto
END; END;
IF ~middle THEN
IF exit THEN IF exit THEN
Close Close
ELSE ELSE
repaint repaint
END END
END
END BtnClick; END BtnClick;
@ -1921,6 +1940,7 @@ VAR
firstClickX, firstClickY, time, blink, i: INTEGER; firstClickX, firstClickY, time, blink, i: INTEGER;
key, scr: INTEGER; key, scr: INTEGER;
BEGIN BEGIN
font := G.font1;
header := ""; header := "";
K.GetSystemColors; K.GetSystemColors;
switch := FALSE; switch := FALSE;
@ -1932,20 +1952,21 @@ BEGIN
leftButton := FALSE; leftButton := FALSE;
resized := FALSE; resized := FALSE;
K.ScreenSize(winWidth, winHeight); K.ScreenSize(winWidth, winHeight);
scrollWidth := winHeight DIV 35;
winWidth := (winWidth*80) DIV 100 - (128 + 30); winWidth := (winWidth*80) DIV 100 - (128 + 30);
winHeight := winHeight - (128 + 30); winHeight := winHeight - (128 + 30);
winWidth := MAX(winWidth, minWinWidth); winWidth := MAX(winWidth, minWinWidth);
winHeight := MAX(winHeight, minWinHeight); winHeight := MAX(winHeight, minWinHeight);
cliWidth := winWidth; cliWidth := winWidth;
cliHeight := winHeight; cliHeight := winHeight;
LEFT := LEFT_PADDING; LEFT := LEFT_PADDING;
RIGHT := scrollWidth - 2;
BOTTOM := SB.height() + scrollWidth - 1;
SkinHeight := K.SkinHeight(); SkinHeight := K.SkinHeight();
canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 11 + RIGHT_PADDING), winHeight - (TOP + BOTTOM + 5) - SkinHeight); canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 11 + RIGHT_PADDING), winHeight - (TOP + BOTTOM + 5) - SkinHeight);
tabs := Tabs.create(); tabs := Tabs.create();
Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight); Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight);
font1 := G.CreateFont(1, "", {});
font2 := G.CreateFont(2, "", {});
font := font1;
G.SetFont(canvas, font); G.SetFont(canvas, font);
T.init(resetTimer); T.init(resetTimer);
T.setCanvas(canvas); T.setCanvas(canvas);
@ -2050,8 +2071,8 @@ BEGIN
CurrentTime := K.GetTickCount(); CurrentTime := K.GetTickCount();
IF (CurrentTime - CursorTime > blink) & (blink > 0) & timerEnabled & ~K.RolledUp() THEN IF (CurrentTime - CursorTime > blink) & (blink > 0) & timerEnabled & ~K.RolledUp() THEN
CursorTime := CurrentTime; CursorTime := CurrentTime;
T.toggleCursor; T.cursor(text);
repaint drawText
END; END;
CASE K.EventTimeout(10) OF CASE K.EventTimeout(10) OF

View File

@ -46,7 +46,7 @@ TYPE
tLog* = POINTER TO RECORD tLog* = POINTER TO RECORD
Log*, Pointers*: List.tList; Log*, Pointers*: List.tList;
guard: tGuard; guard, first: tGuard;
isLast: BOOLEAN isLast: BOOLEAN
END; END;
@ -73,16 +73,25 @@ BEGIN
END isLastGuard; END isLastGuard;
PROCEDURE isFirstGuard* (guard: tGuard): BOOLEAN; PROCEDURE getFirstGuard (): tGuard;
VAR VAR
item: List.tItem; item: List.tItem;
BEGIN BEGIN
ASSERT(guard # NIL);
item := CL.Log.first; item := CL.Log.first;
WHILE ~(item IS tGuard) DO WHILE ~(item IS tGuard) DO
item := item.next item := item.next
END END
RETURN guard = item RETURN item(tGuard)
END getFirstGuard;
PROCEDURE isFirstGuard* (guard: tGuard): BOOLEAN;
BEGIN
ASSERT(guard # NIL);
IF CL.first = NIL THEN
CL.first := getFirstGuard()
END
RETURN guard = CL.first
END isFirstGuard; END isFirstGuard;
@ -285,6 +294,7 @@ VAR
BEGIN BEGIN
NEW(newLog); NEW(newLog);
newLog.guard := NIL; newLog.guard := NIL;
newLog.first := NIL;
newLog.isLast := TRUE; newLog.isLast := TRUE;
newLog.Log := List.create(NIL); newLog.Log := List.create(NIL);
newLog.Pointers := List.create(NIL); newLog.Pointers := List.create(NIL);

View File

@ -82,7 +82,7 @@ BEGIN
res.mouse := FALSE; res.mouse := FALSE;
COPY(text, res.text); COPY(text, res.text);
res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1); res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
G.SetFont(res.canvas, G.CreateFont(1, "", {})); G.SetFont(res.canvas, G.font1);
chkbox := res chkbox := res
END create; END create;

View File

@ -19,7 +19,7 @@
MODULE Graph; MODULE Graph;
IMPORT SYSTEM, KOSAPI, Lines, Languages; IMPORT SYSTEM, KOSAPI, Lines, Languages, E := Encodings;
CONST CONST
@ -39,6 +39,7 @@ TYPE
height*: INTEGER; height*: INTEGER;
width*: INTEGER; width*: INTEGER;
size: INTEGER; size: INTEGER;
flags: INTEGER;
name*: ARRAY 256 OF WCHAR name*: ARRAY 256 OF WCHAR
END; END;
@ -50,6 +51,10 @@ TYPE
mode: INTEGER mode: INTEGER
END; END;
VAR
font0*, font1*, font2*: tFont;
PROCEDURE getRGB* (color: INTEGER; VAR r, g, b: BYTE); PROCEDURE getRGB* (color: INTEGER; VAR r, g, b: BYTE);
BEGIN BEGIN
@ -83,15 +88,26 @@ BEGIN
END SetBkColor; END SetBkColor;
PROCEDURE CreateFont* (height: INTEGER; name: ARRAY OF WCHAR; attr: SET): tFont; PROCEDURE CreateFont (size: INTEGER; name: ARRAY OF WCHAR; attr: SET): tFont;
VAR VAR
font: tFont; font: tFont;
BEGIN BEGIN
ASSERT(size IN {0, 1, 2});
NEW(font); NEW(font);
font.size := MAX(MIN(height, 8), 1); font.size := size;
font.width := font.size*8; IF size = 0 THEN
font.height := font.size*16; font.width := 6;
DEC(font.size); font.height := 9;
font.flags := 08000000H
ELSE
font.width := size*8;
font.height := size*16;
IF size = 1 THEN
font.flags := 28000000H
ELSIF size = 2 THEN
font.flags := 29000000H
END
END;
font.name := name font.name := name
RETURN font RETURN font
END CreateFont; END CreateFont;
@ -256,24 +272,25 @@ PROCEDURE TextOut* (canvas: tCanvas; x, y: INTEGER; text: INTEGER; n: INTEGER; d
CONST CONST
WCHAR_SIZE = 2; WCHAR_SIZE = 2;
VAR VAR
color, i, font: INTEGER; color, i, ch: INTEGER;
font: tFont;
c: WCHAR; c: WCHAR;
BEGIN BEGIN
IF (0 <= y) & (y <= canvas.height - canvas.font.height - 1) THEN font := canvas.font;
IF (0 <= y) & (y <= canvas.height - font.height - 1) THEN
IF x < 0 THEN IF x < 0 THEN
i := -(x DIV canvas.font.width); i := -(x DIV font.width);
INC(x, i*canvas.font.width); INC(x, i*font.width);
DEC(n, i) DEC(n, i)
ELSE ELSE
i := 0 i := 0
END; END;
IF n > 0 THEN IF n > 0 THEN
n := MAX(MIN(n, (canvas.width - x) DIV canvas.font.width), 0); n := MAX(MIN(n, (canvas.width - x) DIV font.width), 0);
color := canvas.color; color := canvas.color;
canvas.color := canvas.backColor; canvas.color := canvas.backColor;
FillRect(canvas, x, y, x + n*canvas.font.width, y + canvas.font.height); FillRect(canvas, x, y, x + n*font.width, y + font.height);
canvas.color := color; canvas.color := color;
font := LSL(28H + canvas.font.size, 24);
WHILE n > 0 DO WHILE n > 0 DO
SYSTEM.GET(text + i*WCHAR_SIZE, c); SYSTEM.GET(text + i*WCHAR_SIZE, c);
IF ~Lines.isSpace(c) THEN IF ~Lines.isSpace(c) THEN
@ -285,9 +302,17 @@ BEGIN
IF c = Lines.NUL THEN IF c = Lines.NUL THEN
c := 0X c := 0X
END; END;
KOSAPI.sysfunc6(4, x*65536 + y, font + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8) IF font = font0 THEN
ch := E.UNI[ORD(c), E.CP866];
IF ch = E.UNDEF THEN
c := "?"
ELSE
c := WCHR(ch)
END
END; END;
INC(x, canvas.font.width); KOSAPI.sysfunc6(4, x*65536 + y, font.flags + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8)
END;
INC(x, font.width);
INC(i); INC(i);
DEC(n) DEC(n)
END END
@ -322,10 +347,14 @@ END CreateCanvas;
PROCEDURE destroy* (VAR canvas: tCanvas); PROCEDURE destroy* (VAR canvas: tCanvas);
BEGIN BEGIN
IF canvas # NIL THEN IF canvas # NIL THEN
canvas.bitmap := KOSAPI.free(canvas.bitmap); canvas.bitmap := KOSAPI.free(canvas.bitmap - 8);
DISPOSE(canvas) DISPOSE(canvas)
END END
END destroy; END destroy;
BEGIN
font0 := CreateFont(0, "", {});
font1 := CreateFont(1, "", {});
font2 := CreateFont(2, "", {});
END Graph. END Graph.

View File

@ -56,7 +56,7 @@ BEGIN
END GetInf; END GetInf;
PROCEDURE GetImg* (ptr, size: INTEGER): INTEGER; PROCEDURE GetImg (ptr, size: INTEGER): INTEGER;
VAR VAR
image_data, dst, x, type: INTEGER; image_data, dst, x, type: INTEGER;
BEGIN BEGIN
@ -133,7 +133,7 @@ BEGIN
(*ELSE (*ELSE
copy(source, icons); copy(source, icons);
copy(source, grayIcons)*) copy(source, grayIcons)*)
END; END
END get; END get;

View File

@ -45,6 +45,12 @@ TYPE
PTypedPtr = PROCEDURE (p: List.tItem); PTypedPtr = PROCEDURE (p: List.tItem);
PUntypedPtr = PROCEDURE (p: INTEGER); PUntypedPtr = PROCEDURE (p: INTEGER);
tVector* = POINTER TO RECORD
size, data: INTEGER
END;
tVectorItem = tLine;
VAR VAR
@ -58,6 +64,57 @@ VAR
tabs*: BOOLEAN; tabs*: BOOLEAN;
PROCEDURE createVector* (size: INTEGER): tVector;
VAR
res: tVector;
BEGIN
IF size > 0 THEN
NEW(res);
res.size := size;
IF size < 4096 THEN
size := 4096
END;
res.data := API._NEW(size*SYSTEM.SIZE(tVectorItem));
IF res.data = 0 THEN
DISPOSE(res)
END
ELSE
res := NIL
END
RETURN res
END createVector;
PROCEDURE destroyVector* (VAR vector: tVector);
BEGIN
IF vector # NIL THEN
IF vector.data # 0 THEN
vector.data := API._DISPOSE(vector.data)
END;
DISPOSE(vector)
END
END destroyVector;
PROCEDURE setVectorItem* (vector: tVector; idx: INTEGER; item: tVectorItem);
BEGIN
ASSERT(vector # NIL);
ASSERT((0 <= idx) & (idx < vector.size));
SYSTEM.PUT(vector.data + idx*SYSTEM.SIZE(tVectorItem), item)
END setVectorItem;
PROCEDURE getVectorItem* (vector: tVector; idx: INTEGER): tVectorItem;
VAR
res: tVectorItem;
BEGIN
ASSERT(vector # NIL);
ASSERT((0 <= idx) & (idx < vector.size));
SYSTEM.GET(vector.data + idx*SYSTEM.SIZE(tVectorItem), res)
RETURN res
END getVectorItem;
PROCEDURE movInt (VAR v: INTEGER; x: INTEGER); PROCEDURE movInt (VAR v: INTEGER; x: INTEGER);
BEGIN BEGIN
_movInt(v, x) _movInt(v, x)

View File

@ -22,7 +22,7 @@ MODULE List;
TYPE TYPE
tItem* = POINTER TO RECORD tItem* = POINTER TO RECORD
prev*, next*: tItem next*, prev*: tItem
END; END;
tList* = POINTER TO RECORD tList* = POINTER TO RECORD
@ -56,15 +56,24 @@ PROCEDURE getItem* (list: tList; idx: INTEGER): tItem;
VAR VAR
item: tItem; item: tItem;
BEGIN BEGIN
IF idx < 0 THEN IF (idx < 0) OR (idx >= list.count) THEN
item := NIL item := NIL
ELSE
IF list.count DIV 2 < idx THEN
item := list.last;
idx := list.count - idx - 1;
WHILE idx > 0 DO
item := item.prev;
DEC(idx)
END
ELSE ELSE
item := list.first; item := list.first;
WHILE (idx > 0) & (item # NIL) DO WHILE idx > 0 DO
item := item.next; item := item.next;
DEC(idx) DEC(idx)
END END
END END
END
RETURN item RETURN item
END getItem; END getItem;

View File

@ -641,7 +641,7 @@ BEGIN
END; END;
m.width := maxLength*fontWidth + LEFT + RIGHT; m.width := maxLength*fontWidth + LEFT + RIGHT;
m.height := items.count*fontHeight - 2; m.height := items.count*fontHeight - 2;
m.font := G.CreateFont(1, "", {}); m.font := G.font1;
m.canvas := G.CreateCanvas(m.width + 1, m.height + 1); m.canvas := G.CreateCanvas(m.width + 1, m.height + 1);
G.SetFont(m.canvas, m.font); G.SetFont(m.canvas, m.font);
RETURN m RETURN m

View File

@ -76,12 +76,17 @@ BEGIN
END setEnc; END setEnc;
PROCEDURE height* (): INTEGER;
RETURN font.height + 3
END height;
PROCEDURE setWidth* (width: INTEGER); PROCEDURE setWidth* (width: INTEGER);
BEGIN BEGIN
ASSERT(width > 0); ASSERT(width > 0);
IF (SB.canvas = NIL) OR (SB.canvas.width # width) THEN IF (SB.canvas = NIL) OR (SB.canvas.width # width) OR (SB.canvas.height # height()) THEN
G.destroy(SB.canvas); G.destroy(SB.canvas);
SB.canvas := G.CreateCanvas(width, 19); SB.canvas := G.CreateCanvas(width, height());
G.SetFont(SB.canvas, font) G.SetFont(SB.canvas, font)
END END
END setWidth; END setWidth;
@ -100,13 +105,22 @@ BEGIN
G.SetTextColor(SB.canvas, K.colors.work_text); G.SetTextColor(SB.canvas, K.colors.work_text);
G.clear(SB.canvas); G.clear(SB.canvas);
TextOut(1, SB.pos); TextOut(1, SB.pos);
TextOut(16*K.fontWidth, SB.sel); TextOut(16*font.width, SB.sel);
TextOut(SB.canvas.width - LENGTH(SB.enc)*K.fontWidth - 1, SB.enc); TextOut(SB.canvas.width - LENGTH(SB.enc)*font.width - 1, SB.enc);
G.DrawCanvas(SB.canvas, left, top) G.DrawCanvas(SB.canvas, left, top)
END draw; END draw;
PROCEDURE SetFont* (_font: G.tFont);
BEGIN
font := _font;
IF SB.canvas # NIL THEN
setWidth(SB.canvas.width)
END
END SetFont;
BEGIN BEGIN
SB.canvas := NIL; SB.canvas := NIL;
font := G.CreateFont(1, "", {}) font := G.font1
END StatusBar. END StatusBar.

View File

@ -65,7 +65,8 @@ TYPE
cursor, select, select2: pPoint; cursor, select, select2: pPoint;
scroll: tPoint; scroll: tPoint;
CurX: INTEGER; CurX: INTEGER;
modified*: BOOLEAN; smallChange: INTEGER;
modified*, smallMove: BOOLEAN;
edition*: tGuard; edition*: tGuard;
comments, numbers*, guard, comments, numbers*, guard,
search, cs, whole: BOOLEAN; search, cs, whole: BOOLEAN;
@ -76,6 +77,7 @@ TYPE
foundList: List.tList; foundList: List.tList;
foundSel: INTEGER; foundSel: INTEGER;
searchText: tString; searchText: tString;
LinesVector: Lines.tVector;
chLog*: ChangeLog.tLog; chLog*: ChangeLog.tLog;
maxLength*: INTEGER; maxLength*: INTEGER;
fileName*: RW.tFileName fileName*: RW.tFileName
@ -155,12 +157,6 @@ BEGIN
END toggleNumbers; END toggleNumbers;
PROCEDURE toggleCursor*;
BEGIN
drawCursor := ~drawCursor
END toggleCursor;
PROCEDURE showCursor*; PROCEDURE showCursor*;
BEGIN BEGIN
drawCursor := TRUE drawCursor := TRUE
@ -223,24 +219,62 @@ BEGIN
END ProcessComments; END ProcessComments;
PROCEDURE getLine2 (text: tText; n: INTEGER): tLine;
VAR
item: tLine;
BEGIN
IF (0 <= n) & (n < text.count) THEN
item := Lines.getVectorItem(text.LinesVector, n)
ELSE
item := NIL
END
RETURN item
END getLine2;
PROCEDURE Comments (text: tText); PROCEDURE Comments (text: tText);
VAR VAR
line: tLine; line: tLine;
i: INTEGER; i, k, cout: INTEGER;
BEGIN BEGIN
IF text.smallChange = 1 THEN
line := getLine2(text, text.cursor.Y);
IF line.prev # NIL THEN
line.cin := line.prev(tLine).cout
ELSE
line.cin := 0
END;
cout := line.cout;
line.cout := line.cin;
i := 0;
ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
IF line.cout # cout THEN
text.smallChange := 0;
Comments(text)
END
ELSE
Lines.destroyVector(text.LinesVector);
text.LinesVector := Lines.createVector(text.count);
k := 0;
line := text.first(tLine); line := text.first(tLine);
Lines.setVectorItem(text.LinesVector, k, line);
INC(k);
line.cin := 0; line.cin := 0;
line.cout := 0; line.cout := 0;
i := 0; i := 0;
ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang); ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
NextLine(line); NextLine(line);
WHILE line # NIL DO WHILE line # NIL DO
Lines.setVectorItem(text.LinesVector, k, line);
INC(k);
line.cin := line.prev(tLine).cout; line.cin := line.prev(tLine).cout;
line.cout := line.cin; line.cout := line.cin;
i := 0; i := 0;
ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang); ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
NextLine(line) NextLine(line)
END
END; END;
text.smallChange := 0;
text.comments := FALSE text.comments := FALSE
END Comments; END Comments;
@ -933,7 +967,7 @@ PROCEDURE getLine (text: tText; n: INTEGER): tLine;
VAR VAR
item: List.tItem; item: List.tItem;
BEGIN BEGIN
item := List.getItem(text, n); item := List.getItem(text, n)
RETURN item(tLine) RETURN item(tLine)
END getLine; END getLine;
@ -1110,6 +1144,7 @@ BEGIN
resetSelect(text); resetSelect(text);
curLine := text.curLine; curLine := text.curLine;
IF text.cursor.X > 0 THEN IF text.cursor.X > 0 THEN
INC(text.smallChange);
i := text.cursor.X; i := text.cursor.X;
n := leadingSpaces(curLine); n := leadingSpaces(curLine);
modify(text); modify(text);
@ -1236,7 +1271,7 @@ VAR
BEGIN BEGIN
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
i := selEnd.Y - selBeg.Y + 1; i := selEnd.Y - selBeg.Y + 1;
line := getLine(text, selBeg.Y); line := getLine2(text, selBeg.Y);
modified := incr; modified := incr;
WHILE i > 0 DO WHILE i > 0 DO
IF incr THEN IF incr THEN
@ -1247,11 +1282,12 @@ BEGIN
NextLine(line); NextLine(line);
DEC(i) DEC(i)
END; END;
line := getLine(text, selEnd.Y); line := getLine2(text, selEnd.Y);
text.select^ := selBeg; text.select^ := selBeg;
text.select.X := 0; text.select.X := 0;
SetPos(text, line.length, selEnd.Y); SetPos(text, line.length, selEnd.Y);
IF modified THEN IF modified THEN
INC(text.smallChange);
modify(text) modify(text)
END END
END Indent; END Indent;
@ -1293,6 +1329,9 @@ VAR
BEGIN BEGIN
IF (code >= ORD(SPACE)) & (code # 127) THEN IF (code >= ORD(SPACE)) & (code # 127) THEN
IF ~selected(text) THEN
INC(text.smallChange)
END;
delSelect(text); delSelect(text);
curLine := text.curLine; curLine := text.curLine;
Lines.insert(curLine, text.cursor.X, WCHR(code)); Lines.insert(curLine, text.cursor.X, WCHR(code));
@ -1309,6 +1348,7 @@ BEGIN
IF selected(text) THEN IF selected(text) THEN
Indent(text, TRUE) Indent(text, TRUE)
ELSE ELSE
INC(text.smallChange);
tab(text) tab(text)
END END
ELSIF code = 13 THEN ELSIF code = 13 THEN
@ -1461,8 +1501,8 @@ VAR
BEGIN BEGIN
IF selected(text) THEN IF selected(text) THEN
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
first := getLine(text, selBeg.Y); first := getLine2(text, selBeg.Y);
last := getLine(text, selEnd.Y); last := getLine2(text, selEnd.Y);
lines := selEnd.Y - selBeg.Y + 1; lines := selEnd.Y - selBeg.Y + 1;
IF lines > 1 THEN IF lines > 1 THEN
@ -1505,7 +1545,7 @@ VAR
BEGIN BEGIN
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
first := getLine(text, selBeg.Y); first := getLine2(text, selBeg.Y);
line := first; line := first;
n := selEnd.Y - selBeg.Y; n := selEnd.Y - selBeg.Y;
@ -1697,6 +1737,7 @@ BEGIN
END; END;
IF Lines.chCase(line, i + 1, text.cursor.X - 1, upper) THEN IF Lines.chCase(line, i + 1, text.cursor.X - 1, upper) THEN
INC(text.smallChange);
modify(text) modify(text)
END END
END changeCase; END changeCase;
@ -1712,7 +1753,7 @@ BEGIN
modified := FALSE; modified := FALSE;
IF selected(text) THEN IF selected(text) THEN
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
first := getLine(text, selBeg.Y); first := getLine2(text, selBeg.Y);
line := first; line := first;
cnt := selEnd.Y - selBeg.Y; cnt := selEnd.Y - selBeg.Y;
IF cnt = 0 THEN IF cnt = 0 THEN
@ -1737,6 +1778,7 @@ BEGIN
END END
END; END;
IF modified THEN IF modified THEN
INC(text.smallChange);
modify(text) modify(text)
END END
END chCase; END chCase;
@ -1757,6 +1799,7 @@ END UpDown;
PROCEDURE delLine* (text: tText); PROCEDURE delLine* (text: tText);
BEGIN BEGIN
text.smallChange := 2;
resetSelect(text); resetSelect(text);
IF text.curLine.length > 0 THEN IF text.curLine.length > 0 THEN
Lines.delCharN(text.curLine, 0, text.curLine.length) Lines.delCharN(text.curLine, 0, text.curLine.length)
@ -1905,6 +1948,9 @@ BEGIN
str := "" str := ""
END END
END; END;
IF text.searchText # str THEN
text.smallMove := FALSE
END;
IF search(text, str, Lang.isCS(text.lang), TRUE) THEN END IF search(text, str, Lang.isCS(text.lang), TRUE) THEN END
END wordSel; END wordSel;
@ -1934,12 +1980,16 @@ END getWordPos;
PROCEDURE key* (text: tText; code: INTEGER; shift, ctrl: BOOLEAN); PROCEDURE key* (text: tText; code: INTEGER; shift, ctrl: BOOLEAN);
VAR VAR
n, wPos: INTEGER; n, wPos: INTEGER;
scrX, scrY: INTEGER;
resSel: BOOLEAN;
BEGIN BEGIN
resSel := FALSE;
IF shift THEN IF shift THEN
setSelect(text) setSelect(text)
ELSE ELSE
IF (33 <= code) & (code <= 40) THEN IF (33 <= code) & (code <= 40) THEN
IF ~(((code = 38) OR (code = 40)) & ctrl) THEN IF ~(((code = 38) OR (code = 40)) & ctrl) THEN
resSel := selected(text);
resetSelect(text) resetSelect(text)
END END
END END
@ -1980,6 +2030,8 @@ BEGIN
IF (text.cursor.X = 0) & (text.curLine.prev # NIL) THEN IF (text.cursor.X = 0) & (text.curLine.prev # NIL) THEN
SetPos(text, text.curLine.prev(tLine).length, text.cursor.Y - 1) SetPos(text, text.curLine.prev(tLine).length, text.cursor.Y - 1)
ELSE ELSE
scrX := text.scroll.X;
scrY := text.scroll.Y;
IF ctrl THEN IF ctrl THEN
wPos := 0; wPos := 0;
REPEAT REPEAT
@ -1989,7 +2041,8 @@ BEGIN
move(text, n - text.cursor.X) move(text, n - text.cursor.X)
ELSE ELSE
move(text, -1) move(text, -1)
END END;
text.smallMove := (scrX = text.scroll.X) & (scrY = text.scroll.Y) & ~resSel
END END
|38: |38:
IF ctrl THEN IF ctrl THEN
@ -2001,11 +2054,14 @@ BEGIN
IF (text.cursor.X = text.curLine.length) & (text.curLine.next # NIL) THEN IF (text.cursor.X = text.curLine.length) & (text.curLine.next # NIL) THEN
SetPos(text, 0, text.cursor.Y + 1) SetPos(text, 0, text.cursor.Y + 1)
ELSE ELSE
scrX := text.scroll.X;
scrY := text.scroll.Y;
IF ctrl THEN IF ctrl THEN
move(text, getWordPos(text.curLine, text.cursor.X) - text.cursor.X) move(text, getWordPos(text.curLine, text.cursor.X) - text.cursor.X)
ELSE ELSE
move(text, 1) move(text, 1)
END END;
text.smallMove := (scrX = text.scroll.X) & (scrY = text.scroll.Y) & ~resSel
END END
|40: |40:
IF ctrl THEN IF ctrl THEN
@ -2017,6 +2073,9 @@ BEGIN
IF ctrl THEN IF ctrl THEN
delLine(text) delLine(text)
ELSE ELSE
IF ~selected(text) & (text.cursor.X < text.curLine.length) THEN
INC(text.smallChange)
END;
delete(text); delete(text);
ShowCursor ShowCursor
END END
@ -2103,11 +2162,12 @@ BEGIN
END selectWord; END selectWord;
PROCEDURE cursor (text: tText); PROCEDURE cursor* (text: tText);
VAR VAR
x, y1, y2, scrollX, scrollY: INTEGER; x, y1, y2, scrollX, scrollY: INTEGER;
cursor: pPoint; cursor: pPoint;
BEGIN BEGIN
IF drawCursor THEN
cursor := text.cursor; cursor := text.cursor;
scrollX := text.scroll.X; scrollX := text.scroll.X;
scrollY := text.scroll.Y; scrollY := text.scroll.Y;
@ -2119,6 +2179,7 @@ BEGIN
G.notVLine(canvas, x, y1, y2); G.notVLine(canvas, x, y1, y2);
G.notVLine(canvas, x - 1, y1, y2) G.notVLine(canvas, x - 1, y1, y2)
END END
END
END cursor; END cursor;
@ -2168,7 +2229,7 @@ END setPadding;
PROCEDURE draw* (text: tText); PROCEDURE draw* (text: tText);
VAR VAR
y, n, Len, cnt, i, x: INTEGER; y, n, cnt, i, x: INTEGER;
line, firstLine, lastLine: tLine; line, firstLine, lastLine: tLine;
selBeg, selEnd: tPoint; selBeg, selEnd: tPoint;
s: ARRAY 12 OF WCHAR; s: ARRAY 12 OF WCHAR;
@ -2176,10 +2237,10 @@ VAR
p: Search.tPos; p: Search.tPos;
guard: tGuard; guard: tGuard;
BEGIN BEGIN
IF text.search & search(text, text.searchText, text.cs, text.whole) THEN END; IF text.comments THEN
IF (text.lang # Lang.langText) & text.comments THEN
Comments(text) Comments(text)
END; END;
IF text.search & search(text, text.searchText, text.cs, text.whole) THEN END;
IF text.guard THEN IF text.guard THEN
NEW(guard); NEW(guard);
List.append(ChangeLog.CL.Log, guard); List.append(ChangeLog.CL.Log, guard);
@ -2197,7 +2258,9 @@ BEGIN
guard.selected := text.select = text.select2; guard.selected := text.select = text.select2;
G.SetColor(canvas, colors.back); G.SetColor(canvas, colors.back);
G.clear(canvas); IF ~text.smallMove THEN
G.clear(canvas)
END;
wNum := charWidth; wNum := charWidth;
IF text.numbers THEN IF text.numbers THEN
numWidth := U.lg10(text.count) + 2; numWidth := U.lg10(text.count) + 2;
@ -2209,9 +2272,19 @@ BEGIN
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
y := padding.top + inter DIV 2; y := padding.top + inter DIV 2;
n := text.scroll.Y; n := text.scroll.Y;
line := getLine(text, n); firstLine := getLine2(text, n);
firstLine := line; IF text.smallMove THEN
cnt := 0; line := text.curLine;
cnt := textsize.Y - 1;
y := y + charHeight*(text.cursor.Y - text.scroll.Y);
G.SetColor(canvas, colors.back);
G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight);
n := text.cursor.Y
ELSE
line := firstLine;
cnt := 0
END;
WHILE (line # NIL) & (cnt < textsize.Y) DO WHILE (line # NIL) & (cnt < textsize.Y) DO
backColor := colors.back; backColor := colors.back;
IF (line = text.curLine) & ~selected(text) THEN IF (line = text.curLine) & ~selected(text) THEN
@ -2220,26 +2293,28 @@ BEGIN
backColor := colors.curline backColor := colors.curline
END; END;
SetColor(colors.text, backColor); SetColor(colors.text, backColor);
Len := MAX(line.length - text.scroll.X, 0);
G.TextOut(canvas, padding.left, y, Lines.getPChar(line, text.scroll.X), MIN(Len, textsize.X + 1), colors.delim);
IF text.lang # Lang.langText THEN
parse(text, line, y, backColor, text.lang)
END;
mark(line, y - inter DIV 2);
IF (selBeg.Y < n) & (n < selEnd.Y) THEN IF (selBeg.Y < n) & (n < selEnd.Y) THEN
drawSelect(text, line, 0, line.length, y) drawSelect(text, line, 0, line.length, y)
ELSIF (selBeg.Y = n) & (selEnd.Y = n) & (selBeg.X # selEnd.X) THEN ELSE
G.TextOut(canvas, padding.left, y, Lines.getPChar(line, text.scroll.X), MIN(MAX(line.length - text.scroll.X, 0), textsize.X + 1), colors.delim);
IF text.lang # Lang.langText THEN
parse(text, line, y, backColor, text.lang)
END
END;
IF (selBeg.Y = n) & (selEnd.Y = n) & (selBeg.X # selEnd.X) THEN
drawSelect(text, line, selBeg.X, selEnd.X, y) drawSelect(text, line, selBeg.X, selEnd.X, y)
ELSIF (selBeg.Y = n) & (selEnd.Y # n) THEN ELSIF (selBeg.Y = n) & (selEnd.Y # n) THEN
drawSelect(text, line, selBeg.X, line.length, y) drawSelect(text, line, selBeg.X, line.length, y)
ELSIF (selBeg.Y # n) & (selEnd.Y = n) THEN ELSIF (selBeg.Y # n) & (selEnd.Y = n) THEN
drawSelect(text, line, 0, selEnd.X, y) drawSelect(text, line, 0, selEnd.X, y)
END; END;
mark(line, y - inter DIV 2);
NextLine(line); NextLine(line);
INC(y, charHeight); INC(y, charHeight);
INC(n); INC(n);
INC(cnt) INC(cnt)
END; END;
G.SetColor(canvas, colors.numback); G.SetColor(canvas, colors.numback);
G.FillRect(canvas, 0, 0, padding.left - pad_left (*+ 1*), size.Y - 1); G.FillRect(canvas, 0, 0, padding.left - pad_left (*+ 1*), size.Y - 1);
line := firstLine; line := firstLine;
@ -2267,17 +2342,18 @@ BEGIN
END; END;
IF text.searchText # "" THEN IF text.searchText # "" THEN
cnt := 0; IF text.smallMove THEN
line := firstLine; firstLine := text.curLine;
lastLine := line; lastLine := firstLine
WHILE (line # NIL) & (cnt < textsize.Y) DO ELSE
lastLine := line; lastLine := getLine2(text, text.scroll.Y + textsize.Y - 1)
NextLine(line);
INC(cnt)
END; END;
p := text.foundList.first(Search.tPos); p := text.foundList.first(Search.tPos);
WHILE p # NIL DO WHILE p # NIL DO
y := padding.top + inter DIV 2; y := padding.top + inter DIV 2;
IF text.smallMove THEN
y := y + charHeight*(text.cursor.Y - text.scroll.Y)
END;
IF (firstLine.pos <= p.pos) & (p.pos <= lastLine.pos + lastLine.length) THEN IF (firstLine.pos <= p.pos) & (p.pos <= lastLine.pos + lastLine.length) THEN
line := firstLine; line := firstLine;
WHILE (line.pos <= p.pos) & (line # lastLine) DO WHILE (line.pos <= p.pos) & (line # lastLine) DO
@ -2296,12 +2372,14 @@ BEGIN
END; END;
INC(x); INC(x);
DEC(n) DEC(n)
END; END
END; END;
p := p.next(Search.tPos) p := p.next(Search.tPos)
END END
END; END;
text.smallMove := FALSE;
IF text.foundSel > 0 THEN IF text.foundSel > 0 THEN
x := (text.cursor.X - text.scroll.X)*charWidth + padding.left; x := (text.cursor.X - text.scroll.X)*charWidth + padding.left;
y := (text.cursor.Y - text.scroll.Y)*charHeight + padding.top + inter DIV 2; y := (text.cursor.Y - text.scroll.Y)*charHeight + padding.top + inter DIV 2;
@ -2314,10 +2392,7 @@ BEGIN
DEC(n) DEC(n)
END END
END; END;
IF drawCursor THEN
cursor(text) cursor(text)
END
END draw; END draw;
@ -2346,6 +2421,7 @@ BEGIN
setPadding(padding.left, padding.top); setPadding(padding.left, padding.top);
text.curLine := NIL; text.curLine := NIL;
text.modified := FALSE; text.modified := FALSE;
text.smallMove := FALSE;
text.comments := TRUE; text.comments := TRUE;
text.search := TRUE; text.search := TRUE;
text.cs := FALSE; text.cs := FALSE;
@ -2357,7 +2433,9 @@ BEGIN
text.searchText := ""; text.searchText := "";
text.foundSel := 0; text.foundSel := 0;
text.CurX := -1; text.CurX := -1;
text.smallChange := 0;
text.lang := Lang.langText; text.lang := Lang.langText;
text.LinesVector := NIL;
Lang.setCurLang(Lang.langText); Lang.setCurLang(Lang.langText);
setName(text, fileName); setName(text, fileName);
ASSERT(text = List.create(text)) ASSERT(text = List.create(text))
@ -2408,6 +2486,7 @@ PROCEDURE destroy* (VAR text: tText);
BEGIN BEGIN
IF search(text, "", FALSE, FALSE) THEN END; IF search(text, "", FALSE, FALSE) THEN END;
ChangeLog.destroy(text.chLog); ChangeLog.destroy(text.chLog);
Lines.destroyVector(text.LinesVector);
DISPOSE(text.foundList); DISPOSE(text.foundList);
DISPOSE(text.cursor); DISPOSE(text.cursor);
DISPOSE(text.select2); DISPOSE(text.select2);
@ -2450,12 +2529,10 @@ BEGIN
RW.destroy(file); RW.destroy(file);
text.curLine := text.first(tLine); text.curLine := text.first(tLine);
SetPos(text, 0, 0); SetPos(text, 0, 0);
resetSelect(text) resetSelect(text);
Comments(text)
ELSE ELSE
errno := 1 errno := 1
END;
IF (text # NIL) & (text.lang # Lang.langText) THEN
Comments(text)
END END
RETURN text RETURN text
END open; END open;