Kaydet (Commit) b8c1f54d authored tarafından Tor Lillqvist's avatar Tor Lillqvist

tdf#124752: Add system clipboard interface for iOS

Based on the corresponding macOS code. Work in progress. The image
support ifdeffed out still (because it uses some macOS specific APIs
for which I couldn't right away find the equivalent iOS ones).

I made it much simpler than the macOS code. I dropped the keeping of a
local in-process clipboard completely. Firstly, as far as I see, the
iOS clipboard API (UIPasteboard etc) does not even offer the
possibility to separately offer some formats and actually provide the
data on request. Secondly, we must be prepared anyway that the system
can kill an iOS app at any stage while the user is using some other
app, so we need to make sure everything that is copied goes onto the
system clipboard right away anyway.

I had to disable the copying of HTML to the clipboard as that lead to
a mysterious assertion failure. See comment in
DataFlavorMapper::openOfficeToSystemFlavor(). But RTF seems to work
well, too. I assume RTF is what gets used for cross-application
copy/paste (and cross-device, even, through Apple's Universal
Clipboard thing, where you can copy/paste between your Macs and iOS
devices on the same network).

I am not sure how relevant the various application/x-openoffice-foo
formats are.

Change-Id: I174495e33d86fc3990996c229243c05d6cbfcda7
üst 1c7a2eff
......@@ -135,6 +135,9 @@ $(eval $(call gb_Rdb_add_components,services,\
$(if $(filter iOS MACOSX,$(OS)), \
lingucomponent/source/spellcheck/macosxspell/MacOSXSpell \
) \
$(if $(filter iOS,$(OS)), \
vcl/vcl.ios \
) \
$(if $(filter WNT,$(OS)), \
avmedia/source/win/avmediawin \
dtrans/source/generic/dtrans \
......
......@@ -642,6 +642,10 @@ $(eval $(call gb_Library_add_cxxflags,vcl,\
$(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/ios/iosinst \
vcl/ios/dummies \
vcl/ios/clipboard \
vcl/ios/iOSTransferable \
vcl/ios/DataFlavorMapping \
vcl/ios/HtmlFmtFlt \
$(vcl_coretext_code) \
$(vcl_quartz_code) \
$(vcl_headless_code) \
......
......@@ -37,7 +37,9 @@ public:
virtual ~IosSalInstance();
static IosSalInstance *getInstance();
virtual SalSystem* CreateSalSystem() override;
SalSystem* CreateSalSystem() override;
css::uno::Reference< css::uno::XInterface > CreateClipboard( const css::uno::Sequence< css::uno::Any >& i_rArguments ) override;
void GetWorkArea( tools::Rectangle& rRect );
SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
......
This diff is collapsed.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 .
*/
#ifndef INCLUDED_VCL_IOS_DATAFLAVORMAPPING_HXX
#define INCLUDED_VCL_IOS_DATAFLAVORMAPPING_HXX
#include <com/sun/star/datatransfer/DataFlavor.hpp>
#include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <premac.h>
#import <UIKit/UIKit.h>
#include <postmac.h>
#include <memory>
#include <unordered_map>
/* An interface to get the clipboard data in either
system or OOo format.
*/
class DataProvider
{
public:
virtual ~DataProvider(){};
/* Get the clipboard data in the system format.
The caller has to retain/release the returned
CFDataRef on demand.
*/
virtual NSData* getSystemData() = 0;
/* Get the clipboard data in OOo format.
*/
virtual css::uno::Any getOOoData() = 0;
};
typedef std::unique_ptr<DataProvider> DataProviderPtr_t;
class DataFlavorMapper
{
public:
/* Initialize a DataFavorMapper instance. Throws a RuntimeException in case the XMimeContentTypeFactory service
cannot be created.
*/
DataFlavorMapper();
~DataFlavorMapper();
/* Map a system data flavor to an OpenOffice data flavor.
Return an empty string if there is not suitable
mapping from a system data flavor to a OpenOffice data
flavor.
*/
css::datatransfer::DataFlavor systemToOpenOfficeFlavor(const NSString* systemDataFlavor) const;
/* Map an OpenOffice data flavor to a system data flavor.
If there is no suitable mapping available NULL will
be returned.
*/
NSString* openOfficeToSystemFlavor(const css::datatransfer::DataFlavor& oooDataFlavor,
bool& rbInternal) const;
/* Select the best available image data type
If there is no suitable mapping available NULL will
be returned.
*/
static NSString* openOfficeImageToSystemFlavor(UIPasteboard* pPasteboard);
/* Get a data provider which is able to provide the data 'rTransferable' offers in a format that can
be put on to the system clipboard.
*/
DataProviderPtr_t getDataProvider(
const NSString* systemFlavor,
const css::uno::Reference<css::datatransfer::XTransferable>& rTransferable) const;
/* Get a data provider which is able to provide 'systemData' in the OOo expected format.
*/
static DataProviderPtr_t getDataProvider(const NSString* systemFlavor, NSArray* systemData);
/* Get a data provider which is able to provide 'systemData' in the OOo expected format.
*/
static DataProviderPtr_t getDataProvider(const NSString* systemFlavor, NSData* systemData);
/* Translate a sequence of DataFlavors into a NSArray of system types.
Only those DataFlavors for which a suitable mapping to a system
type exist will be contained in the returned types array.
*/
NSArray* flavorSequenceToTypesArray(
const css::uno::Sequence<css::datatransfer::DataFlavor>& flavors) const;
/* Translate a NSArray of system types into a sequence of DataFlavors.
Only those types for which a suitable mapping to a DataFlavor
exist will be contained in the new DataFlavor Sequence.
*/
css::uno::Sequence<css::datatransfer::DataFlavor>
typesArrayToFlavorSequence(NSArray* types) const;
/* Returns an NSArray containing all pasteboard types supported by OOo
*/
static NSArray* getAllSupportedPboardTypes();
private:
/* Determines if the provided Mime content type is valid.
*/
bool isValidMimeContentType(const OUString& contentType) const;
private:
css::uno::Reference<css::datatransfer::XMimeContentTypeFactory> mrXMimeCntFactory;
typedef std::unordered_map<OUString, NSString*> OfficeOnlyTypes;
mutable OfficeOnlyTypes maOfficeOnlyTypes;
};
#endif // INCLUDED_VCL_IOS_DATAFLAVORMAPPING_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "HtmlFmtFlt.hxx"
#include <rtl/string.h>
#include <osl/diagnose.h>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <cassert>
using namespace com::sun::star::uno;
// converts the openoffice text/html clipboard format to the HTML Format
// well known under MS Windows
// the MS HTML Format has a header before the real html data
// Version:1.0 Version number of the clipboard. Starting is 0.9
// StartHTML: Byte count from the beginning of the clipboard to the start
// of the context, or -1 if no context
// EndHTML: Byte count from the beginning of the clipboard to the end
// of the context, or -1 if no context
// StartFragment: Byte count from the beginning of the clipboard to the
// start of the fragment
// EndFragment: Byte count from the beginning of the clipboard to the
// end of the fragment
// StartSelection: Byte count from the beginning of the clipboard to the
// start of the selection
// EndSelection: Byte count from the beginning of the clipboard to the
// end of the selection
// StartSelection and EndSelection are optional
// The fragment should be preceded and followed by the HTML comments
// <!--StartFragment--> and <!--EndFragment--> (no space between !-- and the
// text
namespace
{
std::string GetHtmlFormatHeader(size_t startHtml, size_t endHtml, size_t startFragment,
size_t endFragment)
{
std::ostringstream htmlHeader;
htmlHeader << "Version:1.0" << '\r' << '\n';
htmlHeader << "StartHTML:" << std::setw(10) << std::setfill('0') << std::dec << startHtml
<< '\r' << '\n';
htmlHeader << "EndHTML:" << std::setw(10) << std::setfill('0') << std::dec << endHtml << '\r'
<< '\n';
htmlHeader << "StartFragment:" << std::setw(10) << std::setfill('0') << std::dec
<< startFragment << '\r' << '\n';
htmlHeader << "EndFragment:" << std::setw(10) << std::setfill('0') << std::dec << endFragment
<< '\r' << '\n';
return htmlHeader.str();
}
}
// the office always writes the start and end html tag in upper cases and
// without spaces both tags don't allow parameters
const std::string TAG_HTML = std::string("<html>");
const std::string TAG_END_HTML = std::string("</html>");
// The body tag may have parameters so we need to search for the
// closing '>' manually e.g. <BODY param> #92840#
const std::string TAG_BODY = std::string("<body");
const std::string TAG_END_BODY = std::string("</body");
Sequence<sal_Int8> SAL_CALL TextHtmlToHTMLFormat(Sequence<sal_Int8> const& aTextHtml)
{
OSL_ASSERT(aTextHtml.getLength() > 0);
if (aTextHtml.getLength() <= 0)
return Sequence<sal_Int8>();
// fill the buffer with dummy values to calc the exact length
std::string dummyHtmlHeader = GetHtmlFormatHeader(0, 0, 0, 0);
size_t lHtmlFormatHeader = dummyHtmlHeader.length();
std::string textHtml(reinterpret_cast<const sal_Char*>(aTextHtml.getConstArray()),
reinterpret_cast<const sal_Char*>(aTextHtml.getConstArray())
+ aTextHtml.getLength());
std::string::size_type nStartHtml = textHtml.find(TAG_HTML) + lHtmlFormatHeader
- 1; // we start one before '<HTML>' Word 2000 does also so
std::string::size_type nEndHtml = textHtml.find(TAG_END_HTML) + lHtmlFormatHeader
+ TAG_END_HTML.length()
+ 1; // our SOffice 5.2 wants 2 behind </HTML>?
// The body tag may have parameters so we need to search for the
// closing '>' manually e.g. <BODY param> #92840#
std::string::size_type nStartFragment
= textHtml.find(">", textHtml.find(TAG_BODY)) + lHtmlFormatHeader + 1;
std::string::size_type nEndFragment = textHtml.find(TAG_END_BODY) + lHtmlFormatHeader;
std::string htmlFormat
= GetHtmlFormatHeader(nStartHtml, nEndHtml, nStartFragment, nEndFragment);
htmlFormat += textHtml;
Sequence<sal_Int8> byteSequence(htmlFormat.length() + 1); // space the trailing '\0'
memset(byteSequence.getArray(), 0, byteSequence.getLength());
memcpy(static_cast<void*>(byteSequence.getArray()),
static_cast<const void*>(htmlFormat.c_str()), htmlFormat.length());
return byteSequence;
}
const char* const HtmlStartTag = "<html";
Sequence<sal_Int8> HTMLFormatToTextHtml(const Sequence<sal_Int8>& aHTMLFormat)
{
assert(isHTMLFormat(aHTMLFormat) && "No HTML Format provided");
Sequence<sal_Int8>& nonconstHTMLFormatRef = const_cast<Sequence<sal_Int8>&>(aHTMLFormat);
sal_Char* dataStart = reinterpret_cast<sal_Char*>(nonconstHTMLFormatRef.getArray());
sal_Char* dataEnd = dataStart + nonconstHTMLFormatRef.getLength() - 1;
const sal_Char* htmlStartTag = strcasestr(dataStart, HtmlStartTag);
assert(htmlStartTag && "Seems to be no HTML at all");
// It doesn't seem to be HTML? Well then simply return what has been
// provided in non-debug builds
if (htmlStartTag == nullptr)
{
return aHTMLFormat;
}
sal_Int32 len = dataEnd - htmlStartTag;
Sequence<sal_Int8> plainHtmlData(len);
memcpy(static_cast<void*>(plainHtmlData.getArray()), htmlStartTag, len);
return plainHtmlData;
}
/* A simple format detection. We are just comparing the first few bytes
of the provided byte sequence to see whether or not it is the MS
Office Html format. If it shows that this is not reliable enough we
can improve this
*/
const char HtmlFormatStart[] = "Version:";
int const HtmlFormatStartLen = (sizeof(HtmlFormatStart) - 1);
bool isHTMLFormat(const Sequence<sal_Int8>& aHtmlSequence)
{
if (aHtmlSequence.getLength() < HtmlFormatStartLen)
return false;
return rtl_str_compareIgnoreAsciiCase_WithLength(
HtmlFormatStart, HtmlFormatStartLen,
reinterpret_cast<const sal_Char*>(aHtmlSequence.getConstArray()), HtmlFormatStartLen)
== 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 .
*/
#ifndef INCLUDED_VCL_OSX_HTMLFMTFLT_HXX
#define INCLUDED_VCL_OSX_HTMLFMTFLT_HXX
#include <com/sun/star/uno/Sequence.hxx>
/* Transform plain HTML into the format expected by MS Office.
*/
css::uno::Sequence<sal_Int8> TextHtmlToHTMLFormat(css::uno::Sequence<sal_Int8> const& aTextHtml);
/* Transform the MS Office HTML format into plain HTML.
*/
css::uno::Sequence<sal_Int8> HTMLFormatToTextHtml(const css::uno::Sequence<sal_Int8>& aHTMLFormat);
/* Detects whether the given byte sequence contains the MS Office Html format.
@returns True if the MS Office Html format will be detected False otherwise.
*/
bool isHTMLFormat(const css::uno::Sequence<sal_Int8>& aHtmlSequence);
#endif // INCLUDED_VCL_OSX_HTMLFMTFLT_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "ios/iosinst.hxx"
#include "clipboard.hxx"
#include "DataFlavorMapping.hxx"
#include "iOSTransferable.hxx"
#include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/supportsservice.hxx>
iOSClipboard::iOSClipboard()
: WeakComponentImplHelper<XSystemClipboard, XServiceInfo>(m_aMutex)
{
auto xContext = comphelper::getProcessComponentContext();
mrXMimeCntFactory = css::datatransfer::MimeContentTypeFactory::create(xContext);
mpDataFlavorMapper.reset(new DataFlavorMapper());
mPasteboard = [UIPasteboard generalPasteboard];
assert(mPasteboard != nil);
}
iOSClipboard::~iOSClipboard() {}
css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL iOSClipboard::getContents()
{
osl::MutexGuard aGuard(m_aMutex);
return css::uno::Reference<css::datatransfer::XTransferable>(
new iOSTransferable(mrXMimeCntFactory, mpDataFlavorMapper, mPasteboard));
}
void SAL_CALL iOSClipboard::setContents(
const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& /*xClipboardOwner*/)
{
NSArray* types = xTransferable.is() ? mpDataFlavorMapper->flavorSequenceToTypesArray(
xTransferable->getTransferDataFlavors())
: [NSArray array];
osl::ClearableMutexGuard aGuard(m_aMutex);
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:1];
NSArray* array = @[ dict ];
for (sal_uInt32 i = 0; i < [types count]; ++i)
{
DataProviderPtr_t dp = mpDataFlavorMapper->getDataProvider(types[i], xTransferable);
if (dp.get() != nullptr)
{
NSData* pBoardData = (NSData*)dp->getSystemData();
dict[types[i]] = pBoardData;
}
}
[mPasteboard setItems:array options:@{}];
// We don't keep a copy of the clipboard contents around in-process, so fire the lost clipboard
// ownership event right away.
// fireLostClipboardOwnershipEvent(xClipboardOwner, xTransferable);
// fireClipboardChangedEvent(xTransferable);
}
OUString SAL_CALL iOSClipboard::getName() { return OUString(); }
sal_Int8 SAL_CALL iOSClipboard::getRenderingCapabilities() { return 0; }
void SAL_CALL iOSClipboard::addClipboardListener(
const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
{
osl::MutexGuard aGuard(m_aMutex);
if (!listener.is())
throw css::lang::IllegalArgumentException(
"empty reference", static_cast<css::datatransfer::clipboard::XClipboardEx*>(this), 1);
mClipboardListeners.push_back(listener);
}
void SAL_CALL iOSClipboard::removeClipboardListener(
const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
{
osl::MutexGuard aGuard(m_aMutex);
if (!listener.is())
throw css::lang::IllegalArgumentException(
"empty reference", static_cast<css::datatransfer::clipboard::XClipboardEx*>(this), 1);
mClipboardListeners.remove(listener);
}
void iOSClipboard::fireClipboardChangedEvent(
css::uno::Reference<css::datatransfer::XTransferable> xNewContents)
{
osl::ClearableMutexGuard aGuard(m_aMutex);
std::list<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> listeners(
mClipboardListeners);
css::datatransfer::clipboard::ClipboardEvent aEvent;
if (!listeners.empty())
{
aEvent = css::datatransfer::clipboard::ClipboardEvent(static_cast<OWeakObject*>(this),
xNewContents);
}
aGuard.clear();
while (!listeners.empty())
{
if (listeners.front().is())
{
try
{
listeners.front()->changedContents(aEvent);
}
catch (const css::uno::RuntimeException&)
{
}
}
listeners.pop_front();
}
}
void iOSClipboard::fireLostClipboardOwnershipEvent(
css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> const& oldOwner,
css::uno::Reference<css::datatransfer::XTransferable> const& oldContent)
{
assert(oldOwner.is());
try
{
oldOwner->lostOwnership(static_cast<css::datatransfer::clipboard::XClipboardEx*>(this),
oldContent);
}
catch (const css::uno::RuntimeException&)
{
}
}
OUString SAL_CALL iOSClipboard::getImplementationName()
{
return OUString("com.sun.star.datatransfer.clipboard.iOSClipboard");
}
sal_Bool SAL_CALL iOSClipboard::supportsService(const OUString& ServiceName)
{
return cppu::supportsService(this, ServiceName);
}
css::uno::Sequence<OUString> SAL_CALL iOSClipboard::getSupportedServiceNames()
{
return { OUString("com.sun.star.datatransfer.clipboard.SystemClipboard") };
}
css::uno::Reference<css::uno::XInterface>
IosSalInstance::CreateClipboard(const css::uno::Sequence<css::uno::Any>&)
{
return css::uno::Reference<css::uno::XInterface>(
static_cast<cppu::OWeakObject*>(new iOSClipboard()));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 .
*/
#ifndef INCLUDED_VCL_IOS_CLIPBOARD_HXX
#define INCLUDED_VCL_IOS_CLIPBOARD_HXX
#include "DataFlavorMapping.hxx"
#include <rtl/ustring.hxx>
#include <sal/types.h>
#include <cppuhelper/compbase.hxx>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
#include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/basemutex.hxx>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <list>
#include <premac.h>
#import <UIKit/UIKit.h>
#include <postmac.h>
class iOSClipboard
: public ::cppu::BaseMutex,
public ::cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
css::lang::XServiceInfo>
{
public:
iOSClipboard();
virtual ~iOSClipboard() override;
iOSClipboard(const iOSClipboard&) = delete;
iOSClipboard& operator=(const iOSClipboard&) = delete;
// XClipboard
css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override;
void SAL_CALL setContents(
const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
override;
OUString SAL_CALL getName() override;
// XClipboardEx
sal_Int8 SAL_CALL getRenderingCapabilities() override;
// XClipboardNotifier
void SAL_CALL addClipboardListener(
const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
override;
void SAL_CALL removeClipboardListener(
const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
override;
// XServiceInfo
OUString SAL_CALL getImplementationName() override;
sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
private:
/* Notify the current clipboard owner that he is no longer the clipboard owner. */
void fireLostClipboardOwnershipEvent(
css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> const& oldOwner,
css::uno::Reference<css::datatransfer::XTransferable> const& oldContent);
/* Notify all registered XClipboardListener that the clipboard content has changed. */
void
fireClipboardChangedEvent(css::uno::Reference<css::datatransfer::XTransferable> xNewContents);
private:
css::uno::Reference<css::datatransfer::XMimeContentTypeFactory> mrXMimeCntFactory;
std::list<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>>
mClipboardListeners;
css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> mXClipboardOwner;
std::shared_ptr<DataFlavorMapper> mpDataFlavorMapper;
UIPasteboard* mPasteboard;
};
#endif // INCLUDED_VCL_IOS_CLIPBOARD_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 <sal/config.h>
#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <sal/types.h>
#include <osl/diagnose.h>
#include "iOSTransferable.hxx"
#include "DataFlavorMapping.hxx"
using namespace std;
using namespace osl;
using namespace cppu;
using namespace com::sun::star::uno;
using namespace com::sun::star::datatransfer;
using namespace com::sun::star::lang;
namespace
{
bool isValidFlavor(const DataFlavor& aFlavor)
{
size_t len = aFlavor.MimeType.getLength();
Type dtype = aFlavor.DataType;
return ((len > 0)
&& ((dtype == cppu::UnoType<Sequence<sal_Int8>>::get())
|| (dtype == cppu::UnoType<OUString>::get())));
}
bool cmpAllContentTypeParameter(const Reference<XMimeContentType>& xLhs,
const Reference<XMimeContentType>& xRhs)
{
Sequence<OUString> xLhsFlavors = xLhs->getParameters();
Sequence<OUString> xRhsFlavors = xRhs->getParameters();
// Stop here if the number of parameters is different already
if (xLhsFlavors.getLength() != xRhsFlavors.getLength())
return false;
try
{
OUString pLhs;
OUString pRhs;
for (sal_Int32 i = 0; i < xLhsFlavors.getLength(); i++)
{
pLhs = xLhs->getParameterValue(xLhsFlavors[i]);
pRhs = xRhs->getParameterValue(xLhsFlavors[i]);
if (!pLhs.equalsIgnoreAsciiCase(pRhs))
{
return false;
}
}
}
catch (IllegalArgumentException&)
{
return false;
}
return true;
}
} // unnamed namespace
iOSTransferable::iOSTransferable(const Reference<XMimeContentTypeFactory>& rXMimeCntFactory,
std::shared_ptr<DataFlavorMapper> pDataFlavorMapper,
UIPasteboard* pasteboard)
: mrXMimeCntFactory(rXMimeCntFactory)
, mDataFlavorMapper(pDataFlavorMapper)
, mPasteboard(pasteboard)
{
[mPasteboard retain];
initClipboardItemList();
}
iOSTransferable::~iOSTransferable() { [mPasteboard release]; }
Any SAL_CALL iOSTransferable::getTransferData(const DataFlavor& aFlavor)
{
if (!isValidFlavor(aFlavor) || !isDataFlavorSupported(aFlavor))
{
throw UnsupportedFlavorException("Unsupported data flavor",
static_cast<XTransferable*>(this));
}
bool bInternal(false);
NSString* sysFormat = (aFlavor.MimeType.startsWith("image/png"))
? DataFlavorMapper::openOfficeImageToSystemFlavor(mPasteboard)
: mDataFlavorMapper->openOfficeToSystemFlavor(aFlavor, bInternal);
DataProviderPtr_t dp;
NSData* sysData = [mPasteboard dataForPasteboardType:sysFormat];
dp = DataFlavorMapper::getDataProvider(sysFormat, sysData);
if (dp.get() == nullptr)
{
throw UnsupportedFlavorException("Unsupported data flavor",
static_cast<XTransferable*>(this));
}
return dp->getOOoData();
}
Sequence<DataFlavor> SAL_CALL iOSTransferable::getTransferDataFlavors() { return mFlavorList; }
sal_Bool SAL_CALL iOSTransferable::isDataFlavorSupported(const DataFlavor& aFlavor)
{
for (sal_Int32 i = 0; i < mFlavorList.getLength(); i++)
if (compareDataFlavors(aFlavor, mFlavorList[i]))
return true;
return false;
}
void iOSTransferable::initClipboardItemList()
{
NSArray* pboardFormats = [mPasteboard pasteboardTypes];
if (pboardFormats == nullptr)
{
throw RuntimeException("Cannot get clipboard data", static_cast<XTransferable*>(this));
}
mFlavorList = mDataFlavorMapper->typesArrayToFlavorSequence(pboardFormats);
}
/* Compares two DataFlavors. Returns true if both DataFlavor have the same media type
and the number of parameter and all parameter values do match otherwise false
is returned.
*/
bool iOSTransferable::compareDataFlavors(const DataFlavor& lhs, const DataFlavor& rhs)
{
try
{
Reference<XMimeContentType> xLhs(mrXMimeCntFactory->createMimeContentType(lhs.MimeType));
Reference<XMimeContentType> xRhs(mrXMimeCntFactory->createMimeContentType(rhs.MimeType));
if (!xLhs->getFullMediaType().equalsIgnoreAsciiCase(xRhs->getFullMediaType())
|| !cmpAllContentTypeParameter(xLhs, xRhs))
{
return false;
}
}
catch (IllegalArgumentException&)
{
OSL_FAIL("Invalid content type detected");
return false;
}
return true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 .
*/
#ifndef INCLUDED_VCL_IOS_IOSTRANSFERABLE_HXX
#define INCLUDED_VCL_IOS_IOSTRANSFERABLE_HXX
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
#include <com/sun/star/datatransfer/XMimeContentType.hpp>
#include "DataFlavorMapping.hxx"
#include <premac.h>
#import <UIKit/UIKit.h>
#include <postmac.h>
#include <memory>
#include <vector>
class iOSTransferable : public ::cppu::WeakImplHelper<css::datatransfer::XTransferable>
{
public:
explicit iOSTransferable(
css::uno::Reference<css::datatransfer::XMimeContentTypeFactory> const& rXMimeCntFactory,
std::shared_ptr<DataFlavorMapper> pDataFlavorMapper, UIPasteboard* pasteboard);
virtual ~iOSTransferable() override;
iOSTransferable(const iOSTransferable&) = delete;
iOSTransferable& operator=(const iOSTransferable&) = delete;
// XTransferable
virtual css::uno::Any SAL_CALL
getTransferData(const css::datatransfer::DataFlavor& aFlavor) override;
css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& aFlavor) override;
// Helper functions not part of the XTransferable interface
void initClipboardItemList();
bool compareDataFlavors(const css::datatransfer::DataFlavor& lhs,
const css::datatransfer::DataFlavor& rhs);
private:
css::uno::Sequence<css::datatransfer::DataFlavor> mFlavorList;
css::uno::Reference<css::datatransfer::XMimeContentTypeFactory> mrXMimeCntFactory;
std::shared_ptr<DataFlavorMapper> mDataFlavorMapper;
UIPasteboard* mPasteboard;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -24,7 +24,7 @@
/* Transform plain HTML into the format expected by MS Office.
*/
css::uno::Sequence<sal_Int8> TextHtmlToHTMLFormat(css::uno::Sequence<sal_Int8> const & aTextHtml);
css::uno::Sequence<sal_Int8> TextHtmlToHTMLFormat(css::uno::Sequence<sal_Int8> const& aTextHtml);
/* Transform the MS Office HTML format into plain HTML.
*/
......@@ -34,7 +34,7 @@ css::uno::Sequence<sal_Int8> HTMLFormatToTextHtml(const css::uno::Sequence<sal_I
@returns True if the MS Office Html format will be detected False otherwise.
*/
bool isHTMLFormat (const css::uno::Sequence<sal_Int8>& aHtmlSequence);
bool isHTMLFormat(const css::uno::Sequence<sal_Int8>& aHtmlSequence);
#endif // INCLUDED_VCL_OSX_HTMLFMTFLT_HXX
......
......@@ -220,6 +220,8 @@ OUString Clipboard_getImplementationName()
return OUString(
#if defined MACOSX
"com.sun.star.datatransfer.clipboard.AquaClipboard"
#elif defined IOS
"com.sun.star.datatransfer.clipboard.iOSClipboard"
#elif defined ANDROID
"com.sun.star.datatransfer.VCLGenericClipboard"
#elif defined UNX
......
......@@ -19,6 +19,9 @@
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
prefix="vcl" xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.datatransfer.clipboard.iOSClipboard">
<service name="com.sun.star.datatransfer.clipboard.SystemClipboard"/>
</implementation>
<implementation name="com.sun.star.frame.VCLSessionManagerClient">
<service name="com.sun.star.frame.SessionManagerClient"/>
</implementation>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment