Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / vcl / spritecanvas.cxx
blob91e21038900dbb84f3e851832433849eefc08e65
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <canvas/verbosetrace.hxx>
24 #include <canvas/canvastools.hxx>
26 #include <com/sun/star/registry/XRegistryKey.hpp>
27 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <vcl/canvastools.hxx>
31 #include <vcl/outdev.hxx>
32 #include <vcl/window.hxx>
33 #include <vcl/bitmapex.hxx>
35 #include <basegfx/tools/canvastools.hxx>
37 #include <algorithm>
39 #include "spritecanvas.hxx"
40 #include "windowoutdevholder.hxx"
43 using namespace ::com::sun::star;
45 namespace vclcanvas
47 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
48 const uno::Reference< uno::XComponentContext >& rxContext ) :
49 maArguments(aArguments),
50 mxComponentContext( rxContext )
54 void SpriteCanvas::initialize()
56 SolarMutexGuard aGuard;
58 // #i64742# Only call initialize when not in probe mode
59 if( maArguments.getLength() == 0 )
60 return;
62 OSL_TRACE( "SpriteCanvas created" );
64 // add our own property to GraphicDevice
65 maPropHelper.addProperties(
66 ::canvas::PropertySetHelper::MakeMap
67 ("UnsafeScrolling",
68 boost::bind(&SpriteCanvasHelper::isUnsafeScrolling,
69 boost::ref(maCanvasHelper)),
70 boost::bind(&SpriteCanvasHelper::enableUnsafeScrolling,
71 boost::ref(maCanvasHelper),
72 _1))
73 ("SpriteBounds",
74 boost::bind(&SpriteCanvasHelper::isSpriteBounds,
75 boost::ref(maCanvasHelper)),
76 boost::bind(&SpriteCanvasHelper::enableSpriteBounds,
77 boost::ref(maCanvasHelper),
78 _1)));
80 VERBOSE_TRACE( "VCLSpriteCanvas::initialize called" );
82 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 1,
83 "VCLSpriteCanvas::initialize: wrong number of arguments" );
85 /* maArguments:
86 0: ptr to creating instance (Window or VirtualDevice)
87 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
88 2: current bounds of creating instance
89 3: bool, denoting always on top state for Window (always false for VirtualDevice)
90 4: XWindow for creating Window (or empty for VirtualDevice)
91 5: SystemGraphicsData as a streamed Any
93 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
94 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
95 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
96 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
98 uno::Reference< awt::XWindow > xParentWindow;
99 maArguments[4] >>= xParentWindow;
101 OutDevProviderSharedPtr pOutDev( new WindowOutDevHolder(xParentWindow) );
103 // setup helper
104 maDeviceHelper.init( pOutDev );
105 setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
106 maCanvasHelper.init( maDeviceHelper.getBackBuffer(),
107 *this,
108 maRedrawManager,
109 false, // no OutDev state preservation
110 false ); // no alpha on surface
112 maArguments.realloc(0);
115 SpriteCanvas::~SpriteCanvas()
117 OSL_TRACE( "SpriteCanvas destroyed" );
121 void SpriteCanvas::disposeThis()
123 SolarMutexGuard aGuard;
125 mxComponentContext.clear();
127 // forward to parent
128 SpriteCanvasBaseT::disposeThis();
131 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
133 return updateScreen( bUpdateAll );
136 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
138 return updateScreen( bUpdateAll );
141 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException, std::exception)
143 SolarMutexGuard aGuard;
145 // avoid repaints on hidden window (hidden: not mapped to
146 // screen). Return failure, since the screen really has _not_
147 // been updated (caller should try again later)
148 return mbIsVisible && maCanvasHelper.updateScreen(bUpdateAll,
149 mbSurfaceDirty);
152 OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
154 return OUString( SPRITECANVAS_SERVICE_NAME );
157 bool SpriteCanvas::repaint( const GraphicObjectSharedPtr& rGrf,
158 const rendering::ViewState& viewState,
159 const rendering::RenderState& renderState,
160 const ::Point& rPt,
161 const ::Size& rSz,
162 const GraphicAttr& rAttr ) const
164 SolarMutexGuard aGuard;
166 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */