/* -*- 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 "clipboard.hxx" #include "DataFlavorMapping.hxx" #include "OSXTransferable.hxx" #include #include "comphelper/processfactory.hxx" #include using namespace com::sun::star::datatransfer; using namespace com::sun::star::datatransfer::clipboard; using namespace com::sun::star::lang; using namespace com::sun::star::uno; using namespace cppu; using namespace osl; using namespace std; using namespace comphelper; @implementation EventListener; -(EventListener*)initWithAquaClipboard: (AquaClipboard*) pcb { self = [super init]; if (self) pAquaClipboard = pcb; return self; } -(void)pasteboard:(NSPasteboard*)sender provideDataForType:(const NSString*)type { if( pAquaClipboard ) pAquaClipboard->provideDataForType(sender, type); } -(void)applicationDidBecomeActive:(NSNotification*)aNotification { if( pAquaClipboard ) pAquaClipboard->applicationDidBecomeActive(aNotification); } -(void)disposing { pAquaClipboard = nullptr; } @end OUString clipboard_getImplementationName() { return OUString("com.sun.star.datatransfer.clipboard.AquaClipboard"); } Sequence clipboard_getSupportedServiceNames() { return { OUString("com.sun.star.datatransfer.clipboard.SystemClipboard") }; } AquaClipboard::AquaClipboard(NSPasteboard* pasteboard, bool bUseSystemPasteboard) : WeakComponentImplHelper(m_aMutex), mIsSystemPasteboard(bUseSystemPasteboard) { Reference xContext = comphelper::getProcessComponentContext(); mrXMimeCntFactory = MimeContentTypeFactory::create(xContext); mpDataFlavorMapper = DataFlavorMapperPtr_t(new DataFlavorMapper()); if (pasteboard != nullptr) { mPasteboard = pasteboard; mIsSystemPasteboard = false; } else { mPasteboard = bUseSystemPasteboard ? [NSPasteboard generalPasteboard] : [NSPasteboard pasteboardWithName: NSDragPboard]; if (mPasteboard == nil) { throw RuntimeException("AquaClipboard: Cannot create Cocoa pasteboard", static_cast(this)); } } [mPasteboard retain]; mEventListener = [[EventListener alloc] initWithAquaClipboard: this]; if (mEventListener == nil) { [mPasteboard release]; throw RuntimeException( "AquaClipboard: Cannot create pasteboard change listener", static_cast(this)); } if (mIsSystemPasteboard) { NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver: mEventListener selector: @selector(applicationDidBecomeActive:) name: @"NSApplicationDidBecomeActiveNotification" object: [NSApplication sharedApplication]]; } mPasteboardChangeCount = [mPasteboard changeCount]; } AquaClipboard::~AquaClipboard() { if (mIsSystemPasteboard) { [[NSNotificationCenter defaultCenter] removeObserver: mEventListener]; } [mEventListener disposing]; [mEventListener release]; [mPasteboard release]; } Reference SAL_CALL AquaClipboard::getContents() throw(RuntimeException, std::exception) { MutexGuard aGuard(m_aMutex); // Shortcut: If we are clipboard owner already we don't need // to drag the data through the system clipboard if (mXClipboardContent.is()) { return mXClipboardContent; } return Reference(new OSXTransferable(mrXMimeCntFactory, mpDataFlavorMapper, mPasteboard)); } void SAL_CALL AquaClipboard::setContents(const Reference& xTransferable, const Reference& xClipboardOwner) throw( RuntimeException, std::exception ) { NSArray* types = xTransferable.is() ? mpDataFlavorMapper->flavorSequenceToTypesArray(xTransferable->getTransferDataFlavors()) : [NSArray array]; ClearableMutexGuard aGuard(m_aMutex); Reference oldOwner(mXClipboardOwner); mXClipboardOwner = xClipboardOwner; Reference oldContent(mXClipboardContent); mXClipboardContent = xTransferable; mPasteboardChangeCount = [mPasteboard declareTypes: types owner: mEventListener]; aGuard.clear(); // if we are already the owner of the clipboard // then fire lost ownership event if (oldOwner.is()) { fireLostClipboardOwnershipEvent(oldOwner, oldContent); } fireClipboardChangedEvent(); } OUString SAL_CALL AquaClipboard::getName() throw( RuntimeException, std::exception ) { return OUString(); } sal_Int8 SAL_CALL AquaClipboard::getRenderingCapabilities() throw( RuntimeException, std::exception ) { return 0; } void SAL_CALL AquaClipboard::addClipboardListener(const Reference< XClipboardListener >& listener) throw( RuntimeException, std::exception ) { MutexGuard aGuard(m_aMutex); if (!listener.is()) throw IllegalArgumentException("empty reference", static_cast(this), 1); mClipboardListeners.push_back(listener); } void SAL_CALL AquaClipboard::removeClipboardListener(const Reference< XClipboardListener >& listener) throw( RuntimeException, std::exception ) { MutexGuard aGuard(m_aMutex); if (!listener.is()) throw IllegalArgumentException("empty reference", static_cast(this), 1); mClipboardListeners.remove(listener); } void AquaClipboard::applicationDidBecomeActive(NSNotification*) { ClearableMutexGuard aGuard(m_aMutex); int currentPboardChgCount = [mPasteboard changeCount]; if (currentPboardChgCount != mPasteboardChangeCount) { mPasteboardChangeCount = currentPboardChgCount; // Clear clipboard content and owner and send lostOwnership // notification to the old clipboard owner as well as // ClipboardChanged notification to any clipboard listener Reference oldOwner(mXClipboardOwner); mXClipboardOwner.clear(); Reference oldContent(mXClipboardContent); mXClipboardContent.clear(); aGuard.clear(); if (oldOwner.is()) { fireLostClipboardOwnershipEvent(oldOwner, oldContent); } fireClipboardChangedEvent(); } } void AquaClipboard::fireClipboardChangedEvent() { ClearableMutexGuard aGuard(m_aMutex); list > listeners(mClipboardListeners); ClipboardEvent aEvent; if (!listeners.empty()) { aEvent = ClipboardEvent(static_cast(this), getContents()); } aGuard.clear(); while (!listeners.empty()) { if (listeners.front().is()) { try { listeners.front()->changedContents(aEvent); } catch (RuntimeException&) { } } listeners.pop_front(); } } void AquaClipboard::fireLostClipboardOwnershipEvent(Reference oldOwner, Reference oldContent) { assert(oldOwner.is()); try { oldOwner->lostOwnership(static_cast(this), oldContent); } catch(RuntimeException&) { } } void AquaClipboard::provideDataForType(NSPasteboard* sender, const NSString* type) { if( mXClipboardContent.is() ) { DataProviderPtr_t dp = mpDataFlavorMapper->getDataProvider(type, mXClipboardContent); NSData* pBoardData = nullptr; if (dp.get() != nullptr) { pBoardData = (NSData*)dp->getSystemData(); [sender setData: pBoardData forType:const_cast(type)]; } } } void SAL_CALL AquaClipboard::flushClipboard() throw(RuntimeException, std::exception) { if (mXClipboardContent.is()) { Sequence flavorList = mXClipboardContent->getTransferDataFlavors(); sal_uInt32 nFlavors = flavorList.getLength(); bool bInternal(false); for (sal_uInt32 i = 0; i < nFlavors; i++) { const NSString* sysType = mpDataFlavorMapper->openOfficeToSystemFlavor(flavorList[i], bInternal); if (sysType != nullptr) { provideDataForType(mPasteboard, sysType); } } mXClipboardContent.clear(); } } NSPasteboard* AquaClipboard::getPasteboard() const { return mPasteboard; } OUString SAL_CALL AquaClipboard::getImplementationName() throw( RuntimeException, std::exception ) { return clipboard_getImplementationName(); } sal_Bool SAL_CALL AquaClipboard::supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) { return cppu::supportsService(this, ServiceName); } Sequence< OUString > SAL_CALL AquaClipboard::getSupportedServiceNames() throw( RuntimeException, std::exception ) { return clipboard_getSupportedServiceNames(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ base-preview'>feature/base-preview LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2019-07-31Improved loplugin:stringconstant (now that GCC 7 supports it): svxStephan Bergmann
Change-Id: Idbdee862f96a3d9e6baaa7203528a423c017eb80 Reviewed-on: https://gerrit.libreoffice.org/76640 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-02-26loplugin:oncevar extend to tools/gen.hxx typesNoel Grandin
Change-Id: I5c75875da44334569c02e2ff039b33c38397a0a2 Reviewed-on: https://gerrit.libreoffice.org/50283 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-11-18RotateFlyFrame3: Corrected interactive CropArmin Le Grand
To correct interactive Crop in transformed states, I had to rework some stuff involved that anyways was in a non optimal state. Added functionality to translate the object to make Crop seem to work more seamlessly. Some mapping was needed to make the Cropped, transformed object to be in the correct relative position to the uncropped, untransfomed one. Restructured TransformableSwFrame to directly re-create last non-transformed SwFrame(s) from the SwFrameAreaDefinition from the current Transformations, offering the untransformed SwRect(s) now for usage. Identified and corrected error when FlyFrame was translated using keyboard, the accessing method needed to adapt position in the transformed case. Started to look at Contour stuff, adapted a set contour to be correctly used by adapting it as needed in the transformed case. Change-Id: I0d5f14958bcd6f826b9abd53f1f47b7d0bc5a0e2
2017-06-27loplugin:oncevar in svxNoel Grandin
Change-Id: I22a3a13e059ac7d3479f12860564fe3eb1b55e44 Reviewed-on: https://gerrit.libreoffice.org/39282 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-12convert SdrLayerId to strong_intNoel Grandin
Also - rename SetOfByte to SdrLayerIDSet - add asserts in SdrLayerAdmin::GetUniqueLayerID so that we don't allocate overlapping SdrLayerID values - add a new constant SDRLAYERPOS_NOTFOUND to be returned from SdrLayerAdmin::GetLayerPos Change-Id: I3bb3489f9338e3d02c4040bcbd811744699941c8 Reviewed-on: https://gerrit.libreoffice.org/37467 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2016-10-01support crop and rotating for drawinglayer object in UI testingMarkus Mohrhard
Change-Id: I57a9a43dc5289a9a987e4bf54a3c8d8d40824e67 Reviewed-on: https://gerrit.libreoffice.org/29421 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
2016-10-01add resizing support to drawinglayer ui test objectsMarkus Mohrhard
Change-Id: Ic17b32c25677855388ff49f2f7daeb1a84557fde Reviewed-on: https://gerrit.libreoffice.org/29419 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Jenkins <ci@libreoffice.org>
2016-10-01add initial drawinglayer support to UI testing frameworkMarkus Mohrhard
Change-Id: Id0450cdf655accb6bd1a50871e83d5c8ecdaab5f Reviewed-on: https://gerrit.libreoffice.org/29417 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>