DropComboTarget.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. unit DropComboTarget;
  2. // -----------------------------------------------------------------------------
  3. // Project: Drag and Drop Component Suite
  4. // Module: DropComboTarget
  5. // Description: Implements a swiss-army-knife drop target component.
  6. // Version: 4.0
  7. // Date: 18-MAY-2001
  8. // Target: Win32, Delphi 5-6
  9. // Authors: Anders Melander, anders@melander.dk, http://www.melander.dk
  10. // Copyright © 1997-2001 Angus Johnson & Anders Melander
  11. // -----------------------------------------------------------------------------
  12. interface
  13. uses
  14. DragDrop,
  15. DropTarget,
  16. DragDropFormats,
  17. DragDropInternet,
  18. DragDropGraphics,
  19. DragDropFile,
  20. DragDropText,
  21. Classes,
  22. Graphics,
  23. ActiveX;
  24. type
  25. // Note: mfCustom is used to support DataFormatAdapters.
  26. TComboFormatType = (mfText, mfFile, mfURL, mfBitmap, mfMetaFile, mfData, mfCustom, mfHtml);
  27. TComboFormatTypes = set of TComboFormatType;
  28. const
  29. AllComboFormats = [mfText, mfFile, mfURL, mfBitmap, mfMetaFile, mfData, mfHtml];
  30. type
  31. ////////////////////////////////////////////////////////////////////////////////
  32. //
  33. // TDropComboTarget
  34. //
  35. ////////////////////////////////////////////////////////////////////////////////
  36. TDropComboTarget = class(TCustomDropMultiTarget)
  37. private
  38. FFileFormat : TFileDataFormat;
  39. FFileMapFormat : TFileMapDataFormat;
  40. FURLFormat : TURLDataFormat;
  41. FBitmapFormat : TBitmapDataFormat;
  42. FMetaFileFormat : TMetaFileDataFormat;
  43. FTextFormat : TTextDataFormat;
  44. FDataFormat : TDataStreamDataFormat;
  45. FHtmlFormat : THTMLDataFormat;
  46. FFormats : TComboFormatTypes;
  47. function GetHtml: String;
  48. protected
  49. procedure DoAcceptFormat(const DataFormat: TCustomDataFormat;
  50. var Accept: boolean); override;
  51. function GetFiles: TStrings;
  52. function GetTitle: string;
  53. function GetURL: string;
  54. function GetBitmap: TBitmap;
  55. function GetMetaFile: TMetaFile;
  56. function GetText: string;
  57. function GetFileMaps: TStrings;
  58. function GetStreams: TStreamList;
  59. public
  60. constructor Create(AOwner: TComponent); override;
  61. property Files: TStrings read GetFiles;
  62. property FileMaps: TStrings read GetFileMaps;
  63. property URL: string read GetURL;
  64. property Title: string read GetTitle;
  65. property Bitmap: TBitmap read GetBitmap;
  66. property MetaFile: TMetaFile read GetMetaFile;
  67. property Text: string read GetText;
  68. property Data: TStreamList read GetStreams;
  69. property Html: String read GetHtml;
  70. published
  71. property OnAcceptFormat;
  72. property Formats: TComboFormatTypes read FFormats write FFormats default AllComboFormats;
  73. end;
  74. (*
  75. ** *** WARNING ***
  76. **
  77. ** The TDropMultiTarget component has been renamed to TDropComboTarget and
  78. ** will be removed shortly. See the readme.txt file for instruction on how to
  79. ** replace TDropMultiTarget with TDropComboTarget.
  80. *)
  81. TDropMultiTarget = class(TDropComboTarget);
  82. ////////////////////////////////////////////////////////////////////////////////
  83. //
  84. // Component registration
  85. //
  86. ////////////////////////////////////////////////////////////////////////////////
  87. procedure Register;
  88. implementation
  89. ////////////////////////////////////////////////////////////////////////////////
  90. //
  91. // Component registration
  92. //
  93. ////////////////////////////////////////////////////////////////////////////////
  94. procedure Register;
  95. begin
  96. RegisterComponents(DragDropComponentPalettePage, [TDropComboTarget]);
  97. RegisterNoIcon([TDropMultiTarget]);
  98. end;
  99. ////////////////////////////////////////////////////////////////////////////////
  100. //
  101. // TDropComboTarget
  102. //
  103. ////////////////////////////////////////////////////////////////////////////////
  104. constructor TDropComboTarget.Create(AOwner: TComponent);
  105. begin
  106. inherited Create(AOwner);
  107. FFileFormat := TFileDataFormat.Create(Self);
  108. FURLFormat := TURLDataFormat.Create(Self);
  109. FBitmapFormat := TBitmapDataFormat.Create(Self);
  110. FMetaFileFormat := TMetaFileDataFormat.Create(Self);
  111. FTextFormat := TTextDataFormat.Create(Self);
  112. FFileMapFormat := TFileMapDataFormat.Create(Self);
  113. FDataFormat := TDataStreamDataFormat.Create(Self);
  114. FHtmlFormat := THTMLDataFormat.Create(Self);
  115. FFormats := AllComboFormats;
  116. end;
  117. procedure TDropComboTarget.DoAcceptFormat(const DataFormat: TCustomDataFormat;
  118. var Accept: boolean);
  119. begin
  120. if (Accept) then
  121. begin
  122. if (DataFormat is TFileDataFormat) or (DataFormat is TFileMapDataFormat) then
  123. Accept := (mfFile in FFormats)
  124. else if (DataFormat is TURLDataFormat) then
  125. Accept := (mfURL in FFormats)
  126. else if (DataFormat is TBitmapDataFormat) then
  127. Accept := (mfBitmap in FFormats)
  128. else if (DataFormat is TMetaFileDataFormat) then
  129. Accept := (mfMetaFile in FFormats)
  130. else if (DataFormat is TTextDataFormat) then
  131. Accept := (mfText in FFormats)
  132. else if (DataFormat is TDataStreamDataFormat) then
  133. Accept := (mfData in FFormats)
  134. else if (DataFormat is THTMLDataFormat) then
  135. Accept := (mfHtml in FFormats)
  136. else
  137. Accept := (mfCustom in FFormats)
  138. end;
  139. if (Accept) then
  140. inherited DoAcceptFormat(DataFormat, Accept);
  141. end;
  142. function TDropComboTarget.GetBitmap: TBitmap;
  143. begin
  144. Result := FBitmapFormat.Bitmap;
  145. end;
  146. function TDropComboTarget.GetFileMaps: TStrings;
  147. begin
  148. Result := FFileMapFormat.FileMaps;
  149. end;
  150. function TDropComboTarget.GetFiles: TStrings;
  151. begin
  152. Result := FFileFormat.Files;
  153. end;
  154. function TDropComboTarget.GetHtml: String;
  155. begin
  156. Result := FHtmlFormat.HTML.Text;
  157. end;
  158. function TDropComboTarget.GetMetaFile: TMetaFile;
  159. begin
  160. Result := FMetaFileFormat.MetaFile;
  161. end;
  162. function TDropComboTarget.GetStreams: TStreamList;
  163. begin
  164. Result := FDataFormat.Streams;
  165. end;
  166. function TDropComboTarget.GetText: string;
  167. begin
  168. Result := FTextFormat.Text;
  169. end;
  170. function TDropComboTarget.GetTitle: string;
  171. begin
  172. Result := FURLFormat.Title;
  173. end;
  174. function TDropComboTarget.GetURL: string;
  175. begin
  176. Result := FURLFormat.URL;
  177. end;
  178. end.