initial commit
[rofl0r-TntUnicode.git] / Source / TntClipBrd.pas
blobcf2c16e9f6a8485149ac43c424fea9399af87f79
2 {*****************************************************************************}
3 { }
4 { Tnt Delphi Unicode Controls }
5 { http://www.tntware.com/delphicontrols/unicode/ }
6 { Version: 2.3.0 }
7 { }
8 { Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
9 { }
10 {*****************************************************************************}
12 unit TntClipBrd;
14 {$INCLUDE TntCompilers.inc}
16 interface
18 uses
19 Windows, Clipbrd;
21 type
22 {TNT-WARN TClipboard}
23 TTntClipboard = class(TClipboard{TNT-ALLOW TClipboard})
24 private
25 function GetAsWideText: WideString;
26 procedure SetAsWideText(const Value: WideString);
27 public
28 property AsWideText: WideString read GetAsWideText write SetAsWideText;
29 property AsText: WideString read GetAsWideText write SetAsWideText;
30 end;
32 {TNT-WARN Clipboard}
33 function TntClipboard: TTntClipboard;
35 implementation
37 { TTntClipboard }
39 function TTntClipboard.GetAsWideText: WideString;
40 var
41 Data: THandle;
42 begin
43 Open;
44 Data := GetClipboardData(CF_UNICODETEXT);
45 try
46 if Data <> 0 then
47 Result := PWideChar(GlobalLock(Data))
48 else
49 Result := '';
50 finally
51 if Data <> 0 then GlobalUnlock(Data);
52 Close;
53 end;
54 if (Data = 0) or (Result = '') then
55 Result := inherited AsText
56 end;
58 procedure TTntClipboard.SetAsWideText(const Value: WideString);
59 begin
60 Open;
61 try
62 inherited AsText := Value; {Ensures ANSI compatiblity across platforms.}
63 SetBuffer(CF_UNICODETEXT, PWideChar(Value)^, (Length(Value) + 1) * SizeOf(WideChar));
64 finally
65 Close;
66 end;
67 end;
69 //------------------------------------------
71 var
72 GTntClipboard: TTntClipboard;
74 function TntClipboard: TTntClipboard;
75 begin
76 if GTntClipboard = nil then
77 GTntClipboard := TTntClipboard.Create;
78 Result := GTntClipboard;
79 end;
81 initialization
83 finalization
84 GTntClipboard.Free;
86 end.