xref: /trunk/main/canvas/source/vcl/spritecanvas.cxx (revision 25ea7f45)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_canvas.hxx"
26 
27 #include <canvas/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 #include <canvas/verbosetrace.hxx>
30 #include <canvas/canvastools.hxx>
31 
32 #include <com/sun/star/registry/XRegistryKey.hpp>
33 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 
36 #include <vcl/canvastools.hxx>
37 #include <vcl/outdev.hxx>
38 #include <vcl/window.hxx>
39 #include <vcl/bitmapex.hxx>
40 
41 #include <basegfx/tools/canvastools.hxx>
42 
43 #include <algorithm>
44 
45 #include "spritecanvas.hxx"
46 #include "windowoutdevholder.hxx"
47 
48 
49 using namespace ::com::sun::star;
50 
51 namespace vclcanvas
52 {
SpriteCanvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)53     SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >&                aArguments,
54                                 const uno::Reference< uno::XComponentContext >& rxContext ) :
55         maArguments(aArguments),
56         mxComponentContext( rxContext )
57     {
58     }
59 
initialize()60     void SpriteCanvas::initialize()
61     {
62         tools::LocalGuard aGuard;
63 
64         // #i64742# Only call initialize when not in probe mode
65         if( maArguments.getLength() == 0 )
66             return;
67 
68         OSL_TRACE( "SpriteCanvas created" );
69 
70         // add our own property to GraphicDevice
71         maPropHelper.addProperties(
72             ::canvas::PropertySetHelper::MakeMap
73             ("UnsafeScrolling",
74              boost::bind(&SpriteCanvasHelper::isUnsafeScrolling,
75                          boost::ref(maCanvasHelper)),
76              boost::bind(&SpriteCanvasHelper::enableUnsafeScrolling,
77                          boost::ref(maCanvasHelper),
78                          _1))
79             ("SpriteBounds",
80              boost::bind(&SpriteCanvasHelper::isSpriteBounds,
81                          boost::ref(maCanvasHelper)),
82              boost::bind(&SpriteCanvasHelper::enableSpriteBounds,
83                          boost::ref(maCanvasHelper),
84                          _1)));
85 
86         VERBOSE_TRACE( "VCLSpriteCanvas::initialize called" );
87 
88         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 1,
89                              "VCLSpriteCanvas::initialize: wrong number of arguments" );
90 
91         /* maArguments:
92            0: ptr to creating instance (Window or VirtualDevice)
93            1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
94            2: current bounds of creating instance
95            3: bool, denoting always on top state for Window (always false for VirtualDevice)
96            4: XWindow for creating Window (or empty for VirtualDevice)
97            5: SystemGraphicsData as a streamed Any
98          */
99         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
100                              maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
101                              maArguments[4].getValueTypeClass() == uno::TypeClass_INTERFACE,
102                              "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
103 
104         uno::Reference< awt::XWindow > xParentWindow;
105         maArguments[4] >>= xParentWindow;
106 
107         OutDevProviderSharedPtr pOutDev( new WindowOutDevHolder(xParentWindow) );
108 
109         // setup helper
110         maDeviceHelper.init( pOutDev );
111         setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
112         maCanvasHelper.init( maDeviceHelper.getBackBuffer(),
113                              *this,
114                              maRedrawManager,
115                              false,   // no OutDev state preservation
116                              false ); // no alpha on surface
117 
118         maArguments.realloc(0);
119     }
120 
~SpriteCanvas()121     SpriteCanvas::~SpriteCanvas()
122     {
123         OSL_TRACE( "SpriteCanvas destroyed" );
124     }
125 
126 
disposing()127     void SAL_CALL SpriteCanvas::disposing()
128     {
129         tools::LocalGuard aGuard;
130 
131         mxComponentContext.clear();
132 
133         // forward to parent
134         SpriteCanvasBaseT::disposing();
135     }
136 
showBuffer(::sal_Bool bUpdateAll)137     ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
138     {
139         return updateScreen( bUpdateAll );
140     }
141 
switchBuffer(::sal_Bool bUpdateAll)142     ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
143     {
144         return updateScreen( bUpdateAll );
145     }
146 
updateScreen(sal_Bool bUpdateAll)147     sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
148     {
149         tools::LocalGuard aGuard;
150 
151         // avoid repaints on hidden window (hidden: not mapped to
152         // screen). Return failure, since the screen really has _not_
153         // been updated (caller should try again later)
154         return !mbIsVisible ? false : maCanvasHelper.updateScreen(bUpdateAll,
155                                                                   mbSurfaceDirty);
156     }
157 
getServiceName()158     ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName(  ) throw (::com::sun::star::uno::RuntimeException)
159     {
160         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SPRITECANVAS_SERVICE_NAME ) );
161     }
162 
repaint(const GraphicObjectSharedPtr & rGrf,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const::Point & rPt,const::Size & rSz,const GraphicAttr & rAttr) const163     bool SpriteCanvas::repaint( const GraphicObjectSharedPtr&	rGrf,
164                                 const rendering::ViewState&     viewState,
165                                 const rendering::RenderState&   renderState,
166                                 const ::Point& 					rPt,
167                                 const ::Size& 					rSz,
168                                 const GraphicAttr&				rAttr ) const
169     {
170         tools::LocalGuard aGuard;
171 
172         return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
173     }
174 }
175