xref: /aoo41x/main/dtrans/source/win32/dtobj/Fetc.cxx (revision cdf0e10c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dtrans.hxx"
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 #include <osl/diagnose.h>
35 #include "Fetc.hxx"
36 #include "..\misc\ImplHelper.hxx"
37 
38 //------------------------------------------------------------------------
39 //
40 //------------------------------------------------------------------------
41 
42 CFormatEtc::CFormatEtc(  )
43 {
44 	m_FormatEtc.cfFormat = 0;
45 	m_FormatEtc.ptd      = NULL;
46 	m_FormatEtc.dwAspect = 0;
47 	m_FormatEtc.lindex   = -1;
48 	m_FormatEtc.tymed    = TYMED_NULL;
49 }
50 
51 //------------------------------------------------------------------------
52 // transfer of ownership
53 //------------------------------------------------------------------------
54 
55 CFormatEtc::CFormatEtc( const FORMATETC& aFormatEtc )
56 {
57 	CopyFormatEtc( &m_FormatEtc, &const_cast< FORMATETC& >( aFormatEtc ) );
58 }
59 
60 //------------------------------------------------------------------------
61 //
62 //------------------------------------------------------------------------
63 
64 CFormatEtc::~CFormatEtc( )
65 {
66 	DeleteTargetDevice( m_FormatEtc.ptd );
67 }
68 
69 //------------------------------------------------------------------------
70 //
71 //------------------------------------------------------------------------
72 
73 CFormatEtc::CFormatEtc( CLIPFORMAT cf, DWORD tymed, DVTARGETDEVICE* ptd, DWORD dwAspect, LONG lindex )
74 {
75 	m_FormatEtc.cfFormat = cf;
76 	m_FormatEtc.ptd      = CopyTargetDevice( ptd );
77 	m_FormatEtc.dwAspect = dwAspect;
78 	m_FormatEtc.lindex   = lindex;
79 	m_FormatEtc.tymed    = tymed;
80 }
81 
82 //------------------------------------------------------------------------
83 //
84 //------------------------------------------------------------------------
85 
86 CFormatEtc::CFormatEtc( const CFormatEtc& theOther )
87 {
88 	m_FormatEtc.cfFormat = theOther.m_FormatEtc.cfFormat;
89 	m_FormatEtc.ptd      = CopyTargetDevice( theOther.m_FormatEtc.ptd );
90 	m_FormatEtc.dwAspect = theOther.m_FormatEtc.dwAspect;
91 	m_FormatEtc.lindex   = theOther.m_FormatEtc.lindex;
92 	m_FormatEtc.tymed    = theOther.m_FormatEtc.tymed;
93 }
94 
95 //------------------------------------------------------------------------
96 //
97 //------------------------------------------------------------------------
98 
99 CFormatEtc& CFormatEtc::operator=( const CFormatEtc& theOther )
100 {
101 	if ( this != &theOther )
102 	{
103 		DeleteTargetDevice( m_FormatEtc.ptd );
104 
105 		m_FormatEtc.cfFormat = theOther.m_FormatEtc.cfFormat;
106 		m_FormatEtc.ptd      = CopyTargetDevice( theOther.m_FormatEtc.ptd );
107 		m_FormatEtc.dwAspect = theOther.m_FormatEtc.dwAspect;
108 		m_FormatEtc.lindex   = theOther.m_FormatEtc.lindex;
109 		m_FormatEtc.tymed    = theOther.m_FormatEtc.tymed;
110 	}
111 
112 	return *this;
113 }
114 
115 //------------------------------------------------------------------------
116 //
117 //------------------------------------------------------------------------
118 
119 CFormatEtc::operator FORMATETC*( )
120 {
121 	return &m_FormatEtc;
122 }
123 
124 //------------------------------------------------------------------------
125 //
126 //------------------------------------------------------------------------
127 
128 CFormatEtc::operator FORMATETC( )
129 {
130 	return m_FormatEtc;
131 }
132 
133 //------------------------------------------------------------------------
134 //
135 //------------------------------------------------------------------------
136 
137 void CFormatEtc::getFORMATETC( LPFORMATETC lpFormatEtc )
138 {
139 	OSL_ASSERT( lpFormatEtc );
140 	OSL_ASSERT( !IsBadWritePtr( lpFormatEtc, sizeof( FORMATETC ) ) );
141 
142 	CopyFormatEtc( lpFormatEtc, &m_FormatEtc );
143 }
144 
145 //------------------------------------------------------------------------
146 //
147 //------------------------------------------------------------------------
148 
149 CLIPFORMAT CFormatEtc::getClipformat( ) const
150 {
151 	return m_FormatEtc.cfFormat;
152 }
153 
154 //------------------------------------------------------------------------
155 //
156 //------------------------------------------------------------------------
157 
158 DWORD CFormatEtc::getTymed( ) const
159 {
160 	return m_FormatEtc.tymed;
161 }
162 
163 //------------------------------------------------------------------------
164 //
165 //------------------------------------------------------------------------
166 
167 void CFormatEtc::getTargetDevice( DVTARGETDEVICE** lpDvTargetDevice ) const
168 {
169 	OSL_ASSERT( lpDvTargetDevice );
170 	OSL_ASSERT( !IsBadWritePtr( lpDvTargetDevice, sizeof( DVTARGETDEVICE ) ) );
171 
172 	*lpDvTargetDevice = NULL;
173 
174 	if ( m_FormatEtc.ptd )
175 		*lpDvTargetDevice = CopyTargetDevice( m_FormatEtc.ptd );
176 }
177 
178 //------------------------------------------------------------------------
179 //
180 //------------------------------------------------------------------------
181 
182 DWORD CFormatEtc::getDvAspect( ) const
183 {
184 	return m_FormatEtc.dwAspect;
185 }
186 
187 //------------------------------------------------------------------------
188 //
189 //------------------------------------------------------------------------
190 
191 LONG CFormatEtc::getLindex( ) const
192 {
193 	return m_FormatEtc.lindex;
194 }
195 
196 //------------------------------------------------------------------------
197 //
198 //------------------------------------------------------------------------
199 
200 void CFormatEtc::setClipformat( CLIPFORMAT cf )
201 {
202 	m_FormatEtc.cfFormat = cf;
203 }
204 
205 //------------------------------------------------------------------------
206 //
207 //------------------------------------------------------------------------
208 
209 void CFormatEtc::setTymed( DWORD tymed )
210 {
211 	m_FormatEtc.tymed = tymed;
212 }
213 
214 //------------------------------------------------------------------------
215 // transfer of ownership!
216 //------------------------------------------------------------------------
217 
218 void CFormatEtc::setTargetDevice( DVTARGETDEVICE* ptd )
219 {
220 	DeleteTargetDevice( m_FormatEtc.ptd );
221 	m_FormatEtc.ptd = ptd;
222 }
223 
224 //------------------------------------------------------------------------
225 //
226 //------------------------------------------------------------------------
227 
228 void CFormatEtc::setDvAspect( DWORD dwAspect )
229 {
230 	m_FormatEtc.dwAspect = dwAspect;
231 }
232 
233 //------------------------------------------------------------------------
234 //
235 //------------------------------------------------------------------------
236 
237 void CFormatEtc::setLindex( LONG lindex )
238 {
239 	m_FormatEtc.lindex = lindex;
240 }
241 
242 //------------------------------------------------------------------------
243 //
244 //------------------------------------------------------------------------
245 
246 sal_Int32 operator==( const CFormatEtc& lhs, const CFormatEtc& rhs )
247 {
248 	return CompareFormatEtc( &lhs.m_FormatEtc, &rhs.m_FormatEtc );
249 }
250 
251 //------------------------------------------------------------------------
252 //
253 //------------------------------------------------------------------------
254 
255 sal_Int32 operator!=( const CFormatEtc& lhs, const CFormatEtc& rhs )
256 {
257 	return ( ( lhs == rhs ) != 1 );
258 }
259 
260