Files
libreoffice/svtools/source/misc/transfer2.cxx

616 lines
15 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patch contributed by: Jurgen Schmidt remove onlineregistration with dependencies http://svn.apache.org/viewvc?view=revision&revision=1240245 imported patch package_eventlistener.patch http://svn.apache.org/viewvc?view=revision&revision=1172103 Patch contributed by Pedro Giffuni Accept Google Chrome OS fonts as equivalent to MS fonts. http://svn.apache.org/viewvc?view=revision&revision=1233155 http://svn.apache.org/viewvc?view=revision&revision=1233408 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i114600#: remove forbidden characters from list of unencoded characters http://svn.apache.org/viewvc?view=revision&revision=1172370 Patches contributed by Oliver Rainer-Wittman some clean up in JPEGReader due to memory constraints http://svn.apache.org/viewvc?view=revision&revision=1299729 119114 - method <UpdateDialog::addSpecificError(..)> - create entry with correct type http://svn.apache.org/viewvc?view=revision&revision=1305265 Patches contributed by Ariel Constenla-Haile i118707 - make toolbar control's popup window grab focus http://svn.apache.org/viewvc?view=revision&revision=1225846 Patches contributed by Herbert Duerr #i118662# remove usage of BerkeleyDB in desktop module http://svn.apache.org/viewvc?view=revision&revision=1213171 minor cleanups in dp_persmap.* http://svn.apache.org/viewvc?view=revision&revision=1215064 flush early to prevent problem with extension manager not cleaning up its objects http://svn.apache.org/viewvc?view=revision&revision=1228147 i118726 do not flush *pmap file while reading it http://svn.apache.org/viewvc?view=revision&revision=1230614 #i119048# migrate BDB extension entries using a simple heuristic http://svn.apache.org/viewvc?view=revision&revision=1300972 #i119048# handle edge cases when importing BDB hash files http://svn.apache.org/viewvc?view=revision&revision=1301428 #i119113# fix of-by-one when importing BDB files http://svn.apache.org/viewvc?view=revision&revision=1305420 restore our encryption settings, icon themes, and dictionaries. removed wrapper hacks, kill obsolete bundled extension blob / pre-registration handling, remove duplicated quickstart code. remove OS/2 conditionals.
2012-11-15 17:28:16 +00:00
/*
* 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 .
*/
2001-02-26 11:58:36 +00:00
#include <osl/mutex.hxx>
2001-02-26 11:58:36 +00:00
#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/svapp.hxx>
#include <vcl/window.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
#include "svl/urlbmk.hxx"
#include <svtools/inetimg.hxx>
#include <svtools/imap.hxx>
#include <svtools/transfer.hxx>
2001-02-26 11:58:36 +00:00
2001-02-26 11:58:36 +00:00
// - Namespaces -
2001-02-26 11:58:36 +00:00
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 -
DragSourceHelper::DragGestureListener::DragGestureListener( DragSourceHelper& rDragSourceHelper ) :
mrParent( rDragSourceHelper )
{
}
DragSourceHelper::DragGestureListener::~DragGestureListener()
{
}
void SAL_CALL DragSourceHelper::DragGestureListener::disposing( const EventObject& ) throw( RuntimeException, std::exception )
{
}
void SAL_CALL DragSourceHelper::DragGestureListener::dragGestureRecognized( const DragGestureEvent& rDGE ) throw( RuntimeException, std::exception )
{
const SolarMutexGuard aGuard;
2001-03-22 17:09:25 +00:00
const Point aPtPixel( rDGE.DragOriginX, rDGE.DragOriginY );
mrParent.StartDrag( rDGE.DragAction, aPtPixel );
}
// - DragSourceHelper -
DragSourceHelper::DragSourceHelper( Window* pWindow ) :
mxDragGestureRecognizer( pWindow->GetDragGestureRecognizer() )
{
if( mxDragGestureRecognizer.is() )
{
mxDragGestureListener = new DragSourceHelper::DragGestureListener( *this );
mxDragGestureRecognizer->addDragGestureListener( mxDragGestureListener );
}
}
DragSourceHelper::~DragSourceHelper()
{
if( mxDragGestureRecognizer.is() )
mxDragGestureRecognizer->removeDragGestureListener( mxDragGestureListener );
}
void DragSourceHelper::StartDrag( sal_Int8, const Point& )
{
}
2001-02-26 11:58:36 +00:00
// - DropTargetHelper::DropTargetListener -
2001-02-26 11:58:36 +00:00
DropTargetHelper::DropTargetListener::DropTargetListener( DropTargetHelper& rDropTargetHelper ) :
mrParent( rDropTargetHelper ),
mpLastDragOverEvent( NULL )
2001-02-26 11:58:36 +00:00
{
}
2001-02-26 11:58:36 +00:00
DropTargetHelper::DropTargetListener::~DropTargetListener()
{
delete mpLastDragOverEvent;
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void SAL_CALL DropTargetHelper::DropTargetListener::disposing( const EventObject& ) throw( RuntimeException, std::exception )
2001-02-26 11:58:36 +00:00
{
}
2001-02-26 11:58:36 +00:00
void SAL_CALL DropTargetHelper::DropTargetListener::drop( const DropTargetDropEvent& rDTDE ) throw( RuntimeException, std::exception )
2001-02-26 11:58:36 +00:00
{
const SolarMutexGuard aGuard;
2001-03-05 11:44:24 +00:00
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;
(DropTargetEvent&)( aAcceptEvent.maDragEvent ) = (DropTargetEvent&) rDTDE;
( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).DropAction = rDTDE.DropAction;
( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).LocationX = rDTDE.LocationX;
( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).LocationY = rDTDE.LocationY;
( (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;
2001-02-26 11:58:36 +00:00
nRet = mrParent.ExecuteDrop( aExecuteEvt );
}
2001-03-05 11:44:24 +00:00
rDTDE.Context->dropComplete( DNDConstants::ACTION_NONE != nRet );
if( mpLastDragOverEvent )
{
delete mpLastDragOverEvent;
mpLastDragOverEvent = NULL;
}
}
catch( const ::com::sun::star::uno::Exception& )
{
}
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void SAL_CALL DropTargetHelper::DropTargetListener::dragEnter( const DropTargetDragEnterEvent& rDTDEE ) throw( RuntimeException, std::exception )
2001-02-26 11:58:36 +00:00
{
const SolarMutexGuard aGuard;
2001-03-05 11:44:24 +00:00
try
{
mrParent.ImplBeginDrag( rDTDEE.SupportedDataFlavors );
}
catch( const ::com::sun::star::uno::Exception& )
{
}
2001-03-05 11:44:24 +00:00
dragOver( rDTDEE );
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void SAL_CALL DropTargetHelper::DropTargetListener::dragOver( const DropTargetDragEvent& rDTDE ) throw( RuntimeException, std::exception )
2001-02-26 11:58:36 +00:00
{
const SolarMutexGuard aGuard;
2001-03-05 11:44:24 +00:00
try
{
if( mpLastDragOverEvent )
delete mpLastDragOverEvent;
mpLastDragOverEvent = 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 ::com::sun::star::uno::Exception& )
{
}
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void SAL_CALL DropTargetHelper::DropTargetListener::dragExit( const DropTargetEvent& ) throw( RuntimeException, std::exception )
2001-02-26 11:58:36 +00:00
{
const SolarMutexGuard aGuard;
2001-03-05 11:44:24 +00:00
try
{
if( mpLastDragOverEvent )
{
mpLastDragOverEvent->mbLeaving = true;
mrParent.AcceptDrop( *mpLastDragOverEvent );
delete mpLastDragOverEvent;
mpLastDragOverEvent = NULL;
}
2001-03-05 11:44:24 +00:00
mrParent.ImplEndDrag();
}
catch( const ::com::sun::star::uno::Exception& )
{
}
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void SAL_CALL DropTargetHelper::DropTargetListener::dropActionChanged( const DropTargetDragEvent& ) throw( RuntimeException, std::exception )
2001-02-26 11:58:36 +00:00
{
}
2001-02-26 11:58:36 +00:00
// - DropTargetHelper -
2001-02-26 11:58:36 +00:00
2001-03-05 11:44:24 +00:00
DropTargetHelper::DropTargetHelper( Window* pWindow ) :
mxDropTarget( pWindow->GetDropTarget() ),
mpFormats( new DataFlavorExVector )
2001-02-26 11:58:36 +00:00
{
ImplConstruct();
}
2001-02-26 11:58:36 +00:00
DropTargetHelper::DropTargetHelper( const Reference< XDropTarget >& rxDropTarget ) :
mxDropTarget( rxDropTarget ),
mpFormats( new DataFlavorExVector )
2001-02-26 11:58:36 +00:00
{
ImplConstruct();
}
2001-02-26 11:58:36 +00:00
DropTargetHelper::~DropTargetHelper()
{
if( mxDropTarget.is() )
mxDropTarget->removeDropTargetListener( mxDropTargetListener );
delete mpFormats;
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void DropTargetHelper::ImplConstruct()
{
if( mxDropTarget.is() )
{
mxDropTargetListener = new DropTargetHelper::DropTargetListener( *this );
mxDropTarget->addDropTargetListener( mxDropTargetListener );
mxDropTarget->setActive( sal_True );
}
}
2001-02-26 11:58:36 +00:00
void DropTargetHelper::ImplBeginDrag( const Sequence< DataFlavor >& rSupportedDataFlavors )
{
mpFormats->clear();
2001-10-18 10:53:11 +00:00
TransferableDataHelper::FillDataFlavorExVector( rSupportedDataFlavors, *mpFormats );
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
void DropTargetHelper::ImplEndDrag()
{
mpFormats->clear();
2001-02-26 11:58:36 +00:00
}
2001-02-26 11:58:36 +00:00
sal_Int8 DropTargetHelper::AcceptDrop( const AcceptDropEvent& )
2001-02-26 11:58:36 +00:00
{
return( DNDConstants::ACTION_NONE );
}
2001-02-26 11:58:36 +00:00
sal_Int8 DropTargetHelper::ExecuteDrop( const ExecuteDropEvent& )
2001-02-26 11:58:36 +00:00
{
return( DNDConstants::ACTION_NONE );
}
2001-02-26 11:58:36 +00:00
bool DropTargetHelper::IsDropFormatSupported( SotFormatStringId nFormat )
2001-02-26 11:58:36 +00:00
{
DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
bool bRet = false;
2001-02-26 11:58:36 +00:00
while( aIter != aEnd )
{
if( nFormat == (*aIter++).mnSotId )
{
bRet = true;
2001-02-26 11:58:36 +00:00
aIter = aEnd;
}
}
return bRet;
}
2001-02-26 11:58:36 +00:00
bool DropTargetHelper::IsDropFormatSupported( const DataFlavor& rFlavor )
2001-02-26 11:58:36 +00:00
{
DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() );
bool bRet = false;
2001-02-26 11:58:36 +00:00
while( aIter != aEnd )
{
if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) )
{
bRet = true;
2001-02-26 11:58:36 +00:00
aIter = aEnd;
}
}
return bRet;
}
2001-10-18 10:53:11 +00:00
// TransferDataContainer
2001-10-18 10:53:11 +00:00
struct TDataCntnrEntry_Impl
{
::com::sun::star::uno::Any aAny;
SotFormatStringId nId;
};
2001-10-18 10:53:11 +00:00
typedef ::std::list< TDataCntnrEntry_Impl > TDataCntnrEntryList;
2001-10-18 10:53:11 +00:00
struct TransferDataContainer_Impl
{
TDataCntnrEntryList aFmtList;
Link aFinshedLnk;
INetBookmark* pBookmk;
Graphic* pGrf;
TransferDataContainer_Impl()
: pBookmk( 0 ), pGrf( 0 )
{
}
~TransferDataContainer_Impl()
{
delete pBookmk;
delete pGrf;
}
};
2001-10-18 10:53:11 +00:00
TransferDataContainer::TransferDataContainer()
: pImpl( new TransferDataContainer_Impl )
{
}
2001-10-18 10:53:11 +00:00
TransferDataContainer::~TransferDataContainer()
{
delete pImpl;
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::AddSupportedFormats()
{
}
2001-10-18 10:53:11 +00:00
bool TransferDataContainer::GetData( const
2001-10-18 10:53:11 +00:00
::com::sun::star::datatransfer::DataFlavor& rFlavor )
{
TDataCntnrEntryList::iterator aIter( pImpl->aFmtList.begin() ),
aEnd( pImpl->aFmtList.end() );
bool bFnd = false;
sal_uLong nFmtId = SotExchange::GetFormat( rFlavor );
2001-10-18 10:53:11 +00:00
// test first the list
for( ; aIter != aEnd; ++aIter )
{
TDataCntnrEntry_Impl& rEntry = (TDataCntnrEntry_Impl&)*aIter;
if( nFmtId == rEntry.nId )
{
bFnd = SetAny( rEntry.aAny, rFlavor );
break;
}
}
// test second the bookmark pointer
if( !bFnd )
switch( nFmtId )
{
case SOT_FORMAT_STRING:
case SOT_FORMATSTR_ID_SOLK:
case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
case SOT_FORMATSTR_ID_FILECONTENT:
case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
if( pImpl->pBookmk )
bFnd = SetINetBookmark( *pImpl->pBookmk, rFlavor );
break;
case SOT_FORMATSTR_ID_SVXB:
case SOT_FORMATSTR_ID_PNG:
2001-10-18 10:53:11 +00:00
case SOT_FORMAT_BITMAP:
case SOT_FORMAT_GDIMETAFILE:
if( pImpl->pGrf )
bFnd = SetGraphic( *pImpl->pGrf, rFlavor );
break;
}
return bFnd;
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyINetBookmark( const INetBookmark& rBkmk )
{
if( !pImpl->pBookmk )
pImpl->pBookmk = new INetBookmark( rBkmk );
else
*pImpl->pBookmk = rBkmk;
AddFormat( SOT_FORMAT_STRING );
AddFormat( SOT_FORMATSTR_ID_SOLK );
AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyAnyData( sal_uLong nFormatId,
const sal_Char* pData, sal_uLong nLen )
2001-10-18 10:53:11 +00:00
{
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 );
}
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyByteString( sal_uLong nFormatId,
const OString& rStr )
2001-10-18 10:53:11 +00:00
{
2011-11-09 22:36:22 +00:00
CopyAnyData( nFormatId, rStr.getStr(), rStr.getLength() );
2001-10-18 10:53:11 +00:00
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyINetImage( const INetImage& rINtImg )
{
SvMemoryStream aMemStm( 1024, 1024 );
aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
rINtImg.Write( aMemStm, SOT_FORMATSTR_ID_INET_IMAGE );
CopyAnyData( SOT_FORMATSTR_ID_INET_IMAGE, (sal_Char*)aMemStm.GetData(),
aMemStm.Seek( STREAM_SEEK_TO_END ) );
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyImageMap( const ImageMap& rImgMap )
{
SvMemoryStream aMemStm( 8192, 8192 );
aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
rImgMap.Write( aMemStm, OUString() );
2001-10-18 10:53:11 +00:00
CopyAnyData( SOT_FORMATSTR_ID_SVIM, (sal_Char*)aMemStm.GetData(),
aMemStm.Seek( STREAM_SEEK_TO_END ) );
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyGraphic( const Graphic& rGrf )
{
GraphicType nType = rGrf.GetType();
2001-10-18 10:53:11 +00:00
if( GRAPHIC_NONE != nType )
{
if( !pImpl->pGrf )
pImpl->pGrf = new Graphic( rGrf );
else
*pImpl->pGrf = rGrf;
AddFormat( SOT_FORMATSTR_ID_SVXB );
2001-10-18 10:53:11 +00:00
if( GRAPHIC_BITMAP == nType )
{
AddFormat( SOT_FORMATSTR_ID_PNG );
2001-10-18 10:53:11 +00:00
AddFormat( SOT_FORMAT_BITMAP );
}
2001-10-18 10:53:11 +00:00
else if( GRAPHIC_GDIMETAFILE == nType )
{
2001-10-18 10:53:11 +00:00
AddFormat( SOT_FORMAT_GDIMETAFILE );
}
2001-10-18 10:53:11 +00:00
}
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyString( sal_uInt16 nFmt, const OUString& rStr )
2001-10-18 10:53:11 +00:00
{
if( !rStr.isEmpty() )
2001-10-18 10:53:11 +00:00
{
TDataCntnrEntry_Impl aEntry;
aEntry.nId = nFmt;
OUString aStr( rStr );
2001-10-18 10:53:11 +00:00
aEntry.aAny <<= aStr;
pImpl->aFmtList.push_back( aEntry );
AddFormat( aEntry.nId );
}
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyString( const OUString& rStr )
2001-10-18 10:53:11 +00:00
{
CopyString( SOT_FORMAT_STRING, rStr );
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::CopyAny( sal_uInt16 nFmt,
2001-10-18 10:53:11 +00:00
const ::com::sun::star::uno::Any& rAny )
{
TDataCntnrEntry_Impl aEntry;
aEntry.nId = nFmt;
aEntry.aAny = rAny;
pImpl->aFmtList.push_back( aEntry );
AddFormat( aEntry.nId );
}
2001-10-18 10:53:11 +00:00
bool TransferDataContainer::HasAnyData() const
2001-10-18 10:53:11 +00:00
{
return pImpl->aFmtList.begin() != pImpl->aFmtList.end() ||
0 != pImpl->pBookmk;
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::StartDrag(
Window* pWindow, sal_Int8 nDragSourceActions,
const Link& rLnk, sal_Int32 nDragPointer, sal_Int32 nDragImage )
{
pImpl->aFinshedLnk = rLnk;
TransferableHelper::StartDrag( pWindow, nDragSourceActions,
nDragPointer, nDragImage );
}
2001-10-18 10:53:11 +00:00
void TransferDataContainer::DragFinished( sal_Int8 nDropAction )
{
if( pImpl->aFinshedLnk.IsSet() )
pImpl->aFinshedLnk.Call( &nDropAction );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */