xref: /trunk/main/canvas/source/vcl/canvas.cxx (revision 25ea7f45)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_canvas.hxx"
26 
27 #include <canvas/debug.hxx>
28 #include <canvas/verbosetrace.hxx>
29 #include <canvas/canvastools.hxx>
30 #include <tools/diagnose_ex.h>
31 
32 #include <com/sun/star/registry/XRegistryKey.hpp>
33 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
34 #include <com/sun/star/lang/NoSupportException.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 
37 #include <vcl/canvastools.hxx>
38 #include <vcl/outdev.hxx>
39 #include <vcl/window.hxx>
40 #include <vcl/bitmapex.hxx>
41 
42 #include <basegfx/tools/canvastools.hxx>
43 
44 #include <algorithm>
45 
46 #include "canvas.hxx"
47 #include "windowoutdevholder.hxx"
48 
49 
50 using namespace ::com::sun::star;
51 
52 namespace vclcanvas
53 {
54     namespace
55     {
56         class OutDevHolder : public OutDevProvider,
57             private ::boost::noncopyable
58         {
59         public:
OutDevHolder(OutputDevice & rOutDev)60             explicit OutDevHolder( OutputDevice& rOutDev ) :
61                 mrOutDev(rOutDev)
62             {}
63 
64         private:
getOutDev()65             virtual OutputDevice& 		getOutDev() { return mrOutDev; }
getOutDev() const66             virtual const OutputDevice& getOutDev() const { return mrOutDev; }
67 
68             // TODO(Q2): Lifetime issue. This _only_ works reliably,
69             // if disposing the Canvas correctly disposes all
70             // entities which hold this pointer.
71             OutputDevice& mrOutDev;
72         };
73     }
74 
Canvas(const uno::Sequence<uno::Any> & aArguments,const uno::Reference<uno::XComponentContext> & rxContext)75     Canvas::Canvas( const uno::Sequence< uno::Any >&                aArguments,
76                     const uno::Reference< uno::XComponentContext >& rxContext ) :
77         maArguments(aArguments),
78         mxComponentContext( rxContext )
79     {
80     }
81 
initialize()82     void Canvas::initialize()
83     {
84         // #i64742# Only perform initialization when not in probe mode
85         if( maArguments.getLength() == 0 )
86             return;
87 
88         /* maArguments:
89            0: ptr to creating instance (Window or VirtualDevice)
90            1: SystemEnvData as a streamed Any (or empty for VirtualDevice)
91            2: current bounds of creating instance
92            3: bool, denoting always on top state for Window (always false for VirtualDevice)
93            4: XWindow for creating Window (or empty for VirtualDevice)
94            5: SystemGraphicsData as a streamed Any
95          */
96         tools::LocalGuard aGuard;
97 
98         VERBOSE_TRACE( "VCLCanvas::initialize called" );
99 
100         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
101                              maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER,
102                              "Canvas::initialize: wrong number of arguments, or wrong types" );
103 
104         sal_Int64 nPtr = 0;
105         maArguments[0] >>= nPtr;
106 
107         OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
108         if( !pOutDev )
109             throw lang::NoSupportException(
110                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
111                                      "Passed OutDev invalid!")),
112                 NULL);
113 
114         OutDevProviderSharedPtr pOutdevProvider( new OutDevHolder(*pOutDev) );
115 
116         // setup helper
117         maDeviceHelper.init( pOutdevProvider );
118         maCanvasHelper.init( *this,
119                              pOutdevProvider,
120                              true,   // OutDev state preservation
121                              false ); // no alpha on surface
122 
123         maArguments.realloc(0);
124     }
125 
~Canvas()126     Canvas::~Canvas()
127     {
128         OSL_TRACE( "Canvas destroyed" );
129     }
130 
disposing()131     void SAL_CALL Canvas::disposing()
132     {
133         tools::LocalGuard aGuard;
134 
135         mxComponentContext.clear();
136 
137         // forward to parent
138         CanvasBaseT::disposing();
139     }
140 
getServiceName()141     ::rtl::OUString SAL_CALL Canvas::getServiceName(  ) throw (::com::sun::star::uno::RuntimeException)
142     {
143         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
144     }
145 
repaint(const GraphicObjectSharedPtr & rGrf,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const::Point & rPt,const::Size & rSz,const GraphicAttr & rAttr) const146     bool Canvas::repaint( const GraphicObjectSharedPtr&	rGrf,
147                           const rendering::ViewState&   viewState,
148                           const rendering::RenderState& renderState,
149                           const ::Point& 				rPt,
150                           const ::Size& 				rSz,
151                           const GraphicAttr&			rAttr ) const
152     {
153         tools::LocalGuard aGuard;
154 
155         return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
156     }
157 }
158