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