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