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