163bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
363bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
463bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
563bba73cSAndrew Rist * distributed with this work for additional information
663bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
763bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
863bba73cSAndrew Rist * "License"); you may not use this file except in compliance
963bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1163bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1363bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
1463bba73cSAndrew Rist * software distributed under the License is distributed on an
1563bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1663bba73cSAndrew Rist * KIND, either express or implied. See the License for the
1763bba73cSAndrew Rist * specific language governing permissions and limitations
1863bba73cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
2063bba73cSAndrew Rist *************************************************************/
2163bba73cSAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
24cdf0e10cSrcweir #include <com/sun/star/text/XTextContent.hpp>
25cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP
26cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp>
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir
29cdf0e10cSrcweir #ifndef _XMLOFF_XMLTIMP_HXX_
30cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
33cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
34cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
35cdf0e10cSrcweir #include "XMLAnchorTypePropHdl.hxx"
36cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
37cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp>
38cdf0e10cSrcweir #include "xmloff/XMLTextShapeImportHelper.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir using ::rtl::OUStringBuffer;
42cdf0e10cSrcweir
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::com::sun::star::frame;
45cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
46cdf0e10cSrcweir using namespace ::com::sun::star::beans;
47cdf0e10cSrcweir using namespace ::com::sun::star::text;
48cdf0e10cSrcweir using namespace ::com::sun::star::container;
49cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
50cdf0e10cSrcweir
XMLTextShapeImportHelper(SvXMLImport & rImp)51cdf0e10cSrcweir XMLTextShapeImportHelper::XMLTextShapeImportHelper(
52cdf0e10cSrcweir SvXMLImport& rImp ) :
53cdf0e10cSrcweir XMLShapeImportHelper( rImp, rImp.GetModel(),
54cdf0e10cSrcweir XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
55cdf0e10cSrcweir rImport( rImp ),
56cdf0e10cSrcweir sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
57cdf0e10cSrcweir sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
58cdf0e10cSrcweir sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
59cdf0e10cSrcweir {
60cdf0e10cSrcweir Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
61cdf0e10cSrcweir if( xDPS.is() )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY );
64cdf0e10cSrcweir pushGroupForSorting( xShapes );
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
~XMLTextShapeImportHelper()69cdf0e10cSrcweir XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir popGroupAndSort();
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
addShape(Reference<XShape> & rShape,const Reference<XAttributeList> & xAttrList,Reference<XShapes> & rShapes)74cdf0e10cSrcweir void XMLTextShapeImportHelper::addShape(
75cdf0e10cSrcweir Reference< XShape >& rShape,
76cdf0e10cSrcweir const Reference< XAttributeList >& xAttrList,
77cdf0e10cSrcweir Reference< XShapes >& rShapes )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir if( rShapes.is() )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir // It's a group shape or 3DScene , so we have to call the base class method.
82cdf0e10cSrcweir XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
83cdf0e10cSrcweir return;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
87cdf0e10cSrcweir sal_Int16 nPage = 0;
88cdf0e10cSrcweir sal_Int32 nY = 0;
89cdf0e10cSrcweir
90cdf0e10cSrcweir UniReference < XMLTextImportHelper > xTxtImport =
91cdf0e10cSrcweir rImport.GetTextImport();
92cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap =
93cdf0e10cSrcweir xTxtImport->GetTextFrameAttrTokenMap();
94cdf0e10cSrcweir
95cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
96cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i );
99cdf0e10cSrcweir const OUString& rValue = xAttrList->getValueByIndex( i );
100cdf0e10cSrcweir
101cdf0e10cSrcweir OUString aLocalName;
102cdf0e10cSrcweir sal_uInt16 nPrefix =
103cdf0e10cSrcweir rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName,
104cdf0e10cSrcweir &aLocalName );
105cdf0e10cSrcweir switch( rTokenMap.Get( nPrefix, aLocalName ) )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
108cdf0e10cSrcweir {
109cdf0e10cSrcweir TextContentAnchorType eNew;
110cdf0e10cSrcweir // OD 2004-06-01 #i26791# - allow all anchor types
111cdf0e10cSrcweir if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir eAnchorType = eNew;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir }
116cdf0e10cSrcweir break;
117cdf0e10cSrcweir case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
118cdf0e10cSrcweir {
119cdf0e10cSrcweir sal_Int32 nTmp;
120cdf0e10cSrcweir if( rImport.GetMM100UnitConverter().
121cdf0e10cSrcweir convertNumber( nTmp, rValue, 1, SHRT_MAX ) )
122cdf0e10cSrcweir nPage = (sal_Int16)nTmp;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir break;
125cdf0e10cSrcweir case XML_TOK_TEXT_FRAME_Y:
126cdf0e10cSrcweir rImport.GetMM100UnitConverter().convertMeasure( nY, rValue );
127cdf0e10cSrcweir break;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
132cdf0e10cSrcweir Any aAny;
133cdf0e10cSrcweir
134cdf0e10cSrcweir // anchor type
135cdf0e10cSrcweir aAny <<= eAnchorType;
136cdf0e10cSrcweir xPropSet->setPropertyValue( sAnchorType, aAny );
137cdf0e10cSrcweir
138cdf0e10cSrcweir Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
139cdf0e10cSrcweir xTxtImport->InsertTextContent( xTxtCntnt );
140cdf0e10cSrcweir
141cdf0e10cSrcweir // page number (must be set after the frame is inserted, because it
142cdf0e10cSrcweir // will be overwritten then inserting the frame.
143cdf0e10cSrcweir switch( eAnchorType )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir case TextContentAnchorType_AT_PAGE:
146cdf0e10cSrcweir // only set positive page numbers
147cdf0e10cSrcweir if ( nPage > 0 )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir aAny <<= nPage;
150cdf0e10cSrcweir xPropSet->setPropertyValue( sAnchorPageNo, aAny );
151cdf0e10cSrcweir }
152cdf0e10cSrcweir break;
153cdf0e10cSrcweir case TextContentAnchorType_AS_CHARACTER:
154cdf0e10cSrcweir aAny <<= nY;
155cdf0e10cSrcweir xPropSet->setPropertyValue( sVertOrientPosition, aAny );
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir default:
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir }
161*25d67f32Smseidel
162*25d67f32Smseidel /* vim: set noet sw=4 ts=4: */
163