/src/libreoffice/canvas/source/vcl/spritecanvas.cxx
Line | Count | Source |
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 | | #include <sal/config.h> |
21 | | #include <sal/log.hxx> |
22 | | |
23 | | #include <com/sun/star/awt/XTopWindow.hpp> |
24 | | #include <com/sun/star/lang/NoSupportException.hpp> |
25 | | #include <cppuhelper/supportsservice.hxx> |
26 | | #include <comphelper/diagnose_ex.hxx> |
27 | | |
28 | | #include "spritecanvas.hxx" |
29 | | #include "outdevholder.hxx" |
30 | | #include "windowoutdevholder.hxx" |
31 | | |
32 | | |
33 | | using namespace ::com::sun::star; |
34 | | |
35 | | namespace vclcanvas |
36 | | { |
37 | | SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments, |
38 | | const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) : |
39 | 0 | maArguments(aArguments) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | void SpriteCanvas::initialize() |
44 | 0 | { |
45 | 0 | SolarMutexGuard aGuard; |
46 | | |
47 | | // #i64742# Only call initialize when not in probe mode |
48 | 0 | if( !maArguments.hasElements() ) |
49 | 0 | return; |
50 | | |
51 | 0 | SAL_INFO("canvas.vcl", "SpriteCanvas created" ); |
52 | | |
53 | | // add our own property to GraphicDevice |
54 | 0 | maPropHelper.addProperties( |
55 | 0 | ::canvas::PropertySetHelper::MakeMap |
56 | 0 | ("UnsafeScrolling", |
57 | 0 | [this]() { return this->maCanvasHelper.isUnsafeScrolling(); }, |
58 | 0 | [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableUnsafeScrolling(aAny); } ) |
59 | 0 | ("SpriteBounds", |
60 | 0 | [this]() { return this->maCanvasHelper.isSpriteBounds(); }, |
61 | 0 | [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableSpriteBounds(aAny); } )); |
62 | |
|
63 | 0 | SAL_INFO("canvas.vcl", "VCLSpriteCanvas::initialize called" ); |
64 | | |
65 | 0 | ENSURE_ARG_OR_THROW( maArguments.hasElements(), |
66 | 0 | "VCLSpriteCanvas::initialize: wrong number of arguments" ); |
67 | | |
68 | | /* maArguments: |
69 | | 0: ptr to creating instance (Window or VirtualDevice) |
70 | | 1: current bounds of creating instance |
71 | | 2: bool, denoting always on top state for Window (always false for VirtualDevice) |
72 | | 3: XWindow for creating Window (or empty for VirtualDevice) |
73 | | 4: SystemGraphicsData as a streamed Any |
74 | | */ |
75 | 0 | ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 && |
76 | 0 | maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER && |
77 | 0 | maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE, |
78 | 0 | "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" ); |
79 | |
|
80 | 0 | sal_Int64 nPtr = 0; |
81 | 0 | maArguments[0] >>= nPtr; |
82 | |
|
83 | 0 | OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr); |
84 | 0 | if( !pOutDev ) |
85 | 0 | throw lang::NoSupportException(u"Passed OutDev invalid!"_ustr, nullptr); |
86 | | |
87 | 0 | uno::Reference< awt::XWindow > xParentWindow; |
88 | 0 | maArguments[3] >>= xParentWindow; |
89 | |
|
90 | 0 | OutDevProviderSharedPtr pOutDevProvider; |
91 | 0 | if( xParentWindow.is()) |
92 | 0 | pOutDevProvider = std::make_shared<WindowOutDevHolder>(xParentWindow); |
93 | 0 | else |
94 | 0 | pOutDevProvider = std::make_shared<OutDevHolder>(*pOutDev); |
95 | | |
96 | | // setup helper |
97 | 0 | maDeviceHelper.init( pOutDevProvider ); |
98 | 0 | setWindow( xParentWindow.is() |
99 | 0 | ? uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW) |
100 | 0 | : uno::Reference<awt::XWindow2>()); |
101 | 0 | maCanvasHelper.init( maDeviceHelper.getBackBuffer(), |
102 | 0 | *this, |
103 | 0 | maRedrawManager, |
104 | 0 | false, // no OutDev state preservation |
105 | 0 | false ); // no alpha on surface |
106 | |
|
107 | 0 | maArguments.realloc(0); |
108 | 0 | } |
109 | | |
110 | | SpriteCanvas::~SpriteCanvas() |
111 | 0 | { |
112 | 0 | SAL_INFO("canvas.vcl", "SpriteCanvas destroyed" ); |
113 | 0 | } |
114 | | |
115 | | |
116 | | void SpriteCanvas::disposeThis() |
117 | 0 | { |
118 | 0 | SolarMutexGuard aGuard; |
119 | | |
120 | | // forward to parent |
121 | 0 | SpriteCanvasBaseT::disposeThis(); |
122 | 0 | } |
123 | | |
124 | | sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll ) |
125 | 0 | { |
126 | 0 | return updateScreen( bUpdateAll ); |
127 | 0 | } |
128 | | |
129 | | sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) |
130 | 0 | { |
131 | 0 | return updateScreen( bUpdateAll ); |
132 | 0 | } |
133 | | |
134 | | sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) |
135 | 0 | { |
136 | 0 | SolarMutexGuard aGuard; |
137 | | |
138 | | // avoid repaints on hidden window (hidden: not mapped to |
139 | | // screen). Return failure, since the screen really has _not_ |
140 | | // been updated (caller should try again later) |
141 | 0 | return mbIsVisible && maCanvasHelper.updateScreen(bUpdateAll, |
142 | 0 | mbSurfaceDirty); |
143 | 0 | } |
144 | | |
145 | | OUString SAL_CALL SpriteCanvas::getServiceName( ) |
146 | 0 | { |
147 | 0 | return u"com.sun.star.rendering.SpriteCanvas.VCL"_ustr; |
148 | 0 | } |
149 | | |
150 | | // XServiceInfo |
151 | | css::uno::Sequence<OUString> SpriteCanvas::getSupportedServiceNames() |
152 | 0 | { |
153 | 0 | return { SpriteCanvas::getServiceName() }; |
154 | 0 | } |
155 | | OUString SpriteCanvas::getImplementationName() |
156 | 0 | { |
157 | 0 | return u"com.sun.star.comp.rendering.SpriteCanvas.VCL"_ustr; |
158 | 0 | } |
159 | | sal_Bool SpriteCanvas::supportsService(const OUString& sServiceName) |
160 | 0 | { |
161 | 0 | return cppu::supportsService(this, sServiceName); |
162 | 0 | } |
163 | | |
164 | | bool SpriteCanvas::repaint( const GraphicObjectSharedPtr& rGrf, |
165 | | const rendering::ViewState& viewState, |
166 | | const rendering::RenderState& renderState, |
167 | | const ::Point& rPt, |
168 | | const ::Size& rSz, |
169 | | const GraphicAttr& rAttr ) const |
170 | 0 | { |
171 | 0 | SolarMutexGuard aGuard; |
172 | |
|
173 | 0 | return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr ); |
174 | 0 | } |
175 | | } |
176 | | |
177 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
178 | | com_sun_star_comp_rendering_SpriteCanvas_VCL_get_implementation( |
179 | | css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args) |
180 | 0 | { |
181 | 0 | rtl::Reference<vclcanvas::SpriteCanvas> p = new vclcanvas::SpriteCanvas(args, context); |
182 | 0 | p->initialize(); |
183 | 0 | return cppu::acquire(p.get()); |
184 | 0 | } |
185 | | |
186 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |