1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SDEXT_PRESENTER_CLOCK_HXX
29 #define SDEXT_PRESENTER_CLOCK_HXX
30 
31 #include "PresenterController.hxx"
32 
33 #include <cppuhelper/basemutex.hxx>
34 #include <cppuhelper/compbase4.hxx>
35 #include <com/sun/star/awt/XMouseListener.hpp>
36 #include <com/sun/star/awt/XPaintListener.hpp>
37 #include <com/sun/star/awt/XWindowListener.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/drawing/framework/XPane.hpp>
40 #include <com/sun/star/drawing/framework/XResourceId.hpp>
41 #include <com/sun/star/drawing/framework/XView.hpp>
42 #include <com/sun/star/frame/XController.hpp>
43 #include <com/sun/star/rendering/XCanvas.hpp>
44 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
45 #include <com/sun/star/uno/XComponentContext.hpp>
46 #include <osl/thread.hxx>
47 #include <rtl/ref.hxx>
48 #include <boost/scoped_ptr.hpp>
49 
50 namespace css = ::com::sun::star;
51 
52 namespace {
53     typedef cppu::WeakComponentImplHelper4<
54         css::awt::XPaintListener,
55         css::awt::XWindowListener,
56         css::awt::XMouseListener,
57         css::drawing::framework::XView
58         > PresenterClockInterfaceBase;
59 }
60 
61 namespace sdext { namespace presenter {
62 
63 
64 /** A clock that displays the current time.  This class is work in
65     progress.  Future extensions may include
66     other times like time since presentation started or remaining time.
67     Painting of the clock is done by the inner Painer class which includes
68     at the moment a simple analog and a simple digital clock.
69 */
70 class PresenterClock
71     : private ::cppu::BaseMutex,
72       public PresenterClockInterfaceBase
73 {
74 public:
75     static ::rtl::Reference<PresenterClock> Create (
76         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
77         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
78         const css::uno::Reference<css::frame::XController>& rxController,
79         const ::rtl::Reference<PresenterController>& rpPresenterController);
80 
81     virtual void SAL_CALL disposing (void);
82 
83     /** Callback for an external timer or thread that initiates updates when
84         the time changes (seconds or minutes).
85     */
86     void UpdateTime (void);
87 
88     /** An internally used base class for different painters.
89     */
90     class Painter;
91 
92 
93     // lang::XEventListener
94 
95     virtual void SAL_CALL
96         disposing (const css::lang::EventObject& rEventObject)
97         throw (css::uno::RuntimeException);
98 
99 
100     // XPaintListener
101 
102     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
103         throw (css::uno::RuntimeException);
104 
105 
106     // XWindowListener
107 
108     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
109         throw (css::uno::RuntimeException);
110 
111     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
112         throw (css::uno::RuntimeException);
113 
114     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
115         throw (css::uno::RuntimeException);
116 
117     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
118         throw (css::uno::RuntimeException);
119 
120 
121     // XMouseListener
122 
123     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
124         throw (css::uno::RuntimeException);
125 
126     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
127         throw (css::uno::RuntimeException);
128 
129     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
130         throw (css::uno::RuntimeException);
131 
132     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
133         throw (css::uno::RuntimeException);
134 
135 
136     // XResourceId
137 
138     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId (void)
139         throw (css::uno::RuntimeException);
140 
141     virtual sal_Bool SAL_CALL isAnchorOnly (void)
142         throw (com::sun::star::uno::RuntimeException);
143 
144 private:
145     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
146     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
147     css::uno::Reference<css::awt::XWindow> mxWindow;
148     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
149     css::uno::Reference<css::drawing::framework::XPane> mxPane;
150     ::rtl::Reference<PresenterController> mpPresenterController;
151     bool mbIsResizePending;
152     css::rendering::ViewState maViewState;
153     css::rendering::RenderState maRenderState;
154     /** A Timer is used for sampling the current time and schedule repaints
155         when the minute or second (when these are displayed) values have changed.
156     */
157     class Timer;
158     Timer* mpTimer;
159     ::boost::scoped_ptr<Painter> mpClockPainter;
160     /**
161         This is used for debugging to show one clock atop another to compare
162         the output of the painters.
163     */
164     ::boost::scoped_ptr<Painter> mpClockPainter2;
165     int mnMode;
166     sal_Int32 mnHour;
167     sal_Int32 mnMinute;
168     sal_Int32 mnSecond;
169 
170     bool mbIsShowSeconds;
171 
172     /** Use the static Create() method for creating a new PresenterClock
173         object.
174     */
175     PresenterClock (
176         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
177         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
178         const css::uno::Reference<css::frame::XController>& rxController,
179         const ::rtl::Reference<PresenterController>& rpPresenterController);
180     virtual ~PresenterClock (void);
181 
182     void LateInit (void);
183     void Resize (void);
184     void Paint (const css::awt::Rectangle& rUpdateRectangle);
185     css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon (
186         const css::awt::Rectangle& rBox);
187     void Clear (const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxUpdatePolygon);
188     void SetMode (sal_Int32 nMode);
189 
190     /** This method throws a DisposedException when the object has already been
191         disposed.
192     */
193     void ThrowIfDisposed (void)
194         throw (css::lang::DisposedException);
195 };
196 
197 } } // end of namespace ::sdext::presenter
198 
199 #endif
200