Author: hdu
Date: Thu Jan 10 09:40:17 2013
New Revision: 1431234

URL: http://svn.apache.org/viewvc?rev=1431234&view=rev
Log:
add OSX clipboard support for transparent bitmaps

Modified:
    
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/DataFlavorMapping.cxx
    
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/OSXTransferable.cxx
    
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.cxx
    
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.hxx
    openoffice/branches/alg/clibboard/main/vcl/inc/vcl/pngwrite.hxx

Modified: 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/DataFlavorMapping.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/DataFlavorMapping.cxx?rev=1431234&r1=1431233&r2=1431234&view=diff
==============================================================================
--- 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/DataFlavorMapping.cxx
 (original)
+++ 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/DataFlavorMapping.cxx
 Thu Jan 10 09:40:17 2013
@@ -125,8 +125,8 @@ namespace // private
        {
          { NSStringPboardType, "text/plain;charset=utf-16", "Unicode Text 
(UTF-16)", CPPUTYPE_OUSTRING },
          { NSRTFPboardType, "text/richtext", "Rich Text Format", 
CPPUTYPE_SEQINT8 },
-         { NSTIFFPboardType, "image/bmp", "Windows Bitmap", CPPUTYPE_SEQINT8 },
-         { NSPICTPboardType, "image/bmp", "Windows Bitmap", CPPUTYPE_SEQINT8 },
+         { NSTIFFPboardType, "image/png", "Portable Network Graphics", 
CPPUTYPE_SEQINT8 },
+         { NSPICTPboardType, "image/png", "Portable Network Graphics", 
CPPUTYPE_SEQINT8 },
          { NSHTMLPboardType, "text/html", "Plain Html", CPPUTYPE_SEQINT8 },
          { NSFilenamesPboardType, 
"application/x-openoffice-filelist;windows_formatname=\"FileList\"", 
"FileList", CPPUTYPE_SEQINT8 }, 
          { PBTYPE_SESX, FLAVOR_SESX, "Star Embed Source (XML)", 
CPPUTYPE_SEQINT8 },
@@ -371,73 +371,65 @@ Any HTMLFormatDataProvider::getOOoData()
 
 //###########################
 
-class BMPDataProvider : public DataProviderBaseImpl
+class PNGDataProvider : public DataProviderBaseImpl
 {
-    NSBitmapImageFileType meImageType;
+       NSBitmapImageFileType meImageType;
 public:
-  BMPDataProvider(const Any& data, NSBitmapImageFileType eImageType );
+       PNGDataProvider( const Any&, NSBitmapImageFileType);
 
-  BMPDataProvider(NSData* data, NSBitmapImageFileType eImageType);
+       PNGDataProvider( NSData*, NSBitmapImageFileType);
 
-  virtual NSData* getSystemData();
+       virtual NSData* getSystemData();
 
-  virtual Any getOOoData();
+       virtual Any getOOoData();
 };
 
-BMPDataProvider::BMPDataProvider(const Any& data, NSBitmapImageFileType 
eImageType) :
+PNGDataProvider::PNGDataProvider( const Any& data, NSBitmapImageFileType 
eImageType) :
   DataProviderBaseImpl(data),
   meImageType( eImageType )
 {
 }
 
-BMPDataProvider::BMPDataProvider(NSData* data, NSBitmapImageFileType 
eImageType) :
+PNGDataProvider::PNGDataProvider( NSData* data, NSBitmapImageFileType 
eImageType) :
   DataProviderBaseImpl(data),
   meImageType( eImageType )
 {
 }
 
-NSData* BMPDataProvider::getSystemData()
+NSData* PNGDataProvider::getSystemData()
 {
-  Sequence<sal_Int8> bmpData;
-  mData >>= bmpData;
+       Sequence<sal_Int8> pngData;
+       mData >>= pngData;
 
-  Sequence<sal_Int8> pictData;
-  NSData* sysData = NULL;
+       Sequence<sal_Int8> imgData;
+       NSData* sysData = NULL;
+       if( PNGToImage( pngData, imgData, meImageType))
+               sysData = [NSData dataWithBytes: imgData.getArray() length: 
imgData.getLength()];
 
-  if (BMPToImage(bmpData, pictData, meImageType))
-       {
-         sysData = [NSData dataWithBytes: pictData.getArray() length: 
pictData.getLength()];
-       }
-
-  return sysData;
+       return sysData;
 }
 
-/* At the moment the OOo 'PCT' filter is not good enough to be used
-   and there is no flavor defined for exchanging 'PCT' with OOo so
-   we will at the moment convert 'PCT' to a Windows BMP and provide
-   this to OOo 
+/* The AOO 'PCT' filter is not yet good enough to be used
+   and there is no flavor defined for exchanging 'PCT' with AOO
+   so we convert 'PCT' to a PNG and provide this to AOO 
 */
-Any BMPDataProvider::getOOoData()
+Any PNGDataProvider::getOOoData()
 {
-  Any oOOData;
+       Any oOOData;
 
-  if (mSystemData)
+       if( mSystemData)
        {
-         unsigned int flavorDataLength = [mSystemData length];
-         Sequence<sal_Int8> pictData(flavorDataLength);
-
-         memcpy(pictData.getArray(), [mSystemData bytes], flavorDataLength);
+               const unsigned int flavorDataLength = [mSystemData length];
+               Sequence<sal_Int8> imgData( flavorDataLength);
+               memcpy( imgData.getArray(), [mSystemData bytes], 
flavorDataLength);
 
-         Sequence<sal_Int8> bmpData;
-         
-         if (ImageToBMP(pictData, bmpData, meImageType))
-               {
-                 oOOData = makeAny(bmpData);
-               }
+               Sequence<sal_Int8> pngData;
+               if( ImageToPNG( imgData, pngData, meImageType))
+                       oOOData = makeAny( pngData);
        }
-  else
+       else
        {
-         oOOData = mData;
+               oOOData = mData;
        }
   
   return oOOData;
@@ -617,11 +609,11 @@ DataProviderPtr_t DataFlavorMapper::getD
                  */
                  if ([systemFlavor caseInsensitiveCompare: NSPICTPboardType] 
== NSOrderedSame)
                        {
-                         dp = DataProviderPtr_t(new BMPDataProvider(data, 
PICTImageFileType));
+                         dp = DataProviderPtr_t( new PNGDataProvider( data, 
PICTImageFileType));
                        }
                  else if ([systemFlavor caseInsensitiveCompare: 
NSTIFFPboardType] == NSOrderedSame)
                        {
-                         dp = DataProviderPtr_t(new BMPDataProvider(data, 
NSTIFFFileType));
+                         dp = DataProviderPtr_t( new PNGDataProvider( data, 
NSTIFFFileType));
                        }
                  else if ([systemFlavor caseInsensitiveCompare: 
NSFilenamesPboardType] == NSOrderedSame)
                        {
@@ -666,11 +658,11 @@ DataProviderPtr_t DataFlavorMapper::getD
        }
   else if ([systemFlavor caseInsensitiveCompare: NSPICTPboardType] == 
NSOrderedSame)
        {
-         dp = DataProviderPtr_t(new BMPDataProvider(systemData, 
PICTImageFileType));
+         dp = DataProviderPtr_t( new PNGDataProvider(systemData, 
PICTImageFileType));
        }
   else if ([systemFlavor caseInsensitiveCompare: NSTIFFPboardType] == 
NSOrderedSame)
        {
-         dp = DataProviderPtr_t(new BMPDataProvider(systemData, 
NSTIFFFileType));
+         dp = DataProviderPtr_t( new PNGDataProvider(systemData, 
NSTIFFFileType));
        }
   else if ([systemFlavor caseInsensitiveCompare: NSFilenamesPboardType] == 
NSOrderedSame)
        {

Modified: 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/OSXTransferable.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/OSXTransferable.cxx?rev=1431234&r1=1431233&r2=1431234&view=diff
==============================================================================
--- 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/OSXTransferable.cxx
 (original)
+++ 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/OSXTransferable.cxx
 Thu Jan 10 09:40:17 2013
@@ -85,7 +85,7 @@ Any SAL_CALL OSXTransferable::getTransfe
        }
 
   NSString* sysFormat = 
-      (aFlavor.MimeType.compareToAscii( "image/bmp", 9 ) == 0)
+      (aFlavor.MimeType.compareToAscii( "image/png", 9 ) == 0)
       ? mDataFlavorMapper->openOfficeImageToSystemFlavor( mPasteboard )
       : mDataFlavorMapper->openOfficeToSystemFlavor(aFlavor);
   DataProviderPtr_t dp;

Modified: 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.cxx?rev=1431234&r1=1431233&r2=1431234&view=diff
==============================================================================
--- 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.cxx 
(original)
+++ 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.cxx 
Thu Jan 10 09:40:17 2013
@@ -36,159 +36,130 @@
 
 #include "PictToBmpFlt.hxx"
 
-bool PICTtoBMP(com::sun::star::uno::Sequence<sal_Int8>& aPict, 
-                          com::sun::star::uno::Sequence<sal_Int8>& aBmp)
+bool PICTtoPNG( com::sun::star::uno::Sequence<sal_Int8>& rPictData,
+                       com::sun::star::uno::Sequence<sal_Int8>& rPngData)
 {
-    
-  bool result = false;
-
-  ComponentInstance bmpExporter;
-  if (OpenADefaultComponent(GraphicsExporterComponentType,
-                                                       kQTFileTypeBMP,
-                                                       &bmpExporter) != noErr)
-       {
-         return result;
-       }
-
-  Handle hPict;
-  if (PtrToHand(aPict.getArray(), &hPict, aPict.getLength()) != noErr)
-       {
-         return result;
-       }
-
-  Handle hBmp;
-  if ((GraphicsExportSetInputPicture(bmpExporter, (PicHandle)hPict) != noErr) 
|| 
-         ((hBmp = NewHandleClear(0)) == NULL))
-       {
-         CloseComponent(bmpExporter);
-         DisposeHandle(hPict);
-         return result;
-       }
-
-  if ((GraphicsExportSetOutputHandle(bmpExporter, hBmp) == noErr) &&
-         (GraphicsExportDoExport(bmpExporter, NULL) == noErr))
-       {
-         size_t sz = GetHandleSize(hBmp);
-         aBmp.realloc(sz);
-
-         HLock(hBmp);
-         rtl_copyMemory(aBmp.getArray(), ((sal_Int8*)*hBmp), sz);
-         HUnlock(hBmp);
-
-         result = true;
+       ComponentInstance pngExporter = NULL;
+       if( OpenADefaultComponent( GraphicsExporterComponentType, 
kQTFileTypePNG, &pngExporter) != noErr)
+               return false;
+
+       Handle hPict = NULL;
+       if( PtrToHand( rPictData.getArray(), &hPict, rPictData.getLength()) != 
noErr)
+               hPict = NULL;
+
+       Handle hPng = NULL;
+       if( hPict && GraphicsExportSetInputPicture( pngExporter, 
(PicHandle)hPict) == noErr)
+               hPng = NewHandleClear(0);
+
+       size_t nPngSize = 0;
+       if( hPng
+       && (GraphicsExportSetOutputHandle( pngExporter, hPng) == noErr)
+       && (GraphicsExportDoExport( pngExporter, NULL) == noErr))
+       {
+               nPngSize = GetHandleSize( hPng);
+               rPngData.realloc( nPngSize);
+
+               HLock( hPng);
+               rtl_copyMemory( rPngData.getArray(), ((sal_Int8*)*hPng), 
nPngSize);
+               HUnlock( hPng);
        } 
 
-  DisposeHandle(hPict);
-  DisposeHandle(hBmp);
-  CloseComponent(bmpExporter);
+       if( hPict)
+               DisposeHandle( hPict);
+       if( hPng)
+               DisposeHandle( hPng);
+       if( pngExporter)
+               CloseComponent( pngExporter);
 
-  return result;
+       return (nPngSize > 0);
 }
 
-bool BMPtoPICT(com::sun::star::uno::Sequence<sal_Int8>& aBmp, 
-                          com::sun::star::uno::Sequence<sal_Int8>& aPict)
-{
-  bool result = false;
 
-  Handle hBmp;
-  ComponentInstance pictExporter;
-  if ((PtrToHand(aBmp.getArray(), &hBmp, aBmp.getLength()) != noErr)) 
-       {
-         return result;
-       }
-
-  if (OpenADefaultComponent(GraphicsImporterComponentType,
-                                                       kQTFileTypeBMP,
-                                                       &pictExporter) != noErr)
-       {
-         DisposeHandle(hBmp);
-         return result;
-       }
+bool PNGtoPICT( com::sun::star::uno::Sequence<sal_Int8>& rPngData,
+                          com::sun::star::uno::Sequence<sal_Int8>& rPictData)
+{
+       ComponentInstance pictExporter;
+       if( OpenADefaultComponent( GraphicsImporterComponentType, 
kQTFileTypePNG, &pictExporter) != noErr)
+               return false;
+
+       Handle hPng = NULL;
+       if( PtrToHand( rPngData.getArray(), &hPng, rPngData.getLength()) != 
noErr)
+               hPng = NULL;
   
-  if (GraphicsImportSetDataHandle(pictExporter, hBmp) != noErr)
-       {
-         DisposeHandle(hBmp);
-         CloseComponent(pictExporter);
-         return result;
-       }
-
-  PicHandle hPict;
-  if (GraphicsImportGetAsPicture(pictExporter, &hPict) == noErr)
-       {
-         size_t sz = GetHandleSize((Handle)hPict);
-         aPict.realloc(sz);
-
-         HLock((Handle)hPict);
-         rtl_copyMemory(aPict.getArray(), ((sal_Int8*)*hPict), sz);
-         HUnlock((Handle)hPict);
-
-         // Release the data associated with the picture
-         // Note: This function is deprecated in Mac OS X 
-         // 10.4.
-         KillPicture(hPict); 
-
-         result = true;
+       size_t nPictSize = 0;
+       PicHandle hPict = NULL;
+       if( hPng
+       && (GraphicsImportSetDataHandle( pictExporter, hPng) == noErr)
+       && (GraphicsImportGetAsPicture( pictExporter, &hPict) == noErr))
+       {
+               nPictSize = GetHandleSize( (Handle)hPict);
+               rPictData.realloc( nPictSize);
+
+               HLock( (Handle)hPict);
+               rtl_copyMemory( rPictData.getArray(), ((sal_Int8*)*hPict), 
nPictSize);
+               HUnlock( (Handle)hPict);
+
+               // Release the data associated with the picture
+               // Note: This function is deprecated in Mac OSX 10.4
+               KillPicture( hPict);
        }
   
-  DisposeHandle(hBmp);
-  CloseComponent(pictExporter);
+       if( hPng)
+               DisposeHandle( hPng);
+       if( pictExporter)
+               CloseComponent( pictExporter);
   
-  return result;
+       return (nPictSize > 512);
 }
 
-bool ImageToBMP( com::sun::star::uno::Sequence<sal_Int8>& aPict, 
-                            com::sun::star::uno::Sequence<sal_Int8>& aBmp,
+bool ImageToPNG( com::sun::star::uno::Sequence<sal_Int8>& rImgData, 
+                            com::sun::star::uno::Sequence<sal_Int8>& rPngData,
                             NSBitmapImageFileType eInFormat)
 {
-    if( eInFormat == PICTImageFileType )
-        return PICTtoBMP( aPict, aBmp );
-    
-    bool bResult = false;
-    
-    NSData* pData = [NSData dataWithBytesNoCopy: (void*)aPict.getConstArray() 
length: aPict.getLength() freeWhenDone: 0];
-    if( pData )
-    {
-        NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData: pData];
-        if( pRep )
-        {
-            NSData* pOut = [pRep representationUsingType: NSBMPFileType 
properties: nil];
-            if( pOut )
-            {
-                aBmp.realloc( [pOut length] );
-                [pOut getBytes: aBmp.getArray() length: aBmp.getLength()];
-                bResult = (aBmp.getLength() != 0);
-            }
-        }
-    }
-    
-    return bResult;
+       if( eInFormat == PICTImageFileType)
+               return PICTtoPNG( rImgData, rPngData);
+
+       NSData* pData = [NSData dataWithBytesNoCopy: 
(void*)rImgData.getConstArray() length: rImgData.getLength() freeWhenDone: 0];
+       if( !pData)
+               return false;
+
+       NSBitmapImageRep* pRep =[NSBitmapImageRep imageRepWithData: pData];
+        if( !pRep)
+               return false;
+
+       NSData* pOut = [pRep representationUsingType: NSPNGFileType properties: 
nil];
+       if( !pOut)
+               return false;
+
+       const size_t nPngSize = [pOut length];
+       rPngData.realloc( nPngSize);
+       [pOut getBytes: rPngData.getArray() length: nPngSize];
+       return (nPngSize > 0);
 }
 
-bool BMPToImage( com::sun::star::uno::Sequence<sal_Int8>& aBmp, 
-                            com::sun::star::uno::Sequence<sal_Int8>& aPict,
+bool PNGToImage( com::sun::star::uno::Sequence<sal_Int8>& rPngData,
+                            com::sun::star::uno::Sequence<sal_Int8>& rImgData,
                             NSBitmapImageFileType eOutFormat
                            )
 {
-    if( eOutFormat == PICTImageFileType )
-        return BMPtoPICT( aBmp, aPict );
-    
-    bool bResult = false;
+       if( eOutFormat == PICTImageFileType)
+               return PNGtoPICT( rPngData, rImgData);
     
-    NSData* pData = [NSData dataWithBytesNoCopy: 
const_cast<sal_Int8*>(aBmp.getConstArray()) length: aBmp.getLength() 
freeWhenDone: 0];
-    if( pData )
-    {
+       NSData* pData = [NSData dataWithBytesNoCopy: 
const_cast<sal_Int8*>(rPngData.getConstArray()) length: rPngData.getLength() 
freeWhenDone: 0];
+       if( !pData)
+               return false;
+
         NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData: pData];
-        if( pRep )
-        {
-            NSData* pOut = [pRep representationUsingType: eOutFormat 
properties: nil];
-            if( pOut )
-            {
-                aPict.realloc( [pOut length] );
-                [pOut getBytes: aPict.getArray() length: aPict.getLength()];
-                bResult = (aPict.getLength() != 0);
-            }
-        }
-    }
-    
-    return bResult;
+        if( !pRep)
+               return false;
+
+       NSData* pOut = [pRep representationUsingType: eOutFormat properties: 
nil];
+       if( !pOut)
+               return false;
+
+       const size_t nImgSize = [pOut length];
+       rImgData.realloc( nImgSize);
+       [pOut getBytes: rImgData.getArray() length: nImgSize];
+       return (nImgSize > 0);
 }
+

Modified: 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.hxx?rev=1431234&r1=1431233&r2=1431234&view=diff
==============================================================================
--- 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.hxx 
(original)
+++ 
openoffice/branches/alg/clibboard/main/vcl/aqua/source/dtrans/PictToBmpFlt.hxx 
Thu Jan 10 09:40:17 2013
@@ -28,31 +28,31 @@
 #include <Cocoa/Cocoa.h>
 #include <postmac.h>
 
-/* Transform PICT into the a Window BMP.
+/** Transform an image from PICT to PNG format
 
    Returns true if the conversion was successful false 
    otherwise.
  */
-bool PICTtoBMP(com::sun::star::uno::Sequence<sal_Int8>& aPict, 
-                          com::sun::star::uno::Sequence<sal_Int8>& aBmp);
+bool PICTtoPNG(com::sun::star::uno::Sequence<sal_Int8>& rPictData, 
+                          com::sun::star::uno::Sequence<sal_Int8>& rPngData);
 
-/* Transform a Windows BMP to a PICT.
+/** Transform an image from PNG to a PICT format
 
    Returns true if the conversion was successful false
    otherwise.
  */
-bool BMPtoPICT(com::sun::star::uno::Sequence<sal_Int8>& aBmp, 
-                          com::sun::star::uno::Sequence<sal_Int8>& aPict);
+bool PNGtoPICT(com::sun::star::uno::Sequence<sal_Int8>& rPngData,
+                          com::sun::star::uno::Sequence<sal_Int8>& rPictData);
 
 #define PICTImageFileType ((NSBitmapImageFileType)~0)
 
-bool ImageToBMP( com::sun::star::uno::Sequence<sal_Int8>& aPict, 
-                            com::sun::star::uno::Sequence<sal_Int8>& aBmp,
+bool ImageToPNG( com::sun::star::uno::Sequence<sal_Int8>& rImgData,
+                            com::sun::star::uno::Sequence<sal_Int8>& rPngData,
                             NSBitmapImageFileType eInFormat);
 
-bool BMPToImage( com::sun::star::uno::Sequence<sal_Int8>& aBmp, 
-                            com::sun::star::uno::Sequence<sal_Int8>& aPict,
-                            NSBitmapImageFileType eOutFormat
-                           );
+bool PNGToImage( com::sun::star::uno::Sequence<sal_Int8>& rPngData,
+                            com::sun::star::uno::Sequence<sal_Int8>& rImgData,
+                            NSBitmapImageFileType eOutFormat);
 
 #endif
+

Modified: openoffice/branches/alg/clibboard/main/vcl/inc/vcl/pngwrite.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/alg/clibboard/main/vcl/inc/vcl/pngwrite.hxx?rev=1431234&r1=1431233&r2=1431234&view=diff
==============================================================================
--- openoffice/branches/alg/clibboard/main/vcl/inc/vcl/pngwrite.hxx (original)
+++ openoffice/branches/alg/clibboard/main/vcl/inc/vcl/pngwrite.hxx Thu Jan 10 
09:40:17 2013
@@ -44,7 +44,7 @@ namespace vcl
 
        public:
 
-               PNGWriter( const BitmapEx& BmpEx,
+               explicit PNGWriter( const BitmapEx&,
                        const ::com::sun::star::uno::Sequence< 
::com::sun::star::beans::PropertyValue >* pFilterData = NULL );
                ~PNGWriter();
 


Reply via email to