|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qdnd_p.h" |
|
43 |
|
44 #if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD)) |
|
45 |
|
46 #if defined(Q_OS_WINCE) |
|
47 #include <shlobj.h> |
|
48 #include "qguifunctions_wince.h" |
|
49 #endif |
|
50 |
|
51 QT_BEGIN_NAMESPACE |
|
52 |
|
53 QOleEnumFmtEtc::QOleEnumFmtEtc(const QVector<FORMATETC> &fmtetcs) |
|
54 { |
|
55 m_isNull = false; |
|
56 m_dwRefs = 1; |
|
57 m_nIndex = 0; |
|
58 |
|
59 for (int idx = 0; idx < fmtetcs.count(); ++idx) { |
|
60 LPFORMATETC destetc = new FORMATETC(); |
|
61 if (copyFormatEtc(destetc, (LPFORMATETC)&(fmtetcs.at(idx)))) { |
|
62 m_lpfmtetcs.append(destetc); |
|
63 } else { |
|
64 m_isNull = true; |
|
65 delete destetc; |
|
66 break; |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 QOleEnumFmtEtc::QOleEnumFmtEtc(const QVector<LPFORMATETC> &lpfmtetcs) |
|
72 { |
|
73 m_isNull = false; |
|
74 m_dwRefs = 1; |
|
75 m_nIndex = 0; |
|
76 |
|
77 for (int idx = 0; idx < lpfmtetcs.count(); ++idx) { |
|
78 LPFORMATETC srcetc = lpfmtetcs.at(idx); |
|
79 LPFORMATETC destetc = new FORMATETC(); |
|
80 if (copyFormatEtc(destetc, srcetc)) { |
|
81 m_lpfmtetcs.append(destetc); |
|
82 } else { |
|
83 m_isNull = true; |
|
84 delete destetc; |
|
85 break; |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 QOleEnumFmtEtc::~QOleEnumFmtEtc() |
|
91 { |
|
92 LPMALLOC pmalloc; |
|
93 |
|
94 #if !defined(Q_OS_WINCE) |
|
95 if (CoGetMalloc(MEMCTX_TASK, &pmalloc) == NOERROR) { |
|
96 #else |
|
97 if (SHGetMalloc(&pmalloc) == NOERROR) { |
|
98 #endif |
|
99 for (int idx = 0; idx < m_lpfmtetcs.count(); ++idx) { |
|
100 LPFORMATETC tmpetc = m_lpfmtetcs.at(idx); |
|
101 if (tmpetc->ptd) |
|
102 pmalloc->Free(tmpetc->ptd); |
|
103 delete tmpetc; |
|
104 } |
|
105 |
|
106 pmalloc->Release(); |
|
107 } |
|
108 m_lpfmtetcs.clear(); |
|
109 } |
|
110 |
|
111 bool QOleEnumFmtEtc::isNull() const |
|
112 { |
|
113 return m_isNull; |
|
114 } |
|
115 |
|
116 // IUnknown methods |
|
117 STDMETHODIMP |
|
118 QOleEnumFmtEtc::QueryInterface(REFIID riid, void FAR* FAR* ppvObj) |
|
119 { |
|
120 if (riid == IID_IUnknown || riid == IID_IEnumFORMATETC) { |
|
121 *ppvObj = this; |
|
122 AddRef(); |
|
123 return NOERROR; |
|
124 } |
|
125 *ppvObj = NULL; |
|
126 return ResultFromScode(E_NOINTERFACE); |
|
127 } |
|
128 |
|
129 STDMETHODIMP_(ULONG) |
|
130 QOleEnumFmtEtc::AddRef(void) |
|
131 { |
|
132 return ++m_dwRefs; |
|
133 } |
|
134 |
|
135 STDMETHODIMP_(ULONG) |
|
136 QOleEnumFmtEtc::Release(void) |
|
137 { |
|
138 if (--m_dwRefs == 0) { |
|
139 delete this; |
|
140 return 0; |
|
141 } |
|
142 return m_dwRefs; |
|
143 } |
|
144 |
|
145 // IEnumFORMATETC methods |
|
146 STDMETHODIMP |
|
147 QOleEnumFmtEtc::Next(ULONG celt, LPFORMATETC rgelt, ULONG FAR* pceltFetched) |
|
148 { |
|
149 ULONG i=0; |
|
150 ULONG nOffset; |
|
151 |
|
152 if (rgelt == NULL) |
|
153 return ResultFromScode(E_INVALIDARG); |
|
154 |
|
155 while (i < celt) { |
|
156 nOffset = m_nIndex + i; |
|
157 |
|
158 if (nOffset < ULONG(m_lpfmtetcs.count())) { |
|
159 copyFormatEtc((LPFORMATETC)&(rgelt[i]), m_lpfmtetcs.at(nOffset)); |
|
160 i++; |
|
161 } else { |
|
162 break; |
|
163 } |
|
164 } |
|
165 |
|
166 m_nIndex += (WORD)i; |
|
167 |
|
168 if (pceltFetched != NULL) |
|
169 *pceltFetched = i; |
|
170 |
|
171 if (i != celt) |
|
172 return ResultFromScode(S_FALSE); |
|
173 |
|
174 return NOERROR; |
|
175 } |
|
176 |
|
177 STDMETHODIMP |
|
178 QOleEnumFmtEtc::Skip(ULONG celt) |
|
179 { |
|
180 ULONG i=0; |
|
181 ULONG nOffset; |
|
182 |
|
183 while (i < celt) { |
|
184 nOffset = m_nIndex + i; |
|
185 |
|
186 if (nOffset < ULONG(m_lpfmtetcs.count())) { |
|
187 i++; |
|
188 } else { |
|
189 break; |
|
190 } |
|
191 } |
|
192 |
|
193 m_nIndex += (WORD)i; |
|
194 |
|
195 if (i != celt) |
|
196 return ResultFromScode(S_FALSE); |
|
197 |
|
198 return NOERROR; |
|
199 } |
|
200 |
|
201 STDMETHODIMP |
|
202 QOleEnumFmtEtc::Reset() |
|
203 { |
|
204 m_nIndex = 0; |
|
205 return NOERROR; |
|
206 } |
|
207 |
|
208 STDMETHODIMP |
|
209 QOleEnumFmtEtc::Clone(LPENUMFORMATETC FAR* newEnum) |
|
210 { |
|
211 if (newEnum == NULL) |
|
212 return ResultFromScode(E_INVALIDARG); |
|
213 |
|
214 QOleEnumFmtEtc *result = new QOleEnumFmtEtc(m_lpfmtetcs); |
|
215 result->m_nIndex = m_nIndex; |
|
216 |
|
217 if (result->isNull()) { |
|
218 delete result; |
|
219 return ResultFromScode(E_OUTOFMEMORY); |
|
220 } else { |
|
221 *newEnum = result; |
|
222 } |
|
223 |
|
224 return NOERROR; |
|
225 } |
|
226 |
|
227 bool QOleEnumFmtEtc::copyFormatEtc(LPFORMATETC dest, LPFORMATETC src) const |
|
228 { |
|
229 if (dest == NULL || src == NULL) |
|
230 return false; |
|
231 |
|
232 *dest = *src; |
|
233 |
|
234 if (src->ptd) { |
|
235 LPVOID pout; |
|
236 LPMALLOC pmalloc; |
|
237 |
|
238 #if !defined(Q_OS_WINCE) |
|
239 if (CoGetMalloc(MEMCTX_TASK, &pmalloc) != NOERROR) |
|
240 #else |
|
241 if (SHGetMalloc(&pmalloc) != NOERROR) |
|
242 #endif |
|
243 return false; |
|
244 |
|
245 pout = (LPVOID)pmalloc->Alloc(src->ptd->tdSize); |
|
246 memcpy(dest->ptd, src->ptd, size_t(src->ptd->tdSize)); |
|
247 |
|
248 pmalloc->Release(); |
|
249 } |
|
250 |
|
251 return true; |
|
252 } |
|
253 |
|
254 QT_END_NAMESPACE |
|
255 #endif // QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD |