| 1 |
{%MainUnit castlecontrols.pas} |
| 2 |
{ |
| 3 |
Copyright 2017-2018 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{$ifdef read_interface} |
| 18 |
|
| 19 |
type |
| 20 |
{ Clipboard to cut / copy / paste the text. |
| 21 |
You usually use this through the single global instance @link(Clipboard). |
| 22 |
The trivial interface is mostly compatible with LCL clipboard. } |
| 23 |
TCastleClipboard = class |
| 24 |
private |
| 25 |
FContents: String; |
| 26 |
protected |
| 27 |
function GetAsText: String; virtual; |
| 28 |
procedure SetAsText(const Value: String); virtual; |
| 29 |
public |
| 30 |
property AsText: String read GetAsText write SetAsText; |
| 31 |
end; |
| 32 |
|
| 33 |
{ Single global instance of TCastleClipboard. |
| 34 |
Automatically created / destroyed by this unit. } |
| 35 |
function Clipboard: TCastleClipboard; |
| 36 |
|
| 37 |
{ Register custom TCastleClipboard implementation, |
| 38 |
that replaces the global @link(Clipboard). |
| 39 |
The instance given here becomes owned by this unit (we will free it automatically). } |
| 40 |
procedure RegisterClipboard(const AClipboard: TCastleClipboard); |
| 41 |
|
| 42 |
{$endif read_interface} |
| 43 |
|
| 44 |
{$ifdef read_implementation} |
| 45 |
|
| 46 |
var |
| 47 |
FClipboard: TCastleClipboard; |
| 48 |
|
| 49 |
function Clipboard: TCastleClipboard; |
| 50 |
begin |
| 51 |
if FClipboard = nil then |
| 52 |
FClipboard := TCastleClipboard.Create; |
| 53 |
Result := FClipboard; |
| 54 |
end; |
| 55 |
|
| 56 |
procedure RegisterClipboard(const AClipboard: TCastleClipboard); |
| 57 |
begin |
| 58 |
FreeAndNil(FClipboard); |
| 59 |
FClipboard := AClipboard; |
| 60 |
end; |
| 61 |
|
| 62 |
procedure FinalizationClipboard; |
| 63 |
begin |
| 64 |
FreeAndNil(FClipboard); |
| 65 |
end; |
| 66 |
|
| 67 |
{ TCastleClipboard ----------------------------------------------------------- } |
| 68 |
|
| 69 |
{ The default clipboard does not communicate with other processes, |
| 70 |
it's just a trivial container to copy-paste strings |
| 71 |
between Castle Game Engine edit boxes. } |
| 72 |
|
| 73 |
function TCastleClipboard.GetAsText: String; |
| 74 |
begin |
| 75 |
Result := FContents; |
| 76 |
end; |
| 77 |
|
| 78 |
procedure TCastleClipboard.SetAsText(const Value: String); |
| 79 |
begin |
| 80 |
FContents := Value; |
| 81 |
end; |
| 82 |
|
| 83 |
{$endif read_implementation} |