Use CComPtr and its method to create instance by prog id
[LibreOffice.git] / oox / source / mathml / imexport.cxx
blob2b5990679bea2509dad09bf7c90d784587423e45
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/.
8 */
10 #include <oox/mathml/imexport.hxx>
12 #include <oox/mathml/importutils.hxx>
13 #include <oox/core/contexthandler.hxx>
14 #include <oox/token/namespaces.hxx>
16 #include <drawingml/textparagraph.hxx>
19 using namespace ::com::sun::star;
21 namespace oox
24 FormulaImExportBase::FormulaImExportBase()
28 namespace formulaimport {
30 namespace {
32 class LazyMathBufferingContext : public core::ContextHandler
34 private:
35 XmlStreamBuilder & m_rBuilder;
36 std::vector<sal_Int32> m_OpenElements;
38 public:
39 LazyMathBufferingContext(core::ContextHandler const& rParent,
40 drawingml::TextParagraph & rPara);
42 // com.sun.star.xml.sax.XFastContextHandler interface ---------------------
44 virtual void SAL_CALL startFastElement(::sal_Int32 Element, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) override;
45 virtual void SAL_CALL endFastElement(::sal_Int32 Element) override;
46 virtual uno::Reference< xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(::sal_Int32 Element, const uno::Reference<xml::sax::XFastAttributeList >& xAttribs) override;
47 virtual void SAL_CALL characters(const OUString& rChars) override;
53 LazyMathBufferingContext::LazyMathBufferingContext(
54 core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
55 : core::ContextHandler(rParent)
56 , m_rBuilder(rPara.GetMathXml())
60 void SAL_CALL LazyMathBufferingContext::startFastElement(
61 sal_Int32 const nElement,
62 uno::Reference<xml::sax::XFastAttributeList> const& xAttrs)
64 if (0 < m_OpenElements.size()) // ignore a14:m
65 { // ignore outer oMathPara
66 if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
68 m_rBuilder.appendOpeningTag(nElement, xAttrs);
71 m_OpenElements.push_back(nElement);
74 void SAL_CALL LazyMathBufferingContext::endFastElement(sal_Int32 const nElement)
76 m_OpenElements.pop_back();
77 if (0 < m_OpenElements.size()) // ignore a14:m
78 { // ignore outer oMathPara
79 if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
81 m_rBuilder.appendClosingTag(nElement);
86 uno::Reference<xml::sax::XFastContextHandler> SAL_CALL
87 LazyMathBufferingContext::createFastChildContext(sal_Int32 const,
88 uno::Reference<xml::sax::XFastAttributeList> const&)
90 return this;
93 void SAL_CALL LazyMathBufferingContext::characters(OUString const& rChars)
95 if (0 < m_OpenElements.size()) // ignore a14:m
97 if (m_OpenElements.back() == OOX_TOKEN(officeMath, t))
99 m_rBuilder.appendCharacters(rChars);
104 } // namespace oox::formulaimport
106 rtl::Reference<core::ContextHandler> CreateLazyMathBufferingContext(
107 core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
109 return new formulaimport::LazyMathBufferingContext(rParent, rPara);
112 } // namespace oox
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */