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 <canvas/verbosetrace.hxx> 33 #include <canvas/canvastools.hxx> 34 #include <tools/diagnose_ex.h> 35 36 #include <com/sun/star/registry/XRegistryKey.hpp> 37 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 38 #include <com/sun/star/lang/NoSupportException.hpp> 39 #include <com/sun/star/uno/XComponentContext.hpp> 40 41 #include <vcl/canvastools.hxx> 42 #include <vcl/outdev.hxx> 43 #include <vcl/window.hxx> 44 #include <vcl/bitmapex.hxx> 45 46 #include <basegfx/tools/canvastools.hxx> 47 48 #include <algorithm> 49 50 #include "canvas.hxx" 51 #include "windowoutdevholder.hxx" 52 53 54 using namespace ::com::sun::star; 55 56 namespace vclcanvas 57 { 58 namespace 59 { 60 class OutDevHolder : public OutDevProvider, 61 private ::boost::noncopyable 62 { 63 public: 64 explicit OutDevHolder( OutputDevice& rOutDev ) : 65 mrOutDev(rOutDev) 66 {} 67 68 private: 69 virtual OutputDevice& getOutDev() { return mrOutDev; } 70 virtual const OutputDevice& getOutDev() const { return mrOutDev; } 71 72 // TODO(Q2): Lifetime issue. This _only_ works reliably, 73 // if disposing the Canvas correctly disposes all 74 // entities which hold this pointer. 75 OutputDevice& mrOutDev; 76 }; 77 } 78 79 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments, 80 const uno::Reference< uno::XComponentContext >& rxContext ) : 81 maArguments(aArguments), 82 mxComponentContext( rxContext ) 83 { 84 } 85 86 void Canvas::initialize() 87 { 88 // #i64742# Only perform initialization when not in probe mode 89 if( maArguments.getLength() == 0 ) 90 return; 91 92 /* maArguments: 93 0: ptr to creating instance (Window or VirtualDevice) 94 1: SystemEnvData as a streamed Any (or empty for VirtualDevice) 95 2: current bounds of creating instance 96 3: bool, denoting always on top state for Window (always false for VirtualDevice) 97 4: XWindow for creating Window (or empty for VirtualDevice) 98 5: SystemGraphicsData as a streamed Any 99 */ 100 tools::LocalGuard aGuard; 101 102 VERBOSE_TRACE( "VCLCanvas::initialize called" ); 103 104 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 && 105 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER, 106 "Canvas::initialize: wrong number of arguments, or wrong types" ); 107 108 sal_Int64 nPtr = 0; 109 maArguments[0] >>= nPtr; 110 111 OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr); 112 if( !pOutDev ) 113 throw lang::NoSupportException( 114 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 115 "Passed OutDev invalid!")), 116 NULL); 117 118 OutDevProviderSharedPtr pOutdevProvider( new OutDevHolder(*pOutDev) ); 119 120 // setup helper 121 maDeviceHelper.init( pOutdevProvider ); 122 maCanvasHelper.init( *this, 123 pOutdevProvider, 124 true, // OutDev state preservation 125 false ); // no alpha on surface 126 127 maArguments.realloc(0); 128 } 129 130 Canvas::~Canvas() 131 { 132 OSL_TRACE( "Canvas destroyed" ); 133 } 134 135 void SAL_CALL Canvas::disposing() 136 { 137 tools::LocalGuard aGuard; 138 139 mxComponentContext.clear(); 140 141 // forward to parent 142 CanvasBaseT::disposing(); 143 } 144 145 ::rtl::OUString SAL_CALL Canvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException) 146 { 147 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) ); 148 } 149 150 bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf, 151 const rendering::ViewState& viewState, 152 const rendering::RenderState& renderState, 153 const ::Point& rPt, 154 const ::Size& rSz, 155 const GraphicAttr& rAttr ) const 156 { 157 tools::LocalGuard aGuard; 158 159 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr ); 160 } 161 } 162