Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/text/XTextContent.hpp>
21 : #include <com/sun/star/text/TextContentAnchorType.hpp>
22 :
23 : #include <sax/tools/converter.hxx>
24 :
25 : #include <xmloff/xmlimp.hxx>
26 : #include <xmloff/txtimp.hxx>
27 : #include <xmloff/xmluconv.hxx>
28 : #include <xmloff/nmspmap.hxx>
29 : #include "XMLAnchorTypePropHdl.hxx"
30 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
31 : #include <com/sun/star/drawing/XShapes.hpp>
32 : #include <xmloff/XMLTextShapeImportHelper.hxx>
33 :
34 :
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::frame;
37 : using namespace ::com::sun::star::drawing;
38 : using namespace ::com::sun::star::beans;
39 : using namespace ::com::sun::star::text;
40 : using namespace ::com::sun::star::container;
41 : using namespace ::com::sun::star::xml::sax;
42 :
43 730 : XMLTextShapeImportHelper::XMLTextShapeImportHelper(
44 : SvXMLImport& rImp ) :
45 730 : XMLShapeImportHelper( rImp, rImp.GetModel(),
46 : XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
47 : rImport( rImp ),
48 : sAnchorType("AnchorType"),
49 : sAnchorPageNo("AnchorPageNo"),
50 1460 : sVertOrientPosition("VertOrientPosition")
51 : {
52 730 : Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
53 730 : if( xDPS.is() )
54 : {
55 730 : Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY );
56 730 : pushGroupForSorting( xShapes );
57 730 : }
58 :
59 730 : }
60 :
61 1460 : XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
62 : {
63 730 : popGroupAndSort();
64 730 : }
65 :
66 280 : void XMLTextShapeImportHelper::addShape(
67 : Reference< XShape >& rShape,
68 : const Reference< XAttributeList >& xAttrList,
69 : Reference< XShapes >& rShapes )
70 : {
71 280 : if( rShapes.is() )
72 : {
73 : // It's a group shape or 3DScene , so we have to call the base class method.
74 136 : XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
75 416 : return;
76 : }
77 :
78 144 : TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
79 144 : sal_Int16 nPage = 0;
80 144 : sal_Int32 nY = 0;
81 :
82 : rtl::Reference < XMLTextImportHelper > xTxtImport =
83 144 : rImport.GetTextImport();
84 : const SvXMLTokenMap& rTokenMap =
85 144 : xTxtImport->GetTextFrameAttrTokenMap();
86 :
87 144 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
88 1360 : for( sal_Int16 i=0; i < nAttrCount; i++ )
89 : {
90 1216 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
91 2432 : const OUString& rValue = xAttrList->getValueByIndex( i );
92 :
93 2432 : OUString aLocalName;
94 : sal_uInt16 nPrefix =
95 1216 : rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName,
96 1216 : &aLocalName );
97 1216 : switch( rTokenMap.Get( nPrefix, aLocalName ) )
98 : {
99 : case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
100 : {
101 : TextContentAnchorType eNew;
102 : // OD 2004-06-01 #i26791# - allow all anchor types
103 144 : if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) )
104 : {
105 144 : eAnchorType = eNew;
106 : }
107 : }
108 144 : break;
109 : case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
110 : {
111 : sal_Int32 nTmp;
112 40 : if (::sax::Converter::convertNumber(nTmp, rValue, 1, SHRT_MAX))
113 40 : nPage = (sal_Int16)nTmp;
114 : }
115 40 : break;
116 : case XML_TOK_TEXT_FRAME_Y:
117 80 : rImport.GetMM100UnitConverter().convertMeasureToCore( nY, rValue );
118 80 : break;
119 : }
120 1216 : }
121 :
122 144 : Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
123 288 : Any aAny;
124 :
125 : // anchor type
126 144 : aAny <<= eAnchorType;
127 144 : xPropSet->setPropertyValue( sAnchorType, aAny );
128 :
129 288 : Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
130 144 : xTxtImport->InsertTextContent( xTxtCntnt );
131 :
132 : // page number (must be set after the frame is inserted, because it
133 : // will be overwritten then inserting the frame.
134 144 : switch( eAnchorType )
135 : {
136 : case TextContentAnchorType_AT_PAGE:
137 : // only set positive page numbers
138 40 : if ( nPage > 0 )
139 : {
140 40 : aAny <<= nPage;
141 40 : xPropSet->setPropertyValue( sAnchorPageNo, aAny );
142 : }
143 40 : break;
144 : case TextContentAnchorType_AS_CHARACTER:
145 16 : aAny <<= nY;
146 16 : xPropSet->setPropertyValue( sVertOrientPosition, aAny );
147 16 : break;
148 : default:
149 88 : break;
150 144 : }
151 : }
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|