1*25ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25ea7f45SAndrew Rist * distributed with this work for additional information 6*25ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 9*25ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*25ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*25ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25ea7f45SAndrew Rist * software distributed under the License is distributed on an 15*25ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 17*25ea7f45SAndrew Rist * specific language governing permissions and limitations 18*25ea7f45SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*25ea7f45SAndrew Rist *************************************************************/ 21*25ea7f45SAndrew Rist 22*25ea7f45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_canvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 29cdf0e10cSrcweir #include <canvas/canvastools.hxx> 30cdf0e10cSrcweir #include <tools/diagnose_ex.h> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 33cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 34cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp> 35cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <vcl/canvastools.hxx> 38cdf0e10cSrcweir #include <vcl/outdev.hxx> 39cdf0e10cSrcweir #include <vcl/window.hxx> 40cdf0e10cSrcweir #include <vcl/bitmapex.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <algorithm> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include "canvas.hxx" 47cdf0e10cSrcweir #include "windowoutdevholder.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace ::com::sun::star; 51cdf0e10cSrcweir 52cdf0e10cSrcweir namespace vclcanvas 53cdf0e10cSrcweir { 54cdf0e10cSrcweir namespace 55cdf0e10cSrcweir { 56cdf0e10cSrcweir class OutDevHolder : public OutDevProvider, 57cdf0e10cSrcweir private ::boost::noncopyable 58cdf0e10cSrcweir { 59cdf0e10cSrcweir public: OutDevHolder(OutputDevice & rOutDev)60cdf0e10cSrcweir explicit OutDevHolder( OutputDevice& rOutDev ) : 61cdf0e10cSrcweir mrOutDev(rOutDev) 62cdf0e10cSrcweir {} 63cdf0e10cSrcweir 64cdf0e10cSrcweir private: getOutDev()65cdf0e10cSrcweir virtual OutputDevice& getOutDev() { return mrOutDev; } getOutDev() const66cdf0e10cSrcweir virtual const OutputDevice& getOutDev() const { return mrOutDev; } 67cdf0e10cSrcweir 68cdf0e10cSrcweir // TODO(Q2): Lifetime issue. This _only_ works reliably, 69cdf0e10cSrcweir // if disposing the Canvas correctly disposes all 70cdf0e10cSrcweir // entities which hold this pointer. 71cdf0e10cSrcweir OutputDevice& mrOutDev; 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir Canvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)75cdf0e10cSrcweir Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments, 76cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& rxContext ) : 77cdf0e10cSrcweir maArguments(aArguments), 78cdf0e10cSrcweir mxComponentContext( rxContext ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir } 81cdf0e10cSrcweir initialize()82cdf0e10cSrcweir void Canvas::initialize() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir // #i64742# Only perform initialization when not in probe mode 85cdf0e10cSrcweir if( maArguments.getLength() == 0 ) 86cdf0e10cSrcweir return; 87cdf0e10cSrcweir 88cdf0e10cSrcweir /* maArguments: 89cdf0e10cSrcweir 0: ptr to creating instance (Window or VirtualDevice) 90cdf0e10cSrcweir 1: SystemEnvData as a streamed Any (or empty for VirtualDevice) 91cdf0e10cSrcweir 2: current bounds of creating instance 92cdf0e10cSrcweir 3: bool, denoting always on top state for Window (always false for VirtualDevice) 93cdf0e10cSrcweir 4: XWindow for creating Window (or empty for VirtualDevice) 94cdf0e10cSrcweir 5: SystemGraphicsData as a streamed Any 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir tools::LocalGuard aGuard; 97cdf0e10cSrcweir 98cdf0e10cSrcweir VERBOSE_TRACE( "VCLCanvas::initialize called" ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 && 101cdf0e10cSrcweir maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER, 102cdf0e10cSrcweir "Canvas::initialize: wrong number of arguments, or wrong types" ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir sal_Int64 nPtr = 0; 105cdf0e10cSrcweir maArguments[0] >>= nPtr; 106cdf0e10cSrcweir 107cdf0e10cSrcweir OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr); 108cdf0e10cSrcweir if( !pOutDev ) 109cdf0e10cSrcweir throw lang::NoSupportException( 110cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 111cdf0e10cSrcweir "Passed OutDev invalid!")), 112cdf0e10cSrcweir NULL); 113cdf0e10cSrcweir 114cdf0e10cSrcweir OutDevProviderSharedPtr pOutdevProvider( new OutDevHolder(*pOutDev) ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir // setup helper 117cdf0e10cSrcweir maDeviceHelper.init( pOutdevProvider ); 118cdf0e10cSrcweir maCanvasHelper.init( *this, 119cdf0e10cSrcweir pOutdevProvider, 120cdf0e10cSrcweir true, // OutDev state preservation 121cdf0e10cSrcweir false ); // no alpha on surface 122cdf0e10cSrcweir 123cdf0e10cSrcweir maArguments.realloc(0); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir ~Canvas()126cdf0e10cSrcweir Canvas::~Canvas() 127cdf0e10cSrcweir { 128cdf0e10cSrcweir OSL_TRACE( "Canvas destroyed" ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir disposing()131cdf0e10cSrcweir void SAL_CALL Canvas::disposing() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir tools::LocalGuard aGuard; 134cdf0e10cSrcweir 135cdf0e10cSrcweir mxComponentContext.clear(); 136cdf0e10cSrcweir 137cdf0e10cSrcweir // forward to parent 138cdf0e10cSrcweir CanvasBaseT::disposing(); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir getServiceName()141cdf0e10cSrcweir ::rtl::OUString SAL_CALL Canvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) ); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir repaint(const GraphicObjectSharedPtr & rGrf,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const::Point & rPt,const::Size & rSz,const GraphicAttr & rAttr) const146cdf0e10cSrcweir bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf, 147cdf0e10cSrcweir const rendering::ViewState& viewState, 148cdf0e10cSrcweir const rendering::RenderState& renderState, 149cdf0e10cSrcweir const ::Point& rPt, 150cdf0e10cSrcweir const ::Size& rSz, 151cdf0e10cSrcweir const GraphicAttr& rAttr ) const 152cdf0e10cSrcweir { 153cdf0e10cSrcweir tools::LocalGuard aGuard; 154cdf0e10cSrcweir 155cdf0e10cSrcweir return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158