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: XMLTextShapeImportHelper.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"
33 #include <com/sun/star/text/XTextContent.hpp>
34 #ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP
35 #include <com/sun/star/text/TextContentAnchorType.hpp>
38 #ifndef _XMLOFF_XMLTIMP_HXX_
39 #include <xmloff/xmlimp.hxx>
41 #include <xmloff/txtimp.hxx>
42 #include <xmloff/xmluconv.hxx>
43 #include <xmloff/nmspmap.hxx>
44 #include "XMLAnchorTypePropHdl.hxx"
45 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
46 #include <com/sun/star/drawing/XShapes.hpp>
47 #include "XMLTextShapeImportHelper.hxx"
49 using ::rtl::OUString
;
50 using ::rtl::OUStringBuffer
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::frame
;
54 using namespace ::com::sun::star::drawing
;
55 using namespace ::com::sun::star::beans
;
56 using namespace ::com::sun::star::text
;
57 using namespace ::com::sun::star::container
;
58 using namespace ::com::sun::star::xml::sax
;
60 XMLTextShapeImportHelper::XMLTextShapeImportHelper(
62 XMLShapeImportHelper( rImp
, rImp
.GetModel(),
63 XMLTextImportHelper::CreateShapeExtPropMapper(rImp
) ),
65 sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
66 sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
67 sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
69 Reference
< XDrawPageSupplier
> xDPS( rImp
.GetModel(), UNO_QUERY
);
72 Reference
< XShapes
> xShapes( xDPS
->getDrawPage(), UNO_QUERY
);
73 pushGroupForSorting( xShapes
);
78 XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
83 void XMLTextShapeImportHelper::addShape(
84 Reference
< XShape
>& rShape
,
85 const Reference
< XAttributeList
>& xAttrList
,
86 Reference
< XShapes
>& rShapes
)
90 // It's a group shape or 3DScene , so we have to call the base class method.
91 XMLShapeImportHelper::addShape( rShape
, xAttrList
, rShapes
);
95 TextContentAnchorType eAnchorType
= TextContentAnchorType_AT_PARAGRAPH
;
99 UniReference
< XMLTextImportHelper
> xTxtImport
=
100 rImport
.GetTextImport();
101 const SvXMLTokenMap
& rTokenMap
=
102 xTxtImport
->GetTextFrameAttrTokenMap();
104 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
105 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
107 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
108 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
112 rImport
.GetNamespaceMap().GetKeyByAttrName( rAttrName
,
114 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
116 case XML_TOK_TEXT_FRAME_ANCHOR_TYPE
:
118 TextContentAnchorType eNew
;
119 // OD 2004-06-01 #i26791# - allow all anchor types
120 if ( XMLAnchorTypePropHdl::convert( rValue
, eNew
) )
126 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER
:
129 if( rImport
.GetMM100UnitConverter().
130 convertNumber( nTmp
, rValue
, 1, SHRT_MAX
) )
131 nPage
= (sal_Int16
)nTmp
;
134 case XML_TOK_TEXT_FRAME_Y
:
135 rImport
.GetMM100UnitConverter().convertMeasure( nY
, rValue
);
140 Reference
< XPropertySet
> xPropSet( rShape
, UNO_QUERY
);
144 aAny
<<= eAnchorType
;
145 xPropSet
->setPropertyValue( sAnchorType
, aAny
);
147 Reference
< XTextContent
> xTxtCntnt( rShape
, UNO_QUERY
);
148 xTxtImport
->InsertTextContent( xTxtCntnt
);
150 // page number (must be set after the frame is inserted, because it
151 // will be overwritten then inserting the frame.
152 switch( eAnchorType
)
154 case TextContentAnchorType_AT_PAGE
:
155 // only set positive page numbers
159 xPropSet
->setPropertyValue( sAnchorPageNo
, aAny
);
162 case TextContentAnchorType_AS_CHARACTER
:
164 xPropSet
->setPropertyValue( sVertOrientPosition
, aAny
);