Line data Source code
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_CANVAS_SOURCE_CAIRO_CAIRO_CANVASCUSTOMSPRITE_HXX
21 : #define INCLUDED_CANVAS_SOURCE_CAIRO_CAIRO_CANVASCUSTOMSPRITE_HXX
22 :
23 : #include <cppuhelper/compbase4.hxx>
24 : #include <comphelper/uno3.hxx>
25 :
26 : #include <com/sun/star/lang/XServiceInfo.hpp>
27 : #include <com/sun/star/lang/XComponent.hpp>
28 : #include <com/sun/star/rendering/XCustomSprite.hpp>
29 : #include <com/sun/star/rendering/XIntegerBitmap.hpp>
30 : #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
31 :
32 : #include <basegfx/point/b2dpoint.hxx>
33 : #include <basegfx/vector/b2isize.hxx>
34 : #include <basegfx/matrix/b2dhommatrix.hxx>
35 :
36 : #include <canvas/base/basemutexhelper.hxx>
37 : #include <canvas/base/canvascustomspritebase.hxx>
38 :
39 : #include <vcl/cairo.hxx>
40 :
41 : #include "cairo_sprite.hxx"
42 : #include "cairo_canvashelper.hxx"
43 : #include "cairo_repainttarget.hxx"
44 : #include "cairo_spritehelper.hxx"
45 : #include "cairo_spritecanvas.hxx"
46 :
47 :
48 : namespace cairocanvas
49 : {
50 : typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XCustomSprite,
51 : ::com::sun::star::rendering::XBitmapCanvas,
52 : ::com::sun::star::rendering::XIntegerBitmap,
53 : ::com::sun::star::lang::XServiceInfo > CanvasCustomSpriteBase_Base;
54 : /** Mixin Sprite
55 :
56 : Have to mixin the Sprite interface before deriving from
57 : ::canvas::CanvasCustomSpriteBase, as this template should
58 : already implement some of those interface methods.
59 :
60 : The reason why this appears kinda convoluted is the fact that
61 : we cannot specify non-IDL types as WeakComponentImplHelperN
62 : template args, and furthermore, don't want to derive
63 : ::canvas::CanvasCustomSpriteBase directly from
64 : ::canvas::Sprite (because derivees of
65 : ::canvas::CanvasCustomSpriteBase have to explicitly forward
66 : the XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
67 : anyway). Basically, ::canvas::CanvasCustomSpriteBase should
68 : remain a base class that provides implementation, not to
69 : enforce any specific interface on its derivees.
70 : */
71 0 : class CanvasCustomSpriteSpriteBase_Base : public ::canvas::BaseMutexHelper< CanvasCustomSpriteBase_Base >,
72 : public Sprite,
73 : public SurfaceProvider
74 : {
75 : };
76 :
77 : typedef ::canvas::CanvasCustomSpriteBase< CanvasCustomSpriteSpriteBase_Base,
78 : SpriteHelper,
79 : CanvasHelper,
80 : ::osl::MutexGuard,
81 : ::cppu::OWeakObject > CanvasCustomSpriteBaseT;
82 :
83 : /* Definition of CanvasCustomSprite class */
84 :
85 0 : class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
86 : public RepaintTarget
87 : {
88 : public:
89 : /** Create a custom sprite
90 :
91 : @param rSpriteSize
92 : Size of the sprite in pixel
93 :
94 : @param rRefDevice
95 : Associated output device
96 :
97 : @param rSpriteCanvas
98 : Target canvas
99 :
100 : @param rDevice
101 : Target DX device
102 : */
103 : CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
104 : const SpriteCanvasRef& rRefDevice );
105 :
106 : virtual void disposeThis() SAL_OVERRIDE;
107 :
108 : // Forwarding the XComponent implementation to the
109 : // cppu::ImplHelper templated base
110 : // Classname Base doing refcount Base implementing the XComponent interface
111 : // | | |
112 : // V V V
113 0 : DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase )
114 :
115 : // XServiceInfo
116 : virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
117 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
118 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
119 :
120 : // Sprite
121 : virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
122 : bool bBufferedUpdate ) const SAL_OVERRIDE;
123 : virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
124 : const ::basegfx::B2DPoint& rOrigOutputPos,
125 : bool bBufferedUpdate ) const SAL_OVERRIDE;
126 :
127 : // RepaintTarget
128 : virtual bool repaint( const ::cairo::SurfaceSharedPtr& pSurface,
129 : const ::com::sun::star::rendering::ViewState& viewState,
130 : const ::com::sun::star::rendering::RenderState& renderState ) SAL_OVERRIDE;
131 :
132 : // SurfaceProvider
133 : virtual ::cairo::SurfaceSharedPtr getSurface() SAL_OVERRIDE;
134 : virtual ::cairo::SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, int aContent = CAIRO_CONTENT_COLOR_ALPHA ) SAL_OVERRIDE;
135 : virtual ::cairo::SurfaceSharedPtr createSurface( ::Bitmap& rBitmap ) SAL_OVERRIDE;
136 : virtual ::cairo::SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent ) SAL_OVERRIDE;
137 : virtual OutputDevice* getOutputDevice() SAL_OVERRIDE;
138 :
139 : private:
140 : /** MUST hold here, too, since CanvasHelper only contains a
141 : raw pointer (without refcounting)
142 : */
143 : SpriteCanvasRef mpSpriteCanvas;
144 : ::cairo::SurfaceSharedPtr mpBufferSurface;
145 : ::basegfx::B2ISize maSize;
146 : };
147 : }
148 :
149 : #endif // INCLUDED_CANVAS_SOURCE_CAIRO_CAIRO_CANVASCUSTOMSPRITE_HXX
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|