Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / vcl / canvas.cxx
blob1ab45a5722996e72e81f77677ea7b5a91ed3d7b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/debug.hxx>
22 #include <canvas/verbosetrace.hxx>
23 #include <canvas/canvastools.hxx>
24 #include <tools/diagnose_ex.h>
26 #include <com/sun/star/registry/XRegistryKey.hpp>
27 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 #include <com/sun/star/lang/NoSupportException.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <vcl/canvastools.hxx>
32 #include <vcl/outdev.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/bitmapex.hxx>
36 #include <basegfx/tools/canvastools.hxx>
38 #include <algorithm>
40 #include "canvas.hxx"
41 #include "windowoutdevholder.hxx"
43 using namespace ::com::sun::star;
45 namespace vclcanvas
47 namespace
49 class OutDevHolder : public OutDevProvider,
50 private ::boost::noncopyable
52 public:
53 explicit OutDevHolder( OutputDevice& rOutDev ) :
54 mrOutDev(rOutDev)
57 private:
58 virtual OutputDevice& getOutDev() SAL_OVERRIDE { return mrOutDev; }
59 virtual const OutputDevice& getOutDev() const SAL_OVERRIDE { return mrOutDev; }
61 // TODO(Q2): Lifetime issue. This _only_ works reliably,
62 // if disposing the Canvas correctly disposes all
63 // entities which hold this pointer.
64 OutputDevice& mrOutDev;
68 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
69 const uno::Reference< uno::XComponentContext >& rxContext ) :
70 maArguments(aArguments),
71 mxComponentContext( rxContext )
75 void Canvas::initialize()
77 // #i64742# Only perform initialization when not in probe mode
78 if( maArguments.getLength() == 0 )
79 return;
81 /* maArguments:
82 0: ptr to creating instance (Window or VirtualDevice)
83 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
84 2: current bounds of creating instance
85 3: bool, denoting always on top state for Window (always false for VirtualDevice)
86 4: XWindow for creating Window (or empty for VirtualDevice)
87 5: SystemGraphicsData as a streamed Any
89 SolarMutexGuard aGuard;
91 VERBOSE_TRACE( "VCLCanvas::initialize called" );
93 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
94 maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER,
95 "Canvas::initialize: wrong number of arguments, or wrong types" );
97 sal_Int64 nPtr = 0;
98 maArguments[0] >>= nPtr;
100 OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
101 if( !pOutDev )
102 throw lang::NoSupportException(
103 OUString( "Passed OutDev invalid!" ),
104 NULL);
106 OutDevProviderSharedPtr pOutdevProvider( new OutDevHolder(*pOutDev) );
108 // setup helper
109 maDeviceHelper.init( pOutdevProvider );
110 maCanvasHelper.init( *this,
111 pOutdevProvider,
112 true, // OutDev state preservation
113 false ); // no alpha on surface
115 maArguments.realloc(0);
118 Canvas::~Canvas()
120 OSL_TRACE( "Canvas destroyed" );
123 void Canvas::disposeThis()
125 SolarMutexGuard aGuard;
127 mxComponentContext.clear();
129 // forward to parent
130 CanvasBaseT::disposeThis();
133 OUString SAL_CALL Canvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
135 return OUString( CANVAS_SERVICE_NAME );
138 bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf,
139 const rendering::ViewState& viewState,
140 const rendering::RenderState& renderState,
141 const ::Point& rPt,
142 const ::Size& rSz,
143 const GraphicAttr& rAttr ) const
145 SolarMutexGuard aGuard;
147 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */