Subversion Repositories Kolibri OS

Rev

Rev 9050 | Rev 9073 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8728 leency 1
(*
2
    Copyright 2021 Anton Krotov
3
 
4
    This file is part of CEdit.
5
 
6
    CEdit is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    CEdit is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with CEdit. If not, see .
18
*)
19
 
20
MODULE CEdit;
21
 
22
IMPORT
8762 leency 23
    OpenDlg, K := KolibriOS,
8728 leency 24
    U := Utils, Lines, Menu, List,
25
    G := Graph, T := Text, E := Encodings,
26
    CB := Clipboard, Languages,
27
    ChangeLog, Scroll,
9050 leency 28
    RW, Ini, box_lib, Icons, Tabs;
8728 leency 29
 
30
CONST
9060 leency 31
    header = "CEdit (12-jul-2021)";
8728 leency 32
 
8762 leency 33
    ShellFilter = "";
8728 leency 34
    EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI";
35
 
36
    fontWidth = K.fontWidth;
37
    fontHeight = K.fontHeight;
38
    scrollWidth = 22;
39
 
40
    btnClose = 1;
41
    btnNew = 20;
42
    btnOpen = 21;
43
    btnSave = 22;
44
    btnSearch = 23;
45
    btnUndo = 24;
46
    btnRedo = 25;
47
    btnUpper = 26;
48
    btnLower = 27;
49
    btnBuild = 28;
50
    btnRun = 29;
51
    btnUp = 30;
52
    btnDown = 31;
53
    btnLeft = 32;
54
    btnRight = 33;
55
    btnYes = 40;
56
    btnNo = 41;
57
    btnFindEdit = 50;
58
    btnReplaceEdit = 51;
59
    btnGotoEdit = 52;
60
    btnFindNext = 60;
61
    btnReplace = 61;
62
    btnReplaceAll = 62;
63
    btnGoto = 63;
64
    btnCloseFind = 64;
65
 
66
    btnFile = 70;
67
    btnEdit = 71;
68
    btnEncoding = 72;
69
    btnView = 73;
70
    btnSyntax = 74;
71
    btnProgram = 75;
72
    btnTools = 76;
73
 
74
    MainMenuHeight = fontHeight + 7;
75
 
76
    btnHeight = 25;
77
    btnWidth = 75;
78
    btnTop = MainMenuHeight + 3;
79
    toolBtnSize = 24;
80
    toolbarDelim = 7;
8859 leency 81
    iconPad = (toolBtnSize - Icons.SIZE) DIV 2;
8728 leency 82
 
9050 leency 83
    TOP = btnTop + toolBtnSize + 10 + Tabs.tabHeight;
8728 leency 84
    RIGHT = scrollWidth - 2;
8859 leency 85
    BOTTOM = scrollWidth + 18;
8728 leency 86
 
8762 leency 87
    minWinWidth = 635; minWinHeight = 542;
8728 leency 88
 
89
    SEARCH_PADDING = 10;
8859 leency 90
    searchLeft = 0;
8728 leency 91
    EditBox_Width = 180;
92
    EDITBOX_MAXCHARS = 500;
93
 
94
    menuFileX = searchLeft;
95
    menuEditX = menuFileX + 4*fontWidth + 2 + 7;
96
    menuEncodingX = menuEditX + 4*fontWidth + 2 + 7;
97
    menuViewX = menuEncodingX + 8*fontWidth + 2 + 7;
98
    menuSyntaxX = menuViewX + 4*fontWidth + 2 + 7;
99
    menuProgramX = menuSyntaxX + 6*fontWidth + 2 + 7;
100
    menuToolsX = menuProgramX + 7*fontWidth + 2 + 7;
101
 
102
    menuCut = 1;
103
    menuCopy = 2;
104
    menuPaste = 3;
105
    menuDelete = 4;
106
    menuSelectAll = 5;
107
 
108
    menuUndo = 6;
109
    menuRedo = 7;
110
 
111
    menuSearch = 8;
112
    menuGoto = 9;
113
 
114
    menuNew = 10;
115
    menuOpen = 11;
116
    menuSave = 12;
117
    menuSaveAs = 13;
9050 leency 118
    menuSaveAll = 14;
119
    menuFolder = 15;
120
    menuClose = 16;
121
    menuExit = 17;
8728 leency 122
 
123
    menuNumbers = 20;
8772 leency 124
    menuFontSize = 21;
8728 leency 125
    menuColors = 1000;
126
    menuMaxColors = menuColors + Ini.MAX_SECTIONS - 1;
127
 
128
    menuNone = 30;
129
    menuC = 31;
130
    menuFasm = 32;
131
    menuIni = 33;
132
    menuLua = 34;
133
    menuOberon = 35;
134
    menuPascal = 36;
135
 
136
    menuBuild = 50;
137
    menuBuildScript = 51;
138
    menuRun = 52;
139
    menuRunScript = 53;
140
    menuDebug = 54;
141
    menuDebugScript = 55;
142
 
143
    menuUTF8BOM = 60;
144
    menuUTF8 = 61;
145
    menuCP866 = 62;
146
    menuWin1251 = 63;
147
 
148
    menuPipet = 70;
149
    menuSysFunc = 71;
150
 
9050 leency 151
    maxTexts = 32;
8762 leency 152
 
9050 leency 153
 
8728 leency 154
VAR
155
    canvas: G.tCanvas;
8772 leency 156
    font, font1, font2: G.tFont;
9050 leency 157
 
158
    tabs: Tabs.tTabs;
8728 leency 159
    text: T.tText;
9050 leency 160
    texts: ARRAY maxTexts OF T.tText;
161
    textsCount, curText: INTEGER;
162
 
8728 leency 163
    winWidth, winHeight: INTEGER;
164
    shift: SET;
165
    AppPath, runScript, buildScript, debugScript: RW.tFileName;
166
    OD: OpenDlg.Dialog;
167
    confirm, notFound, search, modified: BOOLEAN;
168
 
9050 leency 169
    switch: BOOLEAN;
8728 leency 170
    leftButton, VScroll, HScroll: BOOLEAN;
171
    vScroll, hScroll: Scroll.tScroll;
172
    LEFT: INTEGER;
173
 
174
    FindEdit, ReplaceEdit, GotoEdit: box_lib.edit_box;
175
    CS, WH, BKW: box_lib.checkbox;
176
 
177
    new_searchText, searchText, replaceText, gotoText: T.tString;
178
    cs, whole: BOOLEAN;
179
 
180
    replaced: INTEGER;
181
 
182
    mainTID: INTEGER;
183
 
184
    context, menuFile, menuEdit, menuEncoding, menuView, menuSyntax, menuProgram, menuTools: Menu.tMenu;
185
 
186
    icons: INTEGER;
187
    grayIcons: INTEGER;
188
 
189
    IPC: ARRAY 64 OF INTEGER;
190
 
191
 
192
PROCEDURE WritePos (y: INTEGER);
193
VAR
194
    s1, s2: ARRAY 32 OF WCHAR;
195
    line, col: INTEGER;
196
BEGIN
197
    T.getPos(text, col, line);
198
    U.int2str(line, s1);
199
    U.int2str(col, s2);
200
    U.append(s1, ": ");
201
    U.append(s1, s2);
8762 leency 202
    K.DrawText(LEFT, y, K.textColor, s1)
8728 leency 203
END WritePos;
204
 
205
 
206
PROCEDURE EditBox_Focus (edit: box_lib.edit_box): BOOLEAN;
207
    RETURN 1 IN BITS(edit.flags)
208
END EditBox_Focus;
209
 
210
 
211
PROCEDURE EditBox_SetFocus (edit: box_lib.edit_box; value: BOOLEAN);
212
BEGIN
213
    IF value THEN
214
        edit.flags := ORD(BITS(edit.flags) + {1})
215
    ELSE
216
        edit.flags := ORD(BITS(edit.flags) - {1})
217
    END;
218
    IF search THEN
219
        box_lib.edit_box_draw(edit)
220
    END
221
END EditBox_SetFocus;
222
 
223
 
224
PROCEDURE Rect (left, top, right, bottom, color: INTEGER);
225
BEGIN
226
    K.DrawLine(left, top, right, top, color);
227
    K.DrawLine(left, bottom, right, bottom, color);
228
    K.DrawLine(left, top, left, bottom, color);
229
    K.DrawLine(right, top, right, bottom, color);
230
END Rect;
231
 
232
 
233
PROCEDURE Message (s: ARRAY OF WCHAR);
234
CONST
235
    minWidth = 30;
236
    height = 40;
237
    borderColor = 808080H;
238
VAR
239
    top, left, right, bottom, x, y, width: INTEGER;
240
BEGIN
241
    width := minWidth + LENGTH(s)*fontWidth;
242
    left := (canvas.width - width) DIV 2 + LEFT;
243
    top := (canvas.height - height) DIV 2 + TOP;
244
    bottom := top + height - 1;
245
    right := left + width - 1;
246
    x := minWidth DIV 2 + left;
247
    y := (height - fontHeight) DIV 2 + top;
8762 leency 248
    K.DrawRect(left, top, width, height, K.winColor);
8728 leency 249
    Rect(left, top, right, bottom, borderColor);
8762 leency 250
    K.DrawText(x, y, K.textColor, s);
8728 leency 251
END Message;
252
 
253
 
254
PROCEDURE NotFound;
255
BEGIN
256
    IF notFound THEN
257
        Message("not found");
258
        notFound := FALSE;
259
        EditBox_SetFocus(FindEdit, TRUE);
260
        EditBox_SetFocus(ReplaceEdit, FALSE);
261
        EditBox_SetFocus(GotoEdit, FALSE)
262
    END
263
END NotFound;
264
 
265
 
266
PROCEDURE Replaced;
267
VAR
268
    s, s1: ARRAY 32 OF WCHAR;
269
BEGIN
270
    IF replaced # 0 THEN
271
        s := "replaced: ";
272
        U.int2str(replaced, s1);
273
        U.append(s, s1);
274
        Message(s);
275
        replaced := 0;
276
        EditBox_SetFocus(FindEdit, TRUE);
277
        EditBox_SetFocus(ReplaceEdit, FALSE);
278
        EditBox_SetFocus(GotoEdit, FALSE)
279
    END
280
END Replaced;
281
 
282
 
283
PROCEDURE toolbarIcons;
284
VAR
285
    x, color: INTEGER;
286
BEGIN
287
    x := searchLeft + (toolBtnSize + 5)*2;
288
    IF text.modified THEN
8762 leency 289
        Icons.draw(icons, 5, x + iconPad, btnTop + iconPad)
8728 leency 290
    ELSE
8762 leency 291
        Icons.draw(grayIcons, 5, x + iconPad, btnTop + iconPad)
8728 leency 292
    END;
293
 
294
    IF text.edition # NIL THEN
295
        x := searchLeft + (toolBtnSize + 5)*4 + toolbarDelim*2;
296
        IF ChangeLog.isFirstGuard(text.edition) THEN
8762 leency 297
            Icons.draw(grayIcons, 37, x + iconPad, btnTop + iconPad)
8728 leency 298
        ELSE
8762 leency 299
            Icons.draw(icons, 37, x + iconPad, btnTop + iconPad)
8728 leency 300
        END;
301
 
302
        x := searchLeft + (toolBtnSize + 5)*5 + toolbarDelim*2;
303
        IF ChangeLog.isLastGuard(text.edition) THEN
8762 leency 304
            Icons.draw(grayIcons, 36, x + iconPad, btnTop + iconPad)
8728 leency 305
        ELSE
8762 leency 306
            Icons.draw(icons, 36, x + iconPad, btnTop + iconPad)
8728 leency 307
        END
308
    END;
309
 
310
    IF T.selected(text) THEN
8762 leency 311
        color := K.caseColor
8728 leency 312
    ELSE
8762 leency 313
        color := K.disCaseColor
8728 leency 314
    END;
315
 
316
    x := searchLeft + (toolBtnSize + 5)*6 + toolbarDelim*3;
8762 leency 317
    K.DrawRect(x, btnTop, toolBtnSize, toolBtnSize, K.toolbarColor);
8728 leency 318
    K.DrawText69(x + (toolBtnSize - 12) DIV 2, btnTop + (toolBtnSize - 9) DIV 2 + 2, color, "AB");
319
    INC(x, toolBtnSize + 5);
8762 leency 320
    K.DrawRect(x, btnTop, toolBtnSize, toolBtnSize, K.toolbarColor);
8728 leency 321
    K.DrawText69(x + (toolBtnSize - 12) DIV 2, btnTop + (toolBtnSize - 9) DIV 2 + 2, color, "ab");
322
 
323
    x := searchLeft + (toolBtnSize + 5)*8 + toolbarDelim*4;
324
    IF buildScript # "" THEN
8762 leency 325
        Icons.draw(icons, 54, x + iconPad, btnTop + iconPad)
8728 leency 326
    ELSE
8762 leency 327
        Icons.draw(grayIcons, 54, x + iconPad, btnTop + iconPad)
8728 leency 328
    END;
329
    INC(x, toolBtnSize + 5);
330
    IF runScript # "" THEN
8762 leency 331
        Icons.draw(icons, 53, x + iconPad, btnTop + iconPad)
8728 leency 332
    ELSE
8762 leency 333
        Icons.draw(grayIcons, 53, x + iconPad, btnTop + iconPad)
8728 leency 334
    END
335
END toolbarIcons;
336
 
337
 
338
PROCEDURE WriteModified (x, y: INTEGER);
339
BEGIN
340
    modified := text.modified;
8859 leency 341
    K.DrawRect(x, TOP + canvas.height + scrollWidth - 1, 8*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
8728 leency 342
    IF modified THEN
8762 leency 343
        K.DrawText866(x, y, K.textColor, "modified")
8728 leency 344
    END
345
END WriteModified;
346
 
347
 
9050 leency 348
PROCEDURE DrawState (text: T.tText; width, height: INTEGER);
349
VAR
350
    y: INTEGER;
351
BEGIN
352
    y := (btnHeight - fontHeight) DIV 2 + btnTop;
353
    K.DrawRect(width - 12*fontWidth, y, 12*fontWidth, fontHeight, K.winColor);
354
    CASE text.enc OF
355
    |E.UTF8:    K.DrawText866(width -  5*fontWidth, y, K.textColor, "UTF-8")
356
    |E.UTF8BOM: K.DrawText866(width -  9*fontWidth, y, K.textColor, "UTF-8-BOM")
357
    |E.CP866:   K.DrawText866(width -  5*fontWidth, y, K.textColor, "CP866")
358
    |E.W1251:   K.DrawText866(width - 12*fontWidth, y, K.textColor, "Windows-1251")
359
    END;
360
 
361
    y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
362
    K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth - 1, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
363
    K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName);
364
    WriteModified(width - 8*fontWidth, y)
365
END DrawState;
366
 
367
 
8728 leency 368
PROCEDURE repaint;
369
VAR
370
    width, height, scrollX, scrollY, y: INTEGER;
371
BEGIN
372
    IF text # NIL THEN
373
        IF confirm THEN
374
            K.DeleteButton(btnYes);
375
            K.DeleteButton(btnNo);
376
            confirm := FALSE
377
        END;
9010 leency 378
        IF ~search THEN
379
            T.wordSel(text)
380
        END;
9050 leency 381
        K.ClientSize(width, height);
382
        IF switch THEN
383
            DrawState(text, width, height);
384
            Tabs.draw(tabs);
385
            IF search & T.search(text, searchText, cs, whole) THEN END;
386
            switch := FALSE
387
        END;
8728 leency 388
        T.draw(text);
389
        y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
8762 leency 390
        K.DrawRect(LEFT, TOP + canvas.height + scrollWidth - 1, 16*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
8728 leency 391
        WritePos(y);
392
 
393
        IF modified # text.modified THEN
8859 leency 394
            WriteModified(width - 8*fontWidth, y)
8728 leency 395
        END;
396
 
397
        T.getScroll(text, scrollX, scrollY);
398
        vScroll.value := scrollY; vScroll.maxVal := text.count - 1;
9050 leency 399
        hScroll.value := scrollX; hScroll.maxVal := text.maxLength;
8728 leency 400
        Scroll.draw(vScroll, LEFT + canvas.width - 1, TOP + scrollWidth - 1);
401
        Scroll.draw(hScroll, LEFT + scrollWidth, TOP + canvas.height - 1);
402
 
403
        G.DrawCanvas(canvas, LEFT, TOP);
404
        NotFound;
405
        Replaced;
406
        toolbarIcons
407
    END
408
END repaint;
409
 
410
 
411
PROCEDURE resize;
412
VAR
413
    cliWidth, cliHeight: INTEGER;
414
BEGIN
415
    K.WinSize(winWidth, winHeight);
416
    IF winWidth < minWinWidth THEN
417
        winWidth := minWinWidth
418
    END;
419
    IF winHeight < minWinHeight THEN
420
        winHeight := minWinHeight
421
    END;
422
    K.SetWinSize(winWidth, winHeight);
423
    K.WinSize(winWidth, winHeight);
424
    K.ClientSize(cliWidth, cliHeight);
425
    G.destroy(canvas);
426
    canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 1), cliHeight - (TOP + BOTTOM));
9050 leency 427
    Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, cliWidth - (LEFT + RIGHT + 1), Tabs.tabHeight);
8728 leency 428
    G.SetFont(canvas, font);
429
    T.setCanvas(canvas);
430
    T.resize(canvas.width, canvas.height);
9060 leency 431
    Scroll.resize(vScroll, vScroll.xSize, canvas.height - scrollWidth*2 + 2);
8728 leency 432
    Scroll.resize(hScroll, canvas.width - scrollWidth*2, hScroll.ySize);
433
END resize;
434
 
435
 
436
PROCEDURE SearchPanel (left, top: INTEGER);
437
VAR
438
    y, right, bottom, color: INTEGER;
439
BEGIN
9060 leency 440
    DEC(top, Tabs.tabHeight);
8728 leency 441
    right := left + EditBox_Width + SEARCH_PADDING*2;
442
    bottom := top + 395 + btnHeight + SEARCH_PADDING;
8762 leency 443
    color := K.borderColor;
8728 leency 444
    Rect(left, top, right, bottom, color);
445
    K.CreateButton(btnCloseFind, right - 20, top, 20, 20, 0EF999FH, "");
446
    K.DrawLine(right - 14, top + 5, right - 5, top + 14, 0FFFFFFH);
447
    K.DrawLine(right - 15, top + 5, right - 5, top + 15, 0FFFFFFH);
448
    K.DrawLine(right - 15, top + 6, right - 6, top + 15, 0FFFFFFH);
449
    K.DrawLine(right - 15, top + 14, right - 6, top + 5, 0FFFFFFH);
450
    K.DrawLine(right - 15, top + 15, right - 5, top + 5, 0FFFFFFH);
451
    K.DrawLine(right - 14, top + 15, right - 5, top + 6, 0FFFFFFH);
452
 
453
    INC(top, 15);
454
    INC(left, SEARCH_PADDING);
8762 leency 455
    K.DrawText866(left, top, K.textColor, "find");
456
    K.DrawText866(left, top + 55, K.textColor, "replace with");
8728 leency 457
    K.CreateButton(btnFindEdit + ORD({30}), left, top + 20, EditBox_Width, fontHeight + 5, 0, "");
458
    K.CreateButton(btnReplaceEdit + ORD({30}), left, top + 75, EditBox_Width, fontHeight + 5, 0, "");
8762 leency 459
    K.DrawText866(left, top + 330, K.textColor, "go to line");
8728 leency 460
    K.CreateButton(btnGotoEdit + ORD({30}), left, top + 350, EditBox_Width, fontHeight + 5, 0, "");
461
    BKW.top_s := BKW.top_s MOD 65536 + (top + 110) * 65536;
462
    CS.top_s := CS.top_s MOD 65536 + (top + 140) * 65536;
463
    WH.top_s := WH.top_s MOD 65536 + (top + 170) * 65536;
464
    BKW.left_s := BKW.left_s MOD 65536 + left * 65536;
465
    CS.left_s := CS.left_s MOD 65536 + left * 65536;
466
    WH.left_s := WH.left_s MOD 65536 + left * 65536;
467
    FindEdit.top := top + 20;
468
    ReplaceEdit.top := top + 75;
469
    GotoEdit.top := top + 350;
470
    FindEdit.left := left;
471
    ReplaceEdit.left := left;
472
    GotoEdit.left := left;
473
    box_lib.edit_box_draw(FindEdit);
474
    box_lib.edit_box_draw(ReplaceEdit);
475
    box_lib.edit_box_draw(GotoEdit);
8762 leency 476
    box_lib.check_box_draw2(BKW); K.DrawText866(left + 20, top + 110, K.textColor, "backward");
477
    box_lib.check_box_draw2(CS); K.DrawText866(left + 20, top + 140, K.textColor, "match case");
478
    box_lib.check_box_draw2(WH); K.DrawText866(left + 20, top + 170, K.textColor, "whole word");
8728 leency 479
    y := top + 200;
8762 leency 480
    K.CreateButton(btnFindNext, left, y, btnWidth, btnHeight, K.btnColor, "next"); INC(y, btnHeight + 10);
481
    K.CreateButton(btnReplace, left, y, btnWidth, btnHeight, K.btnColor, "replace"); INC(y, btnHeight + 10);
482
    K.CreateButton(btnReplaceAll, left, y, btnWidth + 5*fontWidth - 2, btnHeight, K.btnColor, "replace all");
483
    K.CreateButton(btnGoto, left, top + 380, btnWidth, btnHeight, K.btnColor, "go");
8728 leency 484
END SearchPanel;
485
 
486
 
487
PROCEDURE draw_window;
488
VAR
9050 leency 489
    width, height, x: INTEGER;
8728 leency 490
 
491
 
492
    PROCEDURE drawToolbarBtn (id, x: INTEGER);
493
    BEGIN
8762 leency 494
        K.DrawRect(x, btnTop, toolBtnSize, toolBtnSize, K.toolbarColor);
495
        K.DrawLine(x, btnTop + toolBtnSize, x + toolBtnSize, btnTop + toolBtnSize, K.shadowColor);
496
        K.DrawLine(x + toolBtnSize, btnTop, x + toolBtnSize, btnTop + toolBtnSize, K.shadowColor);
497
        K.CreateButton(id + ORD({30}), x, btnTop, toolBtnSize, toolBtnSize, K.btnColor, "");
8728 leency 498
    END drawToolbarBtn;
499
 
500
 
501
    PROCEDURE drawMainMenu (menu: Menu.tMenu; x: INTEGER; btn: INTEGER; caption: ARRAY OF WCHAR);
502
    VAR
8772 leency 503
        menuColor, textColor, n: INTEGER;
8728 leency 504
    BEGIN
505
        IF menu.tid # 0 THEN
8772 leency 506
            menuColor := K.textColor;
507
            textColor := K.winColor
8728 leency 508
        ELSE
8772 leency 509
            menuColor := K.winColor;
510
            textColor := K.textColor
8728 leency 511
        END;
512
        n := LENGTH(caption);
513
        K.DrawRect(x, 0, n*fontWidth + 2, MainMenuHeight, menuColor);
8762 leency 514
        K.CreateButton(btn + ORD({30}), x, 0, n*fontWidth + 2, MainMenuHeight, K.btnColor, "");
8772 leency 515
        K.DrawText(x + 1, (MainMenuHeight - fontHeight) DIV 2 + 1, textColor, caption)
8728 leency 516
    END drawMainMenu;
517
 
518
 
519
BEGIN
520
    K.BeginDraw;
8772 leency 521
    K.CreateWindow(30 + K.GetTickCount() MOD 128, 30 + K.GetTickCount() MOD 128, winWidth, winHeight, K.winColor, 73H, 0, 0, header);
8728 leency 522
    IF (text # NIL) & ~K.RolledUp() THEN
523
        confirm := FALSE;
524
        K.ClientSize(width, height);
525
 
8762 leency 526
        K.DrawRect(0, 0, width, TOP, K.winColor);
527
        K.DrawRect(0, 0, LEFT, height, K.winColor);
528
        K.DrawRect(LEFT + canvas.width - 1, TOP + canvas.height - 1, scrollWidth, scrollWidth, K.winColor);
8728 leency 529
 
530
        drawMainMenu(menuFile, menuFileX, btnFile, "file");
531
        drawMainMenu(menuEdit, menuEditX, btnEdit, "edit");
532
        drawMainMenu(menuEncoding, menuEncodingX, btnEncoding, "encoding");
533
        drawMainMenu(menuView, menuViewX, btnView, "view");
534
        drawMainMenu(menuSyntax, menuSyntaxX, btnSyntax, "syntax");
535
        drawMainMenu(menuProgram, menuProgramX, btnProgram, "program");
536
        drawMainMenu(menuTools, menuToolsX, btnTools, "tools");
537
 
538
        x := searchLeft;
539
 
540
        drawToolbarBtn(btnNew, x);
8762 leency 541
        Icons.draw(icons, 2, x + iconPad, btnTop + iconPad);
8728 leency 542
        INC(x, toolBtnSize + 5);
543
 
544
        drawToolbarBtn(btnOpen, x);
8762 leency 545
        Icons.draw(icons, 0, x + iconPad, btnTop + iconPad);
8728 leency 546
        INC(x, toolBtnSize + 5);
547
 
548
        drawToolbarBtn(btnSave, x);
549
        INC(x, toolBtnSize + 5 + toolbarDelim);
550
 
551
        drawToolbarBtn(btnSearch, x);
8762 leency 552
        Icons.draw(icons, 49, x + iconPad, btnTop + iconPad);
8728 leency 553
        INC(x, toolBtnSize + 5 + toolbarDelim);
554
 
555
        drawToolbarBtn(btnUndo, x);
556
        INC(x, toolBtnSize + 5);
557
 
558
        drawToolbarBtn(btnRedo, x);
559
        INC(x, toolBtnSize + 5 + toolbarDelim);
560
 
561
        drawToolbarBtn(btnUpper, x);
562
        INC(x, toolBtnSize + 5);
563
 
564
        drawToolbarBtn(btnLower, x);
565
        INC(x, toolBtnSize + 5 + toolbarDelim);
566
 
567
        drawToolbarBtn(btnBuild, x);
568
        INC(x, toolBtnSize + 5);
569
 
570
        drawToolbarBtn(btnRun, x);
571
        INC(x, toolBtnSize + 5);
572
 
8859 leency 573
        toolbarIcons;
574
 
9060 leency 575
        K.CreateButton(btnUp, LEFT + canvas.width - 1, TOP - 1, scrollWidth - 1, scrollWidth, K.btnColor, 0X);
8762 leency 576
        K.DrawText69(LEFT + canvas.width - 1 + (scrollWidth - 6) DIV 2, TOP + (scrollWidth - 9) DIV 2, K.btnTextColor, 18X);
577
        K.CreateButton(btnDown, LEFT + canvas.width - 1, TOP + canvas.height - scrollWidth - 1, scrollWidth - 1, scrollWidth, K.btnColor, 0X);
578
        K.DrawText69(LEFT + canvas.width - 1 + (scrollWidth - 6) DIV 2, TOP + canvas.height - scrollWidth + (scrollWidth - 9) DIV 2, K.btnTextColor, 19X);
8728 leency 579
 
8762 leency 580
        K.CreateButton(btnLeft, LEFT, TOP + canvas.height - 1, scrollWidth, scrollWidth - 1, K.btnColor, 0X);
581
        K.DrawText69(LEFT + (scrollWidth - 6) DIV 2, TOP + canvas.height - 1 + (scrollWidth - 9) DIV 2 + 1, K.btnTextColor, 1BX);
582
        K.CreateButton(btnRight, LEFT + canvas.width - scrollWidth - 1, TOP + canvas.height - 1, scrollWidth, scrollWidth - 1, K.btnColor, 0X);
583
        K.DrawText69(LEFT + canvas.width - scrollWidth - 1 + (scrollWidth - 6) DIV 2, TOP + canvas.height - 1 + (scrollWidth - 9) DIV 2 + 1, K.btnTextColor, 1AX);
8728 leency 584
 
9060 leency 585
        K.PutPixel(LEFT + canvas.width + scrollWidth - 2, TOP - 1, K.winColor);
8762 leency 586
        K.PutPixel(LEFT, TOP + canvas.height + scrollWidth - 2, K.winColor);
587
 
9050 leency 588
        DrawState(text, width, height);
8728 leency 589
        IF search THEN
590
            SearchPanel(searchLeft, TOP)
591
        END;
9050 leency 592
        Tabs.draw(tabs);
8728 leency 593
        repaint
594
    END;
595
    K.EndDraw
596
END draw_window;
597
 
598
 
599
PROCEDURE mouse (VAR x, y: INTEGER);
600
VAR
601
    mouseX, mouseY,
602
    cliX, cliY,
603
    winX, winY: INTEGER;
604
BEGIN
605
    K.MousePos(mouseX, mouseY);
606
    K.WinPos(winX, winY);
607
    K.ClientPos(cliX, cliY);
608
    x := mouseX - winX - cliX - LEFT;
609
    y := mouseY - winY - cliY - TOP;
610
END mouse;
611
 
612
 
613
PROCEDURE getKBState;
614
VAR
615
    kbState: SET;
616
BEGIN
617
    kbState := K.GetControlKeys();
618
    IF {0, 1} * kbState # {} THEN
619
        INCL(shift, T.SHIFT)
620
    ELSE
621
        EXCL(shift, T.SHIFT)
622
    END;
623
 
624
    IF {2, 3} * kbState # {} THEN
625
        INCL(shift, T.CTRL)
626
    ELSE
627
        EXCL(shift, T.CTRL)
628
    END
629
END getKBState;
630
 
631
 
632
PROCEDURE OpenFile (VAR FileName: RW.tFileName; filter: ARRAY OF CHAR);
633
BEGIN
634
    OpenDlg.SetFilter(OD, filter);
635
    OpenDlg.Show(OD, 500, 400);
636
    WHILE OD.status = 2 DO
637
        K.Pause(30)
638
    END;
639
    IF OD.status = 1 THEN
640
        COPY(OD.FilePath, FileName)
641
    ELSE
642
        FileName := ""
643
    END
644
END OpenFile;
645
 
646
 
647
PROCEDURE error (s: RW.tFileName);
648
BEGIN
649
    K.Run("/rd/1/@notify", s)
650
END error;
651
 
652
 
9050 leency 653
PROCEDURE saveError (name: RW.tFileName);
8728 leency 654
VAR
9050 leency 655
    s: RW.tFileName;
656
BEGIN
657
    s := "'cedit: error saving file ";
658
    U.append8(s, name);
659
    U.append8(s, "' -E");
660
    error(s)
661
END saveError;
662
 
663
 
664
PROCEDURE saveAs (text: T.tText);
665
VAR
666
    fileName, name: RW.tFileName;
8728 leency 667
    ext: ARRAY 8 OF CHAR;
668
BEGIN
669
    OD._type := OpenDlg.tsave;
670
    U.getFileName(text.fileName, OD.FileName, U.SLASH);
671
    IF OD.FileName = "" THEN
672
        OD.FileName := "NewFile.";
673
        CASE text.lang OF
674
        |Languages.langNone:   ext := "txt"
675
        |Languages.langC:      ext := "c"
676
        |Languages.langFasm:   ext := "asm"
677
        |Languages.langIni:    ext := "ini"
678
        |Languages.langLua:    ext := "lua"
679
        |Languages.langOberon: ext := "ob07"
680
        |Languages.langPascal: ext := "pas"
681
        END;
682
        U.append8(OD.FileName, ext)
683
    END;
684
    OpenFile(fileName, EditFilter);
685
    IF fileName # "" THEN
686
        IF T.save(text, fileName, text.enc, RW.EOL_CRLF) THEN
9050 leency 687
            T.setName(text, fileName);
688
            U.getFileName(fileName, name, U.SLASH);
689
            Tabs.rename(tabs, curText, name)
8728 leency 690
        ELSE
9050 leency 691
            saveError(fileName)
8728 leency 692
        END
693
    END
694
END saveAs;
695
 
696
 
9050 leency 697
PROCEDURE getIdx (text: T.tText): INTEGER;
698
VAR
699
    i: INTEGER;
8728 leency 700
BEGIN
9050 leency 701
    i := 0;
702
    WHILE texts[i] # text DO
703
        INC(i)
704
    END
705
    RETURN i
706
END getIdx;
707
 
708
 
709
PROCEDURE Switch (txt: T.tText);
710
BEGIN
711
    Tabs.switch(tabs, curText);
712
    text := txt;
713
    T.switch(txt);
714
    switch := TRUE
715
END Switch;
716
 
717
 
718
PROCEDURE save (text: T.tText);
719
BEGIN
8728 leency 720
    IF text.modified THEN
721
        IF text.fileName # "" THEN
722
            IF ~T.save(text, text.fileName, text.enc, RW.EOL_CRLF) THEN
9050 leency 723
                saveError(text.fileName)
8728 leency 724
            END
725
        ELSE
9050 leency 726
            curText := getIdx(text);
727
            Switch(text);
728
            saveAs(text)
8728 leency 729
        END
730
    END
731
END save;
732
 
733
 
9050 leency 734
PROCEDURE saveAll;
735
VAR
736
    i: INTEGER;
8728 leency 737
BEGIN
9050 leency 738
    i := textsCount - 1;
739
    WHILE i >= 0 DO
740
        IF texts[i].modified THEN
741
            save(texts[i])
742
        END;
743
        DEC(i)
744
    END;
745
END saveAll;
8728 leency 746
 
747
 
9050 leency 748
PROCEDURE insert (pos: INTEGER; txt: T.tText);
8728 leency 749
VAR
9050 leency 750
    i: INTEGER;
751
    name: RW.tFileName;
8728 leency 752
BEGIN
9050 leency 753
    FOR i := textsCount - 1 TO pos BY -1 DO
754
        texts[i + 1] := texts[i]
755
    END;
756
    texts[pos] := txt;
757
    INC(textsCount);
758
    curText := pos;
759
    IF txt.fileName = "" THEN
760
        name := "new"
761
    ELSE
762
        U.getFileName(txt.fileName, name, U.SLASH)
763
    END;
764
    Tabs.add(tabs, name);
765
    Switch(txt)
766
END insert;
8728 leency 767
 
768
 
769
PROCEDURE Confirm;
770
CONST
771
    width  = btnWidth*2 + 30;
772
    height = btnHeight*2 + 20;
773
    lineColor = 808080H;
774
VAR
775
    left, top, right, bottom: INTEGER;
776
BEGIN
777
    draw_window;
778
    confirm := TRUE;
779
    left := (canvas.width - width) DIV 2 + LEFT;
780
    top := (canvas.height - height) DIV 2 + TOP;
781
    right := left + width - 1;
782
    bottom := top + height - 1;
8762 leency 783
    K.DrawRect(left, top, width, height, K.winColor);
8728 leency 784
    Rect(left, top, right, bottom, lineColor);
8762 leency 785
    K.DrawText866(left + (width - 10*fontWidth) DIV 2, top + 10, K.textColor, "save file?");
786
    K.CreateButton(btnYes, left + 10, top + 35, btnWidth, btnHeight, K.btnColor, "yes");
787
    K.CreateButton(btnNo, left + 20 + btnWidth, top + 35, btnWidth, btnHeight, K.btnColor, "no");
8728 leency 788
END Confirm;
789
 
790
 
9060 leency 791
PROCEDURE closeFile (conf: BOOLEAN; n: INTEGER);
9050 leency 792
VAR
793
    i: INTEGER;
794
BEGIN
795
    IF text.modified & conf THEN
796
        Confirm
797
    ELSE
9060 leency 798
        Tabs.delete(tabs, n);
799
        FOR i := n + 1 TO textsCount - 1 DO
9050 leency 800
            texts[i - 1] := texts[i]
801
        END;
802
        DEC(textsCount);
9060 leency 803
        IF (curText = textsCount) OR (n < curText) THEN
9050 leency 804
            DEC(curText)
805
        END;
806
        IF curText >= 0 THEN
807
            Switch(texts[curText])
808
        ELSE
809
            K.Exit
810
        END;
811
        draw_window
812
    END
813
END closeFile;
814
 
815
 
816
PROCEDURE NewFile;
817
VAR
818
    nov: T.tText;
819
BEGIN
820
    IF textsCount < maxTexts THEN
821
        nov := T.New();
822
        T.SetPos(nov, 0, 0);
823
        insert(textsCount, nov)
824
    ELSE
825
        error("'cedit: too many files' -E")
826
    END
827
END NewFile;
828
 
829
 
830
PROCEDURE getFileNum (fileName: RW.tFileName): INTEGER;
831
VAR
832
    i: INTEGER;
833
 
834
    PROCEDURE nameEq (name1, name2: RW.tFileName): BOOLEAN;
835
    VAR
836
        n1, n2: RW.tFileName;
837
    BEGIN
838
        n1 := name1;
839
        n2 := name2;
840
        U.upcase(n1);
841
        U.upcase(n2)
842
        RETURN n1 = n2
843
    END nameEq;
844
 
845
BEGIN
846
    i := 0;
847
    WHILE (i < textsCount) & ~nameEq(texts[i].fileName, fileName) DO
848
        INC(i)
849
    END;
850
    IF i = textsCount THEN
851
        i := -1
852
    END
853
    RETURN i
854
END getFileNum;
855
 
856
 
857
PROCEDURE open;
858
VAR
859
    fileName: RW.tFileName;
860
    nov: T.tText;
861
    err, n: INTEGER;
862
BEGIN
863
    IF textsCount < maxTexts THEN
864
        OD._type := OpenDlg.topen;
865
        OpenFile(fileName, EditFilter);
866
        IF fileName # "" THEN
867
            n := getFileNum(fileName);
868
            IF n = -1 THEN
869
                nov := T.open(fileName, err);
870
                IF nov = NIL THEN
871
                    error("'cedit: error opening file' -E")
872
                ELSE
873
                    insert(textsCount, nov);
874
                    T.SetPos(nov, 0, 0)
875
                END
876
            ELSE
877
                curText := n;
878
                Tabs.switch(tabs, n);
879
                Switch(texts[n]);
880
                draw_window
881
            END
882
        END
883
    ELSE
884
        error("'cedit: too many files' -E")
885
    END
886
END open;
887
 
888
 
8728 leency 889
PROCEDURE createEdit (left, top: INTEGER): box_lib.edit_box;
890
VAR
891
    edit, EditBox0: box_lib.edit_box;
892
BEGIN
893
    NEW(EditBox0);
894
    EditBox0.text := K.malloc(EDITBOX_MAXCHARS + 2);
895
    ASSERT(EditBox0.text # 0);
896
    edit := box_lib.kolibri_new_edit_box(left, top, EditBox_Width, EDITBOX_MAXCHARS, EditBox0);
897
    edit.flags := 4002H;
898
    edit.text_color := 30000000H;
899
    EditBox_SetFocus(edit, FALSE)
900
    RETURN edit
901
END createEdit;
902
 
903
 
904
PROCEDURE createSearchForm;
905
BEGIN
906
    FindEdit := createEdit(searchLeft, TOP + 20);
907
    ReplaceEdit := createEdit(searchLeft, TOP + 20 + 55);
908
    GotoEdit := createEdit(searchLeft, TOP + 20 + 330);
909
    GotoEdit.flags := ORD(BITS(GotoEdit.flags) + BITS(8000H));
910
    BKW := box_lib.kolibri_new_check_box(searchLeft, TOP + 90 + 20, 16, 16, "", 8*fontWidth + 4);
911
    CS := box_lib.kolibri_new_check_box(searchLeft, TOP + 120 + 20, 16, 16, "", 10*fontWidth + 4);
912
    WH := box_lib.kolibri_new_check_box(searchLeft, TOP + 150 + 20, 16, 16, "", 10*fontWidth + 4);
913
END createSearchForm;
914
 
915
 
916
PROCEDURE EditBox_GetValue (edit: box_lib.edit_box; VAR s: ARRAY OF WCHAR);
917
VAR
918
    str: ARRAY EDITBOX_MAXCHARS + 1 OF CHAR;
919
    i: INTEGER;
920
BEGIN
921
    box_lib.edit_box_get_value(edit, str);
922
    i := 0;
923
    WHILE str[i] # 0X DO
924
        s[i] := WCHR(E.cp866[ORD(str[i])]);
925
        INC(i)
926
    END;
927
    s[i] := 0X
928
END EditBox_GetValue;
929
 
930
 
931
PROCEDURE Search;
932
BEGIN
933
    search := ~search;
934
    IF search THEN
8859 leency 935
        LEFT := searchLeft + EditBox_Width + SEARCH_PADDING*2 + 5;
8728 leency 936
        IF T.search(text, searchText, cs, whole) THEN END
937
    ELSE
938
        LEFT := searchLeft;
939
        IF T.search(text, "", FALSE, FALSE) THEN END
940
    END;
941
    EditBox_SetFocus(FindEdit, search);
942
    EditBox_SetFocus(ReplaceEdit, FALSE);
943
    EditBox_SetFocus(GotoEdit, FALSE);
944
    resize;
945
    draw_window
946
END Search;
947
 
948
 
949
PROCEDURE click (x, y: INTEGER): INTEGER;
950
VAR
951
    scrollX, scrollY: INTEGER;
952
BEGIN
953
    IF (0 <= x) & (x < canvas.width) & (0 <= y) & (y < canvas.height) THEN
954
        leftButton := TRUE;
955
        EditBox_SetFocus(FindEdit, FALSE);
956
        EditBox_SetFocus(ReplaceEdit, FALSE);
957
        EditBox_SetFocus(GotoEdit, FALSE);
958
        IF ~(T.SHIFT IN shift) THEN
959
            T.resetSelect(text)
960
        END;
961
        T.mouse(text, x, y);
962
        repaint
963
    ELSIF (canvas.width < x) & (x < canvas.width + scrollWidth) & (scrollWidth < y) & (y < canvas.height - scrollWidth) THEN
964
        VScroll := TRUE;
965
        DEC(x, canvas.width);
966
        DEC(y, scrollWidth);
967
        Scroll.mouse(vScroll, x, y);
968
        T.getScroll(text, scrollX, scrollY);
969
        T.scroll(text, 0, vScroll.value - scrollY);
970
        repaint
971
    ELSIF (scrollWidth < x) & (x < canvas.width - scrollWidth) & (canvas.height < y) & (y < canvas.height + scrollWidth) THEN
972
        HScroll := TRUE;
973
        DEC(x, scrollWidth);
974
        DEC(y, canvas.height);
975
        Scroll.mouse(hScroll, x, y);
976
        T.getScroll(text, scrollX, scrollY);
977
        T.scroll(text, hScroll.value - scrollX, 0);
978
        repaint
979
    END
980
    RETURN K.GetTickCount()
981
END click;
982
 
983
 
984
PROCEDURE LeftButtonUp;
985
BEGIN
986
    leftButton := FALSE;
987
    VScroll := FALSE;
988
    HScroll := FALSE;
989
    Scroll.MouseUp(vScroll);
990
    Scroll.MouseUp(hScroll);
991
END LeftButtonUp;
992
 
993
 
994
PROCEDURE close;
9050 leency 995
VAR
996
    cont: BOOLEAN;
8728 leency 997
BEGIN
9050 leency 998
    cont := TRUE;
999
    WHILE (textsCount > 0) & cont DO
1000
        IF text.modified THEN
1001
            Confirm;
1002
            cont := FALSE
1003
        ELSE
9060 leency 1004
            closeFile(FALSE, curText);
9050 leency 1005
            repaint
1006
        END
8728 leency 1007
    END
1008
END close;
1009
 
1010
 
1011
PROCEDURE MenuItemClick (menu: Menu.tMenu; id: INTEGER);
1012
BEGIN
1013
    K.SendIPC(mainTID, id)
1014
END MenuItemClick;
1015
 
1016
 
1017
PROCEDURE goto;
1018
VAR
1019
    gotoVal: INTEGER;
1020
BEGIN
1021
    EditBox_GetValue(GotoEdit, gotoText);
1022
    IF U.str2int(gotoText, gotoVal) & T.goto(text, gotoVal) THEN END
1023
END goto;
1024
 
1025
 
1026
PROCEDURE Script (script: ARRAY OF CHAR);
1027
BEGIN
1028
    IF script # "" THEN
1029
        K.Run("/rd/1/@open", script)
1030
    END
1031
END Script;
1032
 
1033
 
1034
PROCEDURE receiveIPC;
1035
BEGIN
1036
    IF IPC[0] # Menu.lastTID THEN
1037
        IPC[2] := 0
1038
    END;
1039
    CASE IPC[2] OF
1040
    |0:
1041
    |menuCut:       T.key(text, ORD("X"), {T.CTRL})
1042
    |menuCopy:      T.key(text, ORD("C"), {T.CTRL})
1043
    |menuPaste:     T.key(text, ORD("V"), {T.CTRL})
1044
    |menuDelete:    T.key(text, 46, {})
1045
    |menuSelectAll: T.key(text, ORD("A"), {T.CTRL})
1046
 
1047
    |menuNew:
9050 leency 1048
        NewFile
8728 leency 1049
    |menuOpen:
1050
        open
1051
    |menuSave:
9050 leency 1052
        save(text);
8728 leency 1053
        repaint
1054
    |menuSaveAs:
9050 leency 1055
        saveAs(text);
8728 leency 1056
        repaint
9050 leency 1057
    |menuSaveAll:
1058
        saveAll;
1059
        repaint
1060
    |menuClose:
9060 leency 1061
        closeFile(TRUE, curText)
8728 leency 1062
    |menuFolder:
1063
        K.Run("/rd/1/File Managers/Eolite", text.fileName)
1064
    |menuExit:
1065
        close
1066
    |menuUndo:
1067
        T.undo(text);
1068
        repaint
1069
    |menuRedo:
1070
        T.redo(text);
1071
        repaint
1072
    |menuSearch:
1073
        IF ~search THEN
1074
            Search
1075
        END;
1076
        EditBox_SetFocus(FindEdit, TRUE);
1077
        EditBox_SetFocus(ReplaceEdit, FALSE);
1078
        EditBox_SetFocus(GotoEdit, FALSE)
1079
    |menuGoto:
1080
        IF ~search THEN
1081
            Search
1082
        END;
1083
        EditBox_SetFocus(GotoEdit, TRUE);
1084
        EditBox_SetFocus(FindEdit, FALSE);
1085
        EditBox_SetFocus(ReplaceEdit, FALSE)
1086
    |menuNumbers:
1087
        T.toggleNumbers(text)
8772 leency 1088
    |menuFontSize:
1089
        IF font = font1 THEN
1090
            font := font2
1091
        ELSE
1092
            font := font1
1093
        END;
1094
        resize
8728 leency 1095
    |menuNone:
1096
        T.setLang(text, Languages.langNone)
1097
    |menuC:
1098
        T.setLang(text, Languages.langC)
1099
    |menuFasm:
1100
        T.setLang(text, Languages.langFasm)
1101
    |menuIni:
1102
        T.setLang(text, Languages.langIni)
1103
    |menuLua:
1104
        T.setLang(text, Languages.langLua)
1105
    |menuOberon:
1106
        T.setLang(text, Languages.langOberon)
1107
    |menuPascal:
1108
        T.setLang(text, Languages.langPascal)
1109
    |menuBuild:
1110
        Script(buildScript)
1111
    |menuBuildScript:
1112
        OpenFile(buildScript, ShellFilter)
1113
    |menuRun:
1114
        Script(runScript)
1115
    |menuRunScript:
1116
        OpenFile(runScript, ShellFilter)
1117
    |menuDebug:
1118
        Script(debugScript)
1119
    |menuDebugScript:
1120
        OpenFile(debugScript, ShellFilter)
1121
    |menuUTF8BOM:
1122
        text.enc := E.UTF8BOM
1123
    |menuUTF8:
1124
        text.enc := E.UTF8
1125
    |menuCP866:
1126
        text.enc := E.CP866
1127
    |menuWin1251:
1128
        text.enc := E.W1251
1129
    |menuPipet:
1130
        K.Run("/rd/1/develop/pipet", "")
1131
    |menuSysFunc:
1132
        K.Run("/rd/1/docpack", "f")
1133
    |menuColors..menuMaxColors:
1134
        Ini.selectSection(IPC[2] - menuColors)
1135
    END;
1136
    IPC[0] := 0;
1137
    IPC[1] := 0
1138
END receiveIPC;
1139
 
1140
 
1141
PROCEDURE MenuKeyDown (menu: Menu.tMenu; key: INTEGER): BOOLEAN;
1142
VAR
1143
    menuItem: INTEGER;
1144
BEGIN
1145
    menuItem := -1;
1146
    getKBState;
1147
    IF (T.CTRL IN shift) THEN
1148
        CASE key DIV 65536 OF
9060 leency 1149
        |17: menuItem := menuClose
8728 leency 1150
        |21: menuItem := menuRedo
1151
        |30: menuItem := menuSelectAll
1152
        |33: menuItem := menuSearch
1153
        |34: menuItem := menuGoto
1154
        |44: menuItem := menuUndo
1155
        |45: menuItem := menuCut
1156
        |46: menuItem := menuCopy
1157
        |47: menuItem := menuPaste
1158
        |24: menuItem := menuOpen
1159
        |31: menuItem := menuSave
1160
        |49: menuItem := menuNew
1161
        |67: menuItem := menuBuild
1162
        ELSE
1163
        END
1164
    ELSE
1165
        IF key DIV 65536 = 83 THEN
1166
            menuItem := menuDelete
1167
        ELSIF key DIV 65536 = 67 THEN
1168
            menuItem := menuRun
1169
        END
1170
    END;
1171
    IF menuItem # -1 THEN
1172
        IF Menu.isEnabled(menu, menuItem) THEN
1173
            MenuItemClick(menu, menuItem)
1174
        ELSE
1175
            menuItem := -1
1176
        END
1177
    END
1178
    RETURN menuItem # -1
1179
END MenuKeyDown;
1180
 
1181
 
1182
PROCEDURE CreateContextMenu (): Menu.tMenu;
1183
VAR
1184
    menu: List.tList;
1185
BEGIN
1186
    menu := List.create(NIL);
1187
    Menu.AddMenuItem(menu, menuUndo,      "undo         ctrl-Z");
1188
    Menu.AddMenuItem(menu, menuRedo,      "redo         ctrl-Y");
1189
    Menu.delimiter(menu);
1190
    Menu.AddMenuItem(menu, menuCut,       "cut          ctrl-X");
1191
    Menu.AddMenuItem(menu, menuCopy,      "copy         ctrl-C");
1192
    Menu.AddMenuItem(menu, menuPaste,     "paste        ctrl-V");
1193
    Menu.AddMenuItem(menu, menuDelete,    "delete");
1194
    Menu.delimiter(menu);
1195
    Menu.AddMenuItem(menu, menuSelectAll, "select all   ctrl-A");
1196
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1197
END CreateContextMenu;
1198
 
1199
 
1200
PROCEDURE CreateMenuFile (): Menu.tMenu;
1201
VAR
1202
    menu: List.tList;
1203
BEGIN
1204
    menu := List.create(NIL);
9050 leency 1205
    Menu.AddMenuItem(menu, menuNew,     "new         ctrl-N");
1206
    Menu.AddMenuItem(menu, menuOpen,    "open        ctrl-O");
1207
    Menu.AddMenuItem(menu, menuSave,    "save        ctrl-S");
1208
    Menu.AddMenuItem(menu, menuSaveAs,  "save as");
1209
    Menu.AddMenuItem(menu, menuSaveAll, "save all");
1210
    Menu.AddMenuItem(menu, menuFolder,  "folder");
8728 leency 1211
    Menu.delimiter(menu);
9060 leency 1212
    Menu.AddMenuItem(menu, menuClose,   "close       ctrl-W");
9050 leency 1213
    Menu.delimiter(menu);
1214
    Menu.AddMenuItem(menu, menuExit,    "exit");
8728 leency 1215
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1216
END CreateMenuFile;
1217
 
1218
 
1219
PROCEDURE CreateMenuEdit (): Menu.tMenu;
1220
VAR
1221
    menu: List.tList;
1222
BEGIN
1223
    menu := List.create(NIL);
1224
    Menu.AddMenuItem(menu, menuUndo,      "undo          ctrl-Z");
1225
    Menu.AddMenuItem(menu, menuRedo,      "redo          ctrl-Y");
1226
    Menu.delimiter(menu);
1227
    Menu.AddMenuItem(menu, menuSearch,    "search        ctrl-F");
1228
    Menu.AddMenuItem(menu, menuGoto,      "go to line    ctrl-G");
1229
    Menu.delimiter(menu);
1230
    Menu.AddMenuItem(menu, menuCut,       "cut           ctrl-X");
1231
    Menu.AddMenuItem(menu, menuCopy,      "copy          ctrl-C");
1232
    Menu.AddMenuItem(menu, menuPaste,     "paste         ctrl-V");
1233
    Menu.AddMenuItem(menu, menuDelete,    "delete");
1234
    Menu.delimiter(menu);
1235
    Menu.AddMenuItem(menu, menuSelectAll, "select all    ctrl-A");
1236
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1237
END CreateMenuEdit;
1238
 
1239
 
1240
PROCEDURE CreateMenuEncoding (): Menu.tMenu;
1241
VAR
1242
    menu: List.tList;
1243
BEGIN
1244
    menu := List.create(NIL);
1245
    Menu.AddMenuItem(menu, menuUTF8BOM, "UTF-8-BOM");
1246
    Menu.AddMenuItem(menu, menuUTF8,    "UTF-8");
1247
    Menu.AddMenuItem(menu, menuCP866,   "CP866");
1248
    Menu.AddMenuItem(menu, menuWin1251, "Windows-1251");
1249
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1250
END CreateMenuEncoding;
1251
 
1252
 
1253
PROCEDURE CreateMenuView (): Menu.tMenu;
1254
VAR
1255
    menu: List.tList;
1256
    colors: Ini.tSection;
1257
    idx: INTEGER;
1258
BEGIN
1259
    menu := List.create(NIL);
8762 leency 1260
    Menu.AddMenuItem(menu, menuNumbers, "line numbers");
8772 leency 1261
    Menu.AddMenuItem(menu, menuFontSize, "x2");
8728 leency 1262
    Menu.delimiter(menu);
1263
 
1264
    colors := Ini.sections.first(Ini.tSection);
1265
    idx := menuColors;
1266
    WHILE colors # NIL DO
1267
        Menu.AddMenuItem(menu, idx, colors.name);
1268
        INC(idx);
1269
        colors := colors.next(Ini.tSection)
1270
    END;
1271
 
1272
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1273
END CreateMenuView;
1274
 
1275
 
1276
PROCEDURE CreateMenuSyntax (): Menu.tMenu;
1277
VAR
1278
    menu: List.tList;
1279
BEGIN
1280
    menu := List.create(NIL);
1281
    Menu.AddMenuItem(menu, menuC,      "C");
1282
    Menu.AddMenuItem(menu, menuFasm,   "Fasm");
1283
    Menu.AddMenuItem(menu, menuIni,    "Ini");
1284
    Menu.AddMenuItem(menu, menuLua,    "Lua");
1285
    Menu.AddMenuItem(menu, menuOberon, "Oberon");
1286
    Menu.AddMenuItem(menu, menuPascal, "Pascal");
1287
    Menu.delimiter(menu);
1288
    Menu.AddMenuItem(menu, menuNone,   "none");
1289
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1290
END CreateMenuSyntax;
1291
 
1292
 
1293
PROCEDURE CreateMenuProgram (): Menu.tMenu;
1294
VAR
1295
    menu: List.tList;
1296
BEGIN
1297
    menu := List.create(NIL);
1298
    Menu.AddMenuItem(menu, menuBuild,       "build    ctrl+F9");
1299
    Menu.AddMenuItem(menu, menuBuildScript, "script");
1300
    Menu.delimiter(menu);
1301
    Menu.AddMenuItem(menu, menuRun,         "run           F9");
1302
    Menu.AddMenuItem(menu, menuRunScript,   "script");
1303
    Menu.delimiter(menu);
1304
    Menu.AddMenuItem(menu, menuDebug,       "debug");
1305
    Menu.AddMenuItem(menu, menuDebugScript, "script");
1306
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1307
END CreateMenuProgram;
1308
 
1309
 
1310
PROCEDURE CreateMenuTools (): Menu.tMenu;
1311
VAR
1312
    menu: List.tList;
1313
BEGIN
1314
    menu := List.create(NIL);
1315
    Menu.AddMenuItem(menu, menuPipet,   "pipet");
1316
    Menu.AddMenuItem(menu, menuSysFunc, "system functions");
1317
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1318
END CreateMenuTools;
1319
 
1320
 
1321
PROCEDURE CanvasToScreen (VAR x, y: INTEGER);
1322
VAR
1323
    cliX, cliY,
1324
    winX, winY: INTEGER;
1325
BEGIN
1326
    K.WinPos(winX, winY);
1327
    K.ClientPos(cliX, cliY);
1328
    x := x + winX + cliX + LEFT;
1329
    y := y + winY + cliY + TOP;
1330
END CanvasToScreen;
1331
 
1332
 
1333
PROCEDURE ShowMenu (menu: Menu.tMenu);
1334
VAR
1335
    winX, winY, cliX, cliY, x, y, i: INTEGER;
1336
    selected: BOOLEAN;
1337
BEGIN
1338
    IF menu # context THEN
1339
        K.WinPos(winX, winY);
1340
        K.ClientPos(cliX, cliY);
1341
        x := winX + cliX;
1342
        y := MainMenuHeight + winY + cliY
1343
    ELSE
1344
        mouse(x, y);
1345
        IF ~((0 <= x) & (x < canvas.width) & (0 <= y) & (y < canvas.height)) THEN
1346
            menu := NIL
1347
        END
1348
    END;
1349
 
1350
    IF menu = menuFile THEN
1351
        Menu.setEnabled(menu, menuSave, text.modified);
1352
        Menu.setEnabled(menu, menuFolder, text.fileName # "");
9050 leency 1353
        i := 0;
1354
        WHILE (i < textsCount) & ~texts[i].modified DO
1355
            INC(i)
1356
        END;
1357
        Menu.setEnabled(menu, menuSaveAll, i < textsCount);
8728 leency 1358
        INC(x, menuFileX)
1359
    ELSIF (menu = menuEdit) OR (menu = context) THEN
1360
        Menu.setEnabled(menu, menuUndo, ~ChangeLog.isFirstGuard(text.edition));
1361
        Menu.setEnabled(menu, menuRedo, ~ChangeLog.isLastGuard(text.edition));
1362
        selected := T.selected(text);
1363
        Menu.setEnabled(menu, menuCut, selected);
1364
        Menu.setEnabled(menu, menuCopy, selected);
1365
        Menu.setEnabled(menu, menuDelete, selected);
1366
        Menu.setEnabled(menu, menuPaste, CB.available());
1367
        IF menu = menuEdit THEN
1368
            INC(x, menuEditX)
1369
        ELSE
1370
            IF y + menu.height >= canvas.height THEN
1371
                DEC(y, menu.height)
1372
            END;
1373
            IF x + menu.width >= canvas.width THEN
1374
                DEC(x, menu.width)
1375
            END;
1376
            CanvasToScreen(x, y)
1377
        END
1378
    ELSIF menu = menuEncoding THEN
1379
        Menu.setCheck(menu, menuUTF8BOM, ORD(text.enc = E.UTF8BOM)*2);
1380
        Menu.setCheck(menu, menuUTF8,    ORD(text.enc = E.UTF8)*2);
1381
        Menu.setCheck(menu, menuCP866,   ORD(text.enc = E.CP866)*2);
1382
        Menu.setCheck(menu, menuWin1251, ORD(text.enc = E.W1251)*2);
1383
        INC(x, menuEncodingX)
1384
    ELSIF menu = menuView THEN
8772 leency 1385
        Menu.setCheck(menu, menuNumbers,  ORD(text.numbers));
1386
        Menu.setCheck(menu, menuFontSize, ORD(font = font2));
8728 leency 1387
        FOR i := 0 TO Ini.sections.count - 1 DO
1388
            Menu.setCheck(menu, menuColors + i, ORD(Ini.curSectionNum = i)*2)
1389
        END;
1390
        INC(x, menuViewX)
1391
    ELSIF menu = menuSyntax THEN
1392
        Menu.setCheck(menu, menuNone,   ORD(text.lang = Languages.langNone)*2);
1393
        Menu.setCheck(menu, menuC,      ORD(text.lang = Languages.langC)*2);
1394
        Menu.setCheck(menu, menuFasm,   ORD(text.lang = Languages.langFasm)*2);
1395
        Menu.setCheck(menu, menuIni,    ORD(text.lang = Languages.langIni)*2);
1396
        Menu.setCheck(menu, menuLua,    ORD(text.lang = Languages.langLua)*2);
1397
        Menu.setCheck(menu, menuOberon, ORD(text.lang = Languages.langOberon)*2);
1398
        Menu.setCheck(menu, menuPascal, ORD(text.lang = Languages.langPascal)*2);
1399
        INC(x, menuSyntaxX)
1400
    ELSIF menu = menuProgram THEN
1401
        Menu.setEnabled(menu, menuBuild, buildScript # "");
1402
        Menu.setEnabled(menu, menuDebug, debugScript # "");
1403
        Menu.setEnabled(menu, menuRun, runScript # "");
1404
        INC(x, menuProgramX)
1405
    ELSIF menu = menuTools THEN
1406
        INC(x, menuToolsX)
1407
    END;
1408
 
1409
    IF menu # NIL THEN
1410
        IF Menu.opened(menu) THEN
1411
            Menu.close(menu)
1412
        END;
1413
        Menu.open(menu, x, y)
1414
    END
1415
END ShowMenu;
1416
 
1417
 
1418
PROCEDURE main;
1419
VAR
8772 leency 1420
    width, height, x, y, scrollX, scrollY, i: INTEGER;
9050 leency 1421
    key, btn: INTEGER;
8728 leency 1422
    msState: SET;
1423
    scroll: INTEGER;
1424
    err: INTEGER;
1425
    fileName, filePath: RW.tFileName;
8762 leency 1426
    cliWidth, cliHeight: INTEGER;
9060 leency 1427
    resized, middle: BOOLEAN;
8728 leency 1428
    firstClickX, firstClickY, time: INTEGER;
1429
BEGIN
8762 leency 1430
    K.GetSystemColors;
1431
    Icons.get(icons, grayIcons);
8728 leency 1432
    modified := FALSE;
9050 leency 1433
    switch := FALSE;
1434
    textsCount := 0;
1435
    curText := 0;
8728 leency 1436
    mainTID := K.ThreadID();
1437
    K.SetIPC(IPC);
1438
    U.ptr2str(K.GetName(), AppPath);
1439
    Ini.load(AppPath);
1440
    K.SetEventsMask({0, 1, 2, 5, 6, 31});
1441
    LeftButtonUp;
1442
    resized := FALSE;
1443
    shift := {};
8772 leency 1444
    K.ScreenSize(winWidth, winHeight);
9050 leency 1445
    winWidth := (winWidth*80) DIV 100 - (128 + 30);
8772 leency 1446
    winHeight := winHeight - (128 + 30);
1447
    winWidth := MAX(winWidth, minWinWidth);
1448
    winHeight := MAX(winHeight, minWinHeight);
8762 leency 1449
    cliWidth := winWidth;
1450
    cliHeight := winHeight;
8859 leency 1451
    LEFT := searchLeft;
8728 leency 1452
    canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 10), winHeight - (TOP + BOTTOM + 4) - K.SkinHeight());
9050 leency 1453
    tabs := Tabs.create();
1454
    Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight);
8772 leency 1455
    font1 := G.CreateFont(1, "", {});
1456
    font2 := G.CreateFont(2, "", {});
1457
    font := font1;
8728 leency 1458
    G.SetFont(canvas, font);
1459
    T.init(NIL);
1460
    T.setCanvas(canvas);
1461
    U.ptr2str(K.GetCommandLine(), fileName);
1462
    context := CreateContextMenu();
1463
    menuFile := CreateMenuFile();
1464
    menuEdit := CreateMenuEdit();
1465
    menuEncoding := CreateMenuEncoding();
1466
    menuView := CreateMenuView();
1467
    menuSyntax := CreateMenuSyntax();
1468
    menuProgram := CreateMenuProgram();
1469
    menuTools := CreateMenuTools();
1470
    IF fileName = "" THEN
1471
        text := T.New();
1472
        filePath := "/rd/1"
1473
    ELSE
1474
        text := T.open(fileName, err);
1475
        IF text = NIL THEN
1476
            error("'cedit: error opening file' -E");
1477
            K.Exit
1478
        ELSE
1479
            U.getPath(fileName, filePath)
1480
        END
1481
    END;
1482
    OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, "");
9050 leency 1483
    insert(0, text);
8728 leency 1484
 
9060 leency 1485
    vScroll := Scroll.create(scrollWidth, canvas.height - scrollWidth*2 + 2);
8762 leency 1486
    hScroll := Scroll.create(canvas.width - scrollWidth*2, scrollWidth);
8728 leency 1487
    T.resize(canvas.width, canvas.height);
1488
    T.SetPos(text, 0, 0);
1489
    confirm := FALSE;
1490
    notFound := FALSE;
1491
    search := FALSE;
1492
    createSearchForm;
1493
    new_searchText := "";
1494
    searchText := "";
1495
    cs := FALSE;
1496
    whole := FALSE;
1497
    replaced := 0;
9010 leency 1498
    Ini.getStr("paths", "build", buildScript);
1499
    Ini.getStr("paths", "run",   runScript);
1500
    Ini.getStr("paths", "debug", debugScript);
8728 leency 1501
    draw_window;
1502
    repaint;
1503
    WHILE TRUE DO
1504
        CASE K.WaitForEvent() OF
1505
        |1:
8772 leency 1506
            FOR i := 0 TO 1 DO
1507
                K.GetSystemColors;
1508
                Icons.get(icons, grayIcons);
1509
                IF ~K.RolledUp() THEN
1510
                    K.ClientSize(width, height);
1511
                    IF (width # cliWidth) OR (height # cliHeight) THEN
1512
                        cliWidth := width;
1513
                        cliHeight := height;
1514
                        resize;
1515
                        resized := TRUE;
1516
                    END;
1517
                    K.SetEventsMask({0, 1, 2, 5, 6, 31})
1518
                ELSE
1519
                    K.SetEventsMask({0, 30, 31})
8728 leency 1520
                END;
8772 leency 1521
                draw_window
1522
            END
1523
 
8728 leency 1524
        |2:
1525
            key := K.GetKey();
1526
            getKBState;
8848 leency 1527
            IF confirm THEN
1528
                IF key DIV 65536 = 28 THEN (* Enter *)
9050 leency 1529
                    save(text);
8848 leency 1530
                    IF ~text.modified THEN
9060 leency 1531
                        closeFile(FALSE, curText)
8848 leency 1532
                    END;
1533
                    repaint
1534
                END;
1535
                key := -1
1536
            END;
8728 leency 1537
            IF key DIV 65536 = 61 THEN (* F3 *)
1538
                key := -1;
1539
                IF search & (searchText # "") THEN
8772 leency 1540
                    IF T.SHIFT IN shift THEN
1541
                        notFound := ~T.findNext(text, ~box_lib.check_box_get_value(BKW))
1542
                    ELSE
1543
                        notFound := ~T.findNext(text, box_lib.check_box_get_value(BKW))
1544
                    END
8728 leency 1545
                END
9060 leency 1546
            ELSIF key DIV 65536 = 60 THEN (* F2 *)
1547
                key := -1;
1548
                IF T.CTRL IN shift THEN
1549
                    T.toggleLabel(text)
1550
                ELSE
1551
                    T.gotoLabel(text, ~(T.SHIFT IN shift))
1552
                END
8728 leency 1553
            ELSIF key DIV 65536 = 67 THEN (* F9 *)
1554
                key := -1;
1555
                IF T.CTRL IN shift THEN
1556
                    Script(buildScript)
1557
                ELSE
1558
                    Script(runScript)
1559
                END
8848 leency 1560
            ELSIF key DIV 65536 = 1 THEN (* Esc *)
1561
                key := -1;
8772 leency 1562
                IF search THEN
1563
                    Search
1564
                END
8728 leency 1565
            ELSIF (key DIV 65536 = 55) & (key DIV 256 MOD 256 = 52) THEN
1566
                key := -1 (* PrtScn *)
9060 leency 1567
            ELSIF (T.CTRL IN shift) & (key DIV 65536 = 15) THEN (* ctrl+Tab *)
1568
                key := -1;
1569
                curText := (curText + 1) MOD textsCount;
1570
                Tabs.switch(tabs, curText);
1571
                Switch(texts[curText]);
1572
                draw_window
8728 leency 1573
            ELSIF (T.CTRL IN shift) & (key DIV 65536 = 33) THEN
1574
                key := -1;
1575
                IF ~search THEN
1576
                    Search
1577
                END;
1578
                EditBox_SetFocus(FindEdit, TRUE);
1579
                EditBox_SetFocus(ReplaceEdit, FALSE);
9060 leency 1580
                EditBox_SetFocus(GotoEdit, FALSE)
8728 leency 1581
            ELSIF (T.CTRL IN shift) & (key DIV 65536 = 34) THEN
1582
                key := -1;
1583
                IF ~search THEN
1584
                    Search
1585
                END;
1586
                EditBox_SetFocus(GotoEdit, TRUE);
1587
                EditBox_SetFocus(FindEdit, FALSE);
1588
                EditBox_SetFocus(ReplaceEdit, FALSE)
1589
            END;
1590
            IF (key # -1) & EditBox_Focus(FindEdit) THEN
1591
                box_lib.edit_box_key(FindEdit, key);
1592
                EditBox_GetValue(FindEdit, new_searchText);
1593
                IF new_searchText # searchText THEN
1594
                    searchText := new_searchText;
1595
                    notFound := ~T.search(text, searchText, cs, whole)
1596
                END
1597
            ELSIF (key # -1) & EditBox_Focus(ReplaceEdit) THEN
1598
                box_lib.edit_box_key(ReplaceEdit, key);
1599
                EditBox_GetValue(ReplaceEdit, replaceText)
1600
            ELSIF (key # -1) & EditBox_Focus(GotoEdit) THEN
1601
                IF (key DIV 256) MOD 256 = 13 THEN
1602
                    goto
1603
                ELSE
1604
                    box_lib.edit_box_key(GotoEdit, key)
1605
                END
1606
            ELSIF key # -1 THEN
1607
                CASE key DIV 65536 OF
1608
                |73: key := 33
1609
                |81: key := 34
1610
                |71: key := 36
1611
                |79: key := 35
1612
                |72: key := 38
1613
                |80: key := 40
1614
                |75: key := 37
1615
                |77: key := 39
1616
                |82: key := -1 (* insert *)
1617
                |83: key := 46
1618
                |59, 60, 62..66, 68, 87, 88: key := -1 (* F1, F2, F4..F8, F10, F11, F12 *)
1619
                ELSE
1620
                    IF (T.CTRL IN shift) THEN
1621
                        CASE key DIV 65536 OF
9060 leency 1622
                        |17: closeFile(TRUE, curText);
1623
                             key := -2
8728 leency 1624
                        |21: T.redo(text);
1625
                             key := -1
1626
                        |22: key := ORD("U")
1627
                        |24: key := -1;
1628
                             open
1629
                        |30: key := ORD("A")
1630
                        |31: key := -1;
9050 leency 1631
                             save(text)
9010 leency 1632
                        |32: key := ORD("D")
8728 leency 1633
                        |38: key := ORD("L")
1634
                        |44: T.undo(text);
1635
                             key := -1
1636
                        |45: key := ORD("X")
1637
                        |46: key := ORD("C")
1638
                        |47: key := ORD("V")
1639
                        |49: key := -1;
9050 leency 1640
                             NewFile
8728 leency 1641
                        ELSE
1642
                            key := -1
1643
                        END
1644
                    ELSE
1645
                        T.input(text, E.cp866[key DIV 256 MOD 256]);
1646
                        key := -1
1647
                    END
1648
                END;
9060 leency 1649
                IF key >= 0 THEN
8728 leency 1650
                    T.key(text, key, shift)
1651
                END
1652
            END;
9060 leency 1653
            IF key # -2 THEN
1654
                repaint
1655
            END
8728 leency 1656
        |3:
9060 leency 1657
            btn := K.ButtonCode(middle);
1658
            IF (Tabs.btnID <= btn) & (btn <= Tabs.btnID + maxTexts - 1) THEN
1659
                DEC(btn, Tabs.btnID);
1660
                IF middle THEN
1661
                    IF texts[btn].modified THEN
1662
                        curText := btn;
1663
                        Tabs.switch(tabs, btn);
1664
                        Switch(texts[btn]);
1665
                        draw_window;
1666
                    END;
1667
                    closeFile(TRUE, btn)
1668
                ELSE
1669
                    curText := btn;
1670
                    Tabs.switch(tabs, btn);
1671
                    Switch(texts[btn]);
1672
                    draw_window
1673
                END;
1674
                btn := 0
1675
            ELSE
1676
                IF middle THEN
1677
                    btn := 0
1678
                END
1679
            END;
9050 leency 1680
            CASE btn OF
1681
            |Tabs.btnID - 1: Tabs.scroll(tabs, -1); switch := TRUE; repaint
1682
            |Tabs.btnID - 2: Tabs.scroll(tabs, +1); switch := TRUE; repaint
1683
 
8728 leency 1684
            |0:
1685
 
1686
            |btnFile:
1687
                ShowMenu(menuFile)
1688
            |btnEdit:
1689
                ShowMenu(menuEdit)
1690
            |btnEncoding:
1691
                ShowMenu(menuEncoding)
1692
            |btnView:
1693
                ShowMenu(menuView)
1694
            |btnSyntax:
1695
                ShowMenu(menuSyntax)
1696
            |btnProgram:
1697
                ShowMenu(menuProgram)
1698
            |btnTools:
1699
                ShowMenu(menuTools)
1700
            |btnNo:
9060 leency 1701
                closeFile(FALSE, curText);
9050 leency 1702
                repaint
8728 leency 1703
            |btnYes:
9050 leency 1704
                save(text);
8728 leency 1705
                IF ~text.modified THEN
9060 leency 1706
                    closeFile(FALSE, curText)
8728 leency 1707
                END;
1708
                repaint
1709
            |btnClose:
1710
                close
1711
            |btnNew:
9050 leency 1712
                NewFile;
1713
                repaint
8728 leency 1714
            |btnOpen:
1715
                open
1716
            |btnSave:
9050 leency 1717
                save(text);
8728 leency 1718
                repaint
1719
            |btnSearch:
1720
                IF ~search THEN
1721
                    Search
1722
                END
1723
            |btnCloseFind:
1724
                Search
1725
            |btnUndo:
1726
                T.undo(text);
1727
                repaint
1728
            |btnRedo:
1729
                T.redo(text);
1730
                repaint
1731
            |btnUpper:
1732
                T.chCase(text, TRUE);
1733
                repaint
1734
            |btnLower:
1735
                T.chCase(text, FALSE);
1736
                repaint
1737
            |btnBuild:
1738
                Script(buildScript)
1739
            |btnRun:
1740
                Script(runScript)
1741
            |btnUp:
1742
                T.scroll(text, 0, -1);
1743
                repaint
1744
            |btnDown:
1745
                T.scroll(text, 0, 1);
1746
                repaint
1747
            |btnLeft:
1748
                T.scroll(text, -1, 0);
1749
                repaint
1750
            |btnRight:
1751
                T.scroll(text, 1, 0);
1752
                repaint
1753
            |btnFindEdit:
1754
                EditBox_SetFocus(FindEdit, TRUE);
1755
                EditBox_SetFocus(ReplaceEdit, FALSE);
1756
                EditBox_SetFocus(GotoEdit, FALSE)
1757
            |btnReplaceEdit:
1758
                EditBox_SetFocus(ReplaceEdit, TRUE);
1759
                EditBox_SetFocus(FindEdit, FALSE);
1760
                EditBox_SetFocus(GotoEdit, FALSE)
1761
            |btnGotoEdit:
1762
                EditBox_SetFocus(GotoEdit, TRUE);
1763
                EditBox_SetFocus(FindEdit, FALSE);
1764
                EditBox_SetFocus(ReplaceEdit, FALSE)
1765
            |btnFindNext:
1766
                IF searchText # "" THEN
1767
                    notFound := ~T.findNext(text, box_lib.check_box_get_value(BKW));
1768
                    repaint
1769
                END
1770
            |btnReplace:
1771
                T.replace(text, replaceText, LENGTH(searchText));
1772
                repaint
1773
            |btnReplaceAll:
1774
                notFound := ~T.search(text, searchText, cs, whole);
1775
                IF ~notFound THEN
1776
                    replaced := T.replaceAll(text, replaceText, LENGTH(searchText));
1777
                END;
1778
                repaint
1779
            |btnGoto:
1780
                goto;
1781
                repaint
1782
            END
1783
        |6:
1784
            Menu.close(menuFile);
1785
            Menu.close(menuEdit);
1786
            Menu.close(menuEncoding);
1787
            Menu.close(menuView);
1788
            Menu.close(menuSyntax);
1789
            Menu.close(menuProgram);
1790
            Menu.close(menuTools);
1791
            Menu.close(context);
1792
            IF ~resized THEN
1793
                getKBState;
1794
                msState := K.MouseState();
1795
                IF ~(0 IN msState) OR (16 IN msState) THEN
1796
                    LeftButtonUp
1797
                END;
1798
                scroll := K.Scroll();
1799
                IF scroll # 0 THEN
1800
                    T.scroll(text, 0, scroll*3);
1801
                    repaint
1802
                END;
1803
                IF leftButton THEN
1804
                    IF K.GetTickCount() - time > 9 THEN
1805
                        mouse(x, y);
1806
                        T.mouse(text, x, y);
1807
                        repaint
1808
                    END
1809
                END;
1810
                IF VScroll THEN
1811
                    mouse(x, y);
1812
                    Scroll.mouse(vScroll, x, y - scrollWidth);
1813
                    T.getScroll(text, scrollX, scrollY);
1814
                    T.scroll(text, 0, vScroll.value - scrollY);
1815
                    repaint
1816
                END;
1817
                IF HScroll THEN
1818
                    mouse(x, y);
1819
                    Scroll.mouse(hScroll, x - scrollWidth, y);
1820
                    T.getScroll(text, scrollX, scrollY);
1821
                    T.scroll(text, hScroll.value - scrollX, 0);
1822
                    repaint
1823
                END;
1824
                IF (8 IN msState) & ~(24 IN msState) THEN
1825
                    mouse(firstClickX, firstClickY);
1826
                    time := click(firstClickX, firstClickY)
1827
                END;
1828
                IF 9 IN msState THEN
1829
                    ShowMenu(context)
1830
                END;
1831
                IF 24 IN msState THEN
1832
                    mouse(x, y);
1833
                    IF (ABS(x - firstClickX) < 5) & (ABS(y - firstClickY) < 5) THEN
1834
                        VScroll := FALSE;
1835
                        HScroll := FALSE;
1836
                        IF (0 <= x) & (x < canvas.width) & (0 <= y) & (y < canvas.height) THEN
1837
                            leftButton := FALSE;
1838
                            T.selectWord(text);
1839
                            repaint
1840
                        END
1841
                    ELSE
1842
                        firstClickX := x;
1843
                        firstClickY := y;
1844
                        time := click(firstClickX, firstClickY)
1845
                    END
1846
                END
1847
            END;
1848
            IF search THEN
1849
                IF EditBox_Focus(FindEdit) THEN
1850
                    box_lib.edit_box_mouse(FindEdit)
1851
                END;
1852
                IF EditBox_Focus(ReplaceEdit) THEN
1853
                    box_lib.edit_box_mouse(ReplaceEdit)
1854
                END;
1855
                IF EditBox_Focus(GotoEdit) THEN
1856
                    box_lib.edit_box_mouse(GotoEdit)
1857
                END;
1858
                box_lib.check_box_mouse2(CS);
1859
                box_lib.check_box_mouse2(WH);
1860
                box_lib.check_box_mouse2(BKW);
1861
                IF box_lib.check_box_get_value(CS) # cs THEN
1862
                    cs := ~cs;
1863
                    notFound := ~T.search(text, searchText, cs, whole);
1864
                    repaint
1865
                END;
1866
                IF box_lib.check_box_get_value(WH) # whole THEN
1867
                    whole := ~whole;
1868
                    notFound := ~T.search(text, searchText, cs, whole);
1869
                    repaint
1870
                END
1871
            END;
1872
            resized := FALSE
1873
        |7: receiveIPC
1874
        ELSE
1875
        END
1876
    END
1877
END main;
1878
 
1879
 
1880
BEGIN
1881
    main
1882
END CEdit.