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