CEDIT: better timer, minor fixes

git-svn-id: svn://kolibrios.org@9181 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2021-09-07 20:18:42 +00:00
parent 0d7861018a
commit 3f871a7798
5 changed files with 49 additions and 61 deletions

Binary file not shown.

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, box_lib, Icons, Tabs, Timer; RW, Ini, box_lib, Icons, Tabs, Timer;
CONST CONST
header = "CEdit (06-sep-2021)"; header = "CEdit (07-sep-2021)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
@ -81,7 +81,7 @@ CONST
RIGHT = scrollWidth - 2; RIGHT = scrollWidth - 2;
BOTTOM = scrollWidth + 18; BOTTOM = scrollWidth + 18;
minWinWidth = 635; minWinHeight = 538; minWinWidth = 635; minWinHeight = 550;
SEARCH_PADDING = 10; SEARCH_PADDING = 10;
searchLeft = 0; searchLeft = 0;
@ -250,10 +250,10 @@ PROCEDURE resetTimer;
BEGIN BEGIN
IF EditBox_Focus(FindEdit) OR EditBox_Focus(ReplaceEdit) OR EditBox_Focus(GotoEdit) THEN IF EditBox_Focus(FindEdit) OR EditBox_Focus(ReplaceEdit) OR EditBox_Focus(GotoEdit) THEN
T.hideCursor; T.hideCursor;
Timer.stop Timer.kill
ELSE ELSE
T.showCursor; T.showCursor;
Timer.reset Timer.create(mainTID)
END END
END resetTimer; END resetTimer;
@ -298,7 +298,7 @@ CONST
VAR VAR
top, left, right, bottom, x, y, width: INTEGER; top, left, right, bottom, x, y, width: INTEGER;
BEGIN BEGIN
Timer.stop; Timer.kill;
width := minWidth + LENGTH(s)*fontWidth; width := minWidth + LENGTH(s)*fontWidth;
left := (canvas.width - width) DIV 2 + LEFT; left := (canvas.width - width) DIV 2 + LEFT;
top := (canvas.height - height) DIV 2 + TOP; top := (canvas.height - height) DIV 2 + TOP;
@ -411,7 +411,7 @@ END toolbarIcons;
PROCEDURE WriteModified (x, y: INTEGER); PROCEDURE WriteModified (x, y: INTEGER);
BEGIN BEGIN
modified := text.modified; modified := text.modified;
K.DrawRect(x, TOP + canvas.height + scrollWidth - 1, 8*fontWidth, BOTTOM - scrollWidth + 1, K.winColor); K.DrawRect(x, TOP + canvas.height + scrollWidth, 8*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
IF modified THEN IF modified THEN
K.DrawText866(x, y, K.textColor, "modified") K.DrawText866(x, y, K.textColor, "modified")
END END
@ -431,7 +431,7 @@ BEGIN
DEC(x, w + 10); DEC(x, w + 10);
K.DrawText(x, y, K.textColor, RW.eolNames[text.eol]); K.DrawText(x, y, K.textColor, RW.eolNames[text.eol]);
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2; y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth - 1, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor); K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName); K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName);
WriteModified(width - 8*fontWidth, y) WriteModified(width - 8*fontWidth, y)
END DrawState; END DrawState;
@ -471,7 +471,7 @@ BEGIN
END; END;
T.draw(text); T.draw(text);
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2; y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT, TOP + canvas.height + scrollWidth - 1, 16*fontWidth, BOTTOM - scrollWidth + 1, K.winColor); K.DrawRect(LEFT, TOP + canvas.height + scrollWidth, 16*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
WritePos(y); WritePos(y);
IF modified # text.modified THEN IF modified # text.modified THEN
@ -479,8 +479,8 @@ BEGIN
END; END;
T.getScroll(text, scrollX, scrollY); T.getScroll(text, scrollX, scrollY);
DrawScroll(vScroll, LEFT + canvas.width - 1, TOP - 1, scrollY, text.count - 1); DrawScroll(vScroll, LEFT + canvas.width, TOP - 1, scrollY, text.count - 1);
DrawScroll(hScroll, LEFT, TOP + canvas.height - 1, scrollX, text.maxLength); DrawScroll(hScroll, LEFT, TOP + canvas.height, scrollX, text.maxLength);
G.DrawCanvas(canvas, LEFT, TOP); G.DrawCanvas(canvas, LEFT, TOP);
NotFound; NotFound;
@ -505,13 +505,13 @@ BEGIN
K.WinSize(winWidth, winHeight); K.WinSize(winWidth, winHeight);
K.ClientSize(cliWidth, cliHeight); K.ClientSize(cliWidth, cliHeight);
G.destroy(canvas); G.destroy(canvas);
canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 1), cliHeight - (TOP + BOTTOM)); canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 2), cliHeight - (TOP + BOTTOM + 1));
Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, cliWidth - (LEFT + RIGHT + 1), Tabs.tabHeight); Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, cliWidth - (LEFT + RIGHT + 2), Tabs.tabHeight);
G.SetFont(canvas, font); G.SetFont(canvas, font);
T.setCanvas(canvas); T.setCanvas(canvas);
T.resize(canvas.width, canvas.height); T.resize(canvas.width, canvas.height);
Scroll.resize(vScroll, vScroll.width, canvas.height + 1); Scroll.resize(vScroll, vScroll.width, canvas.height + 2);
Scroll.resize(hScroll, canvas.width, hScroll.height); Scroll.resize(hScroll, canvas.width + 1, hScroll.height);
END resize; END resize;
@ -611,7 +611,7 @@ BEGIN
K.DrawRect(0, 0, width, TOP, K.winColor); K.DrawRect(0, 0, width, TOP, K.winColor);
K.DrawRect(0, 0, LEFT, height, K.winColor); K.DrawRect(0, 0, LEFT, height, K.winColor);
K.DrawRect(LEFT + canvas.width - 1, TOP + canvas.height - 1, scrollWidth, scrollWidth, K.winColor); K.DrawRect(LEFT + canvas.width + 1, TOP + canvas.height, scrollWidth - 1, scrollWidth, K.winColor);
drawMainMenu(menuFile, menuFileX, btnFile, "file"); drawMainMenu(menuFile, menuFileX, btnFile, "file");
drawMainMenu(menuEdit, menuEditX, btnEdit, "edit"); drawMainMenu(menuEdit, menuEditX, btnEdit, "edit");
@ -698,9 +698,8 @@ END getKBState;
PROCEDURE stopTimer; PROCEDURE stopTimer;
BEGIN BEGIN
T.hideCursor; T.hideCursor;
Timer.stop; Timer.kill;
repaint; repaint
Timer.stop
END stopTimer; END stopTimer;
@ -867,13 +866,6 @@ BEGIN
END Confirm; END Confirm;
PROCEDURE Exit;
BEGIN
Timer.kill;
K.Exit
END Exit;
PROCEDURE closeFile (conf: BOOLEAN; n: INTEGER); PROCEDURE closeFile (conf: BOOLEAN; n: INTEGER);
VAR VAR
i: INTEGER; i: INTEGER;
@ -892,7 +884,7 @@ BEGIN
IF curText >= 0 THEN IF curText >= 0 THEN
Switch(texts[curText]) Switch(texts[curText])
ELSE ELSE
Exit K.Exit
END; END;
draw_window draw_window
END END
@ -1258,7 +1250,7 @@ BEGIN
Menu.setEnabled(subCase, menuLower, selected); Menu.setEnabled(subCase, menuLower, selected);
IF menu # NIL THEN IF menu # NIL THEN
Timer.stop; Timer.kill;
IF Menu.opened(menu) THEN IF Menu.opened(menu) THEN
Menu.close(menu) Menu.close(menu)
END; END;
@ -1273,10 +1265,11 @@ VAR
scrollIPC: BOOLEAN; scrollIPC: BOOLEAN;
BEGIN BEGIN
scrollIPC := FALSE; scrollIPC := FALSE;
IF IPC[0] = Timer.ID THEN IF IPC[0] = Timer.ID THEN
T.toggleCursor; IF IPC[4] = Timer.n THEN
repaint; T.toggleCursor;
repaint
END;
IPC[2] := 0 IPC[2] := 0
ELSIF IPC[0] = mainTID THEN ELSIF IPC[0] = mainTID THEN
IF IPC[2] = Scroll.ScrollIPC THEN IF IPC[2] = Scroll.ScrollIPC THEN
@ -2128,7 +2121,7 @@ BEGIN
cliWidth := winWidth; cliWidth := winWidth;
cliHeight := winHeight; cliHeight := winHeight;
LEFT := searchLeft; LEFT := searchLeft;
canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 10), winHeight - (TOP + BOTTOM + 4) - K.SkinHeight()); canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 11), winHeight - (TOP + BOTTOM + 5) - K.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, "", {}); font1 := G.CreateFont(1, "", {});
@ -2166,15 +2159,15 @@ BEGIN
text := T.open(fileName, err); text := T.open(fileName, err);
IF text = NIL THEN IF text = NIL THEN
error("'cedit: error opening file' -E"); error("'cedit: error opening file' -E");
Exit K.Exit
ELSE ELSE
U.getPath(fileName, filePath) U.getPath(fileName, filePath)
END END
END; END;
OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, ""); OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, "");
insert(0, text); insert(0, text);
Scroll.create(FALSE, canvas.width, scrollWidth, scrollWidth, scrollWidth, hScroll); Scroll.create(FALSE, canvas.width + 1, scrollWidth, scrollWidth, scrollWidth, hScroll);
Scroll.create(TRUE, scrollWidth, canvas.height, scrollWidth, scrollWidth, vScroll); Scroll.create(TRUE, scrollWidth, canvas.height + 1, scrollWidth, scrollWidth, vScroll);
T.resize(canvas.width, canvas.height); T.resize(canvas.width, canvas.height);
T.SetPos(text, 0, 0); T.SetPos(text, 0, 0);
confirm := FALSE; confirm := FALSE;

View File

@ -2202,9 +2202,7 @@ BEGIN
cursor(text) cursor(text)
END; END;
G.SetColor(canvas, K.borderColor); G.SetColor(canvas, K.borderColor);
G.HLine(canvas, size.Y - 1, 0, size.X - 1);
G.VLine(canvas, 0, 0, size.Y - 1); G.VLine(canvas, 0, 0, size.Y - 1);
G.VLine(canvas, size.X - 1, 0, size.Y - 1)
END draw; END draw;

View File

@ -23,28 +23,15 @@ IMPORT SYSTEM, K := KolibriOS, KOSAPI, Ini;
VAR VAR
stack: ARRAY 1024*64 OF INTEGER; stack: ARRAY 1024*64 OF INTEGER;
ID*, time, cnt: INTEGER; ID*, n*, time, cnt: INTEGER;
paused: BOOLEAN; enabled: BOOLEAN;
msg: ARRAY 3 OF INTEGER;
PROCEDURE reset*;
BEGIN
cnt := time;
paused := FALSE
END reset;
PROCEDURE stop*;
BEGIN
cnt := time;
paused := TRUE
END stop;
PROCEDURE kill*; PROCEDURE kill*;
BEGIN BEGIN
ID := 0; enabled := FALSE;
K.ExitID(ID) INC(n)
END kill; END kill;
@ -52,16 +39,18 @@ PROCEDURE [stdcall] main (mainTID: INTEGER);
CONST CONST
step = 5; step = 5;
BEGIN BEGIN
msg[0] := ID;
msg[1] := 12;
WHILE TRUE DO WHILE TRUE DO
K.Pause(step); K.Pause(step);
IF KOSAPI.sysfunc3(18, 21, mainTID) = 0 THEN IF KOSAPI.sysfunc3(18, 21, mainTID) = 0 THEN
ID := 0; ID := 0;
K.Exit K.Exit
END; END;
IF ~paused THEN IF enabled THEN
DEC(cnt, step); DEC(cnt, step);
IF cnt <= 0 THEN IF cnt <= 0 THEN
K.SendIPC(mainTID, ID); KOSAPI.sysfunc5(60, 2, mainTID, SYSTEM.ADR(msg[0]), msg[1]);
cnt := time cnt := time
END END
END END
@ -72,12 +61,20 @@ END main;
PROCEDURE create* (mainTID: INTEGER); PROCEDURE create* (mainTID: INTEGER);
BEGIN BEGIN
time := Ini.blink; time := Ini.blink;
reset; cnt := time;
stack[LEN(stack) - 1] := mainTID; enabled := TRUE;
ID := K.CreateThread(SYSTEM.ADR(main), stack) IF ID = 0 THEN
stack[LEN(stack) - 1] := mainTID;
ID := K.CreateThread(SYSTEM.ADR(main), stack)
ELSE
INC(n);
msg[2] := n
END
END create; END create;
BEGIN BEGIN
ID := 0 ID := 0;
msg[2] := 0;
n := 0;
END Timer. END Timer.

View File

@ -314,7 +314,7 @@ BEGIN
x := x - scroll.left; x := x - scroll.left;
y := y - scroll.top; y := y - scroll.top;
scroll.mouse := TRUE; scroll.mouse := TRUE;
IF between(0, x, scroll.width - 1) & between(0, y, scroll.height - 1) THEN IF between(1, x, scroll.width - 2) & between(1, y, scroll.height - 2) THEN
IF scroll.vertical THEN IF scroll.vertical THEN
c := y; c := y;
size := scroll.height size := scroll.height