2021-05-23 11:43:28 +02:00
|
|
|
(*
|
2022-01-12 22:15:22 +01:00
|
|
|
Copyright 2021, 2022 Anton Krotov
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
This file is part of CEdit.
|
|
|
|
|
|
|
|
CEdit is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
CEdit is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with CEdit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE Menu;
|
|
|
|
|
|
|
|
IMPORT
|
2021-12-20 20:09:01 +01:00
|
|
|
SYSTEM, G := Graph, List, K := KolibriOS;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
CONST
|
2021-09-03 01:15:33 +02:00
|
|
|
fontHeight = 22;
|
2021-05-23 11:43:28 +02:00
|
|
|
fontWidth = 8;
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
MainMenuHeight* = K.fontHeight + 7;
|
2021-12-29 16:38:29 +01:00
|
|
|
MainMenuX* = 3;
|
2021-09-11 22:57:43 +02:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
RIGHT = 16;
|
|
|
|
LEFT = 16;
|
|
|
|
TOP = 1;
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
maxLEVEL = 1;
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
backColor = 0F0F0F0H;
|
|
|
|
foreColor = 0;
|
|
|
|
selBackColor = 091C9F7H;
|
|
|
|
selForeColor = 0;
|
|
|
|
disBackColor = backColor;
|
|
|
|
disForeColor = 808080H;
|
|
|
|
disSelBackColor = 0E4E4E4H;
|
|
|
|
disSelForeColor = disForeColor;
|
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
SHIFT* = 256;
|
|
|
|
CTRL* = 512;
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
tMainItem* = POINTER TO descMainItem;
|
|
|
|
|
|
|
|
tMain* = POINTER TO RECORD (List.tList)
|
|
|
|
id: INTEGER
|
|
|
|
END;
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
tMenu* = POINTER TO RECORD
|
|
|
|
tid*: INTEGER;
|
2021-09-11 22:57:43 +02:00
|
|
|
active*, keyboard: BOOLEAN;
|
2021-09-03 01:15:33 +02:00
|
|
|
parent*, child: tMenu;
|
2021-09-11 22:57:43 +02:00
|
|
|
mainID: INTEGER;
|
2021-05-23 11:43:28 +02:00
|
|
|
winX, winY, width*, height*: INTEGER;
|
|
|
|
selItem, cliItem: INTEGER;
|
|
|
|
|
|
|
|
font: G.tFont;
|
|
|
|
canvas: G.tCanvas;
|
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
items: List.tList
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
tItem* = POINTER TO RECORD (List.tItem)
|
|
|
|
id*, check: INTEGER;
|
|
|
|
text: ARRAY 32 OF WCHAR;
|
|
|
|
enabled, delim: BOOLEAN;
|
|
|
|
child: tMenu
|
|
|
|
END;
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
descMainItem = RECORD (List.tItem)
|
|
|
|
id*, x: INTEGER;
|
|
|
|
text: ARRAY 32 OF WCHAR;
|
|
|
|
menu*: tMenu;
|
|
|
|
main: tMain
|
|
|
|
END;
|
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
tShortcut = POINTER TO RECORD (List.tItem)
|
|
|
|
key, MenuItem: INTEGER
|
|
|
|
END;
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
tClick = PROCEDURE (menu: tMenu; id: INTEGER);
|
2021-09-03 01:15:33 +02:00
|
|
|
tProc = PROCEDURE;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
VAR
|
2022-01-18 17:23:19 +01:00
|
|
|
MenuItem*: INTEGER;
|
2021-12-29 16:38:29 +01:00
|
|
|
stack: ARRAY maxLEVEL + 1, 2500 OF INTEGER;
|
2021-09-03 01:15:33 +02:00
|
|
|
TIDs: ARRAY maxLEVEL + 1 OF INTEGER;
|
|
|
|
resetTimer: tProc;
|
|
|
|
_open: PROCEDURE (m: tMenu; x, y: INTEGER);
|
2022-01-18 17:23:19 +01:00
|
|
|
shortcuts: List.tList;
|
2021-09-03 18:20:40 +02:00
|
|
|
(*
|
|
|
|
backColor, foreColor, selBackColor, selForeColor,
|
|
|
|
disBackColor, disForeColor, disSelBackColor, disSelForeColor: INTEGER;
|
|
|
|
*)
|
2021-09-03 01:15:33 +02:00
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
PROCEDURE AddMainItem* (main: tMain; text: ARRAY OF WCHAR; menu: tMenu);
|
|
|
|
VAR
|
|
|
|
item, prev: tMainItem;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
|
|
|
item.id := main.id + main.count;
|
|
|
|
COPY(text, item.text);
|
|
|
|
item.menu := menu;
|
|
|
|
item.main := main;
|
|
|
|
menu.mainID := item.id;
|
|
|
|
List.append(main, item);
|
|
|
|
prev := item.prev(tMainItem);
|
|
|
|
IF prev # NIL THEN
|
|
|
|
item.x := prev.x + LENGTH(prev.text)*fontWidth + 9
|
|
|
|
ELSE
|
2021-12-22 16:56:11 +01:00
|
|
|
item.x := MainMenuX
|
2021-09-11 22:57:43 +02:00
|
|
|
END
|
|
|
|
END AddMainItem;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE CreateMain* (id: INTEGER): tMain;
|
|
|
|
VAR
|
|
|
|
res: tMain;
|
|
|
|
list: List.tList;
|
|
|
|
BEGIN
|
|
|
|
NEW(res);
|
|
|
|
res.id := id;
|
|
|
|
list := List.create(res)
|
|
|
|
RETURN res
|
|
|
|
END CreateMain;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE drawMainItem (item: tMainItem);
|
|
|
|
VAR
|
|
|
|
menuColor, textColor, n: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
IF item.menu.tid # 0 THEN
|
2022-01-12 22:15:22 +01:00
|
|
|
menuColor := K.colors.work_text;
|
|
|
|
textColor := K.colors.work
|
2021-09-11 22:57:43 +02:00
|
|
|
ELSE
|
2022-01-12 22:15:22 +01:00
|
|
|
menuColor := K.colors.work;
|
|
|
|
textColor := K.colors.work_text
|
2021-09-11 22:57:43 +02:00
|
|
|
END;
|
|
|
|
n := LENGTH(item.text);
|
|
|
|
K.DrawRect(item.x, 0, n*fontWidth + 2, MainMenuHeight, menuColor);
|
2022-01-12 22:15:22 +01:00
|
|
|
K.CreateButton(item.id + ORD({30}), item.x, 0, n*fontWidth + 2, MainMenuHeight, K.colors.button, "");
|
2021-09-11 22:57:43 +02:00
|
|
|
K.DrawText(item.x + 1, (MainMenuHeight - K.fontHeight) DIV 2 + 1, textColor, item.text)
|
|
|
|
END drawMainItem;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE DrawMain* (main: tMain);
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
|
|
|
BEGIN
|
|
|
|
item := main.first;
|
|
|
|
WHILE item # NIL DO
|
|
|
|
drawMainItem(item(tMainItem));
|
|
|
|
item := item.next
|
|
|
|
END
|
|
|
|
END DrawMain;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE getMainID (m: tMenu): INTEGER;
|
|
|
|
BEGIN
|
|
|
|
WHILE m.parent # NIL DO
|
|
|
|
m := m.parent
|
|
|
|
END
|
|
|
|
RETURN m.mainID
|
|
|
|
END getMainID;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ClickMain* (main: tMain; btn: INTEGER): tMenu;
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
|
|
|
res: tMenu;
|
|
|
|
BEGIN
|
|
|
|
item := List.getItem(main, btn - main.id);
|
|
|
|
IF item # NIL THEN
|
|
|
|
res := item(tMainItem).menu
|
|
|
|
ELSE
|
|
|
|
res := NIL
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END ClickMain;
|
|
|
|
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
PROCEDURE isSender* (tid: INTEGER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
i := 0;
|
|
|
|
WHILE (i <= maxLEVEL) & (TIDs[i] # tid) DO
|
|
|
|
INC(i)
|
|
|
|
END
|
|
|
|
RETURN i <= maxLEVEL
|
|
|
|
END isSender;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE exit (m: tMenu);
|
|
|
|
BEGIN
|
2021-09-03 01:15:33 +02:00
|
|
|
m.active := FALSE;
|
2021-09-11 22:57:43 +02:00
|
|
|
resetTimer;
|
|
|
|
m.tid := 0;
|
2021-05-23 11:43:28 +02:00
|
|
|
K.Exit
|
|
|
|
END exit;
|
|
|
|
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
PROCEDURE escape (m: tMenu);
|
|
|
|
BEGIN
|
|
|
|
m.active := FALSE;
|
|
|
|
IF m.parent = NIL THEN
|
|
|
|
resetTimer
|
|
|
|
END;
|
|
|
|
m.tid := 0;
|
|
|
|
K.Exit
|
|
|
|
END escape;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE repaint (m: tMenu);
|
|
|
|
VAR
|
2022-01-12 22:15:22 +01:00
|
|
|
y, i, X, Y, Y1: INTEGER;
|
2021-05-23 11:43:28 +02:00
|
|
|
item: tItem;
|
|
|
|
BkColor, TextColor: INTEGER;
|
|
|
|
canvas: G.tCanvas;
|
|
|
|
|
|
|
|
BEGIN
|
2021-09-03 18:20:40 +02:00
|
|
|
(*
|
|
|
|
backColor := K.winColor;
|
|
|
|
foreColor := K.textColor;
|
|
|
|
selBackColor := K.btnColor;
|
|
|
|
selForeColor := K.btnTextColor;
|
|
|
|
|
|
|
|
disBackColor := backColor;
|
|
|
|
disForeColor := K.darkColor;
|
|
|
|
disSelBackColor := K.lightColor;
|
|
|
|
disSelForeColor := disForeColor;
|
|
|
|
*)
|
2021-05-23 11:43:28 +02:00
|
|
|
canvas := m.canvas;
|
|
|
|
G.SetColor(canvas, backColor);
|
|
|
|
G.clear(canvas);
|
2021-09-06 23:06:31 +02:00
|
|
|
G.SetColor(canvas, foreColor);
|
2021-05-23 11:43:28 +02:00
|
|
|
G.Rect(canvas, 0, 0, m.width, m.height);
|
|
|
|
y := TOP;
|
|
|
|
i := 0;
|
|
|
|
item := m.items.first(tItem);
|
|
|
|
WHILE item # NIL DO
|
|
|
|
IF item.enabled THEN
|
|
|
|
IF i # m.selItem THEN
|
|
|
|
BkColor := backColor;
|
|
|
|
TextColor := foreColor
|
|
|
|
ELSE
|
|
|
|
BkColor := selBackColor;
|
|
|
|
TextColor := selForeColor
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF i # m.selItem THEN
|
|
|
|
BkColor := disBackColor;
|
|
|
|
TextColor := disForeColor
|
|
|
|
ELSE
|
|
|
|
BkColor := disSelBackColor;
|
|
|
|
TextColor := disSelForeColor
|
|
|
|
END
|
|
|
|
END;
|
2021-12-20 20:09:01 +01:00
|
|
|
Y := y + (fontHeight - 16) DIV 2;
|
2021-05-23 11:43:28 +02:00
|
|
|
G.SetColor(canvas, BkColor);
|
|
|
|
G.FillRect(canvas, 1, y, m.width - 1, y + fontHeight - 4);
|
|
|
|
G.SetTextColor(canvas, TextColor);
|
|
|
|
G.SetBkColor(canvas, BkColor);
|
2021-12-20 20:09:01 +01:00
|
|
|
G.TextOut2(canvas, LEFT, Y - 2, item.text, LENGTH(item.text));
|
2021-05-23 11:43:28 +02:00
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
G.SetColor(canvas, TextColor);
|
2021-05-23 11:43:28 +02:00
|
|
|
IF item.check = 1 THEN
|
2022-01-12 22:15:22 +01:00
|
|
|
G.DLine(canvas, 4, 7, Y + 5, -1);
|
|
|
|
G.DLine(canvas, 4, 7, Y + 6, -1);
|
|
|
|
G.DLine(canvas, 7, 12, Y + 8, 1);
|
|
|
|
G.DLine(canvas, 7, 12, Y + 9, 1)
|
2021-05-23 11:43:28 +02:00
|
|
|
ELSIF item.check = 2 THEN
|
2022-01-12 22:15:22 +01:00
|
|
|
Y1 := y + fontHeight DIV 2 - 2;
|
|
|
|
G.FillRect(canvas, 7, Y1 - 2, 9, Y1 + 2);
|
|
|
|
G.FillRect(canvas, 6, Y1 - 1, 10, Y1 + 1)
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
IF item.child # NIL THEN
|
|
|
|
X := m.width - 9;
|
2021-12-20 20:09:01 +01:00
|
|
|
G.Triangle(canvas, X, Y + 2, X, Y + 10, G.triRight)
|
2021-09-03 01:15:33 +02:00
|
|
|
END;
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
INC(y, fontHeight);
|
|
|
|
IF item.delim THEN
|
2021-09-06 23:06:31 +02:00
|
|
|
G.SetColor(canvas, foreColor);
|
2021-05-23 11:43:28 +02:00
|
|
|
G.HLine(canvas, y - 2, 1, m.width - 1)
|
|
|
|
END;
|
|
|
|
INC(i);
|
|
|
|
item := item.next(tItem)
|
|
|
|
END;
|
|
|
|
G.DrawCanvas(canvas, 0, 0)
|
|
|
|
END repaint;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE draw_window (m: tMenu);
|
|
|
|
BEGIN
|
|
|
|
K.BeginDraw;
|
|
|
|
K.CreateWindow(m.winX, m.winY, m.width, m.height, 0, 61H, 0, 1, "");
|
|
|
|
repaint(m);
|
|
|
|
K.EndDraw
|
|
|
|
END draw_window;
|
|
|
|
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
PROCEDURE close* (m: tMenu);
|
2021-09-11 22:57:43 +02:00
|
|
|
VAR
|
|
|
|
temp: INTEGER;
|
2021-09-03 01:15:33 +02:00
|
|
|
BEGIN
|
|
|
|
IF (m # NIL) & (m.tid # 0) THEN
|
|
|
|
IF m.child # NIL THEN
|
|
|
|
close(m.child);
|
|
|
|
m.child := NIL
|
|
|
|
END;
|
2021-09-11 22:57:43 +02:00
|
|
|
temp := m.tid;
|
|
|
|
m.tid := 0;
|
|
|
|
K.ExitID(temp);
|
2021-09-03 01:15:33 +02:00
|
|
|
m.active := FALSE
|
|
|
|
END
|
|
|
|
END close;
|
|
|
|
|
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
PROCEDURE SetItem* (id: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
MenuItem := id
|
|
|
|
END SetItem;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE click (m: tMenu; i: INTEGER);
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
2021-09-03 01:15:33 +02:00
|
|
|
p: tMenu;
|
2021-09-11 22:57:43 +02:00
|
|
|
id: INTEGER;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2021-09-11 22:57:43 +02:00
|
|
|
id := -1;
|
|
|
|
IF i < 0 THEN
|
|
|
|
id := i
|
|
|
|
ELSE
|
|
|
|
item := List.getItem(m.items, i);
|
|
|
|
IF (item # NIL) & item(tItem).enabled & (item(tItem).child = NIL) THEN
|
|
|
|
id := item(tItem).id
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
IF id # -1 THEN
|
2022-01-18 17:23:19 +01:00
|
|
|
SetItem(id);
|
2021-09-11 22:57:43 +02:00
|
|
|
p := m.parent;
|
|
|
|
WHILE p # NIL DO
|
|
|
|
p.child := NIL;
|
|
|
|
close(p);
|
|
|
|
p := p.parent
|
|
|
|
END;
|
|
|
|
exit(m)
|
|
|
|
END
|
2021-05-23 11:43:28 +02:00
|
|
|
END click;
|
|
|
|
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
PROCEDURE opened* (m: tMenu): BOOLEAN;
|
|
|
|
RETURN m.tid # 0
|
|
|
|
END opened;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isActive (m: tMenu): BOOLEAN;
|
|
|
|
RETURN (m # NIL) & ((m.tid # 0) & m.active OR isActive(m.child))
|
|
|
|
END isActive;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE closeChild (m: tMenu);
|
|
|
|
BEGIN
|
|
|
|
IF m.child # NIL THEN
|
|
|
|
close(m.child);
|
|
|
|
m.child := NIL
|
|
|
|
END
|
|
|
|
END closeChild;
|
|
|
|
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
PROCEDURE submenu (m: tMenu; keyboard: BOOLEAN): BOOLEAN;
|
2021-09-03 01:15:33 +02:00
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
2021-09-11 22:57:43 +02:00
|
|
|
res: BOOLEAN;
|
2021-09-03 01:15:33 +02:00
|
|
|
BEGIN
|
2021-09-11 22:57:43 +02:00
|
|
|
res := FALSE;
|
2021-09-03 01:15:33 +02:00
|
|
|
item := List.getItem(m.items, m.selItem);
|
|
|
|
IF (item # NIL) & item(tItem).enabled & (item(tItem).child # NIL) THEN
|
2021-09-11 22:57:43 +02:00
|
|
|
res := TRUE;
|
2021-09-03 01:15:33 +02:00
|
|
|
IF ~opened(item(tItem).child) THEN
|
|
|
|
closeChild(m);
|
2021-09-11 22:57:43 +02:00
|
|
|
item(tItem).child.keyboard := keyboard;
|
2021-09-03 01:15:33 +02:00
|
|
|
_open(item(tItem).child, m.winX + m.width - 2, m.winY + m.selItem*fontHeight);
|
2021-09-11 22:57:43 +02:00
|
|
|
m.child := item(tItem).child;
|
2021-09-03 01:15:33 +02:00
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
closeChild(m)
|
|
|
|
END
|
2021-09-11 22:57:43 +02:00
|
|
|
RETURN res
|
2021-09-03 01:15:33 +02:00
|
|
|
END submenu;
|
|
|
|
|
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
PROCEDURE getShortcut (key: INTEGER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
item: tShortcut;
|
|
|
|
res: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
item := shortcuts.first(tShortcut);
|
|
|
|
WHILE (item # NIL) & (item.key # key) DO
|
|
|
|
item := item.next(tShortcut)
|
|
|
|
END;
|
|
|
|
IF item # NIL THEN
|
|
|
|
res := item.MenuItem
|
|
|
|
ELSE
|
|
|
|
res := 0
|
|
|
|
END;
|
|
|
|
SetItem(res)
|
|
|
|
RETURN res # 0
|
|
|
|
END getShortcut;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE [stdcall] window (m: tMenu);
|
|
|
|
VAR
|
|
|
|
x, y: INTEGER;
|
|
|
|
msState: SET;
|
2021-12-20 20:09:01 +01:00
|
|
|
key, temp: INTEGER;
|
2021-09-11 22:57:43 +02:00
|
|
|
shift, ctrl: BOOLEAN;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2021-09-11 22:57:43 +02:00
|
|
|
m.selItem := ORD(m.keyboard) - 1;
|
2021-05-23 11:43:28 +02:00
|
|
|
m.cliItem := -1;
|
2021-09-11 22:57:43 +02:00
|
|
|
m.keyboard := FALSE;
|
2021-05-23 11:43:28 +02:00
|
|
|
K.SetEventsMask({0, 1, 5});
|
|
|
|
WHILE TRUE DO
|
2021-12-20 20:09:01 +01:00
|
|
|
CASE K.EventTimeout(100) OF
|
|
|
|
|0:
|
2021-05-23 11:43:28 +02:00
|
|
|
|1:
|
|
|
|
draw_window(m)
|
|
|
|
|2:
|
2021-09-11 22:57:43 +02:00
|
|
|
K.getKBState(shift, ctrl);
|
2022-01-18 17:23:19 +01:00
|
|
|
key := K.GetKey() DIV 65536;
|
|
|
|
IF shift THEN
|
|
|
|
INC(key, SHIFT)
|
|
|
|
END;
|
|
|
|
IF ctrl THEN
|
|
|
|
INC(key, CTRL)
|
|
|
|
END;
|
|
|
|
|
|
|
|
CASE key OF
|
|
|
|
|72:
|
|
|
|
m.selItem := (m.selItem - 1) MOD m.items.count
|
|
|
|
|80:
|
|
|
|
m.selItem := (m.selItem + 1) MOD m.items.count
|
|
|
|
|28:
|
|
|
|
IF m.selItem >= 0 THEN
|
|
|
|
click(m, m.selItem)
|
|
|
|
END;
|
|
|
|
m.cliItem := -1
|
|
|
|
|77:
|
|
|
|
IF ~submenu(m, TRUE) THEN
|
|
|
|
click(m, -(getMainID(m) + 1))
|
|
|
|
END;
|
|
|
|
m.cliItem := -1
|
|
|
|
|75:
|
|
|
|
IF m.parent # NIL THEN
|
|
|
|
escape(m)
|
|
|
|
ELSE
|
|
|
|
click(m, -(getMainID(m) - 1))
|
|
|
|
END;
|
|
|
|
m.cliItem := -1
|
|
|
|
|1:
|
|
|
|
escape(m)
|
2021-05-23 11:43:28 +02:00
|
|
|
ELSE
|
2022-01-18 17:23:19 +01:00
|
|
|
IF getShortcut(key) THEN
|
|
|
|
IF m.parent # NIL THEN
|
|
|
|
temp := m.parent.tid;
|
|
|
|
m.parent.tid := 0;
|
|
|
|
K.ExitID(temp)
|
|
|
|
END;
|
|
|
|
exit(m)
|
|
|
|
END
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
|
|
|
repaint(m)
|
|
|
|
|6:
|
2021-09-28 18:15:37 +02:00
|
|
|
K.mouse(msState, x, y);
|
2021-05-23 11:43:28 +02:00
|
|
|
IF (0 <= x) & (x < m.width) & (0 <= y) & (y < m.height) THEN
|
2021-09-03 01:15:33 +02:00
|
|
|
m.active := TRUE;
|
2021-05-23 11:43:28 +02:00
|
|
|
m.selItem := (y - TOP) DIV fontHeight;
|
|
|
|
IF 8 IN msState THEN
|
|
|
|
m.cliItem := (y - TOP) DIV fontHeight
|
|
|
|
END;
|
|
|
|
IF 16 IN msState THEN
|
|
|
|
IF m.cliItem = m.selItem THEN
|
|
|
|
click(m, m.cliItem)
|
|
|
|
END;
|
|
|
|
m.cliItem := -1
|
|
|
|
END
|
|
|
|
ELSE
|
2021-09-03 01:15:33 +02:00
|
|
|
m.active := FALSE;
|
2021-05-23 11:43:28 +02:00
|
|
|
m.cliItem := -1;
|
2021-09-03 01:15:33 +02:00
|
|
|
IF ({8, 9, 10, 16} * msState # {}) & ~isActive(m.child) THEN
|
2021-05-23 11:43:28 +02:00
|
|
|
exit(m)
|
|
|
|
END
|
|
|
|
END;
|
2021-09-03 01:15:33 +02:00
|
|
|
repaint(m);
|
2021-09-11 22:57:43 +02:00
|
|
|
IF submenu(m, FALSE) THEN END
|
2021-05-23 11:43:28 +02:00
|
|
|
END
|
|
|
|
END
|
|
|
|
END window;
|
|
|
|
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
PROCEDURE level (m: tMenu): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
res := 0;
|
|
|
|
WHILE m.parent # NIL DO
|
|
|
|
INC(res);
|
|
|
|
m := m.parent
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END level;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE open* (m: tMenu; x, y: INTEGER);
|
|
|
|
VAR
|
|
|
|
L: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
IF m.tid = 0 THEN
|
|
|
|
L := level(m);
|
2021-12-20 20:09:01 +01:00
|
|
|
IF K.GetThreadSlot(TIDs[L]) = 0 THEN
|
2021-09-11 22:57:43 +02:00
|
|
|
m.winX := x;
|
|
|
|
m.winY := y;
|
|
|
|
SYSTEM.PUT(SYSTEM.ADR(stack[L][LEN(stack[0]) - 1]), m);
|
|
|
|
m.tid := K.CreateThread(SYSTEM.ADR(window), stack[L]);
|
|
|
|
TIDs[L] := m.tid
|
|
|
|
END
|
2021-09-03 01:15:33 +02:00
|
|
|
END
|
|
|
|
END open;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE AddMenuItem* (items: List.tList; id: INTEGER; s: ARRAY OF WCHAR);
|
|
|
|
VAR
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
|
|
|
item.id := id;
|
|
|
|
item.text := s;
|
|
|
|
item.enabled := TRUE;
|
|
|
|
item.delim := FALSE;
|
2021-09-03 01:15:33 +02:00
|
|
|
item.child := NIL;
|
2021-05-23 11:43:28 +02:00
|
|
|
List.append(items, item);
|
|
|
|
END AddMenuItem;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE delimiter* (items: List.tList);
|
|
|
|
BEGIN
|
|
|
|
items.last(tItem).delim := TRUE
|
|
|
|
END delimiter;
|
|
|
|
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
PROCEDURE child* (items: List.tList; menu: tMenu);
|
|
|
|
BEGIN
|
|
|
|
items.last(tItem).child := menu
|
|
|
|
END child;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE getItem (m: tMenu; id: INTEGER): tItem;
|
|
|
|
VAR
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
item := m.items.first(tItem);
|
|
|
|
WHILE (item # NIL) & (item.id # id) DO
|
|
|
|
item := item.next(tItem)
|
|
|
|
END
|
|
|
|
RETURN item
|
|
|
|
END getItem;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE setEnabled* (m: tMenu; id: INTEGER; value: BOOLEAN);
|
|
|
|
VAR
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
item := getItem(m, id);
|
|
|
|
IF item # NIL THEN
|
|
|
|
item.enabled := value
|
|
|
|
END
|
|
|
|
END setEnabled;
|
|
|
|
|
|
|
|
|
2021-09-08 22:47:14 +02:00
|
|
|
PROCEDURE check* (m: tMenu; id: INTEGER; value: BOOLEAN);
|
2021-05-23 11:43:28 +02:00
|
|
|
VAR
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
item := getItem(m, id);
|
|
|
|
IF item # NIL THEN
|
2021-09-08 22:47:14 +02:00
|
|
|
item.check := ORD(value)
|
2021-05-23 11:43:28 +02:00
|
|
|
END
|
2021-09-08 22:47:14 +02:00
|
|
|
END check;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE option* (m: tMenu; id: INTEGER; value: BOOLEAN);
|
|
|
|
VAR
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
item := getItem(m, id);
|
|
|
|
IF item # NIL THEN
|
|
|
|
item.check := ORD(value)*2
|
|
|
|
END
|
|
|
|
END option;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isEnabled* (m: tMenu; id: INTEGER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
item := getItem(m, id)
|
|
|
|
RETURN (item # NIL) & item.enabled
|
|
|
|
END isEnabled;
|
|
|
|
|
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
PROCEDURE create* (items: List.tList): tMenu;
|
2021-05-23 11:43:28 +02:00
|
|
|
VAR
|
|
|
|
m: tMenu;
|
|
|
|
maxLength: INTEGER;
|
|
|
|
item: tItem;
|
|
|
|
BEGIN
|
|
|
|
NEW(m);
|
|
|
|
m.tid := 0;
|
2021-09-03 01:15:33 +02:00
|
|
|
m.active := FALSE;
|
|
|
|
m.parent := NIL;
|
|
|
|
m.child := NIL;
|
2021-09-11 22:57:43 +02:00
|
|
|
m.mainID := 0;
|
2021-05-23 11:43:28 +02:00
|
|
|
m.items := items;
|
|
|
|
maxLength := 0;
|
|
|
|
item := items.first(tItem);
|
|
|
|
WHILE item # NIL DO
|
|
|
|
maxLength := MAX(maxLength, LENGTH(item.text));
|
|
|
|
item := item.next(tItem)
|
|
|
|
END;
|
|
|
|
m.width := maxLength*fontWidth + LEFT + RIGHT;
|
|
|
|
m.height := items.count*fontHeight - 2;
|
|
|
|
m.font := G.CreateFont(1, "", {});
|
|
|
|
m.canvas := G.CreateCanvas(m.width + 1, m.height + 1);
|
|
|
|
G.SetFont(m.canvas, m.font);
|
|
|
|
RETURN m
|
|
|
|
END create;
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
|
2022-01-18 17:23:19 +01:00
|
|
|
PROCEDURE AddShortcut* (key, MenuItem: INTEGER);
|
|
|
|
VAR
|
|
|
|
item: tShortcut;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
|
|
|
item.key := key;
|
|
|
|
item.MenuItem := MenuItem;
|
|
|
|
List.append(shortcuts, item)
|
|
|
|
END AddShortcut;
|
|
|
|
|
|
|
|
|
2021-09-03 01:15:33 +02:00
|
|
|
PROCEDURE init* (_resetTimer: tProc);
|
|
|
|
VAR
|
|
|
|
i: INTEGER;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2022-01-18 17:23:19 +01:00
|
|
|
SetItem(0);
|
|
|
|
shortcuts := List.create(NIL);
|
2021-09-03 01:15:33 +02:00
|
|
|
resetTimer := _resetTimer;
|
|
|
|
_open := open;
|
|
|
|
FOR i := 0 TO maxLEVEL DO
|
|
|
|
TIDs[i] := 0
|
|
|
|
END
|
|
|
|
END init;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
END Menu.
|