1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <sal/log.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <com/sun/star/drawing/XLayerManager.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 #include <com/sun/star/drawing/XLayerSupplier.hpp>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlimp.hxx>
31 #include <xmloff/xmlnamespace.hxx>
32 #include <xmloff/namespacemap.hxx>
33 #include "layerimp.hxx"
36 #include <XMLStringBufferImportContext.hxx>
38 using namespace ::std
;
39 using namespace ::cppu
;
40 using namespace ::xmloff::token
;
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::xml
;
43 using namespace ::com::sun::star::xml::sax
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::drawing
;
46 using namespace ::com::sun::star::beans
;
47 using namespace ::com::sun::star::lang
;
48 using namespace ::com::sun::star::container
;
49 using ::xmloff::token::IsXMLToken
;
53 class SdXMLLayerContext
: public SvXMLImportContext
56 SdXMLLayerContext( SvXMLImport
& rImport
, const Reference
< XFastAttributeList
>& xAttrList
, const Reference
< XNameAccess
>& xLayerManager
);
58 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
60 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& AttrList
) override
;
61 virtual void SAL_CALL
endFastElement(sal_Int32 nElement
) override
;
64 css::uno::Reference
< css::container::XNameAccess
> mxLayerManager
;
66 OUStringBuffer sDescriptionBuffer
;
67 OUStringBuffer sTitleBuffer
;
74 SdXMLLayerContext::SdXMLLayerContext( SvXMLImport
& rImport
, const Reference
< XFastAttributeList
>& xAttrList
, const Reference
< XNameAccess
>& xLayerManager
)
75 : SvXMLImportContext(rImport
)
76 , mxLayerManager( xLayerManager
)
78 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
80 OUString sValue
= aIter
.toString();
81 switch(aIter
.getToken())
83 case XML_ELEMENT(DRAW
, XML_NAME
):
86 case XML_ELEMENT(DRAW
, XML_DISPLAY
):
89 case XML_ELEMENT(DRAW
, XML_PROTECTED
):
93 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
99 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SdXMLLayerContext::createFastChildContext(
101 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& )
103 if( nElement
== XML_ELEMENT(SVG
, XML_TITLE
) )
105 return new XMLStringBufferImportContext( GetImport(), sTitleBuffer
);
107 else if( nElement
== XML_ELEMENT(SVG
, XML_DESC
) )
109 return new XMLStringBufferImportContext( GetImport(), sDescriptionBuffer
);
112 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
116 void SdXMLLayerContext::endFastElement(sal_Int32
)
118 SAL_WARN_IF( msName
.isEmpty(), "xmloff", "xmloff::SdXMLLayerContext::EndElement(), draw:layer element without draw:name!" );
119 if( msName
.isEmpty() )
124 Reference
< XPropertySet
> xLayer
;
126 if( mxLayerManager
->hasByName( msName
) )
128 mxLayerManager
->getByName( msName
) >>= xLayer
;
129 SAL_WARN_IF( !xLayer
.is(), "xmloff", "xmloff::SdXMLLayerContext::EndElement(), failed to get existing XLayer!" );
133 Reference
< XLayerManager
> xLayerManager( mxLayerManager
, UNO_QUERY
);
134 if( xLayerManager
.is() )
135 xLayer
= xLayerManager
->insertNewByIndex( xLayerManager
->getCount() );
136 SAL_WARN_IF( !xLayer
.is(), "xmloff", "xmloff::SdXMLLayerContext::EndElement(), failed to create new XLayer!" );
139 xLayer
->setPropertyValue("Name", Any( msName
) );
144 xLayer
->setPropertyValue("Title", Any( sTitleBuffer
.makeStringAndClear() ) );
145 xLayer
->setPropertyValue("Description", Any( sDescriptionBuffer
.makeStringAndClear() ) );
146 bool bIsVisible( true );
147 bool bIsPrintable( true );
148 if ( !msDisplay
.isEmpty() )
150 bIsVisible
= (msDisplay
== "always") || (msDisplay
== "screen");
151 bIsPrintable
= (msDisplay
== "always") || (msDisplay
== "printer");
153 xLayer
->setPropertyValue("IsVisible", Any( bIsVisible
) );
154 xLayer
->setPropertyValue("IsPrintable", Any( bIsPrintable
) );
155 bool bIsLocked( false );
156 if ( !msProtected
.isEmpty() )
157 bIsLocked
= (msProtected
== "true");
158 xLayer
->setPropertyValue("IsLocked", Any( bIsLocked
) );
160 // tdf#129898 repair layer "DrawnInSlideshow", which was wrongly written
161 // in LO 6.2 to 6.4. It should always have ODF defaults.
162 if (msName
== "DrawnInSlideshow")
164 xLayer
->setPropertyValue("IsVisible", Any(true));
165 xLayer
->setPropertyValue("IsPrintable", Any(true));
166 xLayer
->setPropertyValue("IsLocked", Any(false));
172 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
177 SdXMLLayerSetContext::SdXMLLayerSetContext( SvXMLImport
& rImport
)
178 : SvXMLImportContext(rImport
)
180 Reference
< XLayerSupplier
> xLayerSupplier( rImport
.GetModel(), UNO_QUERY
);
181 SAL_WARN_IF( !xLayerSupplier
.is(), "xmloff", "xmloff::SdXMLLayerSetContext::SdXMLLayerSetContext(), XModel is not supporting XLayerSupplier!" );
182 if( xLayerSupplier
.is() )
183 mxLayerManager
= xLayerSupplier
->getLayerManager();
186 SdXMLLayerSetContext::~SdXMLLayerSetContext()
190 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SdXMLLayerSetContext::createFastChildContext(
191 sal_Int32
/*nElement*/,
192 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
194 return new SdXMLLayerContext( GetImport(), xAttrList
, mxLayerManager
);
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */