1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* MWAWCalcImportFilter: Sets up the filter, and calls DocumentCollector
3 * to do the actual filtering
5 * This file is part of the LibreOffice project.
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <cppuhelper/supportsservice.hxx>
14 #include <libmwaw/libmwaw.hxx>
16 #include "MWAWCalcImportFilter.hxx"
18 static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData
& data
,
19 OdfDocumentHandler
* pHandler
,
20 const OdfStreamType streamType
)
22 OdgGenerator exporter
;
23 exporter
.addDocumentHandler(pHandler
, streamType
);
24 return MWAWDocument::decodeGraphic(data
, &exporter
);
27 static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData
& data
,
28 OdfDocumentHandler
* pHandler
,
29 const OdfStreamType streamType
)
31 OdsGenerator exporter
;
32 exporter
.addDocumentHandler(pHandler
, streamType
);
33 return MWAWDocument::decodeSpreadsheet(data
, &exporter
);
36 bool MWAWCalcImportFilter::doImportDocument(weld::Window
*, librevenge::RVNGInputStream
& rInput
,
37 OdsGenerator
& rGenerator
, utl::MediaDescriptor
&)
39 return MWAWDocument::MWAW_R_OK
== MWAWDocument::parse(&rInput
, &rGenerator
);
42 bool MWAWCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream
& rInput
, OUString
& rTypeName
)
46 MWAWDocument::Type docType
= MWAWDocument::MWAW_T_UNKNOWN
;
47 MWAWDocument::Kind docKind
= MWAWDocument::MWAW_K_UNKNOWN
;
48 const MWAWDocument::Confidence confidence
49 = MWAWDocument::isFileFormatSupported(&rInput
, docType
, docKind
);
51 if (confidence
== MWAWDocument::MWAW_C_EXCELLENT
)
55 case MWAWDocument::MWAW_K_DATABASE
:
58 case MWAWDocument::MWAW_T_CLARISWORKS
:
59 rTypeName
= "calc_ClarisWorks";
61 case MWAWDocument::MWAW_T_MICROSOFTWORKS
:
62 rTypeName
= "calc_Mac_Works";
65 rTypeName
= "MWAW_Database";
69 case MWAWDocument::MWAW_K_SPREADSHEET
:
72 case MWAWDocument::MWAW_T_CLARISRESOLVE
:
73 rTypeName
= "calc_Claris_Resolve";
75 case MWAWDocument::MWAW_T_CLARISWORKS
:
76 rTypeName
= "calc_ClarisWorks";
78 case MWAWDocument::MWAW_T_MICROSOFTWORKS
:
79 rTypeName
= "calc_Mac_Works";
82 rTypeName
= "MWAW_Spreadsheet";
91 return !rTypeName
.isEmpty();
94 void MWAWCalcImportFilter::doRegisterHandlers(OdsGenerator
& rGenerator
)
96 rGenerator
.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject
);
97 rGenerator
.registerEmbeddedObjectHandler("image/mwaw-ods",
98 &handleEmbeddedMWAWSpreadsheetObject
);
102 OUString SAL_CALL
MWAWCalcImportFilter::getImplementationName()
104 return u
"com.sun.star.comp.Calc.MWAWCalcImportFilter"_ustr
;
107 sal_Bool SAL_CALL
MWAWCalcImportFilter::supportsService(const OUString
& rServiceName
)
109 return cppu::supportsService(this, rServiceName
);
112 css::uno::Sequence
<OUString
> SAL_CALL
MWAWCalcImportFilter::getSupportedServiceNames()
114 return { u
"com.sun.star.document.ImportFilter"_ustr
,
115 u
"com.sun.star.document.ExtendedTypeDetection"_ustr
};
118 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
119 com_sun_star_comp_Calc_MWAWCalcImportFilter_get_implementation(
120 css::uno::XComponentContext
* const context
, const css::uno::Sequence
<css::uno::Any
>&)
122 return cppu::acquire(new MWAWCalcImportFilter(context
));
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */