1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "conditioncontext.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
27cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/animations/XTimeContainer.hpp>
31cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp>
32cdf0e10cSrcweir #include <com/sun/star/animations/AnimationEndSync.hpp>
33cdf0e10cSrcweir #include <com/sun/star/animations/EventTrigger.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
36cdf0e10cSrcweir #include "oox/core/contexthandler.hxx"
37cdf0e10cSrcweir #include "oox/ppt/animationspersist.hxx"
38cdf0e10cSrcweir #include "animationtypes.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "timetargetelementcontext.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace ::oox::core;
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
45cdf0e10cSrcweir using namespace ::com::sun::star::animations;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace oox { namespace ppt {
48cdf0e10cSrcweir 
CondContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,const TimeNodePtr & pNode,AnimationCondition & aValue)49cdf0e10cSrcweir     CondContext::CondContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs,
50cdf0e10cSrcweir                 const TimeNodePtr & pNode, AnimationCondition & aValue )
51cdf0e10cSrcweir         :  TimeNodeContext( rParent, PPT_TOKEN( cond ), xAttribs, pNode )
52cdf0e10cSrcweir 		, maCond( aValue )
53cdf0e10cSrcweir 	{
54cdf0e10cSrcweir 		maEvent.Trigger =  EventTrigger::NONE;
55cdf0e10cSrcweir 		maEvent.Repeat = 0;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 		AttributeList attribs( xAttribs );
58cdf0e10cSrcweir 		if( attribs.hasAttribute( XML_evt ) )
59cdf0e10cSrcweir 		{
60cdf0e10cSrcweir 			sal_Int32 nEvent = xAttribs->getOptionalValueToken( XML_evt, 0 );
61cdf0e10cSrcweir 			switch( nEvent )
62cdf0e10cSrcweir 			{
63cdf0e10cSrcweir 			case XML_onBegin:
64cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_BEGIN;
65cdf0e10cSrcweir 				break;
66cdf0e10cSrcweir 			case XML_onEnd:
67cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_END;
68cdf0e10cSrcweir 				break;
69cdf0e10cSrcweir 			case XML_begin:
70cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::BEGIN_EVENT;
71cdf0e10cSrcweir 				break;
72cdf0e10cSrcweir 			case XML_end:
73cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::END_EVENT;
74cdf0e10cSrcweir 				break;
75cdf0e10cSrcweir 			case XML_onClick:
76cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_CLICK;
77cdf0e10cSrcweir 				break;
78cdf0e10cSrcweir 			case XML_onDblClick:
79cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_DBL_CLICK;
80cdf0e10cSrcweir 				break;
81cdf0e10cSrcweir 			case XML_onMouseOver:
82cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_MOUSE_ENTER;
83cdf0e10cSrcweir 				break;
84cdf0e10cSrcweir 			case XML_onMouseOut:
85cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_MOUSE_LEAVE;
86cdf0e10cSrcweir 				break;
87cdf0e10cSrcweir 			case XML_onNext:
88cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_NEXT;
89cdf0e10cSrcweir 				break;
90cdf0e10cSrcweir 			case XML_onPrev:
91cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_PREV;
92cdf0e10cSrcweir 				break;
93cdf0e10cSrcweir 			case XML_onStopAudio:
94cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_STOP_AUDIO;
95cdf0e10cSrcweir 				break;
96cdf0e10cSrcweir 			default:
97cdf0e10cSrcweir 				break;
98cdf0e10cSrcweir 			}
99cdf0e10cSrcweir 		}
100cdf0e10cSrcweir 		if( attribs.hasAttribute( XML_delay ) || ( maEvent.Trigger == EventTrigger::NONE ) )
101cdf0e10cSrcweir 		{
102cdf0e10cSrcweir 			maEvent.Offset = GetTime( xAttribs->getOptionalValue( XML_delay ) );
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
~CondContext()106cdf0e10cSrcweir 	CondContext::~CondContext( ) throw( )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		if( maCond.mnType == 0 )
109cdf0e10cSrcweir 		{
110cdf0e10cSrcweir 			maCond.maValue = (maEvent.Trigger == EventTrigger::NONE) ? maEvent.Offset : makeAny( maEvent );
111cdf0e10cSrcweir 		}
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
createFastChildContext(::sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)114cdf0e10cSrcweir 	Reference< XFastContextHandler > SAL_CALL CondContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		Reference< XFastContextHandler > xRet;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		switch( aElementToken )
119cdf0e10cSrcweir 		{
120cdf0e10cSrcweir 		case PPT_TOKEN( rtn ):
121cdf0e10cSrcweir 		{
122cdf0e10cSrcweir 			// ST_TLTriggerRuntimeNode { first, last, all }
123cdf0e10cSrcweir 			sal_Int32 aTok;
124cdf0e10cSrcweir 			sal_Int16 nEnum;
125cdf0e10cSrcweir 			aTok = xAttribs->getOptionalValueToken( XML_val, XML_first );
126cdf0e10cSrcweir 			switch( aTok )
127cdf0e10cSrcweir 			{
128cdf0e10cSrcweir 			case XML_first:
129cdf0e10cSrcweir 				nEnum = AnimationEndSync::FIRST;
130cdf0e10cSrcweir 				break;
131cdf0e10cSrcweir 			case XML_last:
132cdf0e10cSrcweir 				nEnum = AnimationEndSync::LAST;
133cdf0e10cSrcweir 				break;
134cdf0e10cSrcweir 			case XML_all:
135cdf0e10cSrcweir 				nEnum = AnimationEndSync::ALL;
136cdf0e10cSrcweir 				break;
137cdf0e10cSrcweir 			default:
138cdf0e10cSrcweir 				break;
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 			maCond.mnType = aElementToken;
141cdf0e10cSrcweir 			maCond.maValue = makeAny( nEnum );
142cdf0e10cSrcweir 			break;
143cdf0e10cSrcweir 		}
144cdf0e10cSrcweir 		case PPT_TOKEN( tn ):
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir 			maCond.mnType = aElementToken;
147cdf0e10cSrcweir 			AttributeList attribs( xAttribs );
148cdf0e10cSrcweir             sal_uInt32 nId = attribs.getUnsigned( XML_val, 0 );
149cdf0e10cSrcweir 			maCond.maValue = makeAny( nId );
150cdf0e10cSrcweir 			break;
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir 		case PPT_TOKEN( tgtEl ):
153cdf0e10cSrcweir 			// CT_TLTimeTargetElement
154cdf0e10cSrcweir             xRet.set( new TimeTargetElementContext( *this, maCond.getTarget() ) );
155cdf0e10cSrcweir 			break;
156cdf0e10cSrcweir 		default:
157cdf0e10cSrcweir 			break;
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		if( !xRet.is() )
161cdf0e10cSrcweir 			xRet.set( this );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		return xRet;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	/** CT_TLTimeConditionList */
CondListContext(ContextHandler & rParent,sal_Int32 aElement,const Reference<XFastAttributeList> & xAttribs,const TimeNodePtr & pNode,AnimationConditionList & aCond)170cdf0e10cSrcweir     CondListContext::CondListContext(
171cdf0e10cSrcweir             ContextHandler& rParent, sal_Int32  aElement,
172cdf0e10cSrcweir             const Reference< XFastAttributeList >& xAttribs,
173cdf0e10cSrcweir             const TimeNodePtr & pNode,
174cdf0e10cSrcweir             AnimationConditionList & aCond )
175cdf0e10cSrcweir         : TimeNodeContext( rParent, aElement, xAttribs, pNode )
176cdf0e10cSrcweir 		, maConditions( aCond )
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
~CondListContext()180cdf0e10cSrcweir 	CondListContext::~CondListContext( )
181cdf0e10cSrcweir 		throw( )
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir 
createFastChildContext(::sal_Int32 aElement,const Reference<XFastAttributeList> & xAttribs)185cdf0e10cSrcweir 	Reference< XFastContextHandler > CondListContext::createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		Reference< XFastContextHandler > xRet;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 		switch( aElement )
190cdf0e10cSrcweir 		{
191cdf0e10cSrcweir 		case PPT_TOKEN( cond ):
192cdf0e10cSrcweir 			// add a condition to the list
193cdf0e10cSrcweir 			maConditions.push_back( AnimationCondition() );
194cdf0e10cSrcweir             xRet.set( new CondContext( *this, xAttribs, mpNode, maConditions.back() ) );
195cdf0e10cSrcweir 			break;
196cdf0e10cSrcweir 		default:
197cdf0e10cSrcweir 			break;
198cdf0e10cSrcweir 		}
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 		if( !xRet.is() )
201cdf0e10cSrcweir 			xRet.set( this );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 		return xRet;
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir } }
208cdf0e10cSrcweir 
209