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