1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <osl/diagnose.h>
22 #include "ftransl.hxx"
23 #include <com/sun/star/container/NoSuchElementException.hpp>
24 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
25 #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/weak.hxx>
30 #include "ImplHelper.hxx"
34 #define CPPUTYPE_SEQSALINT8 cppu::UnoType<Sequence< sal_Int8 >>::get()
35 #define CPPUTYPE_DEFAULT CPPUTYPE_SEQSALINT8
37 const char Windows_FormatName
[] = "windows_formatname";
38 const css::uno::Type CppuType_ByteSequence
= cppu::UnoType
<css::uno::Sequence
<sal_Int8
>>::get();
39 const css::uno::Type CppuType_String
= ::cppu::UnoType
<OUString
>::get();
44 using namespace com::sun::star::uno
;
45 using namespace com::sun::star::lang
;
46 using namespace com::sun::star::datatransfer
;
47 using namespace com::sun::star::container
;
55 const char *mime_content_type
,
56 const char *human_presentable_name
,
57 const char *native_format_name
,
58 CLIPFORMAT std_clipboard_format_id
,
59 css::uno::Type
const & cppu_type
62 css::datatransfer::DataFlavor aDataFlavor
;
63 OUString aNativeFormatName
;
64 sal_Int32 aStandardFormatId
;
69 FormatEntry::FormatEntry(
70 const char *mime_content_type
,
71 const char *human_presentable_name
,
72 const char *native_format_name
,
73 CLIPFORMAT std_clipboard_format_id
,
74 css::uno::Type
const & cppu_type
)
75 : aDataFlavor( OUString::createFromAscii(mime_content_type
), OUString::createFromAscii(human_presentable_name
), cppu_type
)
77 if (native_format_name
)
78 aNativeFormatName
= OUString::createFromAscii(native_format_name
);
80 aNativeFormatName
= OUString::createFromAscii(human_presentable_name
);
82 aStandardFormatId
= std_clipboard_format_id
;
85 // to optimize searching we add all entries with a
86 // standard clipboard format number first, in the
87 // table before the entries with CF_INVALID
88 // if we are searching for a standard clipboard
89 // format number we can stop if we find the first
92 const std::vector
< FormatEntry
> g_TranslTable
{
93 //SotClipboardFormatId::DIF
94 FormatEntry("application/x-openoffice-dif;windows_formatname=\"DIF\"", "DIF", "DIF", CF_DIF
, CPPUTYPE_DEFAULT
),
95 // SotClipboardFormatId::BITMAP
97 // #i124085# CF_DIBV5 disabled, leads to problems at export. To fully support, using
98 // an own mime-type may be necessary. I have tried that, but saw no real advantages
99 // with different apps when exchanging bitmap-based data. So, disabled for now. At
100 // the same time increased png format exchange for better interoperability
101 // FormatEntry("application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"", "Bitmap", "Bitmap", CF_DIBV5, CPPUTYPE_DEFAULT),
103 FormatEntry("application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"", "Bitmap", "Bitmap", CF_DIB
, CPPUTYPE_DEFAULT
),
104 FormatEntry("application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"", "Bitmap", "Bitmap", CF_BITMAP
, CPPUTYPE_DEFAULT
),
105 // SotClipboardFormatId::STRING
106 FormatEntry("text/plain;charset=utf-16", "Unicode-Text", "", CF_UNICODETEXT
, CppuType_String
),
107 // Format Locale - for internal use
108 FormatEntry("application/x-openoffice-locale;windows_formatname=\"Locale\"", "Locale", "Locale", CF_LOCALE
, CPPUTYPE_DEFAULT
),
110 FormatEntry("application/x-openoffice-wmf;windows_formatname=\"Image WMF\"", "Windows MetaFile", "Image WMF", CF_METAFILEPICT
, CPPUTYPE_DEFAULT
),
112 FormatEntry("application/x-openoffice-emf;windows_formatname=\"Image EMF\"", "Windows Enhanced MetaFile", "Image EMF", CF_ENHMETAFILE
, CPPUTYPE_DEFAULT
),
113 // SotClipboardFormatId::FILE_LIST
114 FormatEntry("application/x-openoffice-filelist;windows_formatname=\"FileList\"", "FileList", "FileList", CF_HDROP
, CPPUTYPE_DEFAULT
),
115 //SotClipboardFormatId::SYLK
116 FormatEntry("application/x-openoffice-sylk;windows_formatname=\"Sylk\"", "Sylk", "Sylk", CF_SYLK
, CPPUTYPE_DEFAULT
),
117 // SotClipboardFormatId::GDIMETAFILE
118 FormatEntry("application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"", "GDIMetaFile", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
119 // SotClipboardFormatId::PRIVATE
120 FormatEntry("application/x-openoffice-private;windows_formatname=\"Private\"", "Private", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
121 // SotClipboardFormatId::SIMPLE_FILE
122 FormatEntry("application/x-openoffice-file;windows_formatname=\"FileName\"", "FileName", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
123 // SotClipboardFormatId::RTF
124 FormatEntry("text/rtf", "Rich Text Format", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
125 // SotClipboardFormatId::DRAWING
126 FormatEntry("application/x-openoffice-drawing;windows_formatname=\"Drawing Format\"", "Drawing Format", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
127 // SotClipboardFormatId::SVXB
128 FormatEntry("application/x-openoffice-svbx;windows_formatname=\"SVXB (StarView Bitmap/Animation)\"", "SVXB (StarView Bitmap/Animation)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
129 // SotClipboardFormatId::SVIM
130 FormatEntry("application/x-openoffice-svim;windows_formatname=\"SVIM (StarView ImageMap)\"", "SVIM (StarView ImageMap)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
131 // SotClipboardFormatId::XFA
132 FormatEntry("application/x-libreoffice-xfa;windows_formatname=\"XFA (XOutDev FillAttr Any)\"", "XFA (XOutDev FillAttr Any)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
133 // SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT
134 FormatEntry("application/vnd.oasis.opendocument.text-flat-xml", "EditEngine ODF", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
135 // SotClipboardFormatId::INTERNALLINK_STATE
136 FormatEntry("application/x-openoffice-internallink-state;windows_formatname=\"StatusInfo of SvxInternalLink\"", "StatusInfo of SvxInternalLink", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
137 // SotClipboardFormatId::SOLK
138 FormatEntry("application/x-openoffice-solk;windows_formatname=\"SOLK (StarOffice Link)\"", "SOLK (StarOffice Link)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
139 // SotClipboardFormatId::NETSCAPE_BOOKMARK
140 FormatEntry("application/x-openoffice-netscape-bookmark;windows_formatname=\"Netscape Bookmark\"", "Netscape Bookmark", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
141 // SotClipboardFormatId::TREELISTBOX
142 FormatEntry("application/x-openoffice-treelistbox;windows_formatname=\"SV_LBOX_DD_FORMAT\"", "SV_LBOX_DD_FORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
143 // SotClipboardFormatId::NATIVE
144 FormatEntry("application/x-openoffice-native;windows_formatname=\"Native\"", "Native", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
145 // SotClipboardFormatId::OWNERLINK
146 FormatEntry("application/x-openoffice-ownerlink;windows_formatname=\"OwnerLink\"", "OwnerLink", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
147 // SotClipboardFormatId::STARSERVER
148 FormatEntry("application/x-openoffice-starserver;windows_formatname=\"StarServerFormat\"", "StarServerFormat", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
149 // SotClipboardFormatId::STAROBJECT
150 FormatEntry("application/x-openoffice-starobject;windows_formatname=\"StarObjectFormat\"", "StarObjectFormat", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
151 // SotClipboardFormatId::APPLETOBJECT
152 FormatEntry("application/x-openoffice-appletobject;windows_formatname=\"Applet Object\"", "Applet Object", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
153 // SotClipboardFormatId::PLUGIN_OBJECT
154 FormatEntry("application/x-openoffice-plugin-object;windows_formatname=\"PlugIn Object\"", "PlugIn Object", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
155 // SotClipboardFormatId::STARWRITER_30
156 FormatEntry("application/x-openoffice-starwriter-30;windows_formatname=\"StarWriter 3.0\"", "StarWriter 3.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
157 //SotClipboardFormatId::STARWRITER_40
158 FormatEntry("application/x-openoffice-starwriter-40;windows_formatname=\"StarWriter 4.0\"", "StarWriter 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
159 //SotClipboardFormatId::STARWRITER_50
160 FormatEntry("application/x-openoffice-starwriter-50;windows_formatname=\"StarWriter 5.0\"", "StarWriter 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
161 //SotClipboardFormatId::STARWRITERWEB_40
162 FormatEntry("application/x-openoffice-starwriterweb-40;windows_formatname=\"StarWriter/Web 4.0\"", "StarWriter/Web 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
163 //SotClipboardFormatId::STARWRITERWEB_50
164 FormatEntry("application/x-openoffice-starwriterweb-50;windows_formatname=\"StarWriter/Web 5.0\"", "StarWriter/Web 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
165 //SotClipboardFormatId::STARWRITERGLOB_40
166 FormatEntry("application/x-openoffice-starwriterglob-40;windows_formatname=\"StarWriter/Global 4.0\"", "StarWriter/Global 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
167 // SotClipboardFormatId::STARWRITERGLOB_50
168 FormatEntry("application/x-openoffice-starwriterglob-50;windows_formatname=\"StarWriter/Global 5.0\"", "StarWriter/Global 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
169 //SotClipboardFormatId::STARDRAW
170 FormatEntry("application/x-openoffice-stardraw;windows_formatname=\"StarDrawDocument\"", "StarDrawDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
171 //SotClipboardFormatId::STARDRAW_40
172 FormatEntry("application/x-openoffice-stardraw-40;windows_formatname=\"StarDrawDocument 4.0\"", "StarDrawDocument 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
173 //SotClipboardFormatId::STARIMPRESS_50
174 FormatEntry("application/x-openoffice-starimpress-50;windows_formatname=\"StarImpress 5.0\"", "StarImpress 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
175 // SotClipboardFormatId::STARDRAW_50
176 FormatEntry("application/x-openoffice-stardraw-50;windows_formatname=\"StarDraw 5.0\"", "StarDraw 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
177 //SotClipboardFormatId::STARCALC
178 FormatEntry("application/x-openoffice-starcalc;windows_formatname=\"StarCalcDocument\"", "StarCalcDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
179 //SotClipboardFormatId::STARCALC_40
180 FormatEntry("application/x-openoffice-starcalc-40;windows_formatname=\"StarCalc 4.0\"", "StarCalc 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
181 // SotClipboardFormatId::STARCALC_50
182 FormatEntry("application/x-openoffice-starcalc-50;windows_formatname=\"StarCalc 5.0\"", "StarCalc 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
183 // SotClipboardFormatId::STARCHART
184 FormatEntry("application/x-openoffice-starchart;windows_formatname=\"StarChartDocument\"", "StarChartDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
185 // SotClipboardFormatId::STARCHART_40
186 FormatEntry("application/x-openoffice-starchart-40;windows_formatname=\"StarChartDocument 4.0\"", "StarChartDocument 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
187 // SotClipboardFormatId::STARCHART_50
188 FormatEntry("application/x-openoffice-starchart-50;windows_formatname=\"StarChart 5.0\"", "StarChart 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
189 //SotClipboardFormatId::STARIMAGE
190 FormatEntry("application/x-openoffice-starimage;windows_formatname=\"StarImageDocument\"", "StarImageDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
191 //SotClipboardFormatId::STARIMAGE_40
192 FormatEntry("application/x-openoffice-starimage-40;windows_formatname=\"StarImageDocument 4.0\"", "StarImageDocument 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
193 //SotClipboardFormatId::STARIMAGE_50
194 FormatEntry("application/x-openoffice-starimage-50;windows_formatname=\"StarImage 5.0\"", "StarImage 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
195 //SotClipboardFormatId::STARMATH
196 FormatEntry("application/x-openoffice-starmath;windows_formatname=\"StarMath\"", "StarMath", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
197 //SotClipboardFormatId::STARMATH_40
198 FormatEntry("application/x-openoffice-starmath-40;windows_formatname=\"StarMathDocument 4.0\"", "StarMathDocument 4.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
199 //SotClipboardFormatId::STARMATH_50
200 FormatEntry("application/x-openoffice-starmath-50;windows_formatname=\"StarMath 5.0\"", "StarMath 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
201 //SotClipboardFormatId::STAROBJECT_PAINTDOC
202 FormatEntry("application/x-openoffice-starobject-paintdoc;windows_formatname=\"StarObjectPaintDocument\"", "StarObjectPaintDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
203 //SotClipboardFormatId::FILLED_AREA
204 FormatEntry("application/x-openoffice-filled-area;windows_formatname=\"FilledArea\"", "FilledArea", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
205 //SotClipboardFormatId::HTML
206 FormatEntry("text/html", "HTML (HyperText Markup Language)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
207 //SotClipboardFormatId::HTML_SIMPLE
208 FormatEntry("application/x-openoffice-html-simple;windows_formatname=\"HTML Format\"", "HTML Format", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
209 //SotClipboardFormatId::CHAOS
210 FormatEntry("application/x-openoffice-chaos;windows_formatname=\"FORMAT_CHAOS\"", "FORMAT_CHAOS", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
211 //SotClipboardFormatId::CNT_MSGATTACHFILE
212 FormatEntry("application/x-openoffice-msgattachfile;windows_formatname=\"CNT_MSGATTACHFILE_FORMAT\"", "CNT_MSGATTACHFILE_FORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
213 //SotClipboardFormatId::BIFF_5
214 FormatEntry("application/x-openoffice-biff5;windows_formatname=\"Biff5\"", "Biff5", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
215 //SotClipboardFormatId::BIFF__5
216 FormatEntry("application/x-openoffice-biff-5;windows_formatname=\"Biff 5\"", "Biff 5", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
217 //SotClipboardFormatId::BIFF_8
218 FormatEntry("application/x-openoffice-biff-8;windows_formatname=\"Biff8\"", "Biff8", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
219 //SotClipboardFormatId::SYLK_BIGCAPS
220 FormatEntry("application/x-openoffice-sylk-bigcaps;windows_formatname=\"SYLK\"", "SYLK", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
221 //SotClipboardFormatId::LINK
222 FormatEntry("application/x-openoffice-link;windows_formatname=\"Link\"", "Link", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
223 //SotClipboardFormatId::STARDRAW_TABBAR
224 FormatEntry("application/x-openoffice-stardraw-tabbar;windows_formatname=\"StarDraw TabBar\"", "StarDraw TabBar", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
225 //SotClipboardFormatId::SONLK
226 FormatEntry("application/x-openoffice-sonlk;windows_formatname=\"SONLK (StarOffice Navi Link)\"", "SONLK (StarOffice Navi Link)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
227 //SotClipboardFormatId::MSWORD_DOC
228 FormatEntry("application/msword", "MSWordDoc", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
229 //SotClipboardFormatId::STAR_FRAMESET_DOC
230 FormatEntry("application/x-openoffice-star-frameset-doc;windows_formatname=\"StarFrameSetDocument\"", "StarFrameSetDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
231 //SotClipboardFormatId::OFFICE_DOC
232 FormatEntry("application/x-openoffice-office-doc;windows_formatname=\"OfficeDocument\"", "OfficeDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
233 //SotClipboardFormatId::NOTES_DOCINFO
234 FormatEntry("application/x-openoffice-notes-docinfo;windows_formatname=\"NotesDocInfo\"", "NotesDocInfo", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
235 //SotClipboardFormatId::NOTES_HNOTE
236 FormatEntry("application/x-openoffice-notes-hnote;windows_formatname=\"NoteshNote\"", "NoteshNote", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
237 //SotClipboardFormatId::NOTES_NATIVE
238 FormatEntry("application/x-openoffice-notes-native;windows_formatname=\"Native\"", "Native", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
239 //SotClipboardFormatId::SFX_DOC
240 FormatEntry("application/x-openoffice-sfx-doc;windows_formatname=\"SfxDocument\"", "SfxDocument", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
241 //SotClipboardFormatId::EVDF
242 FormatEntry("application/x-openoffice-evdf;windows_formatname=\"EVDF (Explorer View Dummy Format)\"", "EVDF (Explorer View Dummy Format)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
243 //SotClipboardFormatId::ESDF
244 FormatEntry("application/x-openoffice-esdf;windows_formatname=\"ESDF (Explorer Search Dummy Format)\"", "ESDF (Explorer Search Dummy Format)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
245 //SotClipboardFormatId::IDF
246 FormatEntry("application/x-openoffice-idf;windows_formatname=\"IDF (Iconview Dummy Format)\"", "IDF (Iconview Dummy Format)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
247 //SotClipboardFormatId::EFTP
248 FormatEntry("application/x-openoffice-eftp;windows_formatname=\"EFTP (Explorer Ftp File)\"", "EFTP (Explorer Ftp File)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
249 //SotClipboardFormatId::EFD
250 FormatEntry("application/x-openoffice-efd;windows_formatname=\"EFD (Explorer Ftp Dir)\"", "EFD (Explorer Ftp Dir)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
251 //SotClipboardFormatId::SVX_FORMFIELDEXCH
252 FormatEntry("application/x-openoffice-svx-formfieldexch;windows_formatname=\"SvxFormFieldExch\"", "SvxFormFieldExch", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
253 //SotClipboardFormatId::EXTENDED_TABBAR
254 FormatEntry("application/x-openoffice-extended-tabbar;windows_formatname=\"ExtendedTabBar\"", "ExtendedTabBar", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
255 //SotClipboardFormatId::SBA_DATAEXCHANGE
256 FormatEntry("application/x-openoffice-sba-dataexchange;windows_formatname=\"SBA-DATAFORMAT\"", "SBA-DATAFORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
257 //SotClipboardFormatId::SBA_FIELDDATAEXCHANGE
258 FormatEntry("application/x-openoffice-sba-fielddataexchange;windows_formatname=\"SBA-FIELDFORMAT\"", "SBA-FIELDFORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
259 //SotClipboardFormatId::SBA_PRIVATE_URL
260 FormatEntry("application/x-openoffice-sba-private-url;windows_formatname=\"SBA-PRIVATEURLFORMAT\"", "SBA-PRIVATEURLFORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
261 //SotClipboardFormatId::SBA_TABED
262 FormatEntry("application/x-openoffice-sba-tabed;windows_formatname=\"Tabed\"", "Tabed", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
263 //SotClipboardFormatId::SBA_TABID
264 FormatEntry("application/x-openoffice-sba-tabid;windows_formatname=\"Tabid\"", "Tabid", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
265 //SotClipboardFormatId::SBA_JOIN
266 FormatEntry("application/x-openoffice-sba-join;windows_formatname=\"SBA-JOINFORMAT\"", "SBA-JOINFORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
267 //SotClipboardFormatId::OBJECTDESCRIPTOR
268 FormatEntry("application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"", "Star Object Descriptor (XML)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
269 //SotClipboardFormatId::LINKSRCDESCRIPTOR
270 FormatEntry("application/x-openoffice-linksrcdescriptor-xml;windows_formatname=\"Star Link Source Descriptor (XML)\"", "Star Link Source Descriptor (XML)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
271 //SotClipboardFormatId::EMBED_SOURCE
272 FormatEntry("application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"", "Star Embed Source (XML)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
273 //SotClipboardFormatId::LINK_SOURCE
274 FormatEntry("application/x-openoffice-link-source-xml;windows_formatname=\"Star Link Source (XML)\"", "Star Link Source (XML)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
275 //SotClipboardFormatId::EMBEDDED_OBJ
276 FormatEntry("application/x-openoffice-embedded-obj-xml;windows_formatname=\"Star Embedded Object (XML)\"", "Star Embedded Object (XML)", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
277 //SotClipboardFormatId::FILECONTENT
278 FormatEntry("application/x-openoffice-filecontent;windows_formatname=\"" CFSTR_FILECONTENTS
"\"", CFSTR_FILECONTENTS
, nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
279 //SotClipboardFormatId::FILEGRPDESCRIPTOR
280 FormatEntry("application/x-openoffice-filegrpdescriptor;windows_formatname=\"" CFSTR_FILEDESCRIPTOR
"\"", CFSTR_FILEDESCRIPTOR
, nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
281 //SotClipboardFormatId::FILENAME
282 FormatEntry("application/x-openoffice-filename;windows_formatname=\"" CFSTR_FILENAME
"\"", CFSTR_FILENAME
, nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
283 //SotClipboardFormatId::SD_OLE
284 FormatEntry("application/x-openoffice-sd-ole;windows_formatname=\"SD-OLE\"", "SD-OLE", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
285 //SotClipboardFormatId::EMBEDDED_OBJ_OLE
286 FormatEntry("application/x-openoffice-embedded-obj-ole;windows_formatname=\"Embedded Object\"", "Embedded Object", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
287 //SotClipboardFormatId::EMBED_SOURCE_OLE
288 FormatEntry("application/x-openoffice-embed-source-ole;windows_formatname=\"Embed Source\"", "Embed Source", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
289 //SotClipboardFormatId::OBJECTDESCRIPTOR_OLE
290 FormatEntry("application/x-openoffice-objectdescriptor-ole;windows_formatname=\"Object Descriptor\"", "Object Descriptor", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
291 //SotClipboardFormatId::LINKSRCDESCRIPTOR_OLE
292 FormatEntry("application/x-openoffice-linkdescriptor-ole;windows_formatname=\"Link Source Descriptor\"", "Link Source Descriptor", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
293 //SotClipboardFormatId::LINK_SOURCE_OLE
294 FormatEntry("application/x-openoffice-link-source-ole;windows_formatname=\"Link Source\"", "Link Source", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
295 //SotClipboardFormatId::SBA_CTRLDATAEXCHANGE
296 FormatEntry("application/x-openoffice-sba-ctrldataexchange;windows_formatname=\"SBA-CTRLFORMAT\"", "SBA-CTRLFORMAT", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
297 //SotClipboardFormatId::OUTPLACE_OBJ
298 FormatEntry("application/x-openoffice-outplace-obj;windows_formatname=\"OutPlace Object\"", "OutPlace Object", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
299 //SotClipboardFormatId::CNT_OWN_CLIP
300 FormatEntry("application/x-openoffice-cnt-own-clip;windows_formatname=\"CntOwnClipboard\"", "CntOwnClipboard", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
301 //SotClipboardFormatId::INET_IMAGE
302 FormatEntry("application/x-openoffice-inet-image;windows_formatname=\"SO-INet-Image\"", "SO-INet-Image", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
303 //SotClipboardFormatId::NETSCAPE_IMAGE
304 FormatEntry("application/x-openoffice-netscape-image;windows_formatname=\"Netscape Image Format\"", "Netscape Image Format", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
305 //SotClipboardFormatId::SBA_FORMEXCHANGE
306 FormatEntry("application/x-openoffice-sba-formexchange;windows_formatname=\"SBA_FORMEXCHANGE\"", "SBA_FORMEXCHANGE", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
), //SotClipboardFormatId::SBA_REPORTEXCHANGE
307 FormatEntry("application/x-openoffice-sba-reportexchange;windows_formatname=\"SBA_REPORTEXCHANGE\"", "SBA_REPORTEXCHANGE", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
308 //SotClipboardFormatId::UNIFORMRESOURCELOCATOR
309 FormatEntry("application/x-openoffice-uniformresourcelocator;windows_formatname=\"UniformResourceLocator\"", "UniformResourceLocator", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
310 //SotClipboardFormatId::STARCHARTDOCUMENT_50
311 FormatEntry("application/x-openoffice-starchartdocument-50;windows_formatname=\"StarChartDocument 5.0\"", "StarChartDocument 5.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
312 //SotClipboardFormatId::GRAPHOBJ
313 FormatEntry("application/x-openoffice-graphobj;windows_formatname=\"Graphic Object\"", "Graphic Object", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
314 //SotClipboardFormatId::STARWRITER_60
315 FormatEntry("application/vnd.sun.xml.writer", "Writer 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
316 //SotClipboardFormatId::STARWRITERWEB_60
317 FormatEntry("application/vnd.sun.xml.writer.web", "Writer/Web 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
318 //SotClipboardFormatId::STARWRITERGLOB_60
319 FormatEntry("application/vnd.sun.xml.writer.global", "Writer/Global 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
320 //SotClipboardFormatId::STARWDRAW_60
321 FormatEntry("application/vnd.sun.xml.draw", "Draw 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
322 //SotClipboardFormatId::STARIMPRESS_60
323 FormatEntry("application/vnd.sun.xml.impress", "Impress 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
324 //SotClipboardFormatId::STARCALC_60
325 FormatEntry("application/vnd.sun.xml.calc", "Calc 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
326 //SotClipboardFormatId::STARCHART_60
327 FormatEntry("application/vnd.sun.xml.chart", "Chart 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
328 //SotClipboardFormatId::STARMATH_60
329 FormatEntry("application/vnd.sun.xml.math", "Math 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
330 //SotClipboardFormatId::DIALOG_60
331 FormatEntry("application/vnd.sun.xml.dialog", "Dialog 6.0", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
332 //SotClipboardFormatId::BMP
333 FormatEntry("image/bmp", "Windows Bitmap", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
334 //SotClipboardFormatId::PNG
335 FormatEntry("image/png", "PNG", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
336 //SotClipboardFormatId::MATHML
337 FormatEntry("application/mathml+xml", "MathML", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
338 //SotClipboardFormatId::DUMMY3
339 FormatEntry("application/x-openoffice-dummy3;windows_formatname=\"SO_DUMMYFORMAT_3\"", "SO_DUMMYFORMAT_3", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
340 //SotClipboardFormatId::DUMMY4
341 FormatEntry("application/x-openoffice-dummy4;windows_formatname=\"SO_DUMMYFORMAT_4\"", "SO_DUMMYFORMAT_4", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
342 // SotClipboardFormatId::RICHTEXT
343 FormatEntry("text/richtext", "Richtext Format", nullptr, CF_INVALID
, CPPUTYPE_DEFAULT
),
348 void findDataFlavorForStandardFormatId( sal_Int32 aStandardFormatId
, DataFlavor
& aDataFlavor
)
351 we stop search if we find the first CF_INVALID
352 because in the translation table the entries with a
353 standard clipboard format id appear before the other
354 entries with CF_INVALID
356 vector
< FormatEntry
>::const_iterator citer
= std::find_if(g_TranslTable
.begin(), g_TranslTable
.end(),
357 [&aStandardFormatId
](const FormatEntry
& rEntry
) {
358 return rEntry
.aStandardFormatId
== aStandardFormatId
359 || rEntry
.aStandardFormatId
== CF_INVALID
;
361 if (citer
!= g_TranslTable
.end() && citer
->aStandardFormatId
== aStandardFormatId
)
362 aDataFlavor
= citer
->aDataFlavor
;
365 void findDataFlavorForNativeFormatName( const OUString
& aNativeFormatName
, DataFlavor
& aDataFlavor
)
367 vector
< FormatEntry
>::const_iterator citer
= std::find_if(g_TranslTable
.begin(), g_TranslTable
.end(),
368 [&aNativeFormatName
](const FormatEntry
& rEntry
) {
369 return aNativeFormatName
.equalsIgnoreAsciiCase(rEntry
.aNativeFormatName
); });
370 if (citer
!= g_TranslTable
.end())
371 aDataFlavor
= citer
->aDataFlavor
;
374 void findStandardFormatIdForCharset( const OUString
& aCharset
, Any
& aAny
)
376 if ( aCharset
.equalsIgnoreAsciiCase( "utf-16" ) )
377 aAny
<<= static_cast< sal_Int32
>( CF_UNICODETEXT
);
380 sal_Int32 wincp
= getWinCPFromMimeCharset( aCharset
);
381 if ( IsOEMCP ( wincp
) )
382 aAny
<<= static_cast< sal_Int32
>( CF_OEMTEXT
);
386 void setStandardFormatIdForNativeFormatName( const OUString
& aNativeFormatName
, Any
& aAny
)
388 vector
< FormatEntry
>::const_iterator citer
= std::find_if(g_TranslTable
.begin(), g_TranslTable
.end(),
389 [&aNativeFormatName
](const FormatEntry
& rEntry
) {
390 return aNativeFormatName
.equalsIgnoreAsciiCase(rEntry
.aNativeFormatName
)
391 && (CF_INVALID
!= rEntry
.aStandardFormatId
);
393 if (citer
!= g_TranslTable
.end())
394 aAny
<<= citer
->aStandardFormatId
;
397 void findStdFormatIdOrNativeFormatNameForFullMediaType(
398 const Reference
< XMimeContentTypeFactory
>& aRefXMimeFactory
,
399 const OUString
& aFullMediaType
,
402 vector
< FormatEntry
>::const_iterator citer
= std::find_if(g_TranslTable
.begin(), g_TranslTable
.end(),
403 [&aRefXMimeFactory
, &aFullMediaType
](const FormatEntry
& rEntry
) {
404 Reference
<XMimeContentType
> refXMime( aRefXMimeFactory
->createMimeContentType(rEntry
.aDataFlavor
.MimeType
) );
405 return aFullMediaType
.equalsIgnoreAsciiCase(refXMime
->getFullMediaType());
407 if (citer
!= g_TranslTable
.end())
409 sal_Int32 cf
= citer
->aStandardFormatId
;
410 if ( CF_INVALID
!= cf
)
414 OSL_ENSURE( citer
->aNativeFormatName
.getLength( ),
415 "Invalid standard format id and empty native format name in translation table" );
416 aAny
<<= citer
->aNativeFormatName
;
421 bool isTextPlainMediaType( const OUString
& fullMediaType
)
423 return fullMediaType
.equalsIgnoreAsciiCase("text/plain");
426 DataFlavor
mkDataFlv(const OUString
& cnttype
, const OUString
& hpname
, Type dtype
)
429 dflv
.MimeType
= cnttype
;
430 dflv
.HumanPresentableName
= hpname
;
431 dflv
.DataType
= dtype
;
437 CDataFormatTranslatorUNO::CDataFormatTranslatorUNO( const Reference
< XComponentContext
>& rxContext
) :
438 m_xContext( rxContext
)
442 Any SAL_CALL
CDataFormatTranslatorUNO::getSystemDataTypeFromDataFlavor( const DataFlavor
& aDataFlavor
)
448 Reference
< XMimeContentTypeFactory
> refXMimeCntFactory
= MimeContentTypeFactory::create( m_xContext
);
450 Reference
< XMimeContentType
>
451 refXMimeCntType( refXMimeCntFactory
->createMimeContentType( aDataFlavor
.MimeType
) );
453 OUString fullMediaType
= refXMimeCntType
->getFullMediaType( );
454 if ( isTextPlainMediaType( fullMediaType
) )
456 // default is CF_TEXT
457 aAny
<<= static_cast< sal_Int32
>( CF_TEXT
);
459 if ( refXMimeCntType
->hasParameter( "charset" ) )
461 // but maybe it is unicode text or oem text
462 OUString charset
= refXMimeCntType
->getParameterValue( "charset" );
463 findStandardFormatIdForCharset( charset
, aAny
);
468 if (refXMimeCntType
->hasParameter(Windows_FormatName
))
470 OUString winfmtname
= refXMimeCntType
->getParameterValue(Windows_FormatName
);
473 setStandardFormatIdForNativeFormatName( winfmtname
, aAny
);
476 findStdFormatIdOrNativeFormatNameForFullMediaType( refXMimeCntFactory
, fullMediaType
, aAny
);
479 catch( IllegalArgumentException
& )
481 OSL_FAIL( "Invalid content-type detected!" );
483 catch( NoSuchElementException
& )
485 OSL_FAIL( "Illegal content-type parameter" );
489 OSL_FAIL( "Unexpected error" );
496 DataFlavor SAL_CALL
CDataFormatTranslatorUNO::getDataFlavorFromSystemDataType( const Any
& aSysDataType
)
498 OSL_PRECOND( aSysDataType
.hasValue( ), "Empty system data type delivered" );
500 DataFlavor aFlavor
= mkDataFlv( OUString(), OUString(), CPPUTYPE_SEQSALINT8
);
502 if ( aSysDataType
.getValueType( ) == cppu::UnoType
<sal_Int32
>::get() )
504 sal_Int32 clipformat
= CF_INVALID
;
505 aSysDataType
>>= clipformat
;
506 if ( CF_INVALID
!= clipformat
)
507 findDataFlavorForStandardFormatId( clipformat
, aFlavor
);
509 else if ( aSysDataType
.getValueType( ) == cppu::UnoType
<OUString
>::get() )
511 OUString nativeFormatName
;
512 aSysDataType
>>= nativeFormatName
;
514 findDataFlavorForNativeFormatName( nativeFormatName
, aFlavor
);
517 OSL_FAIL( "Invalid data type received" );
524 OUString SAL_CALL
CDataFormatTranslatorUNO::getImplementationName( )
526 return "com.sun.star.datatransfer.DataFormatTranslator";
529 sal_Bool SAL_CALL
CDataFormatTranslatorUNO::supportsService( const OUString
& ServiceName
)
531 return cppu::supportsService(this, ServiceName
);
534 Sequence
< OUString
> SAL_CALL
CDataFormatTranslatorUNO::getSupportedServiceNames( )
536 return { "com.sun.star.datatransfer.DataFormatTranslator" };
539 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
540 dtrans_CDataFormatTranslatorUNO_get_implementation(
541 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
543 return cppu::acquire(static_cast<cppu::OWeakObject
*>(new CDataFormatTranslatorUNO(context
)));
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */