Update ooo320-m1
[ooovba.git] / canvas / source / vcl / spritecanvas.cxx
blob9613a1a89b9d0d82154c7476f581d54016d4d46e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: spritecanvas.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <canvas/verbosetrace.hxx>
37 #include <canvas/canvastools.hxx>
39 #include <com/sun/star/registry/XRegistryKey.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <vcl/canvastools.hxx>
44 #include <vcl/outdev.hxx>
45 #include <vcl/window.hxx>
46 #include <vcl/bitmapex.hxx>
48 #include <basegfx/tools/canvastools.hxx>
50 #include <algorithm>
52 #include "spritecanvas.hxx"
53 #include "windowoutdevholder.hxx"
56 using namespace ::com::sun::star;
58 namespace vclcanvas
60 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
61 const uno::Reference< uno::XComponentContext >& rxContext ) :
62 maArguments(aArguments),
63 mxComponentContext( rxContext )
67 void SpriteCanvas::initialize()
69 tools::LocalGuard aGuard;
71 // #i64742# Only call initialize when not in probe mode
72 if( maArguments.getLength() == 0 )
73 return;
75 OSL_TRACE( "SpriteCanvas created" );
77 // add our own property to GraphicDevice
78 maPropHelper.addProperties(
79 ::canvas::PropertySetHelper::MakeMap
80 ("UnsafeScrolling",
81 boost::bind(&SpriteCanvasHelper::isUnsafeScrolling,
82 boost::ref(maCanvasHelper)),
83 boost::bind(&SpriteCanvasHelper::enableUnsafeScrolling,
84 boost::ref(maCanvasHelper),
85 _1))
86 ("SpriteBounds",
87 boost::bind(&SpriteCanvasHelper::isSpriteBounds,
88 boost::ref(maCanvasHelper)),
89 boost::bind(&SpriteCanvasHelper::enableSpriteBounds,
90 boost::ref(maCanvasHelper),
91 _1)));
93 VERBOSE_TRACE( "VCLSpriteCanvas::initialize called" );
95 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 1,
96 "VCLSpriteCanvas::initialize: wrong number of arguments" );
98 /* maArguments:
99 0: ptr to creating instance (Window or VirtualDevice)
100 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
101 2: current bounds of creating instance
102 3: bool, denoting always on top state for Window (always false for VirtualDevice)
103 4: XWindow for creating Window (or empty for VirtualDevice)
104 5: SystemGraphicsData as a streamed Any
106 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
107 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
108 maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
109 "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
111 uno::Reference< awt::XWindow > xParentWindow;
112 maArguments[4] >>= xParentWindow;
114 OutDevProviderSharedPtr pOutDev( new WindowOutDevHolder(xParentWindow) );
116 // setup helper
117 maDeviceHelper.init( pOutDev );
118 setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
119 maCanvasHelper.init( maDeviceHelper.getBackBuffer(),
120 *this,
121 maRedrawManager,
122 false, // no OutDev state preservation
123 false ); // no alpha on surface
125 maArguments.realloc(0);
128 SpriteCanvas::~SpriteCanvas()
130 OSL_TRACE( "SpriteCanvas destroyed" );
134 void SAL_CALL SpriteCanvas::disposing()
136 tools::LocalGuard aGuard;
138 mxComponentContext.clear();
140 // forward to parent
141 SpriteCanvasBaseT::disposing();
144 ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
146 return updateScreen( bUpdateAll );
149 ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
151 return updateScreen( bUpdateAll );
154 sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
156 tools::LocalGuard aGuard;
158 // avoid repaints on hidden window (hidden: not mapped to
159 // screen). Return failure, since the screen really has _not_
160 // been updated (caller should try again later)
161 return !mbIsVisible ? false : maCanvasHelper.updateScreen(bUpdateAll,
162 mbSurfaceDirty);
165 ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException)
167 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) );
170 bool SpriteCanvas::repaint( const GraphicObjectSharedPtr& rGrf,
171 const rendering::ViewState& viewState,
172 const rendering::RenderState& renderState,
173 const ::Point& rPt,
174 const ::Size& rSz,
175 const GraphicAttr& rAttr ) const
177 tools::LocalGuard aGuard;
179 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );