merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / directx / dx_canvas.cxx
bloba10b00b84b985d1940b5c5898559d984344304d7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_canvas.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <ctype.h> // don't ask. msdev breaks otherwise...
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
37 #include <canvas/canvastools.hxx>
38 #include <tools/diagnose_ex.h>
40 #include <osl/mutex.hxx>
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
44 #include <com/sun/star/registry/XRegistryKey.hpp>
45 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
46 #include <com/sun/star/uno/XComponentContext.hpp>
47 #include <com/sun/star/lang/NoSupportException.hpp>
49 #include <toolkit/helper/vclunohelper.hxx>
50 #include <cppuhelper/factory.hxx>
51 #include <cppuhelper/implementationentry.hxx>
52 #include <comphelper/servicedecl.hxx>
54 #include <basegfx/matrix/b2dhommatrix.hxx>
55 #include <basegfx/point/b2dpoint.hxx>
56 #include <basegfx/tools/canvastools.hxx>
57 #include <basegfx/numeric/ftools.hxx>
59 #include "dx_graphicsprovider.hxx"
60 #include "dx_winstuff.hxx"
61 #include "dx_canvas.hxx"
63 #include <vcl/sysdata.hxx>
65 #define CANVAS_TECH "GDI+"
66 #define CANVAS_SERVICE_NAME "com.sun.star.rendering.Canvas." CANVAS_TECH
67 #define CANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.Canvas." CANVAS_TECH
68 #define BITMAPCANVAS_SERVICE_NAME "com.sun.star.rendering.BitmapCanvas." CANVAS_TECH
69 #define BITMAPCANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.BitmapCanvas." CANVAS_TECH
72 using namespace ::com::sun::star;
74 namespace dxcanvas
76 /// Actual canonical implementation of the GraphicsProvider interface
77 class GraphicsProviderImpl : public GraphicsProvider
79 GraphicsSharedPtr mpGraphics;
80 public:
81 explicit GraphicsProviderImpl( Gdiplus::Graphics* pGraphics ) : mpGraphics( pGraphics ) {}
82 virtual GraphicsSharedPtr getGraphics() { return mpGraphics; }
85 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
86 const uno::Reference< uno::XComponentContext >& rxContext ) :
87 maArguments(aArguments),
88 mxComponentContext( rxContext )
92 void Canvas::initialize()
94 // #i64742# Only perform initialization when not in probe mode
95 if( maArguments.getLength() == 0 )
96 return;
98 VERBOSE_TRACE( "Canvas::initialize called" );
100 // At index 1, we expect a HWND handle here, containing a
101 // pointer to a valid window, on which to output
102 // At index 2, we expect the current window bound rect
103 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
104 maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
105 "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
107 uno::Sequence<sal_Int8> aSeq;
108 maArguments[5] >>= aSeq;
110 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
111 if( !pSysData || !pSysData->hDC )
112 throw lang::NoSupportException(
113 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
114 "Passed SystemGraphicsData or HDC invalid!")),
115 NULL);
117 // setup helper
118 maDeviceHelper.init( pSysData->hDC,
119 *this );
120 maCanvasHelper.setDevice( *this );
121 maCanvasHelper.setTarget(
122 GraphicsProviderSharedPtr(
123 new GraphicsProviderImpl(
124 Gdiplus::Graphics::FromHDC(pSysData->hDC))));
126 maArguments.realloc(0);
129 void SAL_CALL Canvas::disposing()
131 ::osl::MutexGuard aGuard( m_aMutex );
133 mxComponentContext.clear();
135 // forward to parent
136 CanvasBaseT::disposing();
139 ::rtl::OUString SAL_CALL Canvas::getServiceName( ) throw (uno::RuntimeException)
141 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CANVAS_SERVICE_NAME ) );
144 BitmapCanvas::BitmapCanvas( const uno::Sequence< uno::Any >& aArguments,
145 const uno::Reference< uno::XComponentContext >& rxContext ) :
146 maArguments(aArguments),
147 mxComponentContext( rxContext ),
148 mpTarget()
152 void BitmapCanvas::initialize()
154 // #i64742# Only perform initialization when not in probe mode
155 if( maArguments.getLength() == 0 )
156 return;
158 VERBOSE_TRACE( "BitmapCanvas::initialize called" );
160 // At index 1, we expect a HWND handle here, containing a
161 // pointer to a valid window, on which to output
162 // At index 2, we expect the current window bound rect
163 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
164 maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
165 "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
167 uno::Sequence<sal_Int8> aSeq;
168 maArguments[5] >>= aSeq;
170 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
171 if( !pSysData || !pSysData->hDC )
172 throw lang::NoSupportException(
173 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
174 "Passed SystemGraphicsData or HDC invalid!")),
175 NULL);
177 // setup helper
178 maDeviceHelper.init( pSysData->hDC,
179 *this );
180 maCanvasHelper.setDevice( *this );
182 // check whether we can actually provide a BitmapCanvas
183 // here. for this, check whether the HDC has a bitmap
184 // selected.
185 HBITMAP hBmp;
186 hBmp=(HBITMAP)GetCurrentObject(pSysData->hDC, OBJ_BITMAP);
187 if( !hBmp || GetObjectType(pSysData->hDC) != OBJ_MEMDC )
189 throw lang::NoSupportException(
190 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
191 "Passed HDC is no mem DC/has no bitmap selected!")),
192 NULL);
195 mpTarget.reset( new DXBitmap(
196 BitmapSharedPtr(
197 Gdiplus::Bitmap::FromHBITMAP(
198 hBmp, 0) ),
199 false ));
201 maCanvasHelper.setTarget( mpTarget );
203 maArguments.realloc(0);
206 void SAL_CALL BitmapCanvas::disposing()
208 ::osl::MutexGuard aGuard( m_aMutex );
210 mpTarget.reset();
211 mxComponentContext.clear();
213 // forward to parent
214 BitmapCanvasBaseT::disposing();
217 ::rtl::OUString SAL_CALL BitmapCanvas::getServiceName( ) throw (uno::RuntimeException)
219 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( BITMAPCANVAS_SERVICE_NAME ) );
222 IBitmapSharedPtr BitmapCanvas::getBitmap() const
224 return mpTarget;
227 static uno::Reference<uno::XInterface> initCanvas( Canvas* pCanvas )
229 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
230 pCanvas->initialize();
231 return xRet;
234 namespace sdecl = comphelper::service_decl;
235 sdecl::class_<Canvas, sdecl::with_args<true> > serviceImpl1(&initCanvas);
236 const sdecl::ServiceDecl dxCanvasDecl(
237 serviceImpl1,
238 CANVAS_IMPLEMENTATION_NAME,
239 CANVAS_SERVICE_NAME );
241 static uno::Reference<uno::XInterface> initBitmapCanvas( BitmapCanvas* pCanvas )
243 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
244 pCanvas->initialize();
245 return xRet;
248 namespace sdecl = comphelper::service_decl;
249 sdecl::class_<BitmapCanvas, sdecl::with_args<true> > serviceImpl2(&initBitmapCanvas);
250 const sdecl::ServiceDecl dxBitmapCanvasDecl(
251 serviceImpl2,
252 BITMAPCANVAS_IMPLEMENTATION_NAME,
253 BITMAPCANVAS_SERVICE_NAME );
256 // The C shared lib entry points
257 COMPHELPER_SERVICEDECL_EXPORTS2(dxcanvas::dxCanvasDecl,
258 dxcanvas::dxBitmapCanvasDecl);