update dev300-m58
[ooovba.git] / sc / source / filter / xml / xmlannoi.cxx
blob839a140d2439dd05d8a949e78f89f24e146ebe47
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlannoi.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #include "xmlannoi.hxx"
37 #include "xmlimprt.hxx"
38 #include "xmlconti.hxx"
39 #include "XMLTableShapeImportHelper.hxx"
41 #include <xmloff/xmltkmap.hxx>
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmlnmspe.hxx>
44 #include <xmloff/xmltoken.hxx>
46 using namespace com::sun::star;
47 using namespace xmloff::token;
49 //------------------------------------------------------------------
51 ScXMLAnnotationData::ScXMLAnnotationData() :
52 mbUseShapePos( false ),
53 mbShown( false )
57 ScXMLAnnotationData::~ScXMLAnnotationData()
61 //------------------------------------------------------------------
63 ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport& rImport,
64 USHORT nPrfx,
65 const ::rtl::OUString& rLName,
66 const uno::Reference<xml::sax::XAttributeList>& xAttrList,
67 ScXMLAnnotationData& rAnnotationData,
68 ScXMLTableRowCellContext* pTempCellContext) :
69 SvXMLImportContext( rImport, nPrfx, rLName ),
70 mrAnnotationData( rAnnotationData ),
71 nParagraphCount(0),
72 bHasTextP(sal_False),
73 pCellContext(pTempCellContext),
74 pShapeContext(NULL)
76 uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
77 if (xLocalShapes.is())
79 XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
80 pTableShapeImport->SetAnnotation(this);
81 pShapeContext = GetScImport().GetShapeImport()->CreateGroupChildContext(
82 GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, sal_True);
85 pCellContext = pTempCellContext;
86 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
87 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
88 for( sal_Int16 i=0; i < nAttrCount; ++i )
90 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
91 rtl::OUString aLocalName;
92 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
93 sAttrName, &aLocalName );
94 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
96 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
98 case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR:
100 maAuthorBuffer = sValue;
102 break;
103 case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE:
105 maCreateDateBuffer = sValue;
107 break;
108 case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING:
110 maCreateDateStringBuffer = sValue;
112 break;
113 case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY:
115 mrAnnotationData.mbShown = IsXMLToken(sValue, XML_TRUE);
117 break;
118 case XML_TOK_TABLE_ANNOTATION_ATTR_X:
120 mrAnnotationData.mbUseShapePos = true;
122 break;
123 case XML_TOK_TABLE_ANNOTATION_ATTR_Y:
125 mrAnnotationData.mbUseShapePos = true;
127 break;
132 ScXMLAnnotationContext::~ScXMLAnnotationContext()
136 void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList)
138 if (pShapeContext)
139 pShapeContext->StartElement(xAttrList);
142 SvXMLImportContext *ScXMLAnnotationContext::CreateChildContext( USHORT nPrefix,
143 const ::rtl::OUString& rLName,
144 const ::com::sun::star::uno::Reference<
145 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
147 SvXMLImportContext *pContext = 0;
149 if( XML_NAMESPACE_DC == nPrefix )
151 if( IsXMLToken( rLName, XML_CREATOR ) )
152 pContext = new ScXMLContentContext(GetScImport(), nPrefix,
153 rLName, xAttrList, maAuthorBuffer);
154 else if( IsXMLToken( rLName, XML_DATE ) )
155 pContext = new ScXMLContentContext(GetScImport(), nPrefix,
156 rLName, xAttrList, maCreateDateBuffer);
158 else if( XML_NAMESPACE_META == nPrefix )
160 if( IsXMLToken( rLName, XML_DATE_STRING ) )
161 pContext = new ScXMLContentContext(GetScImport(), nPrefix,
162 rLName, xAttrList, maCreateDateStringBuffer);
164 /* else if ((nPrefix == XML_NAMESPACE_TEXT) && IsXMLToken(rLName, XML_P) )
166 if (!bHasTextP)
168 bHasTextP = sal_True;
169 maTextBuffer.setLength(0);
171 if(nParagraphCount)
172 maTextBuffer.append(static_cast<sal_Unicode>('\n'));
173 ++nParagraphCount;
174 pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, maTextBuffer);
177 if( !pContext && pShapeContext )
178 pContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
180 if( !pContext )
181 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
183 return pContext;
186 void ScXMLAnnotationContext::Characters( const ::rtl::OUString& rChars )
188 if (!bHasTextP)
189 maTextBuffer.append(rChars);
192 void ScXMLAnnotationContext::EndElement()
194 if (pShapeContext)
196 pShapeContext->EndElement();
197 delete pShapeContext;
198 pShapeContext = NULL;
201 mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
202 mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
203 if (!mrAnnotationData.maCreateDate.getLength())
204 mrAnnotationData.maCreateDate = maCreateDateStringBuffer.makeStringAndClear();
205 mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
207 XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
208 pTableShapeImport->SetAnnotation(NULL);
211 void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
212 const rtl::OUString& rStyleName, const rtl::OUString& rTextStyle )
214 mrAnnotationData.mxShape = rxShape;
215 mrAnnotationData.mxShapes = rxShapes;
216 mrAnnotationData.maStyleName = rStyleName;
217 mrAnnotationData.maTextStyle = rTextStyle;
220 void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily, const rtl::OUString& rName, const ESelection& rSelection )
222 mrAnnotationData.maContentStyles.push_back( ScXMLAnnotationStyleEntry( nFamily, rName, rSelection ) );