CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / directx / dx_winstuff.hxx
blobf4dc1fcd0496f93a0f47db2ac8db1b8dd46afb52
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _DXCANVAS_WINSTUFF_HXX
29 #define _DXCANVAS_WINSTUFF_HXX
31 #include <algorithm>
33 #include <boost/shared_ptr.hpp>
35 #include <basegfx/numeric/ftools.hxx>
37 #ifdef _WINDOWS_
38 #error someone else included <windows.h>
39 #endif
41 // Enabling Direct3D Debug Information Further more, with registry key
42 // \\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Direct3D\D3D9Debugging\\EnableCreationStack
43 // set to 1, sets a backtrace each time an object is created to the
44 // following global variable: LPCWSTR CreationCallStack
45 #if OSL_DEBUG_LEVEL > 0
46 # define D3D_DEBUG_INFO
47 #endif
49 #ifndef DIRECTX_VERSION
50 #error please define for which directx version we should compile
51 #endif
53 #if defined _MSC_VER
54 #pragma warning(push,1)
55 #endif
58 #define GradientStyle_RECT win32GradientStyle_RECT
59 #define Polygon win32Polygon
60 #define PolyPolygon win32PolyPolygon
61 #undef WB_LEFT
62 #undef WB_RIGHT
64 #define WIN32_LEAN_AND_MEAN
65 #include <windows.h> // TODO(Q1): extract minimal set of required headers for gdiplus
67 #if DIRECTX_VERSION < 0x0900
69 #include <multimon.h>
71 // Be compatible with directdraw 3.0. Lets see how far this takes us
72 #define DIRECTDRAW_VERSION 0x0300
73 #include <ddraw.h>
75 // Be compatible with direct3d 5.0. Lets see how far this takes us
76 #define DIRECT3D_VERSION 0x0500
77 #define D3D_OVERLOADS
78 #include <d3d.h>
80 typedef IDirectDrawSurface surface_type;
82 #else
84 #include <d3d9.h>
85 #include <d3dx9.h>
86 // #include <dxerr9.h> #i107614# removing include, it has been changed in the latest sdk fron August2009 from dxerr9.h into dxerr.h
88 typedef IDirect3DSurface9 surface_type;
90 #endif
92 #undef DrawText
94 #ifdef __MINGW32__
95 using ::std::max;
96 using ::std::min;
97 #endif
99 #include <gdiplus.h>
101 #ifdef min
102 # undef min
103 #endif
104 #ifdef max
105 # undef max
106 #endif
108 namespace dxcanvas
110 // some shared pointer typedefs to Gdiplus objects
111 typedef ::boost::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr;
112 typedef ::boost::shared_ptr< Gdiplus::GraphicsPath > GraphicsPathSharedPtr;
113 typedef ::boost::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr;
114 typedef ::boost::shared_ptr< Gdiplus::CachedBitmap > CachedBitmapSharedPtr;
115 typedef ::boost::shared_ptr< Gdiplus::Font > FontSharedPtr;
116 typedef ::boost::shared_ptr< Gdiplus::Brush > BrushSharedPtr;
117 typedef ::boost::shared_ptr< Gdiplus::TextureBrush > TextureBrushSharedPtr;
119 /** COM object RAII wrapper
121 This template wraps a Windows COM object, transparently
122 handling lifetime issues the C++ way (i.e. releasing the
123 reference when the object is destroyed)
125 template< typename T > class COMReference
127 public:
128 typedef T Wrappee;
130 COMReference() :
131 mp( NULL )
135 /** Create from raw pointer
137 @attention This constructor assumes the interface is
138 already acquired (unless p is NULL), no additional AddRef
139 is called here.
141 This caters e.g. for all DirectX factory methods, which
142 return the created interfaces pre-acquired, into a raw
143 pointer. Simply pass the pointer to this class, but don't
144 call Release manually on it!
146 @example IDirectDrawSurface* pSurface;
147 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL);
148 mpSurface = COMReference< IDirectDrawSurface >(pSurface);
151 explicit COMReference( T* p ) :
152 mp( p )
156 COMReference( const COMReference& rNew ) :
157 mp( NULL )
159 if( rNew.mp == NULL )
160 return;
162 rNew.mp->AddRef(); // do that _before_ assigning the
163 // pointer. Just in case...
164 mp = rNew.mp;
167 COMReference& operator=( const COMReference& rRHS )
169 COMReference aTmp(rRHS);
170 ::std::swap( mp, aTmp.mp );
172 return *this;
175 ~COMReference()
177 reset();
180 int reset()
182 int refcount = 0;
183 if( mp )
184 refcount = mp->Release();
186 mp = NULL;
187 return refcount;
190 bool is() const { return mp != NULL; }
191 T* get() const { return mp; }
192 T* operator->() const { return mp; }
193 T& operator*() const { return *mp; }
195 private:
196 T* mp;
199 // get_pointer() enables boost::mem_fn to recognize COMReference
200 template<class T> inline T * get_pointer(COMReference<T> const& p)
202 return p.get();
206 #if defined _MSC_VER
207 #pragma warning(pop)
208 #endif
210 #undef DELETE
211 #undef PolyPolygon
213 #endif /* _DXCANVAS_WINSTUFF_HXX */