home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kolekce / d6 / rxlibsetup.exe / {app} / units / CLIPVIEW.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-02-19  |  18.8 KB  |  648 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 2001,2002 SGB Software          }
  6. {         Copyright (c) 1997, 1998 Fedor Koshevnikov,   }
  7. {                        Igor Pavluk and Serge Korolev  }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11.  
  12. unit ClipView;
  13.  
  14. interface
  15.  
  16. {$I RX.INC}
  17.  
  18. uses SysUtils, {$IFDEF WIN32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  19.   Messages, Classes, Graphics, Controls, Clipbrd, Forms, StdCtrls,
  20.   ExtCtrls, Menus;
  21.  
  22. type
  23.  
  24. { TCustomClipboardViewer }
  25.  
  26.   TClipboardViewFormat = (cvDefault, cvEmpty, cvUnknown, cvText, cvBitmap,
  27.     cvMetafile, cvPalette, cvOemText, cvPicture, cvComponent, cvIcon);
  28.  
  29.   TCustomClipboardViewer = class(TScrollBox)
  30.   private
  31.     { Private declarations }
  32.     FWndNext: HWnd;
  33.     FChained: Boolean;
  34.     FPaintControl: TComponent;
  35.     FViewFormat: TClipboardViewFormat;
  36.     FOnChange: TNotifyEvent;
  37.     function IsEmptyClipboard: Boolean;
  38.     procedure ForwardMessage(var Message: TMessage);
  39.     procedure WMSize(var Message: TMessage); message WM_SIZE;
  40.     procedure WMDestroyClipboard(var Message: TMessage); message WM_DESTROYCLIPBOARD;
  41.     procedure WMChangeCBChain(var Message: TWMChangeCBChain); message WM_CHANGECBCHAIN;
  42.     procedure WMDrawClipboard(var Message: TMessage); message WM_DRAWCLIPBOARD;
  43.     procedure WMNCDestroy(var Message: TWMNCDestroy); message WM_NCDESTROY;
  44.     procedure SetViewFormat(Value: TClipboardViewFormat);
  45.     function GetClipboardFormatNames(Index: Integer): string;
  46.   protected
  47.     { Protected declarations }
  48.     procedure CreateWnd; override;
  49.     procedure DestroyWindowHandle; override;
  50.     procedure Change; dynamic;
  51.     procedure CreatePaintControl; virtual;
  52.     function GetDrawFormat: TClipboardViewFormat; virtual;
  53.     function ValidFormat(Format: TClipboardViewFormat): Boolean; dynamic;
  54.     property ViewFormat: TClipboardViewFormat read FViewFormat write
  55.       SetViewFormat stored False;
  56.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  57.   public
  58.     { Public declarations }
  59.     constructor Create(AOwner: TComponent); override;
  60.     class function CanDrawFormat(ClipboardFormat: Word): Boolean;
  61.     property ClipboardFormatNames[Index: Integer]: string read GetClipboardFormatNames;
  62.   published
  63.     property Color default clWindow;
  64.     property ParentColor default False;
  65.   end;
  66.  
  67.   TClipboardViewer = class(TCustomClipboardViewer)
  68.   published
  69. {$IFDEF RX_D4}
  70.     property Anchors;
  71.     property BiDiMode;
  72.     property Constraints;
  73.     property DragKind;
  74.     property ParentBiDiMode;
  75. {$ENDIF}
  76.     property ViewFormat;
  77.     property OnChange;
  78. {$IFDEF RX_D5}
  79.     property OnContextPopup;
  80. {$ENDIF}
  81. {$IFDEF WIN32}
  82.     property OnStartDrag;
  83. {$ENDIF}
  84. {$IFDEF RX_D4}
  85.     property OnEndDock;
  86.     property OnStartDock;
  87. {$ENDIF}
  88.   end;
  89.  
  90. function ClipboardFormatToView(Value: Word): TClipboardViewFormat;
  91.  
  92. implementation
  93.  
  94. uses Grids, ClipIcon, MaxMin, RxTConst, {$IFNDEF WIN32} Str16, {$ENDIF}
  95.   VCLUtils;
  96.  
  97. { Utility routines }
  98.  
  99. function ClipboardFormatName(Format: Word): string;
  100. var
  101.   Buffer: array[0..255] of Char;
  102. begin
  103.   SetString(Result, Buffer, GetClipboardFormatName(Format, Buffer, 255));
  104.   if Result = '' then
  105.     case Format of
  106.       CF_BITMAP: Result := 'Bitmap';
  107.       CF_DIB: Result := 'DIB Bitmap';
  108.       CF_DIF: Result := 'DIF';
  109.       CF_METAFILEPICT: Result := 'Metafile Picture';
  110. {$IFDEF WIN32}
  111.       CF_ENHMETAFILE: Result := 'Enchanced Metafile';
  112. {$ENDIF}
  113.       CF_OEMTEXT: Result := 'OEM Text';
  114.       CF_PALETTE: Result := 'Palette';
  115.       CF_PENDATA: Result := 'Pen Data';
  116.       CF_RIFF: Result := 'RIFF File';
  117.       CF_SYLK: Result := 'SYLK';
  118.       CF_TEXT: Result := 'Text';
  119.       CF_TIFF: Result := 'Tag Image';
  120.       CF_WAVE: Result := 'Wave';
  121.     end;
  122. end;
  123.  
  124. function ViewToClipboardFormat(Value: TClipboardViewFormat): Word;
  125. begin
  126.   case Value of
  127.     cvDefault, cvUnknown, cvEmpty: Result := 0;
  128.     cvText: Result := CF_TEXT;
  129.     cvBitmap: Result := CF_BITMAP;
  130.     cvMetafile: Result := CF_METAFILEPICT;
  131.     cvPalette: Result := CF_PALETTE;
  132.     cvOemText: Result := CF_OEMTEXT;
  133.     cvPicture: Result := CF_PICTURE; { CF_BITMAP, CF_METAFILEPICT }
  134.     cvComponent: Result := CF_COMPONENT; { CF_TEXT }
  135.     cvIcon: Result := CF_ICON; { CF_BITMAP }
  136.     else Result := 0;
  137.   end;
  138. end;
  139.  
  140. function ClipboardFormatToView(Value: Word): TClipboardViewFormat;
  141. begin
  142.   if Value = CF_TEXT then Result := cvText
  143.   else if Value = CF_BITMAP then Result := cvBitmap
  144.   else if Value = CF_METAFILEPICT then Result := cvMetafile
  145. {$IFDEF WIN32}
  146.   else if Value = CF_ENHMETAFILE then Result := cvMetafile
  147. {$ENDIF}
  148.   else if Value = CF_PALETTE then Result := cvPalette
  149.   else if Value = CF_OEMTEXT then Result := cvOemText
  150.   else if Value = CF_PICTURE then Result := cvPicture { CF_BITMAP, CF_METAFILEPICT }
  151.   else if Value = CF_COMPONENT then Result := cvComponent { CF_TEXT }
  152.   else if Value = CF_ICON then Result := cvIcon { CF_BITMAP }
  153.   else Result := cvDefault;
  154. end;
  155.  
  156. procedure ComponentToStrings(Instance: TComponent; Text: TStrings);
  157. var
  158.   Mem, Out: TMemoryStream;
  159. begin
  160.   Mem := TMemoryStream.Create;
  161.   try
  162.     Mem.WriteComponent(Instance);
  163.     Mem.Position := 0;
  164.     Out := TMemoryStream.Create;
  165.     try
  166.       ObjectBinaryToText(Mem, Out);
  167.       Out.Position := 0;
  168.       Text.LoadFromStream(Out);
  169.     finally
  170.       Out.Free;
  171.     end;
  172.   finally
  173.     Mem.Free;
  174.   end;
  175. end;
  176.  
  177. { TPaletteGrid }
  178.  
  179. const
  180.   NumPaletteEntries = 256;
  181.  
  182. type
  183.   TPaletteGrid = class(TDrawGrid)
  184.   private
  185.     FPaletteEntries: array[0..NumPaletteEntries - 1] of TPaletteEntry;
  186.     FPalette: HPALETTE;
  187.     FCount: Integer;
  188.     FSizing: Boolean;
  189.     procedure SetPalette(Value: HPALETTE);
  190.     procedure UpdateSize;
  191.     function CellColor(ACol, ARow: Longint): TColor;
  192.     procedure DrawSquare(CellColor: TColor; CellRect: TRect; ShowSelector: Boolean);
  193.   protected
  194.     function GetPalette: HPALETTE; override;
  195.     procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
  196.       AState: TGridDrawState); override;
  197.     function SelectCell(ACol, ARow: Longint): Boolean; override;
  198.     procedure WMSize(var Message: TWMSize); message WM_SIZE;
  199.   public
  200.     constructor Create(AOwner: TComponent); override;
  201.     destructor Destroy; override;
  202.     property Palette: HPALETTE read FPalette write SetPalette;
  203.   end;
  204.  
  205. function CopyPalette(Palette: HPALETTE): HPALETTE;
  206. var
  207.   PaletteSize: Integer;
  208.   LogSize: Integer;
  209.   LogPalette: PLogPalette;
  210. begin
  211.   Result := 0;
  212.   if Palette = 0 then Exit;
  213.   GetObject(Palette, SizeOf(PaletteSize), @PaletteSize);
  214.   LogSize := SizeOf(TLogPalette) + (PaletteSize - 1) * SizeOf(TPaletteEntry);
  215.   GetMem(LogPalette, LogSize);
  216.   try
  217.     with LogPalette^ do
  218.     begin
  219.       palVersion := $0300;
  220.       palNumEntries := PaletteSize;
  221.       GetPaletteEntries(Palette, 0, PaletteSize, palPalEntry);
  222.     end;
  223.     Result := CreatePalette(LogPalette^);
  224.   finally
  225.     FreeMem(LogPalette, LogSize);
  226.   end;
  227. end;
  228.  
  229. constructor TPaletteGrid.Create(AOwner: TComponent);
  230. begin
  231.   inherited Create(AOwner);
  232.   DefaultColWidth := 20;
  233.   DefaultRowHeight := 20;
  234.   Options := [];
  235.   GridLineWidth := 0;
  236.   FixedCols := 0;
  237.   FixedRows := 0;
  238.   ColCount := 0;
  239.   RowCount := 0;
  240.   DefaultDrawing := False;
  241.   ScrollBars := ssVertical;
  242. end;
  243.  
  244. destructor TPaletteGrid.Destroy;
  245. begin
  246.   if FPalette <> 0 then DeleteObject(FPalette);
  247.   inherited Destroy;
  248. end;
  249.  
  250. procedure TPaletteGrid.UpdateSize;
  251. var
  252.   Rows: Integer;
  253. begin
  254.   if FSizing then Exit;
  255.   FSizing := True;
  256.   try
  257.     ColCount := (ClientWidth - GetSystemMetrics(SM_CXVSCROLL)) div
  258.       DefaultColWidth;
  259.     Rows := FCount div ColCount;
  260.     if FCount mod ColCount > 0 then Inc(Rows);
  261.     RowCount := Max(1, Rows);
  262.     ClientHeight := DefaultRowHeight * RowCount;
  263.   finally
  264.     FSizing := False;
  265.   end;
  266. end;
  267.  
  268. function TPaletteGrid.GetPalette: HPALETTE;
  269. begin
  270.   if FPalette <> 0 then Result := FPalette
  271.   else Result := inherited GetPalette;
  272. end;
  273.  
  274. procedure TPaletteGrid.SetPalette(Value: HPALETTE);
  275. var
  276.   I: Integer;
  277.   ParentForm: TCustomForm;
  278. begin
  279.   if FPalette <> 0 then DeleteObject(FPalette);
  280.   FPalette := CopyPalette(Value);
  281.   FCount := Min(PaletteEntries(FPalette), NumPaletteEntries);
  282.   GetPaletteEntries(FPalette, 0, FCount, FPaletteEntries);
  283.   for I := FCount to NumPaletteEntries - 1 do
  284.     FillChar(FPaletteEntries[I], SizeOf(TPaletteEntry), $80);
  285.   UpdateSize;
  286.   if Visible and (not (csLoading in ComponentState)) then begin
  287.     ParentForm := GetParentForm(Self);
  288.     if Assigned(ParentForm) and ParentForm.Active and
  289.       Parentform.HandleAllocated then
  290.       PostMessage(ParentForm.Handle, WM_QUERYNEWPALETTE, 0, 0);
  291.   end;
  292. end;
  293.  
  294. function TPaletteGrid.CellColor(ACol, ARow: Longint): TColor;
  295. var
  296.   PalIndex: Integer;
  297. begin
  298.   PalIndex := ACol + (ARow * ColCount);
  299.   if PalIndex <= FCount - 1 then
  300.     with FPaletteEntries[PalIndex] do
  301.       Result := TColor(RGB(peRed, peGreen, peBlue))
  302.   else Result := clNone;
  303. end;
  304.  
  305. procedure TPaletteGrid.DrawSquare(CellColor: TColor; CellRect: TRect;
  306.   ShowSelector: Boolean);
  307. var
  308.   SavePal: HPalette;
  309. begin
  310.   Canvas.Pen.Color := clBtnFace;
  311.   with CellRect do Canvas.Rectangle(Left, Top, Right, Bottom);
  312.   InflateRect(CellRect, -1, -1);
  313.   Frame3D(Canvas, CellRect, clBtnShadow, clBtnHighlight, 2);
  314.   SavePal := 0;
  315.   if FPalette <> 0 then begin
  316.     SavePal := SelectPalette(Canvas.Handle, FPalette, False);
  317.     RealizePalette(Canvas.Handle);
  318.   end;
  319.   try
  320.     Canvas.Brush.Color := CellColor;
  321.     Canvas.Pen.Color := CellColor;
  322.     with CellRect do Canvas.Rectangle(Left, Top, Right, Bottom);
  323.   finally
  324.     if FPalette <> 0 then SelectPalette(Canvas.Handle, SavePal, True);
  325.   end;
  326.   if ShowSelector then begin
  327.     Canvas.Brush.Color := Self.Color;
  328.     Canvas.Pen.Color := Self.Color;
  329.     InflateRect(CellRect, -1, -1);
  330.     Canvas.DrawFocusRect(CellRect);
  331.   end;
  332. end;
  333.  
  334. function TPaletteGrid.SelectCell(ACol, ARow: Longint): Boolean;
  335. begin
  336.   Result := ((ACol = 0) and (ARow = 0)) or (CellColor(ACol, ARow) <> clNone);
  337. end;
  338.  
  339. procedure TPaletteGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
  340.   AState: TGridDrawState);
  341. var
  342.   Color: TColor;
  343. begin
  344.   Color := CellColor(ACol, ARow);
  345.   if Color <> clNone then
  346.     DrawSquare(PaletteColor(Color), ARect, gdFocused in AState)
  347.   else begin
  348.     Canvas.Brush.Color := Self.Color;
  349.     Canvas.FillRect(ARect);
  350.   end;
  351. end;
  352.  
  353. procedure TPaletteGrid.WMSize(var Message: TWMSize);
  354. begin
  355.   inherited;
  356.   UpdateSize;
  357. end;
  358.  
  359. { TCustomClipboardViewer }
  360.  
  361. constructor TCustomClipboardViewer.Create(AOwner: TComponent);
  362. begin
  363.   inherited Create(AOwner);
  364.   ControlState := ControlState + [csCreating];
  365. {$IFNDEF WIN32}
  366.   ControlStyle := ControlStyle + [csFramed];
  367. {$ENDIF}
  368.   FWndNext := 0;
  369.   FPaintControl := nil;
  370.   FViewFormat := cvDefault;
  371.   ParentColor := False;
  372.   Color := clWindow;
  373.   ControlState := ControlState - [csCreating];
  374. end;
  375.  
  376. procedure TCustomClipboardViewer.ForwardMessage(var Message: TMessage);
  377. begin
  378.   if FWndNext <> 0 then
  379.     with Message do SendMessage(FWndNext, Msg, WParam, LParam);
  380. end;
  381.  
  382. procedure TCustomClipboardViewer.CreateWnd;
  383. begin
  384.   inherited CreateWnd;
  385.   if Handle <> 0 then begin
  386.     FWndNext := SetClipboardViewer(Handle);
  387.     FChained := True;
  388.   end;
  389. end;
  390.  
  391. procedure TCustomClipboardViewer.DestroyWindowHandle;
  392. begin
  393.   if FChained then begin
  394.     ChangeClipboardChain(Handle, FWndNext);
  395.     FChained := False;
  396.   end;
  397.   FWndNext := 0;
  398.   inherited DestroyWindowHandle;
  399. end;
  400.  
  401. procedure TCustomClipboardViewer.CreatePaintControl;
  402. var
  403.   Icon: TIcon;
  404.   Format: TClipboardViewFormat;
  405.   Instance: TComponent;
  406. begin
  407.   if csDesigning in ComponentState then Exit;
  408.   FPaintControl.Free;
  409.   FPaintControl := nil;
  410.   if IsEmptyClipboard then Exit;
  411.   Format := GetDrawFormat;
  412.   if not ValidFormat(Format) then Format := cvUnknown;
  413.   case Format of
  414.     cvText, cvOemText, cvUnknown, cvDefault, cvEmpty:
  415.       begin
  416.         FPaintControl := TMemo.Create(Self);
  417.         with TMemo(FPaintControl) do begin
  418.           BorderStyle := bsNone;
  419.           Parent := Self;
  420.           Left := 0;
  421.           Top := 0;
  422.           ScrollBars := ssBoth;
  423.           Align := alClient;
  424.           if Format = cvOemText then begin
  425.             ParentFont := False;
  426.             Font.Name := 'Terminal';
  427.           end;
  428.           Visible := True;
  429.           if Clipboard.HasFormat(CF_TEXT) then PasteFromClipboard
  430.           else if (Format = cvText) and Clipboard.HasFormat(CF_COMPONENT) then
  431.           begin
  432.             Instance := Clipboard.GetComponent(Self, Self);
  433.             try
  434.               ComponentToStrings(Instance, Lines);
  435.             finally
  436.               Instance.Free;
  437.             end;
  438.           end
  439.           else if IsEmptyClipboard then Text := LoadStr(SClipbrdEmpty)
  440.           else Text := LoadStr(SClipbrdUnknown);
  441.           ReadOnly := True;
  442.         end;
  443.       end;
  444.     cvPicture, cvMetafile, cvBitmap, cvIcon:
  445.       begin
  446.         FPaintControl := TImage.Create(Self);
  447.         with TImage(FPaintControl) do begin
  448.           Parent := Self;
  449.           AutoSize := True;
  450.           Left := 0;
  451.           Top := 0;
  452.           Visible := True;
  453.           if Format = cvIcon then begin
  454.             if Clipboard.HasFormat(CF_ICON) then begin
  455.               Icon := CreateIconFromClipboard;
  456.               try
  457.                 Picture.Icon := Icon;
  458.               finally
  459.                 Icon.Free;
  460.               end;
  461.             end;
  462.           end
  463.           else if ((Format = cvBitmap) and Clipboard.HasFormat(CF_BITMAP))
  464.             or ((Format = cvMetafile) and (Clipboard.HasFormat(CF_METAFILEPICT))
  465.             {$IFDEF WIN32} or Clipboard.HasFormat(CF_ENHMETAFILE) {$ENDIF WIN32})
  466.             or ((Format = cvPicture) and Clipboard.HasFormat(CF_PICTURE)) then
  467.           begin
  468.             Picture.Assign(Clipboard);
  469.           end;
  470.         end;
  471.         CenterControl(TImage(FPaintControl));
  472.       end;
  473.     cvComponent:
  474.       begin
  475.         Instance := Clipboard.GetComponent(Self, Self);
  476.         FPaintControl := Instance;
  477.         if FPaintControl is TControl then
  478.         begin
  479.           with TControl(FPaintControl) do begin
  480.             Left := 1;
  481.             Top := 1;
  482.             Parent := Self;
  483.           end;
  484.           CenterControl(TControl(FPaintControl));
  485.         end
  486.         else begin
  487.           FPaintControl := TMemo.Create(Self);
  488.           try
  489.             with TMemo(FPaintControl) do begin
  490.               BorderStyle := bsNone;
  491.               Parent := Self;
  492.               Left := 0;
  493.               Top := 0;
  494.               ScrollBars := ssBoth;
  495.               Align := alClient;
  496.               ReadOnly := True;
  497.               ComponentToStrings(Instance, Lines);
  498.               Visible := True;
  499.             end;
  500.           finally
  501.             Instance.Free;
  502.           end;
  503.         end;
  504.       end;
  505.     cvPalette:
  506.       begin
  507.         FPaintControl := TPaletteGrid.Create(Self);
  508.         with TPaletteGrid(FPaintControl) do
  509.         try
  510.           BorderStyle := bsNone;
  511.           Parent := Self;
  512.           Ctl3D := False;
  513.           Align := alClient;
  514.           Clipboard.Open;
  515.           try
  516.             Palette := GetClipboardData(CF_PALETTE);
  517.           finally
  518.             Clipboard.Close;
  519.           end;
  520.         except
  521.           FPaintControl.Free;
  522.           raise;
  523.         end;
  524.       end;
  525.   end;
  526. end;
  527.  
  528. function TCustomClipboardViewer.GetClipboardFormatNames(Index: Integer): string;
  529. begin
  530.   Result := '';
  531.   if Index < Clipboard.FormatCount then
  532.     Result := ClipboardFormatName(Clipboard.Formats[Index]);
  533. end;
  534.  
  535. procedure TCustomClipboardViewer.Change;
  536. begin
  537.   if Assigned(FOnChange) then FOnChange(Self);
  538. end;
  539.  
  540. procedure TCustomClipboardViewer.WMSize(var Message: TMessage);
  541. begin
  542.   inherited;
  543.   if (FPaintControl <> nil) and (FPaintControl is TControl) then
  544.     CenterControl(TControl(FPaintControl));
  545. end;
  546.  
  547. procedure TCustomClipboardViewer.WMChangeCBChain(var Message: TWMChangeCBChain);
  548. begin
  549.   if Message.Remove = FWndNext then FWndNext := Message.Next
  550.   else ForwardMessage(TMessage(Message));
  551.   inherited;
  552. end;
  553.  
  554. procedure TCustomClipboardViewer.WMNCDestroy(var Message: TWMNCDestroy);
  555. begin
  556.   if FChained then begin
  557.     ChangeClipboardChain(Handle, FWndNext);
  558.     FChained := False;
  559.     FWndNext := 0;
  560.   end;
  561.   inherited;
  562. end;
  563.  
  564. procedure TCustomClipboardViewer.WMDrawClipboard(var Message: TMessage);
  565. var
  566.   Format: Word;
  567. begin
  568.   ForwardMessage(Message);
  569.   Format := ViewToClipboardFormat(ViewFormat);
  570.   if IsEmptyClipboard then FViewFormat := cvEmpty
  571.   else if not Clipboard.HasFormat(Format) then FViewFormat := cvDefault;
  572.   Change;
  573.   DisableAlign;
  574.   try
  575.     CreatePaintControl;
  576.   finally
  577.     EnableAlign;
  578.   end;
  579.   inherited;
  580. end;
  581.  
  582. procedure TCustomClipboardViewer.WMDestroyClipboard(var Message: TMessage);
  583. begin
  584.   FViewFormat := cvEmpty;
  585.   Change;
  586.   CreatePaintControl;
  587. end;
  588.  
  589. function TCustomClipboardViewer.IsEmptyClipboard: Boolean;
  590. begin
  591.   Result := (Clipboard.FormatCount = 0);
  592. end;
  593.  
  594. procedure TCustomClipboardViewer.SetViewFormat(Value: TClipboardViewFormat);
  595. var
  596.   Format: Word;
  597. begin
  598.   if Value <> ViewFormat then begin
  599.     Format := ViewToClipboardFormat(Value);
  600.     if (Clipboard.HasFormat(Format) and ValidFormat(Value)) then
  601.       FViewFormat := Value
  602.     else FViewFormat := cvDefault;
  603.     CreatePaintControl;
  604.   end;
  605. end;
  606.  
  607. function TCustomClipboardViewer.GetDrawFormat: TClipboardViewFormat;
  608.  
  609.   function DefaultFormat: TClipboardViewFormat;
  610.   begin
  611.     if Clipboard.HasFormat(CF_TEXT) then Result := cvText
  612.     else if Clipboard.HasFormat(CF_OEMTEXT) then Result := cvOemText
  613.     else if Clipboard.HasFormat(CF_BITMAP) then Result := cvBitmap
  614.     else if (Clipboard.HasFormat(CF_METAFILEPICT))
  615. {$IFDEF WIN32}
  616.       or (Clipboard.HasFormat(CF_ENHMETAFILE))
  617. {$ENDIF}
  618.       then Result := cvMetafile
  619.     else if Clipboard.HasFormat(CF_ICON) then Result := cvIcon
  620.     else if Clipboard.HasFormat(CF_PICTURE) then Result := cvPicture
  621.     else if Clipboard.HasFormat(CF_COMPONENT) then Result := cvComponent
  622.     else if Clipboard.HasFormat(CF_PALETTE) then Result := cvPalette
  623.     else Result := cvUnknown;
  624.   end;
  625.  
  626. begin
  627.   if IsEmptyClipboard then Result := cvEmpty
  628.   else begin
  629.     Result := ViewFormat;
  630.     if Result = cvDefault then Result := DefaultFormat;
  631.   end;
  632. end;
  633.  
  634. class function TCustomClipboardViewer.CanDrawFormat(ClipboardFormat: Word): Boolean;
  635. begin
  636.   Result := ClipboardFormatToView(ClipboardFormat) <> cvUnknown;
  637. end;
  638.  
  639. function TCustomClipboardViewer.ValidFormat(Format: TClipboardViewFormat): Boolean;
  640. begin
  641.   Result := (Format in [cvDefault, cvEmpty, cvUnknown]);
  642.   if not Result then begin
  643.     if Clipboard.HasFormat(ViewToClipboardFormat(Format)) then
  644.       Result := True;
  645.   end;
  646. end;
  647.  
  648. end.