1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 #ifndef _DXCANVAS_WINSTUFF_HXX 29 #define _DXCANVAS_WINSTUFF_HXX 30 31 #include <algorithm> 32 33 #include <boost/shared_ptr.hpp> 34 35 #include <basegfx/numeric/ftools.hxx> 36 37 #ifdef _WINDOWS_ 38 #error someone else included <windows.h> 39 #endif 40 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 48 49 #ifndef DIRECTX_VERSION 50 #error please define for which directx version we should compile 51 #endif 52 53 #if defined _MSC_VER 54 #pragma warning(push,1) 55 #endif 56 57 58 #define GradientStyle_RECT win32GradientStyle_RECT 59 #define Polygon win32Polygon 60 #define PolyPolygon win32PolyPolygon 61 #undef WB_LEFT 62 #undef WB_RIGHT 63 64 #define WIN32_LEAN_AND_MEAN 65 #include <windows.h> // TODO(Q1): extract minimal set of required headers for gdiplus 66 67 #if DIRECTX_VERSION < 0x0900 68 69 #include <multimon.h> 70 71 // Be compatible with directdraw 3.0. Lets see how far this takes us 72 #define DIRECTDRAW_VERSION 0x0300 73 #include <ddraw.h> 74 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> 79 80 typedef IDirectDrawSurface surface_type; 81 82 #else 83 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 87 88 typedef IDirect3DSurface9 surface_type; 89 90 #endif 91 92 #undef DrawText 93 94 #ifdef __MINGW32__ 95 using ::std::max; 96 using ::std::min; 97 #endif 98 99 #include <gdiplus.h> 100 101 #ifdef min 102 # undef min 103 #endif 104 #ifdef max 105 # undef max 106 #endif 107 108 namespace dxcanvas 109 { 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; 118 119 /** COM object RAII wrapper 120 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) 124 */ 125 template< typename T > class COMReference 126 { 127 public: 128 typedef T Wrappee; 129 130 COMReference() : 131 mp( NULL ) 132 { 133 } 134 135 /** Create from raw pointer 136 137 @attention This constructor assumes the interface is 138 already acquired (unless p is NULL), no additional AddRef 139 is called here. 140 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! 145 146 @example IDirectDrawSurface* pSurface; 147 pDD->CreateSurface(&aSurfaceDesc, &pSurface, NULL); 148 mpSurface = COMReference< IDirectDrawSurface >(pSurface); 149 150 */ 151 explicit COMReference( T* p ) : 152 mp( p ) 153 { 154 } 155 156 COMReference( const COMReference& rNew ) : 157 mp( NULL ) 158 { 159 if( rNew.mp == NULL ) 160 return; 161 162 rNew.mp->AddRef(); // do that _before_ assigning the 163 // pointer. Just in case... 164 mp = rNew.mp; 165 } 166 167 COMReference& operator=( const COMReference& rRHS ) 168 { 169 COMReference aTmp(rRHS); 170 ::std::swap( mp, aTmp.mp ); 171 172 return *this; 173 } 174 175 ~COMReference() 176 { 177 reset(); 178 } 179 180 int reset() 181 { 182 int refcount = 0; 183 if( mp ) 184 refcount = mp->Release(); 185 186 mp = NULL; 187 return refcount; 188 } 189 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; } 194 195 private: 196 T* mp; 197 }; 198 199 // get_pointer() enables boost::mem_fn to recognize COMReference 200 template<class T> inline T * get_pointer(COMReference<T> const& p) 201 { 202 return p.get(); 203 } 204 } 205 206 #if defined _MSC_VER 207 #pragma warning(pop) 208 #endif 209 210 #undef DELETE 211 #undef PolyPolygon 212 213 #endif /* _DXCANVAS_WINSTUFF_HXX */ 214