CEdit: new toolbar buttons design; refactoring

git-svn-id: svn://kolibrios.org@9522 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2021-12-29 15:38:29 +00:00
parent 336def41ce
commit 02272ecd2b
11 changed files with 303 additions and 222 deletions

Binary file not shown.

View File

@ -25,10 +25,10 @@ IMPORT
G := Graph, T := Text, E := Encodings, G := Graph, T := Text, E := Encodings,
CB := Clipboard, Languages, CB := Clipboard, Languages,
ChangeLog, Scroll, CheckBox, ChangeLog, Scroll, CheckBox,
RW, Ini, EB := EditBox, Tabs, Toolbar; RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST CONST
HEADER = "CEdit (23-dec-2021)"; HEADER = "CEdit (29-dec-2021)";
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";
@ -182,8 +182,7 @@ VAR
winWidth, winHeight: INTEGER; winWidth, winHeight: INTEGER;
AppPath, runScript, buildScript, debugScript: RW.tFileName; AppPath, runScript, buildScript, debugScript: RW.tFileName;
OD: OpenDlg.Dialog; OD: OpenDlg.Dialog;
confirm, notFound, menuFindClicked, search, searchOpened, modified: BOOLEAN; confirm, notFound, menuFindClicked, search, searchOpened: BOOLEAN;
eol, enc: INTEGER;
switch, closing: BOOLEAN; switch, closing: BOOLEAN;
leftButton: BOOLEAN; leftButton: BOOLEAN;
@ -216,33 +215,6 @@ VAR
timerEnabled: BOOLEAN; timerEnabled: BOOLEAN;
PROCEDURE WritePos (y: INTEGER);
VAR
s1, s2, s3: ARRAY 32 OF WCHAR;
line, col, chars, lines: INTEGER;
BEGIN
T.getPos(text, col, line);
U.int2str(line, s1);
U.int2str(col, s2);
U.append(s1, ": ");
U.append(s1, s2);
IF T.selected(text) THEN
T.getSelCnt(text, chars, lines);
s3 := "sel: ";
U.int2str(chars, s2);
U.append(s3, s2);
U.append(s3, " | ");
U.int2str(lines, s2);
U.append(s3, s2)
ELSE
s3 := ""
END;
K.DrawRect(LEFT, TOP + canvas.height + scrollWidth, (16+24)*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
K.DrawText(LEFT, y, K.textColor, s1);
K.DrawText(LEFT + 16*fontWidth, y, K.textColor, s3)
END WritePos;
PROCEDURE EditBox_Focus (edit: EB.tEditBox): BOOLEAN; PROCEDURE EditBox_Focus (edit: EB.tEditBox): BOOLEAN;
RETURN 1 IN edit.flags RETURN 1 IN edit.flags
END EditBox_Focus; END EditBox_Focus;
@ -356,13 +328,6 @@ BEGIN
END getIdx; END getIdx;
PROCEDURE MarkModified;
BEGIN
modified := text.modified;
Tabs.modify(tabs, getIdx(text), modified)
END MarkModified;
PROCEDURE SetCaption (fileName: RW.tFileName); PROCEDURE SetCaption (fileName: RW.tFileName);
VAR VAR
header: RW.tFileName; header: RW.tFileName;
@ -376,23 +341,19 @@ BEGIN
END SetCaption; END SetCaption;
PROCEDURE DrawState (text: T.tText; width, height: INTEGER); PROCEDURE Status (text: T.tText; height: INTEGER);
VAR VAR
y: INTEGER; line, col, chars, lines: INTEGER;
s: ARRAY 24 OF WCHAR;
BEGIN BEGIN
eol := T.getEol(text); T.getPos(text, col, line);
enc := T.getEnc(text); T.getSelCnt(text, chars, lines);
s := ""; SB.setWidth(canvas.width + scrollWidth);
U.append(s, RW.eolNames[eol]); SB.setPos(line, col);
U.append(s, 20X + 20X); SB.setSel(chars, lines);
U.append(s, E.names[enc]); SB.setEnc(RW.eolNames[T.getEol(text)], E.names[T.getEnc(text)]);
SetCaption(text.fileName); SB.draw(LEFT, height - BOTTOM + scrollWidth - 1);
K.DrawRect(LEFT + (16+24)*fontWidth, TOP + canvas.height + scrollWidth, width - (LEFT + (16+24)*fontWidth), BOTTOM - scrollWidth + 1, K.winColor); Tabs.modify(tabs, getIdx(text), text.modified)
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2; END Status;
K.DrawText(width - LENGTH(s)*fontWidth - (RIGHT_PADDING + 1), y, K.textColor, s);
MarkModified
END DrawState;
PROCEDURE DrawScroll (VAR scroll: Scroll.tScroll; left, top, value, maxVal: INTEGER); PROCEDURE DrawScroll (VAR scroll: Scroll.tScroll; left, top, value, maxVal: INTEGER);
@ -422,19 +383,13 @@ BEGIN
END; END;
K.ClientSize(width, height); K.ClientSize(width, height);
IF switch THEN IF switch THEN
DrawState(text, width, height); Status(text, height);
Tabs.draw(tabs); Tabs.draw(tabs);
IF search & T.search(text, searchText, cs, whole) THEN END; IF search & T.search(text, searchText, cs, whole) THEN END;
switch := FALSE switch := FALSE
END; END;
T.draw(text); T.draw(text);
WritePos(height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2); Status(text, height);
IF (enc # T.getEnc(text)) OR (eol # T.getEol(text)) THEN
DrawState(text, width, height)
ELSIF modified # text.modified THEN
MarkModified
END;
T.getScroll(text, scrollX, scrollY); T.getScroll(text, scrollX, scrollY);
DrawScroll(vScroll, LEFT + canvas.width, TOP - 1, scrollY, text.count - 1); DrawScroll(vScroll, LEFT + canvas.width, TOP - 1, scrollY, text.count - 1);
@ -487,13 +442,13 @@ END resize;
PROCEDURE SearchPanel (left, top: INTEGER); PROCEDURE SearchPanel (left, top: INTEGER);
VAR VAR
y, right, bottom, color: INTEGER; y, right, bottom: INTEGER;
BEGIN BEGIN
DEC(top, Tabs.tabHeight); DEC(top, Tabs.tabHeight);
right := left + EditBox_Width + SEARCH_PADDING*2; right := left + EditBox_Width + SEARCH_PADDING*2;
bottom := top + 395 + btnHeight + SEARCH_PADDING; bottom := top + 395 + btnHeight + SEARCH_PADDING;
color := K.borderColor; Rect(left, top, right, bottom, K.borderColor);
Rect(left, top, right, bottom, color);
K.CreateButton(btnCloseSearch, right - 20, top, 20, 20, 0EF999FH, ""); K.CreateButton(btnCloseSearch, right - 20, top, 20, 20, 0EF999FH, "");
K.DrawLine(right - 14, top + 5, right - 5, top + 14, 0FFFFFFH); K.DrawLine(right - 14, top + 5, right - 5, top + 14, 0FFFFFFH);
K.DrawLine(right - 15, top + 5, right - 5, top + 15, 0FFFFFFH); K.DrawLine(right - 15, top + 5, right - 5, top + 15, 0FFFFFFH);
@ -537,7 +492,6 @@ END SearchPanel;
PROCEDURE draw_window; PROCEDURE draw_window;
VAR VAR
width, height: INTEGER; width, height: INTEGER;
BEGIN BEGIN
K.BeginDraw; K.BeginDraw;
K.CreateWindow(30 + K.GetTickCount() MOD 128, 30 + K.GetTickCount() MOD 128, winWidth, winHeight, K.winColor, 73H, 0, 0, ""); K.CreateWindow(30 + K.GetTickCount() MOD 128, 30 + K.GetTickCount() MOD 128, winWidth, winHeight, K.winColor, 73H, 0, 0, "");
@ -555,8 +509,8 @@ BEGIN
Menu.DrawMain(mainMenu); Menu.DrawMain(mainMenu);
Toolbar.draw(toolbar); Toolbar.draw(toolbar);
SetCaption(text.fileName);
DrawState(text, width, height); Status(text, height);
IF search & searchOpened THEN IF search & searchOpened THEN
SearchPanel(LEFT_PADDING, TOP) SearchPanel(LEFT_PADDING, TOP)
END; END;
@ -1998,7 +1952,6 @@ VAR
firstClickX, firstClickY, time: INTEGER; firstClickX, firstClickY, time: INTEGER;
BEGIN BEGIN
K.GetSystemColors; K.GetSystemColors;
modified := FALSE;
switch := FALSE; switch := FALSE;
closing := FALSE; closing := FALSE;
textsCount := 0; textsCount := 0;
@ -2058,7 +2011,7 @@ BEGIN
Menu.AddMainItem(mainMenu, "program", menuProgram); Menu.AddMainItem(mainMenu, "program", menuProgram);
Menu.AddMainItem(mainMenu, "tools", menuTools); Menu.AddMainItem(mainMenu, "tools", menuTools);
Toolbar.create(toolbar, LEFT_PADDING + 1, toolbarTop); Toolbar.create(toolbar, LEFT_PADDING + 5, toolbarTop);
Toolbar.add(toolbar, btnNew, 2, ""); Toolbar.add(toolbar, btnNew, 2, "");
Toolbar.add(toolbar, btnOpen, 0, ""); Toolbar.add(toolbar, btnOpen, 0, "");
Toolbar.add(toolbar, btnSave, 5, ""); Toolbar.add(toolbar, btnSave, 5, "");

View File

@ -175,13 +175,10 @@ VAR
color: INTEGER; color: INTEGER;
d: INTEGER; d: INTEGER;
BEGIN BEGIN
ASSERT(ABS(k) = 1);
color := canvas.color; color := canvas.color;
ptr := canvas.bitmap + 4*(y*canvas.width + x1); ptr := canvas.bitmap + 4*(y*canvas.width + x1);
IF k = -1 THEN d := 4*(1 - canvas.width*k);
d := 4*(canvas.width + 1)
ELSIF k = 1 THEN
d := 4*(1 - canvas.width)
END;
WHILE x1 <= x2 DO WHILE x1 <= x2 DO
SYSTEM.PUT32(ptr, color); SYSTEM.PUT32(ptr, color);
INC(ptr, d); INC(ptr, d);

View File

@ -81,7 +81,7 @@ BEGIN
END gray; END gray;
PROCEDURE iconsBackColor (icons: INTEGER); PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
VAR VAR
sizeX, sizeY, data, x, y: INTEGER; sizeX, sizeY, data, x, y: INTEGER;
b, g, r: BYTE; b, g, r: BYTE;
@ -93,7 +93,7 @@ BEGIN
SYSTEM.GET8(data + 1, g); SYSTEM.GET8(data + 1, g);
SYSTEM.GET8(data + 2, r); SYSTEM.GET8(data + 2, r);
IF b + g + r = 765 THEN IF b + g + r = 765 THEN
Graph.getRGB(K.toolbarColor, r, g, b) Graph.getRGB(BackColor, r, g, b)
END; END;
SYSTEM.PUT8(data, b); SYSTEM.PUT8(data, b);
SYSTEM.PUT8(data + 1, g); SYSTEM.PUT8(data + 1, g);
@ -104,7 +104,7 @@ BEGIN
END iconsBackColor; END iconsBackColor;
PROCEDURE get* (VAR icons, grayIcons: INTEGER); PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER);
BEGIN BEGIN
IF source = 0 THEN IF source = 0 THEN
source := load(); source := load();
@ -115,8 +115,8 @@ BEGIN
copy(source, grayIcons) copy(source, grayIcons)
END; END;
gray(grayIcons); gray(grayIcons);
iconsBackColor(icons); iconsBackColor(icons, BackColor);
iconsBackColor(grayIcons) iconsBackColor(grayIcons, BackColor)
END get; END get;

View File

@ -29,9 +29,7 @@ CONST
VAR VAR
winColor*, textColor*, btnColor*, btnTextColor*, winColor*, textColor*, btnColor*, btnTextColor*,
toolbarColor*, scrollColor*, scrollBkColor*, borderColor*, (*darkColor,*) lightColor*: INTEGER;
borderColor*, shadowColor*, (*darkColor,*) lightColor*,
textToolbarColor*, disTextToolbarColor*: INTEGER;
PROCEDURE GetCommandLine* (): INTEGER; PROCEDURE GetCommandLine* (): INTEGER;
@ -337,21 +335,13 @@ VAR
BEGIN BEGIN
ASSERT(LEN(buf) >= 10); ASSERT(LEN(buf) >= 10);
KOSAPI.sysfunc4(48, 3, SYSTEM.ADR(buf[0]), 40); KOSAPI.sysfunc4(48, 3, SYSTEM.ADR(buf[0]), 40);
(*darkColor := buf[2];*) (*darkColor := buf[2];*)
lightColor := buf[3]; lightColor := buf[3];
winColor := buf[5]; winColor := buf[5];
textColor := buf[8];
btnColor := buf[6]; btnColor := buf[6];
btnTextColor := buf[7]; btnTextColor := buf[7];
scrollColor := btnColor; textColor := buf[8];
scrollBkColor := winColor;
borderColor := buf[9]; borderColor := buf[9];
toolbarColor := lightColor;(*0DFDFDFH;*)
shadowColor := borderColor;(*0808080H;*)
textToolbarColor := 00000FFH;
disTextToolbarColor := borderColor;(*0808080H*)
END GetSystemColors; END GetSystemColors;
@ -413,4 +403,10 @@ PROCEDURE GetThreadSlot* (tid: INTEGER): INTEGER;
END GetThreadSlot; END GetThreadSlot;
PROCEDURE PutPixel* (x, y, color: INTEGER);
BEGIN
KOSAPI.sysfunc5(1, x, y, color, 0)
END PutPixel;
END KolibriOS. END KolibriOS.

View File

@ -167,6 +167,20 @@ BEGIN
END destroy; END destroy;
PROCEDURE resize* (line: tLine; size: INTEGER);
BEGIN
ASSERT(line.temp);
IF size > 0 THEN
line.ptr := API._DISPOSE(line.ptr);
size := size*WCHAR_SIZE + 4;
INC(size, (-size) MOD 32);
line.ptr := API._NEW(size)
ELSE
destroy(line)
END
END resize;
PROCEDURE getChar* (line: tLine; i: INTEGER): WCHAR; PROCEDURE getChar* (line: tLine; i: INTEGER): WCHAR;
VAR VAR
c: WCHAR; c: WCHAR;
@ -236,25 +250,6 @@ BEGIN
END move; END move;
PROCEDURE concat* (line: tLine; s: ARRAY OF WCHAR);
VAR
Len: INTEGER;
ptr: INTEGER;
BEGIN
Len := LENGTH(s);
ptr := malloc(line.length + Len + 1);
ASSERT(ptr # 0);
SYSTEM.MOVE(line.ptr, ptr, line.length*WCHAR_SIZE);
SYSTEM.MOVE(SYSTEM.ADR(s[0]), ptr + line.length*WCHAR_SIZE, Len*WCHAR_SIZE);
SYSTEM.PUT16(ptr + (line.length + Len)*WCHAR_SIZE, 0);
IF ~line.temp THEN
movInt(line.length, line.length + Len)
END;
INC(line.length, Len);
free(line, ptr)
END concat;
PROCEDURE delChar* (line: tLine; pos: INTEGER); PROCEDURE delChar* (line: tLine; pos: INTEGER);
VAR VAR
ptr: INTEGER; ptr: INTEGER;
@ -292,7 +287,7 @@ BEGIN
END insert; END insert;
PROCEDURE insert2* (line1: tLine; pos: INTEGER; line2: tLine); PROCEDURE _insert2* (line1: tLine; pos: INTEGER; line2: tLine);
VAR VAR
ptr: INTEGER; ptr: INTEGER;
BEGIN BEGIN
@ -310,10 +305,18 @@ BEGIN
movInt(line2.length, 0) movInt(line2.length, 0)
END; END;
INC(line1.length, line2.length); INC(line1.length, line2.length);
line2.length := 0; free(line1, ptr)
free(line1, ptr);
free(line2, 0)
END END
END _insert2;
PROCEDURE insert2* (line1: tLine; pos: INTEGER; line2: tLine);
BEGIN
_insert2(line1, pos, line2);
IF line2.length > 0 THEN
line2.length := 0;
free(line2, 0)
END
END insert2; END insert2;

View File

@ -27,7 +27,7 @@ CONST
fontWidth = 8; fontWidth = 8;
MainMenuHeight* = K.fontHeight + 7; MainMenuHeight* = K.fontHeight + 7;
MainMenuX* = 0; MainMenuX* = 3;
RIGHT = 16; RIGHT = 16;
LEFT = 16; LEFT = 16;
@ -88,7 +88,7 @@ TYPE
tProc = PROCEDURE; tProc = PROCEDURE;
VAR VAR
stack: ARRAY maxLEVEL + 1, 250000 OF INTEGER; stack: ARRAY maxLEVEL + 1, 2500 OF INTEGER;
TIDs: ARRAY maxLEVEL + 1 OF INTEGER; TIDs: ARRAY maxLEVEL + 1 OF INTEGER;
resetTimer: tProc; resetTimer: tProc;
_open: PROCEDURE (m: tMenu; x, y: INTEGER); _open: PROCEDURE (m: tMenu; x, y: INTEGER);

View File

@ -44,6 +44,7 @@ TYPE
tInput* = POINTER TO RECORD tInput* = POINTER TO RECORD
buffer: INTEGER; buffer: INTEGER;
strBuf: Lines.tLine;
pos, cnt: INTEGER; pos, cnt: INTEGER;
CR: BOOLEAN; CR: BOOLEAN;
clipbrd: BOOLEAN; clipbrd: BOOLEAN;
@ -55,7 +56,8 @@ TYPE
buffer: ARRAY BUF_SIZE OF BYTE; buffer: ARRAY BUF_SIZE OF BYTE;
pos: INTEGER; pos: INTEGER;
eol: tEOL; eol: tEOL;
putChar: PROCEDURE (file: tOutput; code: INTEGER): BOOLEAN putChar: PROCEDURE (file: tOutput; code: INTEGER);
error: BOOLEAN
END; END;
@ -63,7 +65,6 @@ VAR
eol*: ARRAY 3 OF tEOL; eol*: ARRAY 3 OF tEOL;
eolNames*: ARRAY 3, 16 OF WCHAR; eolNames*: ARRAY 3, 16 OF WCHAR;
strBuf: ARRAY 1000000 OF WCHAR;
PROCEDURE getByte (file: tInput): BYTE; PROCEDURE getByte (file: tInput): BYTE;
@ -168,9 +169,8 @@ END getCharUTF16LE;
PROCEDURE getString* (file: tInput; line: Lines.tLine; tabs: BOOLEAN; VAR eol: BOOLEAN): INTEGER; PROCEDURE getString* (file: tInput; line: Lines.tLine; tabs: BOOLEAN; VAR eol: BOOLEAN): INTEGER;
VAR VAR
c: WCHAR; c: WCHAR;
i, L, k, n: INTEGER; i, k, n: INTEGER;
BEGIN BEGIN
L := LEN(strBuf);
eol := FALSE; eol := FALSE;
n := 0; n := 0;
i := ORD(file.cnt > 0) - 1; i := ORD(file.cnt > 0) - 1;
@ -190,43 +190,34 @@ BEGIN
ELSIF c = TAB THEN ELSIF c = TAB THEN
k := Lines.tab - i MOD Lines.tab; k := Lines.tab - i MOD Lines.tab;
IF tabs THEN IF tabs THEN
strBuf[i] := TAB Lines.setChar(file.strBuf, i, TAB)
ELSE ELSE
strBuf[i] := SPACE Lines.setChar(file.strBuf, i, SPACE)
END; END;
INC(i); INC(i);
DEC(k); DEC(k);
WHILE k > 0 DO WHILE k > 0 DO
IF tabs THEN IF tabs THEN
strBuf[i] := Lines.TAB1 Lines.setChar(file.strBuf, i, Lines.TAB1)
ELSE ELSE
strBuf[i] := SPACE Lines.setChar(file.strBuf, i, SPACE)
END; END;
INC(i); INC(i);
IF i = L THEN
Lines.concat(line, strBuf);
INC(n, i);
i := 0
END;
DEC(k) DEC(k)
END; END;
file.CR := FALSE file.CR := FALSE
ELSIF c = BOM THEN ELSIF c = BOM THEN
file.CR := FALSE file.CR := FALSE
ELSE ELSE
strBuf[i] := c; Lines.setChar(file.strBuf, i, c);
INC(i); INC(i);
IF i = L THEN
Lines.concat(line, strBuf);
INC(n, i);
i := 0
END;
file.CR := FALSE file.CR := FALSE
END END
END; END;
IF i >= 0 THEN IF i >= 0 THEN
strBuf[i] := 0X; Lines.setChar(file.strBuf, i, 0X);
Lines.concat(line, strBuf); file.strBuf.length := i;
Lines._insert2(line, 0, file.strBuf)
END; END;
INC(n, i) INC(n, i)
RETURN n RETURN n
@ -324,6 +315,40 @@ BEGIN
END detectEOL; END detectEOL;
PROCEDURE getMaxLength (file: tInput): INTEGER;
VAR
res, cur, cnt: INTEGER;
c: WCHAR;
BEGIN
res := 0;
cur := 0;
cnt := file.cnt;
WHILE file.cnt > 0 DO
c := WCHR(file.getChar(file) MOD 65536);
IF (c = CR) OR (c = LF) THEN
cur := 0
ELSIF c = TAB THEN
INC(cur, Lines.tab - cur MOD Lines.tab)
ELSE
INC(cur)
END;
IF cur > res THEN
res := cur
END
END;
file.cnt := cnt;
file.pos := 0
RETURN res
END getMaxLength;
PROCEDURE createStrBuf (file: tInput);
BEGIN
file.strBuf := Lines.create(TRUE);
Lines.resize(file.strBuf, MAX(2048, getMaxLength(file) + 1))
END createStrBuf;
PROCEDURE load* (name: tFileName; VAR enc, eol: INTEGER): tInput; PROCEDURE load* (name: tFileName; VAR enc, eol: INTEGER): tInput;
VAR VAR
res: tInput; res: tInput;
@ -337,7 +362,6 @@ BEGIN
fsize := File.FileSize(name); fsize := File.FileSize(name);
IF fsize = 0 THEN IF fsize = 0 THEN
res.buffer := KOSAPI.malloc(4096); res.buffer := KOSAPI.malloc(4096);
ASSERT(res.buffer # 0);
res.cnt := 0 res.cnt := 0
ELSE ELSE
res.buffer := File.Load(name, res.cnt) res.buffer := File.Load(name, res.cnt)
@ -353,7 +377,8 @@ BEGIN
ELSIF enc = E.W1251 THEN ELSIF enc = E.W1251 THEN
res.getChar := getCharW1251 res.getChar := getCharW1251
END; END;
eol := detectEOL(res) eol := detectEOL(res);
createStrBuf(res)
END END
RETURN res RETURN res
END load; END load;
@ -372,17 +397,19 @@ BEGIN
res.buffer := CB.get(res.cnt); res.buffer := CB.get(res.cnt);
IF res.buffer = 0 THEN IF res.buffer = 0 THEN
DISPOSE(res) DISPOSE(res)
ELSE
createStrBuf(res)
END END
RETURN res RETURN res
END clipboard; END clipboard;
PROCEDURE putByte (file: tOutput; b: BYTE); PROCEDURE putByte (file: tOutput; b: BYTE);
VAR
c: INTEGER;
BEGIN BEGIN
IF file.pos = BUF_SIZE THEN IF file.pos = BUF_SIZE THEN
c := File.Write(file.handle, SYSTEM.ADR(file.buffer[0]), BUF_SIZE); IF File.Write(file.handle, SYSTEM.ADR(file.buffer[0]), BUF_SIZE) # BUF_SIZE THEN
file.error := TRUE
END;
file.pos := 0 file.pos := 0
END; END;
file.buffer[file.pos] := b; file.buffer[file.pos] := b;
@ -390,45 +417,34 @@ BEGIN
END putByte; END putByte;
PROCEDURE putString* (file: tOutput; line: Lines.tLine; n: INTEGER): INTEGER; PROCEDURE putString* (file: tOutput; line: Lines.tLine; n: INTEGER);
VAR VAR
i: INTEGER; i: INTEGER;
c: WCHAR; c: WCHAR;
err: BOOLEAN;
BEGIN BEGIN
i := 0; FOR i := 0 TO n - 1 DO
err := FALSE;
WHILE (i < n) & ~err DO
c := Lines.getChar(line, i); c := Lines.getChar(line, i);
IF c # Lines.TAB1 THEN IF c # Lines.TAB1 THEN
IF ~file.putChar(file, ORD(c)) THEN file.putChar(file, ORD(c))
err := TRUE; END
DEC(i)
END
END;
INC(i)
END END
RETURN i
END putString; END putString;
PROCEDURE newLine* (file: tOutput): BOOLEAN; PROCEDURE newLine* (file: tOutput);
VAR VAR
i: INTEGER; i: INTEGER;
BEGIN BEGIN
i := 0; i := 0;
WHILE (file.eol[i] # 0X) & file.putChar(file, ORD(file.eol[i])) DO WHILE file.eol[i] # 0X DO
file.putChar(file, ORD(file.eol[i]));
INC(i) INC(i)
END END
RETURN i = LENGTH(file.eol)
END newLine; END newLine;
PROCEDURE putCharUTF8 (file: tOutput; code: INTEGER): BOOLEAN; PROCEDURE putCharUTF8 (file: tOutput; code: INTEGER);
VAR
res: BOOLEAN;
BEGIN BEGIN
res := TRUE;
IF code <= 7FH THEN IF code <= 7FH THEN
putByte(file, code) putByte(file, code)
ELSIF (80H <= code) & (code <= 7FFH) THEN ELSIF (80H <= code) & (code <= 7FFH) THEN
@ -439,56 +455,44 @@ BEGIN
putByte(file, (code DIV 64) MOD 64 + 080H); putByte(file, (code DIV 64) MOD 64 + 080H);
putByte(file, code MOD 64 + 080H) putByte(file, code MOD 64 + 080H)
ELSE ELSE
res := FALSE putByte(file, ORD("?"))
END END
RETURN res
END putCharUTF8; END putCharUTF8;
PROCEDURE putCharW1251 (file: tOutput; code: INTEGER): BOOLEAN; PROCEDURE putCharW1251 (file: tOutput; code: INTEGER);
VAR VAR
n: INTEGER; n: INTEGER;
res: BOOLEAN;
BEGIN BEGIN
res := TRUE;
n := E.UNI[code, E.W1251]; n := E.UNI[code, E.W1251];
IF n # E.UNDEF THEN IF n # E.UNDEF THEN
putByte(file, n) putByte(file, n)
ELSE ELSE
res := FALSE putByte(file, ORD("?"))
END END
RETURN res
END putCharW1251; END putCharW1251;
PROCEDURE putCharCP866 (file: tOutput; code: INTEGER): BOOLEAN; PROCEDURE putCharCP866 (file: tOutput; code: INTEGER);
VAR VAR
n: INTEGER; n: INTEGER;
res: BOOLEAN;
BEGIN BEGIN
res := TRUE;
n := E.UNI[code, E.CP866]; n := E.UNI[code, E.CP866];
IF n # E.UNDEF THEN IF n # E.UNDEF THEN
putByte(file, n) putByte(file, n)
ELSE ELSE
res := FALSE putByte(file, ORD("?"))
END END
RETURN res
END putCharCP866; END putCharCP866;
PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER): BOOLEAN; PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER);
VAR
res: BOOLEAN;
BEGIN BEGIN
IF (0 <= code) & (code <= 65535) THEN IF ~((0 <= code) & (code <= 65535)) THEN
res := TRUE; code := ORD("?")
putByte(file, code MOD 256); END;
putByte(file, code DIV 256) putByte(file, code MOD 256);
ELSE putByte(file, code DIV 256)
res := FALSE
END
RETURN res
END putCharUTF16LE; END putCharUTF16LE;
@ -502,6 +506,7 @@ BEGIN
IF file.pos > 0 THEN IF file.pos > 0 THEN
res := File.Write(file.handle, SYSTEM.ADR(file.buffer[0]), file.pos) = file.pos res := File.Write(file.handle, SYSTEM.ADR(file.buffer[0]), file.pos) = file.pos
END; END;
res := res & ~file.error;
File.Close(file.handle) File.Close(file.handle)
END; END;
DISPOSE(file) DISPOSE(file)
@ -521,7 +526,7 @@ BEGIN
IF (enc = E.UTF8) OR (enc = E.UTF8BOM) THEN IF (enc = E.UTF8) OR (enc = E.UTF8BOM) THEN
res.putChar := putCharUTF8; res.putChar := putCharUTF8;
IF enc = E.UTF8BOM THEN IF enc = E.UTF8BOM THEN
ASSERT(res.putChar(res, ORD(BOM))) res.putChar(res, ORD(BOM))
END END
ELSIF enc = E.UTF16LE THEN ELSIF enc = E.UTF16LE THEN
res.putChar := putCharUTF16LE; res.putChar := putCharUTF16LE;
@ -532,6 +537,7 @@ BEGIN
END; END;
ASSERT(res.putChar # NIL); ASSERT(res.putChar # NIL);
res.handle := File.Create(name); res.handle := File.Create(name);
res.error := FALSE;
IF res.handle = NIL THEN IF res.handle = NIL THEN
DISPOSE(res) DISPOSE(res)
END END
@ -540,10 +546,15 @@ END create;
PROCEDURE destroy* (VAR file: tInput); PROCEDURE destroy* (VAR file: tInput);
VAR
null: INTEGER;
BEGIN BEGIN
IF file # NIL THEN IF file # NIL THEN
IF file.buffer # 0 THEN IF file.buffer # 0 THEN
file.buffer := KOSAPI.free(file.buffer - 12*ORD(file.clipbrd)) null := KOSAPI.free(file.buffer - 12*ORD(file.clipbrd))
END;
IF file.strBuf # NIL THEN
Lines.resize(file.strBuf, 0)
END; END;
DISPOSE(file) DISPOSE(file)
END END

View File

@ -0,0 +1,112 @@
(*
Copyright 2021 Anton Krotov
This file is part of CEdit.
CEdit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CEdit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CEdit. If not, see <http://www.gnu.org/licenses/>.
*)
MODULE StatusBar;
IMPORT G := Graph, U := Utils, K := KolibriOS;
TYPE
tString = ARRAY 32 OF WCHAR;
tStatusBar* = RECORD
pos, sel, enc: tString;
canvas: G.tCanvas
END;
VAR
SB: tStatusBar;
font: G.tFont;
PROCEDURE setPos* (line, col: INTEGER);
VAR
s1, s2: tString;
BEGIN
U.int2str(line, s1);
U.append(s1, ": ");
U.int2str(col, s2);
U.append(s1, s2);
SB.pos := s1
END setPos;
PROCEDURE setSel* (chars, lines: INTEGER);
VAR
s1, s2: tString;
BEGIN
IF chars # 0 THEN
s1 := "sel: ";
U.int2str(chars, s2);
U.append(s1, s2);
U.append(s1, " | ");
U.int2str(lines, s2);
U.append(s1, s2);
SB.sel := s1
ELSE
SB.sel := ""
END
END setSel;
PROCEDURE setEnc* (eol, enc: ARRAY OF WCHAR);
BEGIN
SB.enc := eol;
U.append(SB.enc, 20X + 20X);
U.append(SB.enc, enc)
END setEnc;
PROCEDURE setWidth* (width: INTEGER);
BEGIN
ASSERT(width > 0);
IF (SB.canvas = NIL) OR (SB.canvas.width # width) THEN
G.destroy(SB.canvas);
SB.canvas := G.CreateCanvas(width, 19);
G.SetFont(SB.canvas, font)
END
END setWidth;
PROCEDURE TextOut (x: INTEGER; s: ARRAY OF WCHAR);
BEGIN
G.TextOut2(SB.canvas, x, 2, s, LENGTH(s))
END TextOut;
PROCEDURE draw* (left, top: INTEGER);
BEGIN
G.SetColor(SB.canvas, K.winColor);
G.SetBkColor(SB.canvas, K.winColor);
G.SetTextColor(SB.canvas, K.textColor);
G.clear(SB.canvas);
TextOut(1, SB.pos);
TextOut(16*K.fontWidth, SB.sel);
TextOut(SB.canvas.width - LENGTH(SB.enc)*K.fontWidth - 1, SB.enc);
G.DrawCanvas(SB.canvas, left, top)
END draw;
BEGIN
SB.canvas := NIL;
font := G.CreateFont(1, "", {})
END StatusBar.

View File

@ -823,7 +823,6 @@ VAR
buf: CB.tBuffer; buf: CB.tBuffer;
size: INTEGER; size: INTEGER;
line: tLine; line: tLine;
EOT: ARRAY 2 OF WCHAR;
BEGIN BEGIN
size := 0; size := 0;
line := text.first(tLine); line := text.first(tLine);
@ -848,9 +847,7 @@ BEGIN
END END
END; END;
IF eot THEN IF eot THEN
EOT[0] := 0X; CB.appends(buf, 0X + 0X, 0, 1)
EOT[1] := 0X;
CB.appends(buf, EOT, 0, 1)
END END
RETURN buf RETURN buf
END plain; END plain;
@ -1355,29 +1352,20 @@ VAR
line: tLine; line: tLine;
file: RW.tOutput; file: RW.tOutput;
res: BOOLEAN; res: BOOLEAN;
Len: INTEGER;
BEGIN BEGIN
ChangeLog.setGuard(text.edition); ChangeLog.setGuard(text.edition);
res := TRUE;
file := RW.create(tempFile, text.enc, text.eol); file := RW.create(tempFile, text.enc, text.eol);
IF file # NIL THEN IF file # NIL THEN
ChangeLog.delSaved; ChangeLog.delSaved;
line := text.first(tLine); line := text.first(tLine);
WHILE (line # NIL) & res DO WHILE line # NIL DO
Len := Lines.trimLength(line); RW.putString(file, line, Lines.trimLength(line));
IF RW.putString(file, line, Len) # Len THEN
res := FALSE
END;
NextLine(line); NextLine(line);
IF line # NIL THEN IF line # NIL THEN
IF ~RW.newLine(file) THEN RW.newLine(file)
res := FALSE
END
END END
END; END;
IF ~RW.close(file) THEN res := RW.close(file)
res := FALSE
END
ELSE ELSE
res := FALSE res := FALSE
END; END;
@ -1393,11 +1381,10 @@ BEGIN
Lines.save(line) Lines.save(line)
END; END;
NextLine(line) NextLine(line)
END; END
IF File.Delete(tempFile) THEN END
END END
END; END;
IF File.Delete(tempFile) THEN END;
IF ~res THEN IF ~res THEN
ChangeLog.delCurSaved ChangeLog.delCurSaved
END END
@ -2465,10 +2452,16 @@ VAR
line: tLine; line: tLine;
BEGIN BEGIN
errno := 0; errno := 0;
text := NIL; text := create(name);
file := RW.load(name, enc, eol); IF text # NIL THEN
file := RW.load(name, enc, eol);
IF file = NIL THEN
destroy(text)
END
ELSE
file := NIL
END;
IF file # NIL THEN IF file # NIL THEN
text := create(name);
ChangeLog.changeInt(text.enc, enc); ChangeLog.changeInt(text.enc, enc);
ChangeLog.changeInt(text.eol, eol); ChangeLog.changeInt(text.eol, eol);
text.enc := enc; text.enc := enc;

View File

@ -25,7 +25,7 @@ IMPORT
CONST CONST
max = 14; max = 14;
BtnSize* = 24; BtnSize* = 26;
BtnInter = 5; BtnInter = 5;
DelimSize = 7; DelimSize = 7;
IconPad = (BtnSize - Icons.SIZE) DIV 2; IconPad = (BtnSize - Icons.SIZE) DIV 2;
@ -42,7 +42,8 @@ TYPE
tToolbar* = RECORD tToolbar* = RECORD
buttons: ARRAY max OF tButton; buttons: ARRAY max OF tButton;
x, y, cnt, width: INTEGER; x, y, cnt, width: INTEGER;
icons, grayIcons: INTEGER icons, grayIcons: INTEGER;
colors: RECORD back, text, disText, light, shadow, window: INTEGER END
END; END;
@ -57,15 +58,15 @@ BEGIN
IF button.btn # 0 THEN IF button.btn # 0 THEN
IF button.enabled THEN IF button.enabled THEN
icons := toolbar.icons; icons := toolbar.icons;
color := K.textToolbarColor color := toolbar.colors.text
ELSE ELSE
icons := toolbar.grayIcons; icons := toolbar.grayIcons;
color := K.disTextToolbarColor color := toolbar.colors.disText
END; END;
IF button.icon # -1 THEN IF button.icon # -1 THEN
Icons.draw(icons, button.icon, button.x + IconPad, toolbar.y + IconPad) Icons.draw(icons, button.icon, button.x + IconPad, toolbar.y + IconPad)
ELSE ELSE
K.DrawRect(button.x, toolbar.y, BtnSize, BtnSize, K.toolbarColor); K.DrawRect(button.x + 1, toolbar.y + 1, BtnSize - 1, BtnSize - 1, toolbar.colors.back);
K.DrawText69(button.x + (BtnSize - LENGTH(button.text)*6) DIV 2, toolbar.y + (BtnSize - 9) DIV 2 + 2, color, button.text) K.DrawText69(button.x + (BtnSize - LENGTH(button.text)*6) DIV 2, toolbar.y + (BtnSize - 9) DIV 2 + 2, color, button.text)
END END
END; END;
@ -74,12 +75,24 @@ BEGIN
END drawIcons; END drawIcons;
PROCEDURE setColors (VAR toolbar: tToolbar);
BEGIN
toolbar.colors.back := 0F2EFECH;//K.lightColor;
toolbar.colors.text := 00000FFH;
toolbar.colors.disText := 0808080H;//K.borderColor;
toolbar.colors.light := 0FEFEFEH;
toolbar.colors.shadow := 09F9C9AH;//K.borderColor;
toolbar.colors.window := K.winColor
END setColors;
PROCEDURE draw* (VAR toolbar: tToolbar); PROCEDURE draw* (VAR toolbar: tToolbar);
VAR VAR
i, x, y, btn: INTEGER; i, x, y, btn: INTEGER;
button: tButton; button: tButton;
BEGIN BEGIN
Icons.get(toolbar.icons, toolbar.grayIcons); setColors(toolbar);
Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back);
i := 0; i := 0;
WHILE i < toolbar.cnt DO WHILE i < toolbar.cnt DO
button := toolbar.buttons[i]; button := toolbar.buttons[i];
@ -87,10 +100,14 @@ BEGIN
IF btn # 0 THEN IF btn # 0 THEN
x := button.x; x := button.x;
y := toolbar.y; y := toolbar.y;
K.DrawRect(x, y, BtnSize, BtnSize, K.toolbarColor); K.DrawRect(x + 1, y + 1, BtnSize, BtnSize - 1, toolbar.colors.back);
K.DrawLine(x, y + BtnSize, x + BtnSize, y + BtnSize, K.shadowColor); K.DrawLine(x + 1, y + BtnSize, x + BtnSize - 1, y + BtnSize, toolbar.colors.shadow);
K.DrawLine(x + BtnSize, y, x + BtnSize, y + BtnSize, K.shadowColor); K.DrawLine(x + 1, y, x + BtnSize - 1, y, toolbar.colors.light);
K.CreateButton(btn + ORD({30}), x, y, BtnSize, BtnSize, K.btnColor, "") K.DrawLine(x, y + 1, x, y + BtnSize - 1, toolbar.colors.light);
K.PutPixel(x + BtnSize, y + 1, toolbar.colors.light);
K.PutPixel(x, y + BtnSize - 1, toolbar.colors.shadow);
K.PutPixel(x + BtnSize, y + BtnSize - 1, toolbar.colors.shadow);
K.CreateButton(btn + ORD({30}), x, y, BtnSize, BtnSize, 0, "")
END; END;
INC(i) INC(i)
END; END;
@ -119,7 +136,7 @@ BEGIN
ASSERT(toolbar.cnt < max); ASSERT(toolbar.cnt < max);
button.btn := btn; button.btn := btn;
button.icon := icon; button.icon := icon;
button.x := toolbar.width; button.x := toolbar.width + toolbar.x;
button.text := text; button.text := text;
button.enabled := TRUE; button.enabled := TRUE;
toolbar.buttons[toolbar.cnt] := button; toolbar.buttons[toolbar.cnt] := button;
@ -143,8 +160,7 @@ BEGIN
toolbar.x := x; toolbar.x := x;
toolbar.y := y; toolbar.y := y;
toolbar.cnt := 0; toolbar.cnt := 0;
toolbar.width := x; toolbar.width := 0
Icons.get(toolbar.icons, toolbar.grayIcons)
END create; END create;