Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

Delphi Haven: My FMX TClipboard and TMacPreferencesIniFile implementations now compiling in XE4

$
0
0

A bit belatedly, but my FireMonkey TClipboard and TMacPreferencesIniFile/TApplePreferencesIniFile (*) implementations are now compiling with XE4 (thanks goes to Ken Schafer for prodding me in the case of the former). See my post from nearly a year ago for the details:

http://delphihaven.wordpress.com/2012/07/27/fmx-tclipboard-and-tmacpreferencesinifile/

With respect to TClipboard, I’ve also done the following:

  • Added a cfPNG TClipboardFormat identifier (this is the same as cfBitmap on OS X).
  • Fixed a bad assumption about bitmap pitches on Windows that was causing issues for some people.
  • Switched to using CF_DIBV5 internally when reading or writing bitmaps on Windows.
  • When assigning to a bitmap, cfPNG is now looked for first (this makes things works better with MS Word), and correspondingly, HasFormat(cfBitmap) now also checks for cfPNG as a special case.
  • On Windows again, when a source bitmap includes transparency, the outputted DIB has this transparency removed, however at the same time a PNG representation is added that maintains the original alpha channel.
  • For greater flexibility (e.g. when there is only PDF data on the clipboard), the Mac implementation may now use NSImage as an intermediary when assigning to a TBitmap.
  • For both Windows and OS X, added GetFormats and GetFormatName methods. Where the former returns an array of TClipboardFormat, the latter converts a TClipboardFormat to a string:
procedure TfrmClipboardDemo.btnListClick(Sender: TObject);
var
  Format: TClipboardFormat;
  S: string;
begin
  for Format in Clipboard.GetFormats do
    S := S + sLineBreak + Clipboard.GetFormatName(Format);
  if S = '' then
    S := 'Nothing is currently on the clipboard.'
  else
    S := 'The following formats are on the clipboard:' + S;
  MessageDlg(S, TMsgDlgType.mtInformation, [TMsgDlgBtn.mbOK], 0)
end;

This is the result when I copy a word on a webpage in Safari:

One word copied from Safari

As this example hints at, it’s better to use Apple’s ‘UTI’ format for custom clipboard identifiers on OS X (e.g. com.mycompany.formatname, though ultimately just something.something, or something.something.something, etc.). While things still work if you don’t, failing to do so will lead the OS to allocate a parallel ‘dynamic’ UTI for you (e.g. dyn.a1oad0fg1bber13hthat600s0nand0nand0n). As such, I’ve tweaked the demo accordingly – click the ‘Copy as Custom Clipboard Format’ button then the ‘List’ one, and you get this:

Custom format list

(*) Update (14/9/13): as the code actually worked for iOS too, I’ve renamed the unit CCR.Apple.PrefsIniFile.pas and the class TApplePreferencesIniFile. For XE5, I’ve also written a TAndroidPreferencesIniFile class – see here.



Viewing all articles
Browse latest Browse all 1725

Trending Articles