LibreOffice Module oox (master)  1
conditioncontext.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 "conditioncontext.hxx"
21 
22 #include <com/sun/star/animations/AnimationEndSync.hpp>
23 #include <com/sun/star/animations/EventTrigger.hpp>
24 
27 #include "animationtypes.hxx"
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 
32 
33 using namespace ::oox::core;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::xml::sax;
36 using namespace ::com::sun::star::animations;
37 
38 namespace oox::ppt {
39 
40  CondContext::CondContext( FragmentHandler2 const & rParent, const Reference< XFastAttributeList >& xAttribs,
41  const TimeNodePtr & pNode, AnimationCondition & aValue )
42  : TimeNodeContext( rParent, PPT_TOKEN( cond ), pNode )
43  , maCond( aValue )
44  {
45  maEvent.Trigger = EventTrigger::NONE;
46  maEvent.Repeat = 0;
47 
48  AttributeList attribs( xAttribs );
49  if( attribs.hasAttribute( XML_evt ) )
50  {
51  sal_Int32 nEvent = xAttribs->getOptionalValueToken( XML_evt, 0 );
52  switch( nEvent )
53  {
54  case XML_onBegin:
55  maEvent.Trigger = EventTrigger::ON_BEGIN;
56  break;
57  case XML_onEnd:
58  maEvent.Trigger = EventTrigger::ON_END;
59  break;
60  case XML_begin:
61  maEvent.Trigger = EventTrigger::BEGIN_EVENT;
62  break;
63  case XML_end:
64  maEvent.Trigger = EventTrigger::END_EVENT;
65  break;
66  case XML_onClick:
67  maEvent.Trigger = EventTrigger::ON_CLICK;
68  break;
69  case XML_onDblClick:
70  maEvent.Trigger = EventTrigger::ON_DBL_CLICK;
71  break;
72  case XML_onMouseOver:
73  maEvent.Trigger = EventTrigger::ON_MOUSE_ENTER;
74  break;
75  case XML_onMouseOut:
76  maEvent.Trigger = EventTrigger::ON_MOUSE_LEAVE;
77  break;
78  case XML_onNext:
79  maEvent.Trigger = EventTrigger::ON_NEXT;
80  break;
81  case XML_onPrev:
82  maEvent.Trigger = EventTrigger::ON_PREV;
83  break;
84  case XML_onStopAudio:
85  maEvent.Trigger = EventTrigger::ON_STOP_AUDIO;
86  break;
87  default:
88  break;
89  }
90  }
91  if( attribs.hasAttribute( XML_delay ) || ( maEvent.Trigger == EventTrigger::NONE ) )
92  {
93  maEvent.Offset = GetTime( xAttribs->getOptionalValue( XML_delay ) );
94  }
95  }
96 
98  {
99  if( maCond.mnType == 0 || maCond.mnType == PPT_TOKEN(tn))
100  {
101  maCond.maValue = (maEvent.Trigger == EventTrigger::NONE) ? maEvent.Offset : makeAny( maEvent );
102  }
103  }
104 
106  {
107  switch( aElementToken )
108  {
109  case PPT_TOKEN( rtn ):
110  {
111  // ST_TLTriggerRuntimeNode { first, last, all }
112  sal_Int32 aTok;
113  sal_Int16 nEnum;
114  aTok = rAttribs.getToken( XML_val, XML_first );
115  switch( aTok )
116  {
117  case XML_first:
118  nEnum = AnimationEndSync::FIRST;
119  break;
120  case XML_last:
121  nEnum = AnimationEndSync::LAST;
122  break;
123  case XML_all:
124  nEnum = AnimationEndSync::ALL;
125  break;
126  default:
127  break;
128  }
129  maCond.mnType = aElementToken;
130  maCond.maValue <<= nEnum;
131  return this;
132  }
133  case PPT_TOKEN( tn ):
134  {
135  maCond.mnType = aElementToken;
136  // Convert the node id string to XAnimationNode later
137  maEvent.Source <<= rAttribs.getString(XML_val, OUString());
138  return this;
139  }
140  case PPT_TOKEN( tgtEl ):
141  // CT_TLTimeTargetElement
142  return new TimeTargetElementContext( *this, maCond.getTarget() );
143  default:
144  break;
145  }
146 
147  return this;
148 
149  }
150 
153  FragmentHandler2 const & rParent, sal_Int32 aElement,
154  const TimeNodePtr & pNode,
155  AnimationConditionList & aCond )
156  : TimeNodeContext( rParent, aElement, pNode )
157  , maConditions( aCond )
158  {
159  }
160 
162  noexcept
163  {
164  }
165 
167  {
168  switch( aElement )
169  {
170  case PPT_TOKEN( cond ):
171  // add a condition to the list
172  maConditions.emplace_back( );
173  return new CondContext( *this, rAttribs.getFastAttributeList(), mpNode, maConditions.back() );
174  default:
175  break;
176  }
177  return this;
178  }
179 
180 }
181 
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CondContext(::oox::core::FragmentHandler2 const &rParent, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttribs, const TimeNodePtr &pNode, AnimationCondition &aCond)
data for CT_TLTimeCondition
Any GetTime(const OUString &val)
CondListContext(::oox::core::FragmentHandler2 const &rParent, sal_Int32 aElement, const TimeNodePtr &pNode, AnimationConditionList &aCondList)
CT_TLTimeConditionList.
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
virtual ~CondListContext() noexcept override
std::vector< AnimationCondition > AnimationConditionList
Provides access to attribute values of an element.
AnimationConditionList & maConditions
virtual ~CondContext() noexcept override
css::animations::Event maEvent
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
CT_TLTimeCondition.
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
std::shared_ptr< TimeNode > TimeNodePtr
Definition: timenode.hxx:44
AnimationCondition & maCond
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
AnimTargetElementPtr & getTarget()
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)