-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCCR.Clipboard.pas
3509 lines (3162 loc) · 116 KB
/
CCR.Clipboard.pas
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{**************************************************************************************}
{ }
{ CCR.Clipboard }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 2.0 }
{ (the "License"); you may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at https://www.mozilla.org/MPL/2.0 }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT }
{ WARRANTY OF ANY KIND, either express or implied. See the License for the specific }
{ language governing rights and limitations under the License. }
{ }
{ The Initial Developer of the Original Code is Chris Rolliston. Portions created by }
{ Chris Rolliston are Copyright (C) 2012-15 Chris Rolliston. All Rights Reserved. }
{ }
{**************************************************************************************}
unit CCR.Clipboard;
{
Abstracts from the Windows clipboard, OLE drag and drop, and Cocoa pasteboard APIs to
provide an interface very close to the stock VCL TClipboard, only with many added
features; supports both FMX and the VCL.
Currently Windows and OS X for XE2+ and iOS for XE7+ are supported; for unknown
future target platforms, a default text-only implementation is provided that delegates
to the text-only IFMXClipboardService.
}
interface
{$IFDEF NEXTGEN}
{$LEGACYIFEND ON}
{$ENDIF}
uses
System.SysUtils, System.Classes, System.Generics.Collections, System.Generics.Defaults,
System.TypInfo, System.Rtti {$IF RTLVersion >= 29}, System.Hash{$IFEND};
type
EClipboardException = class(Exception);
EUnsupportedClipboardFeature = class(EClipboardException);
TClipboard = class;
{ On Windows a TClipboardFormat holds a CF_XXX value, on OS X and iOS a CFStringRef.
In general it's best to consider TClipboardFormat an opaque type however. If the
underlying native representation is really required, CCR.Clipboard.Apple and
CCR.Clipboard.Win both extend TClipboardFormat with a Handle instance property and
Wrap class method appropriate for their respective platforms. }
TClipboardFormat = record
strict private
OrdValue: NativeUInt;
function GetName: string;
function GetDescription: string;
public
class operator Equal(const Format1, Format2: TClipboardFormat): Boolean;
class operator NotEqual(const Format1, Format2: TClipboardFormat): Boolean; inline;
function ConformsTo(const BaseFormat: TClipboardFormat): Boolean;
function ToHexString(MinDigits: Integer = 4): string; inline;
property Description: string read GetDescription;
property Name: string read GetName;
end;
TObjectHandlerList<T: IInterface> = class
strict private type
TItem = class
Detail: TPair<TClass, T>;
GenCount: Integer;
end;
strict private
FItems: TObjectList<TItem>;
function FindItem(const ClassFor: TClass; var Matched: TItem; Exact: Boolean): Boolean;
public
constructor Create;
destructor Destroy; override;
procedure AddOrReplace(const ClassFor: TClass; const Handler: T);
function Find(const ClassFor: TClass; var Handler: T): Boolean;
end;
TEnumFormatSetsCallback = reference to procedure (const Formats: TArray<TClipboardFormat>;
const GetFormatBytes: TFunc<TClipboardFormat, TBytes>; var LookForMore: Boolean);
TGetBytesCallback = reference to procedure (const Bytes: TBytes; var LookForMore: Boolean);
TGetInstancesCallback<T> = reference to procedure (const Obj: T; var LookForMore: Boolean);
TLoadObjectsCallback<T: class> = reference to procedure (
const AssignTo: TProc<T>; var LookForMore: Boolean);
TEnumVirtualFilesStreamCallback = reference to procedure (const Descriptor: string;
const SaveToStream: TProc<TStream>; var LookForMore: Boolean);
TEnumVirtualFileBytesCallback = reference to procedure (const Descriptor: string;
const GetBytes: TFunc<TBytes>; var LookForMore: Boolean);
TSaveVirtualFileFunc = reference to function (const DestDirectory: string): TFileName;
TSaveVirtualFilesCallback = reference to procedure (const Descriptor: string;
const SaveToFile: TSaveVirtualFileFunc; var LookForMore: Boolean);
TVirtualTextFileOption = (tfNeverOutputBOM);
TVirtualTextFileOptions = set of TVirtualTextFileOption;
TAssignClipboardForDragEvent = reference to procedure (DraggedObject: TObject; Clipboard: TClipboard);
IClipboardDropInfo = interface
['{9734706E-17CD-4624-91F0-0F9FAF720775}']
function GetClipboard: TClipboard;
property Clipboard: TClipboard read GetClipboard;
end;
ICustomClipper = interface
['{399C374B-854A-47D6-AA89-64642E8FC078}']
function CanLoadFromClipboard(const Clipboard: TClipboard): Boolean;
end;
ICustomClipper<T> = interface(ICustomClipper)
procedure SaveToClipboard(const Clipboard: TClipboard; PreferDelayed: Boolean;
const Getter: TFunc<T>);
end;
IRecordClipper<T: record> = interface(ICustomClipper<T>)
procedure LoadFromClipboard(const Clipboard: TClipboard;
const Callback: TGetInstancesCallback<T>);
end;
IObjectClipper<T: class> = interface(ICustomClipper<T>)
['{A1F0A310-77BD-4DD7-A1A5-AF4BED2CA220}']
procedure LoadFromClipboard(const Clipboard: TClipboard;
const Callback: TLoadObjectsCallback<T>);
end;
TLoadFromClipboardFormatEvent<T: class> = reference to procedure (const Clipboard: TClipboard;
const Format: TClipboardFormat; Obj: T);
TSaveToClipboardFormatEvent<T: class> = reference to procedure (const Clipboard: TClipboard;
const Format: TClipboardFormat; PreferDelayed: Boolean; const ObjGetter: TFunc<T>);
TLoadFromClipboardStreamEvent<T: class> = reference to procedure (Obj: T; Stream: TStream);
TSaveToClipboardStreamEvent<T: class> = reference to procedure (Obj: T;
const Format: TClipboardFormat; Stream: TStream);
TObjectClipper<T: class> = class abstract(TInterfacedObject, ICustomClipper, IObjectClipper<T>)
strict private
FReadFormats, FWrittenFormats: TArray<TClipboardFormat>;
strict protected
function CreateBlankObject: T; virtual; abstract;
function CanLoadFromClipboardFile(const Clipboard: TClipboard): Boolean; virtual;
procedure LoadFromClipboardFormat(const Clipboard: TClipboard;
const Format: TClipboardFormat; const Callback: TLoadObjectsCallback<T>); virtual; abstract;
procedure LoadFromClipboardFiles(const Clipboard: TClipboard;
const Callback: TLoadObjectsCallback<T>); virtual;
procedure SaveToClipboardFormat(Clipboard: TClipboard; const Format: TClipboardFormat;
PreferDelayed: Boolean; const ObjGetter: TFunc<T>); virtual; abstract;
{ IObjectClipper<T> }
function CanLoadFromClipboard(const Clipboard: TClipboard): Boolean;
procedure LoadFromClipboard(const Clipboard: TClipboard; const Callback: TLoadObjectsCallback<T>); overload;
procedure SaveToClipboard(const Clipboard: TClipboard; PreferDelayed: Boolean;
const ObjGetter: TFunc<T>); overload; virtual;
protected
property ReadFormats: TArray<TClipboardFormat> read FReadFormats;
property WrittenFormats: TArray<TClipboardFormat> read FWrittenFormats;
public
constructor Create(const ReadFormats, WrittenFormats: array of TClipboardFormat);
end;
TClipping = class(TComponent)
strict private class var
FFormatSettings: TFormatSettings;
class constructor InitializeClass;
strict private
FClippedClass: string;
FDateTime: string;
FOriginator: string;
FObj: TPersistent;
FSetSubComponent: Boolean;
FRTLVersion: Single;
procedure SetObj(const Value: TPersistent);
public
constructor Create(const ObjToWrap: TPersistent); reintroduce;
destructor Destroy; override;
published
//provide some metadata
property TimeStamp: string read FDateTime write FDateTime;
property Originator: string read FOriginator write FOriginator;
property RTLVersion: Single read FRTLVersion write FRTLVersion;
property ClippedClass: string read FClippedClass write FClippedClass;
//provide the actual clipped object
property Clipped: TPersistent read FObj write SetObj;
end;
ISimpleObjectClipper<T: TPersistent> = interface(IObjectClipper<T>)
function GetOnBeginRead: TProc<TReader>;
function GetOnEndRead: TProc<TClipping>;
procedure SetOnBeginRead(const NewHandler: TProc<TReader>);
procedure SetOnEndRead(const NewHandler: TProc<TClipping>);
function GetFormat: TClipboardFormat;
property Format: TClipboardFormat read GetFormat;
property OnBeginRead: TProc<TReader> read GetOnBeginRead write SetOnBeginRead;
property OnEndRead: TProc<TClipping> read GetOnEndRead write SetOnEndRead;
end;
TPersistentClipper<T: TPersistent, constructor> = class(TObjectClipper<T>, ISimpleObjectClipper<T>)
strict private
FOnBeginRead: TProc<TReader>;
FOnEndRead: TProc<TClipping>;
strict protected
function CreateBlankObject: T; override;
procedure LoadFromClipboardFormat(const Clipboard: TClipboard;
const Format: TClipboardFormat; const Callback: TLoadObjectsCallback<T>); override;
procedure SaveToClipboardFormat(Clipboard: TClipboard; const Format: TClipboardFormat;
PreferDelayed: Boolean; const ObjGetter: TFunc<T>); override;
{ ISimpleObjectClipper<T> }
function GetOnBeginRead: TProc<TReader>;
function GetOnEndRead: TProc<TClipping>;
procedure SetOnBeginRead(const NewHandler: TProc<TReader>);
procedure SetOnEndRead(const NewHandler: TProc<TClipping>);
function GetFormat: TClipboardFormat;
protected
procedure BeginRead(Reader: TReader); virtual;
procedure EndRead(Clipping: TClipping); virtual;
public
constructor Create(const Format: TClipboardFormat);
end;
TStreamableObjectClipper<T: class> = class abstract(TObjectClipper<T>)
strict private
FFileExts: TArray<string>;
protected
class function ObjAsIStreamPersist(const Obj: TObject): IStreamPersist; static;
function CanLoadFromClipboardFile(const Clipboard: TClipboard): Boolean; override;
function IsCompatibleVirtualFile(const Descriptor: string): Boolean; inline;
procedure LoadFromClipboardFormat(const Clipboard: TClipboard;
const Format: TClipboardFormat; const Callback: TLoadObjectsCallback<T>); override;
procedure LoadFromStream(Obj: T; const Stream: TStream); virtual;
procedure LoadFromClipboardFiles(const Clipboard: TClipboard;
const Callback: TLoadObjectsCallback<T>); override;
procedure SaveToStream(const Obj: T; const Format: TClipboardFormat; Stream: TStream); virtual;
procedure SaveToClipboardFormat(Clipboard: TClipboard;
const Format: TClipboardFormat; PreferDelayed: Boolean; const ObjGetter: TFunc<T>); override;
property FileExts: TArray<string> read FFileExts;
public
constructor Create(const Formats: array of TClipboardFormat; const FileExts: array of string); overload;
constructor Create(const ReadFormats, WrittenFormats: array of TClipboardFormat;
const FileExts: array of string); overload;
end;
TDelegatedObjectClipper<T: class, constructor> = class(TStreamableObjectClipper<T>)
strict private
FOnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
FOnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>;
FOnLoadFromStream: TLoadFromClipboardStreamEvent<T>;
FOnSaveToStream: TSaveToClipboardStreamEvent<T>;
strict protected
function CreateBlankObject: T; override;
procedure LoadFromClipboardFormat(const Clipboard: TClipboard;
const Format: TClipboardFormat; const Callback: TLoadObjectsCallback<T>); override;
procedure LoadFromStream(ObjToLoad: T; const Stream: TStream); override;
procedure SaveToStream(const ObjToSave: T; const Format: TClipboardFormat; Stream: TStream); override;
procedure SaveToClipboardFormat(Clipboard: TClipboard;
const Format: TClipboardFormat; PreferDelayed: Boolean; const ObjGetter: TFunc<T>); override;
public
constructor Create(const ReadFormats, WrittenFormats: array of TClipboardFormat;
const FileExts: array of string;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>;
const OnLoadFromStream: TLoadFromClipboardStreamEvent<T>;
const OnSaveToStream: TSaveToClipboardStreamEvent<T>);
end;
TVirtualFileAdditionalDetail = (vfAttr, vfSize, vfCreationDate, vfLastAccessDate,
vfLastWriteDate, vfDatesAreUTC);
TVirtualFileAdditionalDetails = set of TVirtualFileAdditionalDetail;
TVirtualFileDetails = record
strict private
FAttr: Integer;
FCreationDate, FLastAccessDate, FLastWriteDate: TDateTime;
FSize: Int64;
procedure SetAttr(const Value: Integer);
procedure SetCreationDate(const Value: TDateTime);
procedure SetLastAccessDate(const Value: TDateTime);
procedure SetLastWriteDate(const Value: TDateTime);
procedure SetSize(const Value: Int64);
public
FileName: string;
AdditionalData: TVirtualFileAdditionalDetails;
constructor Create(const AFileName: string; const AKnownSize: Int64 = 0);
property Attr: Integer read FAttr write SetAttr;
property CreationDate: TDateTime read FCreationDate write SetCreationDate;
property LastAccessDate: TDateTime read FLastAccessDate write SetLastAccessDate;
property LastWriteDate: TDateTime read FLastWriteDate write SetLastWriteDate;
property Size: Int64 read FSize write SetSize;
end;
TClipboardChangeCount = NativeUInt;
IClipboardListener = interface
['{69E4BCA1-9CA9-4D5B-B536-DEF2FE1C53F6}']
procedure ClipboardChanged(const Clipboard: TClipboard);
end;
TClipboard = class(TInterfacedPersistent)
public type
TEnumerator = record
strict private
FRegisteredFormats: TArray<TClipboardFormat>;
FIndex: Integer;
function GetCurrent: TClipboardFormat;
public
constructor Create(const AFormats: TArray<TClipboardFormat>);
function MoveNext: Boolean;
property Current: TClipboardFormat read GetCurrent;
end;
TStdFormatValues = class
cfComponent, cfComponents, cfFileName, cfGIF, cfJPEG, cfPNG, cfRTF, cfUnicodeText,
cfUTF8Text, cfTIFF, cfURL, cfVirtualFileDescriptor: TClipboardFormat;
end;
TCore = class(TInterfacedObject)
protected
class procedure Register;
class function ConformingFormat(const FormatToTest, BaseFormat: TClipboardFormat): Boolean; virtual;
class function SameFormat(const Format1, Format2: TClipboardFormat): Boolean; virtual;
class procedure InitializeFormats(StdFormats: TStdFormatValues;
var CustomFormatsSupported: Boolean); virtual; abstract;
class function GetFormatName(const Format: TClipboardFormat): string; virtual; abstract;
class function GetFormatDescription(const Format: TClipboardFormat): string; virtual;
class function RegisterFormat(const Name: string): TClipboardFormat; virtual;
class function IsCompatibleVirtualFileDescriptor(const Descriptor: string;
const SupportedFileExts: TArray<string>): Boolean; virtual;
strict private
FDummyChangeCount: TClipboardChangeCount;
FChangeNotifications: Boolean;
FOwnerWeakRef: Pointer;
function GetOwner: TClipboard; inline;
procedure SetChangeNotifications(Enable: Boolean);
strict protected //the HasXXX methods don't need to be virtual (are for interfaces)
function HasFile: Boolean;
function HasURL: Boolean;
function HasVirtualFile: Boolean;
procedure EnableChangeNotifications(const Callback: TThreadMethod); virtual;
procedure DisableChangeNotifications; virtual;
protected
constructor Create(const AOwner: TClipboard); virtual;
function WrapsSystemClipboard: Boolean; virtual;
function SupportsChangeNotifications: Boolean; virtual;
function GetChangeCount: TClipboardChangeCount; virtual;
function GetFormats: TArray<TClipboardFormat>; virtual; abstract;
function HasFormat(Format: TClipboardFormat): Boolean; overload; virtual; abstract;
function HasFormat(const Formats: array of TClipboardFormat; var Matched: TClipboardFormat): Boolean; overload; virtual; abstract;
function HasPlainText: Boolean; virtual;
function DoOpen: Boolean; virtual; abstract;
procedure DoClose; virtual; abstract;
procedure DoClear; virtual; abstract;
function ReadPlainText: TArray<string>; virtual; abstract;
procedure WritePlainText(const Renderer: TFunc<string>; PreferDelayed: Boolean); virtual; abstract;
public
destructor Destroy; override;
property Clipboard: TClipboard read GetOwner;
property ChangeNotifications: Boolean read FChangeNotifications write SetChangeNotifications;
end;
TCoreClass = class of TCore;
IReadWriteBytes = interface
['{D2DC7C1D-C701-4D6C-8002-B549349BEFA3}']
function ReadBytes(const Format: TClipboardFormat): TBytes;
procedure WriteBytes(const Format: TClipboardFormat;
const Renderer: TFunc<TBytes>; PreferDelayed: Boolean);
end;
IMultipleFormatSets = interface
['{1096EEF3-E605-4629-8AD7-941AEA9B07DD}']
procedure NewFormatSet;
procedure EnumBytes(const Format: TClipboardFormat; const Callback: TGetBytesCallback);
procedure EnumFormatSets(const Callback: TEnumFormatSetsCallback);
end;
IReadWriteStream = interface
['{C6E56A63-CB1D-480B-8A54-C75FC688C8C1}']
function ReadStream(const Format: TClipboardFormat; const Stream: TStream): Boolean;
procedure WriteStream(const Format: TClipboardFormat;
const Renderer: TProc<TStream>; PreferDelayed: Boolean);
end;
IReadWriteFileNames = interface
['{C9221809-4AFF-4796-985A-3654B7F2C44F}']
function HasFile: Boolean;
function ReadFileNames: TArray<string>;
procedure WriteFileName(const Renderer: TFunc<TFileName>; PreferDelayed: Boolean);
end;
IReadWriteURL = interface
['{EA8FDD4F-D91A-4D2C-A59D-D9BB9ECB9F39}']
function HasURL: Boolean;
function ReadURLs: TArray<string>;
procedure WriteURL(const Renderer: TFunc<string>; PreferDelayed: Boolean);
end;
IReadWriteVirtualFile = interface
['{2D4B25F6-8502-4BD5-9068-7BAA2DA2E0B5}']
function HasVirtualFile: Boolean;
function ReadVirtualFileDescriptors: TArray<string>;
procedure ReadVirtualFiles(const Callback: TEnumVirtualFilesStreamCallback);
procedure SaveVirtualFiles(const Callback: TSaveVirtualFilesCallback);
procedure WriteVirtualFile(const Details: TVirtualFileDetails;
const Renderer: TProc<TStream>; PreferDelayed: Boolean);
end;
IDelayedRendering = interface
['{61A843F1-E035-4B8C-9A5D-839B269AC248}']
function HasOutstandingPromisesToOS: Boolean;
procedure ResolveOutstandingPromisesToOS(IsExplicitlyRequested: Boolean);
procedure CancelOutstandingPromisesToOS;
end;
strict private type
TFindClipper = function (TypeHandle: Pointer; var Clipper: ICustomClipper): Boolean;
strict private const
RTFStringSig = '{\rtf';
strict private class var
RTFBytesSig: TBytes;
FObjectClippers: TObjectHandlerList<ICustomClipper>;
FRecordClippers: TDictionary<PTypeInfo, ICustomClipper>;
FCoreClass: TCoreClass;
FCreateReaderDef: TFunc<TStream, TReader>;
FFormatDescriptions: TDictionary<TClipboardFormat, string>;
FObjectBeingDragged: TObject;
FSingleton: TClipboard;
FStdFormats: TStdFormatValues;
FSupportsCustomFormats: Boolean;
FOnGetDragData: TDictionary<Pointer, TAssignClipboardForDragEvent>;
FOnStartDrag: TAssignClipboardForDragEvent;
class constructor InitializeClass;
class destructor FinalizeClass;
class procedure NeedClassInitialized; static; //workaround for class constructor getting called out of order on OS X!
class procedure CheckInterfaceAssigned<T: IInterface>(const Service: T); static;
class function AllocFormat(ClassType: TClass): TClipboardFormat; static;
class procedure NoClipperError(const TypeName: string); static;
class function TypeInfo<T>: PTypeInfo; static;
class function GetStdFormats: TStdFormatValues; static; inline;
class procedure SetCoreClass(const CoreClass: TCoreClass);
class function GetOnGetDragData(const DraggedObject: TObject): TAssignClipboardForDragEvent; static;
class procedure SetOnGetDragData(const DraggedObject: TObject; const Handler: TAssignClipboardForDragEvent); static;
private
class function CreateDynArray<T>(const Items: array of T): TArray<T>; static;
class function GetFormatDescription(const Format: TClipboardFormat): string;
class property CreateReaderDef: TFunc<TStream, TReader> read FCreateReaderDef;
strict private
FAssignedFormatCount: Integer;
FUserAssignDelayedCount: Integer;
FChangeListeners: TList<Pointer>; //weak refs
FComponentStreams: TObjectDictionary<TClipboardFormat, TBytesStream>;
FCore: TCore;
FCoreIntf: IInterface;
FDelayedRenderingIntf: IDelayedRendering;
FFileNamesCache: TArray<string>;
FFileNamesCacheChangeCount: TClipboardChangeCount;
FFormatsCache: TArray<TClipboardFormat>;
FFormatsCacheChangeCount: TClipboardChangeCount;
FFreeNotifyProxy: TComponent;
FIsOpenForWriting: Boolean;
FHasFormatForCache: array of TPair<Pointer, Boolean>;
FHasFormatForCacheCount: Integer;
FHasFormatForCacheChangeCount: TClipboardChangeCount;
FMultipleFormatSetsIntf: IMultipleFormatSets;
FReadWriteBytesIntf: IReadWriteBytes;
FReadWriteStreamIntf: IReadWriteStream;
FReadWriteFileNamesIntf: IReadWriteFileNames;
FReadWriteURLIntf: IReadWriteURL;
FReadWriteVirtualFileIntf: IReadWriteVirtualFile;
FOpenCount: Integer;
FURLsCache: TArray<string>;
FURLsCacheChangeCount: TClipboardChangeCount;
FVirtualFileDescriptorsCache: TArray<string>;
FVirtualFileDescriptorsCacheChangeCount: TClipboardChangeCount;
procedure AddFreeNotification(const Obj: TObject);
procedure RemoveFreeNotification(const Obj: TObject);
function HasFormatFor(TypeHandle: Pointer; const FindClipper: TFindClipper): Boolean; overload;
class function FindClipperForClass(TypeHandle: Pointer; var Clipper: ICustomClipper): Boolean; static;
class function FindClipperForRecord(TypeHandle: Pointer; var Clipper: ICustomClipper): Boolean; static;
function GetChangeCount: TClipboardChangeCount;
function GetEmpty: Boolean;
function GetAsRTF: string;
function GetAsURL: string;
procedure DoAssignBytes(UserAssignDelayed: Boolean; const Format: TClipboardFormat;
const Renderer: TFunc<TBytes>);
procedure DoAssignText(UserAssignDelayed: Boolean; const Renderer: TFunc<string>);
procedure DoAssignURL(UserAssignDelayed: Boolean; const Renderer: TFunc<string>);
procedure DoAssignVirtualFile(UserAssignDelayed: Boolean;
const Details: TVirtualFileDetails; const Renderer: TProc<TStream>); overload;
procedure DoAssignVirtualFile<T: class, IStreamPersist>(UserDelayed: Boolean;
const Details: TVirtualFileDetails; const ObjGetter: TFunc<T>); overload;
procedure DoAssignVirtualTextFile(UserDelayed: Boolean;
Details: TVirtualFileDetails; const Renderer: TFunc<string>;
Encoding: TEncoding; Options: TVirtualTextFileOptions);
procedure FlushComponents;
procedure ResolveOutstandingPromisesToOS(ExplicitlyRequested: Boolean); overload;
strict protected
class function CreateCombinedGetDragDataCallback(
const OnGetDataOverride: TAssignClipboardForDragEvent = nil;
const OnGetDataDefault: TProc = nil): TAssignClipboardForDragEvent; static;
class procedure SetObjectBeingDragged(const Obj: TObject); static;
protected
class procedure CheckIsRTF(const Str: string); overload; static;
class procedure CheckIsRTF(const Bytes: TBytes); overload; static;
class function GetSuitableCoreClass(const MinClass: TCoreClass): TCoreClass; static;
constructor Create(const ACore: TCore = nil);
procedure AssignTo(Dest: TPersistent); override;
procedure NotifyChangeListeners;
procedure OpenForReading;
procedure OpenForWriting;
function TryOpenForReading(RaiseExceptionIfOpenForWriting: Boolean = True): Boolean;
property Core: TCore read FCore;
class function GetSingleton: TClipboard;
class procedure NeedCoreClassSet;
class property CoreClass: TCoreClass read FCoreClass;
class property StdFormatValues: TStdFormatValues read GetStdFormats;
{$IF RTLVersion < 24}
public
{$IFEND}
procedure Add(const DoAssignCode: TProc);
public
destructor Destroy; override;
procedure BeforeDestruction; override;
function GetEnumerator: TEnumerator;
function IsSystemClipboard: Boolean; //as opposed to the drag and drop pasteboard or some other data object
procedure Clear;
function TryOpen: Boolean;
procedure Open;
procedure Close;
function IsOpenForWriting: Boolean;
procedure NewFormatSet;
{ Change listening }
function SupportsChangeListeners: Boolean;
procedure RegisterChangeListener(const Listener: IClipboardListener);
procedure UnregisterChangeListener(const Listener: IClipboardListener);
{ Assign }
procedure Assign(Source: TPersistent); overload; override;
procedure Assign(const Source: TObject); reintroduce; overload;
procedure Assign<T: record>(const Source: T); reintroduce; overload;
procedure Assign(const Format: TClipboardFormat; const Source: IStreamPersist); reintroduce; overload; inline;
procedure Assign(const Format: TClipboardFormat; const Source: TStream); reintroduce; overload; inline;
procedure Assign(const Format: TClipboardFormat; const Data: TBytes); reintroduce; overload;
procedure Assign(const Format: TClipboardFormat; const Buffer; Size: Integer); reintroduce; overload;
{ AssignDelayed }
procedure AssignDelayed(const Format: TClipboardFormat; const Renderer: TFunc<TBytes>); reintroduce; overload;
procedure AssignDelayed(const Format: TClipboardFormat; const Renderer: TProc<TStream>); reintroduce; overload;
procedure AssignDelayed<T>(const ObjGetter: TFunc<T>); reintroduce; overload;
procedure AssignDelayed<T: class, constructor>(const Renderer: TProc<T>); reintroduce; overload;
{ AssignFile/AssignFileDelayed }
procedure AssignFile(const FileName: TFileName); overload;
procedure AssignFileDelayed(const Renderer: TFunc<TFileName>); overload;
{ AssignRTF/AssignRTFDelayed }
procedure AssignRTF(const Value: string); overload;
procedure AssignRTF(const RTFBytes: TBytes); overload;
procedure AssignRTFDelayed(const Renderer: TFunc<string>); overload;
procedure AssignRTFDelayed(const Renderer: TFunc<TBytes>); overload;
procedure AssignRTFDelayed(const Renderer: TProc<TStream>); overload;
{ AssignText/AssignTextDelayed }
procedure AssignText(const Value: string); overload;
procedure AssignTextDelayed(const Renderer: TFunc<string>); overload;
{ AssignURL/AssignURLDelayed }
procedure AssignURL(const Value: string); overload;
procedure AssignURLDelayed(const Renderer: TFunc<string>); overload;
{ AssignVirtualFile }
procedure AssignVirtualFile(const VirtualFileName: string; const Data: TBytes); overload; //inline;
procedure AssignVirtualFile(Details: TVirtualFileDetails; const Data: TBytes); overload;
procedure AssignVirtualFile(const VirtualFileName: string; const Source: IStreamPersist); overload; //inline;
procedure AssignVirtualFile(const Details: TVirtualFileDetails; const Source: IStreamPersist); overload; inline;
procedure AssignVirtualFile(const VirtualFileName, Text: string; Encoding: TEncoding = nil;
Options: TVirtualTextFileOptions = []); overload;
procedure AssignVirtualFile(const Details: TVirtualFileDetails; const Text: string;
Encoding: TEncoding = nil; Options: TVirtualTextFileOptions = []); overload;
{ AssignVirtualFileDelayed }
procedure AssignVirtualFileDelayed(const VirtualFileName: string; const Renderer: TProc<TStream>); overload; inline;
procedure AssignVirtualFileDelayed(const Details: TVirtualFileDetails; const Renderer: TProc<TStream>); overload; inline;
procedure AssignVirtualFileDelayed(const VirtualFileName: string; const Renderer: TFunc<TBytes>); overload; inline;
procedure AssignVirtualFileDelayed(const Details: TVirtualFileDetails;
const Renderer: TFunc<TBytes>); overload; inline;
procedure AssignVirtualFileDelayed<T: class, IStreamPersist>(
const VirtualFileName: string; const ObjGetter: TFunc<T>); overload; inline;
procedure AssignVirtualFileDelayed<T: class, IStreamPersist>(
const Details: TVirtualFileDetails; const ObjGetter: TFunc<T>); overload; inline;
procedure AssignVirtualFileDelayed<T: class, constructor, IStreamPersist>(
const VirtualFileName: string; const Renderer: TProc<T>); overload; inline;
procedure AssignVirtualFileDelayed<T: class, constructor, IStreamPersist>(
const Details: TVirtualFileDetails; const Renderer: TProc<T>); overload; inline;
procedure AssignVirtualFileDelayed(const VirtualFileName: string; const Renderer: TFunc<string>;
Encoding: TEncoding = nil; Options: TVirtualTextFileOptions = []); overload; inline;
procedure AssignVirtualFileDelayed(const Details: TVirtualFileDetails;
const Renderer: TFunc<string>; Encoding: TEncoding = nil;
Options: TVirtualTextFileOptions = []); overload; inline;
{ other writing }
procedure LoadFromStream(const Format: TClipboardFormat; Stream: TStream);
procedure SetComponent(const Component: TComponent); overload; inline;
procedure SetComponent(const Format: TClipboardFormat; const Component: TComponent); overload;
{ promising status }
function HasOutstandingPromisesToOS: Boolean; inline;
procedure CancelOutstandingPromisesToOS; inline;
procedure ResolveOutstandingPromisesToOS; overload; inline;
{ reading data }
procedure EnumFormatSets(const Callback: TEnumFormatSetsCallback);
function GetBytes(const Format: TClipboardFormat): TBytes; overload;
procedure GetBytes(const Format: TClipboardFormat; const Callback: TGetBytesCallback); overload;
function GetComponent(const Owner: TComponent; const Parent: TComponent = nil): TComponent; overload;
function GetComponents(const Owner: TComponent; const Callback: TGetInstancesCallback<TComponent>): Boolean; overload; inline;
function GetComponents(const Owner: TComponent; const ReaderCreator: TFunc<TStream, TReader>;
const Callback: TGetInstancesCallback<TComponent>): Boolean; overload; inline;
function GetComponents(const Format: TClipboardFormat; const Owner: TComponent;
const Callback: TGetInstancesCallback<TComponent>): Boolean; overload; inline;
function GetComponents(const Format: TClipboardFormat; const Owner: TComponent;
const ReaderCreator: TFunc<TStream, TReader>; const Callback: TGetInstancesCallback<TComponent>): Boolean; overload;
function GetFormats: TArray<TClipboardFormat>;
function GetFileNames: TArray<string>; overload;
procedure GetFileNames(Strings: TStrings); overload;
procedure GetObjects<T: class>(const Callback: TLoadObjectsCallback<T>); overload;
procedure GetObjects<T: class, constructor>(DestList: TObjectList<T>); overload;
procedure GetValues<T: record>(const Callback: TGetInstancesCallback<T>); overload;
procedure GetValues<T: record>(DestList: TList<T>); overload;
function GetValues<T: record>: TArray<T>; overload;
function GetText: TArray<string>; overload;
procedure GetText(Strings: TStrings); overload;
function GetURLs: TArray<string>; overload;
procedure GetURLs(Strings: TStrings); overload;
function GetVirtualFileDescriptors: TArray<string>; overload;
procedure GetVirtualFileDescriptors(Strings: TStrings); overload;
procedure EnumVirtualFiles(const Callback: TEnumVirtualFilesStreamCallback); overload; inline;
procedure EnumVirtualFiles(const Callback: TEnumVirtualFileBytesCallback); overload;
procedure SaveVirtualFiles(const Callback: TSaveVirtualFilesCallback); overload;
procedure SaveVirtualFiles(const Directory: string; SavedFiles: TStrings); overload;
procedure SaveVirtualFiles(const Directory: string); overload;
function HasComponent: Boolean; inline;
function HasFile: Boolean;
function HasFormat(const Format: TClipboardFormat): Boolean; overload;
function HasFormat(const Formats: array of TClipboardFormat; var Matched: TClipboardFormat): Boolean; overload;
function HasFormat(const Formats: array of TClipboardFormat): Boolean; overload;
function HasFormatFor(const ClassType: TClass): Boolean; overload; inline;
function HasFormatFor<T>: Boolean; overload;
function HasText: Boolean;
function HasURL: Boolean;
function HasVirtualFile: Boolean;
function SaveToStream(const Format: TClipboardFormat; Stream: TStream): Boolean;
function ToString: string; overload; override;
property ChangeCount: TClipboardChangeCount read GetChangeCount;
property Empty: Boolean read GetEmpty;
property AsRTF: string read GetAsRTF write AssignRTF;
property AsText: string read ToString write AssignText;
property AsURL: string read GetAsURL write AssignURL;
property OpenCount: Integer read FOpenCount;
public
{ The range of possible clipboard formats (as distinct from the range of formats actually
in the clipboard) is considered global not local to any particular TClipboard instance.
Use the second version of RegisterFormat or RegisterFormatDescription to force
a specific value to be returned by GetFormatDescription; otherwise, the latter will
return either a system-provided description or the just format name. }
class function GetFormatName(const Format: TClipboardFormat): string; deprecated 'Use Format.Name instead';
class function RegisterFormat(const Name: string): TClipboardFormat; overload;
class function RegisterFormat(const Name, Description: string): TClipboardFormat; overload;
class procedure RegisterFormatDescription(const Format: TClipboardFormat; const Description: string);
class function SupportsCustomFormats: Boolean;
class function SupportsMultipleFormatSets: Boolean;
{ Returns True if a clipper has been registered for the type itself or an ancestor }
class function HasClipper(ClassType: TClass): Boolean; overload;
class function HasClipper<T>: Boolean; overload;
{ Retrieves registered clipper for class itself (preferred) or an ancestor }
class function GetClipper(ClassType: TClass): ICustomClipper; overload;
class function GetClipper<T>: ICustomClipper<T>; overload;
class function GetObjectClipper<T: class>: IObjectClipper<T>; overload;
class function GetRecordClipper<T: record>: IRecordClipper<T>; overload;
{ A 'clipper' acts as an intermediary between a TClipboard instance and an instance of
another type that you want to be able to assign to or from. }
class procedure RegisterClipper<T: class>(Clipper: IObjectClipper<T>); overload;
class procedure RegisterClipper<T: record>(Clipper: IRecordClipper<T>); overload;
{ Convenience overloads for creating object clippers; the 'file extensions' can be UTIs
on OS X, just make sure any actual file extensions start with a full stop (period). }
class procedure RegisterClipper<T: class, constructor>(
const Format: TClipboardFormat;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>); overload;
class procedure RegisterClipper<T: class, constructor>(
const ReadFormats, WrittenFormats: array of TClipboardFormat;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>); overload;
class procedure RegisterClipper<T: class, constructor>(
const ReadFormats, WrittenFormats: array of TClipboardFormat;
const FileExts: array of string;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>;
const OnLoadFromStream: TLoadFromClipboardStreamEvent<T>;
const OnSaveToStream: TSaveToClipboardStreamEvent<T>); overload;
class procedure RegisterClipper<T: class, constructor>(
const Format: TClipboardFormat; const FileExts: array of string;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>;
const OnLoadFromStream: TLoadFromClipboardStreamEvent<T>;
const OnSaveToStream: TSaveToClipboardStreamEvent<T>); overload;
{ ... and more specifically, object clippers for IStreamPersist implementors }
class procedure RegisterClipper<T: class, constructor, IStreamPersist>(
const ReadFormats, WrittenFormats: array of TClipboardFormat;
const FileExts: array of string;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>); overload;
class procedure RegisterClipper<T: class, constructor, IStreamPersist>(
const Format: TClipboardFormat; const FileExts: array of string;
const OnLoadFromClipboardFormat: TLoadFromClipboardFormatEvent<T>;
const OnSaveToClipboardFormat: TSaveToClipboardFormatEvent<T>); overload;
{ ..or for any TPersistent descendant with a parameterless constructor, using DFM streaming }
class function RegisterSimpleClipper<T: TPersistent, constructor>: ISimpleObjectClipper<T>; overload;
class function RegisterSimpleClipper<T: TPersistent, constructor>(
const FormatName: string): ISimpleObjectClipper<T>; overload;
{ Whether virtual files are supported at all; if False, an attempt to write a virtual file
will raise an exception. Note that while returns True on OS X, Finder (unlike Explorer on
Windows) does not support virtual files via the system clipboard, only via drag and drop. }
class function SupportsVirtualFiles: Boolean;
{ The full drag and drop interface is implemented at the framework level with a
class helper; these are the common parts }
class property ObjectBeingDragged: TObject read FObjectBeingDragged;
class property OnGetDragData[const DraggedObject: TObject]: TAssignClipboardForDragEvent read GetOnGetDragData write SetOnGetDragData;
class property OnStartDrag: TAssignClipboardForDragEvent read FOnStartDrag write FOnStartDrag;
end;
{ Helper classes }
TUserMemoryStream = class(TCustomMemoryStream)
constructor Create(AMemory: Pointer; const ALength: NativeInt);
function Write(const Buffer; Count: Longint): Longint; override;
end;
{ Renderer adapters and helpers }
ICachedFunc<T> = interface(TFunc<T>)
['{4D1F49E0-39BB-4118-B25C-FB085DED2C30}']
end;
TCachedFunc<T> = class(TInterfacedObject, TFunc<T>, ICachedFunc<T>)
strict private
FCoreRenderer: TFunc<T>;
FRendered: Boolean;
FValue: T;
strict protected
constructor CreateInternal(const CoreRenderer: TFunc<T>);
function Invoke: T;
property Rendered: Boolean read FRendered;
public
class function Create(const CoreRenderer: TFunc<T>): TFunc<T>;
end;
TRenderedObject<T: class, constructor> = class(TCachedFunc<T>)
public
class function Create(const Renderer: TProc<T>): TFunc<T>;
{$IFNDEF AUTOREFCOUNT}
destructor Destroy; override;
{$ENDIF}
end;
function BytesToStreamRenderer(const Bytes: TBytes): TProc<TStream>;
function BytesRendererToStreamRenderer(const RendererToWrap: TFunc<TBytes>): TProc<TStream>;
function StreamRendererToBytesRenderer(const RendererToWrap: TProc<TStream>): TFunc<TBytes>;
function BytesOf(const Obj: IStreamPersist): TBytes; overload;
function MatchFileExt(const FileName: string; const FileExts: TArray<string>): Boolean; overload;
function MatchFileExt(const FileNames, FileExts: TArray<string>;
var MatchedFileName: string): Boolean; overload;
function MatchFileExt(const FileNames, FileExts: TArray<string>): Boolean; overload;
function Clipboard: TClipboard; inline;
function cfComponent: TClipboardFormat; inline;
function cfComponents: TClipboardFormat; inline;
function cfFileName: TClipboardFormat; inline;
function cfGIF: TClipboardFormat; inline;
function cfJpeg: TClipboardFormat; inline;
function cfPNG: TClipboardFormat; inline;
function cfRTF: TClipboardFormat; inline;
function cfUnicodeText: TClipboardFormat; inline;
function cfUTF8Text: TClipboardFormat; inline;
function cfTIFF: TClipboardFormat; inline;
function cfURL: TClipboardFormat; inline;
function cfVirtualFileDescriptor: TClipboardFormat; inline;
implementation
uses
System.Math, System.SysConst, System.RTLConsts,
{$IF DEFINED(MSWINDOWS)}
CCR.Clipboard.Win,
{$ELSEIF DEFINED(MACOS)}
CCR.Clipboard.Apple,
// {$ELSEIF DEFINED(ANDROID)}
// CCR.Clipboard.Android;
{$IFEND}
CCR.Clipboard.Consts;
function HashBuffer(const Buffer; Size: Integer): Integer; inline;
begin
{$IF DECLARED(THashBobJenkins)}
Result := THashBobJenkins.GetHashValue(Buffer, Size);
{$ELSE}
Result := BobJenkinsHash(Buffer, Size, 0);
{$IFEND}
end;
function Clipboard: TClipboard;
begin
Result := TClipboard.GetSingleton;
end;
function cfUnicodeText: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfUnicodeText
end;
function cfUTF8Text: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfUTF8Text
end;
function cfComponent: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfComponent;
end;
function cfComponents: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfComponents;
end;
function cfFileName: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfFileName;
end;
function cfGIF: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfGIF;
end;
function cfJpeg: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfJPEG;
end;
function cfPNG: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfPNG
end;
function cfRTF: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfRTF;
end;
function cfTIFF: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfTIFF
end;
function cfURL: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfURL;
end;
function cfVirtualFileDescriptor: TClipboardFormat;
begin
Result := TClipboard.StdFormatValues.cfVirtualFileDescriptor;
end;
function ExpandAndValidateFileName(const FileName: TFileName): TFileName;
begin
Result := ExpandFileName(FileName);
if (Result = '') or not (FileExists(Result) or DirectoryExists(Result)) then
raise EClipboardException.CreateResFmt(@SInvalidFileName, [FileName]);
end;
{$REGION 'TClipboardFormat'}
class operator TClipboardFormat.Equal(const Format1, Format2: TClipboardFormat): Boolean;
begin
Result := (Format1.OrdValue = Format2.OrdValue) or
(Assigned(TClipboard.CoreClass) and TClipboard.CoreClass.SameFormat(Format1, Format2));
end;
class operator TClipboardFormat.NotEqual(const Format1, Format2: TClipboardFormat): Boolean;
begin
Result := not (Format1 = Format2);
end;
function TClipboardFormat.ConformsTo(const BaseFormat: TClipboardFormat): Boolean;
begin
Result := (Self.OrdValue = BaseFormat.OrdValue) or
((TClipboard.CoreClass <> nil) and TClipboard.CoreClass.ConformingFormat(Self, BaseFormat));
end;
function TClipboardFormat.GetName: string;
begin
if TClipboard.CoreClass = nil then
Result := ''
else
Result := TClipboard.CoreClass.GetFormatName(Self);
end;
function TClipboardFormat.GetDescription: string;
begin
if TClipboard.CoreClass = nil then
Result := ''
else
Result := TClipboard.GetFormatDescription(Self);
end;
function TClipboardFormat.ToHexString(MinDigits: Integer = 4): string;
begin
Result := IntToHex(OrdValue, MinDigits);
end;
{$ENDREGION}
{$REGION 'TObjectHandlerList<T>'}
constructor TObjectHandlerList<T>.Create;
begin
inherited Create;
FItems := TObjectList<TItem>.Create;
end;
destructor TObjectHandlerList<T>.Destroy;
begin
FItems.Free;
inherited;
end;
procedure TObjectHandlerList<T>.AddOrReplace(const ClassFor: TClass; const Handler: T);
var
Item: TItem;
GenCount, InsIndex, I: Integer;
begin
if PPointer(@Handler)^ = nil then
raise EArgumentNilException.CreateRes(@SArgumentNil);
if not FindItem(ClassFor, Item, True) then
begin
GenCount := CountGenerations(TObject, ClassFor);
InsIndex := FItems.Count;
for I := 0 to InsIndex - 1 do
if GenCount >= FItems[I].GenCount then
begin
InsIndex := I;
Break;
end;
Item := TItem.Create;
FItems.Insert(InsIndex, Item);
Item.Detail.Key := ClassFor;
end;
Item.Detail.Value := Handler;
end;
function TObjectHandlerList<T>.FindItem(const ClassFor: TClass; var Matched: TItem; Exact: Boolean): Boolean;
var
Item: TItem;
begin
for Item in FItems do
begin
if Exact then
Result := (ClassFor = Item.Detail.Key)
else
Result := ClassFor.InheritsFrom(Item.Detail.Key);
if Result then
begin
Matched := Item;
Exit;
end;
end;
Result := False;
end;
function TObjectHandlerList<T>.Find(const ClassFor: TClass; var Handler: T): Boolean;
var
Item: TItem;
begin
Result := FindItem(ClassFor, Item, False);
if Result then
Handler := Item.Detail.Value;
end;
{$ENDREGION}
{$REGION 'TVirtualFileDetails'}
constructor TVirtualFileDetails.Create(const AFileName: string; const AKnownSize: Int64 = 0);
begin
FileName := AFileName;
if AKnownSize = 0 then
AdditionalData := []
else
begin
AdditionalData := [vfSize];
FSize := AKnownSize;
end;
end;
procedure TVirtualFileDetails.SetAttr(const Value: Integer);
begin
FAttr := Value;
Include(AdditionalData, vfAttr);
end;
procedure TVirtualFileDetails.SetCreationDate(const Value: TDateTime);
begin
FCreationDate := Value;