tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmloff / source / text / XMLAutoTextEventExport.cxx
blob1186470d6c206945d2e96b74bfb1cb9de75c2ab7
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 "XMLAutoTextEventExport.hxx"
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/document/XEventsSupplier.hpp>
24 #include <com/sun/star/container/XNameReplace.hpp>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/uno/Exception.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <osl/diagnose.h>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/XMLEventExport.hxx>
34 #include <tools/debug.hxx>
37 using namespace ::com::sun::star;
38 using namespace ::xmloff::token;
40 using ::com::sun::star::container::XNameReplace;
41 using ::com::sun::star::document::XEventsSupplier;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::uno::Exception;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::XInterface;
47 using ::com::sun::star::uno::UNO_QUERY;
48 using ::com::sun::star::xml::sax::XDocumentHandler;
51 XMLAutoTextEventExport::XMLAutoTextEventExport(
52 const css::uno::Reference< css::uno::XComponentContext >& xContext,
53 OUString const & implementationName, SvXMLExportFlags nFlags
55 : SvXMLExport(xContext, implementationName, util::MeasureUnit::INCH, XML_AUTO_TEXT, nFlags)
59 XMLAutoTextEventExport::~XMLAutoTextEventExport()
63 void XMLAutoTextEventExport::initialize(
64 const Sequence<Any> & rArguments )
66 if (rArguments.getLength() > 1)
68 Reference<XEventsSupplier> xSupplier;
69 rArguments[1] >>= xSupplier;
70 if (xSupplier.is())
72 xEvents = xSupplier->getEvents();
74 else
76 Reference<XNameReplace> xReplace;
77 rArguments[1] >>= xReplace;
78 if (xReplace.is())
80 xEvents = xReplace;
82 else
84 rArguments[1] >>= xEvents;
89 // call super class (for XHandler)
90 SvXMLExport::initialize(rArguments);
94 ErrCode XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum )
96 if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
98 Reference< uno::XComponentContext> xContext = getComponentContext();
99 try
102 Sequence<Any> aArgs{ Any(GetDocHandler()) };
104 // get filter component
105 Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
106 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
107 u"com.sun.star.comp.Oasis2OOoTransformer"_ustr,
108 aArgs,
109 xContext),
110 UNO_QUERY);
111 OSL_ENSURE( xTmpDocHandler.is(),
112 "can't instantiate OASIS transformer component" );
113 if( xTmpDocHandler.is() )
115 SetDocHandler( xTmpDocHandler );
118 catch( css::uno::Exception& )
122 if (hasEvents())
124 GetDocHandler()->startDocument();
126 addChaffWhenEncryptedStorage();
128 addNamespaces();
131 // container element
132 SvXMLElementExport aContainerElement(
133 *this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS,
134 true, true);
136 exportEvents();
139 // and close document again
140 GetDocHandler()->endDocument();
143 return ERRCODE_NONE;
146 bool XMLAutoTextEventExport::hasEvents() const
148 // TODO: provide full implementation that check for presence of events
149 return xEvents.is();
152 void XMLAutoTextEventExport::addNamespaces()
154 // namespaces for office:, text: and script:
155 GetAttrList().AddAttribute(
156 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
157 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
158 GetAttrList().AddAttribute(
159 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
160 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
161 GetAttrList().AddAttribute(
162 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
163 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
164 GetAttrList().AddAttribute(
165 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
166 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
167 GetAttrList().AddAttribute(
168 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
169 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
170 GetAttrList().AddAttribute(
171 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
172 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
175 void XMLAutoTextEventExport::exportEvents()
177 DBG_ASSERT(hasEvents(), "no events to export!");
179 GetEventExport().Export(xEvents);
183 // methods without content:
185 void XMLAutoTextEventExport::ExportMeta_() {}
186 void XMLAutoTextEventExport::ExportScripts_() {}
187 void XMLAutoTextEventExport::ExportFontDecls_() {}
188 void XMLAutoTextEventExport::ExportStyles_( bool ) {}
189 void XMLAutoTextEventExport::ExportAutoStyles_() {}
190 void XMLAutoTextEventExport::ExportMasterStyles_() {}
191 void XMLAutoTextEventExport::ExportContent_() {}
194 // methods to support the component registration
196 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
197 com_sun_star_comp_Writer_XMLOasisAutotextEventsExporter_get_implementation(
198 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
200 return cppu::acquire(new XMLAutoTextEventExport(
201 context, u"com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter"_ustr,
202 SvXMLExportFlags::ALL | SvXMLExportFlags::OASIS));
205 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
206 com_sun_star_comp_Writer_XMLAutotextEventsExporter_get_implementation(
207 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
209 return cppu::acquire(new XMLAutoTextEventExport(
210 context, u"com.sun.star.comp.Writer.XMLAutotextEventsExporter"_ustr,
211 SvXMLExportFlags::ALL));
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */