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