/usr/lib/lazarus/0.9.30.4/lcl/clipbrd.pp is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375  | {
 /***************************************************************************
                               Clipbrd.pp
                             -------------------
                             Component Library Clipboard Controls
                   Initial Revision  : Sat Feb 26 2000
 ***************************************************************************/
 *****************************************************************************
 *                                                                           *
 *  This file is part of the Lazarus Component Library (LCL)                 *
 *                                                                           *
 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
 *  for details about the copyright.                                         *
 *                                                                           *
 *  This program is distributed in the hope that it will be useful,          *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
 *                                                                           *
 *****************************************************************************
}
{
@created(26-Feb-2000)
@lastmod(12-Nov-2001)
    @abstract(This is the clipboard class for Copy/Paste functions)
    Introduced by Shane Miller <smiller@lakefield.net>
    Rewrite done by Hongli Lai <hongli@telekabel.nl>
    Rewrite done by Mattias Gaertner <gaertner@informatik.uni-koeln.de>
Clipboard unit.
For Copying and Pasting.  You know what it's for!  Why am I explaining it?  :-)
  The clipboard object encapsulates the Windows clipboard and the three
  standard Gtk selections. For each of the three clipboards/selections there is
  an object: PrimarySelection, SecondarySelection and Clipboard.
  There is no difference between the three objects except their type.
  
  Brief explanation of TClipboard:
  AddFormat:
    Use these functions to add data to the supported formats.
  Assign:
    Add the data to the clipboard with the corresponding FormatID.
  Clear:
    Clear cache and supported format list.
  FindPictureFormatID
    Search the first FormatID that is a registered TGraphic.
  GetComponent
    Read a component from clipboard
  GetFormat
    Read data from clipboard
  SupportedFormats
    Fills a TStrings list with the supported mime type.
  SupportedFormats
    Returns an array of suupported formats. You must free the memory with
    FreeMem.
  GetTextBuf
    Fetch text from clipboard, if supported.
  HasFormat
    Look up if the format is supported. If Format is the TPicture format
    (CF_PICTURE) all registered graphics formats are tested.
  HasPictureFormat
    Returns true if FindPictureFormatID<>0
  SetComponent
    Write a component to the clipboard.
  SetFormat
    Clears the clipboard and adds the data.
  SetSupportedFormats
    Set all supported formats at once. All data will be empty. This procedure
    is useful if setting the OnRequest event to put the data on the fly.
    Example: Using the PrimarySelection from synedit.pp
      procedure TCustomSynEdit.AquirePrimarySelection;
      var
        FormatList: TClipboardFormat;
      begin
        if (not SelAvail) 
        or (PrimarySelection.OnRequest=@PrimarySelectionRequest) then exit;
        FormatList:=CF_TEXT;
        PrimarySelection.SetSupportedFormats(1,@FormatList);
        PrimarySelection.OnRequest:=@PrimarySelectionRequest;
      end;
      
  SetTextBuf
    Add text to the clipboard
  AsText
    Get text from or set text to the clipboard.
  ClipboardType
    The type of the clipboard object. For example:
      PrimarySelection.ClipboardType = ctPrimarySelection
  FormatCount
    Number of supported formats
  Formats
    You can read the formats with this property one by one. But this will result
    in many requests, which can be very slow (especially on terminals).
    Better use "SupportedFormats".
  OnRequest
    If the clipboard has the ownership, each time data is requested by the
    application or another application from the clipboard this event will be
    called. There is one special case: If the clipboard looses ownership the
    OnRequest event will be called with FormatID=0.
    This event will be erased on lost of ownership.
    If the OnRequest event was already set before, the prior method will be
    called with FormatID=0 to be notified of the loss.
  
  
  For mime types see:
    http://www.isi.edu/in-notes/iana/assignments/media-types/media-types
}
unit Clipbrd;
{$MODE Objfpc}{$H+}
interface
{$ifdef Trace}
  {$ASSERTIONS ON}
{$endif}
uses
  Classes, SysUtils, LCLproc, FPCAdds, LCLType, LResources, LCLIntf, GraphType,
  Graphics;
{ for delphi compatibility:
  In Delphi there are 4 predefined constants, but the LCL has only dynamic
  values.
  
  CF_TEXT = 1;
  CF_BITMAP = 2;
  CF_METAFILEPICT = 3;
  CF_OBJECT = 230
}
function CF_Text: TClipboardFormat;
function CF_Bitmap: TClipboardFormat;
function CF_Picture: TClipboardFormat;
function CF_MetaFilePict: TClipboardFormat;
function CF_Object: TClipboardFormat;
function CF_Component: TClipboardFormat;
type
  TClipboardData = record
    FormatID: TClipboardFormat;
    Stream: TMemoryStream;
  end;
  { TClipboard }
  TClipboard = Class(TPersistent)
  private
    FAllocated: Boolean;    // = has ownership
    FClipboardType: TClipboardType;
    FCount: integer;        // # formats of cached clipboard data
    FData: ^TClipboardData; // cached clipboard data
    FSupportedFormatsChanged: boolean;
    FOnRequest: TClipboardRequestEvent;
    FOpenRefCount: Integer; // reference count for Open and Close (not used yet)
    procedure AssignGraphic(Source: TGraphic);
    procedure AssignGraphic(Source: TGraphic; FormatID: TClipboardFormat);
    procedure AssignPicture(Source: TPicture);
    function AssignToGraphic(Dest: TGraphic): boolean;
    function AssignToGraphic(Dest: TGraphic; FormatID: TClipboardFormat): boolean;
    //procedure AssignToMetafile(Dest: TMetafile);
    procedure AssignToPicture(Dest: TPicture);
    function GetAsText: string;
    function GetFormatCount: Integer;
    function GetFormats(Index: Integer): TClipboardFormat;
    function GetOwnerShip: boolean;
    function IndexOfCachedFormatID(FormatID: TClipboardFormat; 
      CreateIfNotExists: boolean): integer;
    procedure InternalOnRequest(const RequestedFormatID: TClipboardFormat;
      AStream: TStream);
    procedure SetAsText(const Value: string);
    function SetBuffer(FormatID: TClipboardFormat;
                       var Buffer; Size: Integer): Boolean;
    procedure SetOnRequest(AnOnRequest: TClipboardRequestEvent);
    procedure BeginUpdate;
    function EndUpdate: Boolean;
    function IsUpdating: Boolean;
    function CanReadFromInterface: Boolean;
    function CanReadFromCache: Boolean;
    procedure OnDefaultFindClass(Reader: TReader; const AClassName: string;
                                 var ComponentClass: TComponentClass);
  public
    function AddFormat(FormatID: TClipboardFormat; Stream: TStream): Boolean;
    function AddFormat(FormatID: TClipboardFormat; var Buffer; Size: Integer): Boolean;
    procedure Assign(Source: TPersistent); override;
    procedure AssignTo(Dest: TPersistent); override;
    procedure Clear;
    procedure Close;
    constructor Create;
    constructor Create(AClipboardType: TClipboardType);
    destructor Destroy; override;
    function FindPictureFormatID: TClipboardFormat;
    function FindFormatID(const FormatName: string): TClipboardFormat;
    //function GetAsHandle(Format: integer): THandle;
    function GetComponent(Owner, Parent: TComponent): TComponent;
    procedure GetComponent(var RootComponent: TComponent;
                          OnFindComponentClass: TFindComponentClassEvent;
                          Owner: TComponent = nil;
                          Parent: TComponent = nil);
    procedure GetComponentAsText(var RootComponent: TComponent;
                                 OnFindComponentClass: TFindComponentClassEvent;
                                 Owner: TComponent = nil;
                                 Parent: TComponent = nil);
    function GetFormat(FormatID: TClipboardFormat; Stream: TStream): Boolean;
    procedure SupportedFormats(List: TStrings);
    procedure SupportedFormats(var AFormatCount: integer;
                               var FormatList: PClipboardFormat);
    function GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;
    function HasFormat(FormatID: TClipboardFormat): Boolean;
    function HasFormatName(const FormatName: string): Boolean;
    function HasPictureFormat: boolean;
    procedure Open;
    //procedure SetAsHandle(Format: integer; Value: THandle);
    function SetComponent(Component: TComponent): Boolean;
    function SetComponentAsText(Component: TComponent): Boolean;
    function SetFormat(FormatID: TClipboardFormat; Stream: TStream): Boolean;
    function SetSupportedFormats(AFormatCount: integer;
                                  FormatList: PClipboardFormat): Boolean;
    procedure SetTextBuf(Buffer: PChar);
    property AsText: string read GetAsText write SetAsText;
    property ClipboardType: TClipboardType read FClipboardType;
    property FormatCount: Integer read GetFormatCount;
    property Formats[Index: Integer]: TClipboardFormat read GetFormats;
    property OnRequest: TClipboardRequestEvent read FOnRequest write SetOnRequest;
  end;
function Clipboard: TClipboard;
function SetClipboard(NewClipboard: TClipboard): TClipboard;
function PrimarySelection: TClipboard;
function SecondarySelection: TClipboard;
function Clipboard(ClipboardType: TClipboardType): TClipboard;
function SetClipboard(ClipboardType: TClipboardType;
  NewClipboard: TClipboard): TClipboard;
procedure FreeAllClipboards;
function RegisterClipboardFormat(const Format: string): TClipboardFormat;
implementation
var
  FClipboards: array[TClipboardType] of TClipboard;
{$I clipbrd.inc}
function RegisterClipboardFormat(const Format: string): TClipboardFormat;
begin
  Result:=ClipboardRegisterFormat(Format);
end;
function Clipboard: TClipboard;
begin
  Result:=Clipboard(ctClipboard);
end;
function SetClipboard(NewClipboard: TClipboard): TClipboard;
begin
  Result:=SetClipboard(ctClipboard,NewClipboard);
end;
function PrimarySelection: TClipboard;
begin
  Result:=Clipboard(ctPrimarySelection);
end;
function SecondarySelection: TClipboard;
begin
  Result:=Clipboard(ctSecondarySelection);
end;
function Clipboard(ClipboardType: TClipboardType): TClipboard;
begin
  if not Assigned(FClipboards[ClipboardType]) then
     FClipboards[ClipboardType] := TClipboard.Create(ClipboardType);
  Result := FClipboards[ClipboardType];
end;
function SetClipboard(ClipboardType: TClipboardType;
  NewClipboard: TClipboard): TClipboard;
begin
  if Assigned(FClipboards[ClipboardType]) then
  begin
     FClipboards[ClipboardType].Free;
     FClipboards[ClipboardType] := nil;
  end;
  FClipboards[ClipboardType] := NewClipboard;
  Result := FClipboards[ClipboardType];
end;
function CF_Text: TClipboardFormat;
begin
  Result:=PredefinedClipboardFormat(pcfDelphiText);
end;
function CF_Bitmap: TClipboardFormat;
begin
  Result:=PredefinedClipboardFormat(pcfDelphiBitmap);
end;
function CF_Picture: TClipboardFormat;
begin
  Result:=PredefinedClipboardFormat(pcfDelphiPicture);
end;
function CF_MetaFilePict: TClipboardFormat;
begin
  Result:=PredefinedClipboardFormat(pcfDelphiMetaFilePict);
end;
function CF_Object: TClipboardFormat;
begin
  Result:=PredefinedClipboardFormat(pcfDelphiObject);
end;
function CF_Component: TClipboardFormat;
begin
  Result:=PredefinedClipboardFormat(pcfDelphiComponent);
end;
procedure FreeAllClipboards;
var AClipboardType: TClipboardType;
begin
  for AClipboardType:=Low(TClipboardType) to High(TClipboardType) do
    FreeAndNil(FClipboards[AClipboardType]);
end;
procedure LoadGraphicFromClipboardFormat(Dest: TGraphic;
  ClipboardType: TClipboardType; FormatID: TClipboardFormat);
begin
  Clipboard(ClipboardType).AssignToGraphic(Dest,FormatID);
end;
procedure SaveGraphicToClipboardFormat(Src: TGraphic;
  ClipboardType: TClipboardType; FormatID: TClipboardFormat);
begin
  Clipboard(ClipboardType).AssignGraphic(Src,FormatID);
end;
//-----------------------------------------------------------------------------
procedure InternalInit;
var
  AClipboardType: TClipboardType;
begin
  OnLoadGraphicFromClipboardFormat:=@LoadGraphicFromClipboardFormat;
  OnSaveGraphicToClipboardFormat:=@SaveGraphicToClipboardFormat;
  OnLoadSaveClipBrdGraphicValid:=true;
  for AClipboardType:=Low(TClipboardType) to High(TClipboardType) do
    FClipboards[AClipboardType]:=nil;
end;
procedure InternalFinal;
begin
  OnLoadSaveClipBrdGraphicValid:=false;
  FreeAllClipboards;
end;
initialization
  InternalInit;
  
finalization
  InternalFinal;
end.
 |