Subversion Repositories decoder

Rev

Blame | Last modification | View Log | RSS feed

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