diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-10-08 09:02:25 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-11-07 22:01:02 +0100 |
commit | 6311f7ffce8f64b0773d2ad3ea7be3be683924c0 (patch) | |
tree | 67a59c93ca968838e86b63da214c75e98f8d0626 /svtools/source/misc | |
parent | 128bec2c4bf57c2d82ce61319cbd1778bcabfeb1 (diff) |
move SvTreeListBox to vcl
Change-Id: I04a146d3d8a428ac1678827dc883525c40240a44
Reviewed-on: https://gerrit.libreoffice.org/62787
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svtools/source/misc')
-rw-r--r-- | svtools/source/misc/cliplistener.cxx | 2 | ||||
-rw-r--r-- | svtools/source/misc/imap.cxx | 991 | ||||
-rw-r--r-- | svtools/source/misc/imap2.cxx | 532 | ||||
-rw-r--r-- | svtools/source/misc/imap3.cxx | 87 | ||||
-rw-r--r-- | svtools/source/misc/openfiledroptargetlistener.cxx | 2 | ||||
-rw-r--r-- | svtools/source/misc/svtaccessiblefactory.cxx | 9 | ||||
-rw-r--r-- | svtools/source/misc/transfer.cxx | 2177 | ||||
-rw-r--r-- | svtools/source/misc/transfer2.cxx | 472 |
8 files changed, 2 insertions, 4270 deletions
diff --git a/svtools/source/misc/cliplistener.cxx b/svtools/source/misc/cliplistener.cxx index c2d21d4a47c1..992d9efb9370 100644 --- a/svtools/source/misc/cliplistener.cxx +++ b/svtools/source/misc/cliplistener.cxx @@ -24,7 +24,7 @@ #include <vcl/window.hxx> #include <svtools/cliplistener.hxx> -#include <svtools/transfer.hxx> +#include <vcl/transfer.hxx> using namespace ::com::sun::star; diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx deleted file mode 100644 index 0a2739f7eb4c..000000000000 --- a/svtools/source/misc/imap.cxx +++ /dev/null @@ -1,991 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <tools/urlobj.hxx> -#include <tools/fract.hxx> -#include <vcl/svapp.hxx> -#include <vcl/mapmod.hxx> -#include <vcl/window.hxx> -#include <o3tl/numeric.hxx> -#include <svl/urihelper.hxx> -#include <svtools/imap.hxx> -#include <svtools/imapobj.hxx> -#include <svtools/imapcirc.hxx> -#include <svtools/imaprect.hxx> -#include <svtools/imappoly.hxx> - -#include <string.h> -#include <math.h> -#include <memory> -#include <sal/log.hxx> - - -#define SCALEPOINT(aPT,aFracX,aFracY) (aPT).setX(long((aPT).X()*aFracX)); \ - (aPT).setY(long((aPT).Y()*aFracY)); - - -/******************************************************************************/ - -sal_uInt16 IMapObject::nActualTextEncoding = sal_uInt16(RTL_TEXTENCODING_DONTKNOW); - -/******************************************************************************/ - - -IMapObject::IMapObject() - : bActive( false ) - , nReadVersion( 0 ) -{ -} - -IMapObject::IMapObject( const OUString& rURL, const OUString& rAltText, const OUString& rDesc, - const OUString& rTarget, const OUString& rName, bool bURLActive ) -: aURL( rURL ) -, aAltText( rAltText ) -, aDesc( rDesc ) -, aTarget( rTarget ) -, aName( rName ) -, bActive( bURLActive ) -, nReadVersion( 0 ) -{ -} - - -void IMapObject::Write( SvStream& rOStm ) const -{ - const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); - - rOStm.WriteUInt16( GetType() ); - rOStm.WriteUInt16( IMAP_OBJ_VERSION ); - rOStm.WriteUInt16( eEncoding ); - - const OString aRelURL = OUStringToOString( - URIHelper::simpleNormalizedMakeRelative("", aURL), eEncoding); - write_uInt16_lenPrefixed_uInt8s_FromOString(rOStm, aRelURL); - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aAltText, eEncoding); - rOStm.WriteBool( bActive ); - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aTarget, eEncoding); - - std::unique_ptr<IMapCompat> pCompat(new IMapCompat( rOStm, StreamMode::WRITE )); - - WriteIMapObject( rOStm ); - aEventList.Write( rOStm ); // V4 - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aName, eEncoding); // V5 -} - - -/****************************************************************************** -|* -|* Binary import -|* -\******************************************************************************/ - -void IMapObject::Read( SvStream& rIStm ) -{ - rtl_TextEncoding nTextEncoding; - - // read on type and version - rIStm.SeekRel( 2 ); - rIStm.ReadUInt16( nReadVersion ); - rIStm.ReadUInt16( nTextEncoding ); - aURL = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); - aAltText = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); - rIStm.ReadCharAsBool( bActive ); - aTarget = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); - - // make URL absolute - aURL = URIHelper::SmartRel2Abs( INetURLObject(""), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism::Unambiguous ); - std::unique_ptr<IMapCompat> pCompat(new IMapCompat( rIStm, StreamMode::READ )); - - ReadIMapObject( rIStm ); - - // from version 4 onwards we read a eventlist - if ( nReadVersion >= 0x0004 ) - { - aEventList.Read(rIStm); - - // from version 5 onwards an objectname could be available - if ( nReadVersion >= 0x0005 ) - aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); - } -} - -bool IMapObject::IsEqual( const IMapObject& rEqObj ) -{ - return ( ( aURL == rEqObj.aURL ) && - ( aAltText == rEqObj.aAltText ) && - ( aDesc == rEqObj.aDesc ) && - ( aTarget == rEqObj.aTarget ) && - ( aName == rEqObj.aName ) && - ( bActive == rEqObj.bActive ) ); -} - -IMapRectangleObject::IMapRectangleObject( const tools::Rectangle& rRect, - const OUString& rURL, - const OUString& rAltText, - const OUString& rDesc, - const OUString& rTarget, - const OUString& rName, - bool bURLActive, - bool bPixelCoords ) : - IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive ) -{ - ImpConstruct( rRect, bPixelCoords ); -} - -void IMapRectangleObject::ImpConstruct( const tools::Rectangle& rRect, bool bPixel ) -{ - if ( bPixel ) - aRect = Application::GetDefaultDevice()->PixelToLogic( rRect, MapMode( MapUnit::Map100thMM ) ); - else - aRect = rRect; -} - - -/****************************************************************************** -|* -|* Binary export -|* -\******************************************************************************/ - -void IMapRectangleObject::WriteIMapObject( SvStream& rOStm ) const -{ - WriteRectangle( rOStm, aRect ); -} - - -/****************************************************************************** -|* -|* Binary import -|* -\******************************************************************************/ - -void IMapRectangleObject::ReadIMapObject( SvStream& rIStm ) -{ - ReadRectangle( rIStm, aRect ); -} - - -/****************************************************************************** -|* -|* return type -|* -\******************************************************************************/ - -sal_uInt16 IMapRectangleObject::GetType() const -{ - return IMAP_OBJ_RECTANGLE; -} - - -/****************************************************************************** -|* -|* Hit test -|* -\******************************************************************************/ - -bool IMapRectangleObject::IsHit( const Point& rPoint ) const -{ - return aRect.IsInside( rPoint ); -} - -tools::Rectangle IMapRectangleObject::GetRectangle( bool bPixelCoords ) const -{ - tools::Rectangle aNewRect; - - if ( bPixelCoords ) - aNewRect = Application::GetDefaultDevice()->LogicToPixel( aRect, MapMode( MapUnit::Map100thMM ) ); - else - aNewRect = aRect; - - return aNewRect; -} - -void IMapRectangleObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) -{ - Point aTL( aRect.TopLeft() ); - Point aBR( aRect.BottomRight() ); - - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aTL, rFracX, rFracY ); - SCALEPOINT( aBR, rFracX, rFracY ); - } - - aRect = tools::Rectangle( aTL, aBR ); -} - -bool IMapRectangleObject::IsEqual( const IMapRectangleObject& rEqObj ) -{ - return ( IMapObject::IsEqual( rEqObj ) && ( aRect == rEqObj.aRect ) ); -} - -IMapCircleObject::IMapCircleObject( const Point& rCenter, sal_uLong nCircleRadius, - const OUString& rURL, - const OUString& rAltText, - const OUString& rDesc, - const OUString& rTarget, - const OUString& rName, - bool bURLActive, - bool bPixelCoords ) : - IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive ) -{ - ImpConstruct( rCenter, nCircleRadius, bPixelCoords ); -} - -void IMapCircleObject::ImpConstruct( const Point& rCenter, sal_uLong nRad, bool bPixel ) -{ - if ( bPixel ) - { - MapMode aMap100( MapUnit::Map100thMM ); - - aCenter = Application::GetDefaultDevice()->PixelToLogic( rCenter, aMap100 ); - nRadius = Application::GetDefaultDevice()->PixelToLogic( Size( nRad, 0 ), aMap100 ).Width(); - } - else - { - aCenter = rCenter; - nRadius = nRad; - } -} - - -/****************************************************************************** -|* -|* Binary export -|* -\******************************************************************************/ - -void IMapCircleObject::WriteIMapObject( SvStream& rOStm ) const -{ - sal_uInt32 nTmp = nRadius; - - WritePair( rOStm, aCenter ); - rOStm.WriteUInt32( nTmp ); -} - - -/****************************************************************************** -|* -|* Binary import -|* -\******************************************************************************/ - -void IMapCircleObject::ReadIMapObject( SvStream& rIStm ) -{ - sal_uInt32 nTmp; - - ReadPair( rIStm, aCenter ); - rIStm.ReadUInt32( nTmp ); - - nRadius = nTmp; -} - - -/****************************************************************************** -|* -|* return type -|* -\******************************************************************************/ - -sal_uInt16 IMapCircleObject::GetType() const -{ - return IMAP_OBJ_CIRCLE; -} - - -/****************************************************************************** -|* -|* Hit-Test -|* -\******************************************************************************/ - -bool IMapCircleObject::IsHit( const Point& rPoint ) const -{ - const Point aPoint( aCenter - rPoint ); - bool bRet = false; - - if ( static_cast<sal_Int32>(sqrt( static_cast<double>(aPoint.X()) * aPoint.X() + - aPoint.Y() * aPoint.Y() )) <= nRadius ) - { - bRet = true; - } - - return bRet; -} - -Point IMapCircleObject::GetCenter( bool bPixelCoords ) const -{ - Point aNewPoint; - - if ( bPixelCoords ) - aNewPoint = Application::GetDefaultDevice()->LogicToPixel( aCenter, MapMode( MapUnit::Map100thMM ) ); - else - aNewPoint = aCenter; - - return aNewPoint; -} - -sal_uLong IMapCircleObject::GetRadius( bool bPixelCoords ) const -{ - sal_uLong nNewRadius; - - if ( bPixelCoords ) - nNewRadius = Application::GetDefaultDevice()->LogicToPixel( Size( nRadius, 0 ), MapMode( MapUnit::Map100thMM ) ).Width(); - else - nNewRadius = nRadius; - - return nNewRadius; -} - -void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) -{ - Fraction aAverage( rFracX ); - - aAverage += rFracY; - aAverage *= Fraction( 1, 2 ); - - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aCenter, rFracX, rFracY ); - } - - if (!aAverage.GetDenominator()) - throw o3tl::divide_by_zero(); - - nRadius = double(nRadius * aAverage); -} - -bool IMapCircleObject::IsEqual( const IMapCircleObject& rEqObj ) -{ - return ( IMapObject::IsEqual( rEqObj ) && - ( aCenter == rEqObj.aCenter ) && - ( nRadius == rEqObj.nRadius ) ); -} - -IMapPolygonObject::IMapPolygonObject( const tools::Polygon& rPoly, - const OUString& rURL, - const OUString& rAltText, - const OUString& rDesc, - const OUString& rTarget, - const OUString& rName, - bool bURLActive, - bool bPixelCoords ) : - IMapObject ( rURL, rAltText, rDesc, rTarget, rName, bURLActive ), - bEllipse ( false ) -{ - ImpConstruct( rPoly, bPixelCoords ); -} - -void IMapPolygonObject::ImpConstruct( const tools::Polygon& rPoly, bool bPixel ) -{ - if ( bPixel ) - aPoly = Application::GetDefaultDevice()->PixelToLogic( rPoly, MapMode( MapUnit::Map100thMM ) ); - else - aPoly = rPoly; -} - - -/****************************************************************************** -|* -|* Binary export -|* -\******************************************************************************/ - -void IMapPolygonObject::WriteIMapObject( SvStream& rOStm ) const -{ - WritePolygon( rOStm, aPoly ); - rOStm.WriteBool( bEllipse ); // >= Version 2 - WriteRectangle( rOStm, aEllipse ); // >= Version 2 -} - - -/****************************************************************************** -|* -|* Binary import -|* -\******************************************************************************/ - -void IMapPolygonObject::ReadIMapObject( SvStream& rIStm ) -{ - ReadPolygon( rIStm, aPoly ); - - // Version >= 2 has additional ellipses information - if ( nReadVersion >= 2 ) - { - rIStm.ReadCharAsBool( bEllipse ); - ReadRectangle( rIStm, aEllipse ); - } -} - - -/****************************************************************************** -|* -|* return type -|* -\******************************************************************************/ - -sal_uInt16 IMapPolygonObject::GetType() const -{ - return IMAP_OBJ_POLYGON; -} - - -/****************************************************************************** -|* -|* hit test -|* -\******************************************************************************/ - -bool IMapPolygonObject::IsHit( const Point& rPoint ) const -{ - return aPoly.IsInside( rPoint ); -} - -tools::Polygon IMapPolygonObject::GetPolygon( bool bPixelCoords ) const -{ - tools::Polygon aNewPoly; - - if ( bPixelCoords ) - aNewPoly = Application::GetDefaultDevice()->LogicToPixel( aPoly, MapMode( MapUnit::Map100thMM ) ); - else - aNewPoly = aPoly; - - return aNewPoly; -} - -void IMapPolygonObject::SetExtraEllipse( const tools::Rectangle& rEllipse ) -{ - if ( aPoly.GetSize() ) - { - bEllipse = true; - aEllipse = rEllipse; - } -} - -void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) -{ - sal_uInt16 nCount = aPoly.GetSize(); - - for ( sal_uInt16 i = 0; i < nCount; i++ ) - { - Point aScaledPt( aPoly[ i ] ); - - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aScaledPt, rFracX, rFracY ); - } - - aPoly[ i ] = aScaledPt; - } - - if ( !bEllipse ) - return; - - Point aTL( aEllipse.TopLeft() ); - Point aBR( aEllipse.BottomRight() ); - - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aTL, rFracX, rFracY ); - SCALEPOINT( aBR, rFracX, rFracY ); - } - - aEllipse = tools::Rectangle( aTL, aBR ); -} - -bool IMapPolygonObject::IsEqual( const IMapPolygonObject& rEqObj ) -{ - bool bRet = false; - - if ( IMapObject::IsEqual( rEqObj ) ) - { - const tools::Polygon& rEqPoly = rEqObj.aPoly; - const sal_uInt16 nCount = aPoly.GetSize(); - const sal_uInt16 nEqCount = rEqPoly.GetSize(); - - if ( nCount == nEqCount ) - { - bool bDifferent = false; - - for ( sal_uInt16 i = 0; i < nCount; i++ ) - { - if ( aPoly[ i ] != rEqPoly[ i ] ) - { - bDifferent = true; - break; - } - } - - if ( !bDifferent ) - bRet = true; - } - } - - return bRet; -} - -/****************************************************************************** -|* -|* Ctor -|* -\******************************************************************************/ - -ImageMap::ImageMap( const OUString& rName ) -: aName( rName ) -{ -} - - -/****************************************************************************** -|* -|* Copy-Ctor -|* -\******************************************************************************/ - -ImageMap::ImageMap( const ImageMap& rImageMap ) -{ - - size_t nCount = rImageMap.GetIMapObjectCount(); - - for ( size_t i = 0; i < nCount; i++ ) - { - IMapObject* pCopyObj = rImageMap.GetIMapObject( i ); - - switch( pCopyObj->GetType() ) - { - case IMAP_OBJ_RECTANGLE: - maList.emplace_back( new IMapRectangleObject( *static_cast<IMapRectangleObject*>( pCopyObj ) ) ); - break; - - case IMAP_OBJ_CIRCLE: - maList.emplace_back( new IMapCircleObject( *static_cast<IMapCircleObject*>( pCopyObj ) ) ); - break; - - case IMAP_OBJ_POLYGON: - maList.emplace_back( new IMapPolygonObject( *static_cast<IMapPolygonObject*>( pCopyObj ) ) ); - break; - - default: - break; - } - } - - aName = rImageMap.aName; -} - - -/****************************************************************************** -|* -|* Dtor -|* -\******************************************************************************/ - -ImageMap::~ImageMap() -{ -} - - -/****************************************************************************** -|* -|* release internal memory -|* -\******************************************************************************/ - -void ImageMap::ClearImageMap() -{ - maList.clear(); - - aName.clear(); -} - - -/****************************************************************************** -|* -|* assignment operator -|* -\******************************************************************************/ - -ImageMap& ImageMap::operator=( const ImageMap& rImageMap ) -{ - if (this != &rImageMap) - { - size_t nCount = rImageMap.GetIMapObjectCount(); - - ClearImageMap(); - - for ( size_t i = 0; i < nCount; i++ ) - { - IMapObject* pCopyObj = rImageMap.GetIMapObject( i ); - - switch( pCopyObj->GetType() ) - { - case IMAP_OBJ_RECTANGLE: - maList.emplace_back( new IMapRectangleObject( *static_cast<IMapRectangleObject*>(pCopyObj) ) ); - break; - - case IMAP_OBJ_CIRCLE: - maList.emplace_back( new IMapCircleObject( *static_cast<IMapCircleObject*>(pCopyObj) ) ); - break; - - case IMAP_OBJ_POLYGON: - maList.emplace_back( new IMapPolygonObject( *static_cast<IMapPolygonObject*>(pCopyObj) ) ); - break; - - default: - break; - } - } - - aName = rImageMap.aName; - } - return *this; -} - - -/****************************************************************************** -|* -|* compare operator I -|* -\******************************************************************************/ - -bool ImageMap::operator==( const ImageMap& rImageMap ) -{ - const size_t nCount = maList.size(); - const size_t nEqCount = rImageMap.GetIMapObjectCount(); - bool bRet = false; - - if ( nCount == nEqCount ) - { - bool bDifferent = ( aName != rImageMap.aName ); - - for ( size_t i = 0; ( i < nCount ) && !bDifferent; i++ ) - { - IMapObject* pObj = maList[ i ].get(); - IMapObject* pEqObj = rImageMap.GetIMapObject( i ); - - if ( pObj->GetType() == pEqObj->GetType() ) - { - switch( pObj->GetType() ) - { - case IMAP_OBJ_RECTANGLE: - { - if ( ! static_cast<IMapRectangleObject*>(pObj)->IsEqual( *static_cast<IMapRectangleObject*>(pEqObj) ) ) - bDifferent = true; - } - break; - - case IMAP_OBJ_CIRCLE: - { - if ( ! static_cast<IMapCircleObject*>(pObj)->IsEqual( *static_cast<IMapCircleObject*>(pEqObj) ) ) - bDifferent = true; - } - break; - - case IMAP_OBJ_POLYGON: - { - if ( ! static_cast<IMapPolygonObject*>(pObj)->IsEqual( *static_cast<IMapPolygonObject*>(pEqObj) ) ) - bDifferent = true; - } - break; - - default: - break; - } - } - else - bDifferent = true; - } - - if ( !bDifferent ) - bRet = true; - } - - return bRet; -} - - -/****************************************************************************** -|* -|* compare operator II -|* -\******************************************************************************/ - -bool ImageMap::operator!=( const ImageMap& rImageMap ) -{ - return !( *this == rImageMap ); -} - - -/****************************************************************************** -|* -|* insert new object -|* -\******************************************************************************/ - -void ImageMap::InsertIMapObject( const IMapObject& rIMapObject ) -{ - switch( rIMapObject.GetType() ) - { - case IMAP_OBJ_RECTANGLE: - maList.emplace_back( new IMapRectangleObject( static_cast<const IMapRectangleObject&>( rIMapObject ) ) ); - break; - - case IMAP_OBJ_CIRCLE: - maList.emplace_back( new IMapCircleObject( static_cast<const IMapCircleObject&>( rIMapObject ) ) ); - break; - - case IMAP_OBJ_POLYGON: - maList.emplace_back( new IMapPolygonObject( static_cast<const IMapPolygonObject&>( rIMapObject ) ) ); - break; - - default: - break; - } -} - -void ImageMap::InsertIMapObject( std::unique_ptr<IMapObject> pNewObject ) -{ - maList.emplace_back( std::move(pNewObject) ); -} - -/****************************************************************************** -|* -|* hit test -|* -\******************************************************************************/ - -IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize, - const Size& rDisplaySize, - const Point& rRelHitPoint, - sal_uLong nFlags ) -{ - Point aRelPoint( rTotalSize.Width() * rRelHitPoint.X() / rDisplaySize.Width(), - rTotalSize.Height() * rRelHitPoint.Y() / rDisplaySize.Height() ); - - // transform point to check before checking if flags to mirror etc. are set, - if ( nFlags ) - { - if ( nFlags & IMAP_MIRROR_HORZ ) - aRelPoint.setX( rTotalSize.Width() - aRelPoint.X() ); - - if ( nFlags & IMAP_MIRROR_VERT ) - aRelPoint.setY( rTotalSize.Height() - aRelPoint.Y() ); - } - - // walk over all objects and execute HitTest - IMapObject* pObj = nullptr; - for(auto& i : maList) { - if ( i->IsHit( aRelPoint ) ) { - pObj = i.get(); - break; - } - } - - return( pObj ? ( pObj->IsActive() ? pObj : nullptr ) : nullptr ); -} - -void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY ) -{ - size_t nCount = maList.size(); - - for ( size_t i = 0; i < nCount; i++ ) - { - IMapObject* pObj = maList[ i ].get(); - - switch( pObj->GetType() ) - { - case IMAP_OBJ_RECTANGLE: - static_cast<IMapRectangleObject*>( pObj )->Scale( rFracX, rFracY ); - break; - - case IMAP_OBJ_CIRCLE: - static_cast<IMapCircleObject*>( pObj )->Scale( rFracX, rFracY ); - break; - - case IMAP_OBJ_POLYGON: - static_cast<IMapPolygonObject*>( pObj )->Scale( rFracX, rFracY ); - break; - - default: - break; - } - } -} - - -/****************************************************************************** -|* -|* sequentially write objects -|* -\******************************************************************************/ - -void ImageMap::ImpWriteImageMap( SvStream& rOStm ) const -{ - size_t nCount = maList.size(); - - for ( size_t i = 0; i < nCount; i++ ) - { - auto& pObj = maList[ i ]; - pObj->Write( rOStm ); - } -} - - -/****************************************************************************** -|* -|* sequentially read objects -|* -\******************************************************************************/ - -void ImageMap::ImpReadImageMap( SvStream& rIStm, size_t nCount ) -{ - const size_t nMinRecordSize = 12; //circle, three 32bit numbers - const size_t nMaxRecords = rIStm.remainingSize() / nMinRecordSize; - - if (nCount > nMaxRecords) - { - SAL_WARN("svtools.misc", "Parsing error: " << nMaxRecords << " max possible entries, but " << - nCount << " claimed, truncating"); - nCount = nMaxRecords; - } - - // read new objects - for (size_t i = 0; i < nCount; ++i) - { - sal_uInt16 nType; - - rIStm.ReadUInt16( nType ); - rIStm.SeekRel( -2 ); - - switch( nType ) - { - case IMAP_OBJ_RECTANGLE: - { - IMapRectangleObject* pObj = new IMapRectangleObject; - pObj->Read( rIStm ); - maList.emplace_back( pObj ); - } - break; - - case IMAP_OBJ_CIRCLE: - { - IMapCircleObject* pObj = new IMapCircleObject; - pObj->Read( rIStm ); - maList.emplace_back( pObj ); - } - break; - - case IMAP_OBJ_POLYGON: - { - IMapPolygonObject* pObj = new IMapPolygonObject; - pObj->Read( rIStm ); - maList.emplace_back( pObj ); - } - break; - - default: - break; - } - } -} - - -/****************************************************************************** -|* -|* store binary -|* -\******************************************************************************/ - -void ImageMap::Write( SvStream& rOStm ) const -{ - IMapCompat* pCompat; - OUString aImageName( GetName() ); - SvStreamEndian nOldFormat = rOStm.GetEndian(); - sal_uInt16 nCount = static_cast<sal_uInt16>(GetIMapObjectCount()); - const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); //vomit! - - rOStm.SetEndian( SvStreamEndian::LITTLE ); - - // write MagicCode - rOStm.WriteCharPtr( IMAPMAGIC ); - rOStm.WriteUInt16( IMAGE_MAP_VERSION ); - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aImageName, eEncoding); - write_uInt16_lenPrefixed_uInt8s_FromOString(rOStm, OString()); //dummy - rOStm.WriteUInt16( nCount ); - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aImageName, eEncoding); - - pCompat = new IMapCompat( rOStm, StreamMode::WRITE ); - - // here one can insert in newer versions - - delete pCompat; - - ImpWriteImageMap( rOStm ); - - rOStm.SetEndian( nOldFormat ); -} - - -/****************************************************************************** -|* -|* load binary -|* -\******************************************************************************/ - -void ImageMap::Read( SvStream& rIStm ) -{ - char cMagic[6]; - SvStreamEndian nOldFormat = rIStm.GetEndian(); - sal_uInt16 nCount; - - rIStm.SetEndian( SvStreamEndian::LITTLE ); - rIStm.ReadBytes(cMagic, sizeof(cMagic)); - - if ( !memcmp( cMagic, IMAPMAGIC, sizeof( cMagic ) ) ) - { - IMapCompat* pCompat; - - // delete old content - ClearImageMap(); - - // read on version - rIStm.SeekRel( 2 ); - - aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, osl_getThreadTextEncoding()); - read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm); // Dummy - rIStm.ReadUInt16( nCount ); - read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm); // Dummy - - pCompat = new IMapCompat( rIStm, StreamMode::READ ); - - // here one can read in newer versions - - delete pCompat; - ImpReadImageMap( rIStm, nCount ); - - } - else - rIStm.SetError( SVSTREAM_GENERALERROR ); - - rIStm.SetEndian( nOldFormat ); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/misc/imap2.cxx b/svtools/source/misc/imap2.cxx deleted file mode 100644 index da99028254fa..000000000000 --- a/svtools/source/misc/imap2.cxx +++ /dev/null @@ -1,532 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <comphelper/string.hxx> -#include <string.h> -#include <rtl/strbuf.hxx> -#include <vcl/svapp.hxx> -#include <tools/urlobj.hxx> -#include <vcl/wrkwin.hxx> -#include <sot/formats.hxx> - -#include <svl/urihelper.hxx> -#include <svtools/imap.hxx> -#include <svtools/imapobj.hxx> -#include <svtools/imaprect.hxx> -#include <svtools/imapcirc.hxx> -#include <svtools/imappoly.hxx> - -#include <math.h> - -#define NOTEOL(c) ((c)!='\0') - -void IMapObject::AppendCERNCoords(OStringBuffer& rBuf, const Point& rPoint100) -{ - const Point aPixPt( Application::GetDefaultDevice()->LogicToPixel( rPoint100, MapMode( MapUnit::Map100thMM ) ) ); - - rBuf.append('('); - rBuf.append(static_cast<sal_Int32>(aPixPt.X())); - rBuf.append(','); - rBuf.append(static_cast<sal_Int32>(aPixPt.Y())); - rBuf.append(") "); -} - -void IMapObject::AppendNCSACoords(OStringBuffer& rBuf, const Point& rPoint100) -{ - const Point aPixPt( Application::GetDefaultDevice()->LogicToPixel( rPoint100, MapMode( MapUnit::Map100thMM ) ) ); - - rBuf.append(static_cast<sal_Int32>(aPixPt.X())); - rBuf.append(','); - rBuf.append(static_cast<sal_Int32>(aPixPt.Y())); - rBuf.append(' '); -} - -void IMapObject::AppendCERNURL(OStringBuffer& rBuf) const -{ - rBuf.append(OUStringToOString(URIHelper::simpleNormalizedMakeRelative("", aURL), osl_getThreadTextEncoding())); -} - -void IMapObject::AppendNCSAURL(OStringBuffer& rBuf) const -{ - rBuf.append(OUStringToOString(URIHelper::simpleNormalizedMakeRelative("", aURL), osl_getThreadTextEncoding())); - rBuf.append(' '); -} - -void IMapRectangleObject::WriteCERN( SvStream& rOStm ) const -{ - OStringBuffer aStrBuf("rectangle "); - - AppendCERNCoords(aStrBuf, aRect.TopLeft()); - AppendCERNCoords(aStrBuf, aRect.BottomRight()); - AppendCERNURL(aStrBuf); - - rOStm.WriteLine(aStrBuf.makeStringAndClear()); -} - -void IMapRectangleObject::WriteNCSA( SvStream& rOStm ) const -{ - OStringBuffer aStrBuf("rect "); - - AppendNCSAURL(aStrBuf); - AppendNCSACoords(aStrBuf, aRect.TopLeft()); - AppendNCSACoords(aStrBuf, aRect.BottomRight()); - - rOStm.WriteLine(aStrBuf.makeStringAndClear()); -} - -void IMapCircleObject::WriteCERN( SvStream& rOStm ) const -{ - OStringBuffer aStrBuf("circle "); - - AppendCERNCoords(aStrBuf, aCenter); - aStrBuf.append(nRadius); - aStrBuf.append(' '); - AppendCERNURL(aStrBuf); - - rOStm.WriteLine(aStrBuf.makeStringAndClear()); -} - -void IMapCircleObject::WriteNCSA( SvStream& rOStm ) const -{ - OStringBuffer aStrBuf("circle "); - - AppendNCSAURL(aStrBuf); - AppendNCSACoords(aStrBuf, aCenter); - AppendNCSACoords(aStrBuf, aCenter + Point(nRadius, 0)); - - rOStm.WriteLine(aStrBuf.makeStringAndClear()); -} - -void IMapPolygonObject::WriteCERN( SvStream& rOStm ) const -{ - OStringBuffer aStrBuf("polygon "); - const sal_uInt16 nCount = aPoly.GetSize(); - - for (sal_uInt16 i = 0; i < nCount; ++i) - AppendCERNCoords(aStrBuf, aPoly[i]); - - AppendCERNURL(aStrBuf); - - rOStm.WriteLine(aStrBuf.makeStringAndClear()); -} - -void IMapPolygonObject::WriteNCSA( SvStream& rOStm ) const -{ - OStringBuffer aStrBuf("poly "); - const sal_uInt16 nCount = std::min( aPoly.GetSize(), sal_uInt16(100) ); - - AppendNCSAURL(aStrBuf); - - for (sal_uInt16 i = 0; i < nCount; ++i) - AppendNCSACoords(aStrBuf, aPoly[i]); - - rOStm.WriteLine(aStrBuf.makeStringAndClear()); -} - -void ImageMap::Write( SvStream& rOStm, sal_uLong nFormat ) const -{ - switch( nFormat ) - { - case IMAP_FORMAT_BIN : Write( rOStm ); break; - case IMAP_FORMAT_CERN : ImpWriteCERN( rOStm ); break; - case IMAP_FORMAT_NCSA : ImpWriteNCSA( rOStm ); break; - - default: - break; - } -} - -void ImageMap::ImpWriteCERN( SvStream& rOStm ) const -{ - size_t nCount = maList.size(); - - for ( size_t i = 0; i < nCount; i++ ) - { - IMapObject* pObj = maList[ i ].get(); - - switch( pObj->GetType() ) - { - case IMAP_OBJ_RECTANGLE: - static_cast<IMapRectangleObject*>( pObj )->WriteCERN( rOStm ); - break; - - case IMAP_OBJ_CIRCLE: - static_cast<IMapCircleObject*>( pObj )->WriteCERN( rOStm ); - break; - - case IMAP_OBJ_POLYGON: - static_cast<IMapPolygonObject*>( pObj )->WriteCERN( rOStm ); - break; - - default: - break; - } - } -} - -void ImageMap::ImpWriteNCSA( SvStream& rOStm ) const -{ - size_t nCount = maList.size(); - - for ( size_t i = 0; i < nCount; i++ ) - { - IMapObject* pObj = maList[ i ].get(); - - switch( pObj->GetType() ) - { - case IMAP_OBJ_RECTANGLE: - static_cast<IMapRectangleObject*>( pObj )->WriteNCSA( rOStm ); - break; - - case IMAP_OBJ_CIRCLE: - static_cast<IMapCircleObject*>( pObj )->WriteNCSA( rOStm ); - break; - - case IMAP_OBJ_POLYGON: - static_cast<IMapPolygonObject*>( pObj )->WriteNCSA( rOStm ); - break; - - default: - break; - } - } -} - -sal_uLong ImageMap::Read( SvStream& rIStm, sal_uLong nFormat ) -{ - sal_uLong nRet = IMAP_ERR_FORMAT; - - if ( nFormat == IMAP_FORMAT_DETECT ) - nFormat = ImpDetectFormat( rIStm ); - - switch ( nFormat ) - { - case IMAP_FORMAT_BIN : Read( rIStm ); break; - case IMAP_FORMAT_CERN : ImpReadCERN( rIStm ); break; - case IMAP_FORMAT_NCSA : ImpReadNCSA( rIStm ); break; - - default: - break; - } - - if ( !rIStm.GetError() ) - nRet = IMAP_ERR_OK; - - return nRet; -} - -void ImageMap::ImpReadCERN( SvStream& rIStm ) -{ - // delete old content - ClearImageMap(); - - OString aStr; - while ( rIStm.ReadLine( aStr ) ) - ImpReadCERNLine( aStr ); -} - -void ImageMap::ImpReadCERNLine( const OString& rLine ) -{ - OString aStr = comphelper::string::stripStart(rLine, ' '); - aStr = comphelper::string::stripStart(aStr, '\t'); - aStr = aStr.replaceAll(";", ""); - aStr = aStr.toAsciiLowerCase(); - - const char* pStr = aStr.getStr(); - char cChar = *pStr++; - - // find instruction - OStringBuffer aBuf; - while( ( cChar >= 'a' ) && ( cChar <= 'z' ) && NOTEOL( cChar ) ) - { - aBuf.append(cChar); - cChar = *pStr++; - } - OString aToken = aBuf.makeStringAndClear(); - - if ( !(NOTEOL( cChar )) ) - return; - - if ( ( aToken == "rectangle" ) || ( aToken == "rect" ) ) - { - const Point aTopLeft( ImpReadCERNCoords( &pStr ) ); - const Point aBottomRight( ImpReadCERNCoords( &pStr ) ); - const OUString aURL( ImpReadCERNURL( &pStr ) ); - const tools::Rectangle aRect( aTopLeft, aBottomRight ); - - maList.emplace_back( new IMapRectangleObject( aRect, aURL, OUString(), OUString(), OUString(), OUString() ) ); - } - else if ( ( aToken == "circle" ) || ( aToken == "circ" ) ) - { - const Point aCenter( ImpReadCERNCoords( &pStr ) ); - const long nRadius = ImpReadCERNRadius( &pStr ); - const OUString aURL( ImpReadCERNURL( &pStr ) ); - - maList.emplace_back( new IMapCircleObject( aCenter, nRadius, aURL, OUString(), OUString(), OUString(), OUString() ) ); - } - else if ( ( aToken == "polygon" ) || ( aToken == "poly" ) ) - { - const sal_uInt16 nCount = comphelper::string::getTokenCount(aStr, '(') - 1; - tools::Polygon aPoly( nCount ); - - for ( sal_uInt16 i = 0; i < nCount; i++ ) - aPoly[ i ] = ImpReadCERNCoords( &pStr ); - - const OUString aURL = ImpReadCERNURL( &pStr ); - - maList.emplace_back( new IMapPolygonObject( aPoly, aURL, OUString(), OUString(), OUString(), OUString() ) ); - } -} - -Point ImageMap::ImpReadCERNCoords( const char** ppStr ) -{ - OUStringBuffer aStrX; - OUStringBuffer aStrY; - Point aPt; - char cChar = *(*ppStr)++; - - while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) ) - cChar = *(*ppStr)++; - - if ( NOTEOL( cChar ) ) - { - while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) ) - { - aStrX.append( cChar ); - cChar = *(*ppStr)++; - } - - if ( NOTEOL( cChar ) ) - { - while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) ) - cChar = *(*ppStr)++; - - while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) ) - { - aStrY.append( cChar ); - cChar = *(*ppStr)++; - } - - if ( NOTEOL( cChar ) ) - while( NOTEOL( cChar ) && ( cChar != ')' ) ) - cChar = *(*ppStr)++; - - aPt = Point( aStrX.makeStringAndClear().toInt32(), aStrY.makeStringAndClear().toInt32() ); - } - } - - return aPt; -} - -long ImageMap::ImpReadCERNRadius( const char** ppStr ) -{ - OUStringBuffer aStr; - char cChar = *(*ppStr)++; - - while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) ) - cChar = *(*ppStr)++; - - if ( NOTEOL( cChar ) ) - { - while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) ) - { - aStr.append( cChar ); - cChar = *(*ppStr)++; - } - } - - return aStr.makeStringAndClear().toInt32(); -} - -OUString ImageMap::ImpReadCERNURL( const char** ppStr ) -{ - OUString aStr(OUString::createFromAscii(*ppStr)); - - aStr = comphelper::string::stripStart(aStr, ' '); - aStr = comphelper::string::stripStart(aStr, '\t'); - aStr = comphelper::string::stripEnd(aStr, ' '); - aStr = comphelper::string::stripEnd(aStr, '\t'); - - return INetURLObject::GetAbsURL( "", aStr ); -} - -void ImageMap::ImpReadNCSA( SvStream& rIStm ) -{ - // delete old content - ClearImageMap(); - - OString aStr; - while ( rIStm.ReadLine( aStr ) ) - ImpReadNCSALine( aStr ); -} - -void ImageMap::ImpReadNCSALine( const OString& rLine ) -{ - OString aStr = comphelper::string::stripStart(rLine, ' '); - aStr = comphelper::string::stripStart(aStr, '\t'); - aStr = aStr.replaceAll(";", ""); - aStr = aStr.toAsciiLowerCase(); - - const char* pStr = aStr.getStr(); - char cChar = *pStr++; - - // find instruction - OStringBuffer aBuf; - while( ( cChar >= 'a' ) && ( cChar <= 'z' ) && NOTEOL( cChar ) ) - { - aBuf.append(cChar); - cChar = *pStr++; - } - OString aToken = aBuf.makeStringAndClear(); - - if ( !(NOTEOL( cChar )) ) - return; - - if ( aToken == "rect" ) - { - const OUString aURL( ImpReadNCSAURL( &pStr ) ); - const Point aTopLeft( ImpReadNCSACoords( &pStr ) ); - const Point aBottomRight( ImpReadNCSACoords( &pStr ) ); - const tools::Rectangle aRect( aTopLeft, aBottomRight ); - - maList.emplace_back( new IMapRectangleObject( aRect, aURL, OUString(), OUString(), OUString(), OUString() ) ); - } - else if ( aToken == "circle" ) - { - const OUString aURL( ImpReadNCSAURL( &pStr ) ); - const Point aCenter( ImpReadNCSACoords( &pStr ) ); - const Point aDX( aCenter - ImpReadNCSACoords( &pStr ) ); - long nRadius = static_cast<long>(sqrt( static_cast<double>(aDX.X()) * aDX.X() + - static_cast<double>(aDX.Y()) * aDX.Y() )); - - maList.emplace_back( new IMapCircleObject( aCenter, nRadius, aURL, OUString(), OUString(), OUString(), OUString() ) ); - } - else if ( aToken == "poly" ) - { - const sal_uInt16 nCount = comphelper::string::getTokenCount(aStr, ',') - 1; - const OUString aURL( ImpReadNCSAURL( &pStr ) ); - tools::Polygon aPoly( nCount ); - - for ( sal_uInt16 i = 0; i < nCount; i++ ) - aPoly[ i ] = ImpReadNCSACoords( &pStr ); - - maList.emplace_back( new IMapPolygonObject( aPoly, aURL, OUString(), OUString(), OUString(), OUString() ) ); - } -} - -OUString ImageMap::ImpReadNCSAURL( const char** ppStr ) -{ - OUStringBuffer aStr; - char cChar = *(*ppStr)++; - - while( NOTEOL( cChar ) && ( ( cChar == ' ' ) || ( cChar == '\t' ) ) ) - cChar = *(*ppStr)++; - - if ( NOTEOL( cChar ) ) - { - while( NOTEOL( cChar ) && ( cChar != ' ' ) && ( cChar != '\t' ) ) - { - aStr.append( cChar ); - cChar = *(*ppStr)++; - } - } - - return INetURLObject::GetAbsURL( "", aStr.makeStringAndClear() ); -} - -Point ImageMap::ImpReadNCSACoords( const char** ppStr ) -{ - OUStringBuffer aStrX; - OUStringBuffer aStrY; - Point aPt; - char cChar = *(*ppStr)++; - - while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) ) - cChar = *(*ppStr)++; - - if ( NOTEOL( cChar ) ) - { - while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) ) - { - aStrX.append( cChar ); - cChar = *(*ppStr)++; - } - - if ( NOTEOL( cChar ) ) - { - while( NOTEOL( cChar ) && ( ( cChar < '0' ) || ( cChar > '9' ) ) ) - cChar = *(*ppStr)++; - - while( NOTEOL( cChar ) && ( cChar >= '0' ) && ( cChar <= '9' ) ) - { - aStrY.append( cChar ); - cChar = *(*ppStr)++; - } - - aPt = Point( aStrX.makeStringAndClear().toInt32(), aStrY.makeStringAndClear().toInt32() ); - } - } - - return aPt; -} - -sal_uLong ImageMap::ImpDetectFormat( SvStream& rIStm ) -{ - sal_uInt64 nPos = rIStm.Tell(); - sal_uLong nRet = IMAP_FORMAT_BIN; - char cMagic[6]; - - rIStm.ReadBytes(cMagic, sizeof(cMagic)); - - // if we do not have an internal formats - // we check the format - if ( memcmp( cMagic, IMAPMAGIC, sizeof( cMagic ) ) ) - { - long nCount = 128; - - rIStm.Seek( nPos ); - OString aStr; - while ( rIStm.ReadLine( aStr ) && nCount-- ) - { - aStr = aStr.toAsciiLowerCase(); - - if ( (aStr.indexOf("rect") != -1) || - (aStr.indexOf("circ") != -1) || - (aStr.indexOf("poly") != -1) ) - { - if ( ( aStr.indexOf('(') != -1 ) && - ( aStr.indexOf(')') != -1 ) ) - { - nRet = IMAP_FORMAT_CERN; - } - else - nRet = IMAP_FORMAT_NCSA; - - break; - } - } - } - - rIStm.Seek( nPos ); - - return nRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/misc/imap3.cxx b/svtools/source/misc/imap3.cxx deleted file mode 100644 index eed27dd2a729..000000000000 --- a/svtools/source/misc/imap3.cxx +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <svtools/imap.hxx> - -#include <tools/debug.hxx> - - -/****************************************************************************** -|* -|* Ctor -|* -\******************************************************************************/ - -IMapCompat::IMapCompat( SvStream& rStm, const StreamMode nStreamMode ) - : pRWStm(&rStm) - , nCompatPos(0) - , nTotalSize(0) - , nStmMode(nStreamMode) -{ - DBG_ASSERT( nStreamMode == StreamMode::READ || nStreamMode == StreamMode::WRITE, "Wrong Mode!" ); - - if ( pRWStm->GetError() ) - return; - - if ( nStmMode == StreamMode::WRITE ) - { - nCompatPos = pRWStm->Tell(); - pRWStm->SeekRel( 4 ); - nTotalSize = nCompatPos + 4; - } - else - { - sal_uInt32 nTotalSizeTmp; - pRWStm->ReadUInt32( nTotalSizeTmp ); - nTotalSize = nTotalSizeTmp; - nCompatPos = pRWStm->Tell(); - } -} - - -/****************************************************************************** -|* -|* Dtor -|* -\******************************************************************************/ - -IMapCompat::~IMapCompat() -{ - if ( pRWStm->GetError() ) - return; - - if ( nStmMode == StreamMode::WRITE ) - { - const sal_uInt64 nEndPos = pRWStm->Tell(); - - pRWStm->Seek( nCompatPos ); - pRWStm->WriteUInt32( nEndPos - nTotalSize ); - pRWStm->Seek( nEndPos ); - } - else - { - const sal_uInt64 nReadSize = pRWStm->Tell() - nCompatPos; - - if ( nTotalSize > nReadSize ) - pRWStm->SeekRel( nTotalSize - nReadSize ); - } -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/misc/openfiledroptargetlistener.cxx b/svtools/source/misc/openfiledroptargetlistener.cxx index 06e92db659ae..4baed7364fd7 100644 --- a/svtools/source/misc/openfiledroptargetlistener.cxx +++ b/svtools/source/misc/openfiledroptargetlistener.cxx @@ -26,7 +26,7 @@ #include <com/sun/star/util/URLTransformer.hpp> #include <com/sun/star/util/XURLTransformer.hpp> -#include <svtools/transfer.hxx> +#include <vcl/transfer.hxx> #include <sot/filelist.hxx> #include <osl/file.hxx> diff --git a/svtools/source/misc/svtaccessiblefactory.cxx b/svtools/source/misc/svtaccessiblefactory.cxx index 08bb8710a555..8d0bbcc04e3c 100644 --- a/svtools/source/misc/svtaccessiblefactory.cxx +++ b/svtools/source/misc/svtaccessiblefactory.cxx @@ -110,15 +110,6 @@ namespace svt } virtual css::uno::Reference< css::accessibility::XAccessible > - createAccessibleTreeListBox( - SvTreeListBox& /*_rListBox*/, - const css::uno::Reference< css::accessibility::XAccessible >& /*_xParent*/ - ) const override - { - return nullptr; - } - - virtual css::uno::Reference< css::accessibility::XAccessible > createAccessibleBrowseBoxHeaderBar( const css::uno::Reference< css::accessibility::XAccessible >& /*rxParent*/, IAccessibleTableProvider& /*_rOwningTable*/, diff --git a/svtools/source/misc/transfer.cxx b/svtools/source/misc/transfer.cxx deleted file mode 100644 index 44c01059684d..000000000000 --- a/svtools/source/misc/transfer.cxx +++ /dev/null @@ -1,2177 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifdef _WIN32 -#include <prewin.h> -#include <postwin.h> -#include <shlobj.h> -#endif -#include <osl/mutex.hxx> -#include <rtl/uri.hxx> -#include <sal/log.hxx> -#include <tools/debug.hxx> -#include <tools/urlobj.hxx> -#include <unotools/ucbstreamhelper.hxx> -#include <sot/exchange.hxx> -#include <sot/storage.hxx> -#include <vcl/bitmap.hxx> -#include <vcl/gdimtf.hxx> -#include <vcl/graph.hxx> -#include <vcl/cvtgrf.hxx> -#include <vcl/svapp.hxx> -#include <vcl/window.hxx> -#include <comphelper/fileformat.h> -#include <comphelper/processfactory.hxx> -#include <comphelper/servicehelper.hxx> -#include <comphelper/sequence.hxx> -#include <sot/filelist.hxx> -#include <cppuhelper/implbase.hxx> - -#include <comphelper/seqstream.hxx> -#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp> -#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp> -#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> -#include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp> -#include <com/sun/star/datatransfer/XMimeContentType.hpp> -#include <com/sun/star/datatransfer/XTransferable2.hpp> -#include <com/sun/star/frame/Desktop.hpp> -#include <com/sun/star/lang/XInitialization.hpp> - -#include <svl/urlbmk.hxx> -#include <svtools/inetimg.hxx> -#include <vcl/wmf.hxx> -#include <svtools/imap.hxx> -#include <svtools/transfer.hxx> -#include <rtl/strbuf.hxx> -#include <cstdio> -#include <vcl/dibtools.hxx> -#include <vcl/pngread.hxx> -#include <vcl/pngwrite.hxx> -#include <vcl/graphicfilter.hxx> -#include <memory> - - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::frame; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::datatransfer; -using namespace ::com::sun::star::datatransfer::clipboard; -using namespace ::com::sun::star::datatransfer::dnd; - - -#define TOD_SIG1 0x01234567 -#define TOD_SIG2 0x89abcdef - -SvStream& WriteTransferableObjectDescriptor( SvStream& rOStm, const TransferableObjectDescriptor& rObjDesc ) -{ - const sal_uInt32 nFirstPos = rOStm.Tell(), nViewAspect = rObjDesc.mnViewAspect; - const sal_uInt32 nSig1 = TOD_SIG1, nSig2 = TOD_SIG2; - - rOStm.SeekRel( 4 ); - WriteSvGlobalName( rOStm, rObjDesc.maClassName ); - rOStm.WriteUInt32( nViewAspect ); - rOStm.WriteInt32( rObjDesc.maSize.Width() ); - rOStm.WriteInt32( rObjDesc.maSize.Height() ); - rOStm.WriteInt32( rObjDesc.maDragStartPos.X() ); - rOStm.WriteInt32( rObjDesc.maDragStartPos.Y() ); - rOStm.WriteUniOrByteString( rObjDesc.maTypeName, osl_getThreadTextEncoding() ); - rOStm.WriteUniOrByteString( rObjDesc.maDisplayName, osl_getThreadTextEncoding() ); - rOStm.WriteUInt32( nSig1 ).WriteUInt32( nSig2 ); - - const sal_uInt32 nLastPos = rOStm.Tell(); - - rOStm.Seek( nFirstPos ); - rOStm.WriteUInt32( nLastPos - nFirstPos ); - rOStm.Seek( nLastPos ); - - return rOStm; -} - - -// the reading of the parameter is done using the special service css::datatransfer::MimeContentType, -// a similar approach should be implemented for creation of the mimetype string; -// for now the set of acceptable characters has to be hardcoded, in future it should be part of the service that creates the mimetype - -static OUString ImplGetParameterString( const TransferableObjectDescriptor& rObjDesc ) -{ - const OUString aClassName( rObjDesc.maClassName.GetHexName() ); - OUString aParams; - - if( !aClassName.isEmpty() ) - { - aParams += ";classname=\"" + aClassName + "\""; - } - - if( !rObjDesc.maTypeName.isEmpty() ) - { - aParams += ";typename=\"" + rObjDesc.maTypeName + "\""; - } - - if( !rObjDesc.maDisplayName.isEmpty() ) - { - // the display name might contain unacceptable characters, encode all of them - // this seems to be the only parameter currently that might contain such characters - sal_Bool pToAccept[128]; - for (sal_Bool & rb : pToAccept) - rb = false; - - const char aQuotedParamChars[] = - "()<>@,;:/[]?=!#$&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~. "; - - for ( sal_Int32 nInd = 0; nInd < RTL_CONSTASCII_LENGTH(aQuotedParamChars); ++nInd ) - { - sal_Unicode nChar = aQuotedParamChars[nInd]; - if ( nChar < 128 ) - pToAccept[nChar] = true; - } - - aParams += ";displayname=\"" - + rtl::Uri::encode( - rObjDesc.maDisplayName, pToAccept, rtl_UriEncodeIgnoreEscapes, - RTL_TEXTENCODING_UTF8) - + "\""; - } - - aParams += ";viewaspect=\"" + OUString::number(rObjDesc.mnViewAspect) - + "\";width=\"" + OUString::number(rObjDesc.maSize.Width()) - + "\";height=\"" + OUString::number(rObjDesc.maSize.Height()) - + "\";posx=\"" + OUString::number(rObjDesc.maDragStartPos.X()) - + "\";posy=\"" + OUString::number(rObjDesc.maDragStartPos.X()) + "\""; - - return aParams; -} - - -static void ImplSetParameterString( TransferableObjectDescriptor& rObjDesc, const DataFlavorEx& rFlavorEx ) -{ - Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - - try - { - Reference< XMimeContentTypeFactory > xMimeFact = MimeContentTypeFactory::create( xContext ); - - Reference< XMimeContentType > xMimeType( xMimeFact->createMimeContentType( rFlavorEx.MimeType ) ); - - if( xMimeType.is() ) - { - const OUString aClassNameString( "classname" ); - const OUString aTypeNameString( "typename" ); - const OUString aDisplayNameString( "displayname" ); - const OUString aViewAspectString( "viewaspect" ); - const OUString aWidthString( "width" ); - const OUString aHeightString( "height" ); - const OUString aPosXString( "posx" ); - const OUString aPosYString( "posy" ); - - if( xMimeType->hasParameter( aClassNameString ) ) - { - rObjDesc.maClassName.MakeId( xMimeType->getParameterValue( aClassNameString ) ); - } - - if( xMimeType->hasParameter( aTypeNameString ) ) - { - rObjDesc.maTypeName = xMimeType->getParameterValue( aTypeNameString ); - } - - if( xMimeType->hasParameter( aDisplayNameString ) ) - { - // the display name might contain unacceptable characters, in this case they should be encoded - // this seems to be the only parameter currently that might contain such characters - rObjDesc.maDisplayName = ::rtl::Uri::decode( xMimeType->getParameterValue( aDisplayNameString ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); - } - - if( xMimeType->hasParameter( aViewAspectString ) ) - { - rObjDesc.mnViewAspect = static_cast< sal_uInt16 >( xMimeType->getParameterValue( aViewAspectString ).toInt32() ); - } - - if( xMimeType->hasParameter( aWidthString ) ) - { - rObjDesc.maSize.setWidth( xMimeType->getParameterValue( aWidthString ).toInt32() ); - } - - if( xMimeType->hasParameter( aHeightString ) ) - { - rObjDesc.maSize.setHeight( xMimeType->getParameterValue( aHeightString ).toInt32() ); - } - - if( xMimeType->hasParameter( aPosXString ) ) - { - rObjDesc.maDragStartPos.setX( xMimeType->getParameterValue( aPosXString ).toInt32() ); - } - - if( xMimeType->hasParameter( aPosYString ) ) - { - rObjDesc.maDragStartPos.setY( xMimeType->getParameterValue( aPosYString ).toInt32() ); - } - } - } - catch( const css::uno::Exception& ) - { - } -} - - -TransferableHelper::TerminateListener::TerminateListener( TransferableHelper& rTransferableHelper ) : - mrParent( rTransferableHelper ) -{ -} - - -TransferableHelper::TerminateListener::~TerminateListener() -{ -} - - -void SAL_CALL TransferableHelper::TerminateListener::disposing( const EventObject& ) -{ -} - - -void SAL_CALL TransferableHelper::TerminateListener::queryTermination( const EventObject& ) -{ -} - - -void SAL_CALL TransferableHelper::TerminateListener::notifyTermination( const EventObject& ) -{ - mrParent.ImplFlush(); -} - -OUString SAL_CALL TransferableHelper::TerminateListener::getImplementationName() -{ - return OUString("com.sun.star.comp.svt.TransferableHelperTerminateListener"); -} - -sal_Bool SAL_CALL TransferableHelper::TerminateListener::supportsService(const OUString& /*rServiceName*/) -{ - return false; -} - -css::uno::Sequence<OUString> TransferableHelper::TerminateListener::getSupportedServiceNames() -{ - return css::uno::Sequence<OUString>(); -} - - -Any SAL_CALL TransferableHelper::getTransferData( const DataFlavor& rFlavor ) -{ - return getTransferData2(rFlavor, OUString()); -} - -Any SAL_CALL TransferableHelper::getTransferData2( const DataFlavor& rFlavor, const OUString& rDestDoc ) -{ - if( !maAny.hasValue() || maFormats.empty() || ( maLastFormat != rFlavor.MimeType ) ) - { - const SolarMutexGuard aGuard; - - maLastFormat = rFlavor.MimeType; - maAny = Any(); - - try - { - DataFlavor aSubstFlavor; - bool bDone = false; - - // add formats if not already done - if (maFormats.empty()) - AddSupportedFormats(); - - // check alien formats first and try to get a substitution format - if( SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aSubstFlavor ) && - TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) ) - { - GetData(aSubstFlavor, rDestDoc); - bDone = maAny.hasValue(); - } - else if(SotExchange::GetFormatDataFlavor(SotClipboardFormatId::BMP, aSubstFlavor ) - && TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) - && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::BITMAP, aSubstFlavor)) - { - GetData(aSubstFlavor, rDestDoc); - bDone = true; - } - else if( SotExchange::GetFormatDataFlavor( SotClipboardFormatId::EMF, aSubstFlavor ) && - TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) && - SotExchange::GetFormatDataFlavor( SotClipboardFormatId::GDIMETAFILE, aSubstFlavor ) ) - { - GetData(aSubstFlavor, rDestDoc); - - if( maAny.hasValue() ) - { - Sequence< sal_Int8 > aSeq; - - if( maAny >>= aSeq ) - { - std::unique_ptr<SvMemoryStream> pSrcStm(new SvMemoryStream( aSeq.getArray(), aSeq.getLength(), StreamMode::WRITE | StreamMode::TRUNC )); - GDIMetaFile aMtf; - - ReadGDIMetaFile( *pSrcStm, aMtf ); - pSrcStm.reset(); - - Graphic aGraphic( aMtf ); - SvMemoryStream aDstStm( 65535, 65535 ); - - if( GraphicConverter::Export( aDstStm, aGraphic, ConvertDataFormat::EMF ) == ERRCODE_NONE ) - { - maAny <<= ( aSeq = Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aDstStm.GetData() ), - aDstStm.TellEnd() ) ); - bDone = true; - } - } - } - } - else if( SotExchange::GetFormatDataFlavor( SotClipboardFormatId::WMF, aSubstFlavor ) && - TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) && - SotExchange::GetFormatDataFlavor( SotClipboardFormatId::GDIMETAFILE, aSubstFlavor ) ) - { - GetData(aSubstFlavor, rDestDoc); - - if( maAny.hasValue() ) - { - Sequence< sal_Int8 > aSeq; - - if( maAny >>= aSeq ) - { - std::unique_ptr<SvMemoryStream> pSrcStm(new SvMemoryStream( aSeq.getArray(), aSeq.getLength(), StreamMode::WRITE | StreamMode::TRUNC )); - GDIMetaFile aMtf; - - ReadGDIMetaFile( *pSrcStm, aMtf ); - pSrcStm.reset(); - - SvMemoryStream aDstStm( 65535, 65535 ); - - // taking wmf without file header - if ( ConvertGDIMetaFileToWMF( aMtf, aDstStm, nullptr, false ) ) - { - maAny <<= ( aSeq = Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aDstStm.GetData() ), - aDstStm.TellEnd() ) ); - bDone = true; - } - } - } - } - - // reset Any if substitute doesn't work - if( !bDone && maAny.hasValue() ) - maAny = Any(); - - // if any is not yet filled, use standard format - if( !maAny.hasValue() ) - GetData(rFlavor, rDestDoc); - } - catch( const css::uno::Exception& ) - { - } - - if( !maAny.hasValue() ) - throw UnsupportedFlavorException(); - } - - return maAny; -} - - -Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() -{ - const SolarMutexGuard aGuard; - - try - { - if(maFormats.empty()) - AddSupportedFormats(); - } - catch( const css::uno::Exception& ) - { - } - - return comphelper::containerToSequence<DataFlavor>(maFormats); -} - - -sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& rFlavor ) -{ - const SolarMutexGuard aGuard; - - try - { - if (maFormats.empty()) - AddSupportedFormats(); - } - catch( const css::uno::Exception& ) - { - } - - for (auto const& format : maFormats) - { - if( TransferableDataHelper::IsEqual( format, rFlavor ) ) - { - return true; - } - } - - return false; -} - - -void SAL_CALL TransferableHelper::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) -{ - const SolarMutexGuard aGuard; - - try - { - if( mxTerminateListener.is() ) - { - Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() ); - xDesktop->removeTerminateListener( mxTerminateListener ); - - mxTerminateListener.clear(); - } - - ObjectReleased(); - } - catch( const css::uno::Exception& ) - { - } -} - - -void SAL_CALL TransferableHelper::disposing( const EventObject& ) -{ -} - - -void SAL_CALL TransferableHelper::dragDropEnd( const DragSourceDropEvent& rDSDE ) -{ - const SolarMutexGuard aGuard; - - try - { - DragFinished( rDSDE.DropSuccess ? ( rDSDE.DropAction & ~DNDConstants::ACTION_DEFAULT ) : DNDConstants::ACTION_NONE ); - ObjectReleased(); - } - catch( const css::uno::Exception& ) - { - } -} - - -void SAL_CALL TransferableHelper::dragEnter( const DragSourceDragEvent& ) -{ -} - - -void SAL_CALL TransferableHelper::dragExit( const DragSourceEvent& ) -{ -} - - -void SAL_CALL TransferableHelper::dragOver( const DragSourceDragEvent& ) -{ -} - - -void SAL_CALL TransferableHelper::dropActionChanged( const DragSourceDragEvent& ) -{ -} - - -sal_Int64 SAL_CALL TransferableHelper::getSomething( const Sequence< sal_Int8 >& rId ) -{ - sal_Int64 nRet; - - if( ( rId.getLength() == 16 ) && - ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ) - { - nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); - } - else - nRet = 0; - - return nRet; -} - - -void TransferableHelper::ImplFlush() -{ - if( !mxClipboard.is() ) - return; - - Reference< XFlushableClipboard > xFlushableClipboard( mxClipboard, UNO_QUERY ); - SolarMutexReleaser aReleaser; - - try - { - if( xFlushableClipboard.is() ) - xFlushableClipboard->flushClipboard(); - } - catch( const css::uno::Exception& ) - { - OSL_FAIL( "Could not flush clipboard" ); - } -} - - -void TransferableHelper::AddFormat( SotClipboardFormatId nFormat ) -{ - DataFlavor aFlavor; - - if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) ) - AddFormat( aFlavor ); -} - - -void TransferableHelper::AddFormat( const DataFlavor& rFlavor ) -{ - bool bAdd = true; - - for (auto & format : maFormats) - { - if( TransferableDataHelper::IsEqual( format, rFlavor ) ) - { - // update MimeType for SotClipboardFormatId::OBJECTDESCRIPTOR in every case - if ((SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId) && mxObjDesc) - { - DataFlavor aObjDescFlavor; - - SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDescFlavor ); - format.MimeType = aObjDescFlavor.MimeType; - format.MimeType += ::ImplGetParameterString(*mxObjDesc); - } - - bAdd = false; - break; - } - } - - if( !bAdd ) - return; - - DataFlavorEx aFlavorEx; - - aFlavorEx.MimeType = rFlavor.MimeType; - aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName; - aFlavorEx.DataType = rFlavor.DataType; - aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor ); - - if ((SotClipboardFormatId::OBJECTDESCRIPTOR == aFlavorEx.mnSotId) && mxObjDesc) - aFlavorEx.MimeType += ::ImplGetParameterString(*mxObjDesc); - - maFormats.push_back(aFlavorEx); - - if( SotClipboardFormatId::BITMAP == aFlavorEx.mnSotId ) - { - AddFormat( SotClipboardFormatId::PNG ); - AddFormat( SotClipboardFormatId::BMP ); - } - else if( SotClipboardFormatId::GDIMETAFILE == aFlavorEx.mnSotId ) - { - AddFormat( SotClipboardFormatId::EMF ); - AddFormat( SotClipboardFormatId::WMF ); - } -} - - -void TransferableHelper::RemoveFormat( SotClipboardFormatId nFormat ) -{ - DataFlavor aFlavor; - - if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) ) - RemoveFormat( aFlavor ); -} - - -void TransferableHelper::RemoveFormat( const DataFlavor& rFlavor ) -{ - DataFlavorExVector::iterator aIter(maFormats.begin()); - - while (aIter != maFormats.end()) - { - if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) ) - aIter = maFormats.erase(aIter); - else - ++aIter; - } -} - - -bool TransferableHelper::HasFormat( SotClipboardFormatId nFormat ) -{ - return std::any_of(maFormats.begin(), maFormats.end(), - [&](const DataFlavorEx& data) { return data.mnSotId == nFormat; }); -} - - -void TransferableHelper::ClearFormats() -{ - maFormats.clear(); - maAny.clear(); -} - - -bool TransferableHelper::SetAny( const Any& rAny ) -{ - maAny = rAny; - return maAny.hasValue(); -} - - -bool TransferableHelper::SetString( const OUString& rString, const DataFlavor& rFlavor ) -{ - DataFlavor aFileFlavor; - - if( !rString.isEmpty() && - SotExchange::GetFormatDataFlavor( SotClipboardFormatId::SIMPLE_FILE, aFileFlavor ) && - TransferableDataHelper::IsEqual( aFileFlavor, rFlavor ) ) - { - const OString aByteStr(OUStringToOString(rString, osl_getThreadTextEncoding())); - Sequence< sal_Int8 > aSeq( aByteStr.getLength() + 1 ); - - memcpy( aSeq.getArray(), aByteStr.getStr(), aByteStr.getLength() ); - aSeq[ aByteStr.getLength() ] = 0; - maAny <<= aSeq; - } - else - maAny <<= rString; - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetBitmapEx( const BitmapEx& rBitmapEx, const DataFlavor& rFlavor ) -{ - if( !rBitmapEx.IsEmpty() ) - { - SvMemoryStream aMemStm( 65535, 65535 ); - - if(rFlavor.MimeType.equalsIgnoreAsciiCase("image/png")) - { - // write a PNG - vcl::PNGWriter aPNGWriter(rBitmapEx); - - aPNGWriter.Write(aMemStm); - } - else - { - const Bitmap aBitmap(rBitmapEx.GetBitmap()); - - // explicitly use Bitmap::Write with bCompressed = sal_False and bFileHeader = sal_True - WriteDIB(aBitmap, aMemStm, false, true); - } - - maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.TellEnd() ); - } - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetGDIMetaFile( const GDIMetaFile& rMtf ) -{ - if( rMtf.GetActionSize() ) - { - SvMemoryStream aMemStm( 65535, 65535 ); - - const_cast<GDIMetaFile&>(rMtf).Write( aMemStm ); - maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.TellEnd() ); - } - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetGraphic( const Graphic& rGraphic ) -{ - if( rGraphic.GetType() != GraphicType::NONE ) - { - SvMemoryStream aMemStm( 65535, 65535 ); - - aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); - aMemStm.SetCompressMode( SvStreamCompressFlags::NATIVE ); - WriteGraphic( aMemStm, rGraphic ); - maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); - } - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetImageMap( const ImageMap& rIMap ) -{ - SvMemoryStream aMemStm( 8192, 8192 ); - - aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); - rIMap.Write( aMemStm ); - maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetTransferableObjectDescriptor( const TransferableObjectDescriptor& rDesc ) -{ - PrepareOLE( rDesc ); - - SvMemoryStream aMemStm( 1024, 1024 ); - - WriteTransferableObjectDescriptor( aMemStm, rDesc ); - maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() ); - - return maAny.hasValue(); - } - - -bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk, - const css::datatransfer::DataFlavor& rFlavor ) -{ - rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding(); - - switch( SotExchange::GetFormat( rFlavor ) ) - { - case SotClipboardFormatId::SOLK: - { - OString sURL(OUStringToOString(rBmk.GetURL(), eSysCSet)); - OString sDesc(OUStringToOString(rBmk.GetDescription(), eSysCSet)); - OStringBuffer sOut; - sOut.append(sURL.getLength()); - sOut.append('@').append(sURL); - sOut.append(sDesc.getLength()); - sOut.append('@').append(sDesc); - - Sequence< sal_Int8 > aSeq(sOut.getLength()); - memcpy(aSeq.getArray(), sOut.getStr(), sOut.getLength()); - maAny <<= aSeq; - } - break; - - case SotClipboardFormatId::STRING: - maAny <<= rBmk.GetURL(); - break; - - case SotClipboardFormatId::UNIFORMRESOURCELOCATOR: - { - OString sURL(OUStringToOString(rBmk.GetURL(), eSysCSet)); - Sequence< sal_Int8 > aSeq( sURL.getLength() ); - memcpy( aSeq.getArray(), sURL.getStr(), sURL.getLength() ); - maAny <<= aSeq; - } - break; - - case SotClipboardFormatId::NETSCAPE_BOOKMARK: - { - Sequence< sal_Int8 > aSeq( 2048 ); - - memset( aSeq.getArray(), 0, 2048 ); - strcpy( reinterpret_cast< char* >( aSeq.getArray() ), OUStringToOString(rBmk.GetURL(), eSysCSet).getStr() ); - strcpy( reinterpret_cast< char* >( aSeq.getArray() ) + 1024, OUStringToOString(rBmk.GetDescription(), eSysCSet).getStr() ); - - maAny <<= aSeq; - } - break; - -#ifdef _WIN32 - case SotClipboardFormatId::FILEGRPDESCRIPTOR: - { - Sequence< sal_Int8 > aSeq( sizeof( FILEGROUPDESCRIPTOR ) ); - FILEGROUPDESCRIPTOR* pFDesc = reinterpret_cast<FILEGROUPDESCRIPTOR*>(aSeq.getArray()); - FILEDESCRIPTOR& rFDesc1 = pFDesc->fgd[ 0 ]; - - pFDesc->cItems = 1; - memset( &rFDesc1, 0, sizeof( FILEDESCRIPTOR ) ); - rFDesc1.dwFlags = FD_LINKUI; - - OStringBuffer aStr(OUStringToOString( - rBmk.GetDescription(), eSysCSet)); - for( sal_Int32 nChar = 0; nChar < aStr.getLength(); ++nChar ) - if( strchr( "\\/:*?\"<>|", aStr[nChar] ) ) - aStr.remove(nChar--, 1); - - aStr.insert(0, "Shortcut to "); - aStr.append(".URL"); - strcpy( rFDesc1.cFileName, aStr.getStr() ); - - maAny <<= aSeq; - } - break; - - case SotClipboardFormatId::FILECONTENT: - { - OUString aStr( "[InternetShortcut]\x0aURL=" ); - maAny <<= ( aStr += rBmk.GetURL() ); - } - break; -#endif - - default: - break; - } - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetINetImage( const INetImage& rINtImg, - const css::datatransfer::DataFlavor& rFlavor ) -{ - SvMemoryStream aMemStm( 1024, 1024 ); - - aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); - rINtImg.Write( aMemStm, SotExchange::GetFormat( rFlavor ) ); - - maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); - - return maAny.hasValue(); -} - - -bool TransferableHelper::SetObject( void* pUserObject, sal_uInt32 nUserObjectId, const DataFlavor& rFlavor ) -{ - tools::SvRef<SotStorageStream> xStm( new SotStorageStream( OUString() ) ); - - xStm->SetVersion( SOFFICE_FILEFORMAT_50 ); - - if( pUserObject && WriteObject( xStm, pUserObject, nUserObjectId, rFlavor ) ) - { - const sal_uInt32 nLen = xStm->TellEnd(); - Sequence< sal_Int8 > aSeq( nLen ); - - xStm->Seek( STREAM_SEEK_TO_BEGIN ); - xStm->ReadBytes(aSeq.getArray(), nLen); - - if( nLen && ( SotExchange::GetFormat( rFlavor ) == SotClipboardFormatId::STRING ) ) - { - //JP 24.7.2001: as I know was this only for the writer application and this - // writes now UTF16 format into the stream - //JP 6.8.2001: and now it writes UTF8 because then exist no problem with - // little / big endians! - Bug 88121 - maAny <<= OUString( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), nLen - 1, RTL_TEXTENCODING_UTF8 ); - } - else - maAny <<= aSeq; - } - - return maAny.hasValue(); -} - - -bool TransferableHelper::WriteObject( tools::SvRef<SotStorageStream>&, void*, sal_uInt32, const DataFlavor& ) -{ - OSL_FAIL( "TransferableHelper::WriteObject( ... ) not implemented" ); - return false; -} - - -void TransferableHelper::DragFinished( sal_Int8 ) -{ -} - - -void TransferableHelper::ObjectReleased() -{ -} - - -void TransferableHelper::PrepareOLE( const TransferableObjectDescriptor& rObjDesc ) -{ - mxObjDesc.reset(new TransferableObjectDescriptor(rObjDesc)); - - if( HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ) ) - AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); -} - - -void TransferableHelper::CopyToClipboard( vcl::Window *pWindow ) const -{ - DBG_ASSERT( pWindow, "Window pointer is NULL" ); - Reference< XClipboard > xClipboard; - - if( pWindow ) - xClipboard = pWindow->GetClipboard(); - - if( xClipboard.is() ) - mxClipboard = xClipboard; - - if( !(mxClipboard.is() && !mxTerminateListener.is()) ) - return; - - try - { - TransferableHelper* pThis = const_cast< TransferableHelper* >( this ); - Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() ); - xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) ); - - mxClipboard->setContents( pThis, pThis ); - } - catch( const css::uno::Exception& ) - { - } -} - - -void TransferableHelper::CopyToSelection( vcl::Window *pWindow ) const -{ - DBG_ASSERT( pWindow, "Window pointer is NULL" ); - Reference< XClipboard > xSelection; - - if( pWindow ) - xSelection = pWindow->GetPrimarySelection(); - - if( !(xSelection.is() && !mxTerminateListener.is()) ) - return; - - try - { - TransferableHelper* pThis = const_cast< TransferableHelper* >( this ); - Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() ); - xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) ); - - xSelection->setContents( pThis, pThis ); - } - catch( const css::uno::Exception& ) - { - } -} - - -void TransferableHelper::StartDrag( vcl::Window* pWindow, sal_Int8 nDnDSourceActions, - sal_Int32 nDnDPointer ) - -{ - DBG_ASSERT( pWindow, "Window pointer is NULL" ); - Reference< XDragSource > xDragSource( pWindow->GetDragSource() ); - - if( !xDragSource.is() ) - return; - - /* - * #96792# release mouse before actually starting DnD. - * This is necessary for the X11 DnD implementation to work. - */ - if( pWindow->IsMouseCaptured() ) - pWindow->ReleaseMouse(); - - const Point aPt( pWindow->GetPointerPosPixel() ); - - // On Mac OS X we are forced to execute 'startDrag' synchronously - // contrary to the XDragSource interface specification because - // we can receive drag events from the system only in the main - // thread -#if !defined(MACOSX) - SolarMutexReleaser aReleaser; -#endif - - try - { - DragGestureEvent aEvt; - aEvt.DragAction = DNDConstants::ACTION_COPY; - aEvt.DragOriginX = aPt.X(); - aEvt.DragOriginY = aPt.Y(); - aEvt.DragSource = xDragSource; - - xDragSource->startDrag( aEvt, nDnDSourceActions, nDnDPointer, DND_IMAGE_NONE, this, this ); - } - catch( const css::uno::Exception& ) - { - } -} - -void TransferableHelper::ClearSelection( vcl::Window *pWindow ) -{ - DBG_ASSERT( pWindow, "Window pointer is NULL" ); - Reference< XClipboard > xSelection( pWindow->GetPrimarySelection() ); - - if( xSelection.is() ) - xSelection->setContents( nullptr, nullptr ); -} - -namespace -{ - class theTransferableHelperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theTransferableHelperUnoTunnelId > {}; -} - -const Sequence< sal_Int8 >& TransferableHelper::getUnoTunnelId() -{ - return theTransferableHelperUnoTunnelId::get().getSeq(); -} - -class TransferableClipboardNotifier : public ::cppu::WeakImplHelper< XClipboardListener > -{ -private: - ::osl::Mutex& mrMutex; - Reference< XClipboardNotifier > mxNotifier; - TransferableDataHelper* mpListener; - -protected: - // XClipboardListener - virtual void SAL_CALL changedContents( const clipboard::ClipboardEvent& event ) override; - - // XEventListener - virtual void SAL_CALL disposing( const EventObject& Source ) override; - -public: - TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex ); - - /// determines whether we're currently listening - bool isListening() const { return mpListener != nullptr; } - - /// makes the instance non-functional - void dispose(); -}; - - -TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex ) - :mrMutex( _rMutex ) - ,mxNotifier( _rxClipboard, UNO_QUERY ) - ,mpListener( &_rListener ) -{ - osl_atomic_increment( &m_refCount ); - { - if ( mxNotifier.is() ) - mxNotifier->addClipboardListener( this ); - else - // born dead - mpListener = nullptr; - } - osl_atomic_decrement( &m_refCount ); -} - - -void SAL_CALL TransferableClipboardNotifier::changedContents( const clipboard::ClipboardEvent& event ) -{ - SolarMutexGuard aSolarGuard; - // the SolarMutex here is necessary, since - // - we cannot call mpListener without our own mutex locked - // - Rebind respectively InitFormats (called by Rebind) will - // try to lock the SolarMutex, too - ::osl::MutexGuard aGuard( mrMutex ); - if( mpListener ) - mpListener->Rebind( event.Contents ); -} - - -void SAL_CALL TransferableClipboardNotifier::disposing( const EventObject& ) -{ - // clipboard is being disposed. Hmm. Okay, become disfunctional myself. - dispose(); -} - - -void TransferableClipboardNotifier::dispose() -{ - ::osl::MutexGuard aGuard( mrMutex ); - - Reference< XClipboardListener > xKeepMeAlive( this ); - - if ( mxNotifier.is() ) - mxNotifier->removeClipboardListener( this ); - mxNotifier.clear(); - - mpListener = nullptr; -} - -struct TransferableDataHelper_Impl -{ - ::osl::Mutex maMutex; - rtl::Reference<TransferableClipboardNotifier> mxClipboardListener; - - TransferableDataHelper_Impl() - { - } -}; - -TransferableDataHelper::TransferableDataHelper() - : mxObjDesc(new TransferableObjectDescriptor) - , mxImpl(new TransferableDataHelper_Impl) -{ -} - -TransferableDataHelper::TransferableDataHelper(const Reference< css::datatransfer::XTransferable >& rxTransferable) - : mxTransfer(rxTransferable) - , mxObjDesc(new TransferableObjectDescriptor) - , mxImpl(new TransferableDataHelper_Impl) -{ - InitFormats(); -} - -TransferableDataHelper::TransferableDataHelper(const TransferableDataHelper& rDataHelper) - : mxTransfer(rDataHelper.mxTransfer) - , mxClipboard(rDataHelper.mxClipboard) - , maFormats(rDataHelper.maFormats) - , mxObjDesc(new TransferableObjectDescriptor(*rDataHelper.mxObjDesc)) - , mxImpl(new TransferableDataHelper_Impl) -{ -} - -TransferableDataHelper::TransferableDataHelper(TransferableDataHelper&& rDataHelper) - : mxTransfer(std::move(rDataHelper.mxTransfer)) - , mxClipboard(std::move(rDataHelper.mxClipboard)) - , maFormats(std::move(rDataHelper.maFormats)) - , mxObjDesc(std::move(rDataHelper.mxObjDesc)) - , mxImpl(new TransferableDataHelper_Impl) -{ -} - -TransferableDataHelper& TransferableDataHelper::operator=( const TransferableDataHelper& rDataHelper ) -{ - if ( this != &rDataHelper ) - { - ::osl::MutexGuard aGuard(mxImpl->maMutex); - - const bool bWasClipboardListening = mxImpl->mxClipboardListener.is(); - - if (bWasClipboardListening) - StopClipboardListening(); - - mxTransfer = rDataHelper.mxTransfer; - maFormats = rDataHelper.maFormats; - mxObjDesc.reset(new TransferableObjectDescriptor(*rDataHelper.mxObjDesc)); - mxClipboard = rDataHelper.mxClipboard; - - if (bWasClipboardListening) - StartClipboardListening(); - } - - return *this; -} - -TransferableDataHelper& TransferableDataHelper::operator=(TransferableDataHelper&& rDataHelper) -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - - const bool bWasClipboardListening = mxImpl->mxClipboardListener.is(); - - if (bWasClipboardListening) - StopClipboardListening(); - - mxTransfer = std::move(rDataHelper.mxTransfer); - maFormats = std::move(rDataHelper.maFormats); - mxObjDesc = std::move(rDataHelper.mxObjDesc); - mxClipboard = std::move(rDataHelper.mxClipboard); - - if (bWasClipboardListening) - StartClipboardListening(); - - return *this; -} - -TransferableDataHelper::~TransferableDataHelper() -{ - StopClipboardListening( ); - { - ::osl::MutexGuard aGuard(mxImpl->maMutex); - maFormats.clear(); - mxObjDesc.reset(); - } -} - -void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor >& rDataFlavorSeq, - DataFlavorExVector& rDataFlavorExVector ) -{ - try - { - Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - Reference< XMimeContentTypeFactory > xMimeFact = MimeContentTypeFactory::create( xContext ); - DataFlavorEx aFlavorEx; - const OUString aCharsetStr( "charset" ); - - - for (auto const& rFlavor : rDataFlavorSeq) - { - Reference< XMimeContentType > xMimeType; - - try - { - if( !rFlavor.MimeType.isEmpty() ) - xMimeType = xMimeFact->createMimeContentType( rFlavor.MimeType ); - } - catch( const css::uno::Exception& ) - { - } - - aFlavorEx.MimeType = rFlavor.MimeType; - aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName; - aFlavorEx.DataType = rFlavor.DataType; - aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor ); - - rDataFlavorExVector.push_back( aFlavorEx ); - - // add additional formats for special mime types - if(SotClipboardFormatId::BMP == aFlavorEx.mnSotId || SotClipboardFormatId::PNG == aFlavorEx.mnSotId) - { - if( SotExchange::GetFormatDataFlavor( SotClipboardFormatId::BITMAP, aFlavorEx ) ) - { - aFlavorEx.mnSotId = SotClipboardFormatId::BITMAP; - rDataFlavorExVector.push_back( aFlavorEx ); - } - } - else if( SotClipboardFormatId::WMF == aFlavorEx.mnSotId || SotClipboardFormatId::EMF == aFlavorEx.mnSotId ) - { - if( SotExchange::GetFormatDataFlavor( SotClipboardFormatId::GDIMETAFILE, aFlavorEx ) ) - { - aFlavorEx.mnSotId = SotClipboardFormatId::GDIMETAFILE; - rDataFlavorExVector.push_back( aFlavorEx ); - } - } - else if ( SotClipboardFormatId::HTML_SIMPLE == aFlavorEx.mnSotId ) - { - // #104735# HTML_SIMPLE may also be inserted without comments - aFlavorEx.mnSotId = SotClipboardFormatId::HTML_NO_COMMENT; - rDataFlavorExVector.push_back( aFlavorEx ); - } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( "text/plain" ) ) - { - // add, if it is a UTF-8 byte buffer - if( xMimeType->hasParameter( aCharsetStr ) ) - { - if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( "unicode" ) || - xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( "utf-16" ) ) - { - rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::STRING; - - } - } - } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( "text/rtf" ) ) - { - rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::RTF; - } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( "text/richtext" ) ) - { - rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::RICHTEXT; - } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( "text/html" ) ) - - { - rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::HTML; - } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( "text/uri-list" ) ) - { - rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::FILE_LIST; - } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( "application/x-openoffice-objectdescriptor-xml" ) ) - { - rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::OBJECTDESCRIPTOR; - } - } - } - catch( const css::uno::Exception& ) - { - } -} - -void TransferableDataHelper::InitFormats() -{ - SolarMutexGuard aSolarGuard; - ::osl::MutexGuard aGuard(mxImpl->maMutex); - - maFormats.clear(); - mxObjDesc.reset(new TransferableObjectDescriptor); - - if( !mxTransfer.is() ) - return; - - TransferableDataHelper::FillDataFlavorExVector(mxTransfer->getTransferDataFlavors(), maFormats); - - for (auto const& format : maFormats) - { - if( SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId ) - { - ImplSetParameterString(*mxObjDesc, format); - break; - } - } -} - - -bool TransferableDataHelper::HasFormat( SotClipboardFormatId nFormat ) const -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - return std::any_of(maFormats.begin(), maFormats.end(), - [&](const DataFlavorEx& data) { return data.mnSotId == nFormat; }); -} - -bool TransferableDataHelper::HasFormat( const DataFlavor& rFlavor ) const -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - for (auto const& format : maFormats) - { - if( TransferableDataHelper::IsEqual( rFlavor, format ) ) - return true; - } - - return false; -} - -sal_uInt32 TransferableDataHelper::GetFormatCount() const -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - return maFormats.size(); -} - -SotClipboardFormatId TransferableDataHelper::GetFormat( sal_uInt32 nFormat ) const -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - DBG_ASSERT(nFormat < maFormats.size(), "TransferableDataHelper::GetFormat: invalid format index"); - return( ( nFormat < maFormats.size() ) ? (maFormats)[ nFormat ].mnSotId : SotClipboardFormatId::NONE ); -} - -DataFlavor TransferableDataHelper::GetFormatDataFlavor( sal_uInt32 nFormat ) const -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - DBG_ASSERT(nFormat < maFormats.size(), "TransferableDataHelper::GetFormat: invalid format index"); - - DataFlavor aRet; - - if (nFormat < maFormats.size()) - aRet = maFormats[nFormat]; - - return aRet; -} - - -Reference< XTransferable > TransferableDataHelper::GetXTransferable() const -{ - Reference< XTransferable > xRet; - - if( mxTransfer.is() ) - { - try - { - xRet = mxTransfer; - - // do a dummy call to check, if this interface is valid (nasty) - xRet->getTransferDataFlavors(); - - } - catch( const css::uno::Exception& ) - { - xRet.clear(); - } - } - - return xRet; -} - - -Any TransferableDataHelper::GetAny( SotClipboardFormatId nFormat, const OUString& rDestDoc ) const -{ - Any aReturn; - - DataFlavor aFlavor; - if ( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) ) - aReturn = GetAny(aFlavor, rDestDoc); - - return aReturn; -} - -Any TransferableDataHelper::GetAny( const DataFlavor& rFlavor, const OUString& rDestDoc ) const -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - Any aRet; - - try - { - if( mxTransfer.is() ) - { - const SotClipboardFormatId nRequestFormat = SotExchange::GetFormat( rFlavor ); - - Reference<css::datatransfer::XTransferable2> xTransfer2(mxTransfer, UNO_QUERY); - - if( nRequestFormat != SotClipboardFormatId::NONE ) - { - // try to get alien format first - for (auto const& format : maFormats) - { - if( ( nRequestFormat == format.mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( format.MimeType ) ) - { - if (xTransfer2.is()) - aRet = xTransfer2->getTransferData2(format, rDestDoc); - else - aRet = mxTransfer->getTransferData(format); - } - - if( aRet.hasValue() ) - break; - } - } - - if( !aRet.hasValue() ) - { - if (xTransfer2.is()) - aRet = xTransfer2->getTransferData2(rFlavor, rDestDoc); - else - aRet = mxTransfer->getTransferData(rFlavor); - } - } - } - catch( const css::uno::Exception& ) - { - } - - return aRet; -} - - -bool TransferableDataHelper::GetString( SotClipboardFormatId nFormat, OUString& rStr ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetString( aFlavor, rStr ) ); -} - - -bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, OUString& rStr ) -{ - Any aAny = GetAny(rFlavor, OUString()); - bool bRet = false; - - if( aAny.hasValue() ) - { - OUString aOUString; - Sequence< sal_Int8 > aSeq; - - if( aAny >>= aOUString ) - { - rStr = aOUString; - bRet = true; - } - else if( aAny >>= aSeq ) - { - - const sal_Char* pChars = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ); - sal_Int32 nLen = aSeq.getLength(); - - //JP 10.10.2001: 92930 - don't copy the last zero character into the string. - //DVO 2002-05-27: strip _all_ trailing zeros - while( nLen && ( 0 == *( pChars + nLen - 1 ) ) ) - --nLen; - - rStr = OUString( pChars, nLen, osl_getThreadTextEncoding() ); - bRet = true; - } - } - - return bRet; -} - - -bool TransferableDataHelper::GetBitmapEx( SotClipboardFormatId nFormat, BitmapEx& rBmpEx ) -{ - if(SotClipboardFormatId::BITMAP == nFormat) - { - // try to get PNG first - DataFlavor aFlavor; - - if(SotExchange::GetFormatDataFlavor(SotClipboardFormatId::PNG, aFlavor)) - { - if(GetBitmapEx(aFlavor, rBmpEx)) - { - return true; - } - } - } - - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetBitmapEx( aFlavor, rBmpEx ) ); -} - - -bool TransferableDataHelper::GetBitmapEx( const DataFlavor& rFlavor, BitmapEx& rBmpEx ) -{ - tools::SvRef<SotStorageStream> xStm; - DataFlavor aSubstFlavor; - bool bRet(GetSotStorageStream(rFlavor, xStm)); - bool bSuppressPNG(false); // #122982# If PNG stream not accessed, but BMP one, suppress trying to load PNG - bool bSuppressJPEG(false); - - if(!bRet && HasFormat(SotClipboardFormatId::PNG) && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::PNG, aSubstFlavor)) - { - // when no direct success, try if PNG is available - bRet = GetSotStorageStream(aSubstFlavor, xStm); - bSuppressJPEG = bRet; - } - - if(!bRet && HasFormat(SotClipboardFormatId::JPEG) && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::JPEG, aSubstFlavor)) - { - bRet = GetSotStorageStream(aSubstFlavor, xStm); - bSuppressPNG = bRet; - } - - if(!bRet && HasFormat(SotClipboardFormatId::BMP) && SotExchange::GetFormatDataFlavor(SotClipboardFormatId::BMP, aSubstFlavor)) - { - // when no direct success, try if BMP is available - bRet = GetSotStorageStream(aSubstFlavor, xStm); - bSuppressPNG = bRet; - bSuppressJPEG = bRet; - } - - if(bRet) - { - if(!bSuppressPNG && rFlavor.MimeType.equalsIgnoreAsciiCase("image/png")) - { - // it's a PNG, import to BitmapEx - vcl::PNGReader aPNGReader(*xStm); - - rBmpEx = aPNGReader.Read(); - } - else if(!bSuppressJPEG && rFlavor.MimeType.equalsIgnoreAsciiCase("image/jpeg")) - { - // it's a JPEG, import to BitmapEx - GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); - Graphic aGraphic; - if (rFilter.ImportGraphic(aGraphic, "", *xStm) == ERRCODE_NONE) - rBmpEx = aGraphic.GetBitmapEx(); - } - - if(rBmpEx.IsEmpty()) - { - Bitmap aBitmap; - AlphaMask aMask; - - // explicitly use Bitmap::Read with bFileHeader = sal_True - // #i124085# keep DIBV5 for read from clipboard, but should not happen - ReadDIBV5(aBitmap, aMask, *xStm); - - if(aMask.GetBitmap().IsEmpty()) - { - rBmpEx = aBitmap; - } - else - { - rBmpEx = BitmapEx(aBitmap, aMask); - } - } - - bRet = (ERRCODE_NONE == xStm->GetError() && !rBmpEx.IsEmpty()); - - /* SJ: #110748# At the moment we are having problems with DDB inserted as DIB. The - problem is, that some graphics are inserted much too big because the nXPelsPerMeter - and nYPelsPerMeter of the bitmap fileheader isn't including the correct value. - Due to this reason the following code assumes that bitmaps with a logical size - greater than 50 cm aren't having the correct mapmode set. - - The following code should be removed if DDBs and DIBs are supported via clipboard - properly. - */ - if(bRet) - { - const MapMode aMapMode(rBmpEx.GetPrefMapMode()); - - if(MapUnit::MapPixel != aMapMode.GetMapUnit()) - { - const Size aSize(OutputDevice::LogicToLogic(rBmpEx.GetPrefSize(), aMapMode, MapMode(MapUnit::Map100thMM))); - - // #i122388# This wrongly corrects in the given case; changing from 5000 100th mm to - // the described 50 cm (which is 50000 100th mm) - if((aSize.Width() > 50000) || (aSize.Height() > 50000)) - { - rBmpEx.SetPrefMapMode(MapMode(MapUnit::MapPixel)); - - // #i122388# also adapt size by applying the mew MapMode - const Size aNewSize(OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapPixel))); - rBmpEx.SetPrefSize(aNewSize); - } - } - } - } - - return bRet; -} - - -bool TransferableDataHelper::GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile& rMtf, size_t nMaxActions) -{ - DataFlavor aFlavor; - return SotExchange::GetFormatDataFlavor(nFormat, aFlavor) && - GetGDIMetaFile(aFlavor, rMtf) && - (nMaxActions == 0 || rMtf.GetActionSize() < nMaxActions); -} - - -bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaFile& rMtf ) -{ - tools::SvRef<SotStorageStream> xStm; - DataFlavor aSubstFlavor; - bool bRet = false; - - if( GetSotStorageStream( rFlavor, xStm ) ) - { - ReadGDIMetaFile( *xStm, rMtf ); - bRet = ( xStm->GetError() == ERRCODE_NONE ); - } - - if( !bRet && - HasFormat( SotClipboardFormatId::EMF ) && - SotExchange::GetFormatDataFlavor( SotClipboardFormatId::EMF, aSubstFlavor ) && - GetSotStorageStream( aSubstFlavor, xStm ) ) - { - Graphic aGraphic; - - if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE ) - { - rMtf = aGraphic.GetGDIMetaFile(); - bRet = true; - } - } - - if( !bRet && - HasFormat( SotClipboardFormatId::WMF ) && - SotExchange::GetFormatDataFlavor( SotClipboardFormatId::WMF, aSubstFlavor ) && - GetSotStorageStream( aSubstFlavor, xStm ) ) - { - Graphic aGraphic; - - if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE ) - { - rMtf = aGraphic.GetGDIMetaFile(); - bRet = true; - } - } - - return bRet; -} - - -bool TransferableDataHelper::GetGraphic( SotClipboardFormatId nFormat, Graphic& rGraphic ) -{ - if(SotClipboardFormatId::BITMAP == nFormat) - { - // try to get PNG first - DataFlavor aFlavor; - - if(SotExchange::GetFormatDataFlavor(SotClipboardFormatId::PNG, aFlavor)) - { - if(GetGraphic(aFlavor, rGraphic)) - { - return true; - } - } - } - - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGraphic( aFlavor, rGraphic ) ); -} - - -bool TransferableDataHelper::GetGraphic( const css::datatransfer::DataFlavor& rFlavor, Graphic& rGraphic ) -{ - DataFlavor aFlavor; - bool bRet = false; - - if(SotExchange::GetFormatDataFlavor(SotClipboardFormatId::PNG, aFlavor) && - TransferableDataHelper::IsEqual(aFlavor, rFlavor)) - { - // try to get PNG first - BitmapEx aBmpEx; - - bRet = GetBitmapEx( aFlavor, aBmpEx ); - if( bRet ) - rGraphic = aBmpEx; - } - else if (SotExchange::GetFormatDataFlavor(SotClipboardFormatId::JPEG, aFlavor) && TransferableDataHelper::IsEqual(aFlavor, rFlavor)) - { - BitmapEx aBitmapEx; - - bRet = GetBitmapEx(aFlavor, aBitmapEx); - if (bRet) - rGraphic = aBitmapEx; - } - else if(SotExchange::GetFormatDataFlavor( SotClipboardFormatId::BITMAP, aFlavor ) && - TransferableDataHelper::IsEqual( aFlavor, rFlavor ) ) - { - BitmapEx aBmpEx; - - bRet = GetBitmapEx( aFlavor, aBmpEx ); - if( bRet ) - rGraphic = aBmpEx; - } - else if( SotExchange::GetFormatDataFlavor( SotClipboardFormatId::GDIMETAFILE, aFlavor ) && - TransferableDataHelper::IsEqual( aFlavor, rFlavor ) ) - { - GDIMetaFile aMtf; - - bRet = GetGDIMetaFile( aFlavor, aMtf ); - if( bRet ) - rGraphic = aMtf; - } - else - { - tools::SvRef<SotStorageStream> xStm; - - if( GetSotStorageStream( rFlavor, xStm ) ) - { - ReadGraphic( *xStm, rGraphic ); - bRet = ( xStm->GetError() == ERRCODE_NONE ); - } - } - - return bRet; -} - - -bool TransferableDataHelper::GetImageMap( SotClipboardFormatId nFormat, ImageMap& rIMap ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetImageMap( aFlavor, rIMap ) ); -} - - -bool TransferableDataHelper::GetImageMap( const css::datatransfer::DataFlavor& rFlavor, ImageMap& rIMap ) -{ - tools::SvRef<SotStorageStream> xStm; - bool bRet = GetSotStorageStream( rFlavor, xStm ); - - if( bRet ) - { - rIMap.Read( *xStm ); - bRet = ( xStm->GetError() == ERRCODE_NONE ); - } - - return bRet; -} - - -bool TransferableDataHelper::GetTransferableObjectDescriptor( SotClipboardFormatId nFormat, TransferableObjectDescriptor& rDesc ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetTransferableObjectDescriptor( rDesc ) ); -} - - -bool TransferableDataHelper::GetTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) -{ - rDesc = *mxObjDesc; - return true; -} - - -bool TransferableDataHelper::GetINetBookmark( SotClipboardFormatId nFormat, INetBookmark& rBmk ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetBookmark( aFlavor, rBmk ) ); -} - - -bool TransferableDataHelper::GetINetBookmark( const css::datatransfer::DataFlavor& rFlavor, INetBookmark& rBmk ) -{ - bool bRet = false; - if( HasFormat( rFlavor )) - { - const SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor ); - switch( nFormat ) - { - case SotClipboardFormatId::SOLK: - case SotClipboardFormatId::UNIFORMRESOURCELOCATOR: - { - OUString aString; - if( GetString( rFlavor, aString ) ) - { - if( SotClipboardFormatId::UNIFORMRESOURCELOCATOR == nFormat ) - { - rBmk = INetBookmark( aString, aString ); - bRet = true; - } - else - { - OUString aURL, aDesc; - sal_Int32 nStart = aString.indexOf( '@' ), nLen = aString.toInt32(); - - if( !nLen && aString[ 0 ] != '0' ) - { - SAL_INFO( "svtools", "SOLK: 1. len=0" ); - } - if( nStart == -1 || nLen > aString.getLength() - nStart - 3 ) - { - SAL_INFO( "svtools", "SOLK: 1. illegal start or wrong len" ); - } - aURL = aString.copy( nStart + 1, nLen ); - - aString = aString.replaceAt( 0, nStart + 1 + nLen, "" ); - nStart = aString.indexOf( '@' ); - nLen = aString.toInt32(); - - if( !nLen && aString[ 0 ] != '0' ) - { - SAL_INFO( "svtools", "SOLK: 2. len=0" ); - } - if( nStart == -1 || nLen > aString.getLength() - nStart - 1 ) - { - SAL_INFO( "svtools", "SOLK: 2. illegal start or wrong len" ); - } - aDesc = aString.copy( nStart+1, nLen ); - - rBmk = INetBookmark( aURL, aDesc ); - bRet = true; - } - } - } - break; - - case SotClipboardFormatId::NETSCAPE_BOOKMARK: - { - Sequence<sal_Int8> aSeq = GetSequence(rFlavor, OUString()); - - if (2048 == aSeq.getLength()) - { - const sal_Char* p1 = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ); - const sal_Char* p2 = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ) + 1024; - rBmk = INetBookmark( OUString( p1, strlen(p1), osl_getThreadTextEncoding() ), - OUString( p2, strlen(p2), osl_getThreadTextEncoding() ) ); - bRet = true; - } - } - break; - -#ifdef _WIN32 - case SotClipboardFormatId::FILEGRPDESCRIPTOR: - { - Sequence<sal_Int8> aSeq = GetSequence(rFlavor, OUString()); - - if (aSeq.getLength()) - { - FILEGROUPDESCRIPTOR const * pFDesc = reinterpret_cast<FILEGROUPDESCRIPTOR const *>(aSeq.getConstArray()); - - if( pFDesc->cItems ) - { - OString aDesc( pFDesc->fgd[ 0 ].cFileName ); - rtl_TextEncoding eTextEncoding = osl_getThreadTextEncoding(); - - if( ( aDesc.getLength() > 4 ) && aDesc.copy(aDesc.getLength() - 4).equalsIgnoreAsciiCase(".URL") ) - { - std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( INetURLObject( OStringToOUString(aDesc, eTextEncoding) ).GetMainURL( INetURLObject::DecodeMechanism::NONE ), - StreamMode::STD_READ )); - - if( !pStream || pStream->GetError() ) - { - DataFlavor aFileContentFlavor; - - aSeq.realloc( 0 ); - pStream.reset(); - - if (SotExchange::GetFormatDataFlavor(SotClipboardFormatId::FILECONTENT, aFileContentFlavor)) - { - aSeq = GetSequence(aFileContentFlavor, OUString()); - if (aSeq.getLength()) - pStream.reset(new SvMemoryStream( const_cast<sal_Int8 *>(aSeq.getConstArray()), aSeq.getLength(), StreamMode::STD_READ )); - } - } - - if( pStream ) - { - OString aLine; - bool bSttFnd = false; - - while( pStream->ReadLine( aLine ) ) - { - if (aLine.equalsIgnoreAsciiCase("[InternetShortcut]")) - bSttFnd = true; - else if (bSttFnd && aLine.copy(0, 4).equalsIgnoreAsciiCase("URL=")) - { - rBmk = INetBookmark( OStringToOUString(aLine.copy(4), eTextEncoding), - OStringToOUString(aDesc.copy(0, aDesc.getLength() - 4), eTextEncoding) ); - bRet = true; - break; - } - } - } - } - } - } - } - break; -#endif - default: break; - } - } - return bRet; -} - - -bool TransferableDataHelper::GetINetImage( SotClipboardFormatId nFormat, - INetImage& rINtImg ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetImage( aFlavor, rINtImg ) ); -} - - -bool TransferableDataHelper::GetINetImage( - const css::datatransfer::DataFlavor& rFlavor, - INetImage& rINtImg ) -{ - tools::SvRef<SotStorageStream> xStm; - bool bRet = GetSotStorageStream( rFlavor, xStm ); - - if( bRet ) - bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) ); - return bRet; -} - - -bool TransferableDataHelper::GetFileList( SotClipboardFormatId nFormat, - FileList& rFileList ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetFileList( rFileList ) ); -} - - -bool TransferableDataHelper::GetFileList( FileList& rFileList ) -{ - tools::SvRef<SotStorageStream> xStm; - bool bRet = false; - - for( sal_uInt32 i = 0, nFormatCount = GetFormatCount(); ( i < nFormatCount ) && !bRet; ++i ) - { - if( SotClipboardFormatId::FILE_LIST == GetFormat( i ) ) - { - const DataFlavor aFlavor( GetFormatDataFlavor( i ) ); - - if( GetSotStorageStream( aFlavor, xStm ) ) - { - if( aFlavor.MimeType.indexOf( "text/uri-list" ) > -1 ) - { - OString aDiskString; - - while( xStm->ReadLine( aDiskString ) ) - if( !aDiskString.isEmpty() && aDiskString[0] != '#' ) - rFileList.AppendFile( OStringToOUString(aDiskString, RTL_TEXTENCODING_UTF8) ); - - bRet = true; - } - else - bRet = ( ReadFileList( *xStm, rFileList ).GetError() == ERRCODE_NONE ); - } - } - } - - return bRet; -} - - -Sequence<sal_Int8> TransferableDataHelper::GetSequence( SotClipboardFormatId nFormat, const OUString& rDestDoc ) -{ - DataFlavor aFlavor; - if (!SotExchange::GetFormatDataFlavor(nFormat, aFlavor)) - return Sequence<sal_Int8>(); - - return GetSequence(aFlavor, rDestDoc); -} - -Sequence<sal_Int8> TransferableDataHelper::GetSequence( const DataFlavor& rFlavor, const OUString& rDestDoc ) -{ - const Any aAny = GetAny(rFlavor, rDestDoc); - Sequence<sal_Int8> aSeq; - if (aAny.hasValue()) - aAny >>= aSeq; - - return aSeq; -} - - -bool TransferableDataHelper::GetSotStorageStream( SotClipboardFormatId nFormat, tools::SvRef<SotStorageStream>& rxStream ) -{ - DataFlavor aFlavor; - return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSotStorageStream( aFlavor, rxStream ) ); -} - - -bool TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor, tools::SvRef<SotStorageStream>& rxStream ) -{ - Sequence<sal_Int8> aSeq = GetSequence(rFlavor, OUString()); - - if (aSeq.getLength()) - { - rxStream = new SotStorageStream( "" ); - rxStream->WriteBytes( aSeq.getConstArray(), aSeq.getLength() ); - rxStream->Seek( 0 ); - } - - return aSeq.getLength(); -} - -Reference<XInputStream> TransferableDataHelper::GetInputStream( SotClipboardFormatId nFormat, const OUString& rDestDoc ) -{ - DataFlavor aFlavor; - if (!SotExchange::GetFormatDataFlavor(nFormat, aFlavor)) - return Reference<XInputStream>(); - - return GetInputStream(aFlavor, rDestDoc); -} - -Reference<XInputStream> TransferableDataHelper::GetInputStream( const DataFlavor& rFlavor, const OUString& rDestDoc ) -{ - Sequence<sal_Int8> aSeq = GetSequence(rFlavor, rDestDoc); - - if (!aSeq.getLength()) - return Reference<XInputStream>(); - - Reference<XInputStream> xStream(new comphelper::SequenceInputStream(aSeq)); - return xStream; -} - -void TransferableDataHelper::Rebind( const Reference< XTransferable >& _rxNewContent ) -{ - mxTransfer = _rxNewContent; - InitFormats(); -} - -bool TransferableDataHelper::StartClipboardListening( ) -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - - StopClipboardListening( ); - - mxImpl->mxClipboardListener = new TransferableClipboardNotifier(mxClipboard, *this, mxImpl->maMutex); - - return mxImpl->mxClipboardListener->isListening(); -} - -void TransferableDataHelper::StopClipboardListening( ) -{ - ::osl::MutexGuard aGuard(mxImpl->maMutex); - - if (mxImpl->mxClipboardListener.is()) - { - mxImpl->mxClipboardListener->dispose(); - mxImpl->mxClipboardListener.clear(); - } -} - - -TransferableDataHelper TransferableDataHelper::CreateFromSystemClipboard( vcl::Window * pWindow ) -{ - DBG_ASSERT( pWindow, "Window pointer is NULL" ); - - Reference< XClipboard > xClipboard; - TransferableDataHelper aRet; - - if( pWindow ) - xClipboard = pWindow->GetClipboard(); - - if( xClipboard.is() ) - { - try - { - Reference< XTransferable > xTransferable( xClipboard->getContents() ); - - if( xTransferable.is() ) - { - aRet = TransferableDataHelper( xTransferable ); - // also copy the clipboard - aRet.mxClipboard = xClipboard; - } - } - catch( const css::uno::Exception& ) - { - } - } - - return aRet; -} - - -TransferableDataHelper TransferableDataHelper::CreateFromSelection( vcl::Window* pWindow ) -{ - DBG_ASSERT( pWindow, "Window pointer is NULL" ); - - Reference< XClipboard > xSelection; - TransferableDataHelper aRet; - - if( pWindow ) - xSelection = pWindow->GetPrimarySelection(); - - if( xSelection.is() ) - { - SolarMutexReleaser aReleaser; - - try - { - Reference< XTransferable > xTransferable( xSelection->getContents() ); - - if( xTransferable.is() ) - { - aRet = TransferableDataHelper( xTransferable ); - aRet.mxClipboard = xSelection; - } - } - catch( const css::uno::Exception& ) - { - } - } - - return aRet; -} - - -bool TransferableDataHelper::IsEqual( const css::datatransfer::DataFlavor& rInternalFlavor, - const css::datatransfer::DataFlavor& rRequestFlavor ) -{ - Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - bool bRet = false; - - try - { - Reference< XMimeContentTypeFactory > xMimeFact = MimeContentTypeFactory::create( xContext ); - - Reference< XMimeContentType > xRequestType1( xMimeFact->createMimeContentType( rInternalFlavor.MimeType ) ); - Reference< XMimeContentType > xRequestType2( xMimeFact->createMimeContentType( rRequestFlavor.MimeType ) ); - - if( xRequestType1.is() && xRequestType2.is() ) - { - if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) ) - { - if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( "text/plain" ) ) - { - // special handling for text/plain media types - const OUString aCharsetString( "charset" ); - - if( !xRequestType2->hasParameter( aCharsetString ) || - xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( "utf-16" ) || - xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( "unicode" ) ) - { - bRet = true; - } - } - else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( "application/x-openoffice" ) ) - { - // special handling for application/x-openoffice media types - const OUString aFormatString( "windows_formatname" ); - - if( xRequestType1->hasParameter( aFormatString ) && - xRequestType2->hasParameter( aFormatString ) && - xRequestType1->getParameterValue( aFormatString ).equalsIgnoreAsciiCase( xRequestType2->getParameterValue( aFormatString ) ) ) - { - bRet = true; - } - } - else - bRet = true; - } - } - } - catch( const css::uno::Exception& ) - { - bRet = rInternalFlavor.MimeType.equalsIgnoreAsciiCase( rRequestFlavor.MimeType ); - } - - return bRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/misc/transfer2.cxx b/svtools/source/misc/transfer2.cxx deleted file mode 100644 index 5405ce9683a2..000000000000 --- a/svtools/source/misc/transfer2.cxx +++ /dev/null @@ -1,472 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <osl/mutex.hxx> -#include <sot/exchange.hxx> -#include <sot/storage.hxx> -#include <vcl/bitmap.hxx> -#include <vcl/gdimtf.hxx> -#include <vcl/graph.hxx> -#include <vcl/svapp.hxx> -#include <vcl/window.hxx> -#include <comphelper/fileformat.h> -#include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp> -#include <svl/urlbmk.hxx> -#include <svtools/inetimg.hxx> -#include <svtools/imap.hxx> -#include <svtools/transfer.hxx> - - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::datatransfer; -using namespace ::com::sun::star::datatransfer::clipboard; -using namespace ::com::sun::star::datatransfer::dnd; - - -DragSourceHelper::DragGestureListener::DragGestureListener( DragSourceHelper& rDragSourceHelper ) : - mrParent( rDragSourceHelper ) -{ -} - - -DragSourceHelper::DragGestureListener::~DragGestureListener() -{ -} - - -void SAL_CALL DragSourceHelper::DragGestureListener::disposing( const EventObject& ) -{ -} - - -void SAL_CALL DragSourceHelper::DragGestureListener::dragGestureRecognized( const DragGestureEvent& rDGE ) -{ - const SolarMutexGuard aGuard; - - const Point aPtPixel( rDGE.DragOriginX, rDGE.DragOriginY ); - mrParent.StartDrag( rDGE.DragAction, aPtPixel ); -} - - -DragSourceHelper::DragSourceHelper( vcl::Window* pWindow ) : - mxDragGestureRecognizer( pWindow->GetDragGestureRecognizer() ) -{ - if( mxDragGestureRecognizer.is() ) - { - mxDragGestureListener = new DragSourceHelper::DragGestureListener( *this ); - mxDragGestureRecognizer->addDragGestureListener( mxDragGestureListener ); - } -} - - -void DragSourceHelper::dispose() -{ - Reference<XDragGestureRecognizer> xTmp; - { - osl::MutexGuard aGuard( maMutex ); - xTmp = mxDragGestureRecognizer; - mxDragGestureRecognizer.clear(); - } - if( xTmp.is() ) - xTmp->removeDragGestureListener( mxDragGestureListener ); -} - -DragSourceHelper::~DragSourceHelper() -{ - dispose(); -} - - -void DragSourceHelper::StartDrag( sal_Int8, const Point& ) -{ -} - - -DropTargetHelper::DropTargetListener::DropTargetListener( DropTargetHelper& rDropTargetHelper ) : - mrParent( rDropTargetHelper ) -{ -} - - -DropTargetHelper::DropTargetListener::~DropTargetListener() -{ -} - - -void SAL_CALL DropTargetHelper::DropTargetListener::disposing( const EventObject& ) -{ -} - - -void SAL_CALL DropTargetHelper::DropTargetListener::drop( const DropTargetDropEvent& rDTDE ) -{ - const SolarMutexGuard aGuard; - - try - { - AcceptDropEvent aAcceptEvent; - ExecuteDropEvent aExecuteEvt( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT, Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE ); - - aExecuteEvt.mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 ); - - // in case of a default action, call ::AcceptDrop first and use the returned - // accepted action as the execute action in the call to ::ExecuteDrop - aAcceptEvent.mnAction = aExecuteEvt.mnAction; - aAcceptEvent.maPosPixel = aExecuteEvt.maPosPixel; - static_cast<DropTargetEvent&>(const_cast<DropTargetDragEvent&>( aAcceptEvent.maDragEvent )) = rDTDE; - const_cast<DropTargetDragEvent&>( aAcceptEvent.maDragEvent ).DropAction = rDTDE.DropAction; - const_cast<DropTargetDragEvent&>( aAcceptEvent.maDragEvent ).LocationX = rDTDE.LocationX; - const_cast<DropTargetDragEvent&>( aAcceptEvent.maDragEvent ).LocationY = rDTDE.LocationY; - const_cast<DropTargetDragEvent&>( aAcceptEvent.maDragEvent ).SourceActions = rDTDE.SourceActions; - aAcceptEvent.mbLeaving = false; - aAcceptEvent.mbDefault = aExecuteEvt.mbDefault; - - sal_Int8 nRet = mrParent.AcceptDrop( aAcceptEvent ); - - if( DNDConstants::ACTION_NONE != nRet ) - { - rDTDE.Context->acceptDrop( nRet ); - - if( aExecuteEvt.mbDefault ) - aExecuteEvt.mnAction = nRet; - - nRet = mrParent.ExecuteDrop( aExecuteEvt ); - } - - rDTDE.Context->dropComplete( DNDConstants::ACTION_NONE != nRet ); - - mpLastDragOverEvent.reset(); - } - catch( const css::uno::Exception& ) - { - } -} - - -void SAL_CALL DropTargetHelper::DropTargetListener::dragEnter( const DropTargetDragEnterEvent& rDTDEE ) -{ - const SolarMutexGuard aGuard; - - try - { - mrParent.ImplBeginDrag( rDTDEE.SupportedDataFlavors ); - } - catch( const css::uno::Exception& ) - { - } - - dragOver( rDTDEE ); -} - - -void SAL_CALL DropTargetHelper::DropTargetListener::dragOver( const DropTargetDragEvent& rDTDE ) -{ - const SolarMutexGuard aGuard; - - try - { - mpLastDragOverEvent.reset( new AcceptDropEvent( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT, Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE ) ); - mpLastDragOverEvent->mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 ); - - const sal_Int8 nRet = mrParent.AcceptDrop( *mpLastDragOverEvent ); - - if( DNDConstants::ACTION_NONE == nRet ) - rDTDE.Context->rejectDrag(); - else - rDTDE.Context->acceptDrag( nRet ); - } - catch( const css::uno::Exception& ) - { - } -} - - -void SAL_CALL DropTargetHelper::DropTargetListener::dragExit( const DropTargetEvent& ) -{ - const SolarMutexGuard aGuard; - - try - { - if( mpLastDragOverEvent ) - { - mpLastDragOverEvent->mbLeaving = true; - mrParent.AcceptDrop( *mpLastDragOverEvent ); - mpLastDragOverEvent.reset(); - } - - mrParent.ImplEndDrag(); - } - catch( const css::uno::Exception& ) - { - } -} - - -void SAL_CALL DropTargetHelper::DropTargetListener::dropActionChanged( const DropTargetDragEvent& ) -{ -} - - -DropTargetHelper::DropTargetHelper( vcl::Window* pWindow ) : - mxDropTarget( pWindow->GetDropTarget() ) -{ - ImplConstruct(); -} - - -DropTargetHelper::DropTargetHelper( const Reference< XDropTarget >& rxDropTarget ) : - mxDropTarget( rxDropTarget ) -{ - ImplConstruct(); -} - - -void DropTargetHelper::dispose() -{ - Reference< XDropTarget > xTmp; - { - osl::MutexGuard aGuard( maMutex ); - xTmp = mxDropTarget; - mxDropTarget.clear(); - } - if( xTmp.is() ) - xTmp->removeDropTargetListener( mxDropTargetListener ); -} - -DropTargetHelper::~DropTargetHelper() -{ - dispose(); -} - - -void DropTargetHelper::ImplConstruct() -{ - if( mxDropTarget.is() ) - { - mxDropTargetListener = new DropTargetHelper::DropTargetListener( *this ); - mxDropTarget->addDropTargetListener( mxDropTargetListener ); - mxDropTarget->setActive( true ); - } -} - - -void DropTargetHelper::ImplBeginDrag( const Sequence< DataFlavor >& rSupportedDataFlavors ) -{ - maFormats.clear(); - TransferableDataHelper::FillDataFlavorExVector( rSupportedDataFlavors, maFormats ); -} - - -void DropTargetHelper::ImplEndDrag() -{ - maFormats.clear(); -} - - -sal_Int8 DropTargetHelper::AcceptDrop( const AcceptDropEvent& ) -{ - return DNDConstants::ACTION_NONE; -} - - -sal_Int8 DropTargetHelper::ExecuteDrop( const ExecuteDropEvent& ) -{ - return DNDConstants::ACTION_NONE; -} - - -bool DropTargetHelper::IsDropFormatSupported( SotClipboardFormatId nFormat ) -{ - return std::any_of(maFormats.begin(), maFormats.end(), - [&](const DataFlavorEx& data) { return data.mnSotId == nFormat; }); -} - - -// TransferDataContainer - - -struct TDataCntnrEntry_Impl -{ - css::uno::Any aAny; - SotClipboardFormatId nId; -}; - - -typedef ::std::vector< TDataCntnrEntry_Impl > TDataCntnrEntryList; - - -struct TransferDataContainer_Impl -{ - TDataCntnrEntryList aFmtList; - Link<sal_Int8,void> aFinshedLnk; - std::unique_ptr<INetBookmark> pBookmk; - - TransferDataContainer_Impl() - { - } -}; - - -TransferDataContainer::TransferDataContainer() - : pImpl( new TransferDataContainer_Impl ) -{ -} - - -TransferDataContainer::~TransferDataContainer() -{ -} - - -void TransferDataContainer::AddSupportedFormats() -{ -} - - -bool TransferDataContainer::GetData( - const css::datatransfer::DataFlavor& rFlavor, const OUString& /*rDestDoc*/ ) -{ - bool bFnd = false; - SotClipboardFormatId nFmtId = SotExchange::GetFormat( rFlavor ); - - // test first the list - for (auto const& format : pImpl->aFmtList) - { - if( nFmtId == format.nId ) - { - bFnd = SetAny( format.aAny ); - break; - } - } - - // test second the bookmark pointer - if( !bFnd ) - switch( nFmtId ) - { - case SotClipboardFormatId::STRING: - case SotClipboardFormatId::SOLK: - case SotClipboardFormatId::NETSCAPE_BOOKMARK: - case SotClipboardFormatId::FILECONTENT: - case SotClipboardFormatId::FILEGRPDESCRIPTOR: - case SotClipboardFormatId::UNIFORMRESOURCELOCATOR: - if( pImpl->pBookmk ) - bFnd = SetINetBookmark( *pImpl->pBookmk, rFlavor ); - break; - - default: break; - } - - return bFnd; -} - - -void TransferDataContainer::CopyINetBookmark( const INetBookmark& rBkmk ) -{ - if( !pImpl->pBookmk ) - pImpl->pBookmk.reset( new INetBookmark( rBkmk ) ); - else - *pImpl->pBookmk = rBkmk; - - AddFormat( SotClipboardFormatId::STRING ); - AddFormat( SotClipboardFormatId::SOLK ); - AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ); - AddFormat( SotClipboardFormatId::FILECONTENT ); - AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ); - AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ); -} - - -void TransferDataContainer::CopyAnyData( SotClipboardFormatId nFormatId, - const sal_Char* pData, sal_uLong nLen ) -{ - if( nLen ) - { - TDataCntnrEntry_Impl aEntry; - aEntry.nId = nFormatId; - - Sequence< sal_Int8 > aSeq( nLen ); - memcpy( aSeq.getArray(), pData, nLen ); - aEntry.aAny <<= aSeq; - pImpl->aFmtList.push_back( aEntry ); - AddFormat( nFormatId ); - } -} - - -void TransferDataContainer::CopyByteString( SotClipboardFormatId nFormatId, - const OString& rStr ) -{ - CopyAnyData( nFormatId, rStr.getStr(), rStr.getLength() ); -} - - -void TransferDataContainer::CopyString( SotClipboardFormatId nFmt, const OUString& rStr ) -{ - if( !rStr.isEmpty() ) - { - TDataCntnrEntry_Impl aEntry; - aEntry.nId = nFmt; - aEntry.aAny <<= rStr; - pImpl->aFmtList.push_back( aEntry ); - AddFormat( aEntry.nId ); - } -} - - -void TransferDataContainer::CopyString( const OUString& rStr ) -{ - CopyString( SotClipboardFormatId::STRING, rStr ); -} - - -void TransferDataContainer::CopyAny( SotClipboardFormatId nFmt, - const css::uno::Any& rAny ) -{ - TDataCntnrEntry_Impl aEntry; - aEntry.nId = nFmt; - aEntry.aAny = rAny; - pImpl->aFmtList.push_back( aEntry ); - AddFormat( aEntry.nId ); -} - - -bool TransferDataContainer::HasAnyData() const -{ - return !pImpl->aFmtList.empty() || - nullptr != pImpl->pBookmk; -} - - -void TransferDataContainer::StartDrag( - vcl::Window* pWindow, sal_Int8 nDragSourceActions, - const Link<sal_Int8,void>& rLnk ) -{ - pImpl->aFinshedLnk = rLnk; - TransferableHelper::StartDrag( pWindow, nDragSourceActions ); -} - - -void TransferDataContainer::DragFinished( sal_Int8 nDropAction ) -{ - pImpl->aFinshedLnk.Call( nDropAction ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |