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