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 :
21 : #include <canvas/debug.hxx>
22 : #include <canvas/verbosetrace.hxx>
23 :
24 : #include "delayevent.hxx"
25 : #include "eventqueue.hxx"
26 : #include "usereventqueue.hxx"
27 : #include "sequentialtimecontainer.hxx"
28 : #include "tools.hxx"
29 :
30 : #include <boost/bind.hpp>
31 : #include <algorithm>
32 :
33 : namespace slideshow {
34 : namespace internal {
35 :
36 0 : void SequentialTimeContainer::activate_st()
37 : {
38 : // resolve first possible child, ignore
39 0 : for ( ; mnFinishedChildren < maChildren.size(); ++mnFinishedChildren ) {
40 0 : if (resolveChild( maChildren[mnFinishedChildren] ))
41 0 : break;
42 : else {
43 : // node still UNRESOLVED, no need to deactivate or end...
44 : OSL_FAIL( "### resolving child failed!" );
45 : }
46 : }
47 :
48 0 : if (isDurationIndefinite() &&
49 0 : (maChildren.empty() || mnFinishedChildren >= maChildren.size()))
50 : {
51 : // deactivate ASAP:
52 : scheduleDeactivationEvent(
53 0 : makeEvent(
54 : boost::bind< void >( boost::mem_fn( &AnimationNode::deactivate ), getSelf() ),
55 0 : "SequentialTimeContainer::deactivate") );
56 : }
57 : else // use default
58 0 : scheduleDeactivationEvent();
59 0 : }
60 :
61 0 : void SequentialTimeContainer::dispose()
62 : {
63 0 : BaseContainerNode::dispose();
64 0 : if (mpCurrentSkipEvent) {
65 0 : mpCurrentSkipEvent->dispose();
66 0 : mpCurrentSkipEvent.reset();
67 : }
68 0 : if (mpCurrentRewindEvent) {
69 0 : mpCurrentRewindEvent->dispose();
70 0 : mpCurrentRewindEvent.reset();
71 : }
72 0 : }
73 :
74 0 : void SequentialTimeContainer::skipEffect(
75 : AnimationNodeSharedPtr const& pChildNode )
76 : {
77 0 : if (isChildNode(pChildNode)) {
78 : // empty all events ignoring timings => until next effect
79 0 : getContext().mrEventQueue.forceEmpty();
80 0 : getContext().mrEventQueue.addEvent(
81 : makeEvent(
82 : boost::bind<void>( boost::mem_fn( &AnimationNode::deactivate ), pChildNode ),
83 0 : "SequentialTimeContainer::deactivate, skipEffect with delay") );
84 : }
85 : else
86 : OSL_FAIL( "unknown notifier!" );
87 0 : }
88 :
89 0 : bool SequentialTimeContainer::resolveChild(
90 : AnimationNodeSharedPtr const& pChildNode )
91 : {
92 0 : bool const bResolved = pChildNode->resolve();
93 0 : if (bResolved && isMainSequenceRootNode()) {
94 : // discharge events:
95 0 : if (mpCurrentSkipEvent)
96 0 : mpCurrentSkipEvent->dispose();
97 0 : if (mpCurrentRewindEvent)
98 0 : mpCurrentRewindEvent->dispose();
99 :
100 : // event that will deactivate the resolved/running child:
101 0 : mpCurrentSkipEvent = makeEvent(
102 : boost::bind( &SequentialTimeContainer::skipEffect,
103 : boost::dynamic_pointer_cast<SequentialTimeContainer>( getSelf() ),
104 : pChildNode ),
105 0 : "SequentialTimeContainer::skipEffect, resolveChild");
106 :
107 : // deactivate child node when skip event occurs:
108 0 : getContext().mrUserEventQueue.registerSkipEffectEvent(
109 : mpCurrentSkipEvent,
110 0 : mnFinishedChildren+1<maChildren.size());
111 : }
112 0 : return bResolved;
113 : }
114 :
115 0 : void SequentialTimeContainer::notifyDeactivating(
116 : AnimationNodeSharedPtr const& rNotifier )
117 : {
118 0 : if (notifyDeactivatedChild( rNotifier ))
119 0 : return;
120 :
121 : OSL_ASSERT( mnFinishedChildren < maChildren.size() );
122 0 : AnimationNodeSharedPtr const& pNextChild = maChildren[mnFinishedChildren];
123 : OSL_ASSERT( pNextChild->getState() == UNRESOLVED );
124 :
125 0 : if (! resolveChild( pNextChild )) {
126 : // could not resolve child - since we risk to
127 : // stall the chain of events here, play it safe
128 : // and deactivate this node (only if we have
129 : // indefinite duration - otherwise, we'll get a
130 : // deactivation event, anyways).
131 0 : deactivate();
132 : }
133 : }
134 :
135 : } // namespace internal
136 3 : } // namespace slideshow
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|