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