Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / ppt / conditioncontext.cxx
blobb69d8009db60dc62f9f98e81a0daa4026ca5d58a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "conditioncontext.hxx"
22 #include "comphelper/anytostring.hxx"
23 #include "cppuhelper/exc_hlp.hxx"
25 #include <com/sun/star/animations/XTimeContainer.hpp>
26 #include <com/sun/star/animations/XAnimationNode.hpp>
27 #include <com/sun/star/animations/AnimationEndSync.hpp>
28 #include <com/sun/star/animations/EventTrigger.hpp>
30 #include "oox/helper/attributelist.hxx"
31 #include "oox/ppt/animationspersist.hxx"
32 #include "animationtypes.hxx"
33 #include <oox/token/namespaces.hxx>
34 #include <oox/token/tokens.hxx>
36 #include "timetargetelementcontext.hxx"
38 using namespace ::oox::core;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::xml::sax;
41 using namespace ::com::sun::star::animations;
43 namespace oox { namespace ppt {
45 CondContext::CondContext( FragmentHandler2& rParent, const Reference< XFastAttributeList >& xAttribs,
46 const TimeNodePtr & pNode, AnimationCondition & aValue )
47 : TimeNodeContext( rParent, PPT_TOKEN( cond ), xAttribs, pNode )
48 , maCond( aValue )
50 maEvent.Trigger = EventTrigger::NONE;
51 maEvent.Repeat = 0;
53 AttributeList attribs( xAttribs );
54 if( attribs.hasAttribute( XML_evt ) )
56 sal_Int32 nEvent = xAttribs->getOptionalValueToken( XML_evt, 0 );
57 switch( nEvent )
59 case XML_onBegin:
60 maEvent.Trigger = EventTrigger::ON_BEGIN;
61 break;
62 case XML_onEnd:
63 maEvent.Trigger = EventTrigger::ON_END;
64 break;
65 case XML_begin:
66 maEvent.Trigger = EventTrigger::BEGIN_EVENT;
67 break;
68 case XML_end:
69 maEvent.Trigger = EventTrigger::END_EVENT;
70 break;
71 case XML_onClick:
72 maEvent.Trigger = EventTrigger::ON_CLICK;
73 break;
74 case XML_onDblClick:
75 maEvent.Trigger = EventTrigger::ON_DBL_CLICK;
76 break;
77 case XML_onMouseOver:
78 maEvent.Trigger = EventTrigger::ON_MOUSE_ENTER;
79 break;
80 case XML_onMouseOut:
81 maEvent.Trigger = EventTrigger::ON_MOUSE_LEAVE;
82 break;
83 case XML_onNext:
84 maEvent.Trigger = EventTrigger::ON_NEXT;
85 break;
86 case XML_onPrev:
87 maEvent.Trigger = EventTrigger::ON_PREV;
88 break;
89 case XML_onStopAudio:
90 maEvent.Trigger = EventTrigger::ON_STOP_AUDIO;
91 break;
92 default:
93 break;
96 if( attribs.hasAttribute( XML_delay ) || ( maEvent.Trigger == EventTrigger::NONE ) )
98 maEvent.Offset = GetTime( xAttribs->getOptionalValue( XML_delay ) );
102 CondContext::~CondContext( ) throw( )
104 if( maCond.mnType == 0 )
106 maCond.maValue = (maEvent.Trigger == EventTrigger::NONE) ? maEvent.Offset : makeAny( maEvent );
110 ::oox::core::ContextHandlerRef CondContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
112 switch( aElementToken )
114 case PPT_TOKEN( rtn ):
116 // ST_TLTriggerRuntimeNode { first, last, all }
117 sal_Int32 aTok;
118 sal_Int16 nEnum;
119 aTok = rAttribs.getToken( XML_val, XML_first );
120 switch( aTok )
122 case XML_first:
123 nEnum = AnimationEndSync::FIRST;
124 break;
125 case XML_last:
126 nEnum = AnimationEndSync::LAST;
127 break;
128 case XML_all:
129 nEnum = AnimationEndSync::ALL;
130 break;
131 default:
132 break;
134 maCond.mnType = aElementToken;
135 maCond.maValue <<= nEnum;
136 return this;
138 case PPT_TOKEN( tn ):
140 maCond.mnType = aElementToken;
141 sal_uInt32 nId = rAttribs.getUnsigned( XML_val, 0 );
142 maCond.maValue <<= nId;
143 return this;
145 case PPT_TOKEN( tgtEl ):
146 // CT_TLTimeTargetElement
147 return new TimeTargetElementContext( *this, maCond.getTarget() );
148 default:
149 break;
152 return this;
156 /** CT_TLTimeConditionList */
157 CondListContext::CondListContext(
158 FragmentHandler2& rParent, sal_Int32 aElement,
159 const Reference< XFastAttributeList >& xAttribs,
160 const TimeNodePtr & pNode,
161 AnimationConditionList & aCond )
162 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
163 , maConditions( aCond )
167 CondListContext::~CondListContext( )
168 throw( )
172 ::oox::core::ContextHandlerRef CondListContext::onCreateContext( sal_Int32 aElement, const AttributeList& rAttribs )
174 switch( aElement )
176 case PPT_TOKEN( cond ):
177 // add a condition to the list
178 maConditions.push_back( AnimationCondition() );
179 return new CondContext( *this, rAttribs.getFastAttributeList(), mpNode, maConditions.back() );
180 default:
181 break;
183 return this;
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */