Subversion Repositories decoder

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
unit DropSource3;
2
 
3
// -----------------------------------------------------------------------------
4
//
5
//                      *** NOT FOR RELEASE ***
6
//
7
// -----------------------------------------------------------------------------
8
// Project:         Drag and Drop Component Suite
9
// Module:          DropSource3
10
// Description:     Deprecated TDropSource class.
11
//                  Provided for compatibility with previous versions of the
12
//                  Drag and Drop Component Suite.
13
// Version:         4.0
14
// Date:            25-JUN-2000
15
// Target:          Win32, Delphi 3-6 and C++ Builder 3-5
16
// Authors:         Angus Johnson, ajohnson@rpi.net.au
17
//                  Anders Melander, anders@melander.dk, http://www.melander.dk
18
// Copyright        © 1997-2000 Angus Johnson & Anders Melander
19
// -----------------------------------------------------------------------------
20
 
21
 
22
interface
23
 
24
uses
25
  DragDrop,
26
  DropSource,
27
  ActiveX,
28
  Classes;
29
 
30
{$include DragDrop.inc}
31
 
32
const
33
  MAXFORMATS = 20;
34
 
35
type
36
  // TODO -oanme -cStopShip : Verify that TDropSource can be used for pre v4 components.
37
  TDropSource = class(TCustomDropSource)
38
  private
39
    FDataFormats: array[0..MAXFORMATS-1] of TFormatEtc;
40
    FDataFormatsCount: integer;
41
 
42
  protected
43
    // IDataObject implementation
44
    function QueryGetData(const FormatEtc: TFormatEtc): HRESULT; stdcall;
45
 
46
    // TCustomDropSource implementation
47
    function HasFormat(const FormatEtc: TFormatEtc): boolean; override;
48
    function GetEnumFormatEtc(dwDirection: LongInt): IEnumFormatEtc; override;
49
 
50
    // New functions...
51
    procedure AddFormatEtc(cfFmt: TClipFormat; pt: PDVTargetDevice;
52
      dwAsp, lInd, tym: longint); virtual;
53
 
54
  public
55
    constructor Create(AOwner: TComponent); override;
56
  end;
57
 
58
implementation
59
 
60
uses
61
  ShlObj,
62
  SysUtils,
63
  Windows;
64
 
65
// -----------------------------------------------------------------------------
66
//                      TEnumFormatEtc
67
// -----------------------------------------------------------------------------
68
 
69
type
70
 
71
  pFormatList = ^TFormatList;
72
  TFormatList = array[0..255] of TFormatEtc;
73
 
74
  TEnumFormatEtc = class(TInterfacedObject, IEnumFormatEtc)
75
  private
76
    FFormatList: pFormatList;
77
    FFormatCount: Integer;
78
    FIndex: Integer;
79
  public
80
    constructor Create(FormatList: pFormatList; FormatCount, Index: Integer);
81
    { IEnumFormatEtc }
82
    function Next(Celt: LongInt; out Elt; pCeltFetched: pLongInt): HRESULT; stdcall;
83
    function Skip(Celt: LongInt): HRESULT; stdcall;
84
    function Reset: HRESULT; stdcall;
85
    function Clone(out Enum: IEnumFormatEtc): HRESULT; stdcall;
86
  end;
87
// -----------------------------------------------------------------------------
88
 
89
constructor TEnumFormatEtc.Create(FormatList: pFormatList;
90
            FormatCount, Index: Integer);
91
begin
92
  inherited Create;
93
  FFormatList := FormatList;
94
  FFormatCount := FormatCount;
95
  FIndex := Index;
96
end;
97
// -----------------------------------------------------------------------------
98
 
99
function TEnumFormatEtc.Next(Celt: LongInt;
100
  out Elt; pCeltFetched: pLongInt): HRESULT;
101
var
102
  i: Integer;
103
begin
104
  i := 0;
105
  WHILE (i < Celt) and (FIndex < FFormatCount) do
106
  begin
107
    TFormatList(Elt)[i] := FFormatList[fIndex];
108
    Inc(FIndex);
109
    Inc(i);
110
  end;
111
  if pCeltFetched <> NIL then pCeltFetched^ := i;
112
  if i = Celt then result := S_OK else result := S_FALSE;
113
end;
114
// -----------------------------------------------------------------------------
115
 
116
function TEnumFormatEtc.Skip(Celt: LongInt): HRESULT;
117
begin
118
  if Celt <= FFormatCount - FIndex then
119
  begin
120
    FIndex := FIndex + Celt;
121
    result := S_OK;
122
  end else
123
  begin
124
    FIndex := FFormatCount;
125
    result := S_FALSE;
126
  end;
127
end;
128
// -----------------------------------------------------------------------------
129
 
130
function TEnumFormatEtc.ReSet: HRESULT;
131
begin
132
  fIndex := 0;
133
  result := S_OK;
134
end;
135
// -----------------------------------------------------------------------------
136
 
137
function TEnumFormatEtc.Clone(out Enum: IEnumFormatEtc): HRESULT;
138
begin
139
  enum := TEnumFormatEtc.Create(FFormatList, FFormatCount, FIndex);
140
  result := S_OK;
141
end;
142
 
143
// -----------------------------------------------------------------------------
144
//                      TDropSource
145
// -----------------------------------------------------------------------------
146
 
147
constructor TDropSource.Create(AOwner: TComponent);
148
begin
149
  inherited Create(aOwner);
150
  FDataFormatsCount := 0;
151
end;
152
// -----------------------------------------------------------------------------
153
 
154
function TDropSource.QueryGetData(const FormatEtc: TFormatEtc): HRESULT; stdcall;
155
var
156
  i: integer;
157
begin
158
  result:= S_OK;
159
  for i := 0 to FDataFormatsCount-1 do
160
    with FDataFormats[i] do
161
    begin
162
      if (FormatEtc.cfFormat = cfFormat) and
163
         (FormatEtc.dwAspect = dwAspect) and
164
         (FormatEtc.tymed and tymed <> 0) then exit; //result:= S_OK;
165
    end;
166
  result:= E_FAIL;
167
end;
168
// -----------------------------------------------------------------------------
169
 
170
function TDropSource.GetEnumFormatEtc(dwDirection: Integer): IEnumFormatEtc;
171
begin
172
  if (dwDirection = DATADIR_GET) then
173
    Result := TEnumFormatEtc.Create(pFormatList(@FDataFormats), FDataFormatsCount, 0)
174
  else
175
    result := nil;
176
end;
177
// -----------------------------------------------------------------------------
178
 
179
procedure TDropSource.AddFormatEtc(cfFmt: TClipFormat;
180
  pt: PDVTargetDevice; dwAsp, lInd, tym: longint);
181
begin
182
  if fDataFormatsCount = MAXFORMATS then exit;
183
 
184
  FDataFormats[fDataFormatsCount].cfFormat := cfFmt;
185
  FDataFormats[fDataFormatsCount].ptd := pt;
186
  FDataFormats[fDataFormatsCount].dwAspect := dwAsp;
187
  FDataFormats[fDataFormatsCount].lIndex := lInd;
188
  FDataFormats[fDataFormatsCount].tymed := tym;
189
  inc(FDataFormatsCount);
190
end;
191
// -----------------------------------------------------------------------------
192
// -----------------------------------------------------------------------------
193
 
194
function TDropSource.HasFormat(const FormatEtc: TFormatEtc): boolean;
195
begin
196
  Result := True;
197
 { TODO -oanme -cStopShip : TDropSource.HasFormat needs implementation }
198
end;
199
 
200
initialization
201
  OleInitialize(NIL);
202
  ShGetMalloc(ShellMalloc);
203
 
204
finalization
205
  ShellMalloc := nil;
206
  OleUninitialize;
207
end.