fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / canvas / source / directx / dx_winstuff.hxx
blobbed64145b5f9afc8b7bd29730b583789bb6a18e6
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 .
20 #ifndef _DXCANVAS_WINSTUFF_HXX
21 #define _DXCANVAS_WINSTUFF_HXX
23 #include <algorithm>
25 #include <boost/shared_ptr.hpp>
27 #include <basegfx/numeric/ftools.hxx>
29 #ifdef _WINDOWS_
30 #error someone else included <windows.h>
31 #endif
33 // Enabling Direct3D Debug Information Further more, with registry key
34 // \\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Direct3D\D3D9Debugging\\EnableCreationStack
35 // set to 1, sets a backtrace each time an object is created to the
36 // following global variable: LPCWSTR CreationCallStack
37 #if OSL_DEBUG_LEVEL > 0
38 # define D3D_DEBUG_INFO
39 #endif
41 #ifndef DIRECTX_VERSION
42 #error please define for which directx version we should compile
43 #endif
45 #if defined _MSC_VER
46 #pragma warning(push,1)
47 #endif
50 #define ULONG win32ULONG
51 #define GradientStyle_RECT win32GradientStyle_RECT
52 #define Polygon win32Polygon
53 #define PolyPolygon win32PolyPolygon
54 #undef WB_LEFT
55 #undef WB_RIGHT
57 #define WIN32_LEAN_AND_MEAN
58 #include <windows.h> // TODO(Q1): extract minimal set of required headers for gdiplus
60 #if DIRECTX_VERSION < 0x0900
62 #include <multimon.h>
64 // Be compatible with directdraw 3.0. Lets see how far this takes us
65 #define DIRECTDRAW_VERSION 0x0300
66 #include <ddraw.h>
68 // Be compatible with direct3d 5.0. Lets see how far this takes us
69 #define DIRECT3D_VERSION 0x0500
70 #define D3D_OVERLOADS
71 #include <d3d.h>
73 typedef IDirectDrawSurface surface_type;
75 #elif WIN8_SDK == 1 || defined(_USING_V110_SDK71_)
77 #include <d3d9.h>
79 typedef IDirect3DSurface9 surface_type;
81 #else
83 #include <dxsdkver.h>
84 #include <d3d9.h>
85 #include <d3dx9.h>
86 #if _DXSDK_BUILD_MAJOR < 1734 /* Earlier than the August 2009 DXSDK */
87 #include <dxerr9.h>
88 #else
89 #include <dxerr.h>
90 #endif
92 typedef IDirect3DSurface9 surface_type;
94 #endif
96 #undef DrawText
98 #ifdef __MINGW32__
99 using ::std::max;
100 using ::std::min;
101 #endif
103 #include <gdiplus.h>
105 #ifdef min
106 # undef min
107 #endif
108 #ifdef max
109 # undef max
110 #endif
112 namespace dxcanvas
114 // some shared pointer typedefs to Gdiplus objects
115 typedef ::boost::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr;
116 typedef ::boost::shared_ptr< Gdiplus::GraphicsPath > GraphicsPathSharedPtr;
117 typedef ::boost::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr;
118 typedef ::boost::shared_ptr< Gdiplus::CachedBitmap > CachedBitmapSharedPtr;
119 typedef ::boost::shared_ptr< Gdiplus::Font > FontSharedPtr;
120 typedef ::boost::shared_ptr< Gdiplus::Brush > BrushSharedPtr;
121 typedef ::boost::shared_ptr< Gdiplus::TextureBrush > TextureBrushSharedPtr;
123 /** COM object RAII wrapper
125 This template wraps a Windows COM object, transparently
126 handling lifetime issues the C++ way (i.e. releasing the
127 reference when the object is destroyed)
129 template< typename T > class COMReference
131 public:
132 typedef T Wrappee;
134 COMReference() :
135 mp( NULL )
139 /** Create from raw pointer
141 @attention This constructor assumes the interface is
142 already acquired (unless p is NULL), no additional AddRef
143 is called here.
145 This caters e.g. for all DirectX factory methods, which
146 return the created interfaces pre-acquired, into a raw
147 pointer. Simply pass the pointer to this class, but don't
148 call Release manually on it!
150 @example IDirectDrawSurface* pSurface;
151 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
152 mpSurface = COMReference< IDirectDrawSurface >(pSurface);
155 explicit COMReference( T* p ) :
156 mp( p )
160 COMReference( const COMReference& rNew ) :
161 mp( NULL )
163 if( rNew.mp == NULL )
164 return;
166 rNew.mp->AddRef(); // do that _before_ assigning the
167 // pointer. Just in case...
168 mp = rNew.mp;
171 COMReference& operator=( const COMReference& rRHS )
173 COMReference aTmp(rRHS);
174 ::std::swap( mp, aTmp.mp );
176 return *this;
179 ~COMReference()
181 reset();
184 int reset()
186 int refcount = 0;
187 if( mp )
188 refcount = mp->Release();
190 mp = NULL;
191 return refcount;
194 bool is() const { return mp != NULL; }
195 T* get() const { return mp; }
196 T* operator->() const { return mp; }
197 T& operator*() const { return *mp; }
199 private:
200 T* mp;
203 // get_pointer() enables boost::mem_fn to recognize COMReference
204 template<class T> inline T * get_pointer(COMReference<T> const& p)
206 return p.get();
210 #if defined _MSC_VER
211 #pragma warning(pop)
212 #endif
214 #undef DELETE
215 #undef PolyPolygon
217 #endif /* _DXCANVAS_WINSTUFF_HXX */
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */