Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <canvas/debug.hxx>
31 : : #include <canvas/verbosetrace.hxx>
32 : : #include <canvas/canvastools.hxx>
33 : : #include <tools/diagnose_ex.h>
34 : :
35 : : #include <com/sun/star/registry/XRegistryKey.hpp>
36 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 : : #include <com/sun/star/lang/NoSupportException.hpp>
38 : : #include <com/sun/star/uno/XComponentContext.hpp>
39 : :
40 : : #include <vcl/canvastools.hxx>
41 : : #include <vcl/outdev.hxx>
42 : : #include <vcl/window.hxx>
43 : : #include <vcl/bitmapex.hxx>
44 : :
45 : : #include <basegfx/tools/canvastools.hxx>
46 : :
47 : : #include <algorithm>
48 : :
49 : : #include "canvas.hxx"
50 : : #include "windowoutdevholder.hxx"
51 : :
52 : :
53 : : using namespace ::com::sun::star;
54 : :
55 : : namespace vclcanvas
56 : : {
57 : : namespace
58 : : {
59 : 0 : class OutDevHolder : public OutDevProvider,
60 : : private ::boost::noncopyable
61 : : {
62 : : public:
63 : 0 : explicit OutDevHolder( OutputDevice& rOutDev ) :
64 : 0 : mrOutDev(rOutDev)
65 : 0 : {}
66 : :
67 : : private:
68 : 0 : virtual OutputDevice& getOutDev() { return mrOutDev; }
69 : 0 : virtual const OutputDevice& getOutDev() const { return mrOutDev; }
70 : :
71 : : // TODO(Q2): Lifetime issue. This _only_ works reliably,
72 : : // if disposing the Canvas correctly disposes all
73 : : // entities which hold this pointer.
74 : : OutputDevice& mrOutDev;
75 : : };
76 : : }
77 : :
78 : 0 : Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
79 : : const uno::Reference< uno::XComponentContext >& rxContext ) :
80 : : maArguments(aArguments),
81 : 0 : mxComponentContext( rxContext )
82 : : {
83 : 0 : }
84 : :
85 : 0 : void Canvas::initialize()
86 : : {
87 : : // #i64742# Only perform initialization when not in probe mode
88 : 0 : if( maArguments.getLength() == 0 )
89 : 0 : return;
90 : :
91 : : /* maArguments:
92 : : 0: ptr to creating instance (Window or VirtualDevice)
93 : : 1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
94 : : 2: current bounds of creating instance
95 : : 3: bool, denoting always on top state for Window (always false for VirtualDevice)
96 : : 4: XWindow for creating Window (or empty for VirtualDevice)
97 : : 5: SystemGraphicsData as a streamed Any
98 : : */
99 : 0 : SolarMutexGuard aGuard;
100 : :
101 : : VERBOSE_TRACE( "VCLCanvas::initialize called" );
102 : :
103 : 0 : ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
104 : : maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER,
105 : : "Canvas::initialize: wrong number of arguments, or wrong types" );
106 : :
107 : 0 : sal_Int64 nPtr = 0;
108 : 0 : maArguments[0] >>= nPtr;
109 : :
110 : 0 : OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
111 : 0 : if( !pOutDev )
112 : : throw lang::NoSupportException(
113 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
114 : : "Passed OutDev invalid!")),
115 : 0 : NULL);
116 : :
117 : 0 : OutDevProviderSharedPtr pOutdevProvider( new OutDevHolder(*pOutDev) );
118 : :
119 : : // setup helper
120 : 0 : maDeviceHelper.init( pOutdevProvider );
121 : : maCanvasHelper.init( *this,
122 : : pOutdevProvider,
123 : : true, // OutDev state preservation
124 : 0 : false ); // no alpha on surface
125 : :
126 : 0 : maArguments.realloc(0);
127 : : }
128 : :
129 : 0 : Canvas::~Canvas()
130 : : {
131 : : OSL_TRACE( "Canvas destroyed" );
132 : 0 : }
133 : :
134 : 0 : void Canvas::disposeThis()
135 : : {
136 : 0 : SolarMutexGuard aGuard;
137 : :
138 : 0 : mxComponentContext.clear();
139 : :
140 : : // forward to parent
141 : 0 : CanvasBaseT::disposeThis();
142 : 0 : }
143 : :
144 : 0 : ::rtl::OUString SAL_CALL Canvas::getServiceName( ) throw (::com::sun::star::uno::RuntimeException)
145 : : {
146 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
147 : : }
148 : :
149 : 0 : bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf,
150 : : const rendering::ViewState& viewState,
151 : : const rendering::RenderState& renderState,
152 : : const ::Point& rPt,
153 : : const ::Size& rSz,
154 : : const GraphicAttr& rAttr ) const
155 : : {
156 : 0 : SolarMutexGuard aGuard;
157 : :
158 : 0 : return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
159 : : }
160 : 0 : }
161 : :
162 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|