-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuclipboard.pas
76 lines (66 loc) · 1.72 KB
/
uclipboard.pas
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
unit UClipboard;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLType, Clipbrd, UFileWorker, fpjson, UFigures, Graphics;
const
{ JSON string }
CLIPBRD_FORMAT_NAME = 'VecDraw';
procedure CopySelected;
procedure PasteFromClipboard;
implementation
procedure CopySelected;
var
cfVecDraw: TClipboardFormat;
s: TStringStream;
json: TJSONObject;
pic: TBitmap;
begin
json := GetFiguresJSON(true);
Clipboard.Open;
if json.Arrays[FILE_HEADER].Count > 0 then
begin
cfVecDraw := Clipboard.FindFormatID(CLIPBRD_FORMAT_NAME);
if cfVecDraw = 0 then
cfVecDraw := RegisterClipboardFormat(CLIPBRD_FORMAT_NAME);
s := TStringStream.Create(json.AsJSON);
pic := GetFiguresBitmap(true);
Clipboard.Assign(pic);
Clipboard.AddFormat(cfVecDraw, s);
FreeAndNil(json);
FreeAndNil(s);
FreeAndNil(pic);
end;
Clipboard.Close;
end;
procedure PasteFromClipboard;
var
cfVecDraw: TClipboardFormat;
s: TStringStream;
json: TJSONObject;
Figures: TFigureList;
Figure: TFigure;
i: integer;
begin
cfVecDraw := Clipboard.FindFormatID(CLIPBRD_FORMAT_NAME);
if cfVecDraw = 0 then
cfVecDraw := RegisterClipboardFormat(CLIPBRD_FORMAT_NAME);
s := TStringStream.Create('');
if Clipboard.GetFormat(cfVecDraw, s) then
begin
json := TJSONObject(GetJSON(s.DataString));
Figures := GetFiguresFromJSON(json);
for Figure in Figures do
if Figure <> nil then
begin
SetLength(CanvasItems, Length(CanvasItems) + 1);
CanvasItems[High(CanvasItems)] := Figure.Clone;
CanvasItems[High(CanvasItems)].Selected := true;
end;
FreeAndNil(json);
for i := Low(Figures) to High(Figures) do
FreeAndNil(Figures[i]);
FreeAndNil(s);
end;
end;
end.