tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / include / animations / animationnodehelper.hxx
blob8c79342c789b5f1ed5c6ac88d5a194f4cdc2c3c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <o3tl/any.hxx>
23 #include <rtl/strbuf.hxx>
24 #include <sal/log.hxx>
25 #include <tools/helpers.hxx>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/animations/XAnimate.hpp>
30 #include <com/sun/star/animations/XAnimationNode.hpp>
31 #include <com/sun/star/container/XEnumerationAccess.hpp>
32 #include <com/sun/star/container/XEnumeration.hpp>
33 #include <com/sun/star/presentation/ParagraphTarget.hpp>
35 #include <vector>
37 /* Declaration and definition of AnimationNode helper */
39 namespace anim
41 // TODO(Q1): this could possibly be implemented with a somewhat
42 // more lightweight template, by having the actual worker receive
43 // only a function pointer, and a thin templated wrapper around
44 // that which converts member functions into that.
46 /** pushes the given node to the given vector and recursively calls itself for each child node.
48 inline void create_deep_vector( const css::uno::Reference< css::animations::XAnimationNode >& xNode,
49 std::vector< css::uno::Reference< css::animations::XAnimationNode > >& rVector )
51 rVector.push_back( xNode );
53 try
55 // get an XEnumerationAccess to the children
56 css::uno::Reference< css::container::XEnumerationAccess >
57 xEnumerationAccess( xNode, css::uno::UNO_QUERY );
59 if( xEnumerationAccess.is() )
61 css::uno::Reference< css::container::XEnumeration >
62 xEnumeration = xEnumerationAccess->createEnumeration();
64 if( xEnumeration.is() )
66 while( xEnumeration->hasMoreElements() )
68 css::uno::Reference< css::animations::XAnimationNode >
69 xChildNode( xEnumeration->nextElement(),
70 css::uno::UNO_QUERY_THROW );
72 create_deep_vector( xChildNode, rVector );
77 catch( css::uno::Exception& )
82 inline bool getVisibilityProperty(
83 const css::uno::Reference< css::animations::XAnimate >& xAnimateNode, bool& bReturn)
85 if( xAnimateNode->getAttributeName().equalsIgnoreAsciiCase("visibility") )
87 bool bVisible( false );
88 css::uno::Any aAny( xAnimateNode->getTo() );
90 // try to extract bool value
91 if( !(aAny >>= bVisible) )
93 // try to extract string
94 OUString aString;
95 if( aAny >>= aString )
97 // we also take the strings "true" and "false",
98 // as well as "on" and "off" here
99 if( aString.equalsIgnoreAsciiCase("true") ||
100 aString.equalsIgnoreAsciiCase("on") )
102 bVisible = true;
104 if( aString.equalsIgnoreAsciiCase("false") ||
105 aString.equalsIgnoreAsciiCase("off") )
107 bVisible = false;
111 bReturn = bVisible;
112 return true;
115 return false;
118 inline css::uno::Reference<css::uno::XInterface> getParagraphTarget(
119 const css::presentation::ParagraphTarget& pTarget)
123 css::uno::Reference<css::container::XEnumerationAccess> xParaEnumAccess(
124 pTarget.Shape, css::uno::UNO_QUERY_THROW);
126 css::uno::Reference<css::container::XEnumeration> xEnumeration(
127 xParaEnumAccess->createEnumeration(),
128 css::uno::UNO_SET_THROW);
129 sal_Int32 nParagraph = pTarget.Paragraph;
131 while (xEnumeration->hasMoreElements())
133 css::uno::Reference<css::uno::XInterface> xRef(
134 xEnumeration->nextElement(), css::uno::UNO_QUERY);
135 if (nParagraph-- == 0)
136 return xRef;
139 catch (const css::uno::RuntimeException&)
141 SAL_WARN("animations", "getParagraphTarget");
144 css::uno::Reference<css::uno::XInterface> xRef;
145 return xRef;
148 inline void convertTarget(OStringBuffer& sTmp, const css::uno::Any& rTarget)
150 if (!rTarget.hasValue())
151 return;
153 css::uno::Reference<css::uno::XInterface> xRef;
154 if (!(rTarget >>= xRef))
156 if (auto pt = o3tl::tryAccess<css::presentation::ParagraphTarget>(rTarget))
158 xRef = getParagraphTarget(*pt);
162 SAL_WARN_IF(!xRef.is(), "animations", "convertTarget(), invalid target type!");
163 if (xRef.is())
165 const std::string aIdentifier(GetInterfaceHash(xRef));
166 if (!aIdentifier.empty())
167 sTmp.append(aIdentifier);
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */