summaryrefslogblamecommitdiffstats
path: root/private/oleutest/simpdnd/idt.cpp
blob: db83df09aa3c3ee104acd4dba2cd3e26db769f25 (plain) (tree)
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851


















































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                   
//**********************************************************************
// File name: IDT.CPP
//
//      Implementation file for CDropTarget
//
// Functions:
//
//      See IDT.H for class definition
//
// Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
//**********************************************************************

#include "pre.h"
#include "iocs.h"
#include "ias.h"
#include "app.h"
#include "site.h"
#include "doc.h"
#include "idt.h"

extern CLIPFORMAT g_cfObjectDescriptor;


//**********************************************************************
//
// CDropTarget::QueryDrop
//
// Purpose:
//
//      Check if the desired drop operation (identified by the given key
//      state) is possible at the current mouse position (pointl).
//
// Parameters:
//
//      DWORD grfKeyState       - current key state
//      POINTL pointl           - position of mouse
//      BOOL fDragScroll        - TRUE if drag scrolling cursor should
//                                be shown.
//      LPDWORD pdwEffect       - (OUT) drag effect that should occur
//
// Return Value:
//
//      BOOL                    - TRUE if drop could take place,
//                                else FALSE
//
// Function Calls:
//      Function                    Location
//
//      OleStdGetDropEffect         OLE2UI API
//
//
//********************************************************************

BOOL CDropTarget::QueryDrop (
    DWORD           grfKeyState,
    POINTL          pointl,
    BOOL            fDragScroll,
    LPDWORD         pdwEffect
)
{
    DWORD      dwScrollEffect = 0L;
    DWORD      dwOKEffects = m_pDoc->m_lpApp->m_dwTargetEffect & *pdwEffect;

    /* check if the cursor is in the active scroll area, if so need the
    **    special scroll cursor.
    */
    if (fDragScroll)
        dwScrollEffect = DROPEFFECT_SCROLL;

    /* if we have already determined that the source does NOT have any
    **    acceptable data for us, the return NO-DROP
    */
    if (! m_fCanDropCopy && ! m_fCanDropLink)
        goto dropeffect_none;

    /* OLE2NOTE: determine what type of drop should be performed given
    **    the current modifier key state. we rely on the standard
    **    interpretation of the modifier keys:
    **          no modifier -- DROPEFFECT_MOVE or whatever is allowed by src
    **          SHIFT       -- DROPEFFECT_MOVE
    **          CTRL        -- DROPEFFECT_COPY
    **          CTRL-SHIFT  -- DROPEFFECT_LINK
    */

    *pdwEffect = OleStdGetDropEffect(grfKeyState);
    if (*pdwEffect == 0)
    {
        // No modifier keys given. Try in order MOVE, COPY, LINK.
        if ((DROPEFFECT_MOVE & dwOKEffects) && m_fCanDropCopy)
            *pdwEffect = DROPEFFECT_MOVE;
        else if ((DROPEFFECT_COPY & dwOKEffects) && m_fCanDropCopy)
            *pdwEffect = DROPEFFECT_COPY;
        else if ((DROPEFFECT_LINK & dwOKEffects) && m_fCanDropLink)
            *pdwEffect = DROPEFFECT_LINK;
        else
            goto dropeffect_none;
    }
    else
    {
        /* OLE2NOTE: we should check if the drag source application allows
        **    the desired drop effect.
        */
        if (!(*pdwEffect & dwOKEffects))
            goto dropeffect_none;

        if ((*pdwEffect == DROPEFFECT_COPY || *pdwEffect == DROPEFFECT_MOVE)
                && ! m_fCanDropCopy)
            goto dropeffect_none;

        if (*pdwEffect == DROPEFFECT_LINK && ! m_fCanDropLink)
            goto dropeffect_none;
    }

    *pdwEffect |= dwScrollEffect;
    return TRUE;

dropeffect_none:

    *pdwEffect = DROPEFFECT_NONE;
    return FALSE;
}


//**********************************************************************
//
// CDropTarget::QueryDrop
//
// Purpose:
//
//     Check to see if Drag scroll operation should be initiated.
//
// Parameters:
//
//      POINTL pointl           - position of mouse
//
// Return Value:
//
//      BOOL                    - TRUE if scroll cursor should be given
//                                else FALSE
//
// Function Calls:
//      Function                    Location
//
//      ScreenToClient              WINDOWS API
//      GetClientRect               WINDOWS API
//
// Comments:
//     A Drag scroll operation should be initiated when the mouse has
//     remained in the active scroll area (11 pixels frame around border
//     of window) for a specified amount of time (50ms).
//
//********************************************************************

BOOL CDropTarget::DoDragScroll (POINTL pointl)
{
    DWORD dwScrollDir = SCROLLDIR_NULL;
    DWORD dwTime = GetCurrentTime();
    int nScrollInset = m_pDoc->m_lpApp->m_nScrollInset;
    int nScrollDelay = m_pDoc->m_lpApp->m_nScrollDelay;
    int nScrollInterval = m_pDoc->m_lpApp->m_nScrollInterval;
    POINT point;
    RECT rect;

    point.x = (int)pointl.x;
    point.y = (int)pointl.y;

    ScreenToClient( m_pDoc->m_hDocWnd, &point);
    GetClientRect ( m_pDoc->m_hDocWnd, (LPRECT) &rect );

    if (rect.top <= point.y && point.y<=(rect.top+nScrollInset))
        dwScrollDir = SCROLLDIR_UP;
    else if ((rect.bottom-nScrollInset) <= point.y && point.y <= rect.bottom)
        dwScrollDir = SCROLLDIR_DOWN;
    else if (rect.left <= point.x && point.x <= (rect.left+nScrollInset))
        dwScrollDir = SCROLLDIR_LEFT;
    else if ((rect.right-nScrollInset) <= point.x && point.x <= rect.right)
        dwScrollDir = SCROLLDIR_RIGHT;

    if (m_dwTimeEnterScrollArea)
    {
        /* cursor was already in Scroll Area */

        if (! dwScrollDir)
        {
            /* cusor moved OUT of scroll area.
            **      clear "EnterScrollArea" time.
            */
            m_dwTimeEnterScrollArea = 0L;
            m_dwNextScrollTime = 0L;
            m_dwLastScrollDir = SCROLLDIR_NULL;

        }
        else
           if (dwScrollDir != m_dwLastScrollDir)
           {
            /* cusor moved into a different direction scroll area.
            **      reset "EnterScrollArea" time to start a new 50ms delay.
            */
            m_dwTimeEnterScrollArea = dwTime;
            m_dwNextScrollTime = dwTime + (DWORD)nScrollDelay;
            m_dwLastScrollDir = dwScrollDir;

           }
           else
              if (dwTime && dwTime >= m_dwNextScrollTime)
              {
                 m_pDoc->Scroll ( dwScrollDir );    // Scroll document now
                 m_dwNextScrollTime = dwTime + (DWORD)nScrollInterval;
              }
    }
    else
    {
        if (dwScrollDir)
        {
            /* cusor moved INTO a scroll area.
            **   reset "EnterScrollArea" time to start a new 50ms delay.
            */
            m_dwTimeEnterScrollArea = dwTime;
            m_dwNextScrollTime = dwTime + (DWORD)nScrollDelay;
            m_dwLastScrollDir = dwScrollDir;
        }
    }

    return (dwScrollDir ? TRUE : FALSE);
}


// Support functions/macros
#define SetTopLeft(rc, pt)		\
	((rc)->top = (pt)->y,(rc)->left = (pt)->x)
#define SetBottomRight(rc, pt)		\
	((rc)->bottom = (pt)->y,(rc)->right = (pt)->x)
#define OffsetPoint(pt, dx, dy)		\
	((pt)->x += dx, (pt)->y += dy)


/* HighlightRect
** -------------
**    Invert rectangle on screen. used for drop target feedback.
*/

static int HighlightRect(HWND hwnd, HDC hdc, LPRECT rc)
{
    POINT pt1, pt2;
    int old = SetROP2(hdc, R2_NOT);
    HPEN hpen;
    HGDIOBJ hold;

    pt1.x = rc->left;
    pt1.y = rc->top;
    pt2.x = rc->right;
    pt2.y = rc->bottom;

    ScreenToClient(hwnd, &pt1);
    ScreenToClient(hwnd, &pt2);

    hold = SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
    hpen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 2,
                          GetSysColor(COLOR_ACTIVEBORDER)));

    Rectangle(hdc, pt1.x, pt1.y, pt2.x, pt2.y);

    SetROP2(hdc, old);

    hold = SelectObject(hdc, hold);
    hpen = (HPEN) SelectObject(hdc, hpen);

    DeleteObject(hpen);

  return 0;
}


//**********************************************************************
//
// CDropTarget::InitDragFeedback
//
// Purpose:
//
//      Initialize data used to draw drop target feedback.
//      As feedback we draw a rectangle the size of the object.
//
// Parameters:
//
//      LPDATAOBJECT pDataObj   - IDataObject from Drop source
//      POINTL pointl           - position of mouse
//
// Return Value:
//
//      none.
//
// Function Calls:
//      Function                    Location
//
//      IDataObject::GetData        Object
//      XformSizeInHimetricToPixels OLE2UI Library
//      GlobalLock                  WINDOWS API
//      GlobalUnlock                WINDOWS API
//      ReleaseStgMedium            OLE2 API
//      OffsetPoint                 IDT.CPP
//      SetTopLeft                  IDT.CPP
//      SetBottomRight              IDT.CPP
//
// Comments:
//      In order to know the size of the object before the object
//      is actually dropped, we render CF_OBJECTDESCRIPTOR format.
//      this data format tells us both the size of the object as
//      well as which aspect is the object is displayed as in the
//      source. If the object is currently displayed as DVASPECT_ICON
//      then we want to create the object also as DVASPECT_ICON.
//
//********************************************************************

void CDropTarget::InitDragFeedback(LPDATAOBJECT pDataObj, POINTL pointl)
{
    FORMATETC fmtetc;
    STGMEDIUM stgmed;
    POINT pt;
    int height, width;
    HRESULT hrErr;

    height = width = 100; // some default values
    pt.x = (int)pointl.x;
    pt.y = (int)pointl.y;

    // do a GetData for CF_OBJECTDESCRIPTOR format to get the size of the
    // object as displayed in the source. using this size, initialize the
    // size for the drag feedback rectangle.
    fmtetc.cfFormat = g_cfObjectDescriptor;
    fmtetc.ptd = NULL;
    fmtetc.lindex = -1;
    fmtetc.dwAspect = DVASPECT_CONTENT;
    fmtetc.tymed = TYMED_HGLOBAL;

    hrErr = pDataObj->GetData(&fmtetc, &stgmed);
    if (hrErr == NOERROR)
    {
        LPOBJECTDESCRIPTOR pOD=(LPOBJECTDESCRIPTOR)GlobalLock(stgmed.hGlobal);
        if (pOD != NULL)
        {
            XformSizeInHimetricToPixels(NULL, &pOD->sizel, &pOD->sizel);

            width = (int)pOD->sizel.cx;
            height = (int)pOD->sizel.cy;
            m_dwSrcAspect = pOD->dwDrawAspect;
        }

        GlobalUnlock(stgmed.hGlobal);
        ReleaseStgMedium(&stgmed);
    }

    m_ptLast = pt;
    m_fDragFeedbackDrawn = FALSE;
	
    OffsetPoint(&pt, -(width/2), -(height/2));
    SetTopLeft(&m_rcDragRect, &pt);

    OffsetPoint(&pt, width, height);
    SetBottomRight(&m_rcDragRect, &pt);
}


//**********************************************************************
//
// CDropTarget::UndrawDragFeedback
//
// Purpose:
//
//      Erase any drop target feedback.
//      As feedback we draw a rectangle the size of the object.
//
// Parameters:
//
//      none.
//
// Return Value:
//
//      none.
//
// Function Calls:
//      Function                    Location
//
//      GetDC                       WINDOWS API
//      ReleaseDC                   WINDOWS API
//      HighlightRect               IDT.CPP
//
// Comments:
//      In order to know the size of the object before the object
//      is actually dropped, we render CF_OBJECTDESCRIPTOR format.
//      this data format tells us both the size of the object as
//      well as which aspect is the object is displayed as in the
//      source. if the object is currently displayed as DVASPECT_ICON
//      then we want to create the object also as DVASPECT_ICON.
//
//********************************************************************

void CDropTarget::UndrawDragFeedback( void )
{
    if (m_fDragFeedbackDrawn)
    {
        m_fDragFeedbackDrawn = FALSE;
        HDC hDC = GetDC(m_pDoc->m_hDocWnd);
        HighlightRect(m_pDoc->m_hDocWnd, hDC, &m_rcDragRect);
        ReleaseDC(m_pDoc->m_hDocWnd, hDC);
    }
}


//**********************************************************************
//
// CDropTarget::DrawDragFeedback
//
// Purpose:
//
//      Compute new position of drop target feedback rectangle and
//      erase old rectangle and draw new rectangle.
//      As feedback we draw a rectangle the size of the object.
//
// Parameters:
//
//      POINTL pointl           - position of mouse
//
// Return Value:
//
//      none.
//
// Function Calls:
//      Function                    Location
//
//      OffsetPoint                 IDT.CPP
//      OffsetRect                  IDT.CPP
//      HighlightRect               IDT.CPP
//      GetDC                       WINDOWS API
//      ReleaseDC                   WINDOWS API
//
//
//********************************************************************

void CDropTarget::DrawDragFeedback( POINTL pointl )
{
    POINT ptDiff;

    ptDiff.x = (int)pointl.x - m_ptLast.x;
    ptDiff.y = (int)pointl.y - m_ptLast.y;

    if (m_fDragFeedbackDrawn && (ptDiff.x == 0 && ptDiff.y == 0))
        return;     // mouse did not move; leave rectangle as drawn

    HDC hDC = GetDC(m_pDoc->m_hDocWnd);
    if (m_fDragFeedbackDrawn)
    {
        m_fDragFeedbackDrawn = FALSE;
        HighlightRect(m_pDoc->m_hDocWnd, hDC, &m_rcDragRect);
    }

    OffsetRect(&m_rcDragRect, ptDiff.x, ptDiff.y);
    HighlightRect(m_pDoc->m_hDocWnd, hDC, &m_rcDragRect);
    m_fDragFeedbackDrawn = TRUE;
	 m_ptLast.x = (int)pointl.x;
    m_ptLast.y = (int)pointl.y;
	 ReleaseDC(m_pDoc->m_hDocWnd, hDC);
}


//**********************************************************************
//
// CDropTarget::QueryInterface
//
// Purpose:
//
//      Used for interface negotiation
//
// Parameters:
//
//      REFIID riid         -   ID of interface to be returned
//      LPVOID FAR* ppvObj  -   Location to return the interface
//
// Return Value:
//
//      S_OK                -   Interface supported
//      E_NOINTERFACE       -   Interface NOT supported
//
// Function Calls:
//      Function                    Location
//
//      TestDebugOut           Windows API
//      CSimpleDoc::QueryInterface  DOC.CPP
//
//
//********************************************************************

STDMETHODIMP CDropTarget::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
{
    TestDebugOut("In IDT::QueryInterface\r\n");

    // delegate to the document
    return m_pDoc->QueryInterface(riid, ppvObj);
}


//**********************************************************************
//
// CDropTarget::AddRef
//
// Purpose:
//
//      Increments the reference count of CSimpleDoc. Since CDropTarget is
//      a nested class of CSimpleDoc, we don't need a separate reference
//      count for CDropTarget. We can safely use the reference count of
//      CSimpleDoc.
//
// Parameters:
//
//      None
//
// Return Value:
//
//      The new reference count of CSimpleDoc
//
// Function Calls:
//      Function                    Location
//
//      CSimpleDoc::AddReff         DOC.CPP
//      TestDebugOut           Windows API
//
//
//********************************************************************

STDMETHODIMP_(ULONG) CDropTarget::AddRef()
{
    TestDebugOut("In IDT::AddRef\r\n");

    // delegate to the document Object
    return m_pDoc->AddRef();
}

//**********************************************************************
//
// CDropTarget::Release
//
// Purpose:
//
//      Decrements the reference count of CSimpleDoc. Since CDropTarget is
//      a nested class of CSimpleDoc, we don't need a separate reference
//      count for CDropTarget. We can safely use the reference count of
//      CSimpleDoc.
//
// Parameters:
//
//      None
//
// Return Value:
//
//      The new reference count of CSimpleDoc
//
// Function Calls:
//      Function                    Location
//
//      CSimpleDoc::Release         DOC.CPP
//      TestDebugOut           Windows API
//
//
//********************************************************************

STDMETHODIMP_(ULONG) CDropTarget::Release()
{
    TestDebugOut("In IDT::Release\r\n");

    // delegate to the document object
    return m_pDoc->Release();
}


//**********************************************************************
//
// CDropTarget::DragEnter
//
// Purpose:
//
//      Called when the mouse first enters our DropTarget window
//
// Parameters:
//
//      LPDATAOBJECT pDataObj   - IDataObject from Drop source
//      DWORD grfKeyState       - current key state
//      POINTL pointl           - position of mouse
//      LPDWORD pdwEffect       - (IN-OUT) drag effect that should occur
//                                ON INPUT, this is dwOKEffects that source
//                                passed to DoDragDrop API.
//                                ON OUTPUT, this is the effect that we
//                                want to take effect (used to determine
//                                cursor feedback).
//
// Return Value:
//
//      NOERROR
//
// Function Calls:
//      Function                    Location
//
//      TestDebugOut           Windows API
//      OleQueryCreateFromData      OLE2 API
//      DoDragScroll                IDT.CPP
//      QueryDrop                   IDT.CPP
//      InitDragFeedback            IDT.CPP
//      DrawDragFeedback            IDT.CPP
//
// Comments:
//      Callee should honor the dwEffects as passed in to determine
//      if the caller allows DROPEFFECT_MOVE.
//
//********************************************************************

STDMETHODIMP CDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState,
                                     POINTL pointl, LPDWORD pdwEffect)
{
    TestDebugOut("In IDT::DragEnter\r\n");

    /* Determine if the drag source data object offers a data format
    **  that we understand. we accept only creating embedded objects.
    */
    m_fCanDropCopy = ((OleQueryCreateFromData(pDataObj) == NOERROR) ?
            TRUE : FALSE);
    m_fCanDropLink = FALSE; // linking NOT supported in this simple sample

    if (m_fCanDropCopy || m_fCanDropLink)
        InitDragFeedback(pDataObj, pointl);

    BOOL fDragScroll = DoDragScroll ( pointl );

    if (QueryDrop(grfKeyState,pointl,fDragScroll,pdwEffect))
    {
        DrawDragFeedback( pointl );
    }

    // with our drag drop optimization, pDataObj will actually be a
    // wrapper data object.  QueryGetData calls (currently) will be
    // propogated to the drag source (whereas EnumFormatetc is handled
    // locally).  Make sure we can do a QueryGetData.

    FORMATETC formatetc;
    formatetc.cfFormat = CF_METAFILEPICT;
    formatetc.tymed = TYMED_MFPICT;
    formatetc.ptd = NULL;
    formatetc.lindex = -1;
    formatetc.dwAspect = DVASPECT_CONTENT;

    // E_FAIL is usually returned if we could not get the drag source
    // data object.
    if( pDataObj->QueryGetData(&formatetc) == E_FAIL )
    {
	TestDebugOut("WARNING! QueryGetData failed!");
    }

    return NOERROR;
}


//**********************************************************************
//
// CDropTarget::DragOver
//
// Purpose:
//
//      Called when the mouse moves, key state changes, or a time
//      interval passes while the mouse is still within our DropTarget
//      window.
//
// Parameters:
//
//      DWORD grfKeyState       - current key state
//      POINTL pointl           - position of mouse
//      LPDWORD pdwEffect       - (IN-OUT) drag effect that should occur
//                                ON INPUT, this is dwOKEffects that source
//                                passed to DoDragDrop API.
//                                ON OUTPUT, this is the effect that we
//                                want to take effect (used to determine
//                                cursor feedback).
//
// Return Value:
//
//      NOERROR
//
// Function Calls:
//      Function                    Location
//
//      TestDebugOut           Windows API
//      DoDragScroll                IDT.CPP
//      QueryDrop                   IDT.CPP
//      DrawDragFeedback            IDT.CPP
//      UndrawDragFeedback          IDT.CPP
//
// Comments:
//      Callee should honor the dwEffects as passed in to determine
//      if the caller allows DROPEFFECT_MOVE. OLE pulses the DragOver
//      calls in order that the DropTarget can implement drag scrolling
//
//********************************************************************

STDMETHODIMP CDropTarget::DragOver (DWORD grfKeyState, POINTL pointl,
                                    LPDWORD pdwEffect)
{
    TestDebugOut("In IDT::DragOver\r\n");

    BOOL fDragScroll = DoDragScroll ( pointl );

    if (QueryDrop(grfKeyState,pointl,fDragScroll,pdwEffect))
    {
        DrawDragFeedback( pointl );
    }
    else
    {
        UndrawDragFeedback();
    }

    return NOERROR;
}


//**********************************************************************
//
// CDropTarget::DragLeave
//
// Purpose:
//
//      Called when the mouse leaves our DropTarget window
//
// Parameters:
//
//      none.
//
// Return Value:
//
//      S_OK
//
// Function Calls:
//      Function                    Location
//
//      TestDebugOut           Windows API
//      UndrawDragFeedback          IDT.CPP
//      ResultFromScode             OLE2 API
//
//
//********************************************************************

STDMETHODIMP CDropTarget::DragLeave ()
{
    TestDebugOut("In IDT::DragLeave\r\n");

    UndrawDragFeedback();

    return ResultFromScode(S_OK);
}


//**********************************************************************
//
// CDropTarget::Drop
//
// Purpose:
//
//      Called when a Drop operation should take place.
//
// Parameters:
//
//      LPDATAOBJECT pDataObj   - IDataObject from Drop source
//      DWORD grfKeyState       - current key state
//      POINTL pointl           - position of mouse
//      LPDWORD pdwEffect       - (IN-OUT) drag effect that should occur
//                                ON INPUT, this is dwOKEffects that source
//                                passed to DoDragDrop API.
//                                ON OUTPUT, this is the effect that we
//                                want to take effect (used to determine
//                                cursor feedback).
//
// Return Value:
//
//      S_OK if sucess or HRESULT of the error code if fails
//
// Function Calls:
//      Function                    Location
//
//      TestDebugOut           Windows API
//      CSimpleSite::Create         SITE.CPP
//      CSimpleSite::InitObject     SITE.CPP
//      OleCreateFromData           OLE2 API
//      DoDragScroll                IDT.CPP
//      QueryDrop                   IDT.CPP
//      InitDragFeedback            IDT.CPP
//      DrawDragFeedback            IDT.CPP
//      UndrawDragFeedback          IDT.CPP
//      GetScode                    OLE2 API
//      ResultFromScode             OLE2 API
//
// Comments:
//      Callee should honor the dwEffects as passed in to determine
//      if the caller allows DROPEFFECT_MOVE.
//
//********************************************************************

STDMETHODIMP CDropTarget::Drop (LPDATAOBJECT pDataObj, DWORD grfKeyState,
                                POINTL pointl, LPDWORD pdwEffect)
{
	 FORMATETC fmtetc;
    SCODE sc = S_OK;
	
    TestDebugOut("In IDT::Drop\r\n");

    UndrawDragFeedback();

    if (pDataObj && QueryDrop(grfKeyState,pointl,FALSE,pdwEffect))
    {
        m_pDoc->m_lpSite = CSimpleSite::Create(m_pDoc);
        if (!m_pDoc->m_lpSite)
        {
           /* memory allocation problem. cannot continue.
            */
           return(ResultFromScode(E_OUTOFMEMORY));
        }

        // keep same aspect as drop source
        m_pDoc->m_lpSite->m_dwDrawAspect = m_dwSrcAspect;

        // in order to specify a particular drawing Aspect we must
        // pass a FORMATETC* to OleCreateFromData
 	     fmtetc.cfFormat = NULL; 			// use whatever for drawing
	     fmtetc.ptd = NULL;
	     fmtetc.lindex = -1;
	     fmtetc.dwAspect = m_dwSrcAspect;	// desired drawing aspect
	     fmtetc.tymed = TYMED_NULL;

        HRESULT hrErr = OleCreateFromData (
                            pDataObj,
                            IID_IOleObject,
                            OLERENDER_DRAW,
                            &fmtetc,
                            &m_pDoc->m_lpSite->m_OleClientSite,
                            m_pDoc->m_lpSite->m_lpObjStorage,
                            (LPVOID FAR *)&m_pDoc->m_lpSite->m_lpOleObject);

        if (hrErr == NOERROR)
        {
            m_pDoc->m_lpSite->InitObject(FALSE /* fCreateNew */);
            m_pDoc->DisableInsertObject();
        }
        else
            sc = GetScode(hrErr);
    }

    return ResultFromScode(sc);
}