-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clipboard.Mod
61 lines (55 loc) · 1.54 KB
/
Clipboard.Mod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
MODULE Clipboard;
IMPORT SYSTEM, Texts, Viewers, TextFrames, Oberon;
CONST control = -24; data = -20;
PROCEDURE Copy(T: Texts.Text; beg, end: INTEGER);
VAR R: Texts.Reader;
ch: CHAR;
BEGIN
Texts.OpenReader(R, T, beg);
SYSTEM.PUT(control, end - beg);
WHILE beg < end DO
Texts.Read(R, ch);
SYSTEM.PUT(data, ch);
beg := beg + 1
END
END Copy;
PROCEDURE CopySelection*;
VAR T: Texts.Text;
beg, end, time: INTEGER;
BEGIN
Oberon.GetSelection(T, beg, end, time);
IF time >= 0 THEN Copy(T, beg, end) END
END CopySelection;
PROCEDURE CopyViewer*;
VAR V: Viewers.Viewer;
F: TextFrames.Frame;
BEGIN
V := Oberon.MarkedViewer();
IF (V # NIL) & (V.dsc # NIL) & (V.dsc.next IS TextFrames.Frame) THEN
F := V.dsc.next(TextFrames.Frame);
Copy(F.text, 0, F.text.len)
END
END CopyViewer;
PROCEDURE Paste*;
VAR W: Texts.Writer;
V: Viewers.Viewer;
F: TextFrames.Frame;
len, i: INTEGER;
ch: CHAR;
BEGIN
V := Oberon.FocusViewer;
IF (V # NIL) & (V.dsc # NIL) & (V.dsc.next IS TextFrames.Frame) THEN
SYSTEM.GET(control, len);
IF len > 0 THEN
Texts.OpenWriter(W);
FOR i := 1 TO len DO
SYSTEM.GET(data, ch);
Texts.Write(W, ch)
END;
F := V.dsc.next(TextFrames.Frame);
Texts.Insert(F.text, F.carloc.pos, W.buf);
TextFrames.SetCaret(F, F.carloc.pos + len)
END
END
END Paste;
END Clipboard.