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