Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / inc / basenode.hxx
blob9798aa11a171cc5726d4506daf87abe77e69791d
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 .
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_BASENODE_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_INC_BASENODE_HXX
22 #include <tools/diagnose_ex.h>
23 #include <osl/diagnose.hxx>
25 #include "event.hxx"
26 #include "animationnode.hxx"
27 #include "slideshowcontext.hxx"
28 #include "shapesubset.hxx"
30 #include <vector>
32 namespace slideshow {
33 namespace internal {
35 /** Context for every node.
37 Besides the global AnimationNodeFactory::Context data,
38 this struct also contains the current DocTree subset
39 for this node. If start and end index of the
40 DocTreeNode are equal, the node should use the
41 complete shape.
43 struct NodeContext
45 NodeContext( const SlideShowContext& rContext,
46 const ::basegfx::B2DVector& rSlideSize )
47 : maContext( rContext ),
48 maSlideSize( rSlideSize ),
49 mpMasterShapeSubset(),
50 mnStartDelay(0.0),
51 mbIsIndependentSubset( true )
54 /// Context as passed to createAnimationNode()
55 SlideShowContext maContext;
57 /// Size in user coordinate space of the corresponding slide
58 ::basegfx::B2DVector maSlideSize;
60 /// Shape to be used (provided by parent, e.g. for iterations)
61 ShapeSubsetSharedPtr mpMasterShapeSubset;
63 /// Additional delay to node begin (to offset iterate effects)
64 double mnStartDelay;
66 /// When true, subset must be created during slide initialization
67 bool mbIsIndependentSubset;
70 class BaseContainerNode;
72 /** This interface extends AnimationNode with some
73 file-private accessor methods.
75 class BaseNode : public AnimationNode,
76 public ::osl::DebugBase<BaseNode>
78 public:
79 BaseNode( css::uno::Reference<css::animations::XAnimationNode> const& xNode,
80 ::std::shared_ptr<BaseContainerNode> const& pParent,
81 NodeContext const& rContext );
82 BaseNode(const BaseNode&) = delete;
83 BaseNode& operator=(const BaseNode&) = delete;
85 /** Provide the node with a shared_ptr to itself.
87 Since implementation has to create objects which need
88 a shared_ptr to this node, and a pointee cannot
89 retrieve a shared_ptr to itself internally, have to
90 set that from the outside.
92 void setSelf( const ::std::shared_ptr< BaseNode >& rSelf );
95 #if defined(DBG_UTIL)
96 virtual void showState() const;
97 virtual const char* getDescription() const;
98 #endif
100 const ::std::shared_ptr< BaseContainerNode >& getParentNode() const
101 { return mpParent; }
103 // Disposable:
104 virtual void dispose() override;
106 // AnimationNode:
107 virtual bool init() override;
108 virtual bool resolve() override;
109 virtual void activate() override;
110 virtual void deactivate() override;
111 virtual void end() override;
112 virtual css::uno::Reference<css::animations::XAnimationNode> getXAnimationNode() const override;
113 virtual NodeState getState() const override;
114 virtual bool registerDeactivatingListener(
115 const AnimationNodeSharedPtr& rNotifee ) override;
116 // nop:
117 virtual void notifyDeactivating( const AnimationNodeSharedPtr& rNotifier ) override;
119 bool isMainSequenceRootNode() const { return mbIsMainSequenceRootNode; }
121 protected:
122 void scheduleDeactivationEvent( EventSharedPtr const& pEvent =
123 EventSharedPtr() );
125 SlideShowContext const& getContext() const { return maContext; }
126 ::std::shared_ptr<BaseNode> const& getSelf() const { return mpSelf; }
128 bool checkValidNode() const {
129 ENSURE_OR_THROW( mpSelf, "no self ptr set!" );
130 bool const bRet = (meCurrState != INVALID);
131 OSL_ENSURE( bRet, "### INVALID node!" );
132 return bRet;
135 private:
136 // all state affecting methods have "_st" counterparts being called at
137 // derived classes when in state transition: no-ops here at BaseNode...
138 virtual bool init_st();
139 virtual bool resolve_st();
140 virtual void activate_st();
141 virtual void deactivate_st( NodeState eDestState );
143 private:
144 /// notifies
145 /// - all registered deactivation listeners
146 /// - single animation end (every node)
147 /// - slide animations (if main sequence root node)
148 void notifyEndListeners() const;
150 /// Get the node's restart mode
151 sal_Int16 getRestartMode();
153 /** Get the default restart mode
155 If this node's default mode is
156 AnimationRestart::DEFAULT, this method recursively
157 calls the parent node.
159 sal_Int16 getRestartDefaultMode() const;
161 /// Get the node's fill mode
162 sal_Int16 getFillMode();
164 /** Get the default fill mode.
166 If this node's default mode is AnimationFill::DEFAULT,
167 this method recursively calls the parent node.
169 sal_Int16 getFillDefaultMode() const;
171 bool isTransition( NodeState eFromState, NodeState eToState,
172 bool debugAssert = true ) const {
173 bool const bRet =((mpStateTransitionTable[eFromState] & eToState) != 0);
174 OSL_ENSURE( !debugAssert || bRet, "### state unreachable!" );
175 return bRet;
178 bool inStateOrTransition( int mask ) const {
179 return ((meCurrState & mask) != 0 ||
180 (meCurrentStateTransition & mask) != 0);
183 class StateTransition;
184 friend class StateTransition;
186 private:
187 SlideShowContext maContext;
189 typedef ::std::vector< AnimationNodeSharedPtr > ListenerVector;
191 ListenerVector maDeactivatingListeners;
192 css::uno::Reference< css::animations::XAnimationNode > mxAnimationNode;
193 ::std::shared_ptr< BaseContainerNode > mpParent;
194 ::std::shared_ptr< BaseNode > mpSelf;
195 const int* mpStateTransitionTable;
196 const double mnStartDelay;
197 NodeState meCurrState;
198 int meCurrentStateTransition;
199 EventSharedPtr mpCurrentEvent;
200 const bool mbIsMainSequenceRootNode;
203 typedef ::std::shared_ptr< BaseNode > BaseNodeSharedPtr;
205 } // namespace internal
206 } // namespace slideshow
208 #endif
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */