-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDropLife32Source.pas
164 lines (142 loc) · 4.4 KB
/
DropLife32Source.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
unit DropLife32Source;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX,
DropSource, DropTarget, LifeBox, LifeGen, LifeConst, LifeUtil;
type
TDropLife32Source = class(TDropSource)
private
FUniverse: TUniverse;
protected
function DoGetData(const FormatEtcIn: TFormatEtc;
out Medium: TStgMedium):HResult; override;
function CutOrCopyToClipboard: boolean; override;
public
constructor Create(aOwner: TComponent); override;
published
property Universe: String read FUniverse write FUniverse;
end;
TDropLife32Target = class(TDropTarget)
private
FUniverse: TUniverse;
protected
procedure ClearData; override;
function DoGetData: boolean; override;
function HasValidFormats: boolean; override;
public
function PasteFromClipboard: longint; override;
property Universe: TUniverse read FUniverse write FUniverse;
end;
procedure Register;
implementation
constructor TDropLife32Source.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
AddFormatEtc(CF_TEXT, nil, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
AddFormatEtc(CF_LIFE32, nil, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
//These next two formats have been commented out (for the time being)
//as they interfer with text drag and drop in Word97.
//AddFormatEtc(CF_FILEGROUPDESCRIPTOR, NIL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
//AddFormatEtc(CF_FILECONTENTS, NIL, DVASPECT_CONTENT, 0, TYMED_HGLOBAL);
end;
// -----------------------------------------------------------------------------
function TDropTextSource.CutOrCopyToClipboard: boolean;
var
FormatEtcIn: TFormatEtc;
Medium: TStgMedium;
begin
FormatEtcIn.cfFormat := CF_TEXT;
FormatEtcIn.dwAspect := DVASPECT_CONTENT;
FormatEtcIn.tymed := TYMED_HGLOBAL;
if not(Assigned(Universe) then result:= false
else if GetData(formatetcIn,Medium) = S_OK then begin
Clipboard.SetAsHandle(CF_TEXT,Medium.hGlobal);
result:= true;
end
else result:= false;
end;
// -----------------------------------------------------------------------------
function TDropTextSource.DoGetData(const FormatEtcIn: TFormatEtc;
out Medium: TStgMedium):HRESULT;
var
pText: PChar;
begin
Medium.tymed := 0;
Medium.UnkForRelease := nil;
Medium.hGlobal := 0;
Result:= S_OK;
if Assigned(FUniverse) then begin
if (FormatEtcIN.cfFormat = CF_LIFE32) then begin
FUniverse.
end
//--------------------------------------------------------------------------
else if (FormatEtcIn.cfFormat = CF_TEXT) then begin
Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GHND, Length(FText)+1);
if (Medium.hGlobal <> 0) then begin
medium.tymed := TYMED_HGLOBAL;
pText := PChar(GlobalLock(Medium.hGlobal));
try
StrCopy(pText, PChar(fText));
finally
GlobalUnlock(Medium.hGlobal);
end; {try}
end {if}
else result:= E_OUTOFMEMORY;
end; {if CF_TEXT}
end {if assigned}
else result:= E_UNEXPECTED;
end;
function TDropTextTarget.PasteFromClipboard: longint;
var
Global: HGlobal;
TextPtr: pChar;
begin
result := DROPEFFECT_NONE;
if not ClipBoard.HasFormat(CF_TEXT) then exit;
Global := Clipboard.GetAsHandle(CF_TEXT);
TextPtr := GlobalLock(Global);
fText := TextPtr;
GlobalUnlock(Global);
result := DROPEFFECT_COPY;
end;
// -----------------------------------------------------------------------------
function TDropTextTarget.HasValidFormats: boolean;
begin
result := (fDataObj.QueryGetData(TextFormatEtc) = S_OK);
end;
// -----------------------------------------------------------------------------
procedure TDropTextTarget.ClearData;
begin
fText := '';
end;
// -----------------------------------------------------------------------------
function TDropTextTarget.DoGetData: boolean;
var
medium: TStgMedium;
cText: pchar;
begin
result := false;
medium.hGlobal:= 0;
if fText <> '' then result := true // already got it!
else if (fDataObj.GetData(TextFormatEtc, medium) = S_OK) then
begin
try
if (medium.tymed <> TYMED_HGLOBAL) then exit;
cText := PChar(GlobalLock(medium.HGlobal));
fText := cText;
GlobalUnlock(medium.HGlobal);
result := true;
finally
ReleaseStgMedium(medium);
end;
end
else
result := false;
end;
procedure Register;
begin
RegisterComponents('Samples', [TDropLife32Source]);
RegisterComponents('Samples', [TDropLife32Target]);
end;
end.