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