xref: /trunk/main/slideshow/source/engine/animationnodes/nodetools.cxx (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_slideshow.hxx"
24 
25 // must be first
26 #include <canvas/debug.hxx>
27 #include <canvas/verbosetrace.hxx>
28 
29 #include <com/sun/star/animations/Timing.hpp>
30 
31 #include <tools.hxx>
32 #include <nodetools.hxx>
33 
34 
35 using namespace ::com::sun::star;
36 
37 namespace slideshow
38 {
39     namespace internal
40     {
41 #if defined(VERBOSE) && defined(DBG_UTIL)
42         int& debugGetCurrentOffset()
43         {
44             static int lcl_nOffset = 0; // to make each tree output distinct
45 
46             return lcl_nOffset;
47         }
48 
49         void debugNodesShowTree( const BaseNode* pNode )
50         {
51             if( pNode )
52                 pNode->showState();
53 
54             ++debugGetCurrentOffset();
55         }
56 
57         void debugNodesShowTreeWithin( const BaseNode* pNode )
58         {
59             if( pNode )
60                 pNode->showTreeFromWithin();
61 
62             ++debugGetCurrentOffset();
63         }
64 #endif
65 
66         AttributableShapeSharedPtr lookupAttributableShape( const ShapeManagerSharedPtr&                rShapeManager,
67                                                             const uno::Reference< drawing::XShape >&    xShape          )
68         {
69             ENSURE_OR_THROW( rShapeManager,
70                               "lookupAttributableShape(): invalid ShapeManager" );
71 
72             ShapeSharedPtr pShape( rShapeManager->lookupShape( xShape ) );
73 
74             ENSURE_OR_THROW( pShape,
75                               "lookupAttributableShape(): no shape found for given XShape" );
76 
77             AttributableShapeSharedPtr pRes(
78                 ::boost::dynamic_pointer_cast< AttributableShape >( pShape ) );
79 
80             // TODO(E3): Cannot throw here, people might set animation info
81             // for non-animatable shapes from the API. AnimationNodes must catch
82             // the exception and handle that differently
83             ENSURE_OR_THROW( pRes,
84                               "lookupAttributableShape(): shape found does not implement AttributableShape interface" );
85 
86             return pRes;
87         }
88 
89         bool isIndefiniteTiming( const uno::Any& rAny )
90         {
91             if( !rAny.hasValue() )
92                 return true;
93 
94             animations::Timing eTiming;
95 
96             if( !(rAny >>= eTiming) ||
97                 eTiming != animations::Timing_INDEFINITE )
98             {
99                 return false;
100             }
101 
102             return true;
103         }
104 
105         // Extract the node type from the user data
106         bool getNodeType( sal_Int16&                                            o_rNodeType,
107                           const uno::Sequence< beans::NamedValue >&             rValues )
108         {
109             beans::NamedValue aNamedValue;
110 
111             if( findNamedValue( &aNamedValue,
112                                 rValues,
113                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("node-type") ) ) )
114             {
115                 if( (aNamedValue.Value >>= o_rNodeType) )
116                     return true;
117             }
118 
119             return false;
120         }
121     }
122 }
123 
124 /* vim: set noet sw=4 ts=4: */
125