fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / canvas / source / directx / dx_canvas.cxx
blob5a256e9bb3dd586d252207421c510b7084614adc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <ctype.h> // don't ask. msdev breaks otherwise...
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <canvas/canvastools.hxx>
25 #include <tools/diagnose_ex.h>
27 #include <osl/mutex.hxx>
29 #include <com/sun/star/awt/XWindow.hpp>
30 #include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
31 #include <com/sun/star/registry/XRegistryKey.hpp>
32 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/lang/NoSupportException.hpp>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <cppuhelper/factory.hxx>
38 #include <cppuhelper/implementationentry.hxx>
39 #include <comphelper/servicedecl.hxx>
41 #include <basegfx/matrix/b2dhommatrix.hxx>
42 #include <basegfx/point/b2dpoint.hxx>
43 #include <basegfx/tools/canvastools.hxx>
44 #include <basegfx/numeric/ftools.hxx>
46 #include "dx_graphicsprovider.hxx"
47 #include "dx_winstuff.hxx"
48 #include "dx_canvas.hxx"
50 #include <vcl/sysdata.hxx>
52 #define CANVAS_TECH "GDI+"
53 #define CANVAS_SERVICE_NAME "com.sun.star.rendering.Canvas." CANVAS_TECH
54 #define CANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.Canvas." CANVAS_TECH
55 #define BITMAPCANVAS_SERVICE_NAME "com.sun.star.rendering.BitmapCanvas." CANVAS_TECH
56 #define BITMAPCANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.BitmapCanvas." CANVAS_TECH
59 using namespace ::com::sun::star;
61 namespace dxcanvas
63 /// Actual canonical implementation of the GraphicsProvider interface
64 class GraphicsProviderImpl : public GraphicsProvider
66 GraphicsSharedPtr mpGraphics;
67 public:
68 explicit GraphicsProviderImpl( Gdiplus::Graphics* pGraphics ) : mpGraphics( pGraphics ) {}
69 virtual GraphicsSharedPtr getGraphics() { return mpGraphics; }
72 Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
73 const uno::Reference< uno::XComponentContext >& rxContext ) :
74 maArguments(aArguments),
75 mxComponentContext( rxContext )
79 void Canvas::initialize()
81 // #i64742# Only perform initialization when not in probe mode
82 if( maArguments.getLength() == 0 )
83 return;
85 VERBOSE_TRACE( "Canvas::initialize called" );
87 // At index 1, we expect a HWND handle here, containing a
88 // pointer to a valid window, on which to output
89 // At index 2, we expect the current window bound rect
90 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
91 maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
92 "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
94 uno::Sequence<sal_Int8> aSeq;
95 maArguments[5] >>= aSeq;
97 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
98 if( !pSysData || !pSysData->hDC )
99 throw lang::NoSupportException("Passed SystemGraphicsData or HDC invalid!", NULL);
101 // setup helper
102 maDeviceHelper.init( pSysData->hDC,
103 *this );
104 maCanvasHelper.setDevice( *this );
105 maCanvasHelper.setTarget(
106 GraphicsProviderSharedPtr(
107 new GraphicsProviderImpl(
108 Gdiplus::Graphics::FromHDC(pSysData->hDC))));
110 maArguments.realloc(0);
113 void Canvas::disposeThis()
115 ::osl::MutexGuard aGuard( m_aMutex );
117 mxComponentContext.clear();
119 // forward to parent
120 CanvasBaseT::disposeThis();
123 OUString SAL_CALL Canvas::getServiceName( ) throw (uno::RuntimeException)
125 return OUString( CANVAS_SERVICE_NAME );
128 BitmapCanvas::BitmapCanvas( const uno::Sequence< uno::Any >& aArguments,
129 const uno::Reference< uno::XComponentContext >& rxContext ) :
130 maArguments(aArguments),
131 mxComponentContext( rxContext ),
132 mpTarget()
136 void BitmapCanvas::initialize()
138 // #i64742# Only perform initialization when not in probe mode
139 if( maArguments.getLength() == 0 )
140 return;
142 VERBOSE_TRACE( "BitmapCanvas::initialize called" );
144 // At index 1, we expect a HWND handle here, containing a
145 // pointer to a valid window, on which to output
146 // At index 2, we expect the current window bound rect
147 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 6 &&
148 maArguments[5].getValueTypeClass() == uno::TypeClass_SEQUENCE,
149 "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
151 uno::Sequence<sal_Int8> aSeq;
152 maArguments[5] >>= aSeq;
154 const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
155 if( !pSysData || !pSysData->hDC )
156 throw lang::NoSupportException( "Passed SystemGraphicsData or HDC invalid!", NULL);
158 // setup helper
159 maDeviceHelper.init( pSysData->hDC,
160 *this );
161 maCanvasHelper.setDevice( *this );
163 // check whether we can actually provide a BitmapCanvas
164 // here. for this, check whether the HDC has a bitmap
165 // selected.
166 HBITMAP hBmp;
167 hBmp=(HBITMAP)GetCurrentObject(pSysData->hDC, OBJ_BITMAP);
168 if( !hBmp || GetObjectType(pSysData->hDC) != OBJ_MEMDC )
170 throw lang::NoSupportException( "Passed HDC is no mem DC/has no bitmap selected!", NULL);
173 mpTarget.reset( new DXBitmap(
174 BitmapSharedPtr(
175 Gdiplus::Bitmap::FromHBITMAP(
176 hBmp, 0) ),
177 false ));
179 maCanvasHelper.setTarget( mpTarget );
181 maArguments.realloc(0);
184 void BitmapCanvas::disposeThis()
186 ::osl::MutexGuard aGuard( m_aMutex );
188 mpTarget.reset();
189 mxComponentContext.clear();
191 // forward to parent
192 BitmapCanvasBaseT::disposeThis();
195 OUString SAL_CALL BitmapCanvas::getServiceName( ) throw (uno::RuntimeException)
197 return OUString( BITMAPCANVAS_SERVICE_NAME );
200 IBitmapSharedPtr BitmapCanvas::getBitmap() const
202 return mpTarget;
205 static uno::Reference<uno::XInterface> initCanvas( Canvas* pCanvas )
207 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
208 pCanvas->initialize();
209 return xRet;
212 namespace sdecl = comphelper::service_decl;
213 sdecl::class_<Canvas, sdecl::with_args<true> > serviceImpl1(&initCanvas);
214 const sdecl::ServiceDecl dxCanvasDecl(
215 serviceImpl1,
216 CANVAS_IMPLEMENTATION_NAME,
217 CANVAS_SERVICE_NAME );
219 static uno::Reference<uno::XInterface> initBitmapCanvas( BitmapCanvas* pCanvas )
221 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
222 pCanvas->initialize();
223 return xRet;
226 namespace sdecl = comphelper::service_decl;
227 sdecl::class_<BitmapCanvas, sdecl::with_args<true> > serviceImpl2(&initBitmapCanvas);
228 const sdecl::ServiceDecl dxBitmapCanvasDecl(
229 serviceImpl2,
230 BITMAPCANVAS_IMPLEMENTATION_NAME,
231 BITMAPCANVAS_SERVICE_NAME );
234 // The C shared lib entry points
235 COMPHELPER_SERVICEDECL_EXPORTS2(gdipluscanvas,
236 dxcanvas::dxCanvasDecl,
237 dxcanvas::dxBitmapCanvasDecl)
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */