update dev300-m58
[ooovba.git] / canvas / source / vcl / canvas.cxx
blob698c286c7127c3f86b872e9c5ab295ee7e7079eb
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: canvas.cxx,v $
10 * $Revision: 1.3 $
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 <canvas/verbosetrace.hxx>
36 #include <canvas/canvastools.hxx>
37 #include <tools/diagnose_ex.h>
39 #include <com/sun/star/registry/XRegistryKey.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/lang/NoSupportException.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <vcl/canvastools.hxx>
45 #include <vcl/outdev.hxx>
46 #include <vcl/window.hxx>
47 #include <vcl/bitmapex.hxx>
49 #include <basegfx/tools/canvastools.hxx>
51 #include <algorithm>
53 #include "canvas.hxx"
54 #include "windowoutdevholder.hxx"
57 using namespace ::com::sun::star;
59 namespace vclcanvas
61 namespace
63 class OutDevHolder : public OutDevProvider,
64 private ::boost::noncopyable
66 public:
67 explicit OutDevHolder( OutputDevice& rOutDev ) :
68 mrOutDev(rOutDev)
71 private:
72 virtual OutputDevice& getOutDev() { return mrOutDev; }
73 virtual const OutputDevice& getOutDev() const { return mrOutDev; }
75 // TODO(Q2): Lifetime issue. This _only_ works reliably,
76 // if disposing the Canvas correctly disposes all
77 // entities which hold this pointer.
78 OutputDevice& mrOutDev;
82 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
83 const uno::Reference< uno::XComponentContext >& rxContext ) :
84 maArguments(aArguments),
85 mxComponentContext( rxContext )
89 void Canvas::initialize()
91 // #i64742# Only perform initialization when not in probe mode
92 if( maArguments.getLength() == 0 )
93 return;
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
103 tools::LocalGuard aGuard;
105 VERBOSE_TRACE( "VCLCanvas::initialize called" );
107 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
108 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER,
109 "Canvas::initialize: wrong number of arguments, or wrong types" );
111 sal_Int64 nPtr = 0;
112 maArguments[0] >>= nPtr;
114 OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
115 if( !pOutDev )
116 throw lang::NoSupportException(
117 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
118 "Passed OutDev invalid!")),
119 NULL);
121 OutDevProviderSharedPtr pOutdevProvider( new OutDevHolder(*pOutDev) );
123 // setup helper
124 maDeviceHelper.init( pOutdevProvider );
125 maCanvasHelper.init( *this,
126 pOutdevProvider,
127 true, // OutDev state preservation
128 false ); // no alpha on surface
130 maArguments.realloc(0);
133 Canvas::~Canvas()
135 OSL_TRACE( "Canvas destroyed" );
138 void SAL_CALL Canvas::disposing()
140 tools::LocalGuard aGuard;
142 mxComponentContext.clear();
144 // forward to parent
145 CanvasBaseT::disposing();
148 ::rtl::OUString SAL_CALL Canvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException)
150 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
153 bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf,
154 const rendering::ViewState& viewState,
155 const rendering::RenderState& renderState,
156 const ::Point& rPt,
157 const ::Size& rSz,
158 const GraphicAttr& rAttr ) const
160 tools::LocalGuard aGuard;
162 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );