Index
3.21. Wydruk i podglšd wydruku (2)
rozdzial 04 (21)
rozdzial 29 (21)
141 21 (10)
tip7 (21)
21 (201)
21 (36)
21 (394)
21 (142)
21 kaz (3)
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • souvenir.htw.pl

  • [ Pobierz całość w formacie PDF ]
    .As you saw earlier in the "Implementinga Drag Source" section, if you return DROPEFFECT_MOVE, the source deletes theitem from itself.Returning DROPEFFECT_NONE rejects the copy.It is OnDragOver()that deals with preparing to accept or reject a drop.The overall structure of thefunction looks like this:DROPEFFECT CShowStringView::OnDragOver(COleDataObject* pDataObject,DWORD dwKeyState, CPoint point){// return if dropping is already rejected// determine drop effect according to keys depressed// adjust focus rectangle}First, check to see whether OnDragEnter() or an earlier call to OnDragOver() alreadyrejected this possible drop:// return if dropping is already rejectedif (!m_OKtodrop){return DROPEFFECT_NONE;}Next, look at the keys that the user is holding down now, available in the parameterpassed to this function, dwKeyState.The code you need to add (see Listing 14.38)is straightforward.Listing 14.38  ShowStringView.cpp--Determine the Drop Effect// determine drop effect according to keys depressedDROPEFFECT dropeffect = DROPEFFECT_NONE;if ((dwKeyState & (MK_CONTROL|MK_SHIFT) )== (MK_CONTROL|MK_SHIFT)){// Ctrl+Shift force a linkdropeffect = DROPEFFECT_LINK;}else if ((dwKeyState & MK_CONTROL) == MK_CONTROL){// Ctrl forces a copydropeffect = DROPEFFECT_COPY;}else if ((dwKeyState & MK_ALT) == MK_ALT){// Alt forces a movedropeffect = DROPEFFECT_MOVE;}else{// default is to movedropeffect = DROPEFFECT_MOVE;}NOTE: This code has to be a lot more complex if the document might be smallerthan the view, as can happen when you are editing a bitmap in Paint, and especiallyif the view can scroll.The Microsoft ActiveX container sample, DRAWCLI, (includedon the Visual C++ CD) handles these contingencies.Look in the CD folder \Vc98\Samples\Mcl\Mfc\Ole\DrawClifor the file drawvw.cpp and compare that code for OnDragOver() to this code. If the item has moved since the last time OnDragOver() was called, the focus rectanglehas to be erased and redrawn at the new location.Because the focus rectangle isa simple XOR of the colors, drawing it a second time in the same place removes it.The code to adjust the focus rectangle is in Listing 14.39.Listing 14.39  ShowStringView.cpp--Adjust the Focus Rectangle// adjust focus rectanglepoint -= m_dragoffset;if (point == m_dragpoint){return dropeffect;}CClientDC dc(this);if (m_FocusRectangleDrawn){dc.DrawFocusRect(CRect(m_dragpoint, m_dragsize));m_FocusRectangleDrawn = FALSE;}if (dropeffect != DROPEFFECT_NONE){dc.DrawFocusRect(CRect(point, m_dragsize));m_dragpoint = point;m_FocusRectangleDrawn = TRUE;}To test whether the focus rectangle should be redrawn, this code adjusts the pointwhere the user clicked by the offset into the item to determine the top-left cornerof the item.It can then compare that location to the top-left corner of the focusrectangle.If they are the same, there is no need to redraw it.If they are different,the focus rectangle might need to be erased.NOTE: The first time OnDragOver() is called, m_dragpoint is uninitialized.That doesn't matter because m_FocusRectangleDrawn is FALSE, and an ASSERT in OnDragEnter()guarantees it.When m_FocusRectangleDrawn is set to TRUE, m_dragpoint gets a valueat the same time. Finally, replace the return statement that was generated for you with one thatreturns the calculated DROPEFFECT:return dropeffect;OnDragLeave()Sometimes a user drags an item right over your view and out the other side.OnDragLeave()just tidies up a little by removing the focus rectangle, as shown in Listing 14.40.Listing 14.40  ShowStringView.cpp--ShowStringView::OnDragLeave()void CShowStringView::OnDragLeave(){CClientDC dc(this);if (m_FocusRectangleDrawn){dc.DrawFocusRect(CRect(m_dragpoint, m_dragsize));m_FocusRectangleDrawn = FALSE;}}OnDragDrop()If the user lets go of an item that is being dragged over ShowString, the itemlands in the container and OnDragDrop() is called.The overall structure is in Listing14.41.Listing 14.41  ShowStringView.cpp--Structure of OnDrop()BOOL CShowStringView::OnDrop(COleDataObject* pDataObject,DROPEFFECT dropEffect, CPoint point){ASSERT_VALID(this);// remove focus rectangle// paste in the data object// adjust the item dimensions, and make it the current selection// update views and set modified flagreturn TRUE;}Removing the focus rectangle is simple, as shown in Listing 14.42.Listing 14.42  ShowStringView.cpp--Removing the Focus Rectangle// remove focus rectangleCClientDC dc(this);if (m_FocusRectangleDrawn){dc.DrawFocusRect(CRect(m_dragpoint, m_dragsize));m_FocusRectangleDrawn = FALSE;}Next, create a new item to hold the data object, as shown in Listing 14.43.Notethe use of the bitwise and (&) to test for a link.Listing 14.43  ShowStringView.cpp--Paste the Data Object// paste the data objectCShowStringDoc* pDoc = GetDocument();CShowStringCntrItem* pNewItem = new CShowStringCntrItem(pDoc);ASSERT_VALID(pNewItem);if (dropEffect & DROPEFFECT_LINK){pNewItem->CreateLinkFromData(pDataObject);}else{pNewItem->CreateFromData(pDataObject);}ASSERT_VALID(pNewItem);The size of the container item needs to be set, as shown in Listing 14.44.Listing 14.44  ShowStringView [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • aceton.keep.pl
  • 
    Wszelkie Prawa Zastrzeżone! Kawa była słaba i bez smaku. Nie miała treści, a jedynie formę. Design by SZABLONY.maniak.pl.