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_PRESENTER_BUTTON_HXX
25 #define SDEXT_PRESENTER_PRESENTER_BUTTON_HXX
26 
27 #include "PresenterBitmapContainer.hxx"
28 #include "PresenterTheme.hxx"
29 #include <com/sun/star/awt/Rectangle.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/awt/XWindowListener.hpp>
32 #include <com/sun/star/awt/XPaintListener.hpp>
33 #include <com/sun/star/awt/XMouseListener.hpp>
34 #include <com/sun/star/awt/XMouseMotionListener.hpp>
35 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <com/sun/star/rendering/XBitmap.hpp>
37 #include <cppuhelper/basemutex.hxx>
38 #include <cppuhelper/compbase4.hxx>
39 #include <boost/noncopyable.hpp>
40 #include <rtl/ref.hxx>
41 
42 namespace css = ::com::sun::star;
43 
44 namespace sdext { namespace presenter {
45 
46 class PresenterController;
47 
48 namespace {
49     typedef ::cppu::WeakComponentImplHelper4 <
50         css::awt::XWindowListener,
51         css::awt::XPaintListener,
52         css::awt::XMouseListener,
53         css::awt::XMouseMotionListener
54     > PresenterButtonInterfaceBase;
55 }
56 
57 /** Button for the presenter screen.  It displays a text surrounded by a
58     frame.
59 */
60 class PresenterButton
61     : private ::boost::noncopyable,
62       private ::cppu::BaseMutex,
63       public PresenterButtonInterfaceBase
64 {
65 public:
66     static ::rtl::Reference<PresenterButton> Create (
67         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
68         const ::rtl::Reference<PresenterController>& rpPresenterController,
69         const ::boost::shared_ptr<PresenterTheme>& rpTheme,
70         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
71         const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas,
72         const ::rtl::OUString& rsConfigurationName);
73     ~PresenterButton (void);
74 
75     virtual void SAL_CALL disposing (void);
76 
77     void SetCenter (const css::geometry::RealPoint2D& rLocation);
78     void SetCanvas (
79         const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas,
80         const css::uno::Reference<css::awt::XWindow>& rxParentWindow);
81     css::geometry::IntegerSize2D GetSize (void);
82 
83     // XWindowListener
84 
85     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
86         throw (css::uno::RuntimeException);
87 
88     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
89         throw (css::uno::RuntimeException);
90 
91     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
92         throw (css::uno::RuntimeException);
93 
94     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
95         throw (css::uno::RuntimeException);
96 
97 
98     // XPaintListener
99 
100     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
101         throw (css::uno::RuntimeException);
102 
103 
104     // XMouseListener
105 
106     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
107         throw(css::uno::RuntimeException);
108 
109     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
110         throw(css::uno::RuntimeException);
111 
112     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
113         throw(css::uno::RuntimeException);
114 
115     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
116         throw(css::uno::RuntimeException);
117 
118 
119     // XMouseMotionListener
120 
121     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent)
122         throw (css::uno::RuntimeException);
123 
124     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent)
125         throw (css::uno::RuntimeException);
126 
127 
128     // lang::XEventListener
129     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
130         throw (css::uno::RuntimeException);
131 
132 private:
133     ::rtl::Reference<PresenterController> mpPresenterController;
134     ::boost::shared_ptr<PresenterTheme> mpTheme;
135     css::uno::Reference<css::awt::XWindow> mxWindow;
136     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
137     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
138     const ::rtl::OUString msText;
139     const PresenterTheme::SharedFontDescriptor mpFont;
140     const PresenterTheme::SharedFontDescriptor mpMouseOverFont;
141     const ::rtl::OUString msAction;
142     css::geometry::RealPoint2D maCenter;
143     css::geometry::IntegerSize2D maButtonSize;
144     PresenterBitmapDescriptor::Mode meState;
145     css::uno::Reference<css::rendering::XBitmap> mxNormalBitmap;
146     css::uno::Reference<css::rendering::XBitmap> mxMouseOverBitmap;
147 
148     PresenterButton (
149         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
150         const ::rtl::Reference<PresenterController>& rpPresenterController,
151         const ::boost::shared_ptr<PresenterTheme>& rpTheme,
152         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
153         const PresenterTheme::SharedFontDescriptor& rFont,
154         const PresenterTheme::SharedFontDescriptor& rMouseOverFont,
155         const ::rtl::OUString& rxText,
156         const ::rtl::OUString& rxAction);
157     void RenderButton (
158         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
159         const css::geometry::IntegerSize2D& rSize,
160         const PresenterTheme::SharedFontDescriptor& rFont,
161         const PresenterBitmapDescriptor::Mode eMode,
162         const SharedBitmapDescriptor& rpLeft,
163         const SharedBitmapDescriptor& rpCenter,
164         const SharedBitmapDescriptor& rpRight);
165     css::geometry::IntegerSize2D CalculateButtonSize (void);
166     void Invalidate (void);
167     css::uno::Reference<css::rendering::XBitmap> GetBitmap (
168         const SharedBitmapDescriptor& mpIcon,
169         const PresenterBitmapDescriptor::Mode eMode);
170     void SetupButtonBitmaps (void);
171     static css::uno::Reference<css::beans::XPropertySet> GetConfigurationProperties (
172         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
173         const ::rtl::OUString& rsConfgurationName);
174 
175     void ThrowIfDisposed (void) const
176         throw (::com::sun::star::lang::DisposedException);
177 };
178 
179 } }
180 
181 #endif
182