tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / text / XMLTextShapeImportHelper.cxx
blob56dba8ed22713de9a8905cf3fa6ce7847185a119
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/text/XTextContent.hpp>
21 #include <com/sun/star/text/TextContentAnchorType.hpp>
22 #include <comphelper/configuration.hxx>
24 #include <sax/tools/converter.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/txtimp.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmlnamespace.hxx>
30 #include "XMLAnchorTypePropHdl.hxx"
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
33 #include <com/sun/star/drawing/XShapes.hpp>
34 #include <com/sun/star/frame/XModel.hpp>
35 #include <xmloff/XMLTextShapeImportHelper.hxx>
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::drawing;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::text;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::xml::sax;
44 using namespace ::xmloff::token;
46 constexpr OUStringLiteral gsAnchorType(u"AnchorType");
47 constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo");
48 constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition");
50 XMLTextShapeImportHelper::XMLTextShapeImportHelper(
51 SvXMLImport& rImp ) :
52 XMLShapeImportHelper( rImp, rImp.GetModel(),
53 XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
54 m_rImport( rImp )
56 Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
57 if( xDPS.is() )
59 Reference < XShapes > xShapes = xDPS->getDrawPage();
60 pushGroupForPostProcessing( xShapes );
65 XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
67 popGroupAndPostProcess();
70 void XMLTextShapeImportHelper::addShape(
71 Reference< XShape >& rShape,
72 const Reference< XFastAttributeList >& xAttrList,
73 Reference< XShapes >& rShapes )
75 if( rShapes.is() )
77 // It's a group shape or 3DScene , so we have to call the base class method.
78 XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
79 return;
82 TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
83 sal_Int16 nPage = 0;
84 sal_Int32 nY = 0;
86 rtl::Reference < XMLTextImportHelper > xTxtImport =
87 m_rImport.GetTextImport();
89 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
91 switch( aIter.getToken() )
93 case XML_ELEMENT(TEXT, XML_ANCHOR_TYPE):
95 TextContentAnchorType eNew;
96 // OD 2004-06-01 #i26791# - allow all anchor types
97 if ( XMLAnchorTypePropHdl::convert( aIter.toView(), eNew ) )
99 eAnchorType = eNew;
102 break;
103 case XML_ELEMENT(TEXT, XML_ANCHOR_PAGE_NUMBER):
105 sal_Int32 nTmp;
106 sal_Int32 nMax = !comphelper::IsFuzzing() ? SHRT_MAX : 100;
107 if (::sax::Converter::convertNumber(nTmp, aIter.toView(), 1, nMax))
108 nPage = static_cast<sal_Int16>(nTmp);
110 break;
111 case XML_ELEMENT(SVG, XML_Y):
112 case XML_ELEMENT(SVG_COMPAT, XML_Y):
113 m_rImport.GetMM100UnitConverter().convertMeasureToCore( nY, aIter.toView() );
114 break;
118 Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
120 // anchor type
121 xPropSet->setPropertyValue( gsAnchorType, Any(eAnchorType) );
123 // page number must be set before the frame is inserted
124 switch( eAnchorType )
126 case TextContentAnchorType_AT_PAGE:
127 // only set positive page numbers
128 if ( nPage > 0 )
130 xPropSet->setPropertyValue( gsAnchorPageNo, Any(nPage) );
132 break;
133 default:
134 break;
137 Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
138 xTxtImport->InsertTextContent( xTxtCntnt );
140 switch( eAnchorType )
142 case TextContentAnchorType_AS_CHARACTER:
143 xPropSet->setPropertyValue( gsVertOrientPosition, Any(nY) );
144 break;
145 default:
146 break;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */