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