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