LibreOffice Module oox (master)  1
timetargetelementcontext.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 <config_features.h>
21 
23 
24 #include <osl/diagnose.h>
25 #include <sal/log.hxx>
26 
29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/tokens.hxx>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <avmedia/mediaitem.hxx>
34 
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace ::oox::core;
38 
39 namespace oox::ppt {
40 
41  namespace {
42 
43  // CT_TLShapeTargetElement
44  class ShapeTargetElementContext
45  : public FragmentHandler2
46  {
47  public:
48  ShapeTargetElementContext( FragmentHandler2 const & rParent, ShapeTargetElement & aValue )
49  : FragmentHandler2( rParent )
50  , bTargetSet(false)
51  , maShapeTarget(aValue)
52  {
53  }
54  virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) override
55  {
56  switch( aElementToken )
57  {
58  case PPT_TOKEN( bg ):
59  bTargetSet = true;
60  maShapeTarget.mnType = XML_bg;
61  return this;
62  case PPT_TOKEN( txEl ):
63  bTargetSet = true;
64  maShapeTarget.mnType = XML_txEl;
65  return this;
66  case PPT_TOKEN( subSp ):
67  bTargetSet = true;
68  maShapeTarget.mnType = XML_subSp;
69  maShapeTarget.msSubShapeId = rAttribs.getString( XML_spid, OUString() );
70  return this;
71  case PPT_TOKEN( graphicEl ):
72  return this; // needs a:dgm for the target
73  case A_TOKEN( dgm ):
74  bTargetSet = true;
75  maShapeTarget.mnType = XML_dgm;
76  maShapeTarget.msSubShapeId = rAttribs.getString( XML_id, OUString() );
77  return this;
78  case PPT_TOKEN( oleChartEl ):
79  bTargetSet = true;
80  // TODO
81  return this;
82  case PPT_TOKEN( charRg ):
83  case PPT_TOKEN( pRg ):
84  if( bTargetSet && maShapeTarget.mnType == XML_txEl )
85  {
86  maShapeTarget.mnRangeType = getBaseToken( aElementToken );
87  maShapeTarget.maRange = drawingml::GetIndexRange( rAttribs.getFastAttributeList() );
88  }
89  return this;
90  default:
91  break;
92  }
93  return this;
94  }
95 
96  private:
97  bool bTargetSet;
98  ShapeTargetElement & maShapeTarget;
99  };
100 
101  }
102 
103  TimeTargetElementContext::TimeTargetElementContext( FragmentHandler2 const & rParent, const AnimTargetElementPtr & pValue )
104  : FragmentHandler2( rParent ),
105  mpTarget( pValue )
106  {
107  OSL_ENSURE( mpTarget, "no valid target passed" );
108  }
109 
111  {
112  }
113 
115  {
116  switch( aElementToken )
117  {
118  case PPT_TOKEN( inkTgt ):
119  {
120  mpTarget->mnType = XML_inkTgt;
121  OUString aId = rAttribs.getString( XML_spid, OUString() );
122  if( !aId.isEmpty() )
123  {
124  mpTarget->msValue = aId;
125  }
126  return this;
127  }
128  case PPT_TOKEN( sldTgt ):
129  mpTarget->mnType = XML_sldTgt;
130  return this;
131  case PPT_TOKEN( sndTgt ):
132  {
133  mpTarget->mnType = XML_sndTgt;
134 
135 #if HAVE_FEATURE_AVMEDIA
136  OUString srcFile = drawingml::getEmbeddedWAVAudioFile(getRelations(), rAttribs);
137  Reference<css::io::XInputStream>
138  xInputStream = getFilter().openInputStream(srcFile);
139 
140  if (xInputStream.is())
141  {
142  ::avmedia::EmbedMedia(getFilter().getModel(), srcFile, mpTarget->msValue, xInputStream);
143  xInputStream->closeInput();
144  }
145 #endif
146  break;
147  }
148  case PPT_TOKEN( spTgt ):
149  {
150  mpTarget->mnType = XML_spTgt;
151  OUString aId = rAttribs.getString( XML_spid, OUString() );
152  mpTarget->msValue = aId;
153  return new ShapeTargetElementContext( *this, mpTarget->maShapeTarget );
154  }
155  default:
156  SAL_INFO(
157  "oox.ppt",
158  "unhandled tag " << getBaseToken(aElementToken)
159  << " in TL_TimeTargetElement");
160  break;
161  }
162 
163  return this;
164  }
165 
166 }
167 
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~TimeTargetElementContext() noexcept override
std::shared_ptr< AnimTargetElement > AnimTargetElementPtr
OUString aId
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
TimeTargetElementContext(::oox::core::FragmentHandler2 const &rParent, const AnimTargetElementPtr &aValue)
T * mpTarget
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
sal_Int32 mnType
Provides access to attribute values of an element.
ShapeTargetElement & maShapeTarget
OUString getEmbeddedWAVAudioFile(const core::Relations &rRelations, const AttributeList &rAttribs)
#define SAL_INFO(area, stream)
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
::rtl::Reference< ContextHandler > ContextHandlerRef
IndexRange GetIndexRange(const Reference< XFastAttributeList > &xAttributes)