1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERBUTTON_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERBUTTON_HXX
22 
23 #include "PresenterBitmapContainer.hxx"
24 #include "PresenterTheme.hxx"
25 #include <com/sun/star/awt/XWindow.hpp>
26 #include <com/sun/star/awt/XPaintListener.hpp>
27 #include <com/sun/star/awt/XMouseListener.hpp>
28 #include <com/sun/star/rendering/XCanvas.hpp>
29 #include <com/sun/star/rendering/XBitmap.hpp>
30 #include <cppuhelper/basemutex.hxx>
31 #include <cppuhelper/compbase.hxx>
32 #include <rtl/ref.hxx>
33 
34 namespace sdext::presenter {
35 
36 class PresenterController;
37 
38 typedef ::cppu::WeakComponentImplHelper <
39     css::awt::XPaintListener,
40     css::awt::XMouseListener
41 > PresenterButtonInterfaceBase;
42 
43 /** Button for the presenter screen.  It displays a text surrounded by a
44     frame.
45 */
46 class PresenterButton
47     : private ::cppu::BaseMutex,
48       public PresenterButtonInterfaceBase
49 {
50 public:
51     static ::rtl::Reference<PresenterButton> Create (
52         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
53         const ::rtl::Reference<PresenterController>& rpPresenterController,
54         const std::shared_ptr<PresenterTheme>& rpTheme,
55         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
56         const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas,
57         const OUString& rsConfigurationName);
58     virtual ~PresenterButton() override;
59     PresenterButton(const PresenterButton&) = delete;
60     PresenterButton& operator=(const PresenterButton&) = delete;
61 
62     virtual void SAL_CALL disposing() override;
63 
64     void SetCenter (const css::geometry::RealPoint2D& rLocation);
65     void SetCanvas (
66         const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas,
67         const css::uno::Reference<css::awt::XWindow>& rxParentWindow);
68     css::geometry::IntegerSize2D const & GetSize();
69 
70     // XPaintListener
71 
72     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent) override;
73 
74     // XMouseListener
75 
76     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent) override;
77 
78     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent) override;
79 
80     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent) override;
81 
82     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent) override;
83 
84     // lang::XEventListener
85     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) override;
86 
87 private:
88     ::rtl::Reference<PresenterController> mpPresenterController;
89     std::shared_ptr<PresenterTheme> mpTheme;
90     css::uno::Reference<css::awt::XWindow> mxWindow;
91     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
92     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
93     const OUString msText;
94     const PresenterTheme::SharedFontDescriptor mpFont;
95     const PresenterTheme::SharedFontDescriptor mpMouseOverFont;
96     const OUString msAction;
97     css::geometry::RealPoint2D maCenter;
98     css::geometry::IntegerSize2D maButtonSize;
99     PresenterBitmapDescriptor::Mode meState;
100     css::uno::Reference<css::rendering::XBitmap> mxNormalBitmap;
101     css::uno::Reference<css::rendering::XBitmap> mxMouseOverBitmap;
102 
103     PresenterButton (
104         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
105         const ::rtl::Reference<PresenterController>& rpPresenterController,
106         const std::shared_ptr<PresenterTheme>& rpTheme,
107         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
108         const PresenterTheme::SharedFontDescriptor& rFont,
109         const PresenterTheme::SharedFontDescriptor& rMouseOverFont,
110         const OUString& rxText,
111         const OUString& rxAction);
112     void RenderButton (
113         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
114         const css::geometry::IntegerSize2D& rSize,
115         const PresenterTheme::SharedFontDescriptor& rFont,
116         const PresenterBitmapDescriptor::Mode eMode,
117         const SharedBitmapDescriptor& rpLeft,
118         const SharedBitmapDescriptor& rpCenter,
119         const SharedBitmapDescriptor& rpRight);
120     css::geometry::IntegerSize2D CalculateButtonSize();
121     void Invalidate();
122     static css::uno::Reference<css::rendering::XBitmap> GetBitmap (
123         const SharedBitmapDescriptor& mpIcon,
124         const PresenterBitmapDescriptor::Mode eMode);
125     void SetupButtonBitmaps();
126     static css::uno::Reference<css::beans::XPropertySet> GetConfigurationProperties (
127         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
128         const OUString& rsConfigurationName);
129 
130     /// @throws css::lang::DisposedException
131     void ThrowIfDisposed() const;
132 };
133 
134 }
135 
136 #endif
137 
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
139