1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_SLIDESHOW_REHEARSETIMINGSACTIVITY_HXX
25 #define INCLUDED_SLIDESHOW_REHEARSETIMINGSACTIVITY_HXX
26 
27 #include "activity.hxx"
28 
29 #include <basegfx/range/b2drange.hxx>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/enable_shared_from_this.hpp>
32 #include <boost/noncopyable.hpp>
33 
34 #include <vector>
35 #include <utility>
36 
37 class Font;
38 namespace canvas{ namespace tools{ class ElapsedTime; }}
39 namespace cppcanvas{ class CustomSprite; }
40 namespace basegfx
41 {
42     class B2IVector;
43     class B2DRange;
44 }
45 
46 namespace slideshow {
47 namespace internal {
48 
49 struct SlideShowContext;
50 class EventMultiplexer;
51 class ScreenUpdater;
52 class RehearseTimingsActivity : public Activity,
53                                 public ViewEventHandler,
54                                 public boost::enable_shared_from_this<RehearseTimingsActivity>,
55                                 private ::boost::noncopyable
56 {
57 public:
58     /** Creates the activity.
59      */
60     static boost::shared_ptr<RehearseTimingsActivity> create(
61         const SlideShowContext& rContext );
62 
63     virtual ~RehearseTimingsActivity();
64 
65     /** Starts and shows the timer; adds to activity queue.
66      */
67     void start();
68 
69     /** Stops and hides the timer.
70         @return elapsed time
71      */
72     double stop();
73 
74     /** Determines whether the timer button has been clicked.
75      */
76     bool hasBeenClicked() const;
77 
78     // ViewEventHandler interface
79     virtual void viewAdded( const UnoViewSharedPtr& rView );
80     virtual void viewRemoved( const UnoViewSharedPtr& rView );
81     virtual void viewChanged( const UnoViewSharedPtr& rView );
82     virtual void viewsChanged();
83 
84     // Disposable:
85     virtual void dispose();
86     // Activity:
87     virtual double calcTimeLag() const;
88     virtual bool perform();
89     virtual bool isActive() const;
90     virtual void dequeued();
91     virtual void end();
92 
93 private:
94     class WakeupEvent;
95 
96     explicit RehearseTimingsActivity( const SlideShowContext& rContext );
97 
98     void paint( ::cppcanvas::CanvasSharedPtr const & canvas ) const;
99     void paintAllSprites() const;
100 
101     class MouseHandler;
102     friend class MouseHandler;
103 
104     typedef ::std::vector<
105         ::std::pair<UnoViewSharedPtr,
106                     boost::shared_ptr<cppcanvas::CustomSprite> > > ViewsVecT;
107 
108     template <typename func_type>
for_each_sprite(func_type const & func) const109     void for_each_sprite( func_type const & func ) const
110     {
111         ViewsVecT::const_iterator iPos( maViews.begin() );
112         const ViewsVecT::const_iterator iEnd( maViews.end() );
113         for ( ; iPos != iEnd; ++iPos )
114             func( iPos->second );
115     }
116 
117     ::basegfx::B2DRange calcSpriteRectangle(
118         UnoViewSharedPtr const & rView ) const;
119 
120     EventQueue&                     mrEventQueue;
121     ScreenUpdater&                  mrScreenUpdater;
122     EventMultiplexer&               mrEventMultiplexer;
123     ActivitiesQueue&                mrActivitiesQueue;
124     canvas::tools::ElapsedTime      maElapsedTime;
125 
126     ViewsVecT                       maViews;
127 
128     /// screen rect of sprite (in view coordinates!)
129     ::basegfx::B2DRange             maSpriteRectangle;
130 
131     Font                            maFont;
132     boost::shared_ptr<WakeupEvent>  mpWakeUpEvent;
133     boost::shared_ptr<MouseHandler> mpMouseHandler;
134     ::basegfx::B2IVector            maSpriteSizePixel;
135     sal_Int32                       mnYOffset;
136     bool                            mbActive;
137     bool                            mbDrawPressed;
138 };
139 
140 } // namespace internal
141 } // namespace presentation
142 
143 #endif /* INCLUDED_SLIDESHOW_REHEARSETIMINGSACTIVITY_HXX */
144