forked from KolibriOS/kolibrios
CEdit: new toolbar buttons design; refactoring
git-svn-id: svn://kolibrios.org@9522 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
336def41ce
commit
02272ecd2b
Binary file not shown.
@ -25,10 +25,10 @@ IMPORT
|
||||
G := Graph, T := Text, E := Encodings,
|
||||
CB := Clipboard, Languages,
|
||||
ChangeLog, Scroll, CheckBox,
|
||||
RW, Ini, EB := EditBox, Tabs, Toolbar;
|
||||
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
|
||||
|
||||
CONST
|
||||
HEADER = "CEdit (23-dec-2021)";
|
||||
HEADER = "CEdit (29-dec-2021)";
|
||||
|
||||
ShellFilter = "";
|
||||
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
|
||||
@ -182,8 +182,7 @@ VAR
|
||||
winWidth, winHeight: INTEGER;
|
||||
AppPath, runScript, buildScript, debugScript: RW.tFileName;
|
||||
OD: OpenDlg.Dialog;
|
||||
confirm, notFound, menuFindClicked, search, searchOpened, modified: BOOLEAN;
|
||||
eol, enc: INTEGER;
|
||||
confirm, notFound, menuFindClicked, search, searchOpened: BOOLEAN;
|
||||
|
||||
switch, closing: BOOLEAN;
|
||||
leftButton: BOOLEAN;
|
||||
@ -216,33 +215,6 @@ VAR
|
||||
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;
|
||||
RETURN 1 IN edit.flags
|
||||
END EditBox_Focus;
|
||||
@ -356,13 +328,6 @@ BEGIN
|
||||
END getIdx;
|
||||
|
||||
|
||||
PROCEDURE MarkModified;
|
||||
BEGIN
|
||||
modified := text.modified;
|
||||
Tabs.modify(tabs, getIdx(text), modified)
|
||||
END MarkModified;
|
||||
|
||||
|
||||
PROCEDURE SetCaption (fileName: RW.tFileName);
|
||||
VAR
|
||||
header: RW.tFileName;
|
||||
@ -376,23 +341,19 @@ BEGIN
|
||||
END SetCaption;
|
||||
|
||||
|
||||
PROCEDURE DrawState (text: T.tText; width, height: INTEGER);
|
||||
PROCEDURE Status (text: T.tText; height: INTEGER);
|
||||
VAR
|
||||
y: INTEGER;
|
||||
s: ARRAY 24 OF WCHAR;
|
||||
line, col, chars, lines: INTEGER;
|
||||
BEGIN
|
||||
eol := T.getEol(text);
|
||||
enc := T.getEnc(text);
|
||||
s := "";
|
||||
U.append(s, RW.eolNames[eol]);
|
||||
U.append(s, 20X + 20X);
|
||||
U.append(s, E.names[enc]);
|
||||
SetCaption(text.fileName);
|
||||
K.DrawRect(LEFT + (16+24)*fontWidth, TOP + canvas.height + scrollWidth, width - (LEFT + (16+24)*fontWidth), BOTTOM - scrollWidth + 1, K.winColor);
|
||||
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
|
||||
K.DrawText(width - LENGTH(s)*fontWidth - (RIGHT_PADDING + 1), y, K.textColor, s);
|
||||
MarkModified
|
||||
END DrawState;
|
||||
T.getPos(text, col, line);
|
||||
T.getSelCnt(text, chars, lines);
|
||||
SB.setWidth(canvas.width + scrollWidth);
|
||||
SB.setPos(line, col);
|
||||
SB.setSel(chars, lines);
|
||||
SB.setEnc(RW.eolNames[T.getEol(text)], E.names[T.getEnc(text)]);
|
||||
SB.draw(LEFT, height - BOTTOM + scrollWidth - 1);
|
||||
Tabs.modify(tabs, getIdx(text), text.modified)
|
||||
END Status;
|
||||
|
||||
|
||||
PROCEDURE DrawScroll (VAR scroll: Scroll.tScroll; left, top, value, maxVal: INTEGER);
|
||||
@ -422,19 +383,13 @@ BEGIN
|
||||
END;
|
||||
K.ClientSize(width, height);
|
||||
IF switch THEN
|
||||
DrawState(text, width, height);
|
||||
Status(text, height);
|
||||
Tabs.draw(tabs);
|
||||
IF search & T.search(text, searchText, cs, whole) THEN END;
|
||||
switch := FALSE
|
||||
END;
|
||||
T.draw(text);
|
||||
WritePos(height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2);
|
||||
|
||||
IF (enc # T.getEnc(text)) OR (eol # T.getEol(text)) THEN
|
||||
DrawState(text, width, height)
|
||||
ELSIF modified # text.modified THEN
|
||||
MarkModified
|
||||
END;
|
||||
Status(text, height);
|
||||
|
||||
T.getScroll(text, scrollX, scrollY);
|
||||
DrawScroll(vScroll, LEFT + canvas.width, TOP - 1, scrollY, text.count - 1);
|
||||
@ -487,13 +442,13 @@ END resize;
|
||||
|
||||
PROCEDURE SearchPanel (left, top: INTEGER);
|
||||
VAR
|
||||
y, right, bottom, color: INTEGER;
|
||||
y, right, bottom: INTEGER;
|
||||
BEGIN
|
||||
DEC(top, Tabs.tabHeight);
|
||||
right := left + EditBox_Width + SEARCH_PADDING*2;
|
||||
bottom := top + 395 + btnHeight + SEARCH_PADDING;
|
||||
color := K.borderColor;
|
||||
Rect(left, top, right, bottom, color);
|
||||
Rect(left, top, right, bottom, K.borderColor);
|
||||
|
||||
K.CreateButton(btnCloseSearch, right - 20, top, 20, 20, 0EF999FH, "");
|
||||
K.DrawLine(right - 14, top + 5, right - 5, top + 14, 0FFFFFFH);
|
||||
K.DrawLine(right - 15, top + 5, right - 5, top + 15, 0FFFFFFH);
|
||||
@ -537,7 +492,6 @@ END SearchPanel;
|
||||
PROCEDURE draw_window;
|
||||
VAR
|
||||
width, height: INTEGER;
|
||||
|
||||
BEGIN
|
||||
K.BeginDraw;
|
||||
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);
|
||||
|
||||
Toolbar.draw(toolbar);
|
||||
|
||||
DrawState(text, width, height);
|
||||
SetCaption(text.fileName);
|
||||
Status(text, height);
|
||||
IF search & searchOpened THEN
|
||||
SearchPanel(LEFT_PADDING, TOP)
|
||||
END;
|
||||
@ -1998,7 +1952,6 @@ VAR
|
||||
firstClickX, firstClickY, time: INTEGER;
|
||||
BEGIN
|
||||
K.GetSystemColors;
|
||||
modified := FALSE;
|
||||
switch := FALSE;
|
||||
closing := FALSE;
|
||||
textsCount := 0;
|
||||
@ -2058,7 +2011,7 @@ BEGIN
|
||||
Menu.AddMainItem(mainMenu, "program", menuProgram);
|
||||
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, btnOpen, 0, "");
|
||||
Toolbar.add(toolbar, btnSave, 5, "");
|
||||
|
@ -175,13 +175,10 @@ VAR
|
||||
color: INTEGER;
|
||||
d: INTEGER;
|
||||
BEGIN
|
||||
ASSERT(ABS(k) = 1);
|
||||
color := canvas.color;
|
||||
ptr := canvas.bitmap + 4*(y*canvas.width + x1);
|
||||
IF k = -1 THEN
|
||||
d := 4*(canvas.width + 1)
|
||||
ELSIF k = 1 THEN
|
||||
d := 4*(1 - canvas.width)
|
||||
END;
|
||||
d := 4*(1 - canvas.width*k);
|
||||
WHILE x1 <= x2 DO
|
||||
SYSTEM.PUT32(ptr, color);
|
||||
INC(ptr, d);
|
||||
|
@ -81,7 +81,7 @@ BEGIN
|
||||
END gray;
|
||||
|
||||
|
||||
PROCEDURE iconsBackColor (icons: INTEGER);
|
||||
PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
|
||||
VAR
|
||||
sizeX, sizeY, data, x, y: INTEGER;
|
||||
b, g, r: BYTE;
|
||||
@ -93,7 +93,7 @@ BEGIN
|
||||
SYSTEM.GET8(data + 1, g);
|
||||
SYSTEM.GET8(data + 2, r);
|
||||
IF b + g + r = 765 THEN
|
||||
Graph.getRGB(K.toolbarColor, r, g, b)
|
||||
Graph.getRGB(BackColor, r, g, b)
|
||||
END;
|
||||
SYSTEM.PUT8(data, b);
|
||||
SYSTEM.PUT8(data + 1, g);
|
||||
@ -104,7 +104,7 @@ BEGIN
|
||||
END iconsBackColor;
|
||||
|
||||
|
||||
PROCEDURE get* (VAR icons, grayIcons: INTEGER);
|
||||
PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER);
|
||||
BEGIN
|
||||
IF source = 0 THEN
|
||||
source := load();
|
||||
@ -115,8 +115,8 @@ BEGIN
|
||||
copy(source, grayIcons)
|
||||
END;
|
||||
gray(grayIcons);
|
||||
iconsBackColor(icons);
|
||||
iconsBackColor(grayIcons)
|
||||
iconsBackColor(icons, BackColor);
|
||||
iconsBackColor(grayIcons, BackColor)
|
||||
END get;
|
||||
|
||||
|
||||
|
@ -29,9 +29,7 @@ CONST
|
||||
VAR
|
||||
|
||||
winColor*, textColor*, btnColor*, btnTextColor*,
|
||||
toolbarColor*, scrollColor*, scrollBkColor*,
|
||||
borderColor*, shadowColor*, (*darkColor,*) lightColor*,
|
||||
textToolbarColor*, disTextToolbarColor*: INTEGER;
|
||||
borderColor*, (*darkColor,*) lightColor*: INTEGER;
|
||||
|
||||
|
||||
PROCEDURE GetCommandLine* (): INTEGER;
|
||||
@ -337,21 +335,13 @@ VAR
|
||||
BEGIN
|
||||
ASSERT(LEN(buf) >= 10);
|
||||
KOSAPI.sysfunc4(48, 3, SYSTEM.ADR(buf[0]), 40);
|
||||
|
||||
(*darkColor := buf[2];*)
|
||||
lightColor := buf[3];
|
||||
winColor := buf[5];
|
||||
textColor := buf[8];
|
||||
btnColor := buf[6];
|
||||
btnTextColor := buf[7];
|
||||
scrollColor := btnColor;
|
||||
scrollBkColor := winColor;
|
||||
textColor := buf[8];
|
||||
borderColor := buf[9];
|
||||
|
||||
toolbarColor := lightColor;(*0DFDFDFH;*)
|
||||
shadowColor := borderColor;(*0808080H;*)
|
||||
textToolbarColor := 00000FFH;
|
||||
disTextToolbarColor := borderColor;(*0808080H*)
|
||||
END GetSystemColors;
|
||||
|
||||
|
||||
@ -413,4 +403,10 @@ PROCEDURE GetThreadSlot* (tid: INTEGER): INTEGER;
|
||||
END GetThreadSlot;
|
||||
|
||||
|
||||
PROCEDURE PutPixel* (x, y, color: INTEGER);
|
||||
BEGIN
|
||||
KOSAPI.sysfunc5(1, x, y, color, 0)
|
||||
END PutPixel;
|
||||
|
||||
|
||||
END KolibriOS.
|
@ -167,6 +167,20 @@ BEGIN
|
||||
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;
|
||||
VAR
|
||||
c: WCHAR;
|
||||
@ -236,25 +250,6 @@ BEGIN
|
||||
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);
|
||||
VAR
|
||||
ptr: INTEGER;
|
||||
@ -292,7 +287,7 @@ BEGIN
|
||||
END insert;
|
||||
|
||||
|
||||
PROCEDURE insert2* (line1: tLine; pos: INTEGER; line2: tLine);
|
||||
PROCEDURE _insert2* (line1: tLine; pos: INTEGER; line2: tLine);
|
||||
VAR
|
||||
ptr: INTEGER;
|
||||
BEGIN
|
||||
@ -310,10 +305,18 @@ BEGIN
|
||||
movInt(line2.length, 0)
|
||||
END;
|
||||
INC(line1.length, line2.length);
|
||||
line2.length := 0;
|
||||
free(line1, ptr);
|
||||
free(line2, 0)
|
||||
free(line1, ptr)
|
||||
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;
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@ CONST
|
||||
fontWidth = 8;
|
||||
|
||||
MainMenuHeight* = K.fontHeight + 7;
|
||||
MainMenuX* = 0;
|
||||
MainMenuX* = 3;
|
||||
|
||||
RIGHT = 16;
|
||||
LEFT = 16;
|
||||
@ -88,7 +88,7 @@ TYPE
|
||||
tProc = PROCEDURE;
|
||||
|
||||
VAR
|
||||
stack: ARRAY maxLEVEL + 1, 250000 OF INTEGER;
|
||||
stack: ARRAY maxLEVEL + 1, 2500 OF INTEGER;
|
||||
TIDs: ARRAY maxLEVEL + 1 OF INTEGER;
|
||||
resetTimer: tProc;
|
||||
_open: PROCEDURE (m: tMenu; x, y: INTEGER);
|
||||
|
@ -44,6 +44,7 @@ TYPE
|
||||
|
||||
tInput* = POINTER TO RECORD
|
||||
buffer: INTEGER;
|
||||
strBuf: Lines.tLine;
|
||||
pos, cnt: INTEGER;
|
||||
CR: BOOLEAN;
|
||||
clipbrd: BOOLEAN;
|
||||
@ -55,7 +56,8 @@ TYPE
|
||||
buffer: ARRAY BUF_SIZE OF BYTE;
|
||||
pos: INTEGER;
|
||||
eol: tEOL;
|
||||
putChar: PROCEDURE (file: tOutput; code: INTEGER): BOOLEAN
|
||||
putChar: PROCEDURE (file: tOutput; code: INTEGER);
|
||||
error: BOOLEAN
|
||||
END;
|
||||
|
||||
|
||||
@ -63,7 +65,6 @@ VAR
|
||||
|
||||
eol*: ARRAY 3 OF tEOL;
|
||||
eolNames*: ARRAY 3, 16 OF WCHAR;
|
||||
strBuf: ARRAY 1000000 OF WCHAR;
|
||||
|
||||
|
||||
PROCEDURE getByte (file: tInput): BYTE;
|
||||
@ -168,9 +169,8 @@ END getCharUTF16LE;
|
||||
PROCEDURE getString* (file: tInput; line: Lines.tLine; tabs: BOOLEAN; VAR eol: BOOLEAN): INTEGER;
|
||||
VAR
|
||||
c: WCHAR;
|
||||
i, L, k, n: INTEGER;
|
||||
i, k, n: INTEGER;
|
||||
BEGIN
|
||||
L := LEN(strBuf);
|
||||
eol := FALSE;
|
||||
n := 0;
|
||||
i := ORD(file.cnt > 0) - 1;
|
||||
@ -190,43 +190,34 @@ BEGIN
|
||||
ELSIF c = TAB THEN
|
||||
k := Lines.tab - i MOD Lines.tab;
|
||||
IF tabs THEN
|
||||
strBuf[i] := TAB
|
||||
Lines.setChar(file.strBuf, i, TAB)
|
||||
ELSE
|
||||
strBuf[i] := SPACE
|
||||
Lines.setChar(file.strBuf, i, SPACE)
|
||||
END;
|
||||
INC(i);
|
||||
DEC(k);
|
||||
WHILE k > 0 DO
|
||||
IF tabs THEN
|
||||
strBuf[i] := Lines.TAB1
|
||||
Lines.setChar(file.strBuf, i, Lines.TAB1)
|
||||
ELSE
|
||||
strBuf[i] := SPACE
|
||||
Lines.setChar(file.strBuf, i, SPACE)
|
||||
END;
|
||||
INC(i);
|
||||
IF i = L THEN
|
||||
Lines.concat(line, strBuf);
|
||||
INC(n, i);
|
||||
i := 0
|
||||
END;
|
||||
DEC(k)
|
||||
END;
|
||||
file.CR := FALSE
|
||||
ELSIF c = BOM THEN
|
||||
file.CR := FALSE
|
||||
ELSE
|
||||
strBuf[i] := c;
|
||||
Lines.setChar(file.strBuf, i, c);
|
||||
INC(i);
|
||||
IF i = L THEN
|
||||
Lines.concat(line, strBuf);
|
||||
INC(n, i);
|
||||
i := 0
|
||||
END;
|
||||
file.CR := FALSE
|
||||
END
|
||||
END;
|
||||
IF i >= 0 THEN
|
||||
strBuf[i] := 0X;
|
||||
Lines.concat(line, strBuf);
|
||||
Lines.setChar(file.strBuf, i, 0X);
|
||||
file.strBuf.length := i;
|
||||
Lines._insert2(line, 0, file.strBuf)
|
||||
END;
|
||||
INC(n, i)
|
||||
RETURN n
|
||||
@ -324,6 +315,40 @@ BEGIN
|
||||
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;
|
||||
VAR
|
||||
res: tInput;
|
||||
@ -337,7 +362,6 @@ BEGIN
|
||||
fsize := File.FileSize(name);
|
||||
IF fsize = 0 THEN
|
||||
res.buffer := KOSAPI.malloc(4096);
|
||||
ASSERT(res.buffer # 0);
|
||||
res.cnt := 0
|
||||
ELSE
|
||||
res.buffer := File.Load(name, res.cnt)
|
||||
@ -353,7 +377,8 @@ BEGIN
|
||||
ELSIF enc = E.W1251 THEN
|
||||
res.getChar := getCharW1251
|
||||
END;
|
||||
eol := detectEOL(res)
|
||||
eol := detectEOL(res);
|
||||
createStrBuf(res)
|
||||
END
|
||||
RETURN res
|
||||
END load;
|
||||
@ -372,17 +397,19 @@ BEGIN
|
||||
res.buffer := CB.get(res.cnt);
|
||||
IF res.buffer = 0 THEN
|
||||
DISPOSE(res)
|
||||
ELSE
|
||||
createStrBuf(res)
|
||||
END
|
||||
RETURN res
|
||||
END clipboard;
|
||||
|
||||
|
||||
PROCEDURE putByte (file: tOutput; b: BYTE);
|
||||
VAR
|
||||
c: INTEGER;
|
||||
BEGIN
|
||||
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
|
||||
END;
|
||||
file.buffer[file.pos] := b;
|
||||
@ -390,45 +417,34 @@ BEGIN
|
||||
END putByte;
|
||||
|
||||
|
||||
PROCEDURE putString* (file: tOutput; line: Lines.tLine; n: INTEGER): INTEGER;
|
||||
PROCEDURE putString* (file: tOutput; line: Lines.tLine; n: INTEGER);
|
||||
VAR
|
||||
i: INTEGER;
|
||||
c: WCHAR;
|
||||
err: BOOLEAN;
|
||||
BEGIN
|
||||
i := 0;
|
||||
err := FALSE;
|
||||
WHILE (i < n) & ~err DO
|
||||
FOR i := 0 TO n - 1 DO
|
||||
c := Lines.getChar(line, i);
|
||||
IF c # Lines.TAB1 THEN
|
||||
IF ~file.putChar(file, ORD(c)) THEN
|
||||
err := TRUE;
|
||||
DEC(i)
|
||||
END
|
||||
END;
|
||||
INC(i)
|
||||
file.putChar(file, ORD(c))
|
||||
END
|
||||
END
|
||||
RETURN i
|
||||
END putString;
|
||||
|
||||
|
||||
PROCEDURE newLine* (file: tOutput): BOOLEAN;
|
||||
PROCEDURE newLine* (file: tOutput);
|
||||
VAR
|
||||
i: INTEGER;
|
||||
BEGIN
|
||||
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)
|
||||
END
|
||||
RETURN i = LENGTH(file.eol)
|
||||
END newLine;
|
||||
|
||||
|
||||
PROCEDURE putCharUTF8 (file: tOutput; code: INTEGER): BOOLEAN;
|
||||
VAR
|
||||
res: BOOLEAN;
|
||||
PROCEDURE putCharUTF8 (file: tOutput; code: INTEGER);
|
||||
BEGIN
|
||||
res := TRUE;
|
||||
IF code <= 7FH THEN
|
||||
putByte(file, code)
|
||||
ELSIF (80H <= code) & (code <= 7FFH) THEN
|
||||
@ -439,56 +455,44 @@ BEGIN
|
||||
putByte(file, (code DIV 64) MOD 64 + 080H);
|
||||
putByte(file, code MOD 64 + 080H)
|
||||
ELSE
|
||||
res := FALSE
|
||||
putByte(file, ORD("?"))
|
||||
END
|
||||
RETURN res
|
||||
END putCharUTF8;
|
||||
|
||||
|
||||
PROCEDURE putCharW1251 (file: tOutput; code: INTEGER): BOOLEAN;
|
||||
PROCEDURE putCharW1251 (file: tOutput; code: INTEGER);
|
||||
VAR
|
||||
n: INTEGER;
|
||||
res: BOOLEAN;
|
||||
BEGIN
|
||||
res := TRUE;
|
||||
n := E.UNI[code, E.W1251];
|
||||
IF n # E.UNDEF THEN
|
||||
putByte(file, n)
|
||||
ELSE
|
||||
res := FALSE
|
||||
putByte(file, ORD("?"))
|
||||
END
|
||||
RETURN res
|
||||
END putCharW1251;
|
||||
|
||||
|
||||
PROCEDURE putCharCP866 (file: tOutput; code: INTEGER): BOOLEAN;
|
||||
PROCEDURE putCharCP866 (file: tOutput; code: INTEGER);
|
||||
VAR
|
||||
n: INTEGER;
|
||||
res: BOOLEAN;
|
||||
BEGIN
|
||||
res := TRUE;
|
||||
n := E.UNI[code, E.CP866];
|
||||
IF n # E.UNDEF THEN
|
||||
putByte(file, n)
|
||||
ELSE
|
||||
res := FALSE
|
||||
putByte(file, ORD("?"))
|
||||
END
|
||||
RETURN res
|
||||
END putCharCP866;
|
||||
|
||||
|
||||
PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER): BOOLEAN;
|
||||
VAR
|
||||
res: BOOLEAN;
|
||||
PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER);
|
||||
BEGIN
|
||||
IF (0 <= code) & (code <= 65535) THEN
|
||||
res := TRUE;
|
||||
putByte(file, code MOD 256);
|
||||
putByte(file, code DIV 256)
|
||||
ELSE
|
||||
res := FALSE
|
||||
END
|
||||
RETURN res
|
||||
IF ~((0 <= code) & (code <= 65535)) THEN
|
||||
code := ORD("?")
|
||||
END;
|
||||
putByte(file, code MOD 256);
|
||||
putByte(file, code DIV 256)
|
||||
END putCharUTF16LE;
|
||||
|
||||
|
||||
@ -502,6 +506,7 @@ BEGIN
|
||||
IF file.pos > 0 THEN
|
||||
res := File.Write(file.handle, SYSTEM.ADR(file.buffer[0]), file.pos) = file.pos
|
||||
END;
|
||||
res := res & ~file.error;
|
||||
File.Close(file.handle)
|
||||
END;
|
||||
DISPOSE(file)
|
||||
@ -521,7 +526,7 @@ BEGIN
|
||||
IF (enc = E.UTF8) OR (enc = E.UTF8BOM) THEN
|
||||
res.putChar := putCharUTF8;
|
||||
IF enc = E.UTF8BOM THEN
|
||||
ASSERT(res.putChar(res, ORD(BOM)))
|
||||
res.putChar(res, ORD(BOM))
|
||||
END
|
||||
ELSIF enc = E.UTF16LE THEN
|
||||
res.putChar := putCharUTF16LE;
|
||||
@ -532,6 +537,7 @@ BEGIN
|
||||
END;
|
||||
ASSERT(res.putChar # NIL);
|
||||
res.handle := File.Create(name);
|
||||
res.error := FALSE;
|
||||
IF res.handle = NIL THEN
|
||||
DISPOSE(res)
|
||||
END
|
||||
@ -540,10 +546,15 @@ END create;
|
||||
|
||||
|
||||
PROCEDURE destroy* (VAR file: tInput);
|
||||
VAR
|
||||
null: INTEGER;
|
||||
BEGIN
|
||||
IF file # NIL 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;
|
||||
DISPOSE(file)
|
||||
END
|
||||
|
112
programs/develop/cedit/SRC/StatusBar.ob07
Normal file
112
programs/develop/cedit/SRC/StatusBar.ob07
Normal 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.
|
@ -823,7 +823,6 @@ VAR
|
||||
buf: CB.tBuffer;
|
||||
size: INTEGER;
|
||||
line: tLine;
|
||||
EOT: ARRAY 2 OF WCHAR;
|
||||
BEGIN
|
||||
size := 0;
|
||||
line := text.first(tLine);
|
||||
@ -848,9 +847,7 @@ BEGIN
|
||||
END
|
||||
END;
|
||||
IF eot THEN
|
||||
EOT[0] := 0X;
|
||||
EOT[1] := 0X;
|
||||
CB.appends(buf, EOT, 0, 1)
|
||||
CB.appends(buf, 0X + 0X, 0, 1)
|
||||
END
|
||||
RETURN buf
|
||||
END plain;
|
||||
@ -1355,29 +1352,20 @@ VAR
|
||||
line: tLine;
|
||||
file: RW.tOutput;
|
||||
res: BOOLEAN;
|
||||
Len: INTEGER;
|
||||
BEGIN
|
||||
ChangeLog.setGuard(text.edition);
|
||||
res := TRUE;
|
||||
file := RW.create(tempFile, text.enc, text.eol);
|
||||
IF file # NIL THEN
|
||||
ChangeLog.delSaved;
|
||||
line := text.first(tLine);
|
||||
WHILE (line # NIL) & res DO
|
||||
Len := Lines.trimLength(line);
|
||||
IF RW.putString(file, line, Len) # Len THEN
|
||||
res := FALSE
|
||||
END;
|
||||
WHILE line # NIL DO
|
||||
RW.putString(file, line, Lines.trimLength(line));
|
||||
NextLine(line);
|
||||
IF line # NIL THEN
|
||||
IF ~RW.newLine(file) THEN
|
||||
res := FALSE
|
||||
END
|
||||
RW.newLine(file)
|
||||
END
|
||||
END;
|
||||
IF ~RW.close(file) THEN
|
||||
res := FALSE
|
||||
END
|
||||
res := RW.close(file)
|
||||
ELSE
|
||||
res := FALSE
|
||||
END;
|
||||
@ -1393,11 +1381,10 @@ BEGIN
|
||||
Lines.save(line)
|
||||
END;
|
||||
NextLine(line)
|
||||
END;
|
||||
|
||||
IF File.Delete(tempFile) THEN END
|
||||
END
|
||||
END
|
||||
END;
|
||||
IF File.Delete(tempFile) THEN END;
|
||||
IF ~res THEN
|
||||
ChangeLog.delCurSaved
|
||||
END
|
||||
@ -2465,10 +2452,16 @@ VAR
|
||||
line: tLine;
|
||||
BEGIN
|
||||
errno := 0;
|
||||
text := NIL;
|
||||
file := RW.load(name, enc, eol);
|
||||
text := create(name);
|
||||
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
|
||||
text := create(name);
|
||||
ChangeLog.changeInt(text.enc, enc);
|
||||
ChangeLog.changeInt(text.eol, eol);
|
||||
text.enc := enc;
|
||||
|
@ -25,7 +25,7 @@ IMPORT
|
||||
CONST
|
||||
max = 14;
|
||||
|
||||
BtnSize* = 24;
|
||||
BtnSize* = 26;
|
||||
BtnInter = 5;
|
||||
DelimSize = 7;
|
||||
IconPad = (BtnSize - Icons.SIZE) DIV 2;
|
||||
@ -42,7 +42,8 @@ TYPE
|
||||
tToolbar* = RECORD
|
||||
buttons: ARRAY max OF tButton;
|
||||
x, y, cnt, width: INTEGER;
|
||||
icons, grayIcons: INTEGER
|
||||
icons, grayIcons: INTEGER;
|
||||
colors: RECORD back, text, disText, light, shadow, window: INTEGER END
|
||||
END;
|
||||
|
||||
|
||||
@ -57,15 +58,15 @@ BEGIN
|
||||
IF button.btn # 0 THEN
|
||||
IF button.enabled THEN
|
||||
icons := toolbar.icons;
|
||||
color := K.textToolbarColor
|
||||
color := toolbar.colors.text
|
||||
ELSE
|
||||
icons := toolbar.grayIcons;
|
||||
color := K.disTextToolbarColor
|
||||
color := toolbar.colors.disText
|
||||
END;
|
||||
IF button.icon # -1 THEN
|
||||
Icons.draw(icons, button.icon, button.x + IconPad, toolbar.y + IconPad)
|
||||
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)
|
||||
END
|
||||
END;
|
||||
@ -74,12 +75,24 @@ BEGIN
|
||||
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);
|
||||
VAR
|
||||
i, x, y, btn: INTEGER;
|
||||
button: tButton;
|
||||
BEGIN
|
||||
Icons.get(toolbar.icons, toolbar.grayIcons);
|
||||
setColors(toolbar);
|
||||
Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back);
|
||||
i := 0;
|
||||
WHILE i < toolbar.cnt DO
|
||||
button := toolbar.buttons[i];
|
||||
@ -87,10 +100,14 @@ BEGIN
|
||||
IF btn # 0 THEN
|
||||
x := button.x;
|
||||
y := toolbar.y;
|
||||
K.DrawRect(x, y, BtnSize, BtnSize, K.toolbarColor);
|
||||
K.DrawLine(x, y + BtnSize, x + BtnSize, y + BtnSize, K.shadowColor);
|
||||
K.DrawLine(x + BtnSize, y, x + BtnSize, y + BtnSize, K.shadowColor);
|
||||
K.CreateButton(btn + ORD({30}), x, y, BtnSize, BtnSize, K.btnColor, "")
|
||||
K.DrawRect(x + 1, y + 1, BtnSize, BtnSize - 1, toolbar.colors.back);
|
||||
K.DrawLine(x + 1, y + BtnSize, x + BtnSize - 1, y + BtnSize, toolbar.colors.shadow);
|
||||
K.DrawLine(x + 1, y, x + BtnSize - 1, y, toolbar.colors.light);
|
||||
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;
|
||||
INC(i)
|
||||
END;
|
||||
@ -119,7 +136,7 @@ BEGIN
|
||||
ASSERT(toolbar.cnt < max);
|
||||
button.btn := btn;
|
||||
button.icon := icon;
|
||||
button.x := toolbar.width;
|
||||
button.x := toolbar.width + toolbar.x;
|
||||
button.text := text;
|
||||
button.enabled := TRUE;
|
||||
toolbar.buttons[toolbar.cnt] := button;
|
||||
@ -143,8 +160,7 @@ BEGIN
|
||||
toolbar.x := x;
|
||||
toolbar.y := y;
|
||||
toolbar.cnt := 0;
|
||||
toolbar.width := x;
|
||||
Icons.get(toolbar.icons, toolbar.grayIcons)
|
||||
toolbar.width := 0
|
||||
END create;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user