LibreOffice Module oox (master) 1
shapecontext.cxx
Go to the documentation of this file.
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/xml/sax/FastToken.hpp>
21#include <com/sun/star/drawing/LineStyle.hpp>
22#include <com/sun/star/beans/XMultiPropertySet.hpp>
23
31#include "hyperlinkcontext.hxx"
32#include <oox/token/namespaces.hxx>
33#include <oox/token/tokens.hxx>
34#include <sal/log.hxx>
36#include <utility>
37
38using namespace oox::core;
39using namespace ::com::sun::star;
40using namespace ::com::sun::star::uno;
41using namespace ::com::sun::star::drawing;
42using namespace ::com::sun::star::beans;
43using namespace ::com::sun::star::text;
44using namespace ::com::sun::star::xml::sax;
45
46namespace oox::drawingml {
47
48// CT_Shape
49ShapeContext::ShapeContext( ContextHandler2Helper const & rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
50: ContextHandler2( rParent )
51, mpMasterShapePtr(std::move( pMasterShapePtr ))
52, mpShapePtr(std::move( pShapePtr ))
53{
54 if( mpMasterShapePtr && mpShapePtr )
55 mpMasterShapePtr->addChild( mpShapePtr );
56}
57
58ShapeContext::~ShapeContext()
59{
60}
61
62ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
63{
64 switch( getBaseToken( aElementToken ) )
65 {
66 // nvSpPr CT_ShapeNonVisual begin
67// case XML_drElemPr:
68// break;
69 case XML_cNvPr:
70 {
71 mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
72 mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) );
73 mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
74 mpShapePtr->setDescription( rAttribs.getStringDefaulted( XML_descr ) );
75 break;
76 }
77 case XML_hlinkMouseOver:
78 case XML_hlinkClick:
79 return new HyperLinkContext( *this, rAttribs, getShape()->getShapeProperties() );
80 case XML_ph:
81 mpShapePtr->setSubType( rAttribs.getToken( XML_type, XML_obj ) );
82 if( rAttribs.hasAttribute( XML_idx ) )
83 mpShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) );
84 break;
85 // nvSpPr CT_ShapeNonVisual end
86
87 case XML_spPr:
88 return new ShapePropertiesContext( *this, *mpShapePtr );
89
90 case XML_style:
91 return new ShapeStyleContext( *this, *mpShapePtr );
92
93 case XML_txBody:
94 case XML_txbxContent:
95 {
96 if (!mpShapePtr->getTextBody())
97 mpShapePtr->setTextBody( std::make_shared<TextBody>() );
98 return new TextBodyContext( *this, mpShapePtr );
99 }
100 case XML_txXfrm: // diagram shape. [MS-ODRAWXML]
101 {
102 const TextBodyPtr& rShapePtr = mpShapePtr->getTextBody();
103 if (rShapePtr)
104 return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
105 }
106 break;
107 case XML_cNvSpPr:
108 break;
109 case XML_spLocks:
110 break;
111 case XML_bodyPr:
112 if (!mpShapePtr->getTextBody())
113 mpShapePtr->setTextBody( std::make_shared<TextBody>() );
114 return new TextBodyPropertiesContext( *this, rAttribs, mpShapePtr );
115 case XML_txbx:
116 break;
117 case XML_cNvPicPr:
118 break;
119 case XML_nvPicPr:
120 case XML_picLocks:
121 break;
122 case XML_relIds:
123 break;
124 case XML_nvSpPr:
125 break;
126 default:
127 SAL_WARN("oox", "ShapeContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
128 break;
129 }
130
131 return this;
132}
133
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
Helper class that provides a context stack.
ShapeContext(::oox::core::ContextHandler2Helper const &rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr)
context to import a CT_Transform2D
#define SAL_WARN(area, stream)
std::shared_ptr< Shape > ShapePtr
std::shared_ptr< TextBody > TextBodyPtr