xref: /trunk/main/sdext/source/presenter/PresenterClock.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
94 
95     // XPaintListener
96 
97     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent);
98 
99 
100     // XWindowListener
101 
102     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent);
103 
104     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent);
105 
106     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent);
107 
108     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent);
109 
110 
111     // XMouseListener
112 
113     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent);
114 
115     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent);
116 
117     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent);
118 
119     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent);
120 
121 
122     // XResourceId
123 
124     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId (void);
125 
126     virtual sal_Bool SAL_CALL isAnchorOnly (void);
127 
128 private:
129     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
130     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
131     css::uno::Reference<css::awt::XWindow> mxWindow;
132     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
133     css::uno::Reference<css::drawing::framework::XPane> mxPane;
134     ::rtl::Reference<PresenterController> mpPresenterController;
135     bool mbIsResizePending;
136     css::rendering::ViewState maViewState;
137     css::rendering::RenderState maRenderState;
138     /** A Timer is used for sampling the current time and schedule repaints
139         when the minute or second (when these are displayed) values have changed.
140     */
141     class Timer;
142     Timer* mpTimer;
143     ::boost::scoped_ptr<Painter> mpClockPainter;
144     /**
145         This is used for debugging to show one clock atop another to compare
146         the output of the painters.
147     */
148     ::boost::scoped_ptr<Painter> mpClockPainter2;
149     int mnMode;
150     sal_Int32 mnHour;
151     sal_Int32 mnMinute;
152     sal_Int32 mnSecond;
153 
154     bool mbIsShowSeconds;
155 
156     /** Use the static Create() method for creating a new PresenterClock
157         object.
158     */
159     PresenterClock (
160         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
161         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
162         const css::uno::Reference<css::frame::XController>& rxController,
163         const ::rtl::Reference<PresenterController>& rpPresenterController);
164     virtual ~PresenterClock (void);
165 
166     void LateInit (void);
167     void Resize (void);
168     void Paint (const css::awt::Rectangle& rUpdateRectangle);
169     css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon (
170         const css::awt::Rectangle& rBox);
171     void Clear (const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxUpdatePolygon);
172     void SetMode (sal_Int32 nMode);
173 
174     /** This method throws a DisposedException when the object has already been
175         disposed.
176     */
177     void ThrowIfDisposed (void);
178 };
179 
180 } } // end of namespace ::sdext::presenter
181 
182 #endif
183