merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ppt / conditioncontext.cxx
blob8c49785486e55d7b96e34ac56875b95bde528f46
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: conditioncontext.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "conditioncontext.hxx"
33 #include "comphelper/anytostring.hxx"
34 #include "cppuhelper/exc_hlp.hxx"
35 #include <osl/diagnose.h>
37 #include <com/sun/star/animations/XTimeContainer.hpp>
38 #include <com/sun/star/animations/XAnimationNode.hpp>
39 #include <com/sun/star/animations/AnimationEndSync.hpp>
40 #include <com/sun/star/animations/EventTrigger.hpp>
42 #include "oox/helper/attributelist.hxx"
43 #include "oox/core/namespaces.hxx"
44 #include "oox/core/contexthandler.hxx"
45 #include "oox/ppt/animationspersist.hxx"
46 #include "animationtypes.hxx"
48 #include "timetargetelementcontext.hxx"
49 #include "tokens.hxx"
51 using namespace ::oox::core;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::xml::sax;
54 using namespace ::com::sun::star::animations;
56 namespace oox { namespace ppt {
58 CondContext::CondContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs,
59 const TimeNodePtr & pNode, AnimationCondition & aValue )
60 : TimeNodeContext( rParent, NMSP_PPT|XML_cond, xAttribs, pNode )
61 , maCond( aValue )
63 maEvent.Trigger = EventTrigger::NONE;
64 maEvent.Repeat = 0;
66 AttributeList attribs( xAttribs );
67 if( attribs.hasAttribute( XML_evt ) )
69 sal_Int32 nEvent = xAttribs->getOptionalValueToken( XML_evt, 0 );
70 switch( nEvent )
72 case XML_onBegin:
73 maEvent.Trigger = EventTrigger::ON_BEGIN;
74 break;
75 case XML_onEnd:
76 maEvent.Trigger = EventTrigger::ON_END;
77 break;
78 case XML_begin:
79 maEvent.Trigger = EventTrigger::BEGIN_EVENT;
80 break;
81 case XML_end:
82 maEvent.Trigger = EventTrigger::END_EVENT;
83 break;
84 case XML_onClick:
85 maEvent.Trigger = EventTrigger::ON_CLICK;
86 break;
87 case XML_onDblClick:
88 maEvent.Trigger = EventTrigger::ON_DBL_CLICK;
89 break;
90 case XML_onMouseOver:
91 maEvent.Trigger = EventTrigger::ON_MOUSE_ENTER;
92 break;
93 case XML_onMouseOut:
94 maEvent.Trigger = EventTrigger::ON_MOUSE_LEAVE;
95 break;
96 case XML_onNext:
97 maEvent.Trigger = EventTrigger::ON_NEXT;
98 break;
99 case XML_onPrev:
100 maEvent.Trigger = EventTrigger::ON_PREV;
101 break;
102 case XML_onStopAudio:
103 maEvent.Trigger = EventTrigger::ON_STOP_AUDIO;
104 break;
105 default:
106 break;
109 if( attribs.hasAttribute( XML_delay ) || ( maEvent.Trigger == EventTrigger::NONE ) )
111 maEvent.Offset = GetTime( xAttribs->getOptionalValue( XML_delay ) );
115 CondContext::~CondContext( ) throw( )
117 if( maCond.mnType == 0 )
119 maCond.maValue = (maEvent.Trigger == EventTrigger::NONE) ? maEvent.Offset : makeAny( maEvent );
123 Reference< XFastContextHandler > SAL_CALL CondContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
125 Reference< XFastContextHandler > xRet;
127 switch( aElementToken )
129 case NMSP_PPT|XML_rtn:
131 // ST_TLTriggerRuntimeNode { first, last, all }
132 sal_Int32 aTok;
133 sal_Int16 nEnum;
134 aTok = xAttribs->getOptionalValueToken( XML_val, XML_first );
135 switch( aTok )
137 case XML_first:
138 nEnum = AnimationEndSync::FIRST;
139 break;
140 case XML_last:
141 nEnum = AnimationEndSync::LAST;
142 break;
143 case XML_all:
144 nEnum = AnimationEndSync::ALL;
145 break;
146 default:
147 break;
149 maCond.mnType = aElementToken;
150 maCond.maValue = makeAny( nEnum );
151 break;
153 case NMSP_PPT|XML_tn:
155 maCond.mnType = aElementToken;
156 AttributeList attribs( xAttribs );
157 sal_uInt32 nId = attribs.getUnsigned( XML_val, 0 );
158 maCond.maValue = makeAny( nId );
159 break;
161 case NMSP_PPT|XML_tgtEl:
162 // CT_TLTimeTargetElement
163 xRet.set( new TimeTargetElementContext( *this, maCond.getTarget() ) );
164 break;
165 default:
166 break;
169 if( !xRet.is() )
170 xRet.set( this );
172 return xRet;
178 /** CT_TLTimeConditionList */
179 CondListContext::CondListContext(
180 ContextHandler& rParent, sal_Int32 aElement,
181 const Reference< XFastAttributeList >& xAttribs,
182 const TimeNodePtr & pNode,
183 AnimationConditionList & aCond )
184 : TimeNodeContext( rParent, aElement, xAttribs, pNode )
185 , maConditions( aCond )
189 CondListContext::~CondListContext( )
190 throw( )
194 Reference< XFastContextHandler > CondListContext::createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
196 Reference< XFastContextHandler > xRet;
198 switch( aElement )
200 case NMSP_PPT|XML_cond:
201 // add a condition to the list
202 maConditions.push_back( AnimationCondition() );
203 xRet.set( new CondContext( *this, xAttribs, mpNode, maConditions.back() ) );
204 break;
205 default:
206 break;
209 if( !xRet.is() )
210 xRet.set( this );
212 return xRet;