Repository navigation
Expand file tree
/
Copy pathCOleDropTarget_Ext.cpp
More file actions
446 lines (384 loc) · 13 KB
/
Copy pathCOleDropTarget_Ext.cpp
File metadata and controls
446 lines (384 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
// Copyright © 2022, 2026 Ivyware Pty Ltd, Khrustal & Mann
// MELBOURNE, VICTORIA, AUSTRALIA, 3000
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//
// Base class for VideomsGroupView tile implementation and management
// NOTES: Intention is all contained tiles be derived from this object.
//
//
#include "stdafx.h"
//#include "ServerMain.h"
#include "COleDropTarget_Ext.h"
#include "CString_Ext.h"
#include "Kernel32_Ext.h"
#include "Msgexception.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
BOOL TargetcoreMFC_EXT
COleDropTarget_Wildcard ( COleDataObject *pDataObject, LPCTSTR lpszWildcard )
{
CString strWildcard = lpszWildcard;
BOOL bResult = FALSE;
// (Implemented by VargaG., on 2020.02.17.)
//m_droppedFilePathNames.RemoveAll();
// (Implemented by VargaG., on 2020.02.17.)
CLIPFORMAT clipFormat = CF_HDROP;
HGLOBAL shGlobalDropFiles = pDataObject->GetGlobalData(clipFormat);
// (Implemented by VargaG., on 2020.02.18.)
if (shGlobalDropFiles != NULL)
{
// (Implemented by VargaG., on 2020.02.17.)
try
{
// (Implemented by VargaG., on 2020.02.17.)
LPDROPFILES pDropFiles = (LPDROPFILES)::GlobalLock(shGlobalDropFiles);
if (pDropFiles == NULL)
{
// (Implemented by VargaG., on 2020.02.17.)
ASSERT(FALSE);
return FALSE;
}
// (Implemented by VargaG., on 2020.02.17.)
if (pDropFiles->fWide)
{
// (Implemented by VargaG., on 2020.02.17.)
bool bAdditionalFileNameExistst = true;
// (Implemented by VargaG., on 2020.02.17.)
PWCHAR pDroppedFilePathAndName = (PWCHAR)((PCHAR)pDropFiles + pDropFiles->pFiles);
do
{
// (Implemented by VargaG., on 2020.02.17.)
CString strDroppedFilename = pDroppedFilePathAndName;
if ( CString_Wildcard(strDroppedFilename,strWildcard,TRUE) )
bResult = TRUE;
//m_droppedFilePathNames.Add(pDroppedFilePathAndName);
// Get the number of characters in the string, not including the terminating null character.
// (Implemented by VargaG., on 2020.02.17.)
size_t nDroppedFilePathAndNameLengthWithoutTerminatingNullCharacter = wcsnlen_s(pDroppedFilePathAndName, MAX_PATH);
// (Implemented by VargaG., on 2020.02.17.)
pDroppedFilePathAndName = pDroppedFilePathAndName + nDroppedFilePathAndNameLengthWithoutTerminatingNullCharacter + 1;
// (Implemented by VargaG., on 2020.02.17.)
bAdditionalFileNameExistst = (*pDroppedFilePathAndName != L'\x0');
}
while (bAdditionalFileNameExistst);
}
else
{
// (Implemented by VargaG., on 2020.02.17.)
TRACE("ANSI characters are not supported, only Unicode characters!");
ASSERT(FALSE);
}
return bResult;
}
catch(...)
{
// (Implemented by VargaG., on 2020.02.17.)
BOOL bGlobalUnlockResult = ::GlobalUnlock(shGlobalDropFiles);
DWORD dwLastError = GetLastError();
if ((bGlobalUnlockResult == FALSE) && (dwLastError != NO_ERROR))
{
// (Implemented by VargaG., on 2020.02.17.)
ASSERT(FALSE);
return FALSE;
}
}
}
// (Implemented by VargaG., on 2020.02.18.)
return bResult;
}
///////////////////////////////////////////////////////////////////////
// COleDataObject extension
//
// Constructors & destructor
COleDataObjectEx::COleDataObjectEx ( COleDataObject *pDataObject ) noexcept
{
m_pDataObject = pDataObject;
}
COleDataObjectEx::~COleDataObjectEx ( ) noexcept
{
if ( m_hDropFiles )
::GlobalUnlock ( m_hDropFiles );
}
// Operations
POSITION
COleDataObjectEx::EnumerateFiles ( LPCTSTR lpszWildcard )
{
m_strWildcard = lpszWildcard;
m_oCListDropFiles.RemoveAll();
// Preamble, expect issues
try
{
const CLIPFORMAT clipFormat = CF_HDROP;
if ( !m_hDropFiles )
m_hDropFiles = m_pDataObject->GetGlobalData(clipFormat);
if ( !m_hDropFiles )
EVERR->MODULE
->Message( L"GetGlobalData() failed" )
->HResult( 0 )
->Throw();
// Initialse search
LPDROPFILES pDropFiles = (LPDROPFILES)::GlobalLock(m_hDropFiles);
if ( pDropFiles == NULL )
return 0;
// Observe character type
if ( !pDropFiles->fWide )
EVERR->MODULE
->Message( L"ANSI characters are not supported, only Unicode" )
->Throw();
// (Implemented by VargaG., on 2020.02.17.)
//bool bAdditionalFileNameExistst = true;
// Parse out files
PWCHAR pDroppedFilePathAndName = (PWCHAR)((PCHAR)pDropFiles + pDropFiles->pFiles);
while ( *pDroppedFilePathAndName )
{
// Confirm against wildcard
CString strDroppedFilename = pDroppedFilePathAndName;
if ( CString_Wildcard(strDroppedFilename,m_strWildcard,TRUE) )
m_oCListDropFiles.AddTail ( strDroppedFilename );
// Move forward
pDroppedFilePathAndName += (strDroppedFilename.GetLength() + 1);
}
// Tidy up, and
return m_oCListDropFiles.GetHeadPosition();
}
// Exceptions
catch_pP2Pevent_Cancel
catch_pCException_Cancel
catch_ALL_Cancel
// Tidy up, and
return 0;
}
LPCTSTR
COleDataObjectEx::GetNextFile ( POSITION& pos )
{
if ( !pos || m_oCListDropFiles.IsEmpty() ) {
pos = 0;
return L"\0";
}
return (LPCTSTR)m_oCListDropFiles.GetNext(pos);
}
//
// Summarises number of encapsulated files matching the wildcard
//
// Parameters: LPCTSTR lpszWildcard
// Matching wildcard
//
// Returns: BOOL
// Number of matching files
BOOL
COleDataObjectEx::Wildcard ( LPCTSTR lpszWildcard )
{
EnumerateFiles(lpszWildcard);
return m_oCListDropFiles.GetCount() ? TRUE : FALSE;
}
/*extern*/ UINT g_uCustomClipbrdFormat;
///////////////////////////////////////
// Constructor and destructor
COleDropTargetEx::COleDropTargetEx()
{
m_DropMsg = NULL;
}
COleDropTargetEx::~COleDropTargetEx()
{
}
///////////////////////////////////////
// Operations
// Register client callbacks
// NOTES: If not defined simply fall through to the base class,
// which in turn delegates through to the CView etc
//
// Parameters: DWORD_PTR dwUser
// User defined data common to all callbacks
//
// OnDragEnterCB pFncOnDragEnterCB
// OnDragEnter() function callback
void
COleDropTargetEx::RegisterCallbacks ( DWORD_PTR dwUser
, fpntOnDragEnter pnfOnDragEnterCB
, fpntOnDragOver pnfOnDragOverCB
, fpntOnDrop pnfOnDropCB )
{
m_fpntOnDragEnterCB = pnfOnDragEnterCB;
m_fpntOnDragOverCB = pnfOnDragOverCB;
m_fpntOnDropCB = pnfOnDropCB;
m_dwUser = dwUser;
}
///////////////////////////////////////
// MFC virtual overrides
// NOTES: All simply delegate back to parent if defined
DROPEFFECT
COleDropTargetEx::OnDragEnter ( CWnd *pCWnd, COleDataObject *pDataObject
, DWORD dwKeyState, CPoint point )
{
// Simply delegate according to settings
if ( m_fpntOnDragEnterCB == nullptr )
return __super::OnDragEnter ( pCWnd, pDataObject, dwKeyState, point );
return (*m_fpntOnDragEnterCB)(m_dwUser, pDataObject, dwKeyState, point);
}
DROPEFFECT
COleDropTargetEx::OnDragOver ( CWnd* pCWnd, COleDataObject *pDataObject
, DWORD dwKeyState, CPoint point )
{
// Simply delegate according to settings
if ( m_fpntOnDragOverCB == nullptr )
return __super::OnDragOver ( pCWnd, pDataObject, dwKeyState, point );
return (*m_fpntOnDragOverCB)(m_dwUser, pDataObject, dwKeyState, point);
}
BOOL
COleDropTargetEx::OnDrop ( CWnd* pCWnd, COleDataObject* pDataObject
, DROPEFFECT dropEffect, CPoint point )
{
// Simply delegate according to settings
if ( m_fpntOnDragOverCB == nullptr )
return __super::OnDrop ( pCWnd, pDataObject, dropEffect, point );
return (*m_fpntOnDropCB)( pDataObject, dropEffect, point);
}
void
COleDropTargetEx::OnDragLeave ( CWnd* )
{
}
/////////////////////////////////////////////////////////////////////////////
/*COleDropTargetEx1::COleDropTargetEx1()
{
}
COleDropTargetEx1::~COleDropTargetEx1()
{
}
// (Implemented by VargaG., on 2020.02.17.)
BOOL
COleDropTargetEx1::IsFilePathNameListIsDragged(COleDataObject* a_pDataObject)
{
// (Implemented by VargaG., on 2020.02.17.)
m_droppedFilePathNames.RemoveAll();
// (Implemented by VargaG., on 2020.02.17.)
CLIPFORMAT clipFormat = CF_HDROP;
HGLOBAL shGlobalDropFiles = a_pDataObject->GetGlobalData(clipFormat);
// (Implemented by VargaG., on 2020.02.18.)
if (shGlobalDropFiles != NULL)
{
// (Implemented by VargaG., on 2020.02.17.)
try
{
// (Implemented by VargaG., on 2020.02.17.)
LPDROPFILES pDropFiles = (LPDROPFILES)::GlobalLock(shGlobalDropFiles);
if (pDropFiles == NULL)
{
// (Implemented by VargaG., on 2020.02.17.)
ASSERT(FALSE);
return FALSE;
}
// (Implemented by VargaG., on 2020.02.17.)
if (pDropFiles->fWide)
{
// (Implemented by VargaG., on 2020.02.17.)
bool bAdditionalFileNameExistst = true;
// (Implemented by VargaG., on 2020.02.17.)
PWCHAR pDroppedFilePathAndName = (PWCHAR)((PCHAR)pDropFiles + pDropFiles->pFiles);
do
{
// (Implemented by VargaG., on 2020.02.17.)
m_droppedFilePathNames.Add(pDroppedFilePathAndName);
// Get the number of characters in the string, not including the terminating null character.
// (Implemented by VargaG., on 2020.02.17.)
size_t nDroppedFilePathAndNameLengthWithoutTerminatingNullCharacter = wcsnlen_s(pDroppedFilePathAndName, MAX_PATH);
// (Implemented by VargaG., on 2020.02.17.)
pDroppedFilePathAndName = pDroppedFilePathAndName + nDroppedFilePathAndNameLengthWithoutTerminatingNullCharacter + 1;
// (Implemented by VargaG., on 2020.02.17.)
bAdditionalFileNameExistst = (*pDroppedFilePathAndName != L'\x0');
}
while (bAdditionalFileNameExistst);
}
else
{
// (Implemented by VargaG., on 2020.02.17.)
TRACE("ANSI characters are not supported, only Unicode characters!");
ASSERT(FALSE);
}
return TRUE;
}
catch(...)
{
// (Implemented by VargaG., on 2020.02.17.)
BOOL bGlobalUnlockResult = ::GlobalUnlock(shGlobalDropFiles);
DWORD dwLastError = GetLastError();
if ((bGlobalUnlockResult == FALSE) && (dwLastError != NO_ERROR))
{
// (Implemented by VargaG., on 2020.02.17.)
ASSERT(FALSE);
return FALSE;
}
}
}
// (Implemented by VargaG., on 2020.02.18.)
return FALSE;
}
// (Implemented by VargaG., on 2020.02.13.)
DROPEFFECT
COleDropTargetEx1::OnDragEnter ( CWnd *a_pWnd, COleDataObject *a_pDataObject
, DWORD a_dwKeyState, CPoint a_point )
{
UNREFERENCED_PARAMETER(a_point);
DROPEFFECT dropEffect = DROPEFFECT_NONE;
// (Implemented by VargaG., on 2020.02.17.)
if (IsFilePathNameListIsDragged(a_pDataObject))
{
// (Implemented by VargaG., on 2020.02.17.)
dropEffect = DROPEFFECT_COPY;
}
//Tidy up, and
return dropEffect;
}
// (Implemented by VargaG., on 2020.02.17.)
DROPEFFECT COleDropTargetEx1::OnDragOver(CWnd* a_pWnd, COleDataObject* a_pDataObject, DWORD a_dwKeyState, CPoint a_point)
{
// (Implemented by VargaG., on 2020.02.17.)
DROPEFFECT dropEffect = DROPEFFECT_NONE;
// (Implemented by VargaG., on 2020.02.17.)
if (IsFilePathNameListIsDragged(a_pDataObject))
{
// (Implemented by VargaG., on 2020.02.17.)
dropEffect = DROPEFFECT_COPY;
}
// (Implemented by VargaG., on 2020.02.17.)
return dropEffect;
}
// (Implemented by VargaG., on 2020.02.13.)
BOOL COleDropTargetEx1::OnDrop(CWnd* a_pWnd, COleDataObject* a_pDataObject, DROPEFFECT a_dropEffect, CPoint a_point)
{
// (Implemented by VargaG., on 2020.02.17.)
BOOL bDropAllowed = IsFilePathNameListIsDragged(a_pDataObject);
// (Implemented by VargaG., on 2020.02.17.)
if (bDropAllowed)
{
// (Implemented by VargaG., on 2020.02.17.)
TRACE("Number of files have been dropped: %d.\n", m_droppedFilePathNames.GetCount());
// (Implemented by VargaG., on 2020.02.17.)
for (int nDroppedFileDataIndex = 0; nDroppedFileDataIndex < m_droppedFilePathNames.GetCount(); nDroppedFileDataIndex++)
{
// (Implemented by VargaG., on 2020.02.17.)
CString stringFileDataIndexed = m_droppedFilePathNames.GetAt(nDroppedFileDataIndex);
TRACE(
_T("Dropped file path and name (%d of %d): %s.\n"),
nDroppedFileDataIndex + 1,
m_droppedFilePathNames.GetCount(),
stringFileDataIndexed
);
}
}
return bDropAllowed;
}*/