DropSource3.pas 6.0 KB

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