sw: clean up Start/EndAction in SwViewShell hierarchy
[LibreOffice.git] / starmath / inc / mathml / export.hxx
blob08d3f92d06def952aaa2035ae2ee1c7da28f5ceb
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 #pragma once
22 // Our mathml
23 #include "element.hxx"
25 // Xml tools
26 #include <utility>
27 #include <xmloff/xmlnamespace.hxx>
28 #include <xmloff/xmlexp.hxx>
29 #include <xmloff/xmltoken.hxx>
31 // Extras
32 #include <com/sun/star/io/XOutputStream.hpp>
34 class SfxMedium;
35 class SmDocShell;
36 class SmModel;
38 class SmMLExportWrapper
40 private:
41 // Model
42 rtl::Reference<SmModel> m_xModel;
43 // Save as a flat document ( mml, fodf ... )
44 bool m_bFlat;
45 // Use html / mathml entities
46 bool m_bUseHTMLMLEntities;
47 // Mathmml tree to parse
48 SmMlElement* m_pElementTree;
49 // Export xmlns tag
50 bool m_bUseExportTag;
52 public:
53 /** Set's the writer to export to flat document
55 void setFlat(bool bFlat) { m_bFlat = bFlat; }
57 /** Checks if the writer is set to export to flat document
59 bool getFlat() const { return m_bFlat; }
61 /** Checks the use of HTML / MathML entities such as &infinity;
63 void setUseHTMLMLEntities(bool bUseHTMLMLEntities)
65 m_bUseHTMLMLEntities = bUseHTMLMLEntities;
68 /** Activates the use of HTML / MathML entities such as &infinity;
70 bool getUseHTMLMLEntities() const { return m_bUseHTMLMLEntities; }
72 /** Get's if xmlns field is added
74 bool getUseExportTag() const { return m_bUseExportTag; }
76 /** Set's if xmlns field is added
78 void setUseExportTag(bool bUseExportTag) { m_bUseExportTag = bUseExportTag; }
80 public:
81 explicit SmMLExportWrapper(rtl::Reference<SmModel> xRef)
82 : m_xModel(std::move(xRef))
83 , m_bFlat(true)
84 , m_bUseHTMLMLEntities(false)
85 , m_pElementTree(nullptr)
86 , m_bUseExportTag(false)
90 /** Export to an archive
92 bool Export(SfxMedium& rMedium);
94 /** Just export a mathml tree
96 OUString Export(SmMlElement* pElementTree);
98 // Making this protected we can keep it from getting trash as input
99 protected:
100 /** export through an XML exporter component (output stream version)
102 bool WriteThroughComponentOS(const css::uno::Reference<css::io::XOutputStream>& xOutputStream,
103 const css::uno::Reference<css::lang::XComponent>& xComponent,
104 css::uno::Reference<css::uno::XComponentContext> const& rxContext,
105 css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
106 const char16_t* pComponentName, int_fast16_t nSyntaxVersion);
108 /** export through an XML exporter component (storage version)
110 bool WriteThroughComponentS(const css::uno::Reference<css::embed::XStorage>& xStor,
111 const css::uno::Reference<css::lang::XComponent>& xComponent,
112 const char16_t* pStreamName,
113 css::uno::Reference<css::uno::XComponentContext> const& rxContext,
114 css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
115 const char16_t* pComponentName, int_fast16_t nSyntaxVersion);
117 /** export through an XML exporter component (memory stream version)
119 OUString
120 WriteThroughComponentMS(const css::uno::Reference<css::lang::XComponent>& xComponent,
121 css::uno::Reference<css::uno::XComponentContext> const& rxContext,
122 css::uno::Reference<css::beans::XPropertySet> const& rPropSet);
125 class SmMLExport final : public SvXMLExport
127 private:
128 SmMlElement* m_pElementTree;
129 bool m_bSuccess;
130 bool m_bUseExportTag;
132 public:
133 /** Everything was allright
135 bool getSuccess() const { return m_bSuccess; }
137 /** Get's if xmlns field is added
139 bool getUseExportTag() const { return m_bUseExportTag; }
141 /** Set's if xmlns field is added
143 void setUseExportTag(bool bUseExportTag) { m_bUseExportTag = bUseExportTag; }
145 /** Set's the element tree to be exported.
146 * If it isn't nullptr the this will be exported instead of the document
148 void setElementTree(SmMlElement* pElementTree) { m_pElementTree = pElementTree; }
150 private:
151 /** Adds an element
153 SvXMLElementExport* createElementExport(xmloff::token::XMLTokenEnum nElement)
155 // We can't afford to ignore white spaces. They are part of the code.
156 return new SvXMLElementExport(*this, XML_NAMESPACE_MATH, nElement, false, false);
159 /** Adds an attribute
161 void addAttribute(xmloff::token::XMLTokenEnum pAttribute,
162 xmloff::token::XMLTokenEnum pAttributeValue)
164 AddAttribute(XML_NAMESPACE_MATH, pAttribute, pAttributeValue);
167 /** Adds an attribute
169 void addAttribute(xmloff::token::XMLTokenEnum pAttribute, const OUString& pAttributeValue)
171 AddAttribute(XML_NAMESPACE_MATH, pAttribute, pAttributeValue);
174 public:
175 /** Exports an attribute of type "length"
177 void exportMlAttributeLength(xmloff::token::XMLTokenEnum pAttribute,
178 const SmLengthValue& aLengthValue);
180 /** Exports attributes of an element
182 void exportMlAttributes(const SmMlElement* pMlElement);
184 /** Exports an element and all it's attributes
186 SvXMLElementExport* exportMlElement(const SmMlElement* pMlElement);
188 /** Exports an element tree
190 void exportMlElementTree();
192 /** Handles an error on the mathml structure
194 void declareMlError();
196 public:
197 /** Constructor
199 SmMLExport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
200 OUString const& implementationName, SvXMLExportFlags nExportFlags);
202 private:
203 /** Get's document shell
205 SmDocShell* getSmDocShell();
207 public:
208 /** Exports auto styles
209 * However math doesn't have any
211 void ExportAutoStyles_() override {}
213 /** Exports master styles
214 * However math doesn't have any
216 void ExportMasterStyles_() override {}
218 /** Exports formula
219 * Handler used from exportDoc
221 void ExportContent_() override { exportMlElementTree(); };
223 /** Exports the document
224 * If m_pElementTree isn't null then exports m_pElementTree
226 ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass
227 = ::xmloff::token::XML_TOKEN_INVALID) override;
229 /** Get's view settings and prepares them to export
231 virtual void GetViewSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
233 /** Get's configuration settings and prepares them to export
235 virtual void
236 GetConfigurationSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */