1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/text/XTextContent.hpp>
30 #include <com/sun/star/text/TextContentAnchorType.hpp>
32 #include <sax/tools/converter.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/txtimp.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/nmspmap.hxx>
38 #include "XMLAnchorTypePropHdl.hxx"
39 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
40 #include <com/sun/star/drawing/XShapes.hpp>
41 #include "xmloff/XMLTextShapeImportHelper.hxx"
43 using ::rtl::OUString
;
44 using ::rtl::OUStringBuffer
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::frame
;
48 using namespace ::com::sun::star::drawing
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::text
;
51 using namespace ::com::sun::star::container
;
52 using namespace ::com::sun::star::xml::sax
;
54 XMLTextShapeImportHelper::XMLTextShapeImportHelper(
56 XMLShapeImportHelper( rImp
, rImp
.GetModel(),
57 XMLTextImportHelper::CreateShapeExtPropMapper(rImp
) ),
59 sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
60 sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
61 sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
63 Reference
< XDrawPageSupplier
> xDPS( rImp
.GetModel(), UNO_QUERY
);
66 Reference
< XShapes
> xShapes( xDPS
->getDrawPage(), UNO_QUERY
);
67 pushGroupForSorting( xShapes
);
72 XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
77 void XMLTextShapeImportHelper::addShape(
78 Reference
< XShape
>& rShape
,
79 const Reference
< XAttributeList
>& xAttrList
,
80 Reference
< XShapes
>& rShapes
)
84 // It's a group shape or 3DScene , so we have to call the base class method.
85 XMLShapeImportHelper::addShape( rShape
, xAttrList
, rShapes
);
89 TextContentAnchorType eAnchorType
= TextContentAnchorType_AT_PARAGRAPH
;
93 UniReference
< XMLTextImportHelper
> xTxtImport
=
94 rImport
.GetTextImport();
95 const SvXMLTokenMap
& rTokenMap
=
96 xTxtImport
->GetTextFrameAttrTokenMap();
98 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
99 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
101 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
102 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
106 rImport
.GetNamespaceMap().GetKeyByAttrName( rAttrName
,
108 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
110 case XML_TOK_TEXT_FRAME_ANCHOR_TYPE
:
112 TextContentAnchorType eNew
;
113 // OD 2004-06-01 #i26791# - allow all anchor types
114 if ( XMLAnchorTypePropHdl::convert( rValue
, eNew
) )
120 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER
:
123 if (::sax::Converter::convertNumber(nTmp
, rValue
, 1, SHRT_MAX
))
124 nPage
= (sal_Int16
)nTmp
;
127 case XML_TOK_TEXT_FRAME_Y
:
128 rImport
.GetMM100UnitConverter().convertMeasureToCore( nY
, rValue
);
133 Reference
< XPropertySet
> xPropSet( rShape
, UNO_QUERY
);
137 aAny
<<= eAnchorType
;
138 xPropSet
->setPropertyValue( sAnchorType
, aAny
);
140 Reference
< XTextContent
> xTxtCntnt( rShape
, UNO_QUERY
);
141 xTxtImport
->InsertTextContent( xTxtCntnt
);
143 // page number (must be set after the frame is inserted, because it
144 // will be overwritten then inserting the frame.
145 switch( eAnchorType
)
147 case TextContentAnchorType_AT_PAGE
:
148 // only set positive page numbers
152 xPropSet
->setPropertyValue( sAnchorPageNo
, aAny
);
155 case TextContentAnchorType_AS_CHARACTER
:
157 xPropSet
->setPropertyValue( sVertOrientPosition
, aAny
);
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */