xref: /AOO41X/main/oox/source/ppt/conditioncontext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "conditioncontext.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
31*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
32*cdf0e10cSrcweir #include <osl/diagnose.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <com/sun/star/animations/XTimeContainer.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/animations/AnimationEndSync.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/animations/EventTrigger.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
40*cdf0e10cSrcweir #include "oox/core/contexthandler.hxx"
41*cdf0e10cSrcweir #include "oox/ppt/animationspersist.hxx"
42*cdf0e10cSrcweir #include "animationtypes.hxx"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include "timetargetelementcontext.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace ::oox::core;
47*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
49*cdf0e10cSrcweir using namespace ::com::sun::star::animations;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir namespace oox { namespace ppt {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     CondContext::CondContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs,
54*cdf0e10cSrcweir                 const TimeNodePtr & pNode, AnimationCondition & aValue )
55*cdf0e10cSrcweir         :  TimeNodeContext( rParent, PPT_TOKEN( cond ), xAttribs, pNode )
56*cdf0e10cSrcweir 		, maCond( aValue )
57*cdf0e10cSrcweir 	{
58*cdf0e10cSrcweir 		maEvent.Trigger =  EventTrigger::NONE;
59*cdf0e10cSrcweir 		maEvent.Repeat = 0;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 		AttributeList attribs( xAttribs );
62*cdf0e10cSrcweir 		if( attribs.hasAttribute( XML_evt ) )
63*cdf0e10cSrcweir 		{
64*cdf0e10cSrcweir 			sal_Int32 nEvent = xAttribs->getOptionalValueToken( XML_evt, 0 );
65*cdf0e10cSrcweir 			switch( nEvent )
66*cdf0e10cSrcweir 			{
67*cdf0e10cSrcweir 			case XML_onBegin:
68*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_BEGIN;
69*cdf0e10cSrcweir 				break;
70*cdf0e10cSrcweir 			case XML_onEnd:
71*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_END;
72*cdf0e10cSrcweir 				break;
73*cdf0e10cSrcweir 			case XML_begin:
74*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::BEGIN_EVENT;
75*cdf0e10cSrcweir 				break;
76*cdf0e10cSrcweir 			case XML_end:
77*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::END_EVENT;
78*cdf0e10cSrcweir 				break;
79*cdf0e10cSrcweir 			case XML_onClick:
80*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_CLICK;
81*cdf0e10cSrcweir 				break;
82*cdf0e10cSrcweir 			case XML_onDblClick:
83*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_DBL_CLICK;
84*cdf0e10cSrcweir 				break;
85*cdf0e10cSrcweir 			case XML_onMouseOver:
86*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_MOUSE_ENTER;
87*cdf0e10cSrcweir 				break;
88*cdf0e10cSrcweir 			case XML_onMouseOut:
89*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_MOUSE_LEAVE;
90*cdf0e10cSrcweir 				break;
91*cdf0e10cSrcweir 			case XML_onNext:
92*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_NEXT;
93*cdf0e10cSrcweir 				break;
94*cdf0e10cSrcweir 			case XML_onPrev:
95*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_PREV;
96*cdf0e10cSrcweir 				break;
97*cdf0e10cSrcweir 			case XML_onStopAudio:
98*cdf0e10cSrcweir 				maEvent.Trigger = EventTrigger::ON_STOP_AUDIO;
99*cdf0e10cSrcweir 				break;
100*cdf0e10cSrcweir 			default:
101*cdf0e10cSrcweir 				break;
102*cdf0e10cSrcweir 			}
103*cdf0e10cSrcweir 		}
104*cdf0e10cSrcweir 		if( attribs.hasAttribute( XML_delay ) || ( maEvent.Trigger == EventTrigger::NONE ) )
105*cdf0e10cSrcweir 		{
106*cdf0e10cSrcweir 			maEvent.Offset = GetTime( xAttribs->getOptionalValue( XML_delay ) );
107*cdf0e10cSrcweir 		}
108*cdf0e10cSrcweir 	}
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	CondContext::~CondContext( ) throw( )
111*cdf0e10cSrcweir 	{
112*cdf0e10cSrcweir 		if( maCond.mnType == 0 )
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir 			maCond.maValue = (maEvent.Trigger == EventTrigger::NONE) ? maEvent.Offset : makeAny( maEvent );
115*cdf0e10cSrcweir 		}
116*cdf0e10cSrcweir 	}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	Reference< XFastContextHandler > SAL_CALL CondContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
119*cdf0e10cSrcweir 	{
120*cdf0e10cSrcweir 		Reference< XFastContextHandler > xRet;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 		switch( aElementToken )
123*cdf0e10cSrcweir 		{
124*cdf0e10cSrcweir 		case PPT_TOKEN( rtn ):
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			// ST_TLTriggerRuntimeNode { first, last, all }
127*cdf0e10cSrcweir 			sal_Int32 aTok;
128*cdf0e10cSrcweir 			sal_Int16 nEnum;
129*cdf0e10cSrcweir 			aTok = xAttribs->getOptionalValueToken( XML_val, XML_first );
130*cdf0e10cSrcweir 			switch( aTok )
131*cdf0e10cSrcweir 			{
132*cdf0e10cSrcweir 			case XML_first:
133*cdf0e10cSrcweir 				nEnum = AnimationEndSync::FIRST;
134*cdf0e10cSrcweir 				break;
135*cdf0e10cSrcweir 			case XML_last:
136*cdf0e10cSrcweir 				nEnum = AnimationEndSync::LAST;
137*cdf0e10cSrcweir 				break;
138*cdf0e10cSrcweir 			case XML_all:
139*cdf0e10cSrcweir 				nEnum = AnimationEndSync::ALL;
140*cdf0e10cSrcweir 				break;
141*cdf0e10cSrcweir 			default:
142*cdf0e10cSrcweir 				break;
143*cdf0e10cSrcweir 			}
144*cdf0e10cSrcweir 			maCond.mnType = aElementToken;
145*cdf0e10cSrcweir 			maCond.maValue = makeAny( nEnum );
146*cdf0e10cSrcweir 			break;
147*cdf0e10cSrcweir 		}
148*cdf0e10cSrcweir 		case PPT_TOKEN( tn ):
149*cdf0e10cSrcweir 		{
150*cdf0e10cSrcweir 			maCond.mnType = aElementToken;
151*cdf0e10cSrcweir 			AttributeList attribs( xAttribs );
152*cdf0e10cSrcweir             sal_uInt32 nId = attribs.getUnsigned( XML_val, 0 );
153*cdf0e10cSrcweir 			maCond.maValue = makeAny( nId );
154*cdf0e10cSrcweir 			break;
155*cdf0e10cSrcweir 		}
156*cdf0e10cSrcweir 		case PPT_TOKEN( tgtEl ):
157*cdf0e10cSrcweir 			// CT_TLTimeTargetElement
158*cdf0e10cSrcweir             xRet.set( new TimeTargetElementContext( *this, maCond.getTarget() ) );
159*cdf0e10cSrcweir 			break;
160*cdf0e10cSrcweir 		default:
161*cdf0e10cSrcweir 			break;
162*cdf0e10cSrcweir 		}
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 		if( !xRet.is() )
165*cdf0e10cSrcweir 			xRet.set( this );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 		return xRet;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	}
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	/** CT_TLTimeConditionList */
174*cdf0e10cSrcweir     CondListContext::CondListContext(
175*cdf0e10cSrcweir             ContextHandler& rParent, sal_Int32  aElement,
176*cdf0e10cSrcweir             const Reference< XFastAttributeList >& xAttribs,
177*cdf0e10cSrcweir             const TimeNodePtr & pNode,
178*cdf0e10cSrcweir             AnimationConditionList & aCond )
179*cdf0e10cSrcweir         : TimeNodeContext( rParent, aElement, xAttribs, pNode )
180*cdf0e10cSrcweir 		, maConditions( aCond )
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	CondListContext::~CondListContext( )
185*cdf0e10cSrcweir 		throw( )
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	Reference< XFastContextHandler > CondListContext::createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
190*cdf0e10cSrcweir 	{
191*cdf0e10cSrcweir 		Reference< XFastContextHandler > xRet;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		switch( aElement )
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir 		case PPT_TOKEN( cond ):
196*cdf0e10cSrcweir 			// add a condition to the list
197*cdf0e10cSrcweir 			maConditions.push_back( AnimationCondition() );
198*cdf0e10cSrcweir             xRet.set( new CondContext( *this, xAttribs, mpNode, maConditions.back() ) );
199*cdf0e10cSrcweir 			break;
200*cdf0e10cSrcweir 		default:
201*cdf0e10cSrcweir 			break;
202*cdf0e10cSrcweir 		}
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		if( !xRet.is() )
205*cdf0e10cSrcweir 			xRet.set( this );
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 		return xRet;
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir } }
212*cdf0e10cSrcweir 
213