LibreOffice Module slideshow (master) 1
tools.hxx
Go to the documentation of this file.
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_SOURCE_INC_TOOLS_HXX
21#define INCLUDED_SLIDESHOW_SOURCE_INC_TOOLS_HXX
22
23#include <com/sun/star/uno/Sequence.hxx>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/uno/Reference.hxx>
26#include <com/sun/star/animations/XAnimationNode.hpp>
27#include <com/sun/star/container/XEnumerationAccess.hpp>
28#include <com/sun/star/container/XEnumeration.hpp>
29#include <comphelper/random.hxx>
30#include <sal/log.hxx>
31
32#include <cppcanvas/color.hxx>
33
35#include "shape.hxx"
36#include "rgbcolor.hxx"
37#include "hslcolor.hxx"
38
39#include <memory>
40
41namespace com::sun::star::beans { struct NamedValue; }
42namespace basegfx
43{
44 class B2DRange;
45 class B2DVector;
46 class B2IVector;
47 class B2DHomMatrix;
48 class B2ISize;
49}
50namespace cppcanvas{ class Canvas; }
51
52class GDIMetaFile;
53
54/* Definition of some animation tools */
55namespace slideshow
56{
57 namespace internal
58 {
59 class UnoView;
60 class Shape;
61 class ShapeAttributeLayer;
62 typedef std::shared_ptr< UnoView > UnoViewSharedPtr;
63 typedef std::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr;
64
65 template <typename T>
66 inline ::std::size_t hash_value( T const * p )
67 {
68 ::std::size_t d = static_cast< ::std::size_t >(
69 reinterpret_cast< ::std::ptrdiff_t >(p) );
70 return d + (d >> 3);
71 }
72
73 template <typename T>
74 struct hash
75 {
76 ::std::size_t operator()( T const& val ) const {
77 return hash_value(val);
78 }
79 };
80 }
81}
82
83namespace com::sun::star::uno {
84
85 template <typename T>
86 inline ::std::size_t hash_value(
87 css::uno::Reference<T> const& x )
88 {
89 // normalize to object root, because _only_ XInterface is defined
90 // to be stable during object lifetime:
91 css::uno::Reference< css::uno::XInterface> const xRoot( x, css::uno::UNO_QUERY );
92 return slideshow::internal::hash<void *>()(xRoot.get());
93 }
94
95}
96
97namespace slideshow
98{
99 namespace internal
100 {
101 // Value extraction from Any
102 // =========================
103
105 bool extractValue( double& o_rValue,
106 const css::uno::Any& rSourceAny,
107 const ShapeSharedPtr& rShape,
108 const basegfx::B2DVector& rSlideBounds );
109
111 bool extractValue( sal_Int32& o_rValue,
112 const css::uno::Any& rSourceAny,
113 const ShapeSharedPtr& rShape,
114 const basegfx::B2DVector& rSlideBounds );
115
117 bool extractValue( sal_Int16& o_rValue,
118 const css::uno::Any& rSourceAny,
119 const ShapeSharedPtr& rShape,
120 const basegfx::B2DVector& rSlideBounds );
121
123 bool extractValue( RGBColor& o_rValue,
124 const css::uno::Any& rSourceAny,
125 const ShapeSharedPtr& rShape,
126 const basegfx::B2DVector& rSlideBounds );
127
129 bool extractValue( HSLColor& o_rValue,
130 const css::uno::Any& rSourceAny,
131 const ShapeSharedPtr& rShape,
132 const basegfx::B2DVector& rSlideBounds );
133
135 bool extractValue( OUString& o_rValue,
136 const css::uno::Any& rSourceAny,
137 const ShapeSharedPtr& rShape,
138 const basegfx::B2DVector& rSlideBounds );
139
141 bool extractValue( bool& o_rValue,
142 const css::uno::Any& rSourceAny,
143 const ShapeSharedPtr& rShape,
144 const basegfx::B2DVector& rSlideBounds );
145
148 const css::uno::Any& rSourceAny,
149 const ShapeSharedPtr& rShape,
150 const basegfx::B2DVector& rSlideBounds );
151
157 bool findNamedValue( css::uno::Sequence< css::beans::NamedValue > const& rSequence,
158 const css::beans::NamedValue& rSearchKey );
159
161 const basegfx::B2DRange& rShapeBounds );
162
174 const basegfx::B2DRectangle& rBounds,
175 const ShapeAttributeLayerSharedPtr& pAttr );
176
193 const basegfx::B2DVector& rPixelSize,
194 const basegfx::B2DVector& rOrigSize,
195 const ShapeAttributeLayerSharedPtr& pAttr );
196
216 const basegfx::B2DRectangle& rUnitBounds,
217 const basegfx::B2DHomMatrix& rShapeTransform,
218 const ShapeAttributeLayerSharedPtr& pAttr );
219
239 const basegfx::B2DRange& rShapeBounds );
240
250 const basegfx::B2DRectangle& rOrigBounds,
251 const ShapeAttributeLayerSharedPtr& pAttr );
252
255 RGBColor unoColor2RGBColor( sal_Int32 );
259
263 const basegfx::B2DRectangle& rRect,
264 cppcanvas::IntSRGBA aFillColor );
265
269 const basegfx::B2ISize& rSize );
270
272 inline ::std::size_t getRandomOrdinal( const ::std::size_t n )
273 {
275 }
276
277 template <typename ValueType>
278 inline bool getPropertyValue(
279 ValueType & rValue,
280 css::uno::Reference<
281 css::beans::XPropertySet> const & xPropSet,
282 OUString const & propName )
283 {
284 try {
285 const css::uno::Any& a(
286 xPropSet->getPropertyValue( propName ) );
287 bool const bRet = css::uno::fromAny(a, &rValue);
288#if OSL_DEBUG_LEVEL > 0
289 if( !bRet )
290 SAL_INFO("slideshow", __func__ << ": while retrieving property " << propName << ", cannot extract Any of type "
291 << a.getValueTypeRef()->pTypeName);
292#endif
293 return bRet;
294 }
295 catch (css::uno::RuntimeException &)
296 {
297 throw;
298 }
299 catch (css::uno::Exception &)
300 {
301 return false;
302 }
303 }
304
305 template <typename ValueType>
306 inline bool getPropertyValue(
307 css::uno::Reference< ValueType >& rIfc,
308 css::uno::Reference< css::beans::XPropertySet> const & xPropSet,
309 OUString const & propName )
310 {
311 try
312 {
313 const css::uno::Any& a(xPropSet->getPropertyValue( propName ));
314 rIfc.set( a, css::uno::UNO_QUERY );
315
316 bool const bRet = rIfc.is();
317#if OSL_DEBUG_LEVEL > 0
318 if( !bRet )
319 SAL_INFO("slideshow", __func__ << ": while retrieving property " << propName << ", cannot extract Any of type "
320 << a.getValueTypeRef()->pTypeName << " to interface");
321#endif
322 return bRet;
323 }
324 catch (css::uno::RuntimeException &)
325 {
326 throw;
327 }
328 catch (css::uno::Exception &)
329 {
330 return false;
331 }
332 }
333
335 basegfx::B2DRectangle getAPIShapeBounds( const css::uno::Reference< css::drawing::XShape >& xShape );
336
337/*
338 TODO(F1): When ZOrder someday becomes usable enable this
339
341 double getAPIShapePrio( const css::uno::Reference< css::drawing::XShape >& xShape );
342*/
343
345 const UnoViewSharedPtr& pView );
346 }
347
348 // TODO(Q1): this could possibly be implemented with a somewhat
349 // more lightweight template, by having the actual worker receive
350 // only a function pointer, and a thin templated wrapper around
351 // that which converts member functions into that.
352
365 template< typename Functor > inline bool for_each_childNode( const css::uno::Reference< css::animations::XAnimationNode >& xNode,
366 Functor& rFunctor )
367 {
368 try
369 {
370 // get an XEnumerationAccess to the children
371 css::uno::Reference< css::container::XEnumerationAccess >
372 xEnumerationAccess( xNode,
373 css::uno::UNO_QUERY_THROW );
374 css::uno::Reference< css::container::XEnumeration >
375 xEnumeration( xEnumerationAccess->createEnumeration(),
376 css::uno::UNO_SET_THROW );
377
378 while( xEnumeration->hasMoreElements() )
379 {
380 css::uno::Reference< css::animations::XAnimationNode >
381 xChildNode( xEnumeration->nextElement(),
382 css::uno::UNO_QUERY_THROW );
383 rFunctor( xChildNode );
384 }
385 return true;
386 }
387 catch( css::uno::Exception& )
388 {
389 return false;
390 }
391 }
392}
393
394#endif // INCLUDED_SLIDESHOW_SOURCE_INC_TOOLS_HXX
395
396/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
HSL color space class.
Definition: hslcolor.hxx:33
RGB color space class.
Definition: rgbcolor.hxx:35
float x
void * p
sal_Int64 n
uno_Any a
#define SAL_INFO(area, stream)
inline ::std::size_t hash_value(css::uno::Reference< T > const &x)
Definition: tools.hxx:86
size_t uniform_size_distribution(size_t a, size_t b)
sal_uInt32 IntSRGBA
std::shared_ptr< Canvas > CanvasSharedPtr
ValueType
::basegfx::B2DRectangle getShapePosSize(const ::basegfx::B2DRectangle &rOrigBounds, const ShapeAttributeLayerSharedPtr &pAttr)
Definition: tools.cxx:591
sal_Int32 RGBAColor2UnoColor(::cppcanvas::IntSRGBA aColor)
Definition: tools.cxx:646
::basegfx::B2DRectangle getShapeUpdateArea(const ::basegfx::B2DRectangle &rUnitBounds, const ::basegfx::B2DHomMatrix &rShapeTransform, const ShapeAttributeLayerSharedPtr &pAttr)
Definition: tools.cxx:541
::std::shared_ptr< ShapeAttributeLayer > ShapeAttributeLayerSharedPtr
basegfx::B2IVector getSlideSizePixel(const basegfx::B2DVector &rSlideSize, const UnoViewSharedPtr &pView)
Definition: tools.cxx:758
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
Definition: tools.hxx:278
::basegfx::B2DHomMatrix getShapeTransformation(const ::basegfx::B2DRectangle &rShapeBounds, const ShapeAttributeLayerSharedPtr &pAttr)
Definition: tools.cxx:456
bool findNamedValue(uno::Sequence< beans::NamedValue > const &rSequence, const beans::NamedValue &rSearchKey)
Definition: tools.cxx:433
::basegfx::B2DRectangle getAPIShapeBounds(const uno::Reference< drawing::XShape > &xShape)
Definition: tools.cxx:718
std::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr
Definition: tools.hxx:63
RGBColor unoColor2RGBColor(sal_Int32)
Convert a plain UNO API 32 bit int to RGBColor.
Definition: tools.cxx:634
void fillRect(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2DRectangle &rRect, ::cppcanvas::IntSRGBA aFillColor)
Definition: tools.cxx:657
inline ::std::size_t hash_value(T const *p)
Definition: tools.hxx:66
inline ::std::size_t getRandomOrdinal(const ::std::size_t n)
Gets a random ordinal [0,n)
Definition: tools.hxx:272
void initSlideBackground(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2ISize &rSize)
Definition: tools.cxx:674
::std::shared_ptr< Shape > ShapeSharedPtr
std::shared_ptr< UnoView > UnoViewSharedPtr
bool extractValue(double &o_rValue, const uno::Any &rSourceAny, const ShapeSharedPtr &rShape, const ::basegfx::B2DVector &rSlideBounds)
extract unary double value from Any
Definition: tools.cxx:137
::basegfx::B2DHomMatrix getSpriteTransformation(const ::basegfx::B2DVector &rPixelSize, const ::basegfx::B2DVector &rOrigSize, const ShapeAttributeLayerSharedPtr &pAttr)
Definition: tools.cxx:474
basegfx::B2DRange calcRelativeShapeBounds(const basegfx::B2DVector &rPageSize, const basegfx::B2DRange &rShapeBounds)
Definition: tools.cxx:440
bool for_each_childNode(const css::uno::Reference< css::animations::XAnimationNode > &xNode, Functor &rFunctor)
Apply given functor to every animation node child.
Definition: tools.hxx:365
::std::size_t operator()(T const &val) const
Definition: tools.hxx:76
Shape