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: VisAreaContext.cxx,v $
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_xmloff.hxx"
37 // INCLUDE ---------------------------------------------------------------
38 #include "VisAreaContext.hxx"
39 #include <xmloff/xmltoken.hxx>
40 #include "xmlnmspe.hxx"
41 #include <xmloff/nmspmap.hxx>
42 #include <xmloff/xmluconv.hxx>
43 #include <xmloff/xmlimp.hxx>
44 #include <tools/gen.hxx>
46 using namespace com::sun::star
;
47 using namespace ::xmloff::token
;
49 //------------------------------------------------------------------
51 XMLVisAreaContext::XMLVisAreaContext( SvXMLImport
& rImport
,
53 const rtl::OUString
& rLName
,
54 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
55 Rectangle
& rRect
, const MapUnit aMapUnit
) :
56 SvXMLImportContext( rImport
, nPrfx
, rLName
)
58 awt::Rectangle
rAwtRect( rRect
.getX(), rRect
.getY(), rRect
.getWidth(), rRect
.getHeight() );
59 process( xAttrList
, rAwtRect
, (sal_Int16
)aMapUnit
);
61 rRect
.setX( rAwtRect
.X
);
62 rRect
.setY( rAwtRect
.Y
);
63 rRect
.setWidth( rAwtRect
.Width
);
64 rRect
.setHeight( rAwtRect
.Height
);
67 XMLVisAreaContext::XMLVisAreaContext( SvXMLImport
& rImport
,
69 const rtl::OUString
& rLName
,
70 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
71 ::com::sun::star::awt::Rectangle
& rRect
, const sal_Int16 nMeasureUnit
) :
72 SvXMLImportContext( rImport
, nPrfx
, rLName
)
74 process( xAttrList
, rRect
, nMeasureUnit
);
77 XMLVisAreaContext::~XMLVisAreaContext()
81 void XMLVisAreaContext::process( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
, awt::Rectangle
& rRect
, const sal_Int16 nMeasureUnit
)
83 MapUnit aMapUnit
= (MapUnit
)nMeasureUnit
;
89 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
90 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
92 rtl::OUString sAttrName
= xAttrList
->getNameByIndex( i
);
93 rtl::OUString aLocalName
;
94 USHORT nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName(
95 sAttrName
, &aLocalName
);
96 rtl::OUString sValue
= xAttrList
->getValueByIndex( i
);
98 if (nPrefix
== XML_NAMESPACE_OFFICE
)
100 if (IsXMLToken( aLocalName
, XML_X
))
102 SvXMLUnitConverter::convertMeasure(nX
, sValue
, aMapUnit
);
105 else if (IsXMLToken( aLocalName
, XML_Y
))
107 SvXMLUnitConverter::convertMeasure(nY
, sValue
, aMapUnit
);
110 else if (IsXMLToken( aLocalName
, XML_WIDTH
))
112 SvXMLUnitConverter::convertMeasure(nWidth
, sValue
, aMapUnit
);
113 rRect
.Width
= nWidth
;
115 else if (IsXMLToken( aLocalName
, XML_HEIGHT
))
117 SvXMLUnitConverter::convertMeasure(nHeight
, sValue
, aMapUnit
);
118 rRect
.Height
= nHeight
;
124 SvXMLImportContext
*XMLVisAreaContext::CreateChildContext( USHORT nPrefix
,
125 const rtl::OUString
& rLocalName
,
126 const ::com::sun::star::uno::Reference
<
127 ::com::sun::star::xml::sax::XAttributeList
>& )
129 // here is no context
130 SvXMLImportContext
*pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
135 void XMLVisAreaContext::EndElement()