Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SLIDESHOW_TOOLS_HXX
21 : #define INCLUDED_SLIDESHOW_TOOLS_HXX
22 :
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 :
26 : #include <cppcanvas/color.hxx>
27 :
28 : #include "shapeattributelayer.hxx"
29 : #include "shape.hxx"
30 : #include "rgbcolor.hxx"
31 : #include "hslcolor.hxx"
32 :
33 : #include <boost/shared_ptr.hpp>
34 : #include <boost/current_function.hpp>
35 :
36 : #include <functional>
37 : #include <cstdlib>
38 : #include <string.h> // for strcmp
39 : #include <algorithm>
40 :
41 :
42 :
43 : namespace com { namespace sun { namespace star { namespace beans {
44 : struct NamedValue;
45 : } } } }
46 : namespace basegfx
47 : {
48 : class B2DRange;
49 : class B2DVector;
50 : class B2IVector;
51 : class B2DHomMatrix;
52 : }
53 : namespace cppcanvas{ class Canvas; }
54 :
55 : class GDIMetaFile;
56 :
57 : /* Definition of some animation tools */
58 : namespace slideshow
59 : {
60 : namespace internal
61 : {
62 : class UnoView;
63 : class Shape;
64 : class ShapeAttributeLayer;
65 :
66 : typedef ::boost::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr;
67 :
68 : template <typename T>
69 0 : inline ::std::size_t hash_value( T * const& p )
70 : {
71 : ::std::size_t d = static_cast< ::std::size_t >(
72 0 : reinterpret_cast< ::std::ptrdiff_t >(p) );
73 0 : return d + (d >> 3);
74 : }
75 :
76 : // xxx todo: remove with boost::hash when 1.33 is available
77 : template <typename T>
78 : struct hash : ::std::unary_function<T, ::std::size_t>
79 : {
80 0 : ::std::size_t operator()( T const& val ) const {
81 0 : return hash_value(val);
82 : }
83 : };
84 : }
85 : }
86 :
87 : namespace com { namespace sun { namespace star { namespace uno {
88 :
89 : template <typename T>
90 0 : inline ::std::size_t hash_value(
91 : ::com::sun::star::uno::Reference<T> const& x )
92 : {
93 : // normalize to object root, because _only_ XInterface is defined
94 : // to be stable during object lifetime:
95 : ::com::sun::star::uno::Reference<
96 : ::com::sun::star::uno::XInterface> const xRoot(
97 0 : x, ::com::sun::star::uno::UNO_QUERY );
98 0 : return slideshow::internal::hash<void *>()(xRoot.get());
99 : }
100 :
101 : } } } }
102 :
103 : namespace slideshow
104 : {
105 : namespace internal
106 : {
107 : /** Cycle mode of intrinsic animations
108 : */
109 : enum CycleMode
110 : {
111 : /// loop the animation back to back
112 : CYCLE_LOOP,
113 : /// loop, but play backwards from end to start
114 : CYCLE_PINGPONGLOOP
115 : };
116 :
117 :
118 : // Value extraction from Any
119 : // =========================
120 :
121 : /// extract unary double value from Any
122 : bool extractValue( double& o_rValue,
123 : const ::com::sun::star::uno::Any& rSourceAny,
124 : const boost::shared_ptr<Shape>& rShape,
125 : const basegfx::B2DVector& rSlideBounds );
126 :
127 : /// extract int from Any
128 : bool extractValue( sal_Int32& o_rValue,
129 : const ::com::sun::star::uno::Any& rSourceAny,
130 : const boost::shared_ptr<Shape>& rShape,
131 : const basegfx::B2DVector& rSlideBounds );
132 :
133 : /// extract enum/constant group value from Any
134 : bool extractValue( sal_Int16& o_rValue,
135 : const ::com::sun::star::uno::Any& rSourceAny,
136 : const boost::shared_ptr<Shape>& rShape,
137 : const basegfx::B2DVector& rSlideBounds );
138 :
139 : /// extract color value from Any
140 : bool extractValue( RGBColor& o_rValue,
141 : const ::com::sun::star::uno::Any& rSourceAny,
142 : const boost::shared_ptr<Shape>& rShape,
143 : const basegfx::B2DVector& rSlideBounds );
144 :
145 : /// extract color value from Any
146 : bool extractValue( HSLColor& o_rValue,
147 : const ::com::sun::star::uno::Any& rSourceAny,
148 : const boost::shared_ptr<Shape>& rShape,
149 : const basegfx::B2DVector& rSlideBounds );
150 :
151 : /// extract plain string from Any
152 : bool extractValue( OUString& o_rValue,
153 : const ::com::sun::star::uno::Any& rSourceAny,
154 : const boost::shared_ptr<Shape>& rShape,
155 : const basegfx::B2DVector& rSlideBounds );
156 :
157 : /// extract bool value from Any
158 : bool extractValue( bool& o_rValue,
159 : const ::com::sun::star::uno::Any& rSourceAny,
160 : const boost::shared_ptr<Shape>& rShape,
161 : const basegfx::B2DVector& rSlideBounds );
162 :
163 : /// extract double 2-tuple from Any
164 : bool extractValue( basegfx::B2DTuple& o_rPair,
165 : const ::com::sun::star::uno::Any& rSourceAny,
166 : const boost::shared_ptr<Shape>& rShape,
167 : const basegfx::B2DVector& rSlideBounds );
168 :
169 : /** Search a sequence of NamedValues for a given element.
170 :
171 : @return true, if the sequence contains the specified
172 : element.
173 : */
174 : bool findNamedValue( ::com::sun::star::uno::Sequence<
175 : ::com::sun::star::beans::NamedValue > const& rSequence,
176 : const ::com::sun::star::beans::NamedValue& rSearchKey );
177 :
178 : basegfx::B2DRange calcRelativeShapeBounds( const basegfx::B2DVector& rPageSize,
179 : const basegfx::B2DRange& rShapeBounds );
180 :
181 : /** Get the shape transformation from the attribute set
182 :
183 : @param rBounds
184 : Original shape bound rect (to substitute default attribute
185 : layer values)
186 :
187 : @param pAttr
188 : Attribute set. Might be NULL (then, rBounds is used to set
189 : a simple scale and translate of the unit rect to rBounds).
190 : */
191 : basegfx::B2DHomMatrix getShapeTransformation(
192 : const basegfx::B2DRange& rBounds,
193 : const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
194 :
195 : /** Get a shape's sprite transformation from the attribute set
196 :
197 : @param rPixelSize
198 : Pixel size of the sprite
199 :
200 : @param rOrigSize
201 : Original shape size (i.e. the size of the actual sprite
202 : content, in the user coordinate system)
203 :
204 : @param pAttr
205 : Attribute set. Might be NULL (then, rBounds is used to set
206 : a simple scale and translate of the unit rect to rBounds).
207 :
208 : @return the transformation to be applied to the sprite.
209 : */
210 : basegfx::B2DHomMatrix getSpriteTransformation(
211 : const basegfx::B2DVector& rPixelSize,
212 : const basegfx::B2DVector& rOrigSize,
213 : const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
214 :
215 : /** Calc update area for a shape.
216 :
217 : This method calculates the 'covered' area for the shape,
218 : i.e. the rectangle that is affected when rendering the
219 : shape. Apart from applying the given transformation to the
220 : shape rectangle, this method also takes attributes into
221 : account, which further scale the output (e.g. character
222 : sizes).
223 :
224 : @param rUnitBounds
225 : Shape bounds, in the unit rect coordinate space
226 :
227 : @param rShapeTransform
228 : Transformation matrix the shape should undergo.
229 :
230 : @param pAttr
231 : Current shape attributes
232 : */
233 : basegfx::B2DRange getShapeUpdateArea(
234 : const basegfx::B2DRange& rUnitBounds,
235 : const basegfx::B2DHomMatrix& rShapeTransform,
236 : const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
237 :
238 : /** Calc update area for a shape.
239 :
240 : This method calculates the 'covered' area for the shape,
241 : i.e. the rectangle that is affected when rendering the
242 : shape. The difference from the other getShapeUpdateArea()
243 : method is the fact that this one works without
244 : ShapeAttributeLayer, and only scales up the given shape
245 : user coordinate bound rect. The method is typically used
246 : to retrieve user coordinate system bound rects for shapes
247 : which are smaller than the default unit bound rect
248 : (because e.g. of subsetting)
249 :
250 : @param rUnitBounds
251 : Shape bounds, in the unit rect coordinate space
252 :
253 : @param rShapeBounds
254 : Current shape bounding box in user coordinate space.
255 : */
256 : basegfx::B2DRange getShapeUpdateArea( const basegfx::B2DRange& rUnitBounds,
257 : const basegfx::B2DRange& rShapeBounds );
258 :
259 : /** Calc output position and size of shape, according to given
260 : attribute layer.
261 :
262 : Rotations, shears etc. and not taken into account,
263 : i.e. the returned rectangle is NOT the bounding box. Use
264 : it as if aBounds.getMinimum() is the output position and
265 : aBounds.getRange() the scaling of the shape.
266 : */
267 : basegfx::B2DRange getShapePosSize(
268 : const basegfx::B2DRange& rOrigBounds,
269 : const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
270 :
271 : /** Convert a plain UNO API 32 bit int to RGBColor
272 : */
273 : RGBColor unoColor2RGBColor( sal_Int32 );
274 : /** Convert an IntSRGBA to plain UNO API 32 bit int
275 : */
276 : sal_Int32 RGBAColor2UnoColor( cppcanvas::Color::IntSRGBA );
277 :
278 : /** Fill a plain rectangle on the given canvas with the given color
279 : */
280 : void fillRect( const boost::shared_ptr< cppcanvas::Canvas >& rCanvas,
281 : const basegfx::B2DRange& rRect,
282 : cppcanvas::Color::IntSRGBA aFillColor );
283 :
284 : /** Init canvas with default background (white)
285 : */
286 : void initSlideBackground( const boost::shared_ptr< cppcanvas::Canvas >& rCanvas,
287 : const basegfx::B2IVector& rSize );
288 :
289 : /// Gets a random ordinal [0,n)
290 0 : inline ::std::size_t getRandomOrdinal( const ::std::size_t n )
291 : {
292 : return static_cast< ::std::size_t >(
293 0 : double(n) * rand() / (RAND_MAX + 1.0) );
294 : }
295 :
296 : /// To work around ternary operator in initializer lists
297 : /// (Solaris compiler problems)
298 : template <typename T>
299 : inline T const & ternary_op(
300 : const bool cond, T const & arg1, T const & arg2 )
301 : {
302 : if (cond)
303 : return arg1;
304 : else
305 : return arg2;
306 : }
307 :
308 : template <typename ValueType>
309 0 : inline bool getPropertyValue(
310 : ValueType & rValue,
311 : com::sun::star::uno::Reference<
312 : com::sun::star::beans::XPropertySet> const & xPropSet,
313 : OUString const & propName )
314 : {
315 : try {
316 : const com::sun::star::uno::Any& a(
317 0 : xPropSet->getPropertyValue( propName ) );
318 0 : bool const bRet = (a >>= rValue);
319 : #if OSL_DEBUG_LEVEL > 0
320 : if( !bRet )
321 : OSL_TRACE( "%s: while retrieving property %s, cannot extract Any of type %s\n",
322 : OUStringToOString( propName,
323 : RTL_TEXTENCODING_ASCII_US ).getStr(),
324 : BOOST_CURRENT_FUNCTION,
325 : OUStringToOString( a.getValueTypeRef()->pTypeName,
326 : RTL_TEXTENCODING_ASCII_US ).getStr() );
327 : #endif
328 0 : return bRet;
329 : }
330 0 : catch (com::sun::star::uno::RuntimeException &)
331 : {
332 0 : throw;
333 : }
334 0 : catch (com::sun::star::uno::Exception &)
335 : {
336 0 : return false;
337 : }
338 : }
339 :
340 : template <typename ValueType>
341 0 : inline bool getPropertyValue(
342 : com::sun::star::uno::Reference< ValueType >& rIfc,
343 : com::sun::star::uno::Reference<
344 : com::sun::star::beans::XPropertySet> const & xPropSet,
345 : OUString const & propName )
346 : {
347 : try
348 : {
349 : const com::sun::star::uno::Any& a(
350 0 : xPropSet->getPropertyValue( propName ));
351 0 : rIfc.set( a,
352 : com::sun::star::uno::UNO_QUERY );
353 :
354 0 : bool const bRet = rIfc.is();
355 : #if OSL_DEBUG_LEVEL > 0
356 : if( !bRet )
357 : OSL_TRACE( "%s: while retrieving property %s, cannot extract Any of type %s to interface\n",
358 : OUStringToOString( propName,
359 : RTL_TEXTENCODING_ASCII_US ).getStr(),
360 : BOOST_CURRENT_FUNCTION,
361 : OUStringToOString( a.getValueTypeRef()->pTypeName,
362 : RTL_TEXTENCODING_ASCII_US ).getStr() );
363 : #endif
364 0 : return bRet;
365 : }
366 0 : catch (com::sun::star::uno::RuntimeException &)
367 : {
368 0 : throw;
369 : }
370 0 : catch (com::sun::star::uno::Exception &)
371 : {
372 0 : return false;
373 : }
374 : }
375 :
376 : /// Get the content of the BoundRect shape property
377 : basegfx::B2DRange getAPIShapeBounds( const ::com::sun::star::uno::Reference<
378 : ::com::sun::star::drawing::XShape >& xShape );
379 :
380 : /*
381 : TODO(F1): When ZOrder someday becomes usable enable this
382 :
383 : /// Get the content of the ZOrder shape property
384 : double getAPIShapePrio( const ::com::sun::star::uno::Reference<
385 : ::com::sun::star::drawing::XShape >& xShape );
386 : */
387 :
388 : basegfx::B2IVector getSlideSizePixel( const basegfx::B2DVector& rSize,
389 : const boost::shared_ptr<UnoView>& pView );
390 : }
391 : }
392 :
393 : #endif /* INCLUDED_SLIDESHOW_TOOLS_HXX */
394 :
395 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|