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