sw: document SwFormatVertOrient
[LibreOffice.git] / vcl / ios / clipboard.cxx
blob46dfa92bfcd76c1e20ff5631477ec7af13346867
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"
22 #include "clipboard.hxx"
24 #include "DataFlavorMapping.hxx"
25 #include "iOSTransferable.hxx"
26 #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <cppuhelper/supportsservice.hxx>
31 iOSClipboard::iOSClipboard()
32 : WeakComponentImplHelper<XSystemClipboard, XServiceInfo>(m_aMutex)
34 auto xContext = comphelper::getProcessComponentContext();
36 mrXMimeCntFactory = css::datatransfer::MimeContentTypeFactory::create(xContext);
38 mpDataFlavorMapper.reset(new DataFlavorMapper());
41 iOSClipboard::~iOSClipboard() {}
43 css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL iOSClipboard::getContents()
45 osl::MutexGuard aGuard(m_aMutex);
47 return css::uno::Reference<css::datatransfer::XTransferable>(
48 new iOSTransferable(mrXMimeCntFactory, mpDataFlavorMapper));
51 void SAL_CALL iOSClipboard::setContents(
52 const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
53 const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& /*xClipboardOwner*/)
55 NSArray* types = xTransferable.is() ? mpDataFlavorMapper->flavorSequenceToTypesArray(
56 xTransferable->getTransferDataFlavors())
57 : [NSArray array];
59 osl::ClearableMutexGuard aGuard(m_aMutex);
61 NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:1];
62 NSArray* array = @[ dict ];
64 for (sal_uInt32 i = 0; i < [types count]; ++i)
66 DataProviderPtr_t dp = mpDataFlavorMapper->getDataProvider(types[i], xTransferable);
68 if (dp.get() != nullptr)
70 NSData* pBoardData = (NSData*)dp->getSystemData();
71 dict[types[i]] = pBoardData;
74 SAL_INFO("vcl.ios.clipboard", "Setting pasteboard items: " << NSDictionaryKeysToOUString(dict));
75 [[UIPasteboard generalPasteboard] setItems:array options:@{}];
77 // We don't keep a copy of the clipboard contents around in-process, so fire the lost clipboard
78 // ownership event right away.
79 // fireLostClipboardOwnershipEvent(xClipboardOwner, xTransferable);
81 // fireClipboardChangedEvent(xTransferable);
84 OUString SAL_CALL iOSClipboard::getName() { return OUString(); }
86 sal_Int8 SAL_CALL iOSClipboard::getRenderingCapabilities() { return 0; }
88 void SAL_CALL iOSClipboard::addClipboardListener(
89 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
91 osl::MutexGuard aGuard(m_aMutex);
93 if (!listener.is())
94 throw css::lang::IllegalArgumentException(
95 "empty reference", static_cast<css::datatransfer::clipboard::XClipboardEx*>(this), 1);
97 mClipboardListeners.push_back(listener);
100 void SAL_CALL iOSClipboard::removeClipboardListener(
101 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
103 osl::MutexGuard aGuard(m_aMutex);
105 if (!listener.is())
106 throw css::lang::IllegalArgumentException(
107 "empty reference", static_cast<css::datatransfer::clipboard::XClipboardEx*>(this), 1);
109 mClipboardListeners.remove(listener);
112 void iOSClipboard::fireClipboardChangedEvent(
113 css::uno::Reference<css::datatransfer::XTransferable> xNewContents)
115 osl::ClearableMutexGuard aGuard(m_aMutex);
117 std::list<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> listeners(
118 mClipboardListeners);
119 css::datatransfer::clipboard::ClipboardEvent aEvent;
121 if (!listeners.empty())
123 aEvent = css::datatransfer::clipboard::ClipboardEvent(static_cast<OWeakObject*>(this),
124 xNewContents);
127 aGuard.clear();
129 while (!listeners.empty())
131 if (listeners.front().is())
135 listeners.front()->changedContents(aEvent);
137 catch (const css::uno::RuntimeException&)
141 listeners.pop_front();
145 void iOSClipboard::fireLostClipboardOwnershipEvent(
146 css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> const& oldOwner,
147 css::uno::Reference<css::datatransfer::XTransferable> const& oldContent)
149 assert(oldOwner.is());
153 oldOwner->lostOwnership(static_cast<css::datatransfer::clipboard::XClipboardEx*>(this),
154 oldContent);
156 catch (const css::uno::RuntimeException&)
161 OUString SAL_CALL iOSClipboard::getImplementationName()
163 return OUString("com.sun.star.datatransfer.clipboard.iOSClipboard");
166 sal_Bool SAL_CALL iOSClipboard::supportsService(const OUString& ServiceName)
168 return cppu::supportsService(this, ServiceName);
171 css::uno::Sequence<OUString> SAL_CALL iOSClipboard::getSupportedServiceNames()
173 return { OUString("com.sun.star.datatransfer.clipboard.SystemClipboard") };
176 css::uno::Reference<css::uno::XInterface>
177 IosSalInstance::CreateClipboard(const css::uno::Sequence<css::uno::Any>&)
179 return css::uno::Reference<css::uno::XInterface>(
180 static_cast<cppu::OWeakObject*>(new iOSClipboard()));
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */