vcl/win/dtrans/DOTransferable.cxx |   30 ++++++++++++------------------
 vcl/win/dtrans/DOTransferable.hxx |    4 +---
 2 files changed, 13 insertions(+), 21 deletions(-)

New commits:
commit e3ae2147984647973b4a64a88adba8724646ea50
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Nov 9 13:34:25 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Nov 9 12:03:16 2025 +0100

    Simplify CDOTransferable::getClipboardData a bit
    
    Use a ScopeGuard to call ReleaseStgMedium.
    Drop unneeded explicit call to DeleteObject in case of CF_BITMAP:
    this is what ReleaseStgMedium does automatically. It was added in
    commit e9391ae8eb3d0a4edf977f0159ee7e07a0a95859 (vcl113: #i111834#
    support pasting HBITMAP, 2010-07-07).
    
    Change-Id: I241c0a7d77c98c30c727548189c476d0cdefded9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193652
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/win/dtrans/DOTransferable.cxx 
b/vcl/win/dtrans/DOTransferable.cxx
index 5f6b2351c1a7..c7c75d9e7e39 100644
--- a/vcl/win/dtrans/DOTransferable.cxx
+++ b/vcl/win/dtrans/DOTransferable.cxx
@@ -17,6 +17,9 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <comphelper/scopeguard.hxx>
 #include <sal/types.h>
 #include <rtl/process.h>
 #include <osl/diagnose.h>
@@ -495,6 +498,7 @@ Sequence<sal_Int8> 
CDOTransferable::getClipboardData(CFormatEtc& aFormatEtc)
             throw RuntimeException( );
     }
 
+    comphelper::ScopeGuard stgMediumReleaser([&stgmedium] { 
ReleaseStgMedium(&stgmedium); });
     Sequence<sal_Int8> byteStream;
 
     try
@@ -504,14 +508,7 @@ Sequence<sal_Int8> 
CDOTransferable::getClipboardData(CFormatEtc& aFormatEtc)
         else if (CF_HDROP == aLocalFormatEtc.getClipformat())
             byteStream = CF_HDROPToFileList(stgmedium.hGlobal);
         else if (CF_BITMAP == aLocalFormatEtc.getClipformat())
-        {
             byteStream = WinBITMAPToOOBMP(stgmedium.hBitmap);
-            if (aLocalFormatEtc.getTymed() == TYMED_GDI &&
-                ! stgmedium.pUnkForRelease )
-            {
-                DeleteObject(stgmedium.hBitmap);
-            }
-        }
         else
         {
             clipDataToByteStream(aLocalFormatEtc.getClipformat(), stgmedium, 
byteStream);
@@ -528,12 +525,9 @@ Sequence<sal_Int8> 
CDOTransferable::getClipboardData(CFormatEtc& aFormatEtc)
                 byteStream = WinMFPictToOOMFPict(byteStream);
             }
         }
-
-        ReleaseStgMedium( &stgmedium );
     }
     catch( CStgTransferHelper::CStgTransferException& )
     {
-        ReleaseStgMedium( &stgmedium );
         throw IOException( );
     }
 
commit 272cbc9d62a231e5814c4ca8b7b5c81e3f4a5b15
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Nov 9 13:24:21 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Nov 9 12:03:02 2025 +0100

    Drop ByteSequence_t typedef; use Sequence<sal_Int8> directly
    
    Change-Id: I4565a82f3a7d5d01f2e3370a59dd37caf94fd05f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193651
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/vcl/win/dtrans/DOTransferable.cxx 
b/vcl/win/dtrans/DOTransferable.cxx
index 3004f9fe16d7..5f6b2351c1a7 100644
--- a/vcl/win/dtrans/DOTransferable.cxx
+++ b/vcl/win/dtrans/DOTransferable.cxx
@@ -57,7 +57,7 @@ namespace
                  ( aFlavor.DataType == CPPUTYPE_OUSTRING ) ) );
     }
 
-void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, 
CDOTransferable::ByteSequence_t& aByteSequence )
+void clipDataToByteStream(CLIPFORMAT cf, STGMEDIUM stgmedium, 
Sequence<sal_Int8>& aByteSequence)
 {
     CStgTransferHelper memTransferHelper;
     LPSTREAM pStream = nullptr;
@@ -125,7 +125,7 @@ void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM 
stgmedium, CDOTransferable::
     memTransferHelper.read( aByteSequence.getArray( ), nMemSize );
 }
 
-OUString byteStreamToOUString( CDOTransferable::ByteSequence_t& aByteStream )
+OUString byteStreamToOUString(Sequence<sal_Int8>& aByteStream)
 {
     sal_Int32 nWChars;
     sal_Int32 nMemSize = aByteStream.getLength( );
@@ -142,7 +142,7 @@ OUString byteStreamToOUString( 
CDOTransferable::ByteSequence_t& aByteStream )
     return OUString( reinterpret_cast< sal_Unicode* >( aByteStream.getArray( ) 
), nWChars );
 }
 
-Any byteStreamToAny( CDOTransferable::ByteSequence_t& aByteStream, const Type& 
aRequestedDataType )
+Any byteStreamToAny(Sequence<sal_Int8>& aByteStream, const Type& 
aRequestedDataType)
 {
     Any aAny;
 
@@ -245,7 +245,7 @@ Any SAL_CALL CDOTransferable::getTransferData( const 
DataFlavor& aFlavor )
 
     //  get the data from clipboard in a byte stream
 
-    ByteSequence_t clipDataStream;
+    Sequence<sal_Int8> clipDataStream;
 
     try
     {
@@ -386,7 +386,7 @@ LCID CDOTransferable::getLocaleFromClipboard( )
     try
     {
         CFormatEtc fetc = CDataFormatTranslator::getFormatEtcForClipformat( 
CF_LOCALE );
-        ByteSequence_t aLCIDSeq = getClipboardData( fetc );
+        Sequence<sal_Int8> aLCIDSeq = getClipboardData(fetc);
         lcid = *reinterpret_cast<LCID*>( aLCIDSeq.getArray( ) );
 
         // because of a Win95/98 Bug; there the high word
@@ -464,7 +464,7 @@ HRESULT getClipboardData_impl(const IDataObjectPtr& 
pDataObject, CFormatEtc& rFo
 }
 }
 
-CDOTransferable::ByteSequence_t CDOTransferable::getClipboardData( CFormatEtc& 
aFormatEtc )
+Sequence<sal_Int8> CDOTransferable::getClipboardData(CFormatEtc& aFormatEtc)
 {
     CFormatEtc aLocalFormatEtc(aFormatEtc);
     STGMEDIUM stgmedium;
@@ -495,7 +495,7 @@ CDOTransferable::ByteSequence_t 
CDOTransferable::getClipboardData( CFormatEtc& a
             throw RuntimeException( );
     }
 
-    ByteSequence_t byteStream;
+    Sequence<sal_Int8> byteStream;
 
     try
     {
@@ -542,7 +542,7 @@ CDOTransferable::ByteSequence_t 
CDOTransferable::getClipboardData( CFormatEtc& a
 
 OUString CDOTransferable::synthesizeUnicodeText( )
 {
-    ByteSequence_t aTextSequence;
+    Sequence<sal_Int8> aTextSequence;
     CFormatEtc     fetc;
     LCID           lcid = getLocaleFromClipboard( );
     sal_uInt32     cpForTxtCnvt = 0;
diff --git a/vcl/win/dtrans/DOTransferable.hxx 
b/vcl/win/dtrans/DOTransferable.hxx
index 1824c7b44844..cab9e5095dd6 100644
--- a/vcl/win/dtrans/DOTransferable.hxx
+++ b/vcl/win/dtrans/DOTransferable.hxx
@@ -41,8 +41,6 @@ class CDOTransferable : public ::cppu::WeakImplHelper<
                             css::datatransfer::XTransferable>
 {
 public:
-    typedef css::uno::Sequence< sal_Int8 > ByteSequence_t;
-
     // XTransferable
 
     virtual css::uno::Any SAL_CALL getTransferData( const 
css::datatransfer::DataFlavor& aFlavor ) override;
@@ -70,7 +68,7 @@ private:
     css::datatransfer::DataFlavor formatEtcToDataFlavor(sal_uInt32 cfFormat);
 
     void tryToGetIDataObjectIfAbsent();
-    ByteSequence_t getClipboardData( CFormatEtc& aFormatEtc );
+    css::uno::Sequence<sal_Int8> getClipboardData(CFormatEtc& aFormatEtc);
     OUString synthesizeUnicodeText( );
 
     LCID getLocaleFromClipboard( );

Reply via email to