fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / win32 / dtobj / DTransHelper.cxx
blob46b1086fe18d18674a9c4e7af80d408fc7113f8c
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 #include <rtl/ustring.h>
21 #include <osl/diagnose.h>
22 #include "DTransHelper.hxx"
24 // implementation
26 CStgTransferHelper::CStgTransferHelper( sal_Bool bAutoInit,
27 HGLOBAL hGlob,
28 sal_Bool bDelStgOnRelease ) :
29 m_lpStream( NULL ),
30 m_bDelStgOnRelease( bDelStgOnRelease )
32 if ( bAutoInit )
33 init( hGlob, m_bDelStgOnRelease );
36 // dtor
38 CStgTransferHelper::~CStgTransferHelper( )
40 if ( m_lpStream )
41 m_lpStream->Release( );
44 // TransferData into the
46 void SAL_CALL CStgTransferHelper::write( const void* lpData, ULONG cb, ULONG* cbWritten )
48 HRESULT hr = E_FAIL;
50 if ( m_lpStream )
51 hr = m_lpStream->Write( lpData, cb, cbWritten );
53 if ( FAILED( hr ) )
54 throw CStgTransferException( hr );
56 #if OSL_DEBUG_LEVEL > 0
57 HGLOBAL hGlob;
58 hr = GetHGlobalFromStream( m_lpStream, &hGlob );
59 OSL_ASSERT( SUCCEEDED( hr ) );
61 /*DWORD dwSize =*/ GlobalSize( hGlob );
62 /*LPVOID lpdbgData =*/ GlobalLock( hGlob );
63 GlobalUnlock( hGlob );
64 #endif
67 // read
69 void SAL_CALL CStgTransferHelper::read( LPVOID pv, ULONG cb, ULONG* pcbRead )
71 HRESULT hr = E_FAIL;
73 if ( m_lpStream )
74 hr = m_lpStream->Read( pv, cb , pcbRead );
76 if ( FAILED( hr ) )
77 throw CStgTransferException( hr );
80 // GetHGlobal
82 HGLOBAL SAL_CALL CStgTransferHelper::getHGlobal( ) const
84 OSL_ASSERT( m_lpStream );
86 HGLOBAL hGlob = NULL;
88 if ( m_lpStream )
90 HRESULT hr = GetHGlobalFromStream( m_lpStream, &hGlob );
91 if ( FAILED( hr ) )
92 hGlob = NULL;
95 return hGlob;
98 // getIStream
100 void SAL_CALL CStgTransferHelper::getIStream( LPSTREAM* ppStream )
102 OSL_ASSERT( ppStream );
103 *ppStream = m_lpStream;
104 if ( *ppStream )
105 static_cast< LPUNKNOWN >( *ppStream )->AddRef( );
108 // Init
110 void SAL_CALL CStgTransferHelper::init( SIZE_T newSize,
111 sal_uInt32 uiFlags,
112 sal_Bool bDelStgOnRelease )
114 cleanup( );
116 m_bDelStgOnRelease = bDelStgOnRelease;
118 HGLOBAL hGlob = GlobalAlloc( uiFlags, newSize );
119 if ( NULL == hGlob )
120 throw CStgTransferException( STG_E_MEDIUMFULL );
122 HRESULT hr = CreateStreamOnHGlobal( hGlob, m_bDelStgOnRelease, &m_lpStream );
123 if ( FAILED( hr ) )
125 GlobalFree( hGlob );
126 m_lpStream = NULL;
127 throw CStgTransferException( hr );
130 #if OSL_DEBUG_LEVEL > 0
131 STATSTG statstg;
132 hr = m_lpStream->Stat( &statstg, STATFLAG_DEFAULT );
133 OSL_ASSERT( SUCCEEDED( hr ) );
134 #endif
137 // Init
139 void SAL_CALL CStgTransferHelper::init( HGLOBAL hGlob,
140 sal_Bool bDelStgOnRelease )
142 cleanup( );
144 m_bDelStgOnRelease = bDelStgOnRelease;
146 HRESULT hr = CreateStreamOnHGlobal( hGlob, m_bDelStgOnRelease, &m_lpStream );
147 if ( FAILED( hr ) )
148 throw CStgTransferException( hr );
151 // free the global memory and invalidate the stream pointer
153 void SAL_CALL CStgTransferHelper::cleanup( )
155 if ( m_lpStream && !m_bDelStgOnRelease )
157 HGLOBAL hGlob;
158 GetHGlobalFromStream( m_lpStream, &hGlob );
159 GlobalFree( hGlob );
162 if ( m_lpStream )
164 m_lpStream->Release( );
165 m_lpStream = NULL;
169 // return the size of memory we point to
171 sal_uInt32 SAL_CALL CStgTransferHelper::memSize( CLIPFORMAT cf ) const
173 DWORD dwSize = 0;
175 if ( NULL != m_lpStream )
177 HGLOBAL hGlob;
178 GetHGlobalFromStream( m_lpStream, &hGlob );
180 if ( CF_TEXT == cf || RegisterClipboardFormat( "HTML Format" ) == cf )
182 sal_Char* pText = static_cast< sal_Char* >( GlobalLock( hGlob ) );
183 if ( pText )
185 dwSize = strlen(pText) + 1; // strlen + trailing '\0'
186 GlobalUnlock( hGlob );
189 else if ( CF_UNICODETEXT == cf )
191 sal_Unicode* pText = static_cast< sal_Unicode* >( GlobalLock( hGlob ) );
192 if ( pText )
194 dwSize = rtl_ustr_getLength( pText ) * sizeof( sal_Unicode );
195 GlobalUnlock( hGlob );
198 else
199 dwSize = GlobalSize( hGlob );
202 return dwSize;
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */