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 "xmlannoi.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlconti.hxx"
23 #include "XMLTableShapeImportHelper.hxx"
25 #include <xmloff/xmltkmap.hxx>
26 #include <xmloff/nmspmap.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/xmltoken.hxx>
30 using namespace com::sun::star
;
31 using namespace xmloff::token
;
33 ScXMLAnnotationData::ScXMLAnnotationData() :
34 mbUseShapePos( false ),
39 ScXMLAnnotationData::~ScXMLAnnotationData()
43 ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport
& rImport
,
45 const OUString
& rLName
,
46 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
47 ScXMLAnnotationData
& rAnnotationData
) :
48 ScXMLImportContext( rImport
, nPrfx
, rLName
),
49 mrAnnotationData( rAnnotationData
)
51 uno::Reference
<drawing::XShapes
> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
52 if (xLocalShapes
.is())
54 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
55 pTableShapeImport
->SetAnnotation(this);
56 pShapeContext
.reset( GetScImport().GetShapeImport()->CreateGroupChildContext(
57 GetScImport(), nPrfx
, rLName
, xAttrList
, xLocalShapes
, true) );
60 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
61 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetTableAnnotationAttrTokenMap();
62 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
64 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
66 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
67 sAttrName
, &aLocalName
);
68 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
70 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
72 case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR
:
74 maAuthorBuffer
= sValue
;
77 case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE
:
79 maCreateDateBuffer
= sValue
;
82 case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING
:
84 maCreateDateStringBuffer
= sValue
;
87 case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY
:
89 mrAnnotationData
.mbShown
= IsXMLToken(sValue
, XML_TRUE
);
92 case XML_TOK_TABLE_ANNOTATION_ATTR_X
:
94 mrAnnotationData
.mbUseShapePos
= true;
97 case XML_TOK_TABLE_ANNOTATION_ATTR_Y
:
99 mrAnnotationData
.mbUseShapePos
= true;
106 ScXMLAnnotationContext::~ScXMLAnnotationContext()
110 void ScXMLAnnotationContext::StartElement(const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
113 pShapeContext
->StartElement(xAttrList
);
116 SvXMLImportContextRef
ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix
,
117 const OUString
& rLName
,
118 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
120 SvXMLImportContextRef xContext
;
122 if( XML_NAMESPACE_DC
== nPrefix
)
124 if( IsXMLToken( rLName
, XML_CREATOR
) )
125 xContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
126 rLName
, maAuthorBuffer
);
127 else if( IsXMLToken( rLName
, XML_DATE
) )
128 xContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
129 rLName
, maCreateDateBuffer
);
131 else if( XML_NAMESPACE_META
== nPrefix
)
133 if( IsXMLToken( rLName
, XML_DATE_STRING
) )
134 xContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
135 rLName
, maCreateDateStringBuffer
);
138 if( !xContext
&& pShapeContext
)
139 xContext
= pShapeContext
->CreateChildContext(nPrefix
, rLName
, xAttrList
);
142 xContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
147 void ScXMLAnnotationContext::Characters( const OUString
& rChars
)
149 maTextBuffer
.append(rChars
);
152 void ScXMLAnnotationContext::EndElement()
156 pShapeContext
->EndElement();
157 pShapeContext
.reset();
160 mrAnnotationData
.maAuthor
= maAuthorBuffer
.makeStringAndClear();
161 mrAnnotationData
.maCreateDate
= maCreateDateBuffer
.makeStringAndClear();
162 if (mrAnnotationData
.maCreateDate
.isEmpty())
163 mrAnnotationData
.maCreateDate
= maCreateDateStringBuffer
.makeStringAndClear();
164 mrAnnotationData
.maSimpleText
= maTextBuffer
.makeStringAndClear();
166 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
167 pTableShapeImport
->SetAnnotation(nullptr);
170 void ScXMLAnnotationContext::SetShape( const uno::Reference
< drawing::XShape
>& rxShape
, const uno::Reference
< drawing::XShapes
>& rxShapes
,
171 const OUString
& rStyleName
, const OUString
& rTextStyle
)
173 mrAnnotationData
.mxShape
= rxShape
;
174 mrAnnotationData
.mxShapes
= rxShapes
;
175 mrAnnotationData
.maStyleName
= rStyleName
;
176 mrAnnotationData
.maTextStyle
= rTextStyle
;
179 void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily
, const OUString
& rName
, const ESelection
& rSelection
)
181 mrAnnotationData
.maContentStyles
.emplace_back( nFamily
, rName
, rSelection
);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */