1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include <com/sun/star/text/XTextContent.hpp> 31 #ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP 32 #include <com/sun/star/text/TextContentAnchorType.hpp> 33 #endif 34 35 #ifndef _XMLOFF_XMLTIMP_HXX_ 36 #include <xmloff/xmlimp.hxx> 37 #endif 38 #include <xmloff/txtimp.hxx> 39 #include <xmloff/xmluconv.hxx> 40 #include <xmloff/nmspmap.hxx> 41 #include "XMLAnchorTypePropHdl.hxx" 42 #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 43 #include <com/sun/star/drawing/XShapes.hpp> 44 #include "xmloff/XMLTextShapeImportHelper.hxx" 45 46 using ::rtl::OUString; 47 using ::rtl::OUStringBuffer; 48 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::frame; 51 using namespace ::com::sun::star::drawing; 52 using namespace ::com::sun::star::beans; 53 using namespace ::com::sun::star::text; 54 using namespace ::com::sun::star::container; 55 using namespace ::com::sun::star::xml::sax; 56 57 XMLTextShapeImportHelper::XMLTextShapeImportHelper( 58 SvXMLImport& rImp ) : 59 XMLShapeImportHelper( rImp, rImp.GetModel(), 60 XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ), 61 rImport( rImp ), 62 sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")), 63 sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")), 64 sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")) 65 { 66 Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY ); 67 if( xDPS.is() ) 68 { 69 Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY ); 70 pushGroupForSorting( xShapes ); 71 } 72 73 } 74 75 XMLTextShapeImportHelper::~XMLTextShapeImportHelper() 76 { 77 popGroupAndSort(); 78 } 79 80 void XMLTextShapeImportHelper::addShape( 81 Reference< XShape >& rShape, 82 const Reference< XAttributeList >& xAttrList, 83 Reference< XShapes >& rShapes ) 84 { 85 if( rShapes.is() ) 86 { 87 // It's a group shape or 3DScene , so we have to call the base class method. 88 XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes ); 89 return; 90 } 91 92 TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH; 93 sal_Int16 nPage = 0; 94 sal_Int32 nY = 0; 95 96 UniReference < XMLTextImportHelper > xTxtImport = 97 rImport.GetTextImport(); 98 const SvXMLTokenMap& rTokenMap = 99 xTxtImport->GetTextFrameAttrTokenMap(); 100 101 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 102 for( sal_Int16 i=0; i < nAttrCount; i++ ) 103 { 104 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 105 const OUString& rValue = xAttrList->getValueByIndex( i ); 106 107 OUString aLocalName; 108 sal_uInt16 nPrefix = 109 rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, 110 &aLocalName ); 111 switch( rTokenMap.Get( nPrefix, aLocalName ) ) 112 { 113 case XML_TOK_TEXT_FRAME_ANCHOR_TYPE: 114 { 115 TextContentAnchorType eNew; 116 // OD 2004-06-01 #i26791# - allow all anchor types 117 if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) ) 118 { 119 eAnchorType = eNew; 120 } 121 } 122 break; 123 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER: 124 { 125 sal_Int32 nTmp; 126 if( rImport.GetMM100UnitConverter(). 127 convertNumber( nTmp, rValue, 1, SHRT_MAX ) ) 128 nPage = (sal_Int16)nTmp; 129 } 130 break; 131 case XML_TOK_TEXT_FRAME_Y: 132 rImport.GetMM100UnitConverter().convertMeasure( nY, rValue ); 133 break; 134 } 135 } 136 137 Reference < XPropertySet > xPropSet( rShape, UNO_QUERY ); 138 Any aAny; 139 140 // anchor type 141 aAny <<= eAnchorType; 142 xPropSet->setPropertyValue( sAnchorType, aAny ); 143 144 Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY ); 145 xTxtImport->InsertTextContent( xTxtCntnt ); 146 147 // page number (must be set after the frame is inserted, because it 148 // will be overwritten then inserting the frame. 149 switch( eAnchorType ) 150 { 151 case TextContentAnchorType_AT_PAGE: 152 // only set positive page numbers 153 if ( nPage > 0 ) 154 { 155 aAny <<= nPage; 156 xPropSet->setPropertyValue( sAnchorPageNo, aAny ); 157 } 158 break; 159 case TextContentAnchorType_AS_CHARACTER: 160 aAny <<= nY; 161 xPropSet->setPropertyValue( sVertOrientPosition, aAny ); 162 break; 163 default: 164 break; 165 } 166 } 167