fdo#54938 Convert comphelper and vcl to cppu::supportsService

Change-Id: I391a7324bf92208fe632dac17874943343b1f65a
Reviewed-on: https://gerrit.libreoffice.org/7757
Reviewed-by: Marcos Souza <marcos.souza.org@gmail.com>
Tested-by: Marcos Souza <marcos.souza.org@gmail.com>
This commit is contained in:
Alexandre Vicenzi
2014-01-31 03:39:50 -02:00
committed by Marcos Souza
parent a7395942ae
commit e17cf91032
6 changed files with 273 additions and 390 deletions

View File

@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "comphelper_module.hxx" #include "comphelper_module.hxx"
#include <com/sun/star/ucb/XAnyCompareFactory.hpp> #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
@@ -27,21 +26,18 @@
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <cppuhelper/implbase3.hxx> #include <cppuhelper/implbase3.hxx>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp> #include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <map> #include <map>
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::ucb; using namespace com::sun::star::ucb;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
using namespace com::sun::star::i18n; using namespace com::sun::star::i18n;
//=============================================================================
class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare > class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare >
{ {
Reference< XCollator > m_rCollator; Reference< XCollator > m_rCollator;
@@ -57,8 +53,6 @@ public:
virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException); virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException);
}; };
//=============================================================================
class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo > class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo >
{ {
Reference< XAnyCompare > m_rAnyCompare; Reference< XAnyCompare > m_rAnyCompare;
@@ -87,8 +81,6 @@ public:
static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& ); static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& );
}; };
//===========================================================================================
sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException) sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException)
{ {
sal_Int16 aResult = 0; sal_Int16 aResult = 0;
@@ -104,8 +96,6 @@ sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw
return aResult; return aResult;
} }
//===========================================================================================
Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException) Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException)
{ {
// for now only OUString properties compare is implemented // for now only OUString properties compare is implemented
@@ -127,7 +117,6 @@ void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments )
return; return;
} }
} }
} }
OUString SAL_CALL AnyCompareFactory::getImplementationName( ) throw( RuntimeException ) OUString SAL_CALL AnyCompareFactory::getImplementationName( ) throw( RuntimeException )
@@ -142,8 +131,7 @@ OUString SAL_CALL AnyCompareFactory::getImplementationName_static( )
sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException) sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException)
{ {
OUString aServiceName( "com.sun.star.ucb.AnyCompareFactory" ); return cppu::supportsService(this, ServiceName);
return aServiceName == ServiceName;
} }
Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException) Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException)

View File

@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "comphelper_module.hxx" #include "comphelper_module.hxx"
#include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/container/XIndexContainer.hpp>
@@ -25,6 +24,7 @@
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <cppuhelper/implbase2.hxx> #include <cppuhelper/implbase2.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <vector> #include <vector>
@@ -226,8 +226,7 @@ OUString SAL_CALL IndexedPropertyValuesContainer::getImplementationName_static(
sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException) sal_Bool SAL_CALL IndexedPropertyValuesContainer::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
{ {
OUString aServiceName( "com.sun.star.document.IndexedPropertyValues" ); return cppu::supportsService(this, ServiceName);
return aServiceName == ServiceName;
} }
::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) ::com::sun::star::uno::Sequence< OUString > SAL_CALL IndexedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)

View File

@@ -25,7 +25,7 @@
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <cppuhelper/implbase2.hxx> #include <cppuhelper/implbase2.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <map> #include <map>
@@ -197,8 +197,7 @@ OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static( )
sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException) sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
{ {
OUString aServiceName( "com.sun.star.document.NamedPropertyValues" ); return cppu::supportsService(this, ServiceName);
return aServiceName == ServiceName;
} }
::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
@@ -206,7 +205,6 @@ sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const OUString&
return getSupportedServiceNames_static(); return getSupportedServiceNames_static();
} }
::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static( ) ::com::sun::star::uno::Sequence< OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static( )
{ {
const OUString aServiceName( "com.sun.star.document.NamedPropertyValues" ); const OUString aServiceName( "com.sun.star.document.NamedPropertyValues" );

View File

@@ -25,6 +25,7 @@
#include "rtl/ustring.hxx" #include "rtl/ustring.hxx"
#include "comphelper/makesequence.hxx" #include "comphelper/makesequence.hxx"
#include <cppuhelper/supportsservice.hxx>
#include "DragSource.hxx" #include "DragSource.hxx"
#include "DragSourceContext.hxx" #include "DragSourceContext.hxx"
@@ -69,7 +70,6 @@ Sequence<OUString> dragSource_getSupportedServiceNames()
return makeSequence(OUString("com.sun.star.datatransfer.dnd.OleDragSource")); return makeSequence(OUString("com.sun.star.datatransfer.dnd.OleDragSource"));
} }
@implementation DragSourceHelper; @implementation DragSourceHelper;
-(DragSourceHelper*)initWithDragSource: (DragSource*) pds -(DragSourceHelper*)initWithDragSource: (DragSource*) pds
@@ -84,25 +84,21 @@ Sequence<OUString> dragSource_getSupportedServiceNames()
return self; return self;
} }
-(void)mouseDown: (NSEvent*)theEvent -(void)mouseDown: (NSEvent*)theEvent
{ {
mDragSource->saveMouseEvent(theEvent); mDragSource->saveMouseEvent(theEvent);
} }
-(void)mouseDragged: (NSEvent*)theEvent -(void)mouseDragged: (NSEvent*)theEvent
{ {
mDragSource->saveMouseEvent(theEvent); mDragSource->saveMouseEvent(theEvent);
} }
-(unsigned int)draggingSourceOperationMaskForLocal: (BOOL)isLocal -(unsigned int)draggingSourceOperationMaskForLocal: (BOOL)isLocal
{ {
return mDragSource->getSupportedDragOperations(isLocal); return mDragSource->getSupportedDragOperations(isLocal);
} }
-(void)draggedImage:(NSImage*)anImage beganAt:(NSPoint)aPoint -(void)draggedImage:(NSImage*)anImage beganAt:(NSPoint)aPoint
{ {
(void)anImage; (void)anImage;
@@ -116,7 +112,6 @@ Sequence<OUString> dragSource_getSupportedServiceNames()
mDragSource->mXDragSrcListener->dragEnter(dsde); mDragSource->mXDragSrcListener->dragEnter(dsde);
} }
-(void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation -(void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{ {
(void)anImage; (void)anImage;
@@ -137,7 +132,6 @@ Sequence<OUString> dragSource_getSupportedServiceNames()
mDragSource->mXDragSrcListener = uno::Reference<XDragSourceListener>(); mDragSource->mXDragSrcListener = uno::Reference<XDragSourceListener>();
} }
-(void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint -(void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint
{ {
(void)draggedImage; (void)draggedImage;
@@ -153,7 +147,6 @@ Sequence<OUString> dragSource_getSupportedServiceNames()
@end @end
DragSource::DragSource(): DragSource::DragSource():
WeakComponentImplHelper3<XDragSource, XInitialization, XServiceInfo>(m_aMutex), WeakComponentImplHelper3<XDragSource, XInitialization, XServiceInfo>(m_aMutex),
mView(NULL), mView(NULL),
@@ -163,7 +156,6 @@ DragSource::DragSource():
{ {
} }
DragSource::~DragSource() DragSource::~DragSource()
{ {
if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
@@ -171,7 +163,6 @@ DragSource::~DragSource()
[mDragSourceHelper release]; [mDragSourceHelper release];
} }
void SAL_CALL DragSource::initialize(const Sequence< Any >& aArguments) void SAL_CALL DragSource::initialize(const Sequence< Any >& aArguments)
throw(Exception) throw(Exception)
{ {
@@ -217,25 +208,18 @@ void SAL_CALL DragSource::initialize(const Sequence< Any >& aArguments)
[(id <MouseEventListener>)mView registerMouseEventListener: mDragSourceHelper]; [(id <MouseEventListener>)mView registerMouseEventListener: mDragSourceHelper];
} }
//----------------------------------------------------
// XDragSource
//----------------------------------------------------
sal_Bool SAL_CALL DragSource::isDragImageSupported( ) sal_Bool SAL_CALL DragSource::isDragImageSupported( )
throw(RuntimeException) throw(RuntimeException)
{ {
return true; return true;
} }
sal_Int32 SAL_CALL DragSource::getDefaultCursor( sal_Int8 /*dragAction*/ ) sal_Int32 SAL_CALL DragSource::getDefaultCursor( sal_Int8 /*dragAction*/ )
throw( IllegalArgumentException, RuntimeException) throw( IllegalArgumentException, RuntimeException)
{ {
return 0; return 0;
} }
void SAL_CALL DragSource::startDrag(const DragGestureEvent& trigger, void SAL_CALL DragSource::startDrag(const DragGestureEvent& trigger,
sal_Int8 sourceActions, sal_Int8 sourceActions,
sal_Int32 /*cursor*/, sal_Int32 /*cursor*/,
@@ -303,7 +287,6 @@ void SAL_CALL DragSource::startDrag(const DragGestureEvent& trigger,
g_DropSuccess = false; g_DropSuccess = false;
} }
// In order to initiate a D&D operation we need to // In order to initiate a D&D operation we need to
// provide the triggering mouse event which we get // provide the triggering mouse event which we get
// from the SalFrameView that is associated with // from the SalFrameView that is associated with
@@ -318,7 +301,6 @@ void DragSource::saveMouseEvent(NSEvent* theEvent)
mLastMouseEventBeforeStartDrag = theEvent; mLastMouseEventBeforeStartDrag = theEvent;
} }
/* isLocal indicates whether or not the DnD operation is OOo /* isLocal indicates whether or not the DnD operation is OOo
internal. internal.
*/ */
@@ -344,29 +326,19 @@ unsigned int DragSource::getSupportedDragOperations(bool isLocal) const
return srcActions; return srcActions;
} }
//################################
// XServiceInfo
//################################
OUString SAL_CALL DragSource::getImplementationName( ) throw (RuntimeException) OUString SAL_CALL DragSource::getImplementationName( ) throw (RuntimeException)
{ {
return dragSource_getImplementationName(); return dragSource_getImplementationName();
} }
sal_Bool SAL_CALL DragSource::supportsService( const OUString& ServiceName ) throw (RuntimeException) sal_Bool SAL_CALL DragSource::supportsService( const OUString& ServiceName ) throw (RuntimeException)
{ {
return ServiceName == "com.sun.star.datatransfer.dnd.OleDragSource"; return cppu::supportsService(this, ServiceName);
} }
Sequence< OUString > SAL_CALL DragSource::getSupportedServiceNames() throw (RuntimeException) Sequence< OUString > SAL_CALL DragSource::getSupportedServiceNames() throw (RuntimeException)
{ {
return dragSource_getSupportedServiceNames(); return dragSource_getSupportedServiceNames();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -20,25 +20,20 @@
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp> #include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp> #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
#include "comphelper/makesequence.hxx" #include "comphelper/makesequence.hxx"
#include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/interfacecontainer.hxx>
#include "clipboard.hxx" #include "clipboard.hxx"
#include "DropTarget.hxx" #include "DropTarget.hxx"
#include "DragActionConversion.hxx" #include "DragActionConversion.hxx"
#include "DragSource.hxx" #include "DragSource.hxx"
#include <rtl/ustring.h> #include <rtl/ustring.h>
#include <stdio.h> #include <stdio.h>
#include <premac.h> #include <premac.h>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <postmac.h> #include <postmac.h>
#include <osx/salframe.h> #include <osx/salframe.h>
#include <osx/salframeview.h> #include <osx/salframeview.h>
#include <cppuhelper/supportsservice.hxx>
using namespace cppu; using namespace cppu;
using namespace osl; using namespace osl;
@@ -54,26 +49,24 @@ using namespace comphelper;
OUString dropTarget_getImplementationName() OUString dropTarget_getImplementationName()
{ {
return OUString("com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"); return OUString("com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1");
} }
Sequence<OUString> dropTarget_getSupportedServiceNames() Sequence<OUString> dropTarget_getSupportedServiceNames()
{ {
return makeSequence(OUString("com.sun.star.datatransfer.dnd.OleDropTarget")); return makeSequence(OUString("com.sun.star.datatransfer.dnd.OleDropTarget"));
} }
namespace /* private */ namespace /* private */
{ {
// Cocoa's coordinate system has its origin lower-left, VCL's // Cocoa's coordinate system has its origin lower-left, VCL's
// coordinate system upper-left hence we need to transform // coordinate system upper-left hence we need to transform
// coordinates // coordinates
inline void CocoaToVCL(NSPoint& rPoint, const NSRect& bounds) inline void CocoaToVCL(NSPoint& rPoint, const NSRect& bounds)
{ {
rPoint.y = bounds.size.height - rPoint.y; rPoint.y = bounds.size.height - rPoint.y;
} }
} }
@@ -82,70 +75,62 @@ namespace /* private */
-(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt -(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt
{ {
self = [super init]; self = [super init];
if (self) if (self)
{ {
mDropTarget = pdt; mDropTarget = pdt;
} }
return self; return self;
} }
-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{ {
return mDropTarget->draggingEntered(sender); return mDropTarget->draggingEntered(sender);
} }
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender -(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{ {
return mDropTarget->draggingUpdated(sender); return mDropTarget->draggingUpdated(sender);
} }
-(void)draggingExited:(id <NSDraggingInfo>)sender -(void)draggingExited:(id <NSDraggingInfo>)sender
{ {
mDropTarget->draggingExited(sender); mDropTarget->draggingExited(sender);
} }
-(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender -(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{ {
return mDropTarget->prepareForDragOperation(sender); return mDropTarget->prepareForDragOperation(sender);
} }
-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ {
return mDropTarget->performDragOperation(sender); return mDropTarget->performDragOperation(sender);
} }
-(void)concludeDragOperation:(id <NSDraggingInfo>)sender -(void)concludeDragOperation:(id <NSDraggingInfo>)sender
{ {
mDropTarget->concludeDragOperation(sender); mDropTarget->concludeDragOperation(sender);
} }
@end @end
DropTarget::DropTarget() : DropTarget::DropTarget() :
WeakComponentImplHelper5<XInitialization, XDropTarget, XDropTargetDragContext, XDropTargetDropContext, XServiceInfo>(m_aMutex), WeakComponentImplHelper5<XInitialization, XDropTarget, XDropTargetDragContext, XDropTargetDropContext, XServiceInfo>(m_aMutex),
mView(nil), mView(nil),
mpFrame(NULL), mpFrame(NULL),
mDropTargetHelper(nil), mDropTargetHelper(nil),
mbActive(false), mbActive(false),
mDragSourceSupportedActions(DNDConstants::ACTION_NONE), mDragSourceSupportedActions(DNDConstants::ACTION_NONE),
mSelectedDropAction(DNDConstants::ACTION_NONE), mSelectedDropAction(DNDConstants::ACTION_NONE),
mDefaultActions(DNDConstants::ACTION_COPY_OR_MOVE | DNDConstants::ACTION_LINK | DNDConstants::ACTION_DEFAULT) mDefaultActions(DNDConstants::ACTION_COPY_OR_MOVE | DNDConstants::ACTION_LINK | DNDConstants::ACTION_DEFAULT)
{ {
mDataFlavorMapper = DataFlavorMapperPtr_t(new DataFlavorMapper()); mDataFlavorMapper = DataFlavorMapperPtr_t(new DataFlavorMapper());
} }
DropTarget::~DropTarget() DropTarget::~DropTarget()
{ {
if( AquaSalFrame::isAlive( mpFrame ) ) if( AquaSalFrame::isAlive( mpFrame ) )
@@ -153,121 +138,118 @@ DropTarget::~DropTarget()
[mDropTargetHelper release]; [mDropTargetHelper release];
} }
sal_Int8 DropTarget::determineDropAction(sal_Int8 dropActions, id sender) const sal_Int8 DropTarget::determineDropAction(sal_Int8 dropActions, id sender) const
{ {
sal_Int8 dropAct = dropActions; sal_Int8 dropAct = dropActions;
bool srcAndDestEqual = false; bool srcAndDestEqual = false;
if ([sender draggingSource] != nil) if ([sender draggingSource] != nil)
{ {
// Internal DnD // Internal DnD
NSView* destView = [[sender draggingDestinationWindow] contentView]; NSView* destView = [[sender draggingDestinationWindow] contentView];
srcAndDestEqual = (DragSource::g_DragSourceView == destView); srcAndDestEqual = (DragSource::g_DragSourceView == destView);
} }
// If ACTION_DEFAULT is set this means NSDragOperationGeneric // If ACTION_DEFAULT is set this means NSDragOperationGeneric
// has been set and we map this to ACTION_MOVE or ACTION_COPY // has been set and we map this to ACTION_MOVE or ACTION_COPY
// depending on whether or not source and dest are equal, // depending on whether or not source and dest are equal,
// this hopefully satisfies all parties // this hopefully satisfies all parties
if( (dropActions == DNDConstants::ACTION_DEFAULT) if( (dropActions == DNDConstants::ACTION_DEFAULT)
|| ((dropActions == mDragSourceSupportedActions) || ((dropActions == mDragSourceSupportedActions)
&& !(~mDragSourceSupportedActions & DNDConstants::ACTION_COPY_OR_MOVE ) ) ) && !(~mDragSourceSupportedActions & DNDConstants::ACTION_COPY_OR_MOVE ) ) )
{ {
dropAct = srcAndDestEqual ? DNDConstants::ACTION_MOVE : dropAct = srcAndDestEqual ? DNDConstants::ACTION_MOVE :
DNDConstants::ACTION_COPY; DNDConstants::ACTION_COPY;
} }
// if more than one drop actions have been specified // if more than one drop actions have been specified
// set ACTION_DEFAULT in order to let the drop target // set ACTION_DEFAULT in order to let the drop target
// decide which one to use // decide which one to use
else if (dropActions != DNDConstants::ACTION_NONE && else if (dropActions != DNDConstants::ACTION_NONE &&
dropActions != DNDConstants::ACTION_MOVE && dropActions != DNDConstants::ACTION_MOVE &&
dropActions != DNDConstants::ACTION_COPY && dropActions != DNDConstants::ACTION_COPY &&
dropActions != DNDConstants::ACTION_LINK) dropActions != DNDConstants::ACTION_LINK)
{ {
if (srcAndDestEqual) if (srcAndDestEqual)
{ {
dropAct = dropActions; dropAct = dropActions;
} }
else // source and destination are different else // source and destination are different
{ {
if (dropActions & DNDConstants::ACTION_COPY) if (dropActions & DNDConstants::ACTION_COPY)
dropAct = DNDConstants::ACTION_COPY; dropAct = DNDConstants::ACTION_COPY;
else if (dropActions & DNDConstants::ACTION_MOVE) else if (dropActions & DNDConstants::ACTION_MOVE)
dropAct = DNDConstants::ACTION_MOVE; dropAct = DNDConstants::ACTION_MOVE;
else if (dropActions & DNDConstants::ACTION_LINK) else if (dropActions & DNDConstants::ACTION_LINK)
dropAct = DNDConstants::ACTION_LINK; dropAct = DNDConstants::ACTION_LINK;
} }
dropAct |= DNDConstants::ACTION_DEFAULT; dropAct |= DNDConstants::ACTION_DEFAULT;
} }
return dropAct; return dropAct;
} }
NSDragOperation DropTarget::draggingEntered(id sender) NSDragOperation DropTarget::draggingEntered(id sender)
{ {
// Initially when DnD will be started no modifier key can be pressed yet // Initially when DnD will be started no modifier key can be pressed yet
// thus we are getting all actions that the drag source supports, we save // thus we are getting all actions that the drag source supports, we save
// this value because later the system masks the drag source actions if // this value because later the system masks the drag source actions if
// a modifier key will be pressed // a modifier key will be pressed
mDragSourceSupportedActions = SystemToOfficeDragActions([sender draggingSourceOperationMask]); mDragSourceSupportedActions = SystemToOfficeDragActions([sender draggingSourceOperationMask]);
// Only if the drop target is really interessted in the drag actions // Only if the drop target is really interessted in the drag actions
// supported by the source // supported by the source
if (mDragSourceSupportedActions & mDefaultActions) if (mDragSourceSupportedActions & mDefaultActions)
{ {
sal_Int8 currentAction = determineDropAction(mDragSourceSupportedActions, sender); sal_Int8 currentAction = determineDropAction(mDragSourceSupportedActions, sender);
NSRect bounds = [mView bounds]; NSRect bounds = [mView bounds];
NSPoint dragLocation = [sender draggedImageLocation]; NSPoint dragLocation = [sender draggedImageLocation];
CocoaToVCL(dragLocation, bounds); CocoaToVCL(dragLocation, bounds);
sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x); sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x);
sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y); sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y);
NSPasteboard* dragPboard = [sender draggingPasteboard]; NSPasteboard* dragPboard = [sender draggingPasteboard];
mXCurrentDragClipboard = new AquaClipboard(dragPboard, false); mXCurrentDragClipboard = new AquaClipboard(dragPboard, false);
uno::Reference<XTransferable> xTransferable = DragSource::g_XTransferable.is() ? uno::Reference<XTransferable> xTransferable = DragSource::g_XTransferable.is() ?
DragSource::g_XTransferable : mXCurrentDragClipboard->getContents(); DragSource::g_XTransferable : mXCurrentDragClipboard->getContents();
DropTargetDragEnterEvent dtdee(static_cast<OWeakObject*>(this), DropTargetDragEnterEvent dtdee(static_cast<OWeakObject*>(this),
0, 0,
this, this,
currentAction, currentAction,
posX, posX,
posY, posY,
mDragSourceSupportedActions, mDragSourceSupportedActions,
xTransferable->getTransferDataFlavors()); xTransferable->getTransferDataFlavors());
fire_dragEnter(dtdee); fire_dragEnter(dtdee);
} }
return OfficeToSystemDragActions(mSelectedDropAction); return OfficeToSystemDragActions(mSelectedDropAction);
} }
NSDragOperation DropTarget::draggingUpdated(id sender) NSDragOperation DropTarget::draggingUpdated(id sender)
{ {
sal_Int8 currentDragSourceActions = sal_Int8 currentDragSourceActions =
SystemToOfficeDragActions([sender draggingSourceOperationMask]); SystemToOfficeDragActions([sender draggingSourceOperationMask]);
NSDragOperation dragOp = NSDragOperationNone; NSDragOperation dragOp = NSDragOperationNone;
if (currentDragSourceActions & mDefaultActions) if (currentDragSourceActions & mDefaultActions)
{ {
sal_Int8 currentAction = determineDropAction(currentDragSourceActions, sender); sal_Int8 currentAction = determineDropAction(currentDragSourceActions, sender);
NSRect bounds = [mView bounds]; NSRect bounds = [mView bounds];
NSPoint dragLocation = [sender draggedImageLocation]; NSPoint dragLocation = [sender draggedImageLocation];
CocoaToVCL(dragLocation, bounds); CocoaToVCL(dragLocation, bounds);
sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x); sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x);
sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y); sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y);
DropTargetDragEvent dtde(static_cast<OWeakObject*>(this), DropTargetDragEvent dtde(static_cast<OWeakObject*>(this),
0, 0,
this, this,
currentAction, currentAction,
@@ -275,27 +257,26 @@ NSDragOperation DropTarget::draggingUpdated(id sender)
posY, posY,
mDragSourceSupportedActions); mDragSourceSupportedActions);
fire_dragOver(dtde); fire_dragOver(dtde);
// drag over callbacks likely have rendered something // drag over callbacks likely have rendered something
[mView setNeedsDisplay: TRUE]; [mView setNeedsDisplay: TRUE];
dragOp = OfficeToSystemDragActions(mSelectedDropAction); dragOp = OfficeToSystemDragActions(mSelectedDropAction);
//NSLog(@"Drag update: Source actions: %x proposed action %x selected action %x", mDragSourceSupportedActions, currentAction, mSelectedDropAction); //NSLog(@"Drag update: Source actions: %x proposed action %x selected action %x", mDragSourceSupportedActions, currentAction, mSelectedDropAction);
} }
if (dragOp == NSDragOperationNone) if (dragOp == NSDragOperationNone)
[[NSCursor operationNotAllowedCursor] set]; [[NSCursor operationNotAllowedCursor] set];
else if (dragOp == NSDragOperationCopy) else if (dragOp == NSDragOperationCopy)
[[NSCursor dragCopyCursor] set]; [[NSCursor dragCopyCursor] set];
else else
[[NSCursor arrowCursor] set]; [[NSCursor arrowCursor] set];
return dragOp; return dragOp;
} }
void DropTarget::draggingExited(id /*sender*/) void DropTarget::draggingExited(id /*sender*/)
{ {
DropTargetEvent dte(static_cast<OWeakObject*>(this), 0); DropTargetEvent dte(static_cast<OWeakObject*>(this), 0);
@@ -305,35 +286,33 @@ void DropTarget::draggingExited(id /*sender*/)
[[NSCursor arrowCursor] set]; [[NSCursor arrowCursor] set];
} }
BOOL DropTarget::prepareForDragOperation(id /*sender*/) BOOL DropTarget::prepareForDragOperation(id /*sender*/)
{ {
return 1; return 1;
} }
BOOL DropTarget::performDragOperation(id sender) BOOL DropTarget::performDragOperation(id sender)
{ {
bool bSuccess = false; bool bSuccess = false;
if (mSelectedDropAction != DNDConstants::ACTION_NONE) if (mSelectedDropAction != DNDConstants::ACTION_NONE)
{ {
uno::Reference<XTransferable> xTransferable = DragSource::g_XTransferable; uno::Reference<XTransferable> xTransferable = DragSource::g_XTransferable;
if (!DragSource::g_XTransferable.is()) if (!DragSource::g_XTransferable.is())
{ {
xTransferable = mXCurrentDragClipboard->getContents(); xTransferable = mXCurrentDragClipboard->getContents();
} }
NSRect bounds = [mView bounds]; NSRect bounds = [mView bounds];
NSPoint dragLocation = [sender draggedImageLocation]; NSPoint dragLocation = [sender draggedImageLocation];
CocoaToVCL(dragLocation, bounds); CocoaToVCL(dragLocation, bounds);
sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x); sal_Int32 posX = static_cast<sal_Int32>(dragLocation.x);
sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y); sal_Int32 posY = static_cast<sal_Int32>(dragLocation.y);
DropTargetDropEvent dtde(static_cast<OWeakObject*>(this), DropTargetDropEvent dtde(static_cast<OWeakObject*>(this),
0, 0,
this, this,
mSelectedDropAction, mSelectedDropAction,
@@ -342,15 +321,14 @@ BOOL DropTarget::performDragOperation(id sender)
mDragSourceSupportedActions, mDragSourceSupportedActions,
xTransferable); xTransferable);
fire_drop(dtde); fire_drop(dtde);
bSuccess = true; bSuccess = true;
} }
return bSuccess; return bSuccess;
} }
void DropTarget::concludeDragOperation(id /*sender*/) void DropTarget::concludeDragOperation(id /*sender*/)
{ {
mDragSourceSupportedActions = DNDConstants::ACTION_NONE; mDragSourceSupportedActions = DNDConstants::ACTION_NONE;
@@ -359,23 +337,21 @@ void DropTarget::concludeDragOperation(id /*sender*/)
[[NSCursor arrowCursor] set]; [[NSCursor arrowCursor] set];
} }
// called from WeakComponentImplHelperX::dispose
// WeakComponentImplHelper calls disposing before it destroys
// itself.
void SAL_CALL DropTarget::disposing()
{
}
// called from WeakComponentImplHelperX::dispose void SAL_CALL DropTarget::initialize(const Sequence< Any >& aArguments)
// WeakComponentImplHelper calls disposing before it destroys
// itself.
void SAL_CALL DropTarget::disposing()
{
}
void SAL_CALL DropTarget::initialize(const Sequence< Any >& aArguments)
throw(Exception) throw(Exception)
{ {
if (aArguments.getLength() < 2) if (aArguments.getLength() < 2)
{ {
throw RuntimeException("DropTarget::initialize: Cannot install window event handler", throw RuntimeException("DropTarget::initialize: Cannot install window event handler",
static_cast<OWeakObject*>(this)); static_cast<OWeakObject*>(this));
} }
Any pNSView = aArguments[0]; Any pNSView = aArguments[0];
sal_uInt64 tmp = 0; sal_uInt64 tmp = 0;
@@ -394,193 +370,168 @@ void DropTarget::concludeDragOperation(id /*sender*/)
unsigned int wndStyles = [wnd styleMask] & topWndStyle; unsigned int wndStyles = [wnd styleMask] & topWndStyle;
if (parentWnd == nil && (wndStyles == topWndStyle)) if (parentWnd == nil && (wndStyles == topWndStyle))
{ {
[wnd registerDraggingDestinationHandler:mDropTargetHelper]; [wnd registerDraggingDestinationHandler:mDropTargetHelper];
[wnd registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; [wnd registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
} }
} }
void SAL_CALL DropTarget::addDropTargetListener(const uno::Reference<XDropTargetListener>& dtl)
void SAL_CALL DropTarget::addDropTargetListener(const uno::Reference<XDropTargetListener>& dtl)
throw(RuntimeException) throw(RuntimeException)
{ {
rBHelper.addListener(::getCppuType(&dtl), dtl); rBHelper.addListener(::getCppuType(&dtl), dtl);
} }
void SAL_CALL DropTarget::removeDropTargetListener(const uno::Reference<XDropTargetListener>& dtl)
void SAL_CALL DropTarget::removeDropTargetListener(const uno::Reference<XDropTargetListener>& dtl)
throw(RuntimeException) throw(RuntimeException)
{ {
rBHelper.removeListener(::getCppuType(&dtl), dtl); rBHelper.removeListener(::getCppuType(&dtl), dtl);
} }
sal_Bool SAL_CALL DropTarget::isActive( ) throw(RuntimeException)
sal_Bool SAL_CALL DropTarget::isActive( ) throw(RuntimeException) {
{
return mbActive; return mbActive;
} }
void SAL_CALL DropTarget::setActive(sal_Bool active) throw(RuntimeException)
void SAL_CALL DropTarget::setActive(sal_Bool active) throw(RuntimeException) {
{
mbActive = active; mbActive = active;
} }
sal_Int8 SAL_CALL DropTarget::getDefaultActions() throw(RuntimeException)
sal_Int8 SAL_CALL DropTarget::getDefaultActions() throw(RuntimeException) {
{
return mDefaultActions; return mDefaultActions;
} }
void SAL_CALL DropTarget::setDefaultActions(sal_Int8 actions) throw(RuntimeException)
void SAL_CALL DropTarget::setDefaultActions(sal_Int8 actions) throw(RuntimeException) {
{
OSL_ENSURE( actions < 8, "No valid default actions"); OSL_ENSURE( actions < 8, "No valid default actions");
mDefaultActions= actions; mDefaultActions= actions;
} }
void SAL_CALL DropTarget::acceptDrag(sal_Int8 dragOperation) throw (RuntimeException)
// XDropTargetDragContext {
void SAL_CALL DropTarget::acceptDrag(sal_Int8 dragOperation) throw (RuntimeException)
{
mSelectedDropAction = dragOperation; mSelectedDropAction = dragOperation;
} }
void SAL_CALL DropTarget::rejectDrag() throw (RuntimeException)
void SAL_CALL DropTarget::rejectDrag() throw (RuntimeException) {
{
mSelectedDropAction = DNDConstants::ACTION_NONE; mSelectedDropAction = DNDConstants::ACTION_NONE;
} }
void SAL_CALL DropTarget::acceptDrop(sal_Int8 dropOperation) throw( RuntimeException)
//XDropTargetDropContext {
void SAL_CALL DropTarget::acceptDrop(sal_Int8 dropOperation) throw( RuntimeException)
{
mSelectedDropAction = dropOperation; mSelectedDropAction = dropOperation;
} }
void SAL_CALL DropTarget::rejectDrop() throw (RuntimeException)
void SAL_CALL DropTarget::rejectDrop() throw (RuntimeException) {
{
mSelectedDropAction = DNDConstants::ACTION_NONE; mSelectedDropAction = DNDConstants::ACTION_NONE;
} }
void SAL_CALL DropTarget::dropComplete(sal_Bool success) throw (RuntimeException)
void SAL_CALL DropTarget::dropComplete(sal_Bool success) throw (RuntimeException) {
{
// Reset the internal transferable used as shortcut in case this is // Reset the internal transferable used as shortcut in case this is
// an internal D&D operation // an internal D&D operation
DragSource::g_XTransferable = uno::Reference<XTransferable>(); DragSource::g_XTransferable = uno::Reference<XTransferable>();
DragSource::g_DropSuccessSet = true; DragSource::g_DropSuccessSet = true;
DragSource::g_DropSuccess = success; DragSource::g_DropSuccess = success;
} }
void DropTarget::fire_drop( const DropTargetDropEvent& dte)
void DropTarget::fire_drop( const DropTargetDropEvent& dte) {
{ OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
if( pContainer) if( pContainer)
{ {
OInterfaceIteratorHelper iter( *pContainer); OInterfaceIteratorHelper iter( *pContainer);
while( iter.hasMoreElements()) while( iter.hasMoreElements())
{ {
uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next()));
try { listener->drop( dte); } try { listener->drop( dte); }
catch(RuntimeException&) {} catch(RuntimeException&) {}
} }
} }
} }
void DropTarget::fire_dragEnter(const DropTargetDragEnterEvent& e)
void DropTarget::fire_dragEnter(const DropTargetDragEnterEvent& e) {
{ OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
if( pContainer) if( pContainer)
{ {
OInterfaceIteratorHelper iter( *pContainer); OInterfaceIteratorHelper iter( *pContainer);
while( iter.hasMoreElements()) while( iter.hasMoreElements())
{ {
uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next()));
try { listener->dragEnter( e); } try { listener->dragEnter( e); }
catch (RuntimeException&) {} catch (RuntimeException&) {}
} }
} }
} }
void DropTarget::fire_dragExit(const DropTargetEvent& dte)
void DropTarget::fire_dragExit(const DropTargetEvent& dte) {
{ OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
if( pContainer) if( pContainer)
{ {
OInterfaceIteratorHelper iter( *pContainer); OInterfaceIteratorHelper iter( *pContainer);
while( iter.hasMoreElements()) while( iter.hasMoreElements())
{ {
uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next()));
try { listener->dragExit( dte); } try { listener->dragExit( dte); }
catch (RuntimeException&) {} catch (RuntimeException&) {}
} }
} }
} }
void DropTarget::fire_dragOver(const DropTargetDragEvent& dtde)
void DropTarget::fire_dragOver(const DropTargetDragEvent& dtde) {
{ OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
if( pContainer) if( pContainer)
{ {
OInterfaceIteratorHelper iter( *pContainer ); OInterfaceIteratorHelper iter( *pContainer );
while( iter.hasMoreElements()) while( iter.hasMoreElements())
{ {
uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next()));
try { listener->dragOver( dtde); } try { listener->dragOver( dtde); }
catch (RuntimeException&) {} catch (RuntimeException&) {}
} }
} }
} }
void DropTarget::fire_dropActionChanged(const DropTargetDragEvent& dtde)
void DropTarget::fire_dropActionChanged(const DropTargetDragEvent& dtde) {
{ OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
OInterfaceContainerHelper* pContainer= rBHelper.getContainer( getCppuType( (uno::Reference<XDropTargetListener>* )0 ) );
if( pContainer) if( pContainer)
{ {
OInterfaceIteratorHelper iter( *pContainer); OInterfaceIteratorHelper iter( *pContainer);
while( iter.hasMoreElements()) while( iter.hasMoreElements())
{ {
uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next())); uno::Reference<XDropTargetListener> listener( static_cast<XDropTargetListener*>( iter.next()));
try { listener->dropActionChanged( dtde); } try { listener->dropActionChanged( dtde); }
catch (RuntimeException&) {} catch (RuntimeException&) {}
} }
} }
} }
OUString SAL_CALL DropTarget::getImplementationName() throw (RuntimeException)
// XServiceInfo {
OUString SAL_CALL DropTarget::getImplementationName() throw (RuntimeException)
{
return dropTarget_getImplementationName(); return dropTarget_getImplementationName();
} }
sal_Bool SAL_CALL DropTarget::supportsService( const OUString& ServiceName ) throw (RuntimeException)
{
return cppu::supportsService(this, ServiceName);
}
sal_Bool SAL_CALL DropTarget::supportsService( const OUString& ServiceName ) throw (RuntimeException) Sequence< OUString > SAL_CALL DropTarget::getSupportedServiceNames( ) throw (RuntimeException)
{ {
return ServiceName == "com.sun.star.datatransfer.dnd.OleDropTarget";
}
Sequence< OUString > SAL_CALL DropTarget::getSupportedServiceNames( ) throw (RuntimeException)
{
return dropTarget_getSupportedServiceNames(); return dropTarget_getSupportedServiceNames();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -24,7 +24,7 @@
#include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp> #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
#include "comphelper/makesequence.hxx" #include "comphelper/makesequence.hxx"
#include "comphelper/processfactory.hxx" #include "comphelper/processfactory.hxx"
#include <cppuhelper/supportsservice.hxx>
#include <boost/assert.hpp> #include <boost/assert.hpp>
using namespace com::sun::star::datatransfer; using namespace com::sun::star::datatransfer;
@@ -68,7 +68,6 @@ using namespace comphelper;
@end @end
OUString clipboard_getImplementationName() OUString clipboard_getImplementationName()
{ {
return OUString("com.sun.star.datatransfer.clipboard.AquaClipboard"); return OUString("com.sun.star.datatransfer.clipboard.AquaClipboard");
@@ -79,7 +78,6 @@ Sequence<OUString> clipboard_getSupportedServiceNames()
return makeSequence(OUString("com.sun.star.datatransfer.clipboard.SystemClipboard")); return makeSequence(OUString("com.sun.star.datatransfer.clipboard.SystemClipboard"));
} }
AquaClipboard::AquaClipboard(NSPasteboard* pasteboard, bool bUseSystemPasteboard) : AquaClipboard::AquaClipboard(NSPasteboard* pasteboard, bool bUseSystemPasteboard) :
WeakComponentImplHelper3<XSystemClipboard, XFlushableClipboard, XServiceInfo>(m_aMutex), WeakComponentImplHelper3<XSystemClipboard, XFlushableClipboard, XServiceInfo>(m_aMutex),
mIsSystemPasteboard(bUseSystemPasteboard) mIsSystemPasteboard(bUseSystemPasteboard)
@@ -88,82 +86,80 @@ AquaClipboard::AquaClipboard(NSPasteboard* pasteboard, bool bUseSystemPasteboard
mrXMimeCntFactory = MimeContentTypeFactory::create(xContext); mrXMimeCntFactory = MimeContentTypeFactory::create(xContext);
mpDataFlavorMapper = DataFlavorMapperPtr_t(new DataFlavorMapper()); mpDataFlavorMapper = DataFlavorMapperPtr_t(new DataFlavorMapper());
if (pasteboard != NULL) if (pasteboard != NULL)
{ {
mPasteboard = pasteboard; mPasteboard = pasteboard;
mIsSystemPasteboard = false; mIsSystemPasteboard = false;
} }
else else
{ {
mPasteboard = bUseSystemPasteboard ? [NSPasteboard generalPasteboard] : mPasteboard = bUseSystemPasteboard ? [NSPasteboard generalPasteboard] :
[NSPasteboard pasteboardWithName: NSDragPboard]; [NSPasteboard pasteboardWithName: NSDragPboard];
if (mPasteboard == nil) if (mPasteboard == nil)
{ {
throw RuntimeException("AquaClipboard: Cannot create Cocoa pasteboard", throw RuntimeException("AquaClipboard: Cannot create Cocoa pasteboard",
static_cast<XClipboardEx*>(this)); static_cast<XClipboardEx*>(this));
} }
} }
[mPasteboard retain]; [mPasteboard retain];
mEventListener = [[EventListener alloc] initWithAquaClipboard: this]; mEventListener = [[EventListener alloc] initWithAquaClipboard: this];
if (mEventListener == nil) if (mEventListener == nil)
{ {
[mPasteboard release]; [mPasteboard release];
throw RuntimeException( throw RuntimeException(
OUString("AquaClipboard: Cannot create pasteboard change listener"), OUString("AquaClipboard: Cannot create pasteboard change listener"),
static_cast<XClipboardEx*>(this)); static_cast<XClipboardEx*>(this));
} }
if (mIsSystemPasteboard) if (mIsSystemPasteboard)
{ {
NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver: mEventListener [notificationCenter addObserver: mEventListener
selector: @selector(applicationDidBecomeActive:) selector: @selector(applicationDidBecomeActive:)
name: @"NSApplicationDidBecomeActiveNotification" name: @"NSApplicationDidBecomeActiveNotification"
object: [NSApplication sharedApplication]]; object: [NSApplication sharedApplication]];
} }
mPasteboardChangeCount = [mPasteboard changeCount]; mPasteboardChangeCount = [mPasteboard changeCount];
} }
AquaClipboard::~AquaClipboard() AquaClipboard::~AquaClipboard()
{ {
if (mIsSystemPasteboard) if (mIsSystemPasteboard)
{ {
[[NSNotificationCenter defaultCenter] removeObserver: mEventListener]; [[NSNotificationCenter defaultCenter] removeObserver: mEventListener];
} }
[mEventListener disposing]; [mEventListener disposing];
[mEventListener release]; [mEventListener release];
[mPasteboard release]; [mPasteboard release];
} }
Reference<XTransferable> SAL_CALL AquaClipboard::getContents() throw(RuntimeException) Reference<XTransferable> SAL_CALL AquaClipboard::getContents() throw(RuntimeException)
{ {
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
// Shortcut: If we are clipboard owner already we don't need // Shortcut: If we are clipboard owner already we don't need
// to drag the data through the system clipboard // to drag the data through the system clipboard
if (mXClipboardContent.is()) if (mXClipboardContent.is())
{ {
return mXClipboardContent; return mXClipboardContent;
} }
return Reference<XTransferable>(new OSXTransferable(mrXMimeCntFactory, return Reference<XTransferable>(new OSXTransferable(mrXMimeCntFactory,
mpDataFlavorMapper, mpDataFlavorMapper,
mPasteboard)); mPasteboard));
} }
void SAL_CALL AquaClipboard::setContents(const Reference<XTransferable>& xTransferable, void SAL_CALL AquaClipboard::setContents(const Reference<XTransferable>& xTransferable,
const Reference<XClipboardOwner>& xClipboardOwner) const Reference<XClipboardOwner>& xClipboardOwner)
throw( RuntimeException ) throw( RuntimeException )
@@ -194,19 +190,16 @@ void SAL_CALL AquaClipboard::setContents(const Reference<XTransferable>& xTransf
fireClipboardChangedEvent(); fireClipboardChangedEvent();
} }
OUString SAL_CALL AquaClipboard::getName() throw( RuntimeException ) OUString SAL_CALL AquaClipboard::getName() throw( RuntimeException )
{ {
return OUString(); return OUString();
} }
sal_Int8 SAL_CALL AquaClipboard::getRenderingCapabilities() throw( RuntimeException ) sal_Int8 SAL_CALL AquaClipboard::getRenderingCapabilities() throw( RuntimeException )
{ {
return 0; return 0;
} }
void SAL_CALL AquaClipboard::addClipboardListener(const Reference< XClipboardListener >& listener) void SAL_CALL AquaClipboard::addClipboardListener(const Reference< XClipboardListener >& listener)
throw( RuntimeException ) throw( RuntimeException )
{ {
@@ -219,7 +212,6 @@ void SAL_CALL AquaClipboard::addClipboardListener(const Reference< XClipboardLis
mClipboardListeners.push_back(listener); mClipboardListeners.push_back(listener);
} }
void SAL_CALL AquaClipboard::removeClipboardListener(const Reference< XClipboardListener >& listener) void SAL_CALL AquaClipboard::removeClipboardListener(const Reference< XClipboardListener >& listener)
throw( RuntimeException ) throw( RuntimeException )
{ {
@@ -232,7 +224,6 @@ void SAL_CALL AquaClipboard::removeClipboardListener(const Reference< XClipboard
mClipboardListeners.remove(listener); mClipboardListeners.remove(listener);
} }
void AquaClipboard::applicationDidBecomeActive(NSNotification*) void AquaClipboard::applicationDidBecomeActive(NSNotification*)
{ {
ClearableMutexGuard aGuard(m_aMutex); ClearableMutexGuard aGuard(m_aMutex);
@@ -263,7 +254,6 @@ void AquaClipboard::applicationDidBecomeActive(NSNotification*)
} }
} }
void AquaClipboard::fireClipboardChangedEvent() void AquaClipboard::fireClipboardChangedEvent()
{ {
ClearableMutexGuard aGuard(m_aMutex); ClearableMutexGuard aGuard(m_aMutex);
@@ -272,33 +262,31 @@ void AquaClipboard::fireClipboardChangedEvent()
ClipboardEvent aEvent; ClipboardEvent aEvent;
if (listeners.begin() != listeners.end()) if (listeners.begin() != listeners.end())
{ {
aEvent = ClipboardEvent(static_cast<OWeakObject*>(this), getContents()); aEvent = ClipboardEvent(static_cast<OWeakObject*>(this), getContents());
} }
aGuard.clear(); aGuard.clear();
while (listeners.begin() != listeners.end()) while (listeners.begin() != listeners.end())
{ {
if (listeners.front().is()) if (listeners.front().is())
{ {
try { listeners.front()->changedContents(aEvent); } try { listeners.front()->changedContents(aEvent); }
catch (RuntimeException&) { } catch (RuntimeException&) { }
} }
listeners.pop_front(); listeners.pop_front();
} }
} }
void AquaClipboard::fireLostClipboardOwnershipEvent(Reference<XClipboardOwner> oldOwner, Reference<XTransferable> oldContent) void AquaClipboard::fireLostClipboardOwnershipEvent(Reference<XClipboardOwner> oldOwner, Reference<XTransferable> oldContent)
{ {
BOOST_ASSERT(oldOwner.is()); BOOST_ASSERT(oldOwner.is());
try { oldOwner->lostOwnership(static_cast<XClipboardEx*>(this), oldContent); } try { oldOwner->lostOwnership(static_cast<XClipboardEx*>(this), oldContent); }
catch(RuntimeException&) { } catch(RuntimeException&) { }
} }
void AquaClipboard::provideDataForType(NSPasteboard* sender, const NSString* type) void AquaClipboard::provideDataForType(NSPasteboard* sender, const NSString* type)
{ {
if( mXClipboardContent.is() ) if( mXClipboardContent.is() )
@@ -314,17 +302,12 @@ void AquaClipboard::provideDataForType(NSPasteboard* sender, const NSString* typ
} }
} }
//------------------------------------------------
// XFlushableClipboard
//------------------------------------------------
void SAL_CALL AquaClipboard::flushClipboard() void SAL_CALL AquaClipboard::flushClipboard()
throw(RuntimeException) throw(RuntimeException)
{ {
if (mXClipboardContent.is()) if (mXClipboardContent.is())
{ {
Sequence<DataFlavor> flavorList = mXClipboardContent->getTransferDataFlavors(); Sequence<DataFlavor> flavorList = mXClipboardContent->getTransferDataFlavors();
sal_uInt32 nFlavors = flavorList.getLength(); sal_uInt32 nFlavors = flavorList.getLength();
bool bInternal(false); bool bInternal(false);
@@ -341,32 +324,24 @@ void SAL_CALL AquaClipboard::flushClipboard()
} }
} }
NSPasteboard* AquaClipboard::getPasteboard() const NSPasteboard* AquaClipboard::getPasteboard() const
{ {
return mPasteboard; return mPasteboard;
} }
//-------------------------------------------------
// XServiceInfo
//-------------------------------------------------
OUString SAL_CALL AquaClipboard::getImplementationName() throw( RuntimeException ) OUString SAL_CALL AquaClipboard::getImplementationName() throw( RuntimeException )
{ {
return clipboard_getImplementationName(); return clipboard_getImplementationName();
} }
sal_Bool SAL_CALL AquaClipboard::supportsService( const OUString& /*ServiceName*/ ) throw( RuntimeException ) sal_Bool SAL_CALL AquaClipboard::supportsService( const OUString& /*ServiceName*/ ) throw( RuntimeException )
{ {
return sal_False; return sal_False;
} }
Sequence< OUString > SAL_CALL AquaClipboard::getSupportedServiceNames() throw( RuntimeException ) Sequence< OUString > SAL_CALL AquaClipboard::getSupportedServiceNames() throw( RuntimeException )
{ {
return clipboard_getSupportedServiceNames(); return clipboard_getSupportedServiceNames();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */