fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / win32 / dtobj / DTransHelper.hxx
blob7754ec302c20f2538dab54650007ff2449277e97
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 INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_DTRANSHELPER_HXX
21 #define INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_DTRANSHELPER_HXX
23 #if defined _MSC_VER
24 #pragma warning(push,1)
25 #endif
26 #include <windows.h>
27 #if defined _MSC_VER
28 #pragma warning(pop)
29 #endif
30 #include "../misc/WinClip.hxx"
32 #define AUTO_INIT TRUE
34 // a helper class to manage a global memory area, the clients can write
35 // into the global memory area and extract the handle to the global mem
36 // note: not thread-safe
38 class CStgTransferHelper
40 public:
41 // will be thrown in case of failures
42 class CStgTransferException
44 public:
45 HRESULT m_hr;
46 CStgTransferException( HRESULT hr ) : m_hr( hr ) {};
49 public:
50 CStgTransferHelper(
51 sal_Bool bAutoInit = sal_False,
52 HGLOBAL hGlob = NULL,
53 sal_Bool bDelStgOnRelease = sal_False );
55 ~CStgTransferHelper( );
57 void SAL_CALL write( const void* lpData, ULONG cb, ULONG* cbWritten = NULL );
58 void SAL_CALL read( LPVOID pv, ULONG cb, ULONG* pcbRead = NULL );
60 HGLOBAL SAL_CALL getHGlobal( ) const;
61 void SAL_CALL getIStream( LPSTREAM* ppStream );
63 void SAL_CALL init(
64 SIZE_T newSize,
65 sal_uInt32 uiFlags = GHND,
66 sal_Bool bDelStgOnRelease = sal_False );
68 void SAL_CALL init(
69 HGLOBAL hGlob,
70 sal_Bool bDelStgOnRelease = sal_False );
72 // returns the size of the managed memory
73 sal_uInt32 SAL_CALL memSize( CLIPFORMAT cf = CF_INVALID ) const;
75 // free the global memory and necessary
76 // release the internal stream pointer
77 void SAL_CALL cleanup( );
79 private:
80 LPSTREAM m_lpStream;
81 sal_Bool m_bDelStgOnRelease;
83 private:
84 CStgTransferHelper( const CStgTransferHelper& );
85 CStgTransferHelper& operator=( const CStgTransferHelper& );
88 // something like an auto-pointer - allows access to the memory belonging
89 // to a HGLOBAL and automatically unlocks a global memory at destruction
90 // time
92 class CRawHGlobalPtr
94 public:
96 // ctor
98 CRawHGlobalPtr( HGLOBAL hGlob ) :
99 m_hGlob( hGlob ),
100 m_bIsLocked( FALSE ),
101 m_pGlobMem( NULL )
105 // ctor
107 CRawHGlobalPtr( const CStgTransferHelper& theHGlobalHelper ) :
108 m_hGlob( theHGlobalHelper.getHGlobal( ) ),
109 m_bIsLocked( FALSE ),
110 m_pGlobMem( NULL )
114 // dtor
116 ~CRawHGlobalPtr( )
118 if ( m_bIsLocked )
119 GlobalUnlock( m_hGlob );
122 // lock the global memory (initializes a
123 // pointer to this memory)
125 BOOL Lock( )
127 if ( !m_bIsLocked && ( NULL != m_hGlob ) )
129 m_pGlobMem = GlobalLock( m_hGlob );
130 m_bIsLocked = ( NULL != m_pGlobMem );
133 return m_bIsLocked;
136 // unlock the global memory (invalidates the
137 // pointer to this memory)
139 BOOL Unlock( )
141 GlobalUnlock( m_hGlob );
142 m_bIsLocked = FALSE;
143 m_pGlobMem = NULL;
145 return ( NO_ERROR == GetLastError( ) );
148 // locks the global memory and returns a
149 // pointer to this memory
151 LPVOID GetMemPtr( )
153 Lock( );
154 return m_pGlobMem;
157 // size of mem we point to
159 int MemSize( ) const
161 return GlobalSize( m_hGlob );
164 private:
165 HGLOBAL m_hGlob;
166 BOOL m_bIsLocked;
167 LPVOID m_pGlobMem;
170 #endif
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */