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 SDEXT_PRESENTER_CLOCK_HXX
25 #define SDEXT_PRESENTER_CLOCK_HXX
26 
27 #include "PresenterController.hxx"
28 
29 #include <cppuhelper/basemutex.hxx>
30 #include <cppuhelper/compbase4.hxx>
31 #include <com/sun/star/awt/XMouseListener.hpp>
32 #include <com/sun/star/awt/XPaintListener.hpp>
33 #include <com/sun/star/awt/XWindowListener.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/drawing/framework/XPane.hpp>
36 #include <com/sun/star/drawing/framework/XResourceId.hpp>
37 #include <com/sun/star/drawing/framework/XView.hpp>
38 #include <com/sun/star/frame/XController.hpp>
39 #include <com/sun/star/rendering/XCanvas.hpp>
40 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #include <osl/thread.hxx>
43 #include <rtl/ref.hxx>
44 #include <boost/scoped_ptr.hpp>
45 
46 namespace css = ::com::sun::star;
47 
48 namespace {
49     typedef cppu::WeakComponentImplHelper4<
50         css::awt::XPaintListener,
51         css::awt::XWindowListener,
52         css::awt::XMouseListener,
53         css::drawing::framework::XView
54         > PresenterClockInterfaceBase;
55 }
56 
57 namespace sdext { namespace presenter {
58 
59 
60 /** A clock that displays the current time.  This class is work in
61     progress.  Future extensions may include
62     other times like time since presentation started or remaining time.
63     Painting of the clock is done by the inner Painer class which includes
64     at the moment a simple analog and a simple digital clock.
65 */
66 class PresenterClock
67     : private ::cppu::BaseMutex,
68       public PresenterClockInterfaceBase
69 {
70 public:
71     static ::rtl::Reference<PresenterClock> Create (
72         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
73         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
74         const css::uno::Reference<css::frame::XController>& rxController,
75         const ::rtl::Reference<PresenterController>& rpPresenterController);
76 
77     virtual void SAL_CALL disposing (void);
78 
79     /** Callback for an external timer or thread that initiates updates when
80         the time changes (seconds or minutes).
81     */
82     void UpdateTime (void);
83 
84     /** An internally used base class for different painters.
85     */
86     class Painter;
87 
88 
89     // lang::XEventListener
90 
91     virtual void SAL_CALL
92         disposing (const css::lang::EventObject& rEventObject)
93         throw (css::uno::RuntimeException);
94 
95 
96     // XPaintListener
97 
98     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
99         throw (css::uno::RuntimeException);
100 
101 
102     // XWindowListener
103 
104     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
105         throw (css::uno::RuntimeException);
106 
107     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
108         throw (css::uno::RuntimeException);
109 
110     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
111         throw (css::uno::RuntimeException);
112 
113     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
114         throw (css::uno::RuntimeException);
115 
116 
117     // XMouseListener
118 
119     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
120         throw (css::uno::RuntimeException);
121 
122     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
123         throw (css::uno::RuntimeException);
124 
125     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
126         throw (css::uno::RuntimeException);
127 
128     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
129         throw (css::uno::RuntimeException);
130 
131 
132     // XResourceId
133 
134     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId (void)
135         throw (css::uno::RuntimeException);
136 
137     virtual sal_Bool SAL_CALL isAnchorOnly (void)
138         throw (com::sun::star::uno::RuntimeException);
139 
140 private:
141     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
142     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
143     css::uno::Reference<css::awt::XWindow> mxWindow;
144     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
145     css::uno::Reference<css::drawing::framework::XPane> mxPane;
146     ::rtl::Reference<PresenterController> mpPresenterController;
147     bool mbIsResizePending;
148     css::rendering::ViewState maViewState;
149     css::rendering::RenderState maRenderState;
150     /** A Timer is used for sampling the current time and schedule repaints
151         when the minute or second (when these are displayed) values have changed.
152     */
153     class Timer;
154     Timer* mpTimer;
155     ::boost::scoped_ptr<Painter> mpClockPainter;
156     /**
157         This is used for debugging to show one clock atop another to compare
158         the output of the painters.
159     */
160     ::boost::scoped_ptr<Painter> mpClockPainter2;
161     int mnMode;
162     sal_Int32 mnHour;
163     sal_Int32 mnMinute;
164     sal_Int32 mnSecond;
165 
166     bool mbIsShowSeconds;
167 
168     /** Use the static Create() method for creating a new PresenterClock
169         object.
170     */
171     PresenterClock (
172         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
173         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
174         const css::uno::Reference<css::frame::XController>& rxController,
175         const ::rtl::Reference<PresenterController>& rpPresenterController);
176     virtual ~PresenterClock (void);
177 
178     void LateInit (void);
179     void Resize (void);
180     void Paint (const css::awt::Rectangle& rUpdateRectangle);
181     css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon (
182         const css::awt::Rectangle& rBox);
183     void Clear (const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxUpdatePolygon);
184     void SetMode (sal_Int32 nMode);
185 
186     /** This method throws a DisposedException when the object has already been
187         disposed.
188     */
189     void ThrowIfDisposed (void)
190         throw (css::lang::DisposedException);
191 };
192 
193 } } // end of namespace ::sdext::presenter
194 
195 #endif
196