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
33 #include <boost/shared_ptr.hpp>
35 #include <basegfx/numeric/ftools.hxx>
38 #error someone else included <windows.h>
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
49 #ifndef DIRECTX_VERSION
50 #error please define for which directx version we should compile
54 #pragma warning(push,1)
58 #define GradientStyle_RECT win32GradientStyle_RECT
59 #define Polygon win32Polygon
60 #define PolyPolygon win32PolyPolygon
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
71 // Be compatible with directdraw 3.0. Lets see how far this takes us
72 #define DIRECTDRAW_VERSION 0x0300
75 // Be compatible with direct3d 5.0. Lets see how far this takes us
76 #define DIRECT3D_VERSION 0x0500
80 typedef IDirectDrawSurface surface_type
;
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
;
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
135 /** Create from raw pointer
137 @attention This constructor assumes the interface is
138 already acquired (unless p is NULL), no additional AddRef
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
) :
156 COMReference( const COMReference
& rNew
) :
159 if( rNew
.mp
== NULL
)
162 rNew
.mp
->AddRef(); // do that _before_ assigning the
163 // pointer. Just in case...
167 COMReference
& operator=( const COMReference
& rRHS
)
169 COMReference
aTmp(rRHS
);
170 ::std::swap( mp
, aTmp
.mp
);
184 refcount
= mp
->Release();
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
; }
199 // get_pointer() enables boost::mem_fn to recognize COMReference
200 template<class T
> inline T
* get_pointer(COMReference
<T
> const& p
)
213 #endif /* _DXCANVAS_WINSTUFF_HXX */