1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <osl/diagnose.h>
21 #include "Fetc.hxx"
22 #include "ImplHelper.hxx"
23
CFormatEtc()24 CFormatEtc::CFormatEtc( )
25 {
26 m_FormatEtc.cfFormat = 0;
27 m_FormatEtc.ptd = nullptr;
28 m_FormatEtc.dwAspect = 0;
29 m_FormatEtc.lindex = -1;
30 m_FormatEtc.tymed = TYMED_NULL;
31 }
32
33 // transfer of ownership
34
CFormatEtc(const FORMATETC & aFormatEtc)35 CFormatEtc::CFormatEtc( const FORMATETC& aFormatEtc )
36 {
37 CopyFormatEtc( &m_FormatEtc, &const_cast< FORMATETC& >( aFormatEtc ) );
38 }
39
~CFormatEtc()40 CFormatEtc::~CFormatEtc( )
41 {
42 DeleteTargetDevice( m_FormatEtc.ptd );
43 }
44
CFormatEtc(CLIPFORMAT cf,DWORD tymed,DVTARGETDEVICE * ptd,DWORD dwAspect,LONG lindex)45 CFormatEtc::CFormatEtc( CLIPFORMAT cf, DWORD tymed, DVTARGETDEVICE* ptd, DWORD dwAspect, LONG lindex )
46 {
47 m_FormatEtc.cfFormat = cf;
48 m_FormatEtc.ptd = CopyTargetDevice( ptd );
49 m_FormatEtc.dwAspect = dwAspect;
50 m_FormatEtc.lindex = lindex;
51 m_FormatEtc.tymed = tymed;
52 }
53
CFormatEtc(const CFormatEtc & theOther)54 CFormatEtc::CFormatEtc( const CFormatEtc& theOther )
55 {
56 m_FormatEtc.cfFormat = theOther.m_FormatEtc.cfFormat;
57 m_FormatEtc.ptd = CopyTargetDevice( theOther.m_FormatEtc.ptd );
58 m_FormatEtc.dwAspect = theOther.m_FormatEtc.dwAspect;
59 m_FormatEtc.lindex = theOther.m_FormatEtc.lindex;
60 m_FormatEtc.tymed = theOther.m_FormatEtc.tymed;
61 }
62
operator =(const CFormatEtc & theOther)63 CFormatEtc& CFormatEtc::operator=( const CFormatEtc& theOther )
64 {
65 if ( this != &theOther )
66 {
67 DeleteTargetDevice( m_FormatEtc.ptd );
68
69 m_FormatEtc.cfFormat = theOther.m_FormatEtc.cfFormat;
70 m_FormatEtc.ptd = CopyTargetDevice( theOther.m_FormatEtc.ptd );
71 m_FormatEtc.dwAspect = theOther.m_FormatEtc.dwAspect;
72 m_FormatEtc.lindex = theOther.m_FormatEtc.lindex;
73 m_FormatEtc.tymed = theOther.m_FormatEtc.tymed;
74 }
75
76 return *this;
77 }
78
operator FORMATETC*()79 CFormatEtc::operator FORMATETC*( )
80 {
81 return &m_FormatEtc;
82 }
83
operator FORMATETC()84 CFormatEtc::operator FORMATETC( )
85 {
86 return m_FormatEtc;
87 }
88
getFORMATETC(LPFORMATETC lpFormatEtc)89 void CFormatEtc::getFORMATETC( LPFORMATETC lpFormatEtc )
90 {
91 OSL_ASSERT( lpFormatEtc );
92 OSL_ASSERT( !IsBadWritePtr( lpFormatEtc, sizeof( FORMATETC ) ) );
93
94 CopyFormatEtc( lpFormatEtc, &m_FormatEtc );
95 }
96
getClipformat() const97 CLIPFORMAT CFormatEtc::getClipformat( ) const
98 {
99 return m_FormatEtc.cfFormat;
100 }
101
getTymed() const102 DWORD CFormatEtc::getTymed( ) const
103 {
104 return m_FormatEtc.tymed;
105 }
106
getTargetDevice(DVTARGETDEVICE ** lpDvTargetDevice) const107 void CFormatEtc::getTargetDevice( DVTARGETDEVICE** lpDvTargetDevice ) const
108 {
109 OSL_ASSERT( lpDvTargetDevice );
110 OSL_ASSERT( !IsBadWritePtr( lpDvTargetDevice, sizeof( DVTARGETDEVICE ) ) );
111
112 *lpDvTargetDevice = nullptr;
113
114 if ( m_FormatEtc.ptd )
115 *lpDvTargetDevice = CopyTargetDevice( m_FormatEtc.ptd );
116 }
117
getDvAspect() const118 DWORD CFormatEtc::getDvAspect( ) const
119 {
120 return m_FormatEtc.dwAspect;
121 }
122
getLindex() const123 LONG CFormatEtc::getLindex( ) const
124 {
125 return m_FormatEtc.lindex;
126 }
127
setClipformat(CLIPFORMAT cf)128 void CFormatEtc::setClipformat( CLIPFORMAT cf )
129 {
130 m_FormatEtc.cfFormat = cf;
131 }
132
setTymed(DWORD tymed)133 void CFormatEtc::setTymed( DWORD tymed )
134 {
135 m_FormatEtc.tymed = tymed;
136 }
137
138 // transfer of ownership!
139
setTargetDevice(DVTARGETDEVICE * ptd)140 void CFormatEtc::setTargetDevice( DVTARGETDEVICE* ptd )
141 {
142 DeleteTargetDevice( m_FormatEtc.ptd );
143 m_FormatEtc.ptd = ptd;
144 }
145
setDvAspect(DWORD dwAspect)146 void CFormatEtc::setDvAspect( DWORD dwAspect )
147 {
148 m_FormatEtc.dwAspect = dwAspect;
149 }
150
setLindex(LONG lindex)151 void CFormatEtc::setLindex( LONG lindex )
152 {
153 m_FormatEtc.lindex = lindex;
154 }
155
operator ==(const CFormatEtc & lhs,const CFormatEtc & rhs)156 bool operator==( const CFormatEtc& lhs, const CFormatEtc& rhs )
157 {
158 return CompareFormatEtc( &lhs.m_FormatEtc, &rhs.m_FormatEtc );
159 }
160
operator !=(const CFormatEtc & lhs,const CFormatEtc & rhs)161 bool operator!=( const CFormatEtc& lhs, const CFormatEtc& rhs )
162 {
163 return !( lhs == rhs );
164 }
165
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
167