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