Subversion Repositories Kolibri OS

Rev

Rev 9010 | Rev 9060 | 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
9050 leency 31
    header = "CEdit (10-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);
431
    Scroll.resize(vScroll, vScroll.xSize, canvas.height - scrollWidth*2 + 1);
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
440
    right := left + EditBox_Width + SEARCH_PADDING*2;
441
    bottom := top + 395 + btnHeight + SEARCH_PADDING;
8762 leency 442
    color := K.borderColor;
8728 leency 443
    Rect(left, top, right, bottom, color);
444
    K.CreateButton(btnCloseFind, right - 20, top, 20, 20, 0EF999FH, "");
445
    K.DrawLine(right - 14, top + 5, right - 5, top + 14, 0FFFFFFH);
446
    K.DrawLine(right - 15, top + 5, right - 5, top + 15, 0FFFFFFH);
447
    K.DrawLine(right - 15, top + 6, right - 6, top + 15, 0FFFFFFH);
448
    K.DrawLine(right - 15, top + 14, right - 6, top + 5, 0FFFFFFH);
449
    K.DrawLine(right - 15, top + 15, right - 5, top + 5, 0FFFFFFH);
450
    K.DrawLine(right - 14, top + 15, right - 5, top + 6, 0FFFFFFH);
451
 
452
    INC(top, 15);
453
    INC(left, SEARCH_PADDING);
8762 leency 454
    K.DrawText866(left, top, K.textColor, "find");
455
    K.DrawText866(left, top + 55, K.textColor, "replace with");
8728 leency 456
    K.CreateButton(btnFindEdit + ORD({30}), left, top + 20, EditBox_Width, fontHeight + 5, 0, "");
457
    K.CreateButton(btnReplaceEdit + ORD({30}), left, top + 75, EditBox_Width, fontHeight + 5, 0, "");
8762 leency 458
    K.DrawText866(left, top + 330, K.textColor, "go to line");
8728 leency 459
    K.CreateButton(btnGotoEdit + ORD({30}), left, top + 350, EditBox_Width, fontHeight + 5, 0, "");
460
    BKW.top_s := BKW.top_s MOD 65536 + (top + 110) * 65536;
461
    CS.top_s := CS.top_s MOD 65536 + (top + 140) * 65536;
462
    WH.top_s := WH.top_s MOD 65536 + (top + 170) * 65536;
463
    BKW.left_s := BKW.left_s MOD 65536 + left * 65536;
464
    CS.left_s := CS.left_s MOD 65536 + left * 65536;
465
    WH.left_s := WH.left_s MOD 65536 + left * 65536;
466
    FindEdit.top := top + 20;
467
    ReplaceEdit.top := top + 75;
468
    GotoEdit.top := top + 350;
469
    FindEdit.left := left;
470
    ReplaceEdit.left := left;
471
    GotoEdit.left := left;
472
    box_lib.edit_box_draw(FindEdit);
473
    box_lib.edit_box_draw(ReplaceEdit);
474
    box_lib.edit_box_draw(GotoEdit);
8762 leency 475
    box_lib.check_box_draw2(BKW); K.DrawText866(left + 20, top + 110, K.textColor, "backward");
476
    box_lib.check_box_draw2(CS); K.DrawText866(left + 20, top + 140, K.textColor, "match case");
477
    box_lib.check_box_draw2(WH); K.DrawText866(left + 20, top + 170, K.textColor, "whole word");
8728 leency 478
    y := top + 200;
8762 leency 479
    K.CreateButton(btnFindNext, left, y, btnWidth, btnHeight, K.btnColor, "next"); INC(y, btnHeight + 10);
480
    K.CreateButton(btnReplace, left, y, btnWidth, btnHeight, K.btnColor, "replace"); INC(y, btnHeight + 10);
481
    K.CreateButton(btnReplaceAll, left, y, btnWidth + 5*fontWidth - 2, btnHeight, K.btnColor, "replace all");
482
    K.CreateButton(btnGoto, left, top + 380, btnWidth, btnHeight, K.btnColor, "go");
8728 leency 483
END SearchPanel;
484
 
485
 
486
PROCEDURE draw_window;
487
VAR
9050 leency 488
    width, height, x: INTEGER;
8728 leency 489
 
490
 
491
    PROCEDURE drawToolbarBtn (id, x: INTEGER);
492
    BEGIN
8762 leency 493
        K.DrawRect(x, btnTop, toolBtnSize, toolBtnSize, K.toolbarColor);
494
        K.DrawLine(x, btnTop + toolBtnSize, x + toolBtnSize, btnTop + toolBtnSize, K.shadowColor);
495
        K.DrawLine(x + toolBtnSize, btnTop, x + toolBtnSize, btnTop + toolBtnSize, K.shadowColor);
496
        K.CreateButton(id + ORD({30}), x, btnTop, toolBtnSize, toolBtnSize, K.btnColor, "");
8728 leency 497
    END drawToolbarBtn;
498
 
499
 
500
    PROCEDURE drawMainMenu (menu: Menu.tMenu; x: INTEGER; btn: INTEGER; caption: ARRAY OF WCHAR);
501
    VAR
8772 leency 502
        menuColor, textColor, n: INTEGER;
8728 leency 503
    BEGIN
504
        IF menu.tid # 0 THEN
8772 leency 505
            menuColor := K.textColor;
506
            textColor := K.winColor
8728 leency 507
        ELSE
8772 leency 508
            menuColor := K.winColor;
509
            textColor := K.textColor
8728 leency 510
        END;
511
        n := LENGTH(caption);
512
        K.DrawRect(x, 0, n*fontWidth + 2, MainMenuHeight, menuColor);
8762 leency 513
        K.CreateButton(btn + ORD({30}), x, 0, n*fontWidth + 2, MainMenuHeight, K.btnColor, "");
8772 leency 514
        K.DrawText(x + 1, (MainMenuHeight - fontHeight) DIV 2 + 1, textColor, caption)
8728 leency 515
    END drawMainMenu;
516
 
517
 
518
BEGIN
519
    K.BeginDraw;
8772 leency 520
    K.CreateWindow(30 + K.GetTickCount() MOD 128, 30 + K.GetTickCount() MOD 128, winWidth, winHeight, K.winColor, 73H, 0, 0, header);
8728 leency 521
    IF (text # NIL) & ~K.RolledUp() THEN
522
        confirm := FALSE;
523
        K.ClientSize(width, height);
524
 
8762 leency 525
        K.DrawRect(0, 0, width, TOP, K.winColor);
526
        K.DrawRect(0, 0, LEFT, height, K.winColor);
527
        K.DrawRect(LEFT + canvas.width - 1, TOP + canvas.height - 1, scrollWidth, scrollWidth, K.winColor);
8728 leency 528
 
529
        drawMainMenu(menuFile, menuFileX, btnFile, "file");
530
        drawMainMenu(menuEdit, menuEditX, btnEdit, "edit");
531
        drawMainMenu(menuEncoding, menuEncodingX, btnEncoding, "encoding");
532
        drawMainMenu(menuView, menuViewX, btnView, "view");
533
        drawMainMenu(menuSyntax, menuSyntaxX, btnSyntax, "syntax");
534
        drawMainMenu(menuProgram, menuProgramX, btnProgram, "program");
535
        drawMainMenu(menuTools, menuToolsX, btnTools, "tools");
536
 
537
        x := searchLeft;
538
 
539
        drawToolbarBtn(btnNew, x);
8762 leency 540
        Icons.draw(icons, 2, x + iconPad, btnTop + iconPad);
8728 leency 541
        INC(x, toolBtnSize + 5);
542
 
543
        drawToolbarBtn(btnOpen, x);
8762 leency 544
        Icons.draw(icons, 0, x + iconPad, btnTop + iconPad);
8728 leency 545
        INC(x, toolBtnSize + 5);
546
 
547
        drawToolbarBtn(btnSave, x);
548
        INC(x, toolBtnSize + 5 + toolbarDelim);
549
 
550
        drawToolbarBtn(btnSearch, x);
8762 leency 551
        Icons.draw(icons, 49, x + iconPad, btnTop + iconPad);
8728 leency 552
        INC(x, toolBtnSize + 5 + toolbarDelim);
553
 
554
        drawToolbarBtn(btnUndo, x);
555
        INC(x, toolBtnSize + 5);
556
 
557
        drawToolbarBtn(btnRedo, x);
558
        INC(x, toolBtnSize + 5 + toolbarDelim);
559
 
560
        drawToolbarBtn(btnUpper, x);
561
        INC(x, toolBtnSize + 5);
562
 
563
        drawToolbarBtn(btnLower, x);
564
        INC(x, toolBtnSize + 5 + toolbarDelim);
565
 
566
        drawToolbarBtn(btnBuild, x);
567
        INC(x, toolBtnSize + 5);
568
 
569
        drawToolbarBtn(btnRun, x);
570
        INC(x, toolBtnSize + 5);
571
 
8859 leency 572
        toolbarIcons;
573
 
8762 leency 574
        K.CreateButton(btnUp, LEFT + canvas.width - 1, TOP, scrollWidth - 1, scrollWidth, K.btnColor, 0X);
575
        K.DrawText69(LEFT + canvas.width - 1 + (scrollWidth - 6) DIV 2, TOP + (scrollWidth - 9) DIV 2, K.btnTextColor, 18X);
576
        K.CreateButton(btnDown, LEFT + canvas.width - 1, TOP + canvas.height - scrollWidth - 1, scrollWidth - 1, scrollWidth, K.btnColor, 0X);
577
        K.DrawText69(LEFT + canvas.width - 1 + (scrollWidth - 6) DIV 2, TOP + canvas.height - scrollWidth + (scrollWidth - 9) DIV 2, K.btnTextColor, 19X);
8728 leency 578
 
8762 leency 579
        K.CreateButton(btnLeft, LEFT, TOP + canvas.height - 1, scrollWidth, scrollWidth - 1, K.btnColor, 0X);
580
        K.DrawText69(LEFT + (scrollWidth - 6) DIV 2, TOP + canvas.height - 1 + (scrollWidth - 9) DIV 2 + 1, K.btnTextColor, 1BX);
581
        K.CreateButton(btnRight, LEFT + canvas.width - scrollWidth - 1, TOP + canvas.height - 1, scrollWidth, scrollWidth - 1, K.btnColor, 0X);
582
        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 583
 
8762 leency 584
        K.PutPixel(LEFT + canvas.width + scrollWidth - 2, TOP, K.winColor);
585
        K.PutPixel(LEFT, TOP + canvas.height + scrollWidth - 2, K.winColor);
586
 
9050 leency 587
        DrawState(text, width, height);
8728 leency 588
        IF search THEN
589
            SearchPanel(searchLeft, TOP)
590
        END;
9050 leency 591
        Tabs.draw(tabs);
8728 leency 592
        repaint
593
    END;
594
    K.EndDraw
595
END draw_window;
596
 
597
 
598
PROCEDURE mouse (VAR x, y: INTEGER);
599
VAR
600
    mouseX, mouseY,
601
    cliX, cliY,
602
    winX, winY: INTEGER;
603
BEGIN
604
    K.MousePos(mouseX, mouseY);
605
    K.WinPos(winX, winY);
606
    K.ClientPos(cliX, cliY);
607
    x := mouseX - winX - cliX - LEFT;
608
    y := mouseY - winY - cliY - TOP;
609
END mouse;
610
 
611
 
612
PROCEDURE getKBState;
613
VAR
614
    kbState: SET;
615
BEGIN
616
    kbState := K.GetControlKeys();
617
    IF {0, 1} * kbState # {} THEN
618
        INCL(shift, T.SHIFT)
619
    ELSE
620
        EXCL(shift, T.SHIFT)
621
    END;
622
 
623
    IF {2, 3} * kbState # {} THEN
624
        INCL(shift, T.CTRL)
625
    ELSE
626
        EXCL(shift, T.CTRL)
627
    END
628
END getKBState;
629
 
630
 
631
PROCEDURE OpenFile (VAR FileName: RW.tFileName; filter: ARRAY OF CHAR);
632
BEGIN
633
    OpenDlg.SetFilter(OD, filter);
634
    OpenDlg.Show(OD, 500, 400);
635
    WHILE OD.status = 2 DO
636
        K.Pause(30)
637
    END;
638
    IF OD.status = 1 THEN
639
        COPY(OD.FilePath, FileName)
640
    ELSE
641
        FileName := ""
642
    END
643
END OpenFile;
644
 
645
 
646
PROCEDURE error (s: RW.tFileName);
647
BEGIN
648
    K.Run("/rd/1/@notify", s)
649
END error;
650
 
651
 
9050 leency 652
PROCEDURE saveError (name: RW.tFileName);
8728 leency 653
VAR
9050 leency 654
    s: RW.tFileName;
655
BEGIN
656
    s := "'cedit: error saving file ";
657
    U.append8(s, name);
658
    U.append8(s, "' -E");
659
    error(s)
660
END saveError;
661
 
662
 
663
PROCEDURE saveAs (text: T.tText);
664
VAR
665
    fileName, name: RW.tFileName;
8728 leency 666
    ext: ARRAY 8 OF CHAR;
667
BEGIN
668
    OD._type := OpenDlg.tsave;
669
    U.getFileName(text.fileName, OD.FileName, U.SLASH);
670
    IF OD.FileName = "" THEN
671
        OD.FileName := "NewFile.";
672
        CASE text.lang OF
673
        |Languages.langNone:   ext := "txt"
674
        |Languages.langC:      ext := "c"
675
        |Languages.langFasm:   ext := "asm"
676
        |Languages.langIni:    ext := "ini"
677
        |Languages.langLua:    ext := "lua"
678
        |Languages.langOberon: ext := "ob07"
679
        |Languages.langPascal: ext := "pas"
680
        END;
681
        U.append8(OD.FileName, ext)
682
    END;
683
    OpenFile(fileName, EditFilter);
684
    IF fileName # "" THEN
685
        IF T.save(text, fileName, text.enc, RW.EOL_CRLF) THEN
9050 leency 686
            T.setName(text, fileName);
687
            U.getFileName(fileName, name, U.SLASH);
688
            Tabs.rename(tabs, curText, name)
8728 leency 689
        ELSE
9050 leency 690
            saveError(fileName)
8728 leency 691
        END
692
    END
693
END saveAs;
694
 
695
 
9050 leency 696
PROCEDURE getIdx (text: T.tText): INTEGER;
697
VAR
698
    i: INTEGER;
8728 leency 699
BEGIN
9050 leency 700
    i := 0;
701
    WHILE texts[i] # text DO
702
        INC(i)
703
    END
704
    RETURN i
705
END getIdx;
706
 
707
 
708
PROCEDURE Switch (txt: T.tText);
709
BEGIN
710
    Tabs.switch(tabs, curText);
711
    text := txt;
712
    T.switch(txt);
713
    switch := TRUE
714
END Switch;
715
 
716
 
717
PROCEDURE save (text: T.tText);
718
BEGIN
8728 leency 719
    IF text.modified THEN
720
        IF text.fileName # "" THEN
721
            IF ~T.save(text, text.fileName, text.enc, RW.EOL_CRLF) THEN
9050 leency 722
                saveError(text.fileName)
8728 leency 723
            END
724
        ELSE
9050 leency 725
            curText := getIdx(text);
726
            Switch(text);
727
            saveAs(text)
8728 leency 728
        END
729
    END
730
END save;
731
 
732
 
9050 leency 733
PROCEDURE saveAll;
734
VAR
735
    i: INTEGER;
8728 leency 736
BEGIN
9050 leency 737
    i := textsCount - 1;
738
    WHILE i >= 0 DO
739
        IF texts[i].modified THEN
740
            save(texts[i])
741
        END;
742
        DEC(i)
743
    END;
744
END saveAll;
8728 leency 745
 
746
 
9050 leency 747
PROCEDURE insert (pos: INTEGER; txt: T.tText);
8728 leency 748
VAR
9050 leency 749
    i: INTEGER;
750
    name: RW.tFileName;
8728 leency 751
BEGIN
9050 leency 752
    FOR i := textsCount - 1 TO pos BY -1 DO
753
        texts[i + 1] := texts[i]
754
    END;
755
    texts[pos] := txt;
756
    INC(textsCount);
757
    curText := pos;
758
    IF txt.fileName = "" THEN
759
        name := "new"
760
    ELSE
761
        U.getFileName(txt.fileName, name, U.SLASH)
762
    END;
763
    Tabs.add(tabs, name);
764
    Switch(txt)
765
END insert;
8728 leency 766
 
767
 
768
PROCEDURE Confirm;
769
CONST
770
    width  = btnWidth*2 + 30;
771
    height = btnHeight*2 + 20;
772
    lineColor = 808080H;
773
VAR
774
    left, top, right, bottom: INTEGER;
775
BEGIN
776
    draw_window;
777
    confirm := TRUE;
778
    left := (canvas.width - width) DIV 2 + LEFT;
779
    top := (canvas.height - height) DIV 2 + TOP;
780
    right := left + width - 1;
781
    bottom := top + height - 1;
8762 leency 782
    K.DrawRect(left, top, width, height, K.winColor);
8728 leency 783
    Rect(left, top, right, bottom, lineColor);
8762 leency 784
    K.DrawText866(left + (width - 10*fontWidth) DIV 2, top + 10, K.textColor, "save file?");
785
    K.CreateButton(btnYes, left + 10, top + 35, btnWidth, btnHeight, K.btnColor, "yes");
786
    K.CreateButton(btnNo, left + 20 + btnWidth, top + 35, btnWidth, btnHeight, K.btnColor, "no");
8728 leency 787
END Confirm;
788
 
789
 
9050 leency 790
PROCEDURE closeFile (conf: BOOLEAN);
791
VAR
792
    i: INTEGER;
793
BEGIN
794
    IF text.modified & conf THEN
795
        Confirm
796
    ELSE
797
        Tabs.delete(tabs, curText);
798
        FOR i := curText + 1 TO textsCount - 1 DO
799
            texts[i - 1] := texts[i]
800
        END;
801
        DEC(textsCount);
802
        IF curText = textsCount THEN
803
            DEC(curText)
804
        END;
805
        IF curText >= 0 THEN
806
            Switch(texts[curText])
807
        ELSE
808
            K.Exit
809
        END;
810
        draw_window
811
    END
812
END closeFile;
813
 
814
 
815
PROCEDURE NewFile;
816
VAR
817
    nov: T.tText;
818
BEGIN
819
    IF textsCount < maxTexts THEN
820
        nov := T.New();
821
        T.SetPos(nov, 0, 0);
822
        insert(textsCount, nov)
823
    ELSE
824
        error("'cedit: too many files' -E")
825
    END
826
END NewFile;
827
 
828
 
829
PROCEDURE getFileNum (fileName: RW.tFileName): INTEGER;
830
VAR
831
    i: INTEGER;
832
 
833
    PROCEDURE nameEq (name1, name2: RW.tFileName): BOOLEAN;
834
    VAR
835
        n1, n2: RW.tFileName;
836
    BEGIN
837
        n1 := name1;
838
        n2 := name2;
839
        U.upcase(n1);
840
        U.upcase(n2)
841
        RETURN n1 = n2
842
    END nameEq;
843
 
844
BEGIN
845
    i := 0;
846
    WHILE (i < textsCount) & ~nameEq(texts[i].fileName, fileName) DO
847
        INC(i)
848
    END;
849
    IF i = textsCount THEN
850
        i := -1
851
    END
852
    RETURN i
853
END getFileNum;
854
 
855
 
856
PROCEDURE open;
857
VAR
858
    fileName: RW.tFileName;
859
    nov: T.tText;
860
    err, n: INTEGER;
861
BEGIN
862
    IF textsCount < maxTexts THEN
863
        OD._type := OpenDlg.topen;
864
        OpenFile(fileName, EditFilter);
865
        IF fileName # "" THEN
866
            n := getFileNum(fileName);
867
            IF n = -1 THEN
868
                nov := T.open(fileName, err);
869
                IF nov = NIL THEN
870
                    error("'cedit: error opening file' -E")
871
                ELSE
872
                    insert(textsCount, nov);
873
                    T.SetPos(nov, 0, 0)
874
                END
875
            ELSE
876
                curText := n;
877
                Tabs.switch(tabs, n);
878
                Switch(texts[n]);
879
                draw_window
880
            END
881
        END
882
    ELSE
883
        error("'cedit: too many files' -E")
884
    END
885
END open;
886
 
887
 
8728 leency 888
PROCEDURE createEdit (left, top: INTEGER): box_lib.edit_box;
889
VAR
890
    edit, EditBox0: box_lib.edit_box;
891
BEGIN
892
    NEW(EditBox0);
893
    EditBox0.text := K.malloc(EDITBOX_MAXCHARS + 2);
894
    ASSERT(EditBox0.text # 0);
895
    edit := box_lib.kolibri_new_edit_box(left, top, EditBox_Width, EDITBOX_MAXCHARS, EditBox0);
896
    edit.flags := 4002H;
897
    edit.text_color := 30000000H;
898
    EditBox_SetFocus(edit, FALSE)
899
    RETURN edit
900
END createEdit;
901
 
902
 
903
PROCEDURE createSearchForm;
904
BEGIN
905
    FindEdit := createEdit(searchLeft, TOP + 20);
906
    ReplaceEdit := createEdit(searchLeft, TOP + 20 + 55);
907
    GotoEdit := createEdit(searchLeft, TOP + 20 + 330);
908
    GotoEdit.flags := ORD(BITS(GotoEdit.flags) + BITS(8000H));
909
    BKW := box_lib.kolibri_new_check_box(searchLeft, TOP + 90 + 20, 16, 16, "", 8*fontWidth + 4);
910
    CS := box_lib.kolibri_new_check_box(searchLeft, TOP + 120 + 20, 16, 16, "", 10*fontWidth + 4);
911
    WH := box_lib.kolibri_new_check_box(searchLeft, TOP + 150 + 20, 16, 16, "", 10*fontWidth + 4);
912
END createSearchForm;
913
 
914
 
915
PROCEDURE EditBox_GetValue (edit: box_lib.edit_box; VAR s: ARRAY OF WCHAR);
916
VAR
917
    str: ARRAY EDITBOX_MAXCHARS + 1 OF CHAR;
918
    i: INTEGER;
919
BEGIN
920
    box_lib.edit_box_get_value(edit, str);
921
    i := 0;
922
    WHILE str[i] # 0X DO
923
        s[i] := WCHR(E.cp866[ORD(str[i])]);
924
        INC(i)
925
    END;
926
    s[i] := 0X
927
END EditBox_GetValue;
928
 
929
 
930
PROCEDURE Search;
931
BEGIN
932
    search := ~search;
933
    IF search THEN
8859 leency 934
        LEFT := searchLeft + EditBox_Width + SEARCH_PADDING*2 + 5;
8728 leency 935
        IF T.search(text, searchText, cs, whole) THEN END
936
    ELSE
937
        LEFT := searchLeft;
938
        IF T.search(text, "", FALSE, FALSE) THEN END
939
    END;
940
    EditBox_SetFocus(FindEdit, search);
941
    EditBox_SetFocus(ReplaceEdit, FALSE);
942
    EditBox_SetFocus(GotoEdit, FALSE);
943
    resize;
944
    draw_window
945
END Search;
946
 
947
 
948
PROCEDURE click (x, y: INTEGER): INTEGER;
949
VAR
950
    scrollX, scrollY: INTEGER;
951
BEGIN
952
    IF (0 <= x) & (x < canvas.width) & (0 <= y) & (y < canvas.height) THEN
953
        leftButton := TRUE;
954
        EditBox_SetFocus(FindEdit, FALSE);
955
        EditBox_SetFocus(ReplaceEdit, FALSE);
956
        EditBox_SetFocus(GotoEdit, FALSE);
957
        IF ~(T.SHIFT IN shift) THEN
958
            T.resetSelect(text)
959
        END;
960
        T.mouse(text, x, y);
961
        repaint
962
    ELSIF (canvas.width < x) & (x < canvas.width + scrollWidth) & (scrollWidth < y) & (y < canvas.height - scrollWidth) THEN
963
        VScroll := TRUE;
964
        DEC(x, canvas.width);
965
        DEC(y, scrollWidth);
966
        Scroll.mouse(vScroll, x, y);
967
        T.getScroll(text, scrollX, scrollY);
968
        T.scroll(text, 0, vScroll.value - scrollY);
969
        repaint
970
    ELSIF (scrollWidth < x) & (x < canvas.width - scrollWidth) & (canvas.height < y) & (y < canvas.height + scrollWidth) THEN
971
        HScroll := TRUE;
972
        DEC(x, scrollWidth);
973
        DEC(y, canvas.height);
974
        Scroll.mouse(hScroll, x, y);
975
        T.getScroll(text, scrollX, scrollY);
976
        T.scroll(text, hScroll.value - scrollX, 0);
977
        repaint
978
    END
979
    RETURN K.GetTickCount()
980
END click;
981
 
982
 
983
PROCEDURE LeftButtonUp;
984
BEGIN
985
    leftButton := FALSE;
986
    VScroll := FALSE;
987
    HScroll := FALSE;
988
    Scroll.MouseUp(vScroll);
989
    Scroll.MouseUp(hScroll);
990
END LeftButtonUp;
991
 
992
 
993
PROCEDURE close;
9050 leency 994
VAR
995
    cont: BOOLEAN;
8728 leency 996
BEGIN
9050 leency 997
    cont := TRUE;
998
    WHILE (textsCount > 0) & cont DO
999
        IF text.modified THEN
1000
            Confirm;
1001
            cont := FALSE
1002
        ELSE
1003
            closeFile(FALSE);
1004
            repaint
1005
        END
8728 leency 1006
    END
1007
END close;
1008
 
1009
 
1010
PROCEDURE MenuItemClick (menu: Menu.tMenu; id: INTEGER);
1011
BEGIN
1012
    K.SendIPC(mainTID, id)
1013
END MenuItemClick;
1014
 
1015
 
1016
PROCEDURE goto;
1017
VAR
1018
    gotoVal: INTEGER;
1019
BEGIN
1020
    EditBox_GetValue(GotoEdit, gotoText);
1021
    IF U.str2int(gotoText, gotoVal) & T.goto(text, gotoVal) THEN END
1022
END goto;
1023
 
1024
 
1025
PROCEDURE Script (script: ARRAY OF CHAR);
1026
BEGIN
1027
    IF script # "" THEN
1028
        K.Run("/rd/1/@open", script)
1029
    END
1030
END Script;
1031
 
1032
 
1033
PROCEDURE receiveIPC;
1034
BEGIN
1035
    IF IPC[0] # Menu.lastTID THEN
1036
        IPC[2] := 0
1037
    END;
1038
    CASE IPC[2] OF
1039
    |0:
1040
    |menuCut:       T.key(text, ORD("X"), {T.CTRL})
1041
    |menuCopy:      T.key(text, ORD("C"), {T.CTRL})
1042
    |menuPaste:     T.key(text, ORD("V"), {T.CTRL})
1043
    |menuDelete:    T.key(text, 46, {})
1044
    |menuSelectAll: T.key(text, ORD("A"), {T.CTRL})
1045
 
1046
    |menuNew:
9050 leency 1047
        NewFile
8728 leency 1048
    |menuOpen:
1049
        open
1050
    |menuSave:
9050 leency 1051
        save(text);
8728 leency 1052
        repaint
1053
    |menuSaveAs:
9050 leency 1054
        saveAs(text);
8728 leency 1055
        repaint
9050 leency 1056
    |menuSaveAll:
1057
        saveAll;
1058
        repaint
1059
    |menuClose:
1060
        closeFile(TRUE)
8728 leency 1061
    |menuFolder:
1062
        K.Run("/rd/1/File Managers/Eolite", text.fileName)
1063
    |menuExit:
1064
        close
1065
    |menuUndo:
1066
        T.undo(text);
1067
        repaint
1068
    |menuRedo:
1069
        T.redo(text);
1070
        repaint
1071
    |menuSearch:
1072
        IF ~search THEN
1073
            Search
1074
        END;
1075
        EditBox_SetFocus(FindEdit, TRUE);
1076
        EditBox_SetFocus(ReplaceEdit, FALSE);
1077
        EditBox_SetFocus(GotoEdit, FALSE)
1078
    |menuGoto:
1079
        IF ~search THEN
1080
            Search
1081
        END;
1082
        EditBox_SetFocus(GotoEdit, TRUE);
1083
        EditBox_SetFocus(FindEdit, FALSE);
1084
        EditBox_SetFocus(ReplaceEdit, FALSE)
1085
    |menuNumbers:
1086
        T.toggleNumbers(text)
8772 leency 1087
    |menuFontSize:
1088
        IF font = font1 THEN
1089
            font := font2
1090
        ELSE
1091
            font := font1
1092
        END;
1093
        resize
8728 leency 1094
    |menuNone:
1095
        T.setLang(text, Languages.langNone)
1096
    |menuC:
1097
        T.setLang(text, Languages.langC)
1098
    |menuFasm:
1099
        T.setLang(text, Languages.langFasm)
1100
    |menuIni:
1101
        T.setLang(text, Languages.langIni)
1102
    |menuLua:
1103
        T.setLang(text, Languages.langLua)
1104
    |menuOberon:
1105
        T.setLang(text, Languages.langOberon)
1106
    |menuPascal:
1107
        T.setLang(text, Languages.langPascal)
1108
    |menuBuild:
1109
        Script(buildScript)
1110
    |menuBuildScript:
1111
        OpenFile(buildScript, ShellFilter)
1112
    |menuRun:
1113
        Script(runScript)
1114
    |menuRunScript:
1115
        OpenFile(runScript, ShellFilter)
1116
    |menuDebug:
1117
        Script(debugScript)
1118
    |menuDebugScript:
1119
        OpenFile(debugScript, ShellFilter)
1120
    |menuUTF8BOM:
1121
        text.enc := E.UTF8BOM
1122
    |menuUTF8:
1123
        text.enc := E.UTF8
1124
    |menuCP866:
1125
        text.enc := E.CP866
1126
    |menuWin1251:
1127
        text.enc := E.W1251
1128
    |menuPipet:
1129
        K.Run("/rd/1/develop/pipet", "")
1130
    |menuSysFunc:
1131
        K.Run("/rd/1/docpack", "f")
1132
    |menuColors..menuMaxColors:
1133
        Ini.selectSection(IPC[2] - menuColors)
1134
    END;
1135
    IPC[0] := 0;
1136
    IPC[1] := 0
1137
END receiveIPC;
1138
 
1139
 
1140
PROCEDURE MenuKeyDown (menu: Menu.tMenu; key: INTEGER): BOOLEAN;
1141
VAR
1142
    menuItem: INTEGER;
1143
BEGIN
1144
    menuItem := -1;
1145
    getKBState;
1146
    IF (T.CTRL IN shift) THEN
1147
        CASE key DIV 65536 OF
1148
        |21: menuItem := menuRedo
1149
        |30: menuItem := menuSelectAll
1150
        |33: menuItem := menuSearch
1151
        |34: menuItem := menuGoto
1152
        |44: menuItem := menuUndo
1153
        |45: menuItem := menuCut
1154
        |46: menuItem := menuCopy
1155
        |47: menuItem := menuPaste
1156
        |24: menuItem := menuOpen
1157
        |31: menuItem := menuSave
1158
        |49: menuItem := menuNew
1159
        |67: menuItem := menuBuild
1160
        ELSE
1161
        END
1162
    ELSE
1163
        IF key DIV 65536 = 83 THEN
1164
            menuItem := menuDelete
1165
        ELSIF key DIV 65536 = 67 THEN
1166
            menuItem := menuRun
1167
        END
1168
    END;
1169
    IF menuItem # -1 THEN
1170
        IF Menu.isEnabled(menu, menuItem) THEN
1171
            MenuItemClick(menu, menuItem)
1172
        ELSE
1173
            menuItem := -1
1174
        END
1175
    END
1176
    RETURN menuItem # -1
1177
END MenuKeyDown;
1178
 
1179
 
1180
PROCEDURE CreateContextMenu (): Menu.tMenu;
1181
VAR
1182
    menu: List.tList;
1183
BEGIN
1184
    menu := List.create(NIL);
1185
    Menu.AddMenuItem(menu, menuUndo,      "undo         ctrl-Z");
1186
    Menu.AddMenuItem(menu, menuRedo,      "redo         ctrl-Y");
1187
    Menu.delimiter(menu);
1188
    Menu.AddMenuItem(menu, menuCut,       "cut          ctrl-X");
1189
    Menu.AddMenuItem(menu, menuCopy,      "copy         ctrl-C");
1190
    Menu.AddMenuItem(menu, menuPaste,     "paste        ctrl-V");
1191
    Menu.AddMenuItem(menu, menuDelete,    "delete");
1192
    Menu.delimiter(menu);
1193
    Menu.AddMenuItem(menu, menuSelectAll, "select all   ctrl-A");
1194
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1195
END CreateContextMenu;
1196
 
1197
 
1198
PROCEDURE CreateMenuFile (): Menu.tMenu;
1199
VAR
1200
    menu: List.tList;
1201
BEGIN
1202
    menu := List.create(NIL);
9050 leency 1203
    Menu.AddMenuItem(menu, menuNew,     "new         ctrl-N");
1204
    Menu.AddMenuItem(menu, menuOpen,    "open        ctrl-O");
1205
    Menu.AddMenuItem(menu, menuSave,    "save        ctrl-S");
1206
    Menu.AddMenuItem(menu, menuSaveAs,  "save as");
1207
    Menu.AddMenuItem(menu, menuSaveAll, "save all");
1208
    Menu.AddMenuItem(menu, menuFolder,  "folder");
8728 leency 1209
    Menu.delimiter(menu);
9050 leency 1210
    Menu.AddMenuItem(menu, menuClose,   "close");
1211
    Menu.delimiter(menu);
1212
    Menu.AddMenuItem(menu, menuExit,    "exit");
8728 leency 1213
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1214
END CreateMenuFile;
1215
 
1216
 
1217
PROCEDURE CreateMenuEdit (): Menu.tMenu;
1218
VAR
1219
    menu: List.tList;
1220
BEGIN
1221
    menu := List.create(NIL);
1222
    Menu.AddMenuItem(menu, menuUndo,      "undo          ctrl-Z");
1223
    Menu.AddMenuItem(menu, menuRedo,      "redo          ctrl-Y");
1224
    Menu.delimiter(menu);
1225
    Menu.AddMenuItem(menu, menuSearch,    "search        ctrl-F");
1226
    Menu.AddMenuItem(menu, menuGoto,      "go to line    ctrl-G");
1227
    Menu.delimiter(menu);
1228
    Menu.AddMenuItem(menu, menuCut,       "cut           ctrl-X");
1229
    Menu.AddMenuItem(menu, menuCopy,      "copy          ctrl-C");
1230
    Menu.AddMenuItem(menu, menuPaste,     "paste         ctrl-V");
1231
    Menu.AddMenuItem(menu, menuDelete,    "delete");
1232
    Menu.delimiter(menu);
1233
    Menu.AddMenuItem(menu, menuSelectAll, "select all    ctrl-A");
1234
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1235
END CreateMenuEdit;
1236
 
1237
 
1238
PROCEDURE CreateMenuEncoding (): Menu.tMenu;
1239
VAR
1240
    menu: List.tList;
1241
BEGIN
1242
    menu := List.create(NIL);
1243
    Menu.AddMenuItem(menu, menuUTF8BOM, "UTF-8-BOM");
1244
    Menu.AddMenuItem(menu, menuUTF8,    "UTF-8");
1245
    Menu.AddMenuItem(menu, menuCP866,   "CP866");
1246
    Menu.AddMenuItem(menu, menuWin1251, "Windows-1251");
1247
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1248
END CreateMenuEncoding;
1249
 
1250
 
1251
PROCEDURE CreateMenuView (): Menu.tMenu;
1252
VAR
1253
    menu: List.tList;
1254
    colors: Ini.tSection;
1255
    idx: INTEGER;
1256
BEGIN
1257
    menu := List.create(NIL);
8762 leency 1258
    Menu.AddMenuItem(menu, menuNumbers, "line numbers");
8772 leency 1259
    Menu.AddMenuItem(menu, menuFontSize, "x2");
8728 leency 1260
    Menu.delimiter(menu);
1261
 
1262
    colors := Ini.sections.first(Ini.tSection);
1263
    idx := menuColors;
1264
    WHILE colors # NIL DO
1265
        Menu.AddMenuItem(menu, idx, colors.name);
1266
        INC(idx);
1267
        colors := colors.next(Ini.tSection)
1268
    END;
1269
 
1270
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1271
END CreateMenuView;
1272
 
1273
 
1274
PROCEDURE CreateMenuSyntax (): Menu.tMenu;
1275
VAR
1276
    menu: List.tList;
1277
BEGIN
1278
    menu := List.create(NIL);
1279
    Menu.AddMenuItem(menu, menuC,      "C");
1280
    Menu.AddMenuItem(menu, menuFasm,   "Fasm");
1281
    Menu.AddMenuItem(menu, menuIni,    "Ini");
1282
    Menu.AddMenuItem(menu, menuLua,    "Lua");
1283
    Menu.AddMenuItem(menu, menuOberon, "Oberon");
1284
    Menu.AddMenuItem(menu, menuPascal, "Pascal");
1285
    Menu.delimiter(menu);
1286
    Menu.AddMenuItem(menu, menuNone,   "none");
1287
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1288
END CreateMenuSyntax;
1289
 
1290
 
1291
PROCEDURE CreateMenuProgram (): Menu.tMenu;
1292
VAR
1293
    menu: List.tList;
1294
BEGIN
1295
    menu := List.create(NIL);
1296
    Menu.AddMenuItem(menu, menuBuild,       "build    ctrl+F9");
1297
    Menu.AddMenuItem(menu, menuBuildScript, "script");
1298
    Menu.delimiter(menu);
1299
    Menu.AddMenuItem(menu, menuRun,         "run           F9");
1300
    Menu.AddMenuItem(menu, menuRunScript,   "script");
1301
    Menu.delimiter(menu);
1302
    Menu.AddMenuItem(menu, menuDebug,       "debug");
1303
    Menu.AddMenuItem(menu, menuDebugScript, "script");
1304
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1305
END CreateMenuProgram;
1306
 
1307
 
1308
PROCEDURE CreateMenuTools (): Menu.tMenu;
1309
VAR
1310
    menu: List.tList;
1311
BEGIN
1312
    menu := List.create(NIL);
1313
    Menu.AddMenuItem(menu, menuPipet,   "pipet");
1314
    Menu.AddMenuItem(menu, menuSysFunc, "system functions");
1315
    RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
1316
END CreateMenuTools;
1317
 
1318
 
1319
PROCEDURE CanvasToScreen (VAR x, y: INTEGER);
1320
VAR
1321
    cliX, cliY,
1322
    winX, winY: INTEGER;
1323
BEGIN
1324
    K.WinPos(winX, winY);
1325
    K.ClientPos(cliX, cliY);
1326
    x := x + winX + cliX + LEFT;
1327
    y := y + winY + cliY + TOP;
1328
END CanvasToScreen;
1329
 
1330
 
1331
PROCEDURE ShowMenu (menu: Menu.tMenu);
1332
VAR
1333
    winX, winY, cliX, cliY, x, y, i: INTEGER;
1334
    selected: BOOLEAN;
1335
BEGIN
1336
    IF menu # context THEN
1337
        K.WinPos(winX, winY);
1338
        K.ClientPos(cliX, cliY);
1339
        x := winX + cliX;
1340
        y := MainMenuHeight + winY + cliY
1341
    ELSE
1342
        mouse(x, y);
1343
        IF ~((0 <= x) & (x < canvas.width) & (0 <= y) & (y < canvas.height)) THEN
1344
            menu := NIL
1345
        END
1346
    END;
1347
 
1348
    IF menu = menuFile THEN
1349
        Menu.setEnabled(menu, menuSave, text.modified);
1350
        Menu.setEnabled(menu, menuFolder, text.fileName # "");
9050 leency 1351
        i := 0;
1352
        WHILE (i < textsCount) & ~texts[i].modified DO
1353
            INC(i)
1354
        END;
1355
        Menu.setEnabled(menu, menuSaveAll, i < textsCount);
8728 leency 1356
        INC(x, menuFileX)
1357
    ELSIF (menu = menuEdit) OR (menu = context) THEN
1358
        Menu.setEnabled(menu, menuUndo, ~ChangeLog.isFirstGuard(text.edition));
1359
        Menu.setEnabled(menu, menuRedo, ~ChangeLog.isLastGuard(text.edition));
1360
        selected := T.selected(text);
1361
        Menu.setEnabled(menu, menuCut, selected);
1362
        Menu.setEnabled(menu, menuCopy, selected);
1363
        Menu.setEnabled(menu, menuDelete, selected);
1364
        Menu.setEnabled(menu, menuPaste, CB.available());
1365
        IF menu = menuEdit THEN
1366
            INC(x, menuEditX)
1367
        ELSE
1368
            IF y + menu.height >= canvas.height THEN
1369
                DEC(y, menu.height)
1370
            END;
1371
            IF x + menu.width >= canvas.width THEN
1372
                DEC(x, menu.width)
1373
            END;
1374
            CanvasToScreen(x, y)
1375
        END
1376
    ELSIF menu = menuEncoding THEN
1377
        Menu.setCheck(menu, menuUTF8BOM, ORD(text.enc = E.UTF8BOM)*2);
1378
        Menu.setCheck(menu, menuUTF8,    ORD(text.enc = E.UTF8)*2);
1379
        Menu.setCheck(menu, menuCP866,   ORD(text.enc = E.CP866)*2);
1380
        Menu.setCheck(menu, menuWin1251, ORD(text.enc = E.W1251)*2);
1381
        INC(x, menuEncodingX)
1382
    ELSIF menu = menuView THEN
8772 leency 1383
        Menu.setCheck(menu, menuNumbers,  ORD(text.numbers));
1384
        Menu.setCheck(menu, menuFontSize, ORD(font = font2));
8728 leency 1385
        FOR i := 0 TO Ini.sections.count - 1 DO
1386
            Menu.setCheck(menu, menuColors + i, ORD(Ini.curSectionNum = i)*2)
1387
        END;
1388
        INC(x, menuViewX)
1389
    ELSIF menu = menuSyntax THEN
1390
        Menu.setCheck(menu, menuNone,   ORD(text.lang = Languages.langNone)*2);
1391
        Menu.setCheck(menu, menuC,      ORD(text.lang = Languages.langC)*2);
1392
        Menu.setCheck(menu, menuFasm,   ORD(text.lang = Languages.langFasm)*2);
1393
        Menu.setCheck(menu, menuIni,    ORD(text.lang = Languages.langIni)*2);
1394
        Menu.setCheck(menu, menuLua,    ORD(text.lang = Languages.langLua)*2);
1395
        Menu.setCheck(menu, menuOberon, ORD(text.lang = Languages.langOberon)*2);
1396
        Menu.setCheck(menu, menuPascal, ORD(text.lang = Languages.langPascal)*2);
1397
        INC(x, menuSyntaxX)
1398
    ELSIF menu = menuProgram THEN
1399
        Menu.setEnabled(menu, menuBuild, buildScript # "");
1400
        Menu.setEnabled(menu, menuDebug, debugScript # "");
1401
        Menu.setEnabled(menu, menuRun, runScript # "");
1402
        INC(x, menuProgramX)
1403
    ELSIF menu = menuTools THEN
1404
        INC(x, menuToolsX)
1405
    END;
1406
 
1407
    IF menu # NIL THEN
1408
        IF Menu.opened(menu) THEN
1409
            Menu.close(menu)
1410
        END;
1411
        Menu.open(menu, x, y)
1412
    END
1413
END ShowMenu;
1414
 
1415
 
1416
PROCEDURE main;
1417
VAR
8772 leency 1418
    width, height, x, y, scrollX, scrollY, i: INTEGER;
9050 leency 1419
    key, btn: INTEGER;
8728 leency 1420
    msState: SET;
1421
    scroll: INTEGER;
1422
    err: INTEGER;
1423
    fileName, filePath: RW.tFileName;
8762 leency 1424
    cliWidth, cliHeight: INTEGER;
8728 leency 1425
    resized: BOOLEAN;
1426
    firstClickX, firstClickY, time: INTEGER;
1427
BEGIN
8762 leency 1428
    K.GetSystemColors;
1429
    Icons.get(icons, grayIcons);
8728 leency 1430
    modified := FALSE;
9050 leency 1431
    switch := FALSE;
1432
    textsCount := 0;
1433
    curText := 0;
8728 leency 1434
    mainTID := K.ThreadID();
1435
    K.SetIPC(IPC);
1436
    U.ptr2str(K.GetName(), AppPath);
1437
    Ini.load(AppPath);
1438
    K.SetEventsMask({0, 1, 2, 5, 6, 31});
1439
    LeftButtonUp;
1440
    resized := FALSE;
1441
    shift := {};
8772 leency 1442
    K.ScreenSize(winWidth, winHeight);
9050 leency 1443
    winWidth := (winWidth*80) DIV 100 - (128 + 30);
8772 leency 1444
    winHeight := winHeight - (128 + 30);
1445
    winWidth := MAX(winWidth, minWinWidth);
1446
    winHeight := MAX(winHeight, minWinHeight);
8762 leency 1447
    cliWidth := winWidth;
1448
    cliHeight := winHeight;
8859 leency 1449
    LEFT := searchLeft;
8728 leency 1450
    canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 10), winHeight - (TOP + BOTTOM + 4) - K.SkinHeight());
9050 leency 1451
    tabs := Tabs.create();
1452
    Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight);
8772 leency 1453
    font1 := G.CreateFont(1, "", {});
1454
    font2 := G.CreateFont(2, "", {});
1455
    font := font1;
8728 leency 1456
    G.SetFont(canvas, font);
1457
    T.init(NIL);
1458
    T.setCanvas(canvas);
1459
    U.ptr2str(K.GetCommandLine(), fileName);
1460
    context := CreateContextMenu();
1461
    menuFile := CreateMenuFile();
1462
    menuEdit := CreateMenuEdit();
1463
    menuEncoding := CreateMenuEncoding();
1464
    menuView := CreateMenuView();
1465
    menuSyntax := CreateMenuSyntax();
1466
    menuProgram := CreateMenuProgram();
1467
    menuTools := CreateMenuTools();
1468
    IF fileName = "" THEN
1469
        text := T.New();
1470
        filePath := "/rd/1"
1471
    ELSE
1472
        text := T.open(fileName, err);
1473
        IF text = NIL THEN
1474
            error("'cedit: error opening file' -E");
1475
            K.Exit
1476
        ELSE
1477
            U.getPath(fileName, filePath)
1478
        END
1479
    END;
1480
    OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, "");
9050 leency 1481
    insert(0, text);
8728 leency 1482
 
8762 leency 1483
    vScroll := Scroll.create(scrollWidth, canvas.height - scrollWidth*2 + 1);
1484
    hScroll := Scroll.create(canvas.width - scrollWidth*2, scrollWidth);
8728 leency 1485
    T.resize(canvas.width, canvas.height);
1486
    T.SetPos(text, 0, 0);
1487
    confirm := FALSE;
1488
    notFound := FALSE;
1489
    search := FALSE;
1490
    createSearchForm;
1491
    new_searchText := "";
1492
    searchText := "";
1493
    cs := FALSE;
1494
    whole := FALSE;
1495
    replaced := 0;
9010 leency 1496
    Ini.getStr("paths", "build", buildScript);
1497
    Ini.getStr("paths", "run",   runScript);
1498
    Ini.getStr("paths", "debug", debugScript);
8728 leency 1499
    draw_window;
1500
    repaint;
1501
    WHILE TRUE DO
1502
        CASE K.WaitForEvent() OF
1503
        |1:
8772 leency 1504
            FOR i := 0 TO 1 DO
1505
                K.GetSystemColors;
1506
                Icons.get(icons, grayIcons);
1507
                IF ~K.RolledUp() THEN
1508
                    K.ClientSize(width, height);
1509
                    IF (width # cliWidth) OR (height # cliHeight) THEN
1510
                        cliWidth := width;
1511
                        cliHeight := height;
1512
                        resize;
1513
                        resized := TRUE;
1514
                    END;
1515
                    K.SetEventsMask({0, 1, 2, 5, 6, 31})
1516
                ELSE
1517
                    K.SetEventsMask({0, 30, 31})
8728 leency 1518
                END;
8772 leency 1519
                draw_window
1520
            END
1521
 
8728 leency 1522
        |2:
1523
            key := K.GetKey();
1524
            getKBState;
8848 leency 1525
            IF confirm THEN
1526
                IF key DIV 65536 = 28 THEN (* Enter *)
9050 leency 1527
                    save(text);
8848 leency 1528
                    IF ~text.modified THEN
9050 leency 1529
                        closeFile(FALSE)
8848 leency 1530
                    END;
1531
                    repaint
1532
                END;
1533
                key := -1
1534
            END;
8728 leency 1535
            IF key DIV 65536 = 61 THEN (* F3 *)
1536
                key := -1;
1537
                IF search & (searchText # "") THEN
8772 leency 1538
                    IF T.SHIFT IN shift THEN
1539
                        notFound := ~T.findNext(text, ~box_lib.check_box_get_value(BKW))
1540
                    ELSE
1541
                        notFound := ~T.findNext(text, box_lib.check_box_get_value(BKW))
1542
                    END
8728 leency 1543
                END
1544
            ELSIF key DIV 65536 = 67 THEN (* F9 *)
1545
                key := -1;
1546
                IF T.CTRL IN shift THEN
1547
                    Script(buildScript)
1548
                ELSE
1549
                    Script(runScript)
1550
                END
8848 leency 1551
            ELSIF key DIV 65536 = 1 THEN (* Esc *)
1552
                key := -1;
8772 leency 1553
                IF search THEN
1554
                    Search
1555
                END
8728 leency 1556
            ELSIF (key DIV 65536 = 55) & (key DIV 256 MOD 256 = 52) THEN
1557
                key := -1 (* PrtScn *)
1558
            ELSIF (T.CTRL IN shift) & (key DIV 65536 = 33) THEN
1559
                key := -1;
1560
                IF ~search THEN
1561
                    Search
1562
                END;
1563
                EditBox_SetFocus(FindEdit, TRUE);
1564
                EditBox_SetFocus(ReplaceEdit, FALSE);
1565
                EditBox_SetFocus(GotoEdit, FALSE);
1566
            ELSIF (T.CTRL IN shift) & (key DIV 65536 = 34) THEN
1567
                key := -1;
1568
                IF ~search THEN
1569
                    Search
1570
                END;
1571
                EditBox_SetFocus(GotoEdit, TRUE);
1572
                EditBox_SetFocus(FindEdit, FALSE);
1573
                EditBox_SetFocus(ReplaceEdit, FALSE)
1574
            END;
1575
            IF (key # -1) & EditBox_Focus(FindEdit) THEN
1576
                box_lib.edit_box_key(FindEdit, key);
1577
                EditBox_GetValue(FindEdit, new_searchText);
1578
                IF new_searchText # searchText THEN
1579
                    searchText := new_searchText;
1580
                    notFound := ~T.search(text, searchText, cs, whole)
1581
                END
1582
            ELSIF (key # -1) & EditBox_Focus(ReplaceEdit) THEN
1583
                box_lib.edit_box_key(ReplaceEdit, key);
1584
                EditBox_GetValue(ReplaceEdit, replaceText)
1585
            ELSIF (key # -1) & EditBox_Focus(GotoEdit) THEN
1586
                IF (key DIV 256) MOD 256 = 13 THEN
1587
                    goto
1588
                ELSE
1589
                    box_lib.edit_box_key(GotoEdit, key)
1590
                END
1591
            ELSIF key # -1 THEN
1592
                CASE key DIV 65536 OF
1593
                |73: key := 33
1594
                |81: key := 34
1595
                |71: key := 36
1596
                |79: key := 35
1597
                |72: key := 38
1598
                |80: key := 40
1599
                |75: key := 37
1600
                |77: key := 39
1601
                |82: key := -1 (* insert *)
1602
                |83: key := 46
1603
                |59, 60, 62..66, 68, 87, 88: key := -1 (* F1, F2, F4..F8, F10, F11, F12 *)
1604
                ELSE
1605
                    IF (T.CTRL IN shift) THEN
1606
                        CASE key DIV 65536 OF
1607
                        |21: T.redo(text);
1608
                             key := -1
1609
                        |22: key := ORD("U")
1610
                        |24: key := -1;
1611
                             open
1612
                        |30: key := ORD("A")
1613
                        |31: key := -1;
9050 leency 1614
                             save(text)
9010 leency 1615
                        |32: key := ORD("D")
8728 leency 1616
                        |38: key := ORD("L")
1617
                        |44: T.undo(text);
1618
                             key := -1
1619
                        |45: key := ORD("X")
1620
                        |46: key := ORD("C")
1621
                        |47: key := ORD("V")
1622
                        |49: key := -1;
9050 leency 1623
                             NewFile
8728 leency 1624
                        ELSE
1625
                            key := -1
1626
                        END
1627
                    ELSE
1628
                        T.input(text, E.cp866[key DIV 256 MOD 256]);
1629
                        key := -1
1630
                    END
1631
                END;
1632
                IF key # -1 THEN
1633
                    T.key(text, key, shift)
1634
                END
1635
            END;
1636
            repaint
1637
        |3:
9050 leency 1638
            btn := K.ButtonCode();
1639
            CASE btn OF
1640
            |Tabs.btnID .. Tabs.btnID + maxTexts - 1:
1641
                DEC(btn, Tabs.btnID);
1642
                curText := btn;
1643
                Tabs.switch(tabs, btn);
1644
                Switch(texts[btn]);
1645
                draw_window
1646
            |Tabs.btnID - 1: Tabs.scroll(tabs, -1); switch := TRUE; repaint
1647
            |Tabs.btnID - 2: Tabs.scroll(tabs, +1); switch := TRUE; repaint
1648
 
8728 leency 1649
            |0:
1650
 
1651
            |btnFile:
1652
                ShowMenu(menuFile)
1653
            |btnEdit:
1654
                ShowMenu(menuEdit)
1655
            |btnEncoding:
1656
                ShowMenu(menuEncoding)
1657
            |btnView:
1658
                ShowMenu(menuView)
1659
            |btnSyntax:
1660
                ShowMenu(menuSyntax)
1661
            |btnProgram:
1662
                ShowMenu(menuProgram)
1663
            |btnTools:
1664
                ShowMenu(menuTools)
1665
            |btnNo:
9050 leency 1666
                closeFile(FALSE);
1667
                repaint
8728 leency 1668
            |btnYes:
9050 leency 1669
                save(text);
8728 leency 1670
                IF ~text.modified THEN
9050 leency 1671
                    closeFile(FALSE)
8728 leency 1672
                END;
1673
                repaint
1674
            |btnClose:
1675
                close
1676
            |btnNew:
9050 leency 1677
                NewFile;
1678
                repaint
8728 leency 1679
            |btnOpen:
1680
                open
1681
            |btnSave:
9050 leency 1682
                save(text);
8728 leency 1683
                repaint
1684
            |btnSearch:
1685
                IF ~search THEN
1686
                    Search
1687
                END
1688
            |btnCloseFind:
1689
                Search
1690
            |btnUndo:
1691
                T.undo(text);
1692
                repaint
1693
            |btnRedo:
1694
                T.redo(text);
1695
                repaint
1696
            |btnUpper:
1697
                T.chCase(text, TRUE);
1698
                repaint
1699
            |btnLower:
1700
                T.chCase(text, FALSE);
1701
                repaint
1702
            |btnBuild:
1703
                Script(buildScript)
1704
            |btnRun:
1705
                Script(runScript)
1706
            |btnUp:
1707
                T.scroll(text, 0, -1);
1708
                repaint
1709
            |btnDown:
1710
                T.scroll(text, 0, 1);
1711
                repaint
1712
            |btnLeft:
1713
                T.scroll(text, -1, 0);
1714
                repaint
1715
            |btnRight:
1716
                T.scroll(text, 1, 0);
1717
                repaint
1718
            |btnFindEdit:
1719
                EditBox_SetFocus(FindEdit, TRUE);
1720
                EditBox_SetFocus(ReplaceEdit, FALSE);
1721
                EditBox_SetFocus(GotoEdit, FALSE)
1722
            |btnReplaceEdit:
1723
                EditBox_SetFocus(ReplaceEdit, TRUE);
1724
                EditBox_SetFocus(FindEdit, FALSE);
1725
                EditBox_SetFocus(GotoEdit, FALSE)
1726
            |btnGotoEdit:
1727
                EditBox_SetFocus(GotoEdit, TRUE);
1728
                EditBox_SetFocus(FindEdit, FALSE);
1729
                EditBox_SetFocus(ReplaceEdit, FALSE)
1730
            |btnFindNext:
1731
                IF searchText # "" THEN
1732
                    notFound := ~T.findNext(text, box_lib.check_box_get_value(BKW));
1733
                    repaint
1734
                END
1735
            |btnReplace:
1736
                T.replace(text, replaceText, LENGTH(searchText));
1737
                repaint
1738
            |btnReplaceAll:
1739
                notFound := ~T.search(text, searchText, cs, whole);
1740
                IF ~notFound THEN
1741
                    replaced := T.replaceAll(text, replaceText, LENGTH(searchText));
1742
                END;
1743
                repaint
1744
            |btnGoto:
1745
                goto;
1746
                repaint
1747
            END
1748
        |6:
1749
            Menu.close(menuFile);
1750
            Menu.close(menuEdit);
1751
            Menu.close(menuEncoding);
1752
            Menu.close(menuView);
1753
            Menu.close(menuSyntax);
1754
            Menu.close(menuProgram);
1755
            Menu.close(menuTools);
1756
            Menu.close(context);
1757
            IF ~resized THEN
1758
                getKBState;
1759
                msState := K.MouseState();
1760
                IF ~(0 IN msState) OR (16 IN msState) THEN
1761
                    LeftButtonUp
1762
                END;
1763
                scroll := K.Scroll();
1764
                IF scroll # 0 THEN
1765
                    T.scroll(text, 0, scroll*3);
1766
                    repaint
1767
                END;
1768
                IF leftButton THEN
1769
                    IF K.GetTickCount() - time > 9 THEN
1770
                        mouse(x, y);
1771
                        T.mouse(text, x, y);
1772
                        repaint
1773
                    END
1774
                END;
1775
                IF VScroll THEN
1776
                    mouse(x, y);
1777
                    Scroll.mouse(vScroll, x, y - scrollWidth);
1778
                    T.getScroll(text, scrollX, scrollY);
1779
                    T.scroll(text, 0, vScroll.value - scrollY);
1780
                    repaint
1781
                END;
1782
                IF HScroll THEN
1783
                    mouse(x, y);
1784
                    Scroll.mouse(hScroll, x - scrollWidth, y);
1785
                    T.getScroll(text, scrollX, scrollY);
1786
                    T.scroll(text, hScroll.value - scrollX, 0);
1787
                    repaint
1788
                END;
1789
                IF (8 IN msState) & ~(24 IN msState) THEN
1790
                    mouse(firstClickX, firstClickY);
1791
                    time := click(firstClickX, firstClickY)
1792
                END;
1793
                IF 9 IN msState THEN
1794
                    ShowMenu(context)
1795
                END;
1796
                IF 24 IN msState THEN
1797
                    mouse(x, y);
1798
                    IF (ABS(x - firstClickX) < 5) & (ABS(y - firstClickY) < 5) THEN
1799
                        VScroll := FALSE;
1800
                        HScroll := FALSE;
1801
                        IF (0 <= x) & (x < canvas.width) & (0 <= y) & (y < canvas.height) THEN
1802
                            leftButton := FALSE;
1803
                            T.selectWord(text);
1804
                            repaint
1805
                        END
1806
                    ELSE
1807
                        firstClickX := x;
1808
                        firstClickY := y;
1809
                        time := click(firstClickX, firstClickY)
1810
                    END
1811
                END
1812
            END;
1813
            IF search THEN
1814
                IF EditBox_Focus(FindEdit) THEN
1815
                    box_lib.edit_box_mouse(FindEdit)
1816
                END;
1817
                IF EditBox_Focus(ReplaceEdit) THEN
1818
                    box_lib.edit_box_mouse(ReplaceEdit)
1819
                END;
1820
                IF EditBox_Focus(GotoEdit) THEN
1821
                    box_lib.edit_box_mouse(GotoEdit)
1822
                END;
1823
                box_lib.check_box_mouse2(CS);
1824
                box_lib.check_box_mouse2(WH);
1825
                box_lib.check_box_mouse2(BKW);
1826
                IF box_lib.check_box_get_value(CS) # cs THEN
1827
                    cs := ~cs;
1828
                    notFound := ~T.search(text, searchText, cs, whole);
1829
                    repaint
1830
                END;
1831
                IF box_lib.check_box_get_value(WH) # whole THEN
1832
                    whole := ~whole;
1833
                    notFound := ~T.search(text, searchText, cs, whole);
1834
                    repaint
1835
                END
1836
            END;
1837
            resized := FALSE
1838
        |7: receiveIPC
1839
        ELSE
1840
        END
1841
    END
1842
END main;
1843
 
1844
 
1845
BEGIN
1846
    main
1847
END CEdit.