calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / ios / clipboard.cxx
blob61530b926e2aa2a1c5710b44772ebc3009ee8348
1 /* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ios/iosinst.hxx"
21 #include "quartz/utils.h"
23 #include "clipboard.hxx"
25 #include "DataFlavorMapping.hxx"
26 #include "iOSTransferable.hxx"
27 #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
28 #include <com/sun/star/lang/IllegalArgumentException.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <cppuhelper/supportsservice.hxx>
32 iOSClipboard::iOSClipboard()
33 : WeakComponentImplHelper<XSystemClipboard, XServiceInfo>(m_aMutex)
35 auto xContext = comphelper::getProcessComponentContext();
37 mrXMimeCntFactory = css::datatransfer::MimeContentTypeFactory::create(xContext);
39 mpDataFlavorMapper.reset(new DataFlavorMapper());
42 iOSClipboard::~iOSClipboard() {}
44 css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL iOSClipboard::getContents()
46 osl::MutexGuard aGuard(m_aMutex);
48 return css::uno::Reference<css::datatransfer::XTransferable>(
49 new iOSTransferable(mrXMimeCntFactory, mpDataFlavorMapper));
52 void SAL_CALL iOSClipboard::setContents(
53 const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
54 const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& /*xClipboardOwner*/)
56 NSArray* types = xTransferable.is() ? mpDataFlavorMapper->flavorSequenceToTypesArray(
57 xTransferable->getTransferDataFlavors())
58 : [NSArray array];
60 osl::ClearableMutexGuard aGuard(m_aMutex);
62 NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:1];
63 NSArray* array = @[ dict ];
65 for (sal_uInt32 i = 0; i < [types count]; ++i)
67 DataProviderPtr_t dp = mpDataFlavorMapper->getDataProvider(types[i], xTransferable);
69 if (dp.get() != nullptr)
71 NSData* pBoardData = (NSData*)dp->getSystemData();
72 dict[types[i]] = pBoardData;
75 SAL_INFO("vcl.ios.clipboard", "Setting pasteboard items: " << NSDictionaryKeysToOUString(dict));
76 [[UIPasteboard generalPasteboard] setItems:array options:@{}];
78 // We don't keep a copy of the clipboard contents around in-process, so fire the lost clipboard
79 // ownership event right away.
80 // fireLostClipboardOwnershipEvent(xClipboardOwner, xTransferable);
82 // fireClipboardChangedEvent(xTransferable);
85 OUString SAL_CALL iOSClipboard::getName() { return OUString(); }
87 sal_Int8 SAL_CALL iOSClipboard::getRenderingCapabilities() { return 0; }
89 void SAL_CALL iOSClipboard::addClipboardListener(
90 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
92 osl::MutexGuard aGuard(m_aMutex);
94 if (!listener.is())
95 throw css::lang::IllegalArgumentException(
96 "empty reference", static_cast<css::datatransfer::clipboard::XClipboardEx*>(this), 1);
98 mClipboardListeners.push_back(listener);
101 void SAL_CALL iOSClipboard::removeClipboardListener(
102 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
104 osl::MutexGuard aGuard(m_aMutex);
106 if (!listener.is())
107 throw css::lang::IllegalArgumentException(
108 "empty reference", static_cast<css::datatransfer::clipboard::XClipboardEx*>(this), 1);
110 mClipboardListeners.remove(listener);
113 void iOSClipboard::fireClipboardChangedEvent(
114 css::uno::Reference<css::datatransfer::XTransferable> xNewContents)
116 osl::ClearableMutexGuard aGuard(m_aMutex);
118 std::list<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> listeners(
119 mClipboardListeners);
120 css::datatransfer::clipboard::ClipboardEvent aEvent;
122 if (!listeners.empty())
124 aEvent = css::datatransfer::clipboard::ClipboardEvent(static_cast<OWeakObject*>(this),
125 xNewContents);
128 aGuard.clear();
130 while (!listeners.empty())
132 if (listeners.front().is())
136 listeners.front()->changedContents(aEvent);
138 catch (const css::uno::RuntimeException&)
142 listeners.pop_front();
146 void iOSClipboard::fireLostClipboardOwnershipEvent(
147 css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> const& oldOwner,
148 css::uno::Reference<css::datatransfer::XTransferable> const& oldContent)
150 assert(oldOwner.is());
154 oldOwner->lostOwnership(static_cast<css::datatransfer::clipboard::XClipboardEx*>(this),
155 oldContent);
157 catch (const css::uno::RuntimeException&)
162 OUString SAL_CALL iOSClipboard::getImplementationName()
164 return OUString("com.sun.star.datatransfer.clipboard.iOSClipboard");
167 sal_Bool SAL_CALL iOSClipboard::supportsService(const OUString& ServiceName)
169 return cppu::supportsService(this, ServiceName);
172 css::uno::Sequence<OUString> SAL_CALL iOSClipboard::getSupportedServiceNames()
174 return { OUString("com.sun.star.datatransfer.clipboard.SystemClipboard") };
177 css::uno::Reference<css::uno::XInterface>
178 IosSalInstance::CreateClipboard(const css::uno::Sequence<css::uno::Any>&)
180 return css::uno::Reference<css::uno::XInterface>(
181 static_cast<cppu::OWeakObject*>(new iOSClipboard()));
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */