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 #pragma once
21 
22 #include <rtl/ref.hxx>
23 
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/lang/XServiceName.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/awt/XWindowListener.hpp>
29 #include <com/sun/star/awt/XTopWindow.hpp>
30 #include <com/sun/star/util/XUpdatable.hpp>
31 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
32 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
33 #include <com/sun/star/rendering/XGraphicDevice.hpp>
34 #include <com/sun/star/rendering/XBufferController.hpp>
35 
36 #include <cppuhelper/compbase.hxx>
37 #include <comphelper/uno3.hxx>
38 
39 #include <base/spritecanvasbase.hxx>
40 #include <base/spritesurface.hxx>
41 #include <base/disambiguationhelper.hxx>
42 #include <base/bufferedgraphicdevicebase.hxx>
43 
44 #include "dx_bitmapprovider.hxx"
45 #include "dx_spritecanvashelper.hxx"
46 #include "dx_surfacebitmap.hxx"
47 #include "dx_impltools.hxx"
48 #include "dx_spritedevicehelper.hxx"
49 
50 
51 namespace dxcanvas
52 {
53     typedef ::cppu::WeakComponentImplHelper< css::rendering::XSpriteCanvas,
54                                              css::rendering::XIntegerBitmap,
55                                              css::rendering::XGraphicDevice,
56                                              css::lang::XMultiServiceFactory,
57                                              css::rendering::XBufferController,
58                                              css::awt::XWindowListener,
59                                              css::util::XUpdatable,
60                                              css::beans::XPropertySet,
61                                              css::lang::XServiceName,
62                                              css::lang::XServiceInfo>    WindowGraphicDeviceBase_Base;
63     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::DisambiguationHelper< WindowGraphicDeviceBase_Base >,
64                                                    SpriteDeviceHelper,
65                                                    ::osl::MutexGuard,
66                                                    ::cppu::OWeakObject >    SpriteCanvasBase_Base;
67     /** Mixin SpriteSurface
68 
69         Have to mixin the SpriteSurface before deriving from
70         ::canvas::SpriteCanvasBase, as this template should already
71         implement some of those interface methods.
72 
73         The reason why this appears kinda convoluted is the fact that
74         we cannot specify non-IDL types as WeakComponentImplHelper
75         template args, and furthermore, don't want to derive
76         ::canvas::SpriteCanvasBase directly from
77         ::canvas::SpriteSurface (because derivees of
78         ::canvas::SpriteCanvasBase have to explicitly forward the
79         XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
80         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
81         remain a base class that provides implementation, not to
82         enforce any specific interface on its derivees.
83      */
84     class SpriteCanvasBaseSpriteSurface_Base : public SpriteCanvasBase_Base,
85                                                public ::canvas::SpriteSurface
86     {
87     };
88 
89     typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
90                                         SpriteCanvasHelper,
91                                         ::osl::MutexGuard,
92                                         ::cppu::OWeakObject >           SpriteCanvasBaseT;
93 
94     /** Product of this component's factory.
95 
96         The SpriteCanvas object combines the actual Window canvas with
97         the XGraphicDevice interface. This is because there's a
98         one-to-one relation between them, anyway, since each window
99         can have exactly one canvas and one associated
100         XGraphicDevice. And to avoid messing around with circular
101         references, this is implemented as one single object.
102      */
103     class SpriteCanvas : public SpriteCanvasBaseT, public BitmapProvider
104     {
105     public:
106         SpriteCanvas( const css::uno::Sequence<
107                             css::uno::Any >&               aArguments,
108                       const css::uno::Reference<
109                             css::uno::XComponentContext >& rxContext );
110 
111         void initialize();
112 
113         /// Dispose all internal references
114         virtual void disposeThis() override;
115 
116         // Forwarding the XComponent implementation to the
117         // cppu::ImplHelper templated base
118         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
119         //                                       |                 |                            |
120         //                                       V                 V                            V
121         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase )
122 
123         // XBufferController (partial)
124         virtual sal_Bool SAL_CALL showBuffer( sal_Bool bUpdateAll ) override;
125         virtual sal_Bool SAL_CALL switchBuffer( sal_Bool bUpdateAll ) override;
126 
127         // XSpriteCanvas (partial)
128         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) override;
129 
130         // XServiceName
131         virtual OUString SAL_CALL getServiceName(  ) override;
132 
133         // XServiceInfo
134         virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames(  ) override;
135         virtual OUString SAL_CALL getImplementationName(  ) override;
136         virtual sal_Bool SAL_CALL supportsService( const OUString& ) override;
137 
138         /// Retrieve rendermodule object for this Canvas
139         const IDXRenderModuleSharedPtr& getRenderModule() const;
140 
141         /// Get backbuffer for this canvas
142         const DXSurfaceBitmapSharedPtr& getBackBuffer() const;
143 
144         // BitmapProvider
145         virtual IBitmapSharedPtr getBitmap() const override;
146 
147      private:
148         css::uno::Sequence< css::uno::Any >                maArguments;
149         css::uno::Reference< css::uno::XComponentContext > mxComponentContext;
150     };
151 
152     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
153 }
154 
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
156